62,269
社区成员
发帖
与我相关
我的任务
分享
function $(o){return document.getElementById(o);}
function CheckImgCss(o,img)
{
if (!/\.((jpg)|(bmp)|(gif)|(png))$/ig.test(o.value))
{
alert('只能上传jpg,bmp,gif,png格式图片!');
o.outerHTML = o.outerHTML;
}
else
{
// $(img).filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src=o.value;
$('Image1').src = o.value;//这里IE7已经不支持了。所以才有上面的方法。
}
}
<table style="width: 95%; background-color: gray" title="编辑图片新闻" cellspacing="1"
cellpadding="1" border="0">
<tbody>
<tr style="height: 25px">
<td style="width: 90px; background-color: white" valign="middle" align="right">
标题:</td>
<td style="background-color: white" valign="middle" align="left">
<asp:TextBox ID="txtNewsTitle" runat="server" BorderStyle="Groove" Width="536px"></asp:TextBox>
<asp:Label ID="lblCheckState" runat="server"></asp:Label></td>
</tr>
<tr style="height: 25px">
<td style="width: 90px; background-color: white" valign="middle" align="right">
来源:</td>
<td style="background-color: white" valign="middle" align="left">
<asp:TextBox ID="txtComFrom" runat="server" BorderStyle="Groove" Width="200px" Text="本站"></asp:TextBox>
</td>
</tr>
<tr style="height: 25px">
<td style="width: 90px; background-color: white" valign="middle" align="right">
关键字:</td>
<td style="background-color: white" valign="middle" align="left">
<asp:TextBox ID="txtKeywords" runat="server" BorderStyle="Groove" Width="200px"></asp:TextBox>
</td>
</tr>
<tr style="height: 25px">
<td align="right" style="width: 90px; background-color: white" valign="middle">
选择图片:</td>
<td align="left" style="background-color: white" valign="middle">
<input id="File1" style="width: 535px" type="file" runat="server" />
</td>
</tr>
<tr style="height: 25px">
<td align="center" valign="middle" style="background-color: white" colspan="2">
<asp:Panel ID="Panel1" runat="server" Height="600px" Width="100%">
<div>
<asp:Image ID="Image1" runat="server"/> </div>
</asp:Panel>
</td>
</tr>
<tr style="height: 25px">
<td align="center" colspan="2" style="height: 30px; background-color: white" valign="middle">
<asp:ImageButton ID="ibtnPost" OnClick="ibtnPost_Click" runat="server" ImageUrl="images/jlygda_index_01.jpg" OnClientClick="return SubNews();">
</asp:ImageButton>
<asp:ImageButton ID="ibtnCheck" runat="server" CausesValidation="false" ImageUrl="images/fbxt_index_bt.jpg" OnClick="ibtnCheck_Click" />
<asp:ImageButton ID="ibnGotoList" runat="server" ImageUrl="images/fbxt_index_bt3.jpg" OnClick="ibnGotoList_Click" />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True"
ShowSummary="False"></asp:ValidationSummary>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
<br>
/// <summary>
/// 保存数据
/// </summary>
/// <returns></returns>
private bool SaveData()
{
string editFlag = Convert.ToString(ViewState["EditFlag"]);
string newsID;
if (editFlag == "add")
newsID = myDB.GetMaxID("T_PicNews", "NewsID").ToString();
else
newsID = Convert.ToString(ViewState["NewsID"]);
GetNewsData(newsID);
if (dstNews == null)
return false;
string fileName;
string filePath = Server.MapPath("~") + "\\";
if (editFlag == "edit" && dstNews.Tables[0].Rows.Count > 0)
{
//先删除原有的文件
fileName = Convert.ToString(dstNews.Tables[0].Rows[0]["PicFilePath"]);
if (System.IO.File.Exists(filePath + fileName))
System.IO.File.Delete(filePath + fileName);
}
if (File1.PostedFile == null)
{
ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "startup", "alert('请选择图片!');EndSub();", true);
return false;
}
if (File1.PostedFile.FileName == "")
{
ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "startup", "alert('请选择图片!');EndSub();", true);
return false;
}
string fileExt = System.IO.Path.GetExtension(File1.PostedFile.FileName);
//首先保存图片到硬盘
fileName = @"BusiImg\PicNewsImg\" + newsID + DateTime.Now.ToString("yyyyMMddhhMMss") + fileExt;
try
{
File1.PostedFile.SaveAs(filePath + fileName);
}
catch
{
return false;
}
//保存数据到数据库
DataRow dr;
if (editFlag == "add")
{
dr = dstNews.Tables[0].NewRow();
dr["NewsID"] = newsID;
dr["InfoType"] = ViewState["NewsKind"];
dr["Status"] = 0;
dr["ZLInfoType"] = Convert.ToInt32(ZLType);
dstNews.Tables[0].Rows.Add(dr);
}
else
{
if (dstNews.Tables[0].Rows.Count == 0)
return false;
dr = dstNews.Tables[0].Rows[0];
}
dr["Title"] = txtNewsTitle.Text;
dr["PicFilePath"] = fileName;
LoginUser aUser = (LoginUser)Session["LoginUser"];
dr["ComFrom"] = txtComFrom.Text;
dr["Keywords"] = txtKeywords.Text;
dr["Staff"] = aUser.StaffName;
dr["CreateTime"] = DateTime.Now.Date;
int ret = myDB.UpdateRS(dstNews, "T_PicNews");
ViewState["EditFlag"] = "edit";
ViewState["NewsID"] = dr["NewsID"];
Image1.ImageUrl = "";
Image1.ImageUrl = "~/" + fileName;
return ret >= 0;
}