615d7fb3e35f95820d15f2cae0585bcaedbd95d3.svn-base 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. using DevExpress.XtraReports.UI;
  2. using iBemsDataService.Controllers;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Net;
  9. using System.Reflection;
  10. using System.Web;
  11. namespace iBemsDataService.Util
  12. {
  13. public class ReportTableHandler
  14. {
  15. public static XRTable CreateTableFromEnergyWithWidth<T>(List<T> list, float[] columnWidth)
  16. {
  17. XRTable table = CreateTableFromEnergy(list);
  18. AdjustTextSizeEnergy(table, columnWidth);
  19. return table;
  20. }
  21. public static XRTable CreateTableFromEnergy<T>(List<T> list)
  22. {
  23. XRTable table = new XRTable();
  24. table.LocationF = new PointF(0, 0);
  25. table.Font = new System.Drawing.Font("맑은 고딕", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  26. table.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleRight;
  27. List<XRTableRow> rowListtop = ConvertEnergyToTableRowstop(list);
  28. for (var i = 0; i < rowListtop.Count; i++)
  29. {
  30. table.Rows.Add(rowListtop[i]);
  31. }
  32. table.AdjustSize();
  33. table.EndInit();
  34. table.WidthF = 839f;
  35. return table;
  36. }
  37. private static List<XRTableRow> ConvertEnergyToTableRowstop<T>(List<T> list)
  38. {
  39. List<XRTableRow> rowList = new List<XRTableRow>();
  40. String[] Text = { "TextResultDate", "TextResult" };
  41. Type type = typeof(T);
  42. foreach (T item in list)
  43. {
  44. XRTableRow newRow = MakeXrTableRowTemplate();
  45. foreach (PropertyInfo propertyInfo in type.GetProperties())
  46. {
  47. var obj = propertyInfo.GetValue(item);
  48. String cellText = "";
  49. bool colorchekck = false;
  50. if (propertyInfo.Name.ToString() == "Name")
  51. {
  52. if (obj != null)
  53. {
  54. cellText = (String)obj;
  55. if (cellText.IndexOf("합계") != -1)
  56. {
  57. colorchekck = true;
  58. }
  59. }
  60. }
  61. else if (propertyInfo.Name.ToString() == "Today")
  62. {
  63. if (obj != null)
  64. {
  65. cellText = obj.ToString();
  66. }
  67. }
  68. else if (propertyInfo.Name.ToString() == "Daybefore")
  69. {
  70. if (obj != null)
  71. {
  72. cellText = obj.ToString();
  73. }
  74. }
  75. else if (propertyInfo.Name.ToString() == "Dailyusage")
  76. {
  77. if (obj != null)
  78. {
  79. cellText = obj.ToString();
  80. }
  81. }
  82. else
  83. {
  84. if (obj != null)
  85. {
  86. cellText = obj.ToString();
  87. }
  88. }
  89. XRTableCell newcell = new XRTableCell();
  90. newcell.Text = cellText;
  91. if (propertyInfo.Name.ToString() == "Name")
  92. {
  93. newcell.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
  94. }
  95. newRow.Cells.Add(newcell);
  96. if (colorchekck)
  97. {
  98. newRow.BackColor = Color.FromArgb(255, 255, 204);
  99. colorchekck = false;
  100. }
  101. }
  102. rowList.Add(newRow);
  103. }
  104. return rowList;
  105. }
  106. public static XRTable CreateTableFromListWithColumnWidth<T>(List<T> list, float[] columnWidth, String[] exceptions = null)
  107. {
  108. XRTable table = CreateTableFromList(list, exceptions);
  109. AdjustTextSize(table, columnWidth);
  110. return table;
  111. }
  112. public static XRTable CreateTableFromListWithColumnWidthPatrol<T>(List<T> list, float[] columnWidth, String[] exceptions = null)
  113. {
  114. XRTable table = CreateTableFromListPatrol(list, exceptions);
  115. AdjustTextSizePatrol(table, columnWidth);
  116. return table;
  117. }
  118. public static XRTable CreateTableFromList<T>(List<T> list, String[] exceptions = null)
  119. {
  120. XRTable table = new XRTable();
  121. table.LocationF = new PointF(0, 0);
  122. table.Font = new System.Drawing.Font("맑은 고딕", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  123. table.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
  124. table.BeginInit();
  125. List<XRTableRow> rowListtop = ConvertListToTableRowstop(list, exceptions);
  126. List<XRTableRow> rowListbottom = ConvertListToTableRowsbottom(list, exceptions);
  127. for (var i = 0; i < rowListtop.Count; i++)
  128. {
  129. table.Rows.Add(rowListtop[i]);
  130. table.Rows.Add(rowListbottom[i]);
  131. }
  132. for (var i = 1; i < rowListtop.Count * 2; i += 2)
  133. {
  134. table.Rows[i].TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
  135. }
  136. table.AdjustSize();
  137. table.EndInit();
  138. table.WidthF = 839f;
  139. return table;
  140. }
  141. public static XRTable CreateTableFromListPatrol<T>(List<T> list, String[] exceptions = null)
  142. {
  143. XRTable table = new XRTable();
  144. table.LocationF = new PointF(0, 0);
  145. table.Font = new System.Drawing.Font("맑은 고딕", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  146. table.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
  147. table.BeginInit();
  148. List<XRTableRow> rowListtop = ConvertListToTableRowstop(list, exceptions);
  149. List<XRTableRow> rowListbottom = ConvertListToTableRowsbottom(list, exceptions);
  150. for (var i = 0; i < rowListtop.Count; i++)
  151. {
  152. table.Rows.Add(rowListtop[i]);
  153. //table.Rows.Add(rowListbottom[i]);
  154. }
  155. //for (var i = 1; i < rowListtop.Count; i += 2)
  156. //{
  157. // table.Rows[i].TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
  158. //}
  159. table.AdjustSize();
  160. table.EndInit();
  161. table.WidthF = 800f;
  162. return table;
  163. }
  164. public static XRTable CreateTableFromListWithColumnWidthMaterial<T>(List<T> list, float[] columnWidth, String[] exceptions = null)
  165. {
  166. XRTable table = CreateTableFromListMaterial(list, exceptions);
  167. AdjustTextSize(table, columnWidth);
  168. return table;
  169. }
  170. public static XRTable CreateTableFromListMaterial<T>(List<T> list, String[] exceptions = null)
  171. {
  172. XRTable table = new XRTable();
  173. table.LocationF = new PointF(0, 0);
  174. table.Font = new System.Drawing.Font("맑은 고딕", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  175. table.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
  176. table.BeginInit();
  177. List<XRTableRow> rowListtop = ConvertListToTableRowstop(list, exceptions);
  178. for (var i = 0; i < rowListtop.Count; i++)
  179. {
  180. table.Rows.Add(rowListtop[i]);
  181. }
  182. table.AdjustSize();
  183. table.EndInit();
  184. table.WidthF = 839f;
  185. return table;
  186. }
  187. private static void AdjustTextSize(XRTable table, float[] columnWidth)
  188. {
  189. float[] columnWidthbottom = { 230f, 609f, 839f };
  190. foreach (XRTableRow row in table.Rows)
  191. {
  192. for (int i = 0; i < row.Cells.Count; i++)
  193. {
  194. if (row.Cells.Count > 2)
  195. {
  196. XRTableCell cell = row.Cells[i];
  197. if (columnWidth != null)
  198. {
  199. cell.SizeF = new SizeF(columnWidth[i], cell.SizeF.Height);
  200. }
  201. }
  202. else
  203. {
  204. XRTableCell cell = row.Cells[i];
  205. if (columnWidth != null)
  206. {
  207. cell.SizeF = new SizeF(columnWidthbottom[2], cell.SizeF.Height);
  208. }
  209. }
  210. }
  211. }
  212. }
  213. private static void AdjustTextSizePatrol(XRTable table, float[] columnWidth)
  214. {
  215. float[] columnWidthbottom = { 230f, 609f, 800f };
  216. foreach (XRTableRow row in table.Rows)
  217. {
  218. for (int i = 0; i < row.Cells.Count; i++)
  219. {
  220. if (row.Cells.Count > 2)
  221. {
  222. XRTableCell cell = row.Cells[i];
  223. if (columnWidth != null)
  224. {
  225. cell.SizeF = new SizeF(columnWidth[i], cell.SizeF.Height);
  226. }
  227. }
  228. else
  229. {
  230. XRTableCell cell = row.Cells[i];
  231. if (columnWidth != null)
  232. {
  233. cell.SizeF = new SizeF(columnWidthbottom[2], cell.SizeF.Height);
  234. }
  235. }
  236. }
  237. }
  238. }
  239. private static void AdjustTextSizeEnergy(XRTable table, float[] columnWidth)
  240. {
  241. foreach (XRTableRow row in table.Rows)
  242. {
  243. for (int i = 0; i < row.Cells.Count; i++)
  244. {
  245. XRTableCell cell = row.Cells[i];
  246. if (columnWidth != null)
  247. {
  248. cell.SizeF = new SizeF(columnWidth[i], cell.SizeF.Height);
  249. }
  250. }
  251. }
  252. }
  253. private static List<XRTableRow> ConvertListToTableRowstop<T>(List<T> list, String[] exceptions)
  254. {
  255. List<XRTableRow> rowList = new List<XRTableRow>();
  256. Type type = typeof(T);
  257. String[] Text = { "TextResultDate", "TextResult" };
  258. foreach (T item in list)
  259. {
  260. XRTableRow newRow = MakeXrTableRowTemplate();
  261. foreach (PropertyInfo propertyInfo in type.GetProperties())
  262. {
  263. if (exceptions != null && exceptions.Contains(propertyInfo.Name)) continue;
  264. if (Text.Contains(propertyInfo.Name)) continue;
  265. var obj = propertyInfo.GetValue(item);
  266. String cellText = null;
  267. if (obj != null)
  268. {
  269. cellText = obj.ToString();
  270. }
  271. XRTableCell newCell = new XRTableCell();
  272. newCell.Text = cellText;
  273. newRow.Cells.Add(newCell);
  274. }
  275. rowList.Add(newRow);
  276. }
  277. return rowList;
  278. }
  279. private static List<XRTableRow> ConvertListToTableRowsbottom<T>(List<T> list, String[] exceptions)
  280. {
  281. List<XRTableRow> rowList = new List<XRTableRow>();
  282. Type type = typeof(T);
  283. String[] Text = { "TextResultDate", "TextResult" };
  284. foreach (T item in list)
  285. {
  286. XRTableRow newRow = MakeXrTableRowTemplate();
  287. //String cellText = null;
  288. String[] temptext = new string[1];
  289. foreach (PropertyInfo propertyInfo in type.GetProperties())
  290. {
  291. if (exceptions != null && exceptions.Contains(propertyInfo.Name)) continue;
  292. if (!Text.Contains(propertyInfo.Name)) continue;
  293. var obj = propertyInfo.GetValue(item);
  294. if (propertyInfo.Name.ToString() == "TextResultDate")
  295. {
  296. if (obj != null)
  297. {
  298. DateTime[] TextResultDate = (DateTime[])obj;
  299. temptext = new string[TextResultDate.Count()];
  300. }
  301. else
  302. {
  303. temptext = null;
  304. }
  305. }
  306. if (propertyInfo.Name.ToString() == "TextResultDate")
  307. {
  308. DateTime[] TextResultDate = (DateTime[])obj;
  309. if (TextResultDate != null)
  310. {
  311. for (var i = 0; i < TextResultDate.Count(); i++)
  312. {
  313. temptext[i] = " " + TextResultDate[i].ToString("yyyy-MM-dd");
  314. }
  315. }
  316. else
  317. {
  318. //for (var i = 0; i < TextResultDate.Count(); i++)
  319. //{
  320. // temptext[i] = "";
  321. //}
  322. }
  323. }
  324. else if (propertyInfo.Name.ToString() == "TextResult")
  325. {
  326. String[] TextResult = (String[])obj;
  327. //var seven = 50;
  328. if (TextResult != null)
  329. {
  330. for (var i = 0; i < TextResult.Count(); i++)
  331. {
  332. //var result = TextResult[i].Replace("\n", " "); //.replace(/\n/gi, '</p><p>&emsp;&emsp;&emsp;&emsp;&emsp;&ensp;');
  333. //temptext[i] += " - " + result + "\r\n";
  334. var result = TextResult[i].Replace("\n", "\n ");
  335. result = result.Replace("?-", " -");
  336. temptext[i] += " - " + result + "\r\n";
  337. //if (temptext[i].Length > seven)
  338. //{
  339. // temptext[i] = factorial(temptext[i]);
  340. //}
  341. }
  342. }
  343. else
  344. {
  345. //for (var i = 0; i < TextResult.Count(); i++)
  346. //{
  347. // temptext[i] += "";
  348. //}
  349. }
  350. }
  351. }
  352. XRTableCell newCell = new XRTableCell();
  353. string finaltempstring = "";
  354. if (temptext != null)
  355. {
  356. for (var i = 0; i < temptext.Length; i++)
  357. {
  358. finaltempstring += temptext[i];
  359. }
  360. }
  361. else
  362. {
  363. finaltempstring = "";
  364. }
  365. newCell.Text = finaltempstring;
  366. newCell.Multiline = true;
  367. newRow.Cells.Add(newCell);
  368. rowList.Add(newRow);
  369. }
  370. return rowList;
  371. }
  372. public static string factorial(string temp)
  373. {
  374. var seven = 50;
  375. var forcnt = temp.Length / seven; //몫
  376. var forcnt1 = temp.Length % seven; //나머지
  377. if (forcnt == 0)
  378. {
  379. return temp;
  380. }
  381. else if (forcnt != 0 && forcnt1 != 0)
  382. {
  383. return temp.Substring(0, seven) + "\r\n" + factorial(temp.Substring(seven));
  384. }
  385. else
  386. {
  387. return temp.Substring(0, seven);
  388. }
  389. }
  390. private static XRTableRow MakeXrTableRowTemplate()
  391. {
  392. XRTableRow newRow = new XRTableRow();
  393. newRow.BorderColor = Color.Black;
  394. newRow.BorderWidth = 1;
  395. newRow.Borders = DevExpress.XtraPrinting.BorderSide.All;
  396. newRow.HeightF = 30f;
  397. return newRow;
  398. }
  399. }
  400. }