FrmSteelGrade.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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.Qcm
  12. {
  13. public partial class FrmSteelGrade : FrmBase
  14. {
  15. public FrmSteelGrade()
  16. {
  17. InitializeComponent();
  18. }
  19. private void FrmSteelGrade_Load(object sender, EventArgs e)
  20. {
  21. cmbGradeType.SelectedIndex = 0;
  22. }
  23. /// <summary>
  24. /// 重写基类方法
  25. /// </summary>
  26. /// <param name="sender"></param>
  27. /// <param name="ToolbarKey"></param>
  28. public override void ToolBar_Click(object sender, string ToolbarKey)
  29. {
  30. switch (ToolbarKey)
  31. {
  32. case "doQuery":
  33. try
  34. {
  35. this.Cursor = Cursors.WaitCursor;
  36. doQuery();
  37. }
  38. finally
  39. {
  40. this.Cursor = Cursors.Default;
  41. }
  42. break;
  43. case "doAdd":
  44. doAdd();
  45. break;
  46. case "doModify":
  47. doModify();
  48. break;
  49. case "doDelete":
  50. this.doDeleteOrResume(true);
  51. break;
  52. case "doResume":
  53. this.doDeleteOrResume(false);
  54. break;
  55. case "Export":
  56. GridHelper.ulGridToExcel(ultraGrid2, "钢级信息");
  57. break;
  58. case "Close":
  59. this.Close();
  60. break;
  61. }
  62. }
  63. /// <summary>
  64. /// 非空项验证
  65. /// </summary>
  66. /// <returns></returns>
  67. private bool ValidInput()
  68. {
  69. if (string.IsNullOrEmpty(txtName.Text.Trim()))
  70. {
  71. MessageBox.Show("请输入钢级或牌号描述!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  72. return false;
  73. }
  74. if (ultraComboEditor1.Value.ToString2() == "")
  75. {
  76. MessageBox.Show("请选择是否TP系列!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  77. return false;
  78. }
  79. return true;
  80. }
  81. /// <summary>
  82. /// 获取钢级牌号代码最大值
  83. /// </summary>
  84. /// <returns></returns>
  85. private string GetMaxCode()
  86. {
  87. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreSteelGrade.GetMaxCode", null, this.ob);
  88. string maxCode = "";
  89. if (dt.Rows.Count > 0)
  90. {
  91. if (!"".Equals(dt.Rows[0][0].ToString()))
  92. {
  93. maxCode = dt.Rows[0][0].ToString();
  94. }
  95. else
  96. {
  97. maxCode = "C000";
  98. }
  99. }
  100. return maxCode;
  101. }
  102. /// <summary>
  103. /// 验证描述是否重复。
  104. /// </summary>
  105. /// <param name="name"></param>
  106. /// <returns></returns>
  107. private bool isRepeatName(string name)
  108. {
  109. DataTable dt = new DataTable();
  110. dt = ServerHelper.GetData("com.steering.pss.qcm.CoreSteelGrade.GetName", new Object[] { name }, this.ob);
  111. if (dt.Rows.Count > 0)
  112. {
  113. return true;
  114. }
  115. else
  116. {
  117. return false;
  118. }
  119. }
  120. /// <summary>
  121. /// 新增
  122. /// </summary>
  123. private void doAdd()
  124. {
  125. if (ValidInput())
  126. {
  127. //验证描述不允许重复。
  128. string name = txtName.Text.Trim();
  129. if (isRepeatName(name))
  130. {
  131. MessageBox.Show("钢级\\牌号描述\"" + name + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  132. return;
  133. }
  134. try
  135. {
  136. ArrayList parm = new ArrayList();
  137. //string chenCode = GridHelper.AutoCode(this.dataTable1);
  138. //自动生成编号
  139. string chenCode = StringUtil.SequenceIncrease(GetMaxCode());
  140. parm.Add(chenCode);
  141. parm.Add(name);
  142. parm.Add(cmbGradeType.Value);
  143. parm.Add(this.UserInfo.GetUserName());
  144. parm.Add(txtMemo.Text);
  145. parm.Add(ultraComboEditor1.Value.ToString2());
  146. CoreClientParam ccp = new CoreClientParam();
  147. ccp.ServerName = "com.steering.pss.qcm.CoreSteelGrade";
  148. ccp.MethodName = "doAdd";
  149. ccp.ServerParams = new object[] { parm };
  150. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  151. if (ccp.ReturnCode == -1) return;
  152. doQuery();
  153. //高亮显示新增的数据
  154. Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  155. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  156. {
  157. row = ultraGrid2.Rows[i];
  158. if (row.Cells["STEELCODE"].Value.ToString().Equals(chenCode))
  159. {
  160. row.Activate();
  161. break;
  162. }
  163. }
  164. }
  165. catch (Exception ex)
  166. {
  167. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  168. }
  169. }
  170. }
  171. /// <summary>
  172. /// 修改
  173. /// </summary>
  174. private void doModify()
  175. {
  176. if (ultraGrid2.ActiveRow == null)
  177. {
  178. MessageBox.Show("请选择需要修改的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  179. return;
  180. }
  181. string validflagStr = ultraGrid2.ActiveRow.Cells["VALIDFLAG"].Value.ToString();
  182. //无效数据不允许修改
  183. if ("0".Equals(validflagStr))
  184. {
  185. MessageBox.Show("无效数据不支持修改操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  186. return;
  187. }
  188. //正式用时 需要打开此段注释
  189. string s1 = ultraGrid2.ActiveRow.GetValue("STEELNAME");
  190. string s2 = ultraGrid2.ActiveRow.GetValue("STEELSTYLE");
  191. if (txtName.Text.Trim() != ultraGrid2.ActiveRow.GetValue("STEELNAME") || cmbGradeType.Value.ToString2() != ultraGrid2.ActiveRow.GetValue("STEELSTYLE"))
  192. {
  193. DataTable dt1 = ServerHelper.GetData("com.steering.pss.qcm.CoreSteelGrade.getPsc", new object[] { ultraGrid2.ActiveRow.Cells["STEELCODE"].Value.ToString() }, this.ob);
  194. if (dt1 != null && dt1.Rows.Count > 0)
  195. {
  196. MessageUtil.ShowWarning("此钢级/牌号已被产品规范码引用,不能修改!");
  197. return;
  198. }
  199. }
  200. if (ValidInput())
  201. {
  202. //验证描述不允许重复。
  203. string name = txtName.Text.Trim();
  204. if (!VName.Equals(name))
  205. {
  206. if (isRepeatName(name))
  207. {
  208. MessageBox.Show("钢级\\牌号描述\"" + name + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  209. return;
  210. }
  211. }
  212. //确认修改吗?
  213. if (MessageBox.Show("是否确认修改选中的数据!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  214. {
  215. return;
  216. }
  217. ArrayList parm = new ArrayList();
  218. string chenCode = ultraGrid2.ActiveRow.Cells["STEELCODE"].Value.ToString();
  219. parm.Add(name);
  220. parm.Add(cmbGradeType.Value);
  221. parm.Add(this.UserInfo.GetUserName());
  222. parm.Add(txtMemo.Text);
  223. parm.Add(ultraComboEditor1.Value.ToString2());
  224. parm.Add(chenCode);
  225. CoreClientParam ccp = new CoreClientParam();
  226. ccp.ServerName = "com.steering.pss.qcm.CoreSteelGrade";
  227. ccp.MethodName = "doModify";
  228. ccp.ServerParams = new object[] { parm };
  229. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  230. if (ccp.ReturnCode == -1) return;
  231. doQuery();
  232. //高亮显示新增的数据
  233. Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  234. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  235. {
  236. row = ultraGrid2.Rows[i];
  237. if (row.Cells["STEELCODE"].Value.ToString().Equals(chenCode))
  238. {
  239. row.Activate();
  240. break;
  241. }
  242. }
  243. }
  244. }
  245. /// <summary>
  246. /// 查询
  247. /// </summary>
  248. private void doQuery()
  249. {
  250. bool validFlag = chkValid.Checked;
  251. string titleName = "";
  252. if (ultraCheckEditor1.Checked)
  253. {
  254. titleName = txtTitleName.Text.Trim();
  255. }
  256. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreSteelGrade.getLineList", new Object[] { validFlag, titleName }, this.ob);
  257. GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, true);
  258. //不同颜色区分是否有效数据
  259. Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  260. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  261. {
  262. row = ultraGrid2.Rows[i];
  263. if (!row.Cells["VALIDFLAG"].Value.ToString().Equals("1"))
  264. {
  265. row.Appearance.ForeColor = Color.Red;
  266. }
  267. else
  268. {
  269. row.Appearance.ForeColor = Color.Black;
  270. }
  271. }
  272. //列自适应
  273. GridHelper.RefreshAndAutoSizeExceptRows(ultraGrid2, new UltraGridColumn[] {
  274. ultraGrid2.DisplayLayout.Bands[0].Columns["MEMO"]
  275. });
  276. }
  277. /// <summary>
  278. /// 用于验证修改时,描述是否已存在
  279. /// </summary>
  280. private static string VName = "";
  281. /// <summary>
  282. /// GRID ROW激活时信息带至编辑区
  283. /// </summary>
  284. /// <param name="sender"></param>
  285. /// <param name="e"></param>
  286. private void ultraGrid2_AfterRowActivate(object sender, EventArgs e)
  287. {
  288. Infragistics.Win.UltraWinGrid.UltraGridRow row = ultraGrid2.ActiveRow;
  289. if (row != null)
  290. {
  291. //STEELCODE,STEELNAME,STEELSTYLE
  292. txtName.Text = row.Cells["STEELNAME"].Value.ToString();
  293. VName = txtName.Text.Trim();
  294. cmbGradeType.Value = row.Cells["STEELSTYLE"].Value.ToString();
  295. txtMemo.Text = row.Cells["MEMO"].Value.ToString();
  296. ultraComboEditor1.Value = row.GetValue("IS_TP");
  297. }
  298. }
  299. /// <summary>
  300. /// 作废或恢复
  301. /// </summary>
  302. /// <param name="isDelete">true作废 false恢复</param>
  303. private void doDeleteOrResume(bool isDelete)
  304. {
  305. if (ultraGrid2.ActiveRow == null)
  306. {
  307. MessageBox.Show("请选择需要" + (isDelete ? "作废" : "恢复") + "的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  308. return;
  309. }
  310. string validflagStr = ultraGrid2.ActiveRow.Cells["VALIDFLAG"].Value.ToString();
  311. //无效数据不允许作废
  312. if ("0".Equals(validflagStr))
  313. {
  314. if (isDelete)
  315. {
  316. MessageBox.Show("无效数据不支持作废操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  317. return;
  318. }
  319. }
  320. else
  321. {
  322. //有效数据不允许恢复
  323. if (!isDelete)
  324. {
  325. MessageBox.Show("有效数据不支持恢复操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  326. return;
  327. }
  328. }
  329. ArrayList param = new ArrayList();
  330. string steelCode = ultraGrid2.ActiveRow.Cells["STEELCODE"].Value.ToString();
  331. param.Add(steelCode);
  332. if (param.Count > 0 && MessageBox.Show("是否确认" + (isDelete ? "作废" : "恢复") + "选中的数据!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  333. {
  334. try
  335. {
  336. int count = ServerHelper.SetData("com.steering.pss.qcm.CoreSteelGrade.deleteLineInfo", new Object[] { param, UserInfo.GetUserName(), isDelete }, this.ob);
  337. if (count > 0)
  338. {
  339. doQuery();
  340. Infragistics.Win.UltraWinGrid.UltraGridRow rowD = null;
  341. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  342. {
  343. rowD = ultraGrid2.Rows[i];
  344. if (rowD.Cells["STEELCODE"].Value.ToString().Equals(steelCode))
  345. {
  346. rowD.Activate();
  347. break;
  348. }
  349. }
  350. }
  351. }
  352. catch (Exception ex)
  353. {
  354. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  355. }
  356. }
  357. }
  358. private void ultraCheckEditor1_CheckedChanged(object sender, EventArgs e)
  359. {
  360. if (ultraCheckEditor1.Checked)
  361. {
  362. txtTitleName.ReadOnly = false;
  363. }
  364. else
  365. {
  366. txtTitleName.ReadOnly = true;
  367. }
  368. }
  369. }
  370. }