PlanTask.aspx.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 PlanTask : System.Web.UI.Page
  12. {
  13. LYS.UserData1 myud = new LYS.UserData1();
  14. // string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Server.MapPath("~\\App_Data\\ZY.mdb");
  15. protected void Page_Load(object sender, EventArgs e)
  16. {
  17. DDLXQ.Items.Add(getCurrentXQ("E"));
  18. TextBox2.Text = Session["Username"].ToString();
  19. for (int i = 1; i <= 20; i++)
  20. {
  21. DDLZC.Items.Add("第"+i.ToString()+"周");
  22. }
  23. }
  24. protected void Button1_Click(object sender, EventArgs e)
  25. {
  26. if (DD.Text.Trim().Length == 0 || TaskTitle.Text.Trim().Length == 0 || DDLXQ.SelectedValue.Trim().Length == 0 || DDLZC.SelectedValue.Trim().Length == 0 || TextBox2.Text.Trim().Length == 0 || TaskContent.Text.Trim().Length==0)
  27. { Response.Write("<script>alert('请检查你的数据是否填写完整!!');</script>"); }
  28. else
  29. {
  30. //检查是否有同样sql="SELECT * FROM Pengfeng where csid="&request.Form("CSID")&" and 评价人='"&request.Form("MyName1")&"' and 评价组='"&request.Form("MyName2")&"'"
  31. string sql = "select * from PlanSet where 周次='" + DDLZC.SelectedValue.Trim() + "' and 任务主题='" + TaskTitle.Text.Trim() + "' and 任务内容='" + TaskContent.Text.Trim() +"'";
  32. //Response.Write(Convert.ToDateTime(ZJ.Text).ToShortDateString());
  33. //Response.Write(sql);
  34. //Response.End();
  35. if (myud.CheckRecord(sql))
  36. {
  37. Response.Write("<script>alert('您已经安排此任务,不能重复安排同一个任务!');</script>");
  38. //Response.Write("<script>window.history.back();</script>");
  39. }
  40. else
  41. {
  42. SqlConnection objConn = new SqlConnection(myud.ConnString());
  43. objConn.Open();
  44. SqlDataAdapter objcmd = new SqlDataAdapter();
  45. objcmd.SelectCommand = new SqlCommand("select * from PlanSet", objConn);
  46. SqlCommandBuilder objtable = new SqlCommandBuilder(objcmd);
  47. DataSet ds = new DataSet();
  48. objcmd.Fill(ds, "PlanSet");
  49. objConn.Close();
  50. DataTable dt = ds.Tables["PlanSet"];
  51. DataRow dtrow = dt.NewRow();
  52. dtrow[0] = DBNull.Value;
  53. dtrow["学期"] = DDLXQ.SelectedValue.Trim().ToString();
  54. dtrow["周次"] = DDLZC.SelectedValue.Trim().ToString(); //系部
  55. dtrow["安排者"] = TextBox2.Text.Trim(); //课程名
  56. dtrow["任务主题"] = TaskTitle.Text.Trim(); //
  57. dtrow["任务内容"] = TaskContent.Text.Trim(); //
  58. dtrow["所在部门"] = XB.SelectedValue.Trim(); //班级
  59. dtrow["星期"] = XQ.Text; //星期
  60. dtrow["节次"] = JC.Text; //节次
  61. dtrow["地点"] = DD.Text; //上课地点
  62. dt.Rows.Add(dtrow);
  63. objcmd.Update(ds, "PlanSet");
  64. Response.Write("<script>alert('任务安排成功!')</script>");
  65. }
  66. }
  67. }
  68. //获得当前学期
  69. public string getCurrentXQ(string EC)
  70. {
  71. System.DateTime currentTime = System.DateTime.Now;
  72. int strYear = Convert.ToInt32(currentTime.Year.ToString());
  73. int strMonth = Convert.ToInt32(currentTime.Month.ToString());
  74. string xq = "", xq1 = "";
  75. if (strMonth > 1 && strMonth < 8)
  76. {
  77. xq = (strYear - 1).ToString() + "-" + strYear.ToString() + "年度第2学期";
  78. xq1 = strYear.ToString() + "春";
  79. }
  80. else
  81. {
  82. xq = strYear.ToString() + "-" + (strYear + 1).ToString() + "年度第1学期";
  83. xq1 = strYear.ToString() + "秋";
  84. }
  85. if (strMonth < 2)
  86. {
  87. xq = (strYear - 1).ToString() + "-" + strYear.ToString() + "年度第1学期";
  88. xq1 = (strYear - 1).ToString() + "秋";
  89. }
  90. if (EC == "E")
  91. {
  92. return xq;
  93. }
  94. else
  95. { return xq1; }
  96. }
  97. }