全部代码
private void save_Click(object sender, System.EventArgs e)
{
System.Web.HttpPostedFile imagefile=this.ImageFile.PostedFile;
int a=imagefile.ContentLength; string title=this.Title.Text.Trim();
string comefrom=this.ComeFrom.Text.Trim();
string content=this.Content.Text.Trim().Replace("\r\n","<br>").Replace("\n","");
int nnewsid;
int isimage;
if(this.modename=="add")
{
ConnIntID NewsIntId=new ConnIntID("bool_news_body","newsid");
nnewsid=NewsIntId.getID();
}
else
{
nnewsid=this.newsid;
} if(this.IsImage.Checked==true){
isimage=1;
}
else
isimage=0;
if(modename=="add")
{
conn=new Conn("select count(*) from bool_news_body where title='"+title+"'","simple");
if(((int)conn.ret)>0)
{
errflag=0;
}
}
else
{
conn=new Conn("select count(*) from bool_news_body where title='"+title+"' and newsid<>"+newsid,"simple");
if(((int)conn.ret)>0)
{
errflag=0;
}
}
if(title.Length==0)
{
this.TitleError.Text="新闻标题为空";
}
else
{
if(errflag==0)
{
this.TitleError.Text="标题已经存在";
}
}
if(content=="")
{
errflag=0;
this.ContentError.Text="新闻内容为空";
}
if(this.modename=="add"&&errflag==1)
{
string insertnewssql="insert into bool_news_body(newsid,title,content,comefrom,IsImage,LastDate,IsVisible,querytime) values("
+ nnewsid.ToString() +",'"+title+"','"+content+"','"+comefrom +"',"+isimage.ToString()+",'"+DateTime.Now+"',1,0)";
conn=new Conn(insertnewssql,"noselect");
conn.CloseDatabase();
ConnIntID updateid=new ConnIntID("bool_news_body","newsid");
updateid.updateID();
}
else{
if(isimage==0&&errflag==1)
{
string updatenewssql="update bool_news_body set title='"+title+"',content='"+content+"',comefrom='"+comefrom+"',lastdate='"+DateTime.Now+"' where newsid="+nnewsid;
conn=new Conn(updatenewssql,"noselect");
conn.CloseDatabase();
}
else
{
if(errflag==1){
string updatenewssql="update bool_news_body set title='"+title+"',content='"+content+"',comefrom='"+comefrom+"',isimage="+isimage.ToString()+
",lastdate='"+DateTime.Now+"' where newsid="+nnewsid;
conn=new Conn(updatenewssql,"noselect");
conn.CloseDatabase();
}
}
}
if(isimage==1&&errflag==1)
{
// try
// {
//System.Web.HttpPostedFile imagefile=this.ImageFile.PostedFile;
if(this.ImageFile.PostedFile.ContentLength>0)
{
string imagefilename=this.ImageFile.PostedFile.FileName;
int imagesize=this.ImageFile.PostedFile.ContentLength;
string imagetype=this.ImageFile.PostedFile.ContentType;
Stream imageStream=this.ImageFile.PostedFile.InputStream;
byte [] input= new byte[imagesize];
int intStatues=imageStream.Read(input,0,imagesize);
string connstr=ConfigurationSettings.AppSettings["connectstring"];
SqlConnection connection = new SqlConnection(connstr);
SqlCommand command = new SqlCommand("update bool_news_body set newsimage=@input,newsimagetype=@imagetype where newsid=@nnewsid",connection);
SqlParameter paramImageFile = new SqlParameter("@input", SqlDbType.Image);
paramImageFile.Value = input;
command.Parameters.Add(paramImageFile);
SqlParameter paramImageType = new SqlParameter( "@imagetype", SqlDbType.VarChar,255);
paramImageType.Value = imagetype;
command.Parameters.Add( paramImageType );
SqlParameter paramNewsID = new SqlParameter( "@nnewsid", SqlDbType.Int);
paramNewsID.Value = nnewsid;
command.Parameters.Add(paramNewsID );
connection.Open();
int numRowsAffected = command.ExecuteNonQuery();
connection.Close();
}
else
{
conn=new Conn("update bool_news_body set isimage=0 where newsid="+nnewsid,"noselect");
conn.CloseDatabase();
}
// }
// catch(Exception err)
// {
// this.err.Text=err.ToString();
// conn=new Conn("update bool_news_body set isimage=0 where newsid="+nnewsid,"noselect");
// conn.CloseDatabase();
// }
}
if(errflag==1)
{
Response.Redirect("index.aspx?module=news&file=index");
}
}
}
private void save_Click(object sender, System.EventArgs e)
{
System.Web.HttpPostedFile imagefile=this.ImageFile.PostedFile;
int a=imagefile.ContentLength; string title=this.Title.Text.Trim();
string comefrom=this.ComeFrom.Text.Trim();
string content=this.Content.Text.Trim().Replace("\r\n","<br>").Replace("\n","");
int nnewsid;
int isimage;
if(this.modename=="add")
{
ConnIntID NewsIntId=new ConnIntID("bool_news_body","newsid");
nnewsid=NewsIntId.getID();
}
else
{
nnewsid=this.newsid;
} if(this.IsImage.Checked==true){
isimage=1;
}
else
isimage=0;
if(modename=="add")
{
conn=new Conn("select count(*) from bool_news_body where title='"+title+"'","simple");
if(((int)conn.ret)>0)
{
errflag=0;
}
}
else
{
conn=new Conn("select count(*) from bool_news_body where title='"+title+"' and newsid<>"+newsid,"simple");
if(((int)conn.ret)>0)
{
errflag=0;
}
}
if(title.Length==0)
{
this.TitleError.Text="新闻标题为空";
}
else
{
if(errflag==0)
{
this.TitleError.Text="标题已经存在";
}
}
if(content=="")
{
errflag=0;
this.ContentError.Text="新闻内容为空";
}
if(this.modename=="add"&&errflag==1)
{
string insertnewssql="insert into bool_news_body(newsid,title,content,comefrom,IsImage,LastDate,IsVisible,querytime) values("
+ nnewsid.ToString() +",'"+title+"','"+content+"','"+comefrom +"',"+isimage.ToString()+",'"+DateTime.Now+"',1,0)";
conn=new Conn(insertnewssql,"noselect");
conn.CloseDatabase();
ConnIntID updateid=new ConnIntID("bool_news_body","newsid");
updateid.updateID();
}
else{
if(isimage==0&&errflag==1)
{
string updatenewssql="update bool_news_body set title='"+title+"',content='"+content+"',comefrom='"+comefrom+"',lastdate='"+DateTime.Now+"' where newsid="+nnewsid;
conn=new Conn(updatenewssql,"noselect");
conn.CloseDatabase();
}
else
{
if(errflag==1){
string updatenewssql="update bool_news_body set title='"+title+"',content='"+content+"',comefrom='"+comefrom+"',isimage="+isimage.ToString()+
",lastdate='"+DateTime.Now+"' where newsid="+nnewsid;
conn=new Conn(updatenewssql,"noselect");
conn.CloseDatabase();
}
}
}
if(isimage==1&&errflag==1)
{
// try
// {
//System.Web.HttpPostedFile imagefile=this.ImageFile.PostedFile;
if(this.ImageFile.PostedFile.ContentLength>0)
{
string imagefilename=this.ImageFile.PostedFile.FileName;
int imagesize=this.ImageFile.PostedFile.ContentLength;
string imagetype=this.ImageFile.PostedFile.ContentType;
Stream imageStream=this.ImageFile.PostedFile.InputStream;
byte [] input= new byte[imagesize];
int intStatues=imageStream.Read(input,0,imagesize);
string connstr=ConfigurationSettings.AppSettings["connectstring"];
SqlConnection connection = new SqlConnection(connstr);
SqlCommand command = new SqlCommand("update bool_news_body set newsimage=@input,newsimagetype=@imagetype where newsid=@nnewsid",connection);
SqlParameter paramImageFile = new SqlParameter("@input", SqlDbType.Image);
paramImageFile.Value = input;
command.Parameters.Add(paramImageFile);
SqlParameter paramImageType = new SqlParameter( "@imagetype", SqlDbType.VarChar,255);
paramImageType.Value = imagetype;
command.Parameters.Add( paramImageType );
SqlParameter paramNewsID = new SqlParameter( "@nnewsid", SqlDbType.Int);
paramNewsID.Value = nnewsid;
command.Parameters.Add(paramNewsID );
connection.Open();
int numRowsAffected = command.ExecuteNonQuery();
connection.Close();
}
else
{
conn=new Conn("update bool_news_body set isimage=0 where newsid="+nnewsid,"noselect");
conn.CloseDatabase();
}
// }
// catch(Exception err)
// {
// this.err.Text=err.ToString();
// conn=new Conn("update bool_news_body set isimage=0 where newsid="+nnewsid,"noselect");
// conn.CloseDatabase();
// }
}
if(errflag==1)
{
Response.Redirect("index.aspx?module=news&file=index");
}
}
}
解决方案 »
- 获取弹出窗口返回值
- 在 北京->丰台->洋桥 附近 那里有好一点的 [[日语]]培训中心
- 如何动态的添加删除用户控件?
- 如何在IE中打开PDF。还有如何读取.dat文件
- 求助,脚本错误
- .net安装问题?请问怎么解决
- 点击datagird colunms属性时提示“未将对象设置引用到对象的实例”
- 哪位能给小弟提供一些关于邮件发送和接收的代码
- datagrid的新增问题
- 急,为什么在windows2003上的sqlserver拒绝我的asp.net程序的访问?
- 高手帮忙,如何做showmodaldialog打印?(高分相送,一周内结贴)
- 请问我在VS.NET中使用Maseegeinnerhtml老是报错。
encType="multipart/form-data" 不能掉 ;
mynumber = InStrRev(filenames, ".")
houzhui = Mid(filenames, mynumber) If Not (file1.PostedFile Is Nothing) Then
Try file1.PostedFile.SaveAs(filepath + tbtdmc.Text + houzhui)
不能掉了 encType="multipart/form-data"
//runat=server 不能少