Нет описания

GDLXSJController.cs 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. using CallCenter.Utility;
  2. using CallCenterApi.DB;
  3. using CallCenterApi.Interface.Controllers.Base;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Linq;
  8. using System.Web;
  9. using System.Web.Mvc;
  10. namespace CallCenterApi.Interface.Controllers.report
  11. {
  12. public class GDLXSJController : BaseController
  13. {
  14. //// GET: GDLXYQ
  15. //public ActionResult Index()
  16. //{
  17. // return View();
  18. //}
  19. /// <summary>
  20. /// 获取报表头
  21. /// </summary>
  22. /// <returns></returns>
  23. public ActionResult GetHeadList()
  24. {
  25. ActionResult res = NoToken("未知错误,请重新登录");
  26. DataTable dtNew = new DataTable();
  27. //添加第一行标题
  28. //DataColumn dc1 = new DataColumn("");
  29. //dtNew.Columns.Add(dc1);
  30. var sqlGDLY1 = "select F_CategoryId,F_CategoryName from T_RepositoryCategory where 1=1 and F_CategoryType = 1 and F_ParentId in (select F_CategoryId from T_RepositoryCategory where F_CategoryType = 1 and F_DeleteFlag = 0 and F_CategoryName = '试剂')";
  31. var dtGDLY1 = DbHelperSQL.Query(sqlGDLY1).Tables[0];
  32. int dtGDLY1rowcount = dtGDLY1.Rows.Count;
  33. //列名
  34. string[] dtGDLY1_name = new string[dtGDLY1rowcount + 2];
  35. dtGDLY1_name[0] = "";
  36. //列数
  37. int[] dtGDLY1_count = new int[dtGDLY1rowcount + 2];
  38. dtGDLY1_count[0] = 1;
  39. for (int v = 0; v < dtGDLY1rowcount; v++)
  40. {
  41. string catename = dtGDLY1.Rows[v]["F_CategoryName"].ToString();
  42. var count_sub = int.Parse(DbHelperSQL.GetSingle("select count(*) from T_RepositoryCategory where 1=1 and F_CategoryType = 1 and F_DeleteFlag = 0 and F_ParentId=" + int.Parse(dtGDLY1.Rows[v]["F_CategoryId"].ToString()) + "").ToString());
  43. dtGDLY1_name[v + 1] = catename;
  44. dtGDLY1_count[v + 1] = count_sub;
  45. }
  46. dtGDLY1_name[dtGDLY1rowcount + 1] = "总计";
  47. dtGDLY1_count[dtGDLY1rowcount + 1] = 1;
  48. res = Success("获取工单类型试剂报表表头成功", dtNew);
  49. return res;
  50. }
  51. /// <summary>
  52. /// 获取工单类型试剂报表
  53. /// </summary>
  54. /// <param name="stime"></param>
  55. /// <param name="endtime"></param>
  56. /// <returns></returns>
  57. public ActionResult GetDataList(string stime, string endtime)
  58. {
  59. ActionResult res = NoToken("未知错误,请重新登录");
  60. DataTable dtNew = new DataTable();
  61. //添加第一行标题
  62. //DataColumn dc1 = new DataColumn("");
  63. //dtNew.Columns.Add(dc1);
  64. var sqlGDLY1 = "select F_CategoryId,F_CategoryName from T_RepositoryCategory where 1=1 and F_CategoryType = 1 and F_ParentId in (select F_CategoryId from T_RepositoryCategory where F_CategoryType = 1 and F_DeleteFlag = 0 and F_CategoryName = '试剂') and F_DeleteFlag = 0";
  65. var dtGDLY1 = DbHelperSQL.Query(sqlGDLY1).Tables[0];
  66. int dtGDLY1rowcount = dtGDLY1.Rows.Count;
  67. //列名
  68. string[] dtGDLY1_name = new string[dtGDLY1rowcount + 2];
  69. dtGDLY1_name[0] = "";
  70. //列数
  71. int[] dtGDLY1_count = new int[dtGDLY1rowcount + 2];
  72. dtGDLY1_count[0] = 1;
  73. for (int v = 0; v < dtGDLY1rowcount; v++)
  74. {
  75. string catename = dtGDLY1.Rows[v]["F_CategoryName"].ToString();
  76. var count_sub = int.Parse(DbHelperSQL.GetSingle("select count(*) from T_RepositoryCategory where 1=1 and F_DeleteFlag = 0 and F_CategoryType = 1 and F_ParentId=" + int.Parse(dtGDLY1.Rows[v]["F_CategoryId"].ToString()) + "").ToString());
  77. dtGDLY1_name[v + 1] = catename;
  78. dtGDLY1_count[v + 1] = count_sub;
  79. }
  80. dtGDLY1_name[dtGDLY1rowcount + 1] = "总计";
  81. dtGDLY1_count[dtGDLY1rowcount + 1] = 1;
  82. dtNew = getData(stime, endtime);
  83. #region 获取第二行标题
  84. //DataColumn dc = new DataColumn("姓名");
  85. //dtNew.Columns.Add(dc);
  86. List<string> colnames = new List<string>();
  87. colnames.Add("姓名");
  88. var sqlGDLY = " and F_CategoryType=1 and F_ParentId in (select F_CategoryId from T_RepositoryCategory where F_CategoryType = 1 and F_ParentId in (select F_CategoryId from T_RepositoryCategory where F_CategoryType = 1 and F_DeleteFlag = 0 and F_CategoryName = '试剂') and F_DeleteFlag = 0) and F_DeleteFlag = 0";
  89. var recordCount = 0;
  90. var dtGDLY = BLL.PagerBLL.GetListPager(
  91. "T_RepositoryCategory",
  92. "F_CategoryId",
  93. "*",
  94. sqlGDLY,
  95. "ORDER BY F_ParentId asc",
  96. 10,
  97. 1,
  98. true,
  99. out recordCount);
  100. int[] cateid = new int[recordCount];
  101. List<Model.T_RepositoryCategory> modelList = new BLL.T_RepositoryCategory().DataTableToList(dtGDLY);
  102. for (int i = 0; i < modelList.Count; i++)
  103. {
  104. string colname = modelList[i].F_CategoryName;
  105. //if (dtNew.Columns.Contains(colname))
  106. // colname += "_1";
  107. colnames.Add(colname);
  108. //dtNew.Columns.Add(new DataColumn(colname));
  109. //cateid[i] = modelList[i].F_CategoryId;
  110. }
  111. //dtNew.Columns.Add("总计");
  112. colnames.Add("");
  113. #endregion
  114. var obj = new
  115. {
  116. linename = dtGDLY1_name,
  117. linecount = dtGDLY1_count,
  118. lineSeName = colnames,
  119. dtlist = dtNew
  120. };
  121. res = Success("获取工单类型数据成功", obj);
  122. return res;
  123. }
  124. private DataTable getData(string stime, string endtime)
  125. {
  126. DataTable dtNew = new DataTable();
  127. #region 添加表格标题
  128. ////添加第一行标题
  129. ////DataColumn dc1 = new DataColumn("");
  130. ////dtNew.Columns.Add(dc1);
  131. //var sqlGDLY1 = "select F_CategoryId,F_CategoryName from T_RepositoryCategory where 1=1 and F_CategoryType = 1 and F_ParentId in (select F_CategoryId from T_RepositoryCategory where F_CategoryType = 1 and F_DeleteFlag = 0 and F_CategoryName = '试剂'))";
  132. //var dtGDLY1 = DbHelperSQL.Query(sqlGDLY1).Tables[0];
  133. //int dtGDLY1rowcount = dtGDLY1.Rows.Count;
  134. ////列名
  135. //string[] dtGDLY1_name = new string[dtGDLY1rowcount + 1];
  136. //dtGDLY1_name[0] = "";
  137. ////列数
  138. //int[] dtGDLY1_count = new int[dtGDLY1rowcount + 1];
  139. //dtGDLY1_count[0] = 1;
  140. //for (int v = 0; v < dtGDLY1rowcount; v++)
  141. //{
  142. // string catename = dtGDLY1.Rows[v]["F_CategoryName"].ToString();
  143. // var count_sub = int.Parse(DbHelperSQL.GetSingle("select count(*) from T_RepositoryCategory where 1=1 and F_CategoryType = 1 and F_ParentId=" + int.Parse(dtGDLY1.Rows[v]["F_CategoryId"].ToString()) + "").ToString());
  144. // dtGDLY1_name[v + 1] = catename;
  145. // dtGDLY1_count[v + 1] = count_sub;
  146. //}
  147. //添加第二行标题
  148. DataColumn dc = new DataColumn("姓名");
  149. dtNew.Columns.Add(dc);
  150. var sqlGDLY = " and F_CategoryType=1 and F_ParentId in (select F_CategoryId from T_RepositoryCategory where F_CategoryType = 1 and F_ParentId in (select F_CategoryId from T_RepositoryCategory where F_CategoryType = 1 and F_DeleteFlag = 0 and F_CategoryName = '试剂') and F_DeleteFlag = 0 ) and F_DeleteFlag = 0";
  151. var recordCount = 0;
  152. var dtGDLY = BLL.PagerBLL.GetListPager(
  153. "T_RepositoryCategory",
  154. "F_CategoryId",
  155. "*",
  156. sqlGDLY,
  157. "ORDER BY F_ParentId asc",
  158. 10,
  159. 1,
  160. true,
  161. out recordCount);
  162. int[] cateid = new int[recordCount];
  163. List<Model.T_RepositoryCategory> modelList = new BLL.T_RepositoryCategory().DataTableToList(dtGDLY);
  164. for (int i = 0; i < modelList.Count; i++)
  165. {
  166. string colname = modelList[i].F_CategoryName;
  167. if (dtNew.Columns.Contains(colname))
  168. colname += "_" + i;
  169. dtNew.Columns.Add(new DataColumn(colname));
  170. cateid[i] = modelList[i].F_CategoryId;
  171. }
  172. dtNew.Columns.Add("总计");
  173. #endregion
  174. string sqltimeCallRecords = "";
  175. if (stime != null && stime.Trim() != "")
  176. {
  177. sqltimeCallRecords += " and CONVERT(varchar , CreateTime, 120)>=CONVERT(varchar , '" + stime.Trim() + " 00:00:01', 120) ";
  178. }
  179. if (endtime != null && endtime.Trim() != "")
  180. {
  181. sqltimeCallRecords += " and CONVERT(varchar , CreateTime, 120)<=CONVERT(varchar , '" + endtime.Trim() + " 23:59:59', 120) ";
  182. }
  183. double day = 0;
  184. if (stime != null && endtime != null && endtime.Trim() != "" && stime.Trim() != "")
  185. {
  186. TimeSpan time = Convert.ToDateTime(endtime) - Convert.ToDateTime(stime);
  187. day = time.Days + 1;
  188. }
  189. //获取坐席数据
  190. DataTable dt = new DataTable();
  191. string sql = "SELECT * from T_Sys_UserAccount where F_DeleteFlag=0 order by F_Userid asc";
  192. dt = DbHelperSQL.Query(sql).Tables[0];
  193. for (int i = 0; i < dt.Rows.Count; i++)
  194. {
  195. DataRow drNew = dtNew.NewRow();
  196. drNew["姓名"] = dt.Rows[i]["F_UserName"].ToString();
  197. //获取工单类型数据
  198. int sum = 0;
  199. for (int j = 0; j < cateid.Length; j++)
  200. {
  201. string str = "select count(*) from T_Wo_WorkOrder where IsDel=0 and typeclass=" + cateid[j] + " and CreateUserID='" + dt.Rows[i]["F_Userid"].ToString() + "'" + sqltimeCallRecords;
  202. int ecount = int.Parse(DbHelperSQL.GetSingle(str).ToString());
  203. sum += ecount;
  204. drNew[j + 1] = ecount.ToString();
  205. }
  206. drNew["总计"] = sum;
  207. dtNew.Rows.Add(drNew);
  208. }
  209. DataRow drsum = dtNew.NewRow();
  210. drsum[0] = "总计";
  211. for (int i = 1; i < dtNew.Columns.Count; i++)
  212. {
  213. int ecount = 0;
  214. int sum = 0;
  215. for (int j = 1; j < dtNew.Rows.Count; j++)
  216. {
  217. if (dtNew.Rows[j][i] != null)
  218. {
  219. ecount = int.Parse(dtNew.Rows[j][i].ToString());
  220. sum += ecount;
  221. }
  222. }
  223. drsum[i] = sum;
  224. }
  225. dtNew.Rows.Add(drsum);
  226. return dtNew;
  227. }
  228. //导出数据
  229. public ActionResult ExptList(string stime, string endtime)
  230. {
  231. ActionResult res = NoToken("未知错误,请重新登录");
  232. if (Request.IsAuthenticated)
  233. {
  234. DataTable dtNew = new DataTable();
  235. //添加第一行标题
  236. //DataColumn dc1 = new DataColumn("");
  237. //dtNew.Columns.Add(dc1);
  238. var sqlGDLY1 = "select F_CategoryId,F_CategoryName from T_RepositoryCategory where 1=1 and F_CategoryType = 1 and F_ParentId in (select F_CategoryId from T_RepositoryCategory where F_CategoryType = 1 and F_DeleteFlag = 0 and F_CategoryName = '试剂') and F_DeleteFlag = 0";
  239. var dtGDLY1 = DbHelperSQL.Query(sqlGDLY1).Tables[0];
  240. int dtGDLY1rowcount = dtGDLY1.Rows.Count;
  241. //每块占的列数
  242. int[] colpos = new int[dtGDLY1rowcount + 1];
  243. colpos[0] = 1;
  244. //列名
  245. string[] dtGDLY1_name = new string[dtGDLY1rowcount + 2];
  246. dtGDLY1_name[0] = "";
  247. //列数
  248. int[] dtGDLY1_count = new int[dtGDLY1rowcount + 2];
  249. dtGDLY1_count[0] = 1;
  250. for (int v = 0; v < dtGDLY1rowcount; v++)
  251. {
  252. string catename = dtGDLY1.Rows[v]["F_CategoryName"].ToString();
  253. var count_sub = int.Parse(DbHelperSQL.GetSingle("select count(*) from T_RepositoryCategory where 1=1 and F_DeleteFlag = 0 and F_CategoryType = 1 and F_ParentId=" + int.Parse(dtGDLY1.Rows[v]["F_CategoryId"].ToString()) + "").ToString());
  254. dtGDLY1_name[v + 1] = catename;
  255. dtGDLY1_count[v + 1] = count_sub;
  256. colpos[v + 1] = count_sub;
  257. }
  258. dtGDLY1_name[dtGDLY1rowcount + 1] = "总计";
  259. dtGDLY1_count[dtGDLY1rowcount + 1] = 1;
  260. NPOIHelper npoi = new NPOIHelper();
  261. DataTable dt = getData(stime, endtime);
  262. if (npoi.ExportToExcelForGDLX("工单类型试剂报表", dt, "试剂", dtGDLY1_name, colpos) == "")
  263. {
  264. var obj = new
  265. {
  266. datatable = dt,
  267. dtnames = dtGDLY1_name,
  268. dtcols = colpos
  269. };
  270. return Success("导出成功", obj);
  271. }
  272. else
  273. {
  274. return Error("导出失败");
  275. }
  276. }
  277. return res;
  278. }
  279. ///// <summary>
  280. ///// 合并单元格
  281. ///// </summary>
  282. ///// <param name="sheet">要合并单元格所在的sheet</param>
  283. ///// <param name="rowstart">开始行的索引</param>
  284. ///// <param name="rowend">结束行的索引</param>
  285. ///// <param name="colstart">开始列的索引</param>
  286. ///// <param name="colend">结束列的索引</param>
  287. //public static void SetCellRangeAddress(ISheet sheet, int rowstart, int rowend, int colstart, int colend)
  288. //{
  289. // CellRangeAddress cellRangeAddress = new CellRangeAddress(rowstart, rowend, colstart, colend);
  290. // sheet.AddMergedRegion(cellRangeAddress);
  291. //}
  292. }
  293. }