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

451 lines
21 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Windows.Forms;
  6. using DevExpress.XtraEditors;
  7. using ICSSoft.Base.Config.AppConfig;
  8. using ICSSoft.Base.Config.DBHelper;
  9. using ICSSoft.Base.ReferForm.AppReferForm;
  10. using ICSSoft.Frame.Data.Entity;
  11. using ICSSoft.Frame.Data.BLL;
  12. namespace ICSSoft.Frame.APP
  13. {
  14. public partial class FormICSDeliveryPlanEdit : DevExpress.XtraEditors.XtraForm
  15. {
  16. String guid = "";
  17. DataSet dataSource = new DataSet();
  18. string Version = "";
  19. string pk_org_ForInvcode = "000110100000000005J9";
  20. DataTable dtSO = new DataTable();
  21. #region 构造函数
  22. public FormICSDeliveryPlanEdit()
  23. {
  24. InitializeComponent();
  25. this.MaximumSize = new System.Drawing.Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  26. this.WindowState = FormWindowState.Maximized;
  27. }
  28. public FormICSDeliveryPlanEdit(String id, string version = null)
  29. {
  30. InitializeComponent();
  31. guid = id;
  32. Version = version;
  33. this.MaximumSize = new System.Drawing.Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  34. this.WindowState = FormWindowState.Maximized;
  35. }
  36. #endregion
  37. #region 关闭 退出
  38. private void btnClose_Click(object sender, EventArgs e)
  39. {
  40. this.Close();
  41. }
  42. #endregion
  43. #region 移动窗体
  44. private const int WM_NCHITTEST = 0x84;
  45. private const int HTCLIENT = 0x1;
  46. private const int HTCAPTION = 0x2;
  47. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  48. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  49. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  50. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  51. //重写窗体,使窗体可以不通过自带标题栏实现移动
  52. protected override void WndProc(ref Message m)
  53. {
  54. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  55. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  56. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  57. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  58. switch (m.Msg)
  59. {
  60. case WM_NCHITTEST:
  61. base.WndProc(ref m);
  62. if ((int)m.Result == HTCLIENT)
  63. m.Result = (IntPtr)HTCAPTION;
  64. return;
  65. }
  66. //拦截双击标题栏、移动窗体的系统消息
  67. if (m.Msg != 0xA3)
  68. {
  69. base.WndProc(ref m);
  70. }
  71. }
  72. #endregion
  73. #region 新增 修改
  74. private void btnOK_Click(object sender, EventArgs e)
  75. {
  76. try
  77. {
  78. if (dataSource == null || dataSource.Tables.Count != 2)
  79. {
  80. return;
  81. }
  82. if (txtCustomer.EditValue == null || string.IsNullOrWhiteSpace(txtCustomer.EditValue.ToString()))
  83. {
  84. throw new Exception("请选择客户!");
  85. }
  86. DataTable dt = dataSource.Tables[1];
  87. //DataRow[] drs = dt.Select("InvCode=''");
  88. //if (drs != null && drs.Length > 0)
  89. // throw new Exception("物料编码不能为空!");
  90. //var InvCodes = (from DataRow dr in dt.Rows
  91. // group dr by (string)dr["InvCode"] into g
  92. // select new
  93. // {
  94. // InvCode = g.Key,
  95. // Count = g.Count()
  96. // }).Where(a => a.Count > 1).Select(a => a.InvCode);
  97. //if (InvCodes != null && InvCodes.Count() > 0)
  98. //{
  99. // string invcodes = string.Join(",", InvCodes);
  100. // throw new Exception("物料编码不能重复:" + invcodes);
  101. //}
  102. //var Sequences = (from DataRow dr in dt.Rows
  103. // group dr by (int)dr["Sequence"] into g
  104. // select new
  105. // {
  106. // Sequence = g.Key,
  107. // Count = g.Count()
  108. // }).Where(a => a.Count > 1).Select(a => a.Sequence);
  109. //if (Sequences != null && Sequences.Count() > 0)
  110. //{
  111. // string invcodes = string.Join(",", Sequences);
  112. // throw new Exception("行号不能重复:" + invcodes);
  113. //}
  114. ICSDeliveryPlan entity = new ICSDeliveryPlan();
  115. entity.ID = guid;
  116. entity.DeliveryPlanNO = txtDeliveryPlanNO.Text.Trim();
  117. entity.Version = txtDeliveryPlanNO.Tag.ToString();
  118. entity.Customer = txtCustomer.EditValue.ToString();
  119. entity.Org = txtCustomer.Text.Trim();
  120. entity.Enable = true;
  121. entity.MUSER = AppConfig.UserCode;
  122. entity.MUSERName = AppConfig.UserName;
  123. entity.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  124. entity.WorkPoint = AppConfig.WorkPointCode;
  125. entity.EATTRIBUTE1 = null;
  126. entity.CreateUser = entity.MUSER;
  127. entity.CreateDateTime = entity.MTIME;
  128. ICSDeliveryPlanBLL.Add(entity, dt, Version, AppConfig.AppConnectString);
  129. this.Close();
  130. ICSBaseSimpleCode.AppshowMessageBox("操作成功");
  131. }
  132. catch (Exception ex)
  133. {
  134. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  135. }
  136. }
  137. #endregion
  138. #region 取消
  139. private void can_Click(object sender, EventArgs e)
  140. {
  141. this.Close();
  142. }
  143. #endregion
  144. #region 页面加载
  145. private void FormICSINVENTORYEditAdd_Load(object sender, EventArgs e)
  146. {
  147. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在加载...请稍等...");
  148. _wait.Show();
  149. try
  150. {
  151. AppConfig.BindCustomDrawRowIndicator(grdDetail);
  152. init();
  153. dataSource = ICSDeliveryPlanBLL.SearchInfoByID(guid, AppConfig.AppConnectString);
  154. if (dataSource == null || dataSource.Tables.Count != 2)
  155. {
  156. throw new Exception("查询数据失败,请重新操作!");
  157. }
  158. DataRow dr = dataSource.Tables[0].Rows[0];
  159. txtDeliveryPlanNO.Text = dr["DeliveryPlanNO"].ToString();
  160. txtDeliveryPlanNO.Tag = dr["Version"].ToString();
  161. if (string.IsNullOrWhiteSpace(guid))
  162. {
  163. guid = AppConfig.GetGuid();
  164. lblTitle.Text = "拉货计划单新增";
  165. txtDeliveryPlanNO.Properties.ReadOnly = true;
  166. txtMUSERName.Text = AppConfig.UserName;
  167. txtMTIME.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  168. }
  169. else
  170. {
  171. if (string.IsNullOrWhiteSpace(Version))
  172. lblTitle.Text = "拉货计划单修改";
  173. else
  174. lblTitle.Text = "拉货计划单变更";
  175. txtCustomer.Text = dr["Customer"].ToString();
  176. txtDeliveryPlanNO.Properties.ReadOnly = true;
  177. txtCustomer.Properties.ReadOnly = true;
  178. txtMUSERName.Text = AppConfig.UserName;
  179. txtMTIME.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  180. }
  181. grvDetail.DataSource = dataSource.Tables[1];
  182. grdDetail.BestFitColumns();
  183. }
  184. catch (Exception ex)
  185. {
  186. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  187. }
  188. finally
  189. {
  190. _wait.Close();
  191. }
  192. }
  193. #endregion
  194. DataTable dtInvInfo = new DataTable();
  195. #region 初始化查询条件
  196. private void init()
  197. {
  198. DataSet ds = ICSDeliveryPlanBLL.GetInvInfoAndCust(pk_org_ForInvcode);
  199. #region 存货编码
  200. ////string sql = "SELECT DISTINCT INVCODE AS [存货编码] ,INVNAME AS [存货名称] ,INVSTD AS [规格型号] FROM ICSINVENTORY WHERE WorkPoint='{0}' ORDER BY INVCODE ";
  201. ////sql = string.Format(sql, AppConfig.WorkPointCode);
  202. ////string sql = @"SELECT a.code AS [存货编码] ,a.name AS [存货名称] ,a.materialspec AS [规格型号]
  203. //// FROM bd_material a
  204. //// -- INNER JOIN org_orgs b ON a.pk_org =b.pk_org
  205. //// WHERE a.pk_org='000110100000000005J9' --b.code='Ahwit'
  206. //// ORDER BY a.code
  207. ////
  208. //// SELECT cus.code AS [客户编码],cus.name AS[客户名称] FROM bd_customer cus
  209. //// INNER JOIN org_orgs org ON cus.pk_org=org.pk_org
  210. //// --WHERE org.code='{0}'
  211. //// ORDER BY cus.code";
  212. ////DataSet ds = DBHelper.ExecuteDataset(erp, CommandType.Text, sql);
  213. //txtINVCode.ValueMember = "物料编码";
  214. //txtINVCode.DisplayMember = "物料编码";
  215. //txtINVCode.DataSource = dtInvInfo = ds.Tables[0];
  216. //txtINVCode.NullText = "";//空时的值
  217. //txtINVCode.ImmediatePopup = true;//输入值是否马上弹出窗体
  218. //txtINVCode.ValidateOnEnterKey = true;//回车确认
  219. //txtINVCode.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
  220. //txtINVCode.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  221. ////自适应宽度
  222. //txtINVCode.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  223. #endregion
  224. #region 存货编码
  225. dtSO = ds.Tables[1];
  226. txtSOCode.ValueMember = "表体标识";
  227. txtSOCode.DisplayMember = "表体标识";
  228. txtSOCode.DataSource = dtSO;
  229. txtSOCode.NullText = "";//空时的值
  230. txtSOCode.ImmediatePopup = true;//输入值是否马上弹出窗体
  231. txtSOCode.ValidateOnEnterKey = true;//回车确认
  232. txtSOCode.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
  233. txtSOCode.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  234. //自适应宽度
  235. txtSOCode.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  236. #endregion
  237. #region 客户
  238. // string sql1 = @"SELECT cus.code AS [客户编码],cus.name AS[客户名称] FROM bd_customer cus
  239. // INNER JOIN org_orgs org ON cus.pk_org=org.pk_org
  240. // --WHERE org.code='{0}'
  241. // ORDER BY cus.code";
  242. // sql1 = string.Format(sql1, AppConfig.WorkPointCode);
  243. // DataTable dt1 = DBHelper.ExecuteDataset(erp, CommandType.Text, sql1).Tables[0];
  244. txtCustomer.Properties.ValueMember = "客户编码";
  245. txtCustomer.Properties.DisplayMember = "客户名称";
  246. txtCustomer.Properties.DataSource = ds.Tables[2];
  247. txtCustomer.Properties.NullText = "";//空时的值
  248. txtCustomer.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体
  249. txtCustomer.Properties.ValidateOnEnterKey = true;//回车确认
  250. txtCustomer.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
  251. txtCustomer.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  252. //自适应宽度
  253. txtCustomer.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  254. #endregion
  255. }
  256. #endregion
  257. #region 增行
  258. private void btnAdd_Click(object sender, EventArgs e)
  259. {
  260. try
  261. {
  262. if (dataSource == null || dataSource.Tables.Count != 2)
  263. {
  264. return;
  265. }
  266. DataRow dr = dataSource.Tables[1].NewRow();
  267. dr["Sequence"] = dataSource.Tables[1].Rows.Count+1;
  268. dr["InvCode"] = "";
  269. dr["PreDate"] = DateTime.Now;
  270. dataSource.Tables[1].Rows.Add(dr);
  271. }
  272. catch (Exception ex)
  273. {
  274. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  275. }
  276. }
  277. #endregion
  278. #region 删行
  279. private void btnDelete_Click(object sender, EventArgs e)
  280. {
  281. try
  282. {
  283. if (dataSource == null || dataSource.Tables.Count != 2)
  284. {
  285. return;
  286. }
  287. dataSource.Tables[1].Rows.RemoveAt(grdDetail.FocusedRowHandle);
  288. }
  289. catch (Exception ex)
  290. {
  291. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  292. }
  293. }
  294. #endregion
  295. #region 复制行
  296. private void btnCopy_Click(object sender, EventArgs e)
  297. {
  298. try
  299. {
  300. if (dataSource == null || dataSource.Tables.Count != 2)
  301. {
  302. return;
  303. }
  304. DataRow dr = dataSource.Tables[1].Rows[grdDetail.FocusedRowHandle];
  305. dataSource.Tables[1].Rows.Add(dr.ItemArray);
  306. int index = dataSource.Tables[1].Rows.Count;
  307. //dataSource.Tables[1].Rows[index - 1]["Sequence"] = "";
  308. dataSource.Tables[1].Rows[index - 1]["InvCode"] = "";
  309. dataSource.Tables[1].Rows[index - 1]["materialmnecode"] = "";
  310. }
  311. catch (Exception ex)
  312. {
  313. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  314. }
  315. }
  316. #endregion
  317. private void txtINVCode_EditValueChanged(object sender, EventArgs e)
  318. {
  319. try
  320. {
  321. GridLookUpEdit edit = sender as GridLookUpEdit;
  322. if (edit.EditValue != null && edit.EditValue.ToString() != "" && edit.EditValue.ToString() != "nulltext")
  323. {
  324. var o = edit.Properties.GetRowByKeyValue(edit.EditValue);
  325. if (o is DataRowView)
  326. {
  327. DataRowView RowView = o as DataRowView;
  328. string InvCT = RowView.Row["客户料号"].ToString();
  329. grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, materialmnecode, InvCT);
  330. }
  331. else
  332. {
  333. grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, materialmnecode, "");
  334. }
  335. }
  336. }
  337. catch (Exception ex)
  338. {
  339. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  340. }
  341. }
  342. //选择销售订单事件
  343. private void txtSOCode_EditValueChanged(object sender, EventArgs e)
  344. {
  345. try
  346. {
  347. GridLookUpEdit edit = sender as GridLookUpEdit;
  348. if (edit.EditValue != null && edit.EditValue.ToString() != "" && edit.EditValue.ToString() != "nulltext")
  349. {
  350. var o = edit.Properties.GetRowByKeyValue(edit.EditValue);
  351. if (o is DataRowView)
  352. {
  353. DataRowView RowView = o as DataRowView;
  354. grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, vcooppohcode, RowView.Row["客户订单号"].ToString());
  355. grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, vbillcode, RowView.Row["销售订单号"].ToString());
  356. grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, crowno, RowView.Row["销售订单行号"].ToString());
  357. grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, InvCode, RowView.Row["物料编码"].ToString());
  358. grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, materialmnecode, RowView.Row["客户料号"].ToString());
  359. grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, SOQTY, RowView.Row["数量"].ToString());
  360. grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, Quantity, RowView.Row["数量"].ToString());
  361. }
  362. else
  363. {
  364. grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, vcooppohcode, "");
  365. grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, vbillcode, "");
  366. grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, crowno, "");
  367. grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, InvCode, "");
  368. grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, materialmnecode, "");
  369. grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, SOQTY, "0");
  370. grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, Quantity, "0");
  371. }
  372. }
  373. }
  374. catch (Exception ex)
  375. {
  376. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  377. }
  378. }
  379. private void txtCustomer_EditValueChanged(object sender, EventArgs e)
  380. {
  381. try
  382. {
  383. GridLookUpEdit edit = sender as GridLookUpEdit;
  384. if (edit.EditValue != null && edit.EditValue.ToString() != "" && edit.EditValue.ToString() != "nulltext")
  385. {
  386. var dv = dtSO.DefaultView;
  387. dv.RowFilter = "客户编码='" + edit.EditValue + "'";
  388. //txtSOCode.ValueMember = "表体标识";
  389. //txtSOCode.DisplayMember = "表体标识";
  390. txtSOCode.DataSource = dv;
  391. //txtSOCode.NullText = "";//空时的值
  392. //txtSOCode.ImmediatePopup = true;//输入值是否马上弹出窗体
  393. //txtSOCode.ValidateOnEnterKey = true;//回车确认
  394. //txtSOCode.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
  395. //txtSOCode.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  396. ////自适应宽度
  397. //txtSOCode.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  398. }
  399. }
  400. catch (Exception ex)
  401. {
  402. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  403. }
  404. }
  405. private void txtCustomer_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
  406. {
  407. try
  408. {
  409. GridLookUpEdit edit = sender as GridLookUpEdit;
  410. if (e.OldValue !=null && e.OldValue.ToString() != e.NewValue.ToString() && grdDetail.RowCount>0)
  411. {
  412. DialogResult result=MessageBox.Show("原客户已维护对应的销售订单,是否要删除?", "提示", MessageBoxButtons.YesNo);
  413. if (result == DialogResult.Yes)
  414. {
  415. dataSource.Tables[1].Clear();
  416. }
  417. else
  418. {
  419. e.NewValue = e.OldValue;
  420. }
  421. }
  422. }
  423. catch (Exception ex)
  424. {
  425. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  426. }
  427. }
  428. }
  429. }