锐腾搅拌上料功能
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.

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