AddOther.aspx.cs 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data;
  8. using System.Data.OleDb;
  9. using System.Data.Sql;
  10. using System.Data.SqlClient;
  11. public partial class AddOther : System.Web.UI.Page
  12. {
  13. LYS.UserData1 myud = new LYS.UserData1();
  14. // int id;
  15. string connectionString = "data source=.\\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\\MYDBSQL.mdf;User Instance=true";
  16. protected void Page_Load(object sender, EventArgs e)
  17. {
  18. if (!IsPostBack)
  19. {
  20. ZJ.Text = DateTime.Now.ToLongDateString().ToString();
  21. }
  22. TextBox1.Text = Session["Username"].ToString();
  23. }
  24. protected void Button1_Click(object sender, EventArgs e)
  25. {
  26. try
  27. {
  28. string DDXm = TextBox1.Text.Trim(); //督导姓名
  29. string DDZJ = ZJ.Text.Trim(); //督导时间
  30. string DDXMM = DropDProg.SelectedValue.Trim();//督导项目名
  31. //检查是否有同样sql="SELECT * FROM Pengfeng where csid="&request.Form("CSID")&" and 评价人='"&request.Form("MyName1")&"' and 评价组='"&request.Form("MyName2")&"'"
  32. string sql = "select * from OthProg where 督导姓名='" + DDXm + "' and 督导项目名='" + DDXMM.Trim() + "' and 督导地点='" + DD.Text.Trim() + "' and 星期='" + XQ.SelectedValue.Trim()+ "' and 节次='" + JC.SelectedValue.Trim() + "' and 督导时间='" + Convert.ToDateTime(DDZJ).ToShortDateString() + "'";
  33. //Response.Write(Convert.ToDateTime(ZJ.Text).ToShortDateString());
  34. //Response.Write(sql);
  35. //Response.End();
  36. if (myud.CheckRecord(sql))
  37. {
  38. Response.Write("<script>alert('您已填写了同样的记录,不要重复填写!');</script>");
  39. //Response.Write("<script>window.history.back();</script>");
  40. }
  41. else
  42. {
  43. //Response.Write("<script>alert('AA!')</script>");
  44. SqlConnection objConn = new SqlConnection(connectionString);
  45. objConn.Open();
  46. SqlDataAdapter objcmd = new SqlDataAdapter();
  47. objcmd.SelectCommand = new SqlCommand("select * from OthProg", objConn);
  48. SqlCommandBuilder objtable = new SqlCommandBuilder(objcmd);
  49. DataSet ds = new DataSet();
  50. objcmd.Fill(ds, "OthProg");
  51. objConn.Close();
  52. DataTable dt = ds.Tables["OthProg"];
  53. DataRow dtrow = dt.NewRow();
  54. // dtrow[0] = DBNull.Value;
  55. dtrow["系部"] = XB.SelectedValue; //系部
  56. dtrow["督导姓名"] = DDXm;//督导姓名
  57. dtrow["督导项目名"] = DDXMM; //督导项目名
  58. dtrow["督导时间"] = DDZJ;
  59. dtrow["星期"] = XQ.Text; //星期
  60. dtrow["节次"] = JC.Text; //节次
  61. dtrow["督导地点"] = DD.Text; //督导地点
  62. dtrow["督导内容"] = TextBox5.Text;//督导内容
  63. dtrow["参与人员"] = BJ.Text;//参与人员
  64. dtrow["建议或结果"] = TextBox2.Text;//参与人员
  65. dtrow["备注"] = PF.Text;//备注
  66. dt.Rows.Add(dtrow);
  67. objcmd.Update(ds, "OthProg");
  68. Response.Write("<script>alert('数据保存成功!')</script>");
  69. }
  70. }
  71. catch (Exception ex)
  72. { Response.Write("<script>alert('" + ex.Message + ";或者是数据库已经有同样的数据,不能重复添加!或出现无法预料的错误!!')</script>"); }
  73. finally
  74. { }
  75. }
  76. protected void Button2_Click(object sender, EventArgs e)
  77. {
  78. Response.Redirect("DispUPlist.aspx");
  79. }
  80. }