frmRackDefine.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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.CA06;
  10. using Core.Mes.Client.Comm.Control;
  11. using Core.Mes.Client.Comm.Server;
  12. using System.Collections;
  13. using Infragistics.Win.UltraWinGrid;
  14. namespace Core.StlMes.Client.YdmBase
  15. {
  16. public partial class frmRackDefine : FrmBase
  17. {
  18. public frmRackDefine()
  19. {
  20. InitializeComponent();
  21. this.IsLoadUserView = true;
  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 "Query":
  33. DoQuery();
  34. break;
  35. case "Add":
  36. DoAdd();
  37. break;
  38. case "Update":
  39. DoUpdate();
  40. break;
  41. case "Delete":
  42. DoDeleteOrResume(true);
  43. break;
  44. case "Resume":
  45. DoDeleteOrResume(false);
  46. break;
  47. case "Refresh":
  48. DoRefresh();
  49. break;
  50. case "Export":
  51. ExportGridData();
  52. break;
  53. case "Close":
  54. this.Close();
  55. break;
  56. }
  57. }
  58. ArrayList list = new ArrayList();
  59. bool isValid = false;
  60. private void frmRackDefine_Load(object sender, EventArgs e)
  61. {
  62. InitComBox();
  63. // QueryTree();
  64. getDepartMent();
  65. getDepartMent1();
  66. this.cmb_dw.Enabled = false;
  67. }
  68. /// <summary>
  69. /// 刷新
  70. /// </summary>
  71. private void DoRefresh()
  72. {
  73. InitComBox();
  74. //QueryTree();
  75. getDepartMent();
  76. getDepartMent1();
  77. }
  78. private void getDepartMent()
  79. {
  80. DataTable dt = new DataTable();
  81. string flag = "0";
  82. dt = ServerHelper.GetData("com.steering.pss.ydm.base.CoreRackDefine.doQueryData", new object[] {"1" }, this.ob);
  83. if (dt.Rows.Count > 0)
  84. {
  85. cmb_dw.DataSource = dt;
  86. cmb_dw.DisplayMember = "DEPARTNAME";
  87. cmb_dw.ValueMember = "DEPARTID";
  88. this.cmb_dw.SelectedIndex = -1;
  89. }
  90. }
  91. private void getDepartMent1()
  92. {
  93. DataTable dt = new DataTable();
  94. string flag = "0";
  95. dt = ServerHelper.GetData("com.steering.pss.ydm.base.CoreRackDefine.doQueryData", new object[] { "1" }, this.ob);
  96. if (dt.Rows.Count > 0)
  97. {
  98. cmbManage1.DataSource = dt;
  99. cmbManage1.DisplayMember = "DEPARTNAME";
  100. cmbManage1.ValueMember = "DEPARTID";
  101. }
  102. }
  103. //刷新Tree
  104. public void QueryTree()
  105. {
  106. //this.cmbManage.Nodes.Clear();
  107. DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.YdmBaseQuery.departQuery", null, this.ob);
  108. //树控件递归绑定方法。
  109. //YdmBaseClass.MakeTree(dt, "PID", null, "DEPARTID", "DEPARTNAME", cmbManage.Nodes, -1);
  110. }
  111. /// <summary>
  112. /// 初始化下拉框
  113. /// </summary>
  114. private void InitComBox()
  115. {
  116. YdmBaseClass.InitComboEditor(cmbRackType, "com.steering.pss.ydm.base.YdmBaseQuery.getRackType", "BASECODE", this.ob, true);
  117. YdmBaseClass.InitComboEditor(cmbType1, "com.steering.pss.ydm.base.YdmBaseQuery.getRackType", "BASECODE", this.ob, false);
  118. //YdmBaseClass.InitComboEditor(cmbManage1, "com.steering.pss.ydm.base.YdmBaseQuery.getManagement", "BASECODE", this.ob, false);
  119. YdmBaseClass.InitComboEditor(cmbSupportRoom, "com.steering.pss.ydm.base.YdmBaseQuery.getRackSp", "BASECODE", this.ob, false);
  120. }
  121. private void ultraCheckEditor1_CheckedChanged(object sender, EventArgs e)
  122. {
  123. if (ultraCheckEditor1.Checked)
  124. {
  125. cmbRackType.ReadOnly = false;
  126. }
  127. else
  128. {
  129. cmbRackType.ReadOnly = true;
  130. }
  131. }
  132. /// <summary>
  133. /// 导出数据
  134. /// </summary>
  135. private void ExportGridData()
  136. {
  137. GridHelper.ulGridToExcel(gdRack,this.Text);
  138. }
  139. /// <summary>
  140. /// 获取编辑区的数据
  141. /// </summary>
  142. private bool GetData()
  143. {
  144. list = new ArrayList();
  145. if (cmbType1.SelectedItem == null)
  146. {
  147. MessageBox.Show("请选择料架类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  148. return false ;
  149. }
  150. if (cmbManage1.SelectedItem == null)
  151. {
  152. MessageBox.Show("请选择所属单位", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  153. return false;
  154. }
  155. if (txtRackWidth.Value==null)
  156. {
  157. MessageBox.Show("请输入料架宽度", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  158. return false;
  159. }
  160. if (txtRackHeight.Value == null)
  161. {
  162. MessageBox.Show("请输入料架高度", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  163. return false;
  164. }
  165. if (txtRackLen.Value == null)
  166. {
  167. MessageBox.Show("请输入料架长度", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  168. return false;
  169. }
  170. if (txtBaseWidth.Value == null)
  171. {
  172. MessageBox.Show("请输入基座宽度", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  173. return false;
  174. }
  175. if (txtBaseHeight == null)
  176. {
  177. MessageBox.Show("请输入基座高度", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  178. return false;
  179. }
  180. if (Convert.ToInt32(txtRackWidth.Value) >Convert.ToInt32(txtBaseWidth.Value))
  181. {
  182. MessageBox.Show("基座宽度不能小于料架宽度", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  183. return false;
  184. }
  185. if (Convert.ToInt32(txtRackHeight.Value) >Convert.ToInt32(txtBaseHeight.Value))
  186. {
  187. MessageBox.Show("基座高度不能小于料架高度", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  188. return false;
  189. }
  190. if (cmbSupportRoom.SelectedItem == null)
  191. {
  192. MessageBox.Show("请选择支持空间", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  193. return false;
  194. }
  195. list.Add(cmbType1.Text.Trim()); //用于编码类型
  196. list.Add(cmbType1.Text.Trim()); //料架类型
  197. list.Add(txtBaseWidth.Value.ToString());
  198. list.Add(txtBaseHeight.Value.ToString());
  199. list.Add(txtRackWidth.Value.ToString());
  200. list.Add(txtRackHeight.Value.ToString());
  201. list.Add(txtRackLen.Value.ToString());
  202. list.Add(cmbSupportRoom.Text.Trim());
  203. list.Add(cmbManage1.Value.ToString());
  204. list.Add(cmbManage1.Text.Trim());
  205. list.Add(txtMemo.Text.Trim());
  206. list.Add(this.UserInfo.GetUserName());
  207. return true;
  208. }
  209. /// <summary>
  210. /// 新增数据
  211. /// </summary>
  212. private void DoAdd()
  213. {
  214. if(!GetData())return;
  215. if (list.Count <= 0)
  216. return;
  217. int count = ServerHelper.SetData("com.steering.pss.ydm.base.CoreRackDefine.doAdd", new Object[] { list }, this.ob);
  218. if (count > 0)
  219. {
  220. MessageBox.Show("数据新增成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  221. DoQuery();
  222. DataRow[] dr = dataTable1.Select("", "CREATE_TIME DESC");
  223. if (dr.Length > 0)
  224. YdmBaseClass.Postioning(gdRack,"RACK_NO",dr[0]["RACK_NO"].ToString());
  225. }
  226. }
  227. /// <summary>
  228. /// 查询
  229. /// </summary>
  230. private void DoQuery()
  231. {
  232. string manage = "";
  233. string racktype = "";
  234. if (this.ultraCheckEditor2.Checked)
  235. {
  236. if (string.IsNullOrEmpty(cmb_dw.Text.Trim()))
  237. {
  238. MessageBox.Show("请选择料架所属单位!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  239. return;
  240. }
  241. else
  242. {
  243. manage = cmb_dw.Text.ToString();
  244. }
  245. }
  246. else
  247. {
  248. manage = "";
  249. }
  250. if (cmbRackType.SelectedItem != null && cmbRackType.Text != "")
  251. racktype = cmbRackType.Text;
  252. else
  253. racktype = "%";
  254. DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.CoreRackDefine.doQuery", new Object[] { manage, racktype, isValid }, this.ob);
  255. GridHelper.CopyDataToDatatable(ref dt, ref dataTable1, true);
  256. YdmBaseClass.SetGridRowColor(gdRack);
  257. YdmBaseClass.SetGridActivateOnly(gdRack);
  258. YdmBaseClass.SetColAutoSizeExceptMemo(gdRack);
  259. gdRack.DisplayLayout.Bands[0].Columns["CREATE_TIME"].SortIndicator = SortIndicator.Ascending;
  260. }
  261. /// <summary>
  262. /// 更新数据
  263. /// </summary>
  264. private void DoUpdate()
  265. {
  266. this.gdRack.UpdateData();
  267. UltraGridRow ugr = gdRack.ActiveRow;
  268. if (ugr == null)
  269. {
  270. MessageBox.Show("请选择需要修改的记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  271. return;
  272. }
  273. string rackNo = ugr.Cells["RACK_NO"].Text.ToString();
  274. DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.CoreRackDefine.getReferRack", new object[] { rackNo }, this.ob);
  275. if (dt.Rows.Count > 0)
  276. {
  277. if (dt.Rows[0]["VALIDFLAG"].ToString() == "0")
  278. {
  279. MessageBox.Show("无效数据,无法修改!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  280. return;
  281. }
  282. if (dt.Rows[0]["USE_FLAG"].ToString() == "1")
  283. {
  284. MessageBox.Show("数据已被引用,无法修改!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  285. return;
  286. }
  287. }
  288. if(!GetData())return;
  289. string newrackno="";
  290. if (list.Count > 0)
  291. {
  292. string rackno = ugr.Cells["RACK_NO"].Value.ToString();
  293. newrackno = rackno.Replace(rackno.Substring(0, 1), cmbType1.Text.Trim());
  294. list.RemoveAt(0);
  295. list.Add(newrackno);
  296. list.Add(rackno);
  297. }
  298. if (MessageBox.Show("是否确认修改该行数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  299. {
  300. return;
  301. }
  302. int count = ServerHelper.SetData("com.steering.pss.ydm.base.CoreRackDefine.doUpdate", new Object[] { list }, this.ob);
  303. if (count > 0)
  304. {
  305. MessageBox.Show("数据修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  306. DoQuery();
  307. YdmBaseClass.Postioning(gdRack,"RACK_NO",newrackno);
  308. }
  309. }
  310. /// <summary>
  311. /// 行激活事件
  312. /// </summary>
  313. /// <param name="sender"></param>
  314. /// <param name="e"></param>
  315. private void gdRack_AfterRowActivate(object sender, EventArgs e)
  316. {
  317. this.gdRack.UpdateData();
  318. UltraGridRow ugr = gdRack.ActiveRow;
  319. if (ugr == null)
  320. {
  321. return;
  322. }
  323. string rackno = ugr.Cells["RACK_NO"].Value.ToString();
  324. txtRacknoHead.Value = rackno.Substring(0, 1);
  325. txtRacknoTail.Value = rackno.Substring(1, 5);
  326. cmbType1.Text= ugr.Cells["RACK_TYPE"].Value.ToString();
  327. this.cmbManage1.Text = ugr.Cells["HL_MANAGEMENT_NAME"].Text.ToString();
  328. txtRackWidth.Value = ugr.Cells["RACK_WIDTH"].Value.ToString();
  329. txtRackHeight.Value = ugr.Cells["RACK_HEIGHT"].Value.ToString();
  330. txtRackLen.Value = ugr.Cells["RACK_LEN"].Value.ToString();
  331. txtBaseWidth.Value = ugr.Cells["BASE_WIDTH"].Value.ToString();
  332. txtBaseHeight.Value = ugr.Cells["BASE_HEIGHT"].Value.ToString();
  333. switch (ugr.Cells["RACK_RL"].Value.ToString())
  334. {
  335. case"左侧":
  336. cmbSupportRoom.Text = "L";
  337. break;
  338. case "右侧":
  339. cmbSupportRoom.Text = "R";
  340. break;
  341. case "两侧":
  342. cmbSupportRoom.Text = "LR";
  343. break;
  344. }
  345. txtMemo.Value = ugr.Cells["MEMO"].Value.ToString();
  346. }
  347. /// <summary>
  348. /// 作废或恢复数据
  349. /// </summary>
  350. /// <param name="flag">true 作废 false 恢复</param>
  351. private void DoDeleteOrResume(bool flag)
  352. {
  353. UltraGridRow ugr = gdRack.ActiveRow;
  354. if (ugr == null)
  355. {
  356. MessageBox.Show("请选择你要操作的记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  357. return;
  358. }
  359. if (flag == false && ugr.Cells["VALIDFLAG"].Value.ToString().ToUpper() == "有效")
  360. {
  361. MessageBox.Show("有效数据,无法恢复!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  362. return;
  363. }
  364. if (flag == true && ugr.Cells["VALIDFLAG"].Value.ToString().ToUpper() != "有效")
  365. {
  366. MessageBox.Show("无效数据,无法作废!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  367. return;
  368. }
  369. if (MessageBox.Show("是否确认" + (flag ? "作废" : "恢复") + "该行数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  370. {
  371. return;
  372. }
  373. string rackno = ugr.Cells["RACK_NO"].Value.ToString();
  374. DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.CoreRackDefine.getReferRack", new object[] { rackno }, this.ob);
  375. if (dt.Rows.Count > 0)
  376. {
  377. if (dt.Rows[0]["VALIDFLAG"].ToString() == "0")
  378. {
  379. MessageBox.Show("无效数据,无法删除!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  380. return;
  381. }
  382. if (dt.Rows[0]["USE_FLAG"].ToString() == "1")
  383. {
  384. MessageBox.Show("数据已被引用,无法删除!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  385. return;
  386. }
  387. }
  388. string name = this.UserInfo.GetUserName();
  389. int count = ServerHelper.SetData("com.steering.pss.ydm.base.CoreRackDefine.doDelete", new Object[] { rackno,name,flag }, this.ob);
  390. if (count > 0)
  391. {
  392. MessageBox.Show("数据" + (flag ? "作废" : "恢复") + "成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  393. DoQuery();
  394. }
  395. }
  396. private void chkValid_CheckedChanged(object sender, EventArgs e)
  397. {
  398. if (chkValid.Checked)
  399. {
  400. isValid = true;
  401. }
  402. else
  403. {
  404. isValid = false;
  405. }
  406. }
  407. private void ultraCheckEditor2_CheckedChanged(object sender, EventArgs e)
  408. {
  409. this.cmb_dw.Enabled = this.ultraCheckEditor2.Checked;
  410. }
  411. }
  412. }