Count.aspx.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. public partial class Count : System.Web.UI.Page
  8. {
  9. LYS.UserData1 myud = new LYS.UserData1();
  10. //string QueryConditions = "";
  11. string SQL = "select ID,教师姓名,系部,课程名,督导姓名,听课日期 from TKJL";
  12. string TableName = "TKJL";
  13. string sql = "";
  14. protected void Page_Load(object sender, EventArgs e)
  15. {
  16. //tbEndTime.Value = DateTime.Now.ToShortDateString();
  17. //tbStartTime.Value = DateTime.Now.ToShortDateString();
  18. Session["SQL"] = "";
  19. HttpContext.Current.Session["TableName"] = "";
  20. HttpContext.Current.Session["SQL"] = SQL;
  21. HttpContext.Current.Session["TableName"] = TableName;
  22. if (!Page.IsPostBack)
  23. {
  24. // myud.BindFiledToDropDownList(QueryField, SQL, TableName);
  25. }
  26. //DateTime startTime = Convert.ToDateTime("2017-9-1");
  27. //DateTime endTime = Convert.ToDateTime("2017-9-11");
  28. // string sql = "select count(*) as 总计 from TKJL where 听课日期 >= #2017-9-1# and 听课日期 <=#2017-9-10#"; //OK
  29. //DateTime time3 = DateTime.D dateTimePicker1.Value.Date.ToString("yyyy-MM-dd");
  30. //DateTime time4 = dateTimePicker2.Value.Date.ToString("yyyy-MM-dd");
  31. // checkCmd = "SELECT sum([单笔账单总计]) As 总计 FROM Account where 时间 between #" + time3 + "# and #" + time4 + "#";
  32. //Literal1.Text = myud.DispLineCount(sql).ToString();
  33. }
  34. protected void Button1_Click(object sender, EventArgs e)
  35. {
  36. Panel1.Visible = true;
  37. Literal2.Text = "《" + sDemp.Value + "》" + ReportName.Value + "督导统计报表";
  38. DateTime startTime = Convert.ToDateTime(tbStartTime.Value.ToString());
  39. DateTime endTime = Convert.ToDateTime(tbEndTime.Value.ToString());
  40. //2.督导听课
  41. if (sDemp.Value.Trim().ToString() == "全院")
  42. {
  43. // sql = "select count(*) as " + ReportName.Value + " from TKJL where 听课日期 >= '" + tbStartTime.Value + "' and 听课日期 <='" + tbEndTime.Value + "'"; //OK
  44. sql = "select count(*) from TKJL where 听课日期 >= '" + tbStartTime.Value + "' and 听课日期 <='" + tbEndTime.Value + "'"; //OK
  45. }
  46. else
  47. {
  48. // sql = "select count(*) as " + ReportName.Value + " from TKJL where 听课日期 >= '" + tbStartTime.Value + "' and 听课日期 <='" + tbEndTime.Value + "' and 系部='" + sDemp.Value.Trim().ToString() + "'"; //OK
  49. sql = "select count(*) from TKJL where 听课日期 >= '" + tbStartTime.Value + "' and 听课日期 <='" + tbEndTime.Value + "' and 系部='" + sDemp.Value.Trim().ToString() + "'"; //OK
  50. }
  51. //string sql = "select count(*) as " + ReportName.Value + " from TKJL where 听课日期 >= #" + tbStartTime.Value + "# and 听课日期 <=#" + tbEndTime.Value + "#"; //OK ACCESS
  52. XB.Text = sDemp.Value.ToString();
  53. DDTK.Text = myud.DispLineCountNum(sql).ToString();
  54. //1.督导会议
  55. if (sDemp.Value.Trim().ToString() == "全院")
  56. {
  57. sql = "select count(*) from OthProg where 督导时间 >= '" + tbStartTime.Value + "' and 督导时间 <='" + tbEndTime.Value + "' and 督导项目名 Like '%督导会议%'"; //OK
  58. }
  59. else
  60. {
  61. sql = "select count(*) from OthProg where 督导时间 >= '" + tbStartTime.Value + "' and 督导时间 <='" + tbEndTime.Value + "' and 督导项目名 Like '%督导会议%' and 系部='" + sDemp.Value.Trim().ToString() + "'"; //OK
  62. }
  63. DDHY.Text = myud.DispLineCountNum(sql).ToString();
  64. //3.评课次数
  65. //if (sDemp.Value.Trim().ToString() == "全院")
  66. //{
  67. // sql = "select count(*) from OthProg where 督导时间 >= '" + tbStartTime.Value + "' and 督导时间 <='" + tbEndTime.Value + "' and 督导项目名 Like '%教学评课%'"; //OK
  68. //}
  69. //else
  70. //{
  71. // sql = "select count(*) from OthProg where 督导时间 >= '" + tbStartTime.Value + "' and 督导时间 <='" + tbEndTime.Value + "' and 督导项目名 Like '%教学评课%' and 系部='" + sDemp.Value.Trim().ToString() + "'"; //OK
  72. //}
  73. if (sDemp.Value.Trim().ToString() == "全院")
  74. {
  75. sql = "select count(*) from TKJL where 听课日期 >= '" + tbStartTime.Value + "' and 听课日期 <='" + tbEndTime.Value + "' and 综合评价 IS NOT NULL"; //OK
  76. }
  77. else
  78. {
  79. sql = "select count(*) from TKJL where 听课日期 >= '" + tbStartTime.Value + "' and 听课日期 <='" + tbEndTime.Value + "' and 综合评价 IS NOT NULL and 系部='" + sDemp.Value.Trim().ToString() + "'"; //OK
  80. }
  81. DDPK.Text = myud.DispLineCountNum(sql).ToString();
  82. //4.督学情况
  83. if (sDemp.Value.Trim().ToString() == "全院")
  84. {
  85. sql = "select count(*) from OthProg where 督导时间 >= '" + tbStartTime.Value + "' and 督导时间 <='" + tbEndTime.Value + "' and 督导项目名 Like '%督学情况%'"; //OK
  86. }
  87. else
  88. {
  89. sql = "select count(*) from OthProg where 督导时间 >= '" + tbStartTime.Value + "' and 督导时间 <='" + tbEndTime.Value + "' and 督导项目名 Like '%督学情况%' and 系部='" + sDemp.Value.Trim().ToString() + "'"; //OK
  90. }
  91. DXCS.Text = myud.DispLineCountNum(sql).ToString();
  92. //5.教学检查
  93. if (sDemp.Value.Trim().ToString() == "全院")
  94. {
  95. sql = "select count(*) from OthProg where 督导时间 >= '" + tbStartTime.Value + "' and 督导时间 <='" + tbEndTime.Value + "' and 督导项目名 Like '%教学检查%'"; //OK
  96. }
  97. else
  98. {
  99. sql = "select count(*) from OthProg where 督导时间 >= '" + tbStartTime.Value + "' and 督导时间 <='" + tbEndTime.Value + "' and 督导项目名 Like '%教学检查%' and 系部='" + sDemp.Value.Trim().ToString() + "'"; //OK
  100. }
  101. JXJC.Text = myud.DispLineCountNum(sql).ToString();
  102. //7.项目评审
  103. if (sDemp.Value.Trim().ToString() == "全院")
  104. {
  105. sql = "select count(*) from OthProg where 督导时间 >= '" + tbStartTime.Value + "' and 督导时间 <='" + tbEndTime.Value + "' and 督导项目名 Like '%项目评审%'"; //OK
  106. }
  107. else
  108. {
  109. sql = "select count(*) from OthProg where 督导时间 >= '" + tbStartTime.Value + "' and 督导时间 <='" + tbEndTime.Value + "' and 督导项目名 Like '%项目评审%' and 系部='" + sDemp.Value.Trim().ToString() + "'"; //OK
  110. }
  111. XMPH.Text = myud.DispLineCountNum(sql).ToString();
  112. //8.培训交流
  113. if (sDemp.Value.Trim().ToString() == "全院")
  114. {
  115. sql = "select count(*) from OthProg where 督导时间 >= '" + tbStartTime.Value + "' and 督导时间 <='" + tbEndTime.Value + "' and 督导项目名 Like '%培训交流%'"; //OK
  116. }
  117. else
  118. {
  119. sql = "select count(*) from OthProg where 督导时间 >= '" + tbStartTime.Value + "' and 督导时间 <='" + tbEndTime.Value + "' and 督导项目名 Like '%培训交流%' and 系部='" + sDemp.Value.Trim().ToString() + "'"; //OK
  120. }
  121. PXJL.Text = myud.DispLineCountNum(sql).ToString();
  122. //9.其它
  123. if (sDemp.Value.Trim().ToString() == "全院")
  124. {
  125. sql = "select count(*) from OthProg where 督导时间 >= '" + tbStartTime.Value + "' and 督导时间 <='" + tbEndTime.Value + "' and 督导项目名 Like '%其它%'"; //OK
  126. }
  127. else
  128. {
  129. sql = "select count(*) from OthProg where 督导时间 >= '" + tbStartTime.Value + "' and 督导时间 <='" + tbEndTime.Value + "' and 督导项目名 Like '%其它%' and 系部='" + sDemp.Value.Trim().ToString() + "'"; //OK
  130. }
  131. Othe.Text = myud.DispLineCountNum(sql).ToString();
  132. }
  133. /// <summary>
  134. /// 以行显示,每一行下划线显示 显示统计结果(总数)
  135. /// </summary>
  136. /// <param name="SQL"></param>
  137. /// <returns></returns>
  138. //public StringBuilder DispLineCount(string SQL)
  139. //{ //调用
  140. // //DateTime startTime = Convert.ToDateTime("2017-9-1");
  141. // //DateTime endTime = Convert.ToDateTime("2017-9-11");
  142. // //string sql = "select count(*) as 总计 from TKJL where 听课日期 >= #2017-9-1# and 听课日期 <=#2017-9-10#"; //OK
  143. // StringBuilder sb = new StringBuilder();
  144. // // sb.Append("\n <link href=\"css/global.css\" rel=\"stylesheet\" type=\"text/css\" />");
  145. // string sql = SQL;
  146. // OleDbConnection dtConn = new OleDbConnection(connectionString);
  147. // OleDbDataAdapter dtCmd = new OleDbDataAdapter(sql, dtConn);
  148. // DataSet dtSet = new DataSet();
  149. // dtCmd.Fill(dtSet);
  150. // DataTableReader objreader = dtSet.CreateDataReader();
  151. // int i = 0, j = 0;
  152. // sb.Append("\n <table width=\"900\" align=\"center\" class=\"lh28 font_st\">");
  153. // sb.Append("\n <tr style=\"background-image: url('images/list_line2-1.gif')\">");
  154. // for (i = 0; i <= objreader.FieldCount - 1; i++)
  155. // {
  156. // sb.Append(" <td align=\"center\" nowrap=\"nowrap\" style=\"background-color:#3F98E9; color:#FFFFFF; height:30px;\"><b>" + objreader.GetName(i) + "&nbsp;</b>");
  157. // }
  158. // sb.Append("\n </tr>");
  159. // while (objreader.Read())
  160. // {
  161. // j = j + 1;
  162. // sb.Append("\n <tr class=\"list_bline1\">");
  163. // for (i = 0; i <= objreader.FieldCount - 1; i++)
  164. // {
  165. // sb.Append("\n <td style=\"height:30px; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #C1CCD5; \">" + objreader.GetValue(i).ToString() + "&nbsp;</td>");
  166. // }
  167. // sb.Append("\n </tr>");
  168. // }
  169. // sb.Append("</table>");
  170. // return sb;
  171. //}
  172. protected void Button3_Click(object sender, EventArgs e)
  173. {
  174. HttpContext.Current.Response.Buffer = true;
  175. HttpContext.Current.Response.Clear();
  176. HttpContext.Current.Response.Charset = "gb2312";
  177. HttpContext.Current.Response.ClearContent();
  178. HttpContext.Current.Response.ClearHeaders();
  179. Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
  180. HttpContext.Current.Response.ContentType = "application/ms-word";
  181. HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=fileDown.doc");
  182. //关闭控件的视图状态 ,如果仍然为true,RenderControl将启用页的跟踪功能,存储与控件有关的跟踪信息
  183. this.EnableViewState = false;
  184. //将要下载的页面输出到HtmlWriter
  185. System.IO.StringWriter writer = new System.IO.StringWriter();
  186. System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(writer);
  187. this.RenderControl(htmlWriter);
  188. //提取要输出的内容
  189. string pageHtml = writer.ToString();
  190. int startIndex = pageHtml.IndexOf("<div style=\"margin: 0 auto;\" id=\"mainContent\">");
  191. int endIndex = pageHtml.LastIndexOf("</div>");
  192. int lenth = endIndex - startIndex;
  193. pageHtml = pageHtml.Substring(startIndex, lenth);
  194. //输出
  195. HttpContext.Current.Response.Write(pageHtml.ToString());
  196. HttpContext.Current.Response.End();
  197. }
  198. }
  199. //SQL
  200. //string datemin=DateTime.Parse("2009年5月1日 00:00");
  201. //string datemax=DateTime.Parse("20009年7月1日 12:12");
  202. //然后写sql语句如下:
  203. //string strsql="select * from T_Chart where F_Date>='"+datemin+"' and F_Date<='"+datemax+"'";