RptProduction.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using CoreFS.SA06;
  10. using Core.Mes.Client.Comm.Server;
  11. using Core.Mes.Client.Comm.Control;
  12. using Core.Mes.Client.Comm.Tool;
  13. using Infragistics.Win.UltraWinGrid;
  14. using Infragistics.Win;
  15. using CoreFS.CA06;
  16. using System.Net;
  17. using System.Collections;
  18. namespace Core.StlMes.Client.BuyBillet
  19. {
  20. public partial class RptProduction : FrmBase
  21. {
  22. public RptProduction()
  23. {
  24. InitializeComponent();
  25. }
  26. private void RptProduction_Load(object sender, EventArgs e)
  27. {
  28. ForbidSort();
  29. this.rptdate.Value = DateTime.Today;
  30. }
  31. private void getproductions()
  32. {
  33. WaitingForm2 wf = new WaitingForm2("正在加载数据,请稍候....");
  34. try
  35. {
  36. string mydate = ((DateTime)this.rptdate.Value).ToString("yyyy-MM-dd");
  37. DataTable dtqry = ServerHelper.GetData("com.steering.rpt.production.TotalProduction.getQuantity", new object[] { mydate }, this.ob);
  38. /**分层显示**********/
  39. //summarytable(dtqry);
  40. /************/
  41. /**汇总显示**********/
  42. summary(dtqry);
  43. /************/
  44. GridHelper.CopyDataToDatatable(ref dtqry, ref this.dataTable1, true);
  45. RefreshSetting(ultraGrid1,((DateTime)this.rptdate.Value).ToString("yyyy年M月d日"));
  46. wf.Close();
  47. }
  48. catch(Exception e)
  49. {
  50. MessageBox.Show(e.Message);
  51. }
  52. finally
  53. {
  54. wf.Close();
  55. }
  56. }
  57. private void summarytable(DataTable dtqry)
  58. {
  59. dataTable0.Clear();
  60. if (dtqry.Rows.Count > 0)
  61. {
  62. dtqry.Columns.Add("processcode_area", Type.GetType("System.String"));
  63. dtqry.Columns.Add("processpline", Type.GetType("System.String"));
  64. string a = dtqry.Rows[0]["processcode"].ToString();
  65. decimal outputweight = 0, production = 0, totalproduction = 0,totaloutputweight = 0;
  66. decimal input = 0, output = 0, firstgood = 0, totalinput = 0, totaloutput = 0, totalfirstgood = 0;
  67. for (int i = 0; i < dtqry.Rows.Count; i++)
  68. {
  69. dtqry.Rows[i]["processcode_area"] = dtqry.Rows[i]["processcode"].ToString() + dtqry.Rows[i]["area"].ToString() ;
  70. dtqry.Rows[i]["processpline"] = dtqry.Rows[i]["processcode"].ToString() + dtqry.Rows[i]["plinename"].ToString();
  71. if (dtqry.Rows[i]["production"].ToString() != "")
  72. production += Convert.ToDecimal(dtqry.Rows[i]["production"].ToString());
  73. if (dtqry.Rows[i]["input"].ToString() != "")
  74. input += Convert.ToDecimal(dtqry.Rows[i]["input"].ToString());
  75. if (dtqry.Rows[i]["output"].ToString() != "")
  76. output += Convert.ToDecimal(dtqry.Rows[i]["output"].ToString());
  77. if (dtqry.Rows[i]["outputweight"].ToString() != "")
  78. outputweight += Convert.ToDecimal(dtqry.Rows[i]["outputweight"].ToString());
  79. if (dtqry.Rows[i]["firstgood"].ToString() != "")
  80. firstgood += Convert.ToDecimal(dtqry.Rows[i]["firstgood"].ToString());
  81. if (dtqry.Rows[i]["totalproduction"].ToString() != "")
  82. totalproduction += Convert.ToDecimal(dtqry.Rows[i]["totalproduction"].ToString());
  83. if (dtqry.Rows[i]["totalinput"].ToString() != "")
  84. totalinput += Convert.ToDecimal(dtqry.Rows[i]["totalinput"].ToString());
  85. if (dtqry.Rows[i]["totaloutput"].ToString() != "")
  86. totaloutput += Convert.ToDecimal(dtqry.Rows[i]["totaloutput"].ToString());
  87. if (dtqry.Rows[i]["totaloutputweight"].ToString() != "")
  88. totaloutputweight += Convert.ToDecimal(dtqry.Rows[i]["totaloutputweight"].ToString());
  89. if (dtqry.Rows[i]["totalfirstgood"].ToString() != "")
  90. totalfirstgood += Convert.ToDecimal(dtqry.Rows[i]["totalfirstgood"].ToString());
  91. if (i + 1 == dtqry.Rows.Count || i + 1 < dtqry.Rows.Count && dtqry.Rows[i + 1]["processcode"].ToString() != a)
  92. {
  93. DataRow myrow = dataTable0.NewRow();
  94. myrow["processcode_t"] = dtqry.Rows[i]["processcode"].ToString();
  95. if (production != 0)
  96. myrow["production_t"] = production.ToString("#,###,##0.000");
  97. if (outputweight != 0)
  98. myrow["outputweight_t"] = outputweight.ToString("#,###,##0.000");
  99. if (input != 0)
  100. myrow["productionrate_t"] = Math.Round(production * 100 / input,2).ToString("##0.00")+"%";
  101. if (output != 0)
  102. myrow["firstgoodrate_t"] = Math.Round(firstgood * 100 / output, 2).ToString("##0.00") + "%";
  103. if (totalproduction != 0)
  104. myrow["totalproduction_t"] = totalproduction.ToString("#,###,##0.000");
  105. if (totaloutputweight != 0)
  106. myrow["totaloutputweight_t"] = totaloutputweight.ToString("#,###,##0.000");
  107. if (input != 0)
  108. myrow["totalproductionrate_t"] = Math.Round(totalproduction * 100 / totalinput, 2).ToString("##0.00") + "%";
  109. if (output != 0)
  110. myrow["totalfirstgoodrate_t"] = Math.Round(totalfirstgood * 100 / totaloutput, 2).ToString("##0.00") + "%";
  111. dataTable0.Rows.Add(myrow);
  112. if (i + 1 < dtqry.Rows.Count)
  113. {
  114. a = dtqry.Rows[i + 1]["processcode"].ToString();
  115. production = 0;
  116. outputweight = 0;
  117. input = 0;
  118. output = 0;
  119. firstgood = 0;
  120. totalproduction = 0;
  121. totaloutputweight = 0;
  122. totalinput = 0;
  123. totaloutput = 0;
  124. totalfirstgood = 0;
  125. }
  126. else
  127. break;
  128. }
  129. }
  130. }
  131. }
  132. private void summary(DataTable dtqry)
  133. {
  134. if (dtqry.Rows.Count > 0)
  135. {
  136. dtqry.Columns.Add("processcode_area", Type.GetType("System.String"));
  137. dtqry.Columns.Add("processpline", Type.GetType("System.String"));
  138. string a = dtqry.Rows[0]["processcode"].ToString();
  139. string b = dtqry.Rows[0]["processcode"].ToString() + dtqry.Rows[0]["dept"].ToString();
  140. string c = dtqry.Rows[0]["processcode"].ToString() + dtqry.Rows[0]["area"].ToString(); ;
  141. decimal[] outputweight = { 0, 0, 0 }, production = { 0, 0, 0 }, totalproduction = { 0, 0, 0 }, totaloutputweight = { 0, 0, 0 };
  142. decimal[] input = { 0, 0, 0 }, output = { 0, 0, 0 }, firstgood = { 0, 0, 0 }, totalinput = { 0, 0, 0 }, totaloutput = { 0, 0, 0 }, totalfirstgood = { 0, 0, 0 };
  143. int count = 0, count1=0;
  144. try
  145. {
  146. for (int i = 0; i < dtqry.Rows.Count; i++)
  147. {
  148. count++;
  149. count1++;
  150. dtqry.Rows[i]["processcode_area"] = dtqry.Rows[i]["processcode"].ToString() + dtqry.Rows[i]["area"].ToString() + dtqry.Rows[i]["dept"].ToString();
  151. dtqry.Rows[i]["processpline"] = dtqry.Rows[i]["processcode"].ToString() + dtqry.Rows[i]["plinename"].ToString();
  152. if (dtqry.Rows[i]["production"].ToString() != "")
  153. {
  154. production[0] += Convert.ToDecimal(dtqry.Rows[i]["production"].ToString());
  155. production[1] += Convert.ToDecimal(dtqry.Rows[i]["production"].ToString());
  156. production[2] += Convert.ToDecimal(dtqry.Rows[i]["production"].ToString());
  157. }
  158. if (dtqry.Rows[i]["input"].ToString() != "")
  159. {
  160. input[0] += Convert.ToDecimal(dtqry.Rows[i]["input"].ToString());
  161. input[1] += Convert.ToDecimal(dtqry.Rows[i]["input"].ToString());
  162. input[2] += Convert.ToDecimal(dtqry.Rows[i]["input"].ToString());
  163. if (dtqry.Rows[i]["production"].ToString() != "" && Convert.ToDecimal(dtqry.Rows[i]["input"].ToString())!=0)
  164. dtqry.Rows[i]["productionrate"] = Math.Round(Convert.ToDecimal(dtqry.Rows[i]["production"].ToString()) * 100 / Convert.ToDecimal(dtqry.Rows[i]["input"].ToString()), 2).ToString("##0.00") + "%";
  165. }
  166. if (dtqry.Rows[i]["output"].ToString() != "")
  167. {
  168. output[0] += Convert.ToDecimal(dtqry.Rows[i]["output"].ToString());
  169. output[1] += Convert.ToDecimal(dtqry.Rows[i]["output"].ToString());
  170. output[2] += Convert.ToDecimal(dtqry.Rows[i]["output"].ToString());
  171. if (dtqry.Rows[i]["firstgood"].ToString() != "" && Convert.ToDecimal(dtqry.Rows[i]["output"].ToString())!=0)
  172. dtqry.Rows[i]["firstgoodrate"] = Math.Round(Convert.ToDecimal(dtqry.Rows[i]["firstgood"].ToString()) * 100 / Convert.ToDecimal(dtqry.Rows[i]["output"].ToString()), 2).ToString("##0.00") + "%";
  173. }
  174. if (dtqry.Rows[i]["outputweight"].ToString() != "")
  175. {
  176. outputweight[0] += Convert.ToDecimal(dtqry.Rows[i]["outputweight"].ToString());
  177. outputweight[1] += Convert.ToDecimal(dtqry.Rows[i]["outputweight"].ToString());
  178. outputweight[2] += Convert.ToDecimal(dtqry.Rows[i]["outputweight"].ToString());
  179. }
  180. if (dtqry.Rows[i]["firstgood"].ToString() != "")
  181. {
  182. firstgood[0] += Convert.ToDecimal(dtqry.Rows[i]["firstgood"].ToString());
  183. firstgood[1] += Convert.ToDecimal(dtqry.Rows[i]["firstgood"].ToString());
  184. firstgood[2] += Convert.ToDecimal(dtqry.Rows[i]["firstgood"].ToString());
  185. }
  186. if (dtqry.Rows[i]["totalproduction"].ToString() != "")
  187. {
  188. totalproduction[0] += Convert.ToDecimal(dtqry.Rows[i]["totalproduction"].ToString());
  189. totalproduction[1] += Convert.ToDecimal(dtqry.Rows[i]["totalproduction"].ToString());
  190. totalproduction[2] += Convert.ToDecimal(dtqry.Rows[i]["totalproduction"].ToString());
  191. }
  192. if (dtqry.Rows[i]["totalinput"].ToString() != "")
  193. {
  194. totalinput[0] += Convert.ToDecimal(dtqry.Rows[i]["totalinput"].ToString());
  195. totalinput[1] += Convert.ToDecimal(dtqry.Rows[i]["totalinput"].ToString());
  196. totalinput[2] += Convert.ToDecimal(dtqry.Rows[i]["totalinput"].ToString());
  197. if (dtqry.Rows[i]["totalproduction"].ToString() != "" && Convert.ToDecimal(dtqry.Rows[i]["totalinput"].ToString())!=0)
  198. dtqry.Rows[i]["productionrate_m"] = Math.Round(Convert.ToDecimal(dtqry.Rows[i]["totalproduction"].ToString()) * 100 / Convert.ToDecimal(dtqry.Rows[i]["totalinput"].ToString()), 2).ToString("##0.00") + "%";
  199. }
  200. if (dtqry.Rows[i]["totaloutput"].ToString() != "")
  201. {
  202. totaloutput[0] += Convert.ToDecimal(dtqry.Rows[i]["totaloutput"].ToString());
  203. totaloutput[1] += Convert.ToDecimal(dtqry.Rows[i]["totaloutput"].ToString());
  204. totaloutput[2] += Convert.ToDecimal(dtqry.Rows[i]["totaloutput"].ToString());
  205. if (dtqry.Rows[i]["totalfirstgood"].ToString() != "" && Convert.ToDecimal(dtqry.Rows[i]["totaloutput"].ToString())!=0)
  206. dtqry.Rows[i]["firstgoodrate_m"] = Math.Round(Convert.ToDecimal(dtqry.Rows[i]["totalfirstgood"].ToString()) * 100 / Convert.ToDecimal(dtqry.Rows[i]["totaloutput"].ToString()), 2).ToString("##0.00") + "%";
  207. }
  208. if (dtqry.Rows[i]["totaloutputweight"].ToString() != "")
  209. {
  210. totaloutputweight[0] += Convert.ToDecimal(dtqry.Rows[i]["totaloutputweight"].ToString());
  211. totaloutputweight[1] += Convert.ToDecimal(dtqry.Rows[i]["totaloutputweight"].ToString());
  212. totaloutputweight[2] += Convert.ToDecimal(dtqry.Rows[i]["totaloutputweight"].ToString());
  213. }
  214. if (dtqry.Rows[i]["totalfirstgood"].ToString() != "")
  215. {
  216. totalfirstgood[0] += Convert.ToDecimal(dtqry.Rows[i]["totalfirstgood"].ToString());
  217. totalfirstgood[1] += Convert.ToDecimal(dtqry.Rows[i]["totalfirstgood"].ToString());
  218. totalfirstgood[2] += Convert.ToDecimal(dtqry.Rows[i]["totalfirstgood"].ToString());
  219. }
  220. string processcode = "", dept = "", area = "";
  221. if (i + 1 < dtqry.Rows.Count)
  222. {
  223. processcode = dtqry.Rows[i + 1]["processcode"].ToString();
  224. dept = dtqry.Rows[i + 1]["dept"].ToString();
  225. area = dtqry.Rows[i + 1]["area"].ToString();
  226. }
  227. if (i + 1 == dtqry.Rows.Count || i + 1 < dtqry.Rows.Count && processcode + dept != b)
  228. {
  229. if (count > 1 && (processcode == a && processcode + dept != b || i + 1 == dtqry.Rows.Count || (processcode != a
  230. && production[0]<production[1] && outputweight[0]<outputweight[1]
  231. && totalproduction[0] < totalproduction[1] && totaloutputweight[0] < totaloutputweight[1] && processcode + dept != b)))
  232. {
  233. DataRow myrow = dtqry.NewRow();
  234. myrow["processcode_area"] = dtqry.Rows[i]["processcode_area"].ToString();
  235. myrow["processcode"] = dtqry.Rows[i]["processcode"].ToString();
  236. myrow["area"] = dtqry.Rows[i]["area"];
  237. myrow["dept"] = dtqry.Rows[i]["dept"];
  238. myrow["plinename"] = "小计";
  239. myrow["processpline"] = myrow["processcode"].ToString() + dtqry.Rows[i]["dept"].ToString() + myrow["plinename"].ToString();
  240. if (production[0] != 0)
  241. myrow["production"] = production[0].ToString("#,###,##0.000");
  242. if (outputweight[0] != 0)
  243. myrow["outputweight"] = outputweight[0].ToString("#,###,##0.000");
  244. if (input[0] != 0)
  245. myrow["productionrate"] = Math.Round(production[0] * 100 / input[0], 2).ToString("##0.00") + "%";
  246. if (output[0] != 0)
  247. myrow["firstgoodrate"] = Math.Round(firstgood[0] * 100 / output[0], 2).ToString("##0.00") + "%";
  248. if (totalproduction[0] != 0)
  249. myrow["totalproduction"] = totalproduction[0].ToString("#,###,##0.000");
  250. if (totaloutputweight[0] != 0)
  251. myrow["totaloutputweight"] = totaloutputweight[0].ToString("#,###,##0.000");
  252. if (totalinput[0] != 0)
  253. myrow["productionrate_m"] = Math.Round(totalproduction[0] * 100 / totalinput[0], 2).ToString("##0.00") + "%";
  254. if (totaloutput[0] != 0)
  255. myrow["firstgoodrate_m"] = Math.Round(totalfirstgood[0] * 100 / totaloutput[0], 2).ToString("##0.00") + "%";
  256. dtqry.Rows.InsertAt(myrow, ++i);
  257. }
  258. if (i + 1 < dtqry.Rows.Count && processcode + dept != b)
  259. {
  260. b = processcode + dept;
  261. count = 0;
  262. production[0] = 0;
  263. outputweight[0] = 0;
  264. input[0] = 0;
  265. output[0] = 0;
  266. firstgood[0] = 0;
  267. totalproduction[0] = 0;
  268. totaloutputweight[0] = 0;
  269. totalinput[0] = 0;
  270. totaloutput[0] = 0;
  271. totalfirstgood[0] = 0;
  272. }
  273. if (count1 > 1 && (processcode == a && processcode + area != c || i + 1 == dtqry.Rows.Count || (processcode != a
  274. && production[2] < production[1] && outputweight[2] < outputweight[1]
  275. && totalproduction[2] < totalproduction[1] && totaloutputweight[2] < totaloutputweight[1] && processcode + area != c)))
  276. {
  277. DataRow myrow = dtqry.NewRow();
  278. myrow["processcode_area"] = dtqry.Rows[i]["processcode_area"].ToString();
  279. myrow["processcode"] = dtqry.Rows[i]["processcode"].ToString();
  280. myrow["area"] = dtqry.Rows[i]["area"];
  281. myrow["dept"] = "小计";
  282. myrow["processpline"] = myrow["processcode"].ToString() + dtqry.Rows[i]["dept"].ToString() + myrow["plinename"].ToString();
  283. if (production[2] != 0)
  284. myrow["production"] = production[2].ToString("#,###,##0.000");
  285. if (outputweight[2] != 0)
  286. myrow["outputweight"] = outputweight[2].ToString("#,###,##0.000");
  287. if (input[2] != 0)
  288. myrow["productionrate"] = Math.Round(production[2] * 100 / input[2], 2).ToString("##0.00") + "%";
  289. if (output[2] != 0)
  290. myrow["firstgoodrate"] = Math.Round(firstgood[2] * 100 / output[2], 2).ToString("##0.00") + "%";
  291. if (totalproduction[2] != 0)
  292. myrow["totalproduction"] = totalproduction[2].ToString("#,###,##0.000");
  293. if (totaloutputweight[2] != 0)
  294. myrow["totaloutputweight"] = totaloutputweight[2].ToString("#,###,##0.000");
  295. if (totalinput[2] != 0)
  296. myrow["productionrate_m"] = Math.Round(totalproduction[2] * 100 / totalinput[2], 2).ToString("##0.00") + "%";
  297. if (totaloutput[2] != 0)
  298. myrow["firstgoodrate_m"] = Math.Round(totalfirstgood[2] * 100 / totaloutput[2], 2).ToString("##0.00") + "%";
  299. dtqry.Rows.InsertAt(myrow, ++i);
  300. }
  301. if (i + 1 < dtqry.Rows.Count && processcode + area != c)
  302. {
  303. c = processcode + area;
  304. count1 = 0;
  305. production[2] = 0;
  306. outputweight[2] = 0;
  307. input[2] = 0;
  308. output[2] = 0;
  309. firstgood[2] = 0;
  310. totalproduction[2] = 0;
  311. totaloutputweight[2] = 0;
  312. totalinput[2] = 0;
  313. totaloutput[2] = 0;
  314. totalfirstgood[2] = 0;
  315. }
  316. if (i + 1 == dtqry.Rows.Count || processcode != a)
  317. {
  318. DataRow myrow = dtqry.NewRow();
  319. myrow["processcode_area"] = dtqry.Rows[i]["processcode_area"].ToString();
  320. myrow["processcode"] = dtqry.Rows[i]["processcode"].ToString();
  321. myrow["area"] = "合计";
  322. myrow["processpline"] = myrow["processcode"].ToString() + myrow["area"].ToString();
  323. if (production[1] != 0)
  324. myrow["production"] = production[1].ToString("#,###,##0.000");
  325. if (outputweight[1] != 0)
  326. myrow["outputweight"] = outputweight[1].ToString("#,###,##0.000");
  327. if (input[1] != 0)
  328. myrow["productionrate"] = Math.Round(production[1] * 100 / input[1], 2).ToString("##0.00") + "%";
  329. if (output[1] != 0)
  330. myrow["firstgoodrate"] = Math.Round(firstgood[1] * 100 / output[1], 2).ToString("##0.00") + "%";
  331. if (totalproduction[1] != 0)
  332. myrow["totalproduction"] = totalproduction[1].ToString("#,###,##0.000");
  333. if (totaloutputweight[1] != 0)
  334. myrow["totaloutputweight"] = totaloutputweight[1].ToString("#,###,##0.000");
  335. if (totalinput[1] != 0)
  336. myrow["productionrate_m"] = Math.Round(totalproduction[1] * 100 / totalinput[1], 2).ToString("##0.00") + "%";
  337. if (totaloutput[1] != 0)
  338. myrow["firstgoodrate_m"] = Math.Round(totalfirstgood[1] * 100 / totaloutput[1], 2).ToString("##0.00") + "%";
  339. dtqry.Rows.InsertAt(myrow, ++i);
  340. if (i + 1 < dtqry.Rows.Count)
  341. {
  342. a = processcode;
  343. production[1] = 0;
  344. outputweight[1] = 0;
  345. input[1] = 0;
  346. output[1] = 0;
  347. firstgood[1] = 0;
  348. totalproduction[1] = 0;
  349. totaloutputweight[1] = 0;
  350. totalinput[1] = 0;
  351. totaloutput[1] = 0;
  352. totalfirstgood[1] = 0;
  353. }
  354. else if (i + 1 == dtqry.Rows.Count)
  355. break;
  356. }
  357. }
  358. }
  359. }
  360. catch (Exception e)
  361. {
  362. MessageBox.Show(e.Message);
  363. }
  364. finally
  365. {
  366. }
  367. }
  368. }
  369. public override void ToolBar_Click(object sender, string ToolbarKey)
  370. {
  371. base.ToolBar_Click(sender, ToolbarKey);
  372. switch (ToolbarKey)
  373. {
  374. case "Query":
  375. getproductions();
  376. break;
  377. case "Export":
  378. Export();
  379. break;
  380. case "Close":
  381. this.Close();
  382. break;
  383. }
  384. }
  385. private void Export()
  386. {
  387. GridHelper.ulGridToExcel(ultraGrid1, "产量日报");
  388. }
  389. /// <summary>
  390. /// 禁止排序
  391. /// </summary>
  392. /// <param name="ugr"></param>
  393. public void ForbidSort()
  394. {
  395. foreach (UltraGridColumn ugc in ultraGrid1.DisplayLayout.Bands[0].Columns)
  396. {
  397. ugc.SortIndicator = SortIndicator.Disabled;
  398. ugc.AllowRowFiltering = DefaultableBoolean.False;
  399. }
  400. }
  401. /// <summary>
  402. /// 刷新Grid数据并根据数据调整Grid列宽
  403. /// </summary>
  404. /// <param name="ultraGrid">需要处理的Grid</param>
  405. public static void RefreshSetting(Infragistics.Win.UltraWinGrid.UltraGrid ultraGrid,string mydate)
  406. {
  407. try
  408. {
  409. ultraGrid.DataBind();
  410. foreach (Infragistics.Win.UltraWinGrid.UltraGridBand band in ultraGrid.DisplayLayout.Bands)
  411. {
  412. CustomMergedCellEvaluator merge = new CustomMergedCellEvaluator("processcode_area");
  413. //band.Columns["area"].MergedCellEvaluator = merge;
  414. band.Columns["dept"].MergedCellEvaluator = merge;
  415. band.Header.Caption = mydate + "产量日报";
  416. //band.Columns["production"].Format = "{0:##,###.000}";
  417. //band.Columns["totalproduction"].Format = "{0:#,##0.000}";
  418. //band.Columns["firstgoodrate"].Format = "{0:#0.##%}";
  419. //band.Columns["productionrate"].Format = "{0:#0.##%}";
  420. //band.Columns["firstgoodrate_m"].Format = "{0:#0.##%}";
  421. //band.Columns["productionrate_m"].Format = "{0:#0.##%}";
  422. //band.Columns["plinename"].PerformAutoResize(Infragistics.Win.UltraWinGrid.PerformAutoSizeType.AllRowsInBand);
  423. foreach (Infragistics.Win.UltraWinGrid.UltraGridColumn column in band.Columns)
  424. {
  425. column.PerformAutoResize(Infragistics.Win.UltraWinGrid.PerformAutoSizeType.AllRowsInBand);
  426. }
  427. foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in band.GetRowEnumerator(GridRowType.DataRow))
  428. {
  429. if (row.Cells["area"].Text == "合计")
  430. {
  431. row.Cells["area"].Appearance.BackColor = Color.LightYellow;
  432. row.Cells["dept"].Appearance.BackColor = Color.LightYellow;
  433. row.Cells["plinename"].Appearance.BackColor = Color.LightYellow;
  434. row.Cells["production"].Appearance.BackColor = Color.LightYellow;
  435. row.Cells["totalproduction"].Appearance.BackColor = Color.LightYellow;
  436. row.Cells["outputweight"].Appearance.BackColor = Color.LightYellow;
  437. row.Cells["totaloutputweight"].Appearance.BackColor = Color.LightYellow;
  438. if (row.Cells["processcode"].Text != "A")
  439. {
  440. row.Cells["productionrate"].Appearance.BackColor = Color.LightYellow;
  441. row.Cells["productionrate_m"].Appearance.BackColor = Color.LightYellow;
  442. row.Cells["firstgoodrate"].Appearance.BackColor = Color.LightYellow;
  443. row.Cells["firstgoodrate_m"].Appearance.BackColor = Color.LightYellow;
  444. }
  445. }
  446. if (row.Cells["plinename"].Text == "小计")
  447. {
  448. row.Cells["plinename"].Appearance.BackColor = Color.LightYellow;
  449. row.Cells["production"].Appearance.BackColor = Color.LightYellow;
  450. row.Cells["totalproduction"].Appearance.BackColor = Color.LightYellow;
  451. row.Cells["outputweight"].Appearance.BackColor = Color.LightYellow;
  452. row.Cells["totaloutputweight"].Appearance.BackColor = Color.LightYellow;
  453. if (row.Cells["processcode"].Text != "A")
  454. {
  455. row.Cells["productionrate"].Appearance.BackColor = Color.LightYellow;
  456. row.Cells["productionrate_m"].Appearance.BackColor = Color.LightYellow;
  457. row.Cells["firstgoodrate"].Appearance.BackColor = Color.LightYellow;
  458. row.Cells["firstgoodrate_m"].Appearance.BackColor = Color.LightYellow;
  459. }
  460. }
  461. if (row.Cells["dept"].Text == "小计")
  462. {
  463. row.Cells["dept"].Appearance.BackColor = Color.LemonChiffon;
  464. row.Cells["plinename"].Appearance.BackColor = Color.LemonChiffon;
  465. row.Cells["production"].Appearance.BackColor = Color.LemonChiffon;
  466. row.Cells["totalproduction"].Appearance.BackColor = Color.LemonChiffon;
  467. row.Cells["outputweight"].Appearance.BackColor = Color.LemonChiffon;
  468. row.Cells["totaloutputweight"].Appearance.BackColor = Color.LemonChiffon;
  469. if (row.Cells["processcode"].Text != "A")
  470. {
  471. row.Cells["productionrate"].Appearance.BackColor = Color.LemonChiffon;
  472. row.Cells["productionrate_m"].Appearance.BackColor = Color.LemonChiffon;
  473. row.Cells["firstgoodrate"].Appearance.BackColor = Color.LemonChiffon;
  474. row.Cells["firstgoodrate_m"].Appearance.BackColor = Color.LemonChiffon;
  475. }
  476. }
  477. //if (row.Cells["production"].Text != "")
  478. //{
  479. // row.Cells["production"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Button;
  480. // row.Cells["production"].ButtonAppearance.Cursor = Cursors.Hand;
  481. //}
  482. //if (row.Cells["outputweight"].Text != "")
  483. //{
  484. // row.Cells["outputweight"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Button;
  485. // row.Cells["outputweight"].ButtonAppearance.Cursor = Cursors.Hand;
  486. //}
  487. }
  488. }
  489. ultraGrid.Refresh();
  490. }
  491. catch { }
  492. }
  493. public class CustomMergedCellEvaluator : Infragistics.Win.UltraWinGrid.IMergedCellEvaluator
  494. {
  495. private string primaryKey;
  496. ///
  497. /// 获取或设置合并列的主键列的绑定名称
  498. ///
  499. public string PrimaryKey
  500. {
  501. get { return primaryKey; }
  502. set { primaryKey = value; }
  503. }
  504. ///
  505. /// CustomMergedCellEvaluator 的构造函数
  506. ///
  507. /// 主键列的绑定名称
  508. public CustomMergedCellEvaluator(string primaryKey)
  509. {
  510. this.primaryKey = primaryKey;
  511. }
  512. #region IMergedCellEvaluator 成员
  513. public bool ShouldCellsBeMerged(Infragistics.Win.UltraWinGrid.UltraGridRow row1, Infragistics.Win.UltraWinGrid.UltraGridRow row2, Infragistics.Win.UltraWinGrid.UltraGridColumn column)
  514. {
  515. //确认逻辑:如果是主键列,自动合并,否则通过联合主键来合并
  516. if (column.MergedCellStyle == Infragistics.Win.UltraWinGrid.MergedCellStyle.Always)
  517. {
  518. if (string.IsNullOrEmpty(this.primaryKey))
  519. {
  520. return row1.GetCellText(column) == row2.GetCellText(column);
  521. }
  522. if ((row1.GetCellValue(row1.Cells[this.primaryKey].Column).ToString() == row2.GetCellValue(row1.Cells[this.primaryKey].Column).ToString()) && (row1.GetCellText(column) == row2.GetCellText(column)))
  523. {
  524. return true;
  525. }
  526. }
  527. return false;
  528. }
  529. #endregion
  530. }
  531. private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
  532. {
  533. UltraGridBand band = e.Layout.Bands[0];
  534. CustomMergedCellEvaluator merge = new CustomMergedCellEvaluator("processcode_area");
  535. //e.Layout.Bands[1].Columns["OrderCode"].MergedCellStyle = MergedCellStyle.Always;
  536. band.Columns["area"].MergedCellEvaluator = merge;
  537. //foreach (Infragistics.Win.UltraWinGrid.UltraGridColumn column in band.Columns)
  538. //{
  539. // column.PerformAutoResize(Infragistics.Win.UltraWinGrid.PerformAutoSizeType.AllRowsInBand);
  540. //}
  541. //band.PerformAutoResizeColumns(true, PerformAutoSizeType.VisibleRows);
  542. band.Columns["production"].Format = "{0:F ##,###.000}";
  543. band.Columns["totalproduction"].Format = "0:F ##,###.000";
  544. band.Columns["firstgoodrate"].Format = "0:F #####.00%";
  545. band.Columns["productionrate"].Format = "{0:F #####.00%}";
  546. band.Columns["firstgoodrate_m"].Format = "{0:F #####.00%}";
  547. band.Columns["productionrate_m"].Format = "{0:F #####.00%}";
  548. }
  549. private void ultraGrid1_BeforeRowExpanded(object sender, CancelableRowEventArgs e)
  550. {
  551. UltraGridBand band = ultraGrid1.DisplayLayout.Bands[0];
  552. foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in band.GetRowEnumerator(GridRowType.DataRow))
  553. {
  554. if (row.IsExpanded && row.Index != e.Row.Index)
  555. row.Expanded = false;
  556. }
  557. if (e.Row.Cells["plinename"].Text != "")
  558. getproduction_detail(e.Row.Cells["processcode"].Text, e.Row.Cells["plinename"].Text);
  559. }
  560. private void getproduction_detail(string processcode,string plinename)
  561. {
  562. WaitingForm2 wf = new WaitingForm2("正在加载数据,请稍候....");
  563. try
  564. {
  565. string mydate = ((DateTime)this.rptdate.Value).ToString("yyyy-MM-dd");
  566. string sqlid = "com.steering.rpt.production.TotalProduction.getQuantityA_detail";
  567. switch (processcode)
  568. {
  569. case "A":
  570. sqlid = "com.steering.rpt.production.TotalProduction.getQuantityA_detail";
  571. break;
  572. case "B":
  573. sqlid = "com.steering.rpt.production.TotalProduction.getQuantityB_detail";
  574. break;
  575. case "D":
  576. sqlid = "com.steering.rpt.production.TotalProduction.getQuantityD_detail";
  577. break;
  578. case "E":
  579. sqlid = "com.steering.rpt.production.TotalProduction.getQuantityE_detail";
  580. break;
  581. case "F":
  582. sqlid = "com.steering.rpt.production.TotalProduction.getQuantityF_detail";
  583. break;
  584. case "G":
  585. sqlid = "com.steering.rpt.production.TotalProduction.getQuantityG_detail";
  586. break;
  587. }
  588. DataTable dtqry = ServerHelper.GetData(sqlid, new object[] { mydate, plinename }, this.ob);
  589. dtqry.Columns.Add("processpline_d", Type.GetType("System.String"));
  590. foreach (DataRow myrow in dtqry.Rows)
  591. {
  592. myrow["processpline_d"] = myrow["processcode_d"].ToString() + myrow["plinename_d"].ToString();
  593. }
  594. GridHelper.CopyDataToDatatable(ref dtqry, ref this.dataTable2, true);
  595. //RefreshSetting(ultraGrid1);
  596. wf.Close();
  597. }
  598. catch (Exception e)
  599. {
  600. MessageBox.Show(e.Message);
  601. }
  602. finally
  603. {
  604. wf.Close();
  605. }
  606. }
  607. private void ultraGrid1_ClickCellButton(object sender, CellEventArgs e)
  608. {
  609. }
  610. }
  611. }