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

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