protected void rjjtsubmit_Click(object sender, EventArgs e) { if (this.rjjtcheck.Checked == true) { bool flag = true; security sc = new security(); if (sc.pictures(Path.GetExtension(this.rjjtfile.FileName)) && this.rjjttitle.Text != "") { string connStr = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString; SqlConnection conn = new SqlConnection(connStr); conn.Open(); try { string leibie; if (this.ruanjianjietu.SelectedItem.Text == "添加新类别") { if (this.rjjtleibie.Text != "") { leibie = this.rjjtleibie.Text; } else { Exception ex = new Exception(); throw ex; } } else { leibie = this.ruanjianjietu.SelectedItem.Text; } // 给管理员发送邮件 sendmailclass sd = new sendmailclass(); string value1 = Session["emaildizhi"].ToString(); string value2 = "您的项目“" + Session["xiangmuming"].ToString() + "”有新成果上传,请前往查看!"; string value3 = "成果更新提醒"; sd.sendmailfunction(value1, value2, value3); // 写入数据库 SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; string filename = shengcheng(Path.GetExtension(this.rjjtfile.FileName)); cmd.CommandText = "INSERT INTO gallery VALUES('" + this.rjjttitle.Text + "','" + leibie + "','" + Session["xiangmuhao"].ToString() + "','" + filename + "')"; cmd.ExecuteNonQuery(); // 上传文件 this.rjjtfile.SaveAs(Server.MapPath("/") + "\\pictures\\" + filename); // 给管理员发送私信 cmd.CommandText = "INSERT INTO webchat VALUES('" + Session["yonghuming"].ToString() + "','" + Session["guanliyuan"].ToString() + "','有新的成果上传,请及时审核!','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','否')"; cmd.ExecuteNonQuery(); } catch { conn.Close(); conn.Dispose(); flag = false; } finally { conn.Close(); conn.Dispose(); if (flag) { ClientScript.RegisterStartupScript(GetType(), "", "<script>alert(\"操作成功!\")</script>"); } else { ClientScript.RegisterStartupScript(GetType(), "", "<script>alert(\"请检查输入并保证网络畅通!\")</script>"); } } } else { ClientScript.RegisterStartupScript(GetType(), "", "<script>alert(\"请检查您输入的信息并注意文件格式!\")</script>"); } } else { ClientScript.RegisterStartupScript(GetType(), "", "<script>alert(\"请检查您输入的信息并确认!\")</script>"); } }