FrmGXElements.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. using Core.Mes.Client.Comm.Control;
  2. using Core.Mes.Client.Comm.Server;
  3. using Core.Mes.Client.Comm.Tool;
  4. using CoreFS.CA06;
  5. using Infragistics.Win.UltraWinGrid;
  6. using System;
  7. using System.Collections;
  8. using System.Data;
  9. using System.Drawing;
  10. using System.Windows.Forms;
  11. namespace Core.StlMes.Client.PlnSaleOrd
  12. {
  13. public partial class FrmGXElements : FrmBase
  14. {
  15. public FrmGXElements()
  16. {
  17. InitializeComponent();
  18. ExceptionHelper.RegistException();
  19. }
  20. private void FrmGXElements_Load(object sender, EventArgs e)
  21. {
  22. //bindcmbStyle();
  23. //this.ultraComboEditor1.SelectedIndex = 0;
  24. //this.cmbStyle.SelectedIndex = 0;
  25. }
  26. /// <summary>
  27. /// 重写基类方法
  28. /// </summary>
  29. /// <param name="sender"></param>
  30. /// <param name="ToolbarKey"></param>
  31. public override void ToolBar_Click(object sender, string ToolbarKey)
  32. {
  33. switch (ToolbarKey)
  34. {
  35. case "doQuery":
  36. doQuery();
  37. break;
  38. case "doAdd":
  39. doAdd();
  40. break;
  41. case "doModify":
  42. doModify();
  43. break;
  44. case "doDelete":
  45. this.doDeleteOrResume(true);
  46. break;
  47. case "doResume":
  48. this.doDeleteOrResume(false);
  49. break;
  50. case "Export":
  51. this.ExportData();
  52. break;
  53. case "Close":
  54. this.Close();
  55. break;
  56. }
  57. }
  58. /// <summary>
  59. /// 新增
  60. /// </summary>
  61. private void doAdd()
  62. {
  63. //验证描述不允许重复。
  64. string CODE = GX_CODE.Text.Trim();
  65. if (isRepeatCode(CODE))
  66. {
  67. MessageBox.Show("高新编码\"" + CODE + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  68. return;
  69. }
  70. if (MessageUtil.ShowYesNoAndQuestion("是否确认新增?") == DialogResult.No) return;
  71. ArrayList parm = new ArrayList();
  72. //string chenCode = AutoCode(this.dataTable1);
  73. parm.Add(CODE);
  74. parm.Add(GX_NAME.Text.ToString2());
  75. parm.Add(GX_YEAR.Text.ToString2());
  76. parm.Add(this.UserInfo.GetUserName());
  77. parm.Add(GX_Memo.Text);
  78. parm.Add(GX_YFFY.Text.ToString2());
  79. parm.Add(GX_FZR.Text.ToString2());
  80. CoreClientParam ccp = new CoreClientParam();
  81. ccp.ServerName = "com.steering.pss.plnsaleord.GpOptimize.CorePlnZgMStoGp";
  82. ccp.MethodName = "doAdd";
  83. ccp.ServerParams = new object[] { parm };
  84. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  85. if (ccp.ReturnCode == -1)
  86. {
  87. return;
  88. }
  89. MessageUtil.ShowTips("新增成功!");
  90. doQuery();
  91. //高亮显示新增的数据
  92. //Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  93. //for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  94. //{
  95. // row = ultraGrid2.Rows[i];
  96. // if (row.Cells["CHEM_CODE"].Value.ToString().Equals(chenCode))
  97. // {
  98. // row.Activate();
  99. // break;
  100. // }
  101. //}
  102. }
  103. ///// <summary>
  104. ///// 获取Table中最大编号,自增1返回。
  105. ///// </summary>
  106. ///// <param name="dt"></param>
  107. ///// <returns></returns>
  108. //private static string AutoCode(DataTable dt)
  109. //{
  110. // int maxCode = 0;
  111. // //substring去除S001中的S,得到001。
  112. // string maxCodeString = dt.Rows[0][0].ToString().Substring(1);
  113. // //是否为数字
  114. // if (StringUtil.IsNumber(maxCodeString))
  115. // {
  116. // maxCode = Convert.ToInt32(maxCodeString);
  117. // }
  118. // else
  119. // {
  120. // MessageBox.Show("传入编号格式有误,请查看代码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  121. // }
  122. // //比较得出最大id。
  123. // for (int i = 1; i < dt.Rows.Count; i++)
  124. // {
  125. // string maxCodeString_Two = dt.Rows[i][0].ToString().Substring(1);
  126. // int maxCode_Two = 0;
  127. // if (StringUtil.IsNumber(maxCodeString_Two))
  128. // {
  129. // maxCode_Two = Convert.ToInt32(maxCodeString_Two);
  130. // if (maxCode_Two > maxCode)
  131. // {
  132. // maxCode = maxCode_Two;
  133. // }
  134. // }
  135. // }
  136. // //新增行
  137. // maxCode += 1;
  138. // string codeTop = "";
  139. // if (maxCode < 10)
  140. // {
  141. // codeTop = "00";
  142. // }
  143. // else if (maxCode < 100)
  144. // {
  145. // codeTop = "0";
  146. // }
  147. // //获取头文字D。
  148. // string d = dt.Rows[0][0].ToString().Substring(0, 1);
  149. // //头文字+0+最大数字
  150. // string newCode = d + codeTop + maxCode;
  151. // return newCode;
  152. //}
  153. /// <summary>
  154. /// 验证高新编码是否重复。
  155. /// </summary>
  156. /// <param name="code"></param>
  157. /// <returns></returns>
  158. private bool isRepeatCode(string code)
  159. {
  160. DataTable dt = new DataTable();
  161. dt = ServerHelper.GetData("com.steering.pss.plnsaleord.GpOptimize.CorePlnZgMStoGp.GetCode", new Object[] { code }, this.ob);
  162. if (dt.Rows.Count > 0)
  163. {
  164. return true;
  165. }
  166. else
  167. {
  168. return false;
  169. }
  170. }
  171. /// <summary>
  172. /// 用于验证修改时,描述是否已存在
  173. /// </summary>
  174. private static string VName = "";
  175. /// <summary>
  176. /// 修改
  177. /// </summary>
  178. private void doModify()
  179. {
  180. if (ultraGrid2.ActiveRow == null)
  181. {
  182. MessageBox.Show("请选择需要修改的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  183. return;
  184. }
  185. string validflagStr = ultraGrid2.ActiveRow.Cells["VALIDFLAG"].Value.ToString();
  186. //无效数据不允许修改
  187. if ("0".Equals(validflagStr))
  188. {
  189. MessageBox.Show("无效数据不支持修改操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  190. return;
  191. }
  192. ////验证高新编码不允许重复。
  193. string CODE = GX_CODE.Text.Trim();
  194. //if (!VName.Equals(CODE))
  195. //{
  196. // if (isRepeatCode(CODE))
  197. // {
  198. // MessageBox.Show("高新编码\"" + CODE + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  199. // return;
  200. // }
  201. //}
  202. //确认修改吗?
  203. if (MessageBox.Show("是否确认修改选中的数据!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  204. {
  205. return;
  206. }
  207. ArrayList parm = new ArrayList();
  208. // string chenCode = ultraGrid2.ActiveRow.Cells["CHEM_CODE"].Value.ToString();
  209. parm.Add(GX_NAME.Text.ToString2());
  210. parm.Add(GX_YEAR.Text.ToString2());
  211. parm.Add(this.UserInfo.GetUserName());
  212. parm.Add(GX_Memo.Text);
  213. parm.Add(GX_YFFY.Text.ToString2());
  214. parm.Add(GX_FZR.Text.ToString2());
  215. parm.Add(CODE);
  216. CoreClientParam ccp = new CoreClientParam();
  217. //ccp.ServerName = "com.steering.pss.qcm.CoreChemistryElements";
  218. ccp.ServerName = "com.steering.pss.plnsaleord.GpOptimize.CorePlnZgMStoGp";
  219. ccp.MethodName = "doModify";
  220. ccp.ServerParams = new object[] { parm };
  221. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  222. if (ccp.ReturnCode == -1) return;
  223. MessageUtil.ShowTips("修改成功!");
  224. doQuery();
  225. //高亮显示新增的数据
  226. Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  227. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  228. {
  229. row = ultraGrid2.Rows[i];
  230. if (row.Cells["GX_CODE"].Value.ToString().Equals(CODE))
  231. {
  232. row.Activate();
  233. break;
  234. }
  235. }
  236. }
  237. /// <summary>
  238. /// 查询
  239. /// </summary>
  240. private void doQuery()
  241. {
  242. bool validFlag = chkValid.Checked;
  243. string titleName = txtTitleName.Text.Trim();
  244. DataTable dt = ServerHelper.GetData("com.steering.pss.plnsaleord.GpOptimize.CorePlnZgMStoGp.getGXList", new Object[] { validFlag, titleName }, this.ob);
  245. GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, true);
  246. //不同颜色区分是否有效数据
  247. Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  248. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  249. {
  250. row = ultraGrid2.Rows[i];
  251. if (!row.Cells["VALIDFLAG"].Value.ToString().Equals("1"))
  252. {
  253. row.Appearance.ForeColor = Color.Red;
  254. }
  255. else
  256. {
  257. row.Appearance.ForeColor = Color.Black;
  258. }
  259. }
  260. SetStaticsInfo();
  261. //列自适应
  262. GridHelper.RefreshAndAutoSizeExceptRows(ultraGrid2, new UltraGridColumn[] {
  263. ultraGrid2.DisplayLayout.Bands[0].Columns["MEMO"]
  264. });
  265. }
  266. /// <summary>
  267. /// GRID ROW激活时信息带至编辑区
  268. /// </summary>
  269. /// <param name="sender"></param>
  270. /// <param name="e"></param>
  271. private void ultraGrid2_AfterRowActivate(object sender, EventArgs e)
  272. {
  273. Infragistics.Win.UltraWinGrid.UltraGridRow row = ultraGrid2.ActiveRow;
  274. if (row != null)
  275. {
  276. GX_CODE.Text = row.Cells["GX_CODE"].Value.ToString();
  277. GX_NAME.Text = row.Cells["GX_NAME"].Value.ToString();
  278. GX_YEAR.Text = row.Cells["GX_TIME"].Value.ToString();
  279. GX_Memo.Text = row.Cells["MEMO"].Value.ToString();
  280. GX_YFFY.Text = row.Cells["GX_YFFY"].Value.ToString();
  281. GX_FZR.Text = row.Cells["GX_FZR"].Value.ToString();
  282. }
  283. }
  284. /// <summary>
  285. /// 导出
  286. /// </summary>
  287. private void ExportData()
  288. {
  289. GridHelper.ulGridToExcel(ultraGrid2, "高新项目管理");
  290. }
  291. private void SetStaticsInfo()
  292. {
  293. try
  294. {
  295. if (this.ultraGrid2.Rows.Count == 0)
  296. {
  297. this.ultraGrid2.DisplayLayout.Bands[0].Summaries.Clear();
  298. }
  299. else
  300. {
  301. ArrayList alist = new ArrayList();
  302. alist.Add("GX_YFFY");
  303. SetStaticsInfoSum(ref this.ultraGrid2, alist, true);
  304. }
  305. }
  306. catch { }
  307. }
  308. public static void SetStaticsInfoSum(ref UltraGrid myGrid1, ArrayList alistColumns, bool clearExists)
  309. {
  310. try
  311. {
  312. UltraGridBand band = myGrid1.DisplayLayout.Bands[0];
  313. if (clearExists)
  314. band.Summaries.Clear();
  315. band.Override.SummaryFooterCaptionVisible = Infragistics.Win.DefaultableBoolean.False;
  316. for (int i = 0; i < alistColumns.Count; i++)
  317. {
  318. try
  319. {
  320. SummarySettings summary = band.Summaries.Add(SummaryType.Sum, band.Columns[alistColumns[i].ToString()]);
  321. summary.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed;
  322. summary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
  323. if (alistColumns[i].ToString().Contains("COUNT"))
  324. {
  325. summary.DisplayFormat = "{0:N0}";
  326. }
  327. else
  328. {
  329. summary.DisplayFormat = "{0:N3}";
  330. }
  331. summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Right;
  332. summary.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle;
  333. // summary.Appearance.FontData.Bold = DefaultableBoolean.True;
  334. summary.Lines = 3;
  335. }
  336. catch { }
  337. }
  338. }
  339. catch { }
  340. }
  341. /// <summary>
  342. /// 作废或恢复
  343. /// </summary>
  344. /// <param name="isDelete">true作废 false恢复</param>
  345. private void doDeleteOrResume(bool isDelete)
  346. {
  347. if (ultraGrid2.ActiveRow == null)
  348. {
  349. MessageBox.Show("请选择需要" + (isDelete ? "作废" : "恢复") + "的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  350. return;
  351. }
  352. string validflagStr = ultraGrid2.ActiveRow.Cells["VALIDFLAG"].Value.ToString();
  353. //无效数据不允许作废
  354. if ("0".Equals(validflagStr))
  355. {
  356. if (isDelete)
  357. {
  358. MessageBox.Show("无效数据不支持作废操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  359. return;
  360. }
  361. }
  362. else
  363. {
  364. //有效数据不允许恢复
  365. if (!isDelete)
  366. {
  367. MessageBox.Show("有效数据不支持恢复操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  368. return;
  369. }
  370. }
  371. ArrayList param = new ArrayList();
  372. string CODE = ultraGrid2.ActiveRow.Cells["GX_CODE"].Value.ToString();
  373. param.Add(CODE);
  374. if (param.Count > 0 && MessageBox.Show("是否确认" + (isDelete ? "作废" : "恢复") + "选中的数据!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  375. {
  376. int count = ServerHelper.SetData("com.steering.pss.plnsaleord.GpOptimize.CorePlnZgMStoGp.deleteLineInfo", new Object[] { param, UserInfo.GetUserName(), isDelete }, this.ob);
  377. if (count > 0)
  378. {
  379. MessageUtil.ShowTips((isDelete ? "作废" : "恢复") + "成功!");
  380. doQuery();
  381. Infragistics.Win.UltraWinGrid.UltraGridRow rowD = null;
  382. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  383. {
  384. rowD = ultraGrid2.Rows[i];
  385. if (rowD.Cells["GX_CODE"].Value.ToString().Equals(CODE))
  386. {
  387. rowD.Activate();
  388. break;
  389. }
  390. }
  391. }
  392. }
  393. }
  394. }
  395. }