frmSpeclLine.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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.CA03;
  10. using CoreFS.CA04;
  11. using CoreFS.CA06;
  12. using System.Collections;
  13. using Infragistics.Win.UltraWinGrid;
  14. using Core.Mes.Client.Comm.Server;
  15. using Core.Mes.Client.Comm.Control;
  16. using Core.Mes.Client.Comm.Tool;
  17. namespace Core.StlMes.Client.SaleBase
  18. {
  19. public partial class frmSpeclLine : FrmBase
  20. {
  21. public frmSpeclLine()
  22. {
  23. InitializeComponent();
  24. }
  25. /// <summary>
  26. /// 重写基类方法
  27. /// </summary>
  28. /// <param name="sender"></param>
  29. /// <param name="ToolbarKey"></param>
  30. public override void ToolBar_Click(object sender, string ToolbarKey)
  31. {
  32. switch (ToolbarKey)
  33. {
  34. case "doQuery":
  35. doQuery();
  36. break;
  37. case "doAdd":
  38. doAdd();
  39. break;
  40. case "doUpdate":
  41. doUpdate();
  42. break;
  43. case "doDelete":
  44. this.doDeleteOrRecovery(true);
  45. break;
  46. case "doRecovery":
  47. this.doDeleteOrRecovery(false);
  48. break;
  49. case "doClose":
  50. this.Close();
  51. break;
  52. }
  53. }
  54. private void frmSpeclLine_Load(object sender, EventArgs e)
  55. {
  56. BindCmbStationName();
  57. cmbStationName.SelectedIndex = 0;
  58. doQuery();
  59. }
  60. protected override void OnLoad(EventArgs e)
  61. {
  62. try
  63. {
  64. base.OnLoad(e);
  65. ultraGrid2.DisplayLayout.Override.FilterUIType = Infragistics.Win.UltraWinGrid.FilterUIType.FilterRow;
  66. ultraGrid2.DisplayLayout.Override.FilterOperatorDefaultValue = Infragistics.Win.UltraWinGrid.FilterOperatorDefaultValue.Contains;
  67. //ultraGrid2.DisplayLayout.Override.CellClickAction = Infragistics.Win.UltraWinGrid.CellClickAction.RowSelect;
  68. }
  69. catch (System.Exception ex)
  70. { }
  71. }
  72. /// <summary>
  73. /// 绑定到站信息
  74. /// </summary>
  75. private void BindCmbStationName()
  76. {
  77. cmbStationName.Items.Clear();
  78. DataTable dt = ServerHelper.GetData("com.steering.pss.sale.base.CoreSpeclLine.GetStation", null, this.ob);
  79. ComboBoxHelper.FillUlcmItemsAddEmpty(cmbStationName, dt);
  80. }
  81. /// <summary>
  82. /// 专用线条件是否可编辑
  83. /// </summary>
  84. /// <param name="sender"></param>
  85. /// <param name="e"></param>
  86. private void uceIsName_CheckedChanged(object sender, EventArgs e)
  87. {
  88. if (uceIsName.Checked)
  89. {
  90. txtSpeclLineTitle.Enabled = true;
  91. }
  92. else
  93. {
  94. txtSpeclLineTitle.Enabled = false;
  95. }
  96. }
  97. /// <summary>
  98. /// 查询
  99. /// </summary>
  100. private void doQuery()
  101. {
  102. bool validFlag = chkValid.Checked;
  103. string titleName = txtSpeclLineTitle.Text.Trim();
  104. DataTable dt = ServerHelper.GetData("com.steering.pss.sale.base.CoreSpeclLine.doQuery", new Object[] { validFlag, titleName }, this.ob);
  105. GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, true);
  106. //不同颜色区分是否有效数据
  107. Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  108. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  109. {
  110. row = ultraGrid2.Rows[i];
  111. if (!row.Cells["VALIDFLAG"].Value.ToString().Equals("1"))
  112. {
  113. row.Cells["VALIDFLAG"].Value = false;
  114. row.Appearance.ForeColor = Color.Red;
  115. }
  116. else
  117. {
  118. row.Cells["VALIDFLAG"].Value = true;
  119. row.Appearance.ForeColor = Color.Black;
  120. }
  121. }
  122. //列自适应
  123. GridHelper.RefreshAndAutoSizeExceptRows(ultraGrid2, new UltraGridColumn[] {
  124. ultraGrid2.DisplayLayout.Bands[0].Columns["MEMO"]
  125. });
  126. }
  127. /// <summary>
  128. /// 验证非空字段。
  129. /// </summary>
  130. /// <returns></returns>
  131. private bool ValidInput()
  132. {
  133. if (string.IsNullOrEmpty(txtSpeclLineName.Text.Trim()))
  134. {
  135. MessageBox.Show("请输入专用线名称!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  136. return false;
  137. }
  138. return true;
  139. }
  140. /// <summary>
  141. /// 专用线名称是否重复。
  142. /// </summary>
  143. /// <param name="name"></param>
  144. /// <returns></returns>
  145. private bool isRepeatName(string name)
  146. {
  147. DataTable dt = new DataTable();
  148. //不依据到站编码,他是唯一的,他与客户挂钩。
  149. //string stationCode = cmbStationName.Value.ToString();
  150. dt = ServerHelper.GetData("com.steering.pss.sale.base.CoreSpeclLine.isRepeatName", new Object[] { name }, this.ob);
  151. if (dt.Rows.Count > 0)
  152. {
  153. return true;
  154. }
  155. else
  156. {
  157. return false;
  158. }
  159. }
  160. /// <summary>
  161. /// 获取专用线代码最大值
  162. /// </summary>
  163. /// <returns></returns>
  164. private string GetMaxCode()
  165. {
  166. //判断到站编码是否为空。
  167. string stationCode = "";
  168. if (cmbStationName.Value == null||"".Equals(cmbStationName.Value.ToString()))
  169. {
  170. //为空则查询到站编码=x0000000x的专用线编码最大值加一。
  171. stationCode = "XX000000X";
  172. }
  173. else
  174. {
  175. stationCode = cmbStationName.Value.ToString();
  176. }
  177. //不为空,则查询到站编码等于stationName的专用线编码最大值。
  178. //专用线代码加一
  179. DataTable dt = ServerHelper.GetData("com.steering.pss.sale.base.CoreSpeclLine.GetMaxCode", new Object[] { stationCode }, this.ob);
  180. string maxCode = "";
  181. if (dt.Rows.Count > 0)
  182. {
  183. if (!"".Equals(dt.Rows[0][0].ToString()))
  184. {
  185. maxCode = dt.Rows[0][0].ToString();
  186. //获取最后三位数字。
  187. int maxNumber = Convert.ToInt32(maxCode.Substring(maxCode.Length - 3)) + 1;
  188. string codeStr = maxCode.Substring(0, maxCode.Length - 3);
  189. if (maxNumber > 999)
  190. {
  191. return "";
  192. }
  193. else if (maxNumber > 99)
  194. {
  195. }
  196. else if (maxNumber > 9)
  197. {
  198. maxCode = codeStr + "0" + maxNumber;
  199. }
  200. else
  201. {
  202. maxCode = codeStr + "00" + maxNumber;
  203. }
  204. }
  205. else
  206. {
  207. maxCode = stationCode + "001";
  208. }
  209. }
  210. return maxCode;
  211. }
  212. /// <summary>
  213. /// 新增
  214. /// </summary>
  215. private void doAdd()
  216. {
  217. if (ValidInput())
  218. {
  219. try
  220. {
  221. //验证描述不允许重复。
  222. string name = txtSpeclLineName.Text.Trim();
  223. if (isRepeatName(name))
  224. {
  225. MessageBox.Show("专用线名称\"" + name + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  226. return;
  227. }
  228. ArrayList parm = new ArrayList();
  229. string autoCode = GetMaxCode();
  230. //自动生成编号
  231. if ("".Equals(autoCode))
  232. {
  233. MessageBox.Show("编号超出限制,请与管理员联系。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  234. return;
  235. }
  236. string speclLineCode = autoCode;
  237. parm.Add(speclLineCode);
  238. parm.Add(name);
  239. string stationCode = "";
  240. if (cmbStationName.Value == null||"".Equals(cmbStationName.Value.ToString()))
  241. {
  242. stationCode = "XX000000X";
  243. }
  244. else
  245. {
  246. stationCode = cmbStationName.Value.ToString();
  247. }
  248. parm.Add(stationCode);
  249. parm.Add(txtMemo.Text);
  250. parm.Add(this.UserInfo.GetUserName());
  251. CoreClientParam ccp = new CoreClientParam();
  252. ccp.ServerName = "com.steering.pss.sale.base.CoreSpeclLine";
  253. ccp.MethodName = "doAdd";
  254. ccp.ServerParams = new object[] { parm };
  255. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  256. if (ccp.ReturnCode == -1) return;
  257. doQuery();
  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["spcl_ln_no"].Value.ToString().Equals(speclLineCode))
  264. {
  265. row.Activate();
  266. break;
  267. }
  268. }
  269. }
  270. catch (Exception ex)
  271. {
  272. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  273. }
  274. }
  275. }
  276. /// <summary>
  277. /// 修改
  278. /// </summary>
  279. private void doUpdate()
  280. {
  281. if (ultraGrid2.ActiveRow == null)
  282. {
  283. MessageBox.Show("请选择需要修改的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  284. return;
  285. }
  286. Boolean validflagStr = Convert.ToBoolean(ultraGrid2.ActiveRow.Cells["VALIDFLAG"].Value);
  287. //无效数据不允许修改
  288. if (!validflagStr)
  289. {
  290. MessageBox.Show("无效数据不支持修改操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  291. return;
  292. }
  293. if (ValidInput())
  294. {
  295. //验证描述不允许重复。
  296. string name = txtSpeclLineName.Text.Trim();
  297. if (!VName.Equals(name))
  298. {
  299. if (isRepeatName(name))
  300. {
  301. MessageBox.Show("专用线名称\"" + name + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  302. return;
  303. }
  304. }
  305. //确认修改吗?
  306. if (MessageBox.Show("是否确认修改选中的数据!", "提示", MessageBoxButtons.YesNo) == DialogResult.No)
  307. {
  308. return;
  309. }
  310. ArrayList parm = new ArrayList();
  311. string speclLineCode = ultraGrid2.ActiveRow.Cells["spcl_ln_no"].Value.ToString(); ;
  312. parm.Add(name);
  313. string stationCode = "";
  314. if (cmbStationName.Value == null||"".Equals(cmbStationName.Value.ToString()))
  315. {
  316. stationCode = "XX000000X";
  317. }
  318. else
  319. {
  320. stationCode = cmbStationName.Value.ToString();
  321. }
  322. parm.Add(stationCode);
  323. parm.Add(txtMemo.Text);
  324. parm.Add(this.UserInfo.GetUserName());
  325. parm.Add(speclLineCode);
  326. CoreClientParam ccp = new CoreClientParam();
  327. ccp.ServerName = "com.steering.pss.sale.base.CoreSpeclLine";
  328. ccp.MethodName = "doUpdate";
  329. ccp.ServerParams = new object[] { parm };
  330. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  331. if (ccp.ReturnCode == -1) return;
  332. doQuery();
  333. //高亮显示新增的数据
  334. Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  335. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  336. {
  337. row = ultraGrid2.Rows[i];
  338. if (row.Cells["spcl_ln_no"].Value.ToString().Equals(speclLineCode))
  339. {
  340. row.Activate();
  341. break;
  342. }
  343. }
  344. }
  345. }
  346. /// <summary>
  347. /// 废除或恢复
  348. /// </summary>
  349. /// <param name="isDelete">true废除 false恢复</param>
  350. private void doDeleteOrRecovery(bool isDelete)
  351. {
  352. if (ultraGrid2.ActiveRow == null)
  353. {
  354. MessageBox.Show("请选择需要" + (isDelete ? "废除" : "恢复") + "的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  355. return;
  356. }
  357. Boolean validflagStr = Convert.ToBoolean(ultraGrid2.ActiveRow.Cells["VALIDFLAG"].Value);
  358. if (isDelete)
  359. {
  360. //有效数据不允许删除。
  361. if (!validflagStr)
  362. {
  363. MessageBox.Show("无效数据不支持废除操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  364. return;
  365. }
  366. }
  367. else
  368. {
  369. //有效数据不允许恢复
  370. if (validflagStr)
  371. {
  372. MessageBox.Show("有效数据不支持恢复操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  373. return;
  374. }
  375. }
  376. ArrayList param = new ArrayList();
  377. string speclLineCode = ultraGrid2.ActiveRow.Cells["spcl_ln_no"].Value.ToString();
  378. param.Add(speclLineCode);
  379. if (param.Count > 0 && MessageBox.Show("是否确认" + (isDelete ? "废除" : "恢复") + "选中的数据!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  380. {
  381. try
  382. {
  383. int count = ServerHelper.SetData("com.steering.pss.sale.base.CoreSpeclLine.deleteLineInfo", new Object[] { param, UserInfo.GetUserName(), isDelete }, this.ob);
  384. if (count > 0)
  385. {
  386. doQuery();
  387. Infragistics.Win.UltraWinGrid.UltraGridRow rowD = null;
  388. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  389. {
  390. rowD = ultraGrid2.Rows[i];
  391. if (rowD.Cells["spcl_ln_no"].Value.ToString().Equals(speclLineCode))
  392. {
  393. rowD.Activate();
  394. break;
  395. }
  396. }
  397. }
  398. }
  399. catch (Exception ex)
  400. {
  401. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  402. }
  403. }
  404. }
  405. /// <summary>
  406. /// 用于验证修改时,描述是否已存在
  407. /// </summary>
  408. private static string VName = "";
  409. /// <summary>
  410. /// GRID ROW激活时信息带至编辑区
  411. /// </summary>
  412. /// <param name="sender"></param>
  413. /// <param name="e"></param>
  414. private void ultraGrid2_AfterRowActivate(object sender, EventArgs e)
  415. {
  416. Infragistics.Win.UltraWinGrid.UltraGridRow row = ultraGrid2.ActiveRow;
  417. if (row != null)
  418. {
  419. txtSpeclLineName.Text = row.Cells["spcl_ln_nm"].Text.Trim();
  420. VName = txtSpeclLineName.Text.Trim();
  421. cmbStationName.Value = row.Cells["station_no"].Value.ToString();
  422. txtMemo.Text = row.Cells["memo"].Value.ToString();
  423. }
  424. }
  425. private void button1_Click(object sender, EventArgs e)
  426. {
  427. this.BindCmbStationName();
  428. }
  429. }
  430. }