锐腾搅拌上料功能
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

611 lines
25 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using DevExpress.XtraEditors;
  9. using ICSSoft.Base.Config.AppConfig;
  10. using System.Data.Linq;
  11. using System.Linq;
  12. using ICSSoft.Base.Language.Tool;
  13. using System.Reflection;
  14. using ICSSoft.Base.Config.DBHelper;
  15. using ICSSoft.Base.ReferForm;
  16. using ICSSoft.Base.Report;
  17. using ICSSoft.Base.ReferForm.AppReferForm;
  18. using ICSSoft.Frame.Data.Entity;
  19. using ICSSoft.Frame.Data.BLL;
  20. using System.Data.SqlClient;
  21. namespace ICSSoft.Frame.APP
  22. {
  23. public partial class FormICSTuiKuAdd : DevExpress.XtraEditors.XtraForm
  24. {
  25. private int flag = 0;
  26. private string Qty = "";
  27. private string StorageCode = "";
  28. private string TransNo = "";
  29. #region 构造函数
  30. public FormICSTuiKuAdd()
  31. {
  32. InitializeComponent();
  33. txtmuser.Text = AppConfig.UserName;
  34. flag = 0;
  35. }
  36. //#region 审核
  37. //public FormICSTuiKuAdd(string TransferNO, string TransLine, string INVCode, string INVName, int status)
  38. // {
  39. // if (status == 0)
  40. // {
  41. // DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在保存请稍等...");
  42. // try
  43. // {
  44. // string sql = @"update ICSTransferNOBack set Status = '审核' where 1=1 and TransferNO = '" + TransferNO + "' and TransLine = '" + TransLine + "' and INVCode = '" + INVCode + "' and INVName = '" + INVName + "'";
  45. // sql = string.Format(sql);
  46. // DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, sql);
  47. // _wait.Close();
  48. // }
  49. // catch (Exception ex)
  50. // {
  51. // _wait.Close();
  52. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  53. // }
  54. // }
  55. // else if (status == 1)
  56. // {
  57. // DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在审核请稍等...");
  58. // try
  59. // {
  60. // string sql = @"update ICSTransferNOBack set Status = '已审核', Approver = '{0}' where 1=1 and TransferNO = '" + TransferNO + "' and TransLine = '" + TransLine + "' and INVCode = '" + INVCode + "' and INVName = '" + INVName + "'";
  61. // sql = string.Format(sql, AppConfig.UserName);
  62. // DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, sql);
  63. // _wait.Close();
  64. // }
  65. // catch (Exception ex)
  66. // {
  67. // _wait.Close();
  68. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  69. // }
  70. // }
  71. // else if (status == 2)
  72. // {
  73. // DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在审核请稍等...");
  74. // try
  75. // {
  76. // string sql = @"update ICSTransferNOBack set Status = '反审核', Approver = '{0}' where 1=1 and TransferNO = '" + TransferNO + "' and TransLine = '" + TransLine + "' and INVCode = '" + INVCode + "' and INVName = '" + INVName + "'";
  77. // sql = string.Format(sql, AppConfig.UserName);
  78. // DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, sql);
  79. // _wait.Close();
  80. // }
  81. // catch (Exception ex)
  82. // {
  83. // _wait.Close();
  84. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  85. // }
  86. // }
  87. // }
  88. //#endregion
  89. #region 删除
  90. public FormICSTuiKuAdd(string TransferNO, string INVCode, string TransLine, string WHCode, string Qty)
  91. {
  92. try
  93. {
  94. SqlConnection conn = new SqlConnection(AppConfig.AppConnectString);
  95. conn.Open();
  96. SqlCommand cmd = new SqlCommand();
  97. SqlTransaction trans = conn.BeginTransaction();
  98. cmd.Transaction = trans;
  99. cmd.Connection = conn;
  100. try
  101. {
  102. string sqls = @"delete ICSMaterialPick where VouchCode = '" + TransferNO + "' and VouchRow = '" + TransLine + "' and SubInvCode = '" + INVCode + "' and WHCode = '" + WHCode + "'and Quantity = '" + Qty + "' ";
  103. cmd.CommandType = CommandType.Text;
  104. cmd.CommandText = sqls;
  105. cmd.ExecuteNonQuery();
  106. trans.Commit();
  107. }
  108. catch (Exception ex)
  109. {
  110. trans.Rollback();
  111. throw ex;
  112. }
  113. }
  114. catch (Exception ex)
  115. {
  116. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  117. }
  118. }
  119. #endregion
  120. public FormICSTuiKuAdd(string TransferNO, string TransLine, string INVCode, string StorageCode,string qty, string muser)
  121. {
  122. InitializeComponent();
  123. this.txtSubInvCode.Enabled = false;
  124. this.txtTransferNO.Enabled = false;
  125. this.txtNO.Enabled = false;
  126. this.txtVouchRow.Enabled = false;
  127. this.txtTransferNO.Text = TransferNO.Substring(0, 8);
  128. this.txtNO.Text = TransferNO.Substring(TransferNO.Length - (TransferNO.Length - 8), TransferNO.Length - 8);
  129. this.txtVouchRow.Text = TransLine;
  130. this.txtSubInvCode.Text = INVCode;
  131. this.txtStorageCode.Text = StorageCode;
  132. this.SearchINVCodeInfo(INVCode);
  133. this.StorageCodeInfo();
  134. this.txtmuser.Text = muser;
  135. Qty = qty;
  136. flag = 1;
  137. }
  138. #endregion
  139. #region 存货名称
  140. private void SearchINVCodeInfo(string INVCode)
  141. {
  142. string sql = @"select INVName from ICSINVENTORY where 1=1 and INVCode='" + INVCode + "' order by MTIME";
  143. sql = string.Format(sql);
  144. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  145. if (dt.Rows.Count > 0)
  146. {
  147. foreach (DataRow dr in dt.Rows)
  148. {
  149. this.txtInvName.Text = dr["INVName"].ToString();
  150. }
  151. if (txtInvName.Text == "")
  152. {
  153. ICSBaseSimpleCode.AppshowMessageBox("物料号对应的存货名称为空,请确认");
  154. return;
  155. }
  156. else
  157. {
  158. this.txtQuantity.Enabled = true;
  159. this.txtQuantity.Focus();
  160. }
  161. }
  162. else
  163. {
  164. ICSBaseSimpleCode.AppshowMessageBox("未查询到物料号对应的存货名称");
  165. return;
  166. }
  167. }
  168. #endregion
  169. public void StorageCodeInfo()
  170. {
  171. string sql = @"SELECT StorageCode FROM ICSStorage where 1=1";
  172. sql = string.Format(sql);
  173. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  174. if (dt.Rows.Count > 0)
  175. {
  176. foreach (DataRow dr in dt.Rows)
  177. {
  178. this.txtStorageCode.Items.Add(dr["StorageCode"].ToString());
  179. }
  180. }
  181. }
  182. public void SearchINVCodeInfo()
  183. {
  184. string sql = @"select DISTINCT TOP 10 INVCode from ICSINVENTORY where 1=1 order by INVCode";
  185. sql = string.Format(sql);
  186. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  187. if (dt.Rows.Count > 0)
  188. {
  189. foreach (DataRow dr in dt.Rows)
  190. {
  191. this.txtSubInvCode.Items.Add(dr["INVCode"].ToString());
  192. }
  193. }
  194. }
  195. #region 关闭 退出
  196. private void btnClose_Click(object sender, EventArgs e)
  197. {
  198. this.Close();
  199. }
  200. #endregion
  201. #region 移动窗体
  202. private const int WM_NCHITTEST = 0x84;
  203. private const int HTCLIENT = 0x1;
  204. private const int HTCAPTION = 0x2;
  205. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  206. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  207. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  208. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  209. //重写窗体,使窗体可以不通过自带标题栏实现移动
  210. protected override void WndProc(ref Message m)
  211. {
  212. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  213. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  214. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  215. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  216. switch (m.Msg)
  217. {
  218. case WM_NCHITTEST:
  219. base.WndProc(ref m);
  220. if ((int)m.Result == HTCLIENT)
  221. m.Result = (IntPtr)HTCAPTION;
  222. return;
  223. }
  224. //拦截双击标题栏、移动窗体的系统消息
  225. if (m.Msg != 0xA3)
  226. {
  227. base.WndProc(ref m);
  228. }
  229. }
  230. #endregion
  231. #region 新增 修改
  232. private void save_Click(object sender, EventArgs e)
  233. {
  234. Decimal qty = new Decimal();
  235. TransNo = this.txtTransferNO.Text + this.txtNO.Text;
  236. if (flag == 0)
  237. {
  238. try
  239. {
  240. #region 判断是否为空
  241. if (txtStorageCode.Text.Trim() == "")
  242. {
  243. ICSBaseSimpleCode.AppshowMessageBox("仓库不能为空");
  244. return;
  245. }
  246. if (txtQuantity.Text.Trim() == "")
  247. {
  248. ICSBaseSimpleCode.AppshowMessageBox("数量不能为空");
  249. return;
  250. }
  251. else
  252. {
  253. try
  254. {
  255. qty = Decimal.Parse(this.txtQuantity.Text);
  256. if (qty <= 0)
  257. {
  258. ICSBaseSimpleCode.AppshowMessageBox("请输入正确的数量");
  259. this.txtQuantity.Text = "";
  260. return;
  261. }
  262. }
  263. catch
  264. {
  265. ICSBaseSimpleCode.AppshowMessageBox("请输入数字");
  266. this.txtQuantity.Text = "";
  267. return;
  268. }
  269. }
  270. #endregion
  271. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在新增请稍等...");
  272. try
  273. {
  274. SqlConnection conn = new SqlConnection(AppConfig.AppConnectString);
  275. SqlCommand com = conn.CreateCommand();
  276. SqlTransaction tran;
  277. conn.Open();
  278. tran = conn.BeginTransaction();
  279. com.Transaction = tran;
  280. try
  281. {
  282. string sql = @"insert into ICSMaterialPick (VouchCode, VouchRow, SubInvCode, InvCode, Quantity, MTIME, MUSER, MUSERName, MoveType,WorkPoint, MOCode, MORow, WBS, DemandQuantity, SupplyQuantity, BackQuantity, HasQuantity,Sign,WHCode,ComUnitCode,BomNo,LotNo,DeleteStatus,VoucherNO,Year,VoucherDate,Status,Writeback)
  283. values (@VouchCode, @VouchRow, @SubInvCode, '', @Quantity, @MTIME, @MUSER, @MUSERName, '退',@WorkPoint,'','','',0,0,0,0,'',@WHCode,'','','','','','','','','')";
  284. com.CommandText = sql;
  285. com.Parameters.Clear();
  286. com.Parameters.AddWithValue("@VouchCode", TransNo);
  287. com.Parameters.AddWithValue("@VouchRow", txtVouchRow.Text.Trim());
  288. com.Parameters.AddWithValue("@SubInvCode", txtSubInvCode.Text.Trim());
  289. com.Parameters.AddWithValue("@WHCode", txtStorageCode.Text.Trim());
  290. com.Parameters.AddWithValue("@Quantity", qty);
  291. com.Parameters.AddWithValue("@Mtime", DateTime.Now.ToString());
  292. com.Parameters.AddWithValue("@Muser", AppConfig.UserName);
  293. com.Parameters.AddWithValue("@MUSERName", AppConfig.UserName);
  294. com.Parameters.AddWithValue("@WorkPoint",AppConfig.WorkPointCode);
  295. com.ExecuteNonQuery();
  296. tran.Commit();
  297. }
  298. catch (Exception ex)
  299. {
  300. tran.Rollback();
  301. throw ex;
  302. }
  303. _wait.Close();
  304. ICSBaseSimpleCode.AppshowMessageBox("新增成功");
  305. }
  306. catch (Exception ex)
  307. {
  308. _wait.Close();
  309. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  310. }
  311. }
  312. catch (Exception ex)
  313. {
  314. MessageBox.Show(ex.Message);
  315. }
  316. }
  317. if (flag == 1)
  318. {
  319. try
  320. {
  321. #region 判断是否为空
  322. StorageCode =txtStorageCode.Text.Trim();
  323. if (txtQuantity.Text.Trim() == "")
  324. {
  325. ICSBaseSimpleCode.AppshowMessageBox("数量不能为空");
  326. return;
  327. }
  328. else
  329. {
  330. try
  331. {
  332. qty = Decimal.Parse(this.txtQuantity.Text);
  333. if (qty <= 0)
  334. {
  335. ICSBaseSimpleCode.AppshowMessageBox("请输入正确的数量");
  336. this.txtQuantity.Text = "";
  337. return;
  338. }
  339. else
  340. {
  341. if (qty == Decimal.Parse(Qty))
  342. {
  343. ICSBaseSimpleCode.AppshowMessageBox("输入数量与原先相同,请确认");
  344. this.txtQuantity.Text = "";
  345. return;
  346. }
  347. }
  348. }
  349. catch
  350. {
  351. ICSBaseSimpleCode.AppshowMessageBox("请输入数字");
  352. this.txtQuantity.Text = "";
  353. return;
  354. }
  355. }
  356. #endregion
  357. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在修改请稍等...");
  358. try
  359. {
  360. string sql = @"update ICSMaterialPick set Quantity = {0} ,WHCode={1}where 1=1 and VouchCode = '" + TransNo + "' and VouchRow = '" + this.txtVouchRow.Text + "' and SubInvCode = '" + this.txtSubInvCode.Text + "' ";
  361. sql = string.Format(sql, qty, StorageCode);
  362. DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, sql);
  363. _wait.Close();
  364. ICSBaseSimpleCode.AppshowMessageBox("修改成功");
  365. }
  366. catch (Exception ex)
  367. {
  368. _wait.Close();
  369. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  370. }
  371. }
  372. catch (Exception ex)
  373. {
  374. MessageBox.Show(ex.Message);
  375. }
  376. }
  377. this.Close();
  378. this.DialogResult = DialogResult.Yes;
  379. }
  380. #endregion
  381. #region 取消
  382. private void can_Click(object sender, EventArgs e)
  383. {
  384. this.Close();
  385. }
  386. #endregion
  387. private void FormICSChuKuAdd_Load(object sender, EventArgs e)
  388. {
  389. if (flag == 0)
  390. {
  391. this.txtTransferNO.Text = "T2" + DateTime.Now.ToString("yyyyMMddHHmmss").Substring(2, 6);
  392. this.SearchINVCodeInfo();
  393. this.StorageCodeInfo();
  394. }
  395. this.txtNO.Focus();
  396. }
  397. #region 判断是否为空
  398. private void cBINVCode_SelectedIndexChanged(object sender, EventArgs e)
  399. {
  400. if (txtSubInvCode.Text.Trim() == "")
  401. {
  402. ICSBaseSimpleCode.AppshowMessageBox("物料号不能为空");
  403. return;
  404. }
  405. this.SearchINVCodeInfo(this.txtSubInvCode.Text.Trim());
  406. }
  407. #endregion
  408. #region 存货编码
  409. private void cBINVCode_KeyDown(object sender, KeyEventArgs e)
  410. {
  411. if (e.KeyCode == Keys.Enter)
  412. {
  413. string sql = @"select DISTINCT INVCode from ICSINVENTORY where 1=1 and INVCode like '%" + this.txtSubInvCode.Text + "%' order by INVCode";
  414. sql = string.Format(sql);
  415. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  416. if (dt.Rows.Count > 1)
  417. {
  418. this.txtSubInvCode.Items.Clear();
  419. foreach (DataRow dr in dt.Rows)
  420. {
  421. this.txtSubInvCode.Items.Add(dr["INVCode"].ToString());
  422. }
  423. }
  424. else if (dt.Rows.Count == 1)
  425. {
  426. this.txtSubInvCode.Items.Clear();
  427. foreach (DataRow dr in dt.Rows)
  428. {
  429. this.txtSubInvCode.Items.Add(dr["INVCode"].ToString());
  430. this.txtSubInvCode.Text = dr["INVCode"].ToString();
  431. }
  432. cBINVCode_SelectedIndexChanged(sender, e);
  433. }
  434. }
  435. }
  436. #endregion
  437. #region 判断是否为空
  438. private void ICSStorageCode_SelectedIndexChanged(object sender, EventArgs e)
  439. {
  440. if (txtStorageCode.Text.Trim() == "")
  441. {
  442. ICSBaseSimpleCode.AppshowMessageBox("仓库编码不能为空");
  443. return;
  444. }
  445. }
  446. #endregion
  447. //#region 仓库
  448. //private void ICSStorageCode_KeyDown(object sender, KeyEventArgs e)
  449. //{
  450. // if (e.KeyCode == Keys.Enter)
  451. // {
  452. // string sql = @"SELECT StorageCode FROM ICSStorage where 1=1";
  453. // sql = string.Format(sql);
  454. // DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  455. // if (dt.Rows.Count > 1)
  456. // {
  457. // this.txtStorageCode.Items.Clear();
  458. // foreach (DataRow dr in dt.Rows)
  459. // {
  460. // this.txtStorageCode.Items.Add(dr["StorageCode"].ToString());
  461. // }
  462. // }
  463. // else if (dt.Rows.Count == 1)
  464. // {
  465. // this.txtStorageCode.Items.Clear();
  466. // foreach (DataRow dr in dt.Rows)
  467. // {
  468. // this.txtStorageCode.Items.Add(dr["WHCode"].ToString());
  469. // this.txtStorageCode.Text = dr["WHCode"].ToString();
  470. // }
  471. // cBINVCode_SelectedIndexChanged(sender, e);
  472. // }
  473. // }
  474. //}
  475. //#endregion
  476. #region 单号
  477. private void txtNO_KeyDown(object sender, KeyEventArgs e)
  478. {
  479. if (e.KeyCode == Keys.Enter)
  480. {
  481. Decimal qty = new Decimal();
  482. if (txtNO.Text.Trim() == "")
  483. {
  484. ICSBaseSimpleCode.AppshowMessageBox("数字不能为空");
  485. return;
  486. }
  487. else
  488. {
  489. try
  490. {
  491. qty = Decimal.Parse(this.txtNO.Text);
  492. if (qty <= 0)
  493. {
  494. ICSBaseSimpleCode.AppshowMessageBox("请输入正确的数字");
  495. this.txtNO.Text = "";
  496. return;
  497. }
  498. if (this.txtNO.Text.Length == 2)
  499. {
  500. TransNo = txtTransferNO.Text.Trim() + txtNO.Text.Trim();
  501. string sql = @"SELECT MAX(A.VouchRow) AS LINE FROM ICSMaterialPick A WHERE A.VouchCode = '{0}'";
  502. sql = string.Format(sql, TransNo);
  503. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  504. if (dt.Rows.Count <= 0)
  505. {
  506. this.txtVouchRow.Text = "001";
  507. this.txtSubInvCode.Focus();
  508. this.txtSubInvCode.SelectAll();
  509. }
  510. else
  511. {
  512. string Line = "";
  513. foreach (DataRow dr in dt.Rows)
  514. {
  515. Line = dr["LINE"].ToString();
  516. }
  517. if (Line == "" || Line == null)
  518. {
  519. this.txtVouchRow.Text = "001";
  520. this.txtSubInvCode.Focus();
  521. this.txtSubInvCode.SelectAll();
  522. }
  523. else
  524. {
  525. this.txtVouchRow.Text = (Convert.ToInt32(Line) + 1).ToString().PadLeft(3, '0');
  526. this.txtSubInvCode.Focus();
  527. this.txtSubInvCode.SelectAll();
  528. }
  529. }
  530. }
  531. else
  532. {
  533. ICSBaseSimpleCode.AppshowMessageBox("请输入正确的位数,为2位");
  534. this.txtNO.Text = "";
  535. return;
  536. }
  537. }
  538. catch
  539. {
  540. ICSBaseSimpleCode.AppshowMessageBox("请输入数字");
  541. this.txtNO.Text = "";
  542. return;
  543. }
  544. }
  545. }
  546. }
  547. #endregion
  548. #region 行号
  549. private void txtTransLine_KeyDown(object sender, KeyEventArgs e)
  550. {
  551. if (e.KeyCode == Keys.Enter)
  552. {
  553. Decimal qty = new Decimal();
  554. if (txtVouchRow.Text.Trim() == "")
  555. {
  556. ICSBaseSimpleCode.AppshowMessageBox("行号不能为空");
  557. return;
  558. }
  559. else
  560. {
  561. try
  562. {
  563. qty = Decimal.Parse(this.txtVouchRow.Text);
  564. if (qty <= 0)
  565. {
  566. ICSBaseSimpleCode.AppshowMessageBox("请输入正确的行号");
  567. this.txtVouchRow.Text = "";
  568. return;
  569. }
  570. }
  571. catch
  572. {
  573. ICSBaseSimpleCode.AppshowMessageBox("请输入数字");
  574. this.txtVouchRow.Text = "";
  575. return;
  576. }
  577. }
  578. }
  579. }
  580. #endregion
  581. }
  582. }