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

1088 lines
46 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 System.Data.SqlClient;
  10. using ICSSoft.Frame.Data.BLL;
  11. using ICSSoft.Base.Language.Tool;
  12. using ICSSoft.Base.UserControl.MessageControl;
  13. using ICSSoft.Base.Report.Filter;
  14. using ICSSoft.Base.Config.DBHelper;
  15. using ICSSoft.Base.UserControl.FormControl;
  16. using ICSSoft.Base.ReferForm.AppReferForm;
  17. using ICSSoft.Base.Lable.PrintTool;
  18. using ICSSoft.Base.Config.AppConfig;
  19. using ICSSoft.Base.Report.GridReport;
  20. using ICSSoft.Frame.Data.Entity;
  21. using ICSSoft.Frame.APP;
  22. using System.Net;
  23. using System.IO;
  24. using ICSSoft.Frame.Data.Entity.NcApiEntity;
  25. using Newtonsoft.Json;
  26. using System.Linq;
  27. namespace ICSSoft.Frame.NC
  28. {
  29. public partial class FormICSDeliveryPlan : DevExpress.XtraEditors.XtraForm
  30. {
  31. string pk_org_ForInvcode = "000110100000000005J9";
  32. private string sqltxt = "";
  33. private string sqlconn = "";
  34. String guid = AppConfig.GetGuid();
  35. private DataSet dataSource = null;
  36. //Excel模板
  37. List<FormReadExcelUIModelColumns> colNameList = new List<FormReadExcelUIModelColumns>();
  38. #region 构造函数
  39. public FormICSDeliveryPlan()
  40. {
  41. InitializeComponent();
  42. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  43. this.WindowState = FormWindowState.Maximized;
  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 SystemOptition
  77. /// <summary>
  78. /// 操作权限
  79. /// </summary>
  80. /// <returns></returns>
  81. public DataTable RightOfExute()
  82. {
  83. DataTable rData = new DataTable();
  84. rData.Columns.Add("BtnName");
  85. rData.Columns.Add("ActionName");
  86. //查看权限(必须有)
  87. DataRow seeRow = rData.NewRow();
  88. seeRow["BtnName"] = "see";
  89. seeRow["ActionName"] = "查看";
  90. rData.Rows.Add(seeRow);
  91. foreach (Control ctr in panelControl3.Controls)
  92. {
  93. if (ctr.Name == btnFilter.Name || ctr.Name == btnConfig.Name ||
  94. ctr.Name == btnSelect.Name || ctr.Name == btnCanSelect.Name ||
  95. ctr.Name == btnImportMould.Name || ctr.Name == btnOutPut.Name ||
  96. ctr.Name == btnFalsh.Name || ctr.Name == btnExit.Name || ctr.Name == lblTitle.Name || ctr.Name == btnClose.Name)
  97. continue;
  98. DataRow dr = rData.NewRow();
  99. dr["BtnName"] = ctr.Name;
  100. dr["ActionName"] = ctr.Text;
  101. rData.Rows.Add(dr);
  102. }
  103. //List<Control> ControlList = new List<Control>();
  104. //ControlList.Add(btnConfig);
  105. //ControlList.Add(btnAdd);
  106. //ControlList.Add(btnEdit);
  107. //ControlList.Add(btnDelLable);
  108. //foreach (Control ctr in ControlList)
  109. //{
  110. // if (ctr.GetType() == typeof(SimpleButton))
  111. // {
  112. // DataRow dr = rData.NewRow();
  113. // dr["BtnName"] = ctr.Name;
  114. // dr["ActionName"] = ctr.Text;
  115. // rData.Rows.Add(dr);
  116. // }
  117. //}
  118. rData.AcceptChanges();
  119. return rData;
  120. }
  121. /// <summary>
  122. /// 数据权限
  123. /// </summary>
  124. /// <returns></returns>
  125. public DataTable RightOfData()
  126. {
  127. DataTable rData = new DataTable();
  128. rData.Columns.Add("BodyName");
  129. rData.Columns.Add("ControlName");
  130. rData.Columns.Add("ControlCaption");
  131. rData.AcceptChanges();
  132. return rData;
  133. }
  134. #endregion
  135. #region 退出
  136. private void btnClose_Click(object sender, EventArgs e)
  137. {
  138. AppConfig.CloseFormShow(this.Text);
  139. this.Close();
  140. }
  141. private void btnExit_Click(object sender, EventArgs e)
  142. {
  143. AppConfig.CloseFormShow(this.Text);
  144. this.Close();
  145. }
  146. #endregion
  147. #region 过滤
  148. private string tempTableName = "";
  149. private void btnFilter_Click(object sender, EventArgs e)
  150. {
  151. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  152. filter.OldTempTableName = tempTableName;
  153. if (filter.ShowDialog() == DialogResult.OK)
  154. {
  155. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  156. try
  157. {
  158. _wait.Show();
  159. tempTableName = filter.NewTempTableName;
  160. sqltxt = filter.SqlText;
  161. sqlconn = filter.FilterConnectString;
  162. dataSource = filter.FilterData;
  163. //DataRelation dr = new DataRelation("详情", new DataColumn[] { dataSource.Tables[0].Columns["ID"] }, new DataColumn[] { dataSource.Tables[1].Columns["DeliveryPlanID"] }, false);
  164. //dataSource.Relations.Add(dr);
  165. grdDetail.DataSource = dataSource.Tables[0];
  166. grvDetail.BestFitColumns();
  167. gridView.BestFitColumns();
  168. rptPage.RecordNum = dataSource.Tables[0].Rows.Count;
  169. rptPage.PageSize = 490;
  170. rptPage.PageIndex = 1;
  171. rptPage.ReLoad();
  172. rptPage.PageIndex = 1;
  173. rptPage.PageSize = 500;
  174. rptPage.ReLoad();
  175. _wait.Close();
  176. }
  177. catch (Exception ex)
  178. {
  179. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  180. _wait.Close();
  181. }
  182. }
  183. }
  184. #endregion
  185. #region 全选
  186. private void btnSelect_Click(object sender, EventArgs e)
  187. {
  188. grvDetail.PostEditor();
  189. this.Validate();
  190. for (int i = 0; i < grvDetail.RowCount; i++)
  191. {
  192. grvDetail.SetRowCellValue(i, colisSelect, true);
  193. }
  194. }
  195. #endregion
  196. #region 全消
  197. private void btnCanSelect_Click(object sender, EventArgs e)
  198. {
  199. grvDetail.PostEditor();
  200. this.Validate();
  201. for (int i = 0; i < grvDetail.RowCount; i++)
  202. {
  203. grvDetail.SetRowCellValue(i, colisSelect, false);
  204. }
  205. }
  206. #endregion
  207. #region 刷新
  208. private void btnFalsh_Click(object sender, EventArgs e)
  209. {
  210. if (sqlconn == null || sqlconn == "")
  211. {
  212. return;
  213. }
  214. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  215. try
  216. {
  217. _wait.Show();
  218. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  219. filter.OldTempTableName = tempTableName;
  220. //tempTableName = filter.NewTempTableName;
  221. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  222. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt);
  223. grdDetail.DataSource = dataSource.Tables[0];
  224. rptPage.RecordNum = dataSource.Tables[0].Rows.Count;
  225. rptPage.PageIndex = 1;
  226. rptPage.ReLoad();
  227. _wait.Close();
  228. }
  229. catch (Exception ex)
  230. {
  231. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  232. _wait.Close();
  233. }
  234. }
  235. #endregion
  236. #region 列表
  237. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  238. {
  239. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  240. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  241. }
  242. #endregion
  243. #region 绑定数据源
  244. private void btnConfig_Click(object sender, EventArgs e)//绑定数据源
  245. {
  246. if (AppConfig.UserCode.ToLower() != "demo")
  247. {
  248. //ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  249. return;
  250. }
  251. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  252. fdata.ShowDialog();
  253. }
  254. #endregion
  255. #region 分页
  256. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  257. {
  258. try
  259. {
  260. if (dataSource == null || dataSource.Tables.Count != 3)
  261. {
  262. return;
  263. }
  264. DataSet ds = new DataSet();
  265. DataTable data = AppConfig.GetPageData(dataSource.Tables[0], rptPage.PageIndex, rptPage.PageSize).Copy();
  266. ds.Tables.Add(data);
  267. ds.Tables.Add(dataSource.Tables[1].Copy());
  268. DataRelation dr = new DataRelation("详情", new DataColumn[] { ds.Tables[0].Columns["ID"] }, new DataColumn[] { ds.Tables[1].Columns["DeliveryPlanID"] }, false);
  269. ds.Relations.Add(dr);
  270. grdDetail.DataSource = data;
  271. //gridExport.DataSource = dataSource.Tables[2];
  272. }
  273. catch (Exception ex)
  274. {
  275. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  276. }
  277. }
  278. #endregion
  279. #region 加载
  280. private void FormICSFACTORY_Load(object sender, EventArgs e)
  281. {
  282. //colNameList.Add(new FormReadExcelUIModelColumns("单据号", true));
  283. //colNameList.Add(new FormReadExcelUIModelColumns("行号", true));
  284. colNameList.Add(new FormReadExcelUIModelColumns("客户编码", true));
  285. colNameList.Add(new FormReadExcelUIModelColumns("物料编码", true));
  286. colNameList.Add(new FormReadExcelUIModelColumns("数量", true));
  287. colNameList.Add(new FormReadExcelUIModelColumns("客户订单号", false));
  288. //colNameList.Add(new FormReadExcelUIModelColumns("销售订单行号", false));
  289. colNameList.Add(new FormReadExcelUIModelColumns("要求交期", true));
  290. btnFilter_Click(sender, e);
  291. }
  292. #endregion
  293. #region 增加
  294. private void btnAdd_Click(object sender, EventArgs e)
  295. {
  296. try
  297. {
  298. SimpleButton btntemp = (SimpleButton)sender;
  299. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  300. {
  301. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  302. return;
  303. }
  304. FormICSDeliveryPlanEdit add = new FormICSDeliveryPlanEdit();
  305. add.ShowDialog();
  306. btnFalsh_Click(null, null);
  307. }
  308. catch (Exception ex)
  309. {
  310. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  311. }
  312. }
  313. #endregion
  314. #region 修改
  315. private void btnEdit_Click(object sender, EventArgs e)
  316. {
  317. try
  318. {
  319. SimpleButton btntemp = (SimpleButton)sender;
  320. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  321. {
  322. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  323. return;
  324. }
  325. int count = 0;
  326. string id = "";
  327. for (int i = 0; i < grvDetail.RowCount; i++)
  328. {
  329. if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect)))
  330. {
  331. count++;
  332. id = grvDetail.GetRowCellValue(i, colID).ToString();
  333. if (!string.IsNullOrWhiteSpace(grvDetail.GetRowCellValue(i, colChecker).ToString()))
  334. throw new Exception("单据已审核,不能修改!");
  335. }
  336. }
  337. if (count != 1)
  338. {
  339. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  340. return;
  341. }
  342. try
  343. {
  344. FormICSDeliveryPlanEdit add = new FormICSDeliveryPlanEdit(id);
  345. add.ShowDialog();
  346. btnFalsh_Click(null, null);
  347. }
  348. catch (Exception ex)
  349. {
  350. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  351. }
  352. }
  353. catch (Exception ex)
  354. {
  355. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  356. }
  357. }
  358. #endregion
  359. #region 删除
  360. private void btnDel_Click(object sender, EventArgs e)
  361. {
  362. try
  363. {
  364. SimpleButton btntemp = (SimpleButton)sender;
  365. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  366. {
  367. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  368. return;
  369. }
  370. List<string> IDList = new List<string>();
  371. for (int i = 0; i < grvDetail.RowCount; i++)
  372. {
  373. if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect)))
  374. {
  375. IDList.Add(grvDetail.GetRowCellValue(i, colID).ToString());
  376. if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colUploadErp)))
  377. throw new Exception("单据:" + grvDetail.GetRowCellValue(i, colDeliveryPlanNO).ToString() + " 已上传,不能删除!");
  378. }
  379. }
  380. if (IDList == null || IDList.Count == 0)
  381. {
  382. ICSBaseSimpleCode.AppshowMessageBox("请选择数据");
  383. return;
  384. }
  385. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除吗?删除后无法恢复,确定吗?") != DialogResult.OK)
  386. {
  387. return;
  388. }
  389. ICSDeliveryPlanBLL.deleteInfo(IDList, AppConfig.AppConnectString);
  390. ICSBaseSimpleCode.AppshowMessageBox("删除成功");
  391. btnFalsh_Click(null, null);
  392. }
  393. catch (Exception ex)
  394. {
  395. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  396. }
  397. }
  398. #endregion
  399. #region 导出
  400. private void btnOutPut_Click(object sender, EventArgs e)
  401. {
  402. try
  403. {
  404. DataTable data = dataSource.Tables[2].Copy();
  405. gridExport.DataSource = data;
  406. grivExport.OptionsPrint.AutoWidth = false;
  407. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), gridExport);
  408. foe.ShowDialog();
  409. }
  410. catch (Exception ex)
  411. {
  412. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  413. }
  414. }
  415. #endregion
  416. #region 导入
  417. private void btnImportData_Click(object sender, EventArgs e)
  418. {
  419. SimpleButton btntemp = (SimpleButton)sender;
  420. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  421. {
  422. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  423. return;
  424. }
  425. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm();
  426. _wait.Hide();
  427. try
  428. {
  429. FormReadExcel fre = new FormReadExcel();
  430. if (fre.ShowDialog() != DialogResult.OK)
  431. {
  432. return;
  433. }
  434. DataTable dataSource = fre._excelData;
  435. if (dataSource == null)
  436. {
  437. throw new Exception("excel数据取得失败");
  438. }
  439. _wait.Show();
  440. _wait.Caption = "模板校验中......";
  441. #region 判断模版是否正确
  442. foreach (FormReadExcelUIModelColumns columnsName in colNameList)
  443. {
  444. if (!dataSource.Columns.Contains(columnsName.columnsName))
  445. {
  446. throw new Exception("模版不正确,缺少列" + columnsName.columnsName);
  447. }
  448. }
  449. #endregion
  450. _wait.SetCaption("数据校验中......");
  451. //1获取助记码(客户料号),客户编码
  452. DataSet ds = ICSDeliveryPlanBLL.GetInvInfoAndCust(pk_org_ForInvcode);
  453. #region 处理已经生成拉货计划的销售订单
  454. DataTable dt = ds.Tables[1].Copy();
  455. //在GetInvInfoAndCust方法中已生成的已经被排除,此处不需要2022.3.29
  456. ////DataRow[] drso = dataSource.Select("LEN(ISNULL(销售订单号,''))<=0");
  457. ////if (drso != null && drso.Length > 0)
  458. ////{
  459. // //var Vourchs = (from DataRow dr in dataSource.Rows
  460. // // group dr by (string)dr["单据号"] into g
  461. // // select new
  462. // // {
  463. // // g.Key
  464. // // }).Select(a=>a.Key);
  465. // string vourchs = "";
  466. // //if (Vourchs != null && Vourchs.Count() > 0)
  467. // //{
  468. // // vourchs = string.Join("','", Vourchs);
  469. // //}
  470. // DataTable dtPlan = ICSDeliveryPlanBLL.GetPlanInfo(vourchs).Tables[0];
  471. // foreach (DataRow dr in dtPlan.Rows)
  472. // {
  473. // string id = dr["SOCode"].ToString();
  474. // decimal qty = Convert.ToDecimal(dr["Quantity"]);
  475. // DataRow[] SOdrs = dt.Select("表体标识='" + id + "'", "要求交期,销售订单号,销售订单行号");
  476. // foreach (DataRow SOdr in SOdrs)
  477. // {
  478. // decimal SOqty = Convert.ToDecimal(SOdr["数量"]);
  479. // //已生成数量大于销售订单行数量
  480. // if (qty >= SOqty)
  481. // {
  482. // qty -= SOqty;
  483. // dt.Rows.Remove(SOdr);
  484. // }
  485. // else
  486. // {
  487. // SOdr["数量"] = SOqty - qty;
  488. // break;
  489. // }
  490. // }
  491. // }
  492. ////}
  493. #endregion
  494. DataColumn dataColumn = new DataColumn("客户名称", typeof(string));
  495. dataSource.Columns.Add(dataColumn);
  496. //2校验
  497. string CT = "";
  498. string SOCode = "";
  499. string inv = "";
  500. for (int i = dataSource.Rows.Count - 1; i >= 0; i--)
  501. {
  502. DataRow dr=dataSource.Rows[i];
  503. ///判断必输项目是否为空
  504. foreach (FormReadExcelUIModelColumns columnsName in colNameList)
  505. {
  506. if (string.IsNullOrWhiteSpace(dr[columnsName.columnsName].ToString()) == true && columnsName.NotNull == true)
  507. {
  508. throw new Exception("列" + columnsName.columnsName + "没有输入值");
  509. }
  510. }
  511. inv = dr["物料编码"].ToString().Trim();
  512. //string so = dr["销售订单号"].ToString().Trim();
  513. //SOCode = so + "_" + dr["销售订单行号"].ToString().Trim();
  514. SOCode = dr["客户订单号"].ToString().Trim();
  515. CT = dr["客户编码"].ToString().Trim();
  516. if (string.IsNullOrEmpty(inv))
  517. {
  518. throw new Exception("行 " + (i + 1).ToString() + " 物料编码为空");
  519. }
  520. if (string.IsNullOrEmpty(CT))
  521. {
  522. throw new Exception("行 " + (i + 1).ToString() + " 客户编码为空");
  523. }
  524. if (ds.Tables[0].Select("物料编码='" + inv + "'").Length == 0)
  525. {
  526. throw new Exception("物料编码:" + inv + ",不存在");
  527. }
  528. var cus = ds.Tables[2].Select("客户编码='" + CT + "'");
  529. if (cus.Length == 0)
  530. {
  531. throw new Exception("客户编码:" + CT + ",不存在");
  532. }
  533. else
  534. {
  535. dataSource.Rows[i]["客户名称"] = cus[0]["客户名称"];
  536. }
  537. //21.11.10销售订单为空时自动根据交期匹配
  538. decimal qty = Convert.ToDecimal(dr["数量"]);
  539. if (string.IsNullOrWhiteSpace(SOCode))
  540. {
  541. DataRow[] SOdrs = dt.Select("物料编码+客户编码='" + inv + CT + "'", "要求交期,销售订单号,销售订单行号");
  542. SO(dataSource,dt,SOdrs,dr,qty);
  543. }
  544. else
  545. {
  546. DataRow[] SOdrs = dt.Select("物料编码+客户编码+客户订单号='" + inv + CT + SOCode + "'", "要求交期,销售订单号,销售订单行号");
  547. SO(dataSource, dt, SOdrs, dr, qty);
  548. //DataRow[] drs = dt.Select("销售订单号+'_'+销售订单行号='" + SOCode + "'");
  549. //if (drs == null || drs.Length == 0)
  550. //{
  551. // throw new Exception("销售订单:" + SOCode + ",不存在");
  552. //}
  553. //else if (CT != drs[0]["客户编码"].ToString())
  554. //{
  555. // throw new Exception("销售订单:" + SOCode + ",对应的客户编码与所填写客户编码:" + CT + " 不符!");
  556. //}
  557. //else if (qty > Convert.ToDecimal(drs[0]["数量"]))
  558. //{
  559. // throw new Exception("销售订单:" + SOCode + ",剩余数量:" + drs[0]["数量"] + ",不能小于填写数量:" + qty);
  560. //}
  561. //else
  562. //{
  563. // drs[0]["数量"] = Convert.ToDecimal(drs[0]["数量"]) - qty;
  564. // dr["销售订单号"] = drs[0]["表体标识"].ToString();
  565. //}
  566. }
  567. }
  568. _wait.SetCaption("数据处理中......");
  569. ICSDeliveryPlanBLL.AddList(dataSource, AppConfig.AppConnectString);
  570. _wait.Close();
  571. ICSBaseSimpleCode.AppshowMessageBox("数据导入成功!");
  572. btnFalsh_Click(null, null);
  573. }
  574. catch (Exception ex)
  575. {
  576. _wait.Close();
  577. ICSBaseSimpleCode.AppshowMessageBox("数据导入失败:" + ex.Message);
  578. }
  579. }
  580. private void SO(DataTable dataSource,DataTable dt, DataRow[] SOdrs, DataRow dr, decimal qty)
  581. {
  582. foreach (DataRow SOdr in SOdrs)
  583. {
  584. decimal SOqty = Convert.ToDecimal(SOdr["数量"]);
  585. //已生成数量大于销售订单行数量
  586. if (qty >= SOqty)
  587. {
  588. qty -= SOqty;
  589. string id = SOdr["表体标识"].ToString();
  590. dt.Rows.Remove(SOdr);
  591. if (qty == 0)
  592. {
  593. dr["客户订单号"] = id;
  594. break;
  595. }
  596. else
  597. {
  598. DataRow drnew = dataSource.NewRow();
  599. drnew.ItemArray = dr.ItemArray;
  600. //drnew["行号"] = dataSource.Rows.Count + 1;
  601. drnew["数量"] = SOqty;
  602. drnew["客户订单号"] = id;
  603. dataSource.Rows.Add(drnew);
  604. dr["数量"] = qty;
  605. }
  606. }
  607. else
  608. {
  609. SOdr["数量"] = SOqty - qty;
  610. qty = 0;
  611. dr["客户订单号"] = SOdr["表体标识"].ToString();
  612. break;
  613. }
  614. }
  615. //if (qty > 0)
  616. //{
  617. // throw new Exception("客户编码:" + CT + ",物料编码:" + inv + ",对应的销售订单数量不足!");
  618. //}
  619. }
  620. #endregion
  621. #region 导入模板下载
  622. private void btnImportMould_Click(object sender, EventArgs e)
  623. {
  624. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm();
  625. _wait.Hide();
  626. string anjianExcelFileName = Environment.CommandLine.Substring(1, Environment.CommandLine.LastIndexOf("\\")) + "Output\\";
  627. try
  628. {
  629. _wait.Show();
  630. _wait.Caption = "模板下载中......";
  631. SaveFileDialog dlgSaveFileDialog = new SaveFileDialog(); //弹框提示保存
  632. dlgSaveFileDialog.InitialDirectory = anjianExcelFileName; //默认打开目录
  633. dlgSaveFileDialog.FilterIndex = 1;
  634. dlgSaveFileDialog.RestoreDirectory = true;
  635. dlgSaveFileDialog.FileName = "拉货计划单导入模板.xlsx"; //默认保存名称
  636. dlgSaveFileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx";
  637. if (dlgSaveFileDialog.ShowDialog() == DialogResult.OK)
  638. {
  639. string fileName = dlgSaveFileDialog.FileName; //获取弹出框选择或填写的文件名称
  640. //List<FormReadExcelUIModelColumns> colNameList = new List<FormReadExcelUIModelColumns>();
  641. //colNameList.Add(new FormReadExcelUIModelColumns("单据号", true));
  642. //colNameList.Add(new FormReadExcelUIModelColumns("客户编码", true));
  643. //colNameList.Add(new FormReadExcelUIModelColumns("客户料号", true));
  644. //DataTable dt = GetMonth();
  645. //foreach (DataRow dr in dt.Rows)
  646. //{
  647. // colNameList.Add(new FormReadExcelUIModelColumns(dr[0].ToString(), false));
  648. //}
  649. FileUtil.exportToExcelFile(fileName, colNameList);
  650. _wait.Close();
  651. ICSBaseSimpleCode.AppshowMessageBox("模板下载成功!");
  652. }
  653. _wait.Close();
  654. }
  655. catch (Exception ex)
  656. {
  657. _wait.Close();
  658. ICSBaseSimpleCode.AppshowMessageBox("模板下载失败:" + ex.Message);
  659. }
  660. }
  661. #endregion
  662. #region 审核
  663. private void btnCheck_Click(object sender, EventArgs e)
  664. {
  665. try
  666. {
  667. SimpleButton btntemp = (SimpleButton)sender;
  668. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  669. {
  670. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  671. return;
  672. }
  673. List<string> IDList = new List<string>();
  674. for (int i = 0; i < grvDetail.RowCount; i++)
  675. {
  676. if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect)))
  677. {
  678. IDList.Add(grvDetail.GetRowCellValue(i, colID).ToString());
  679. }
  680. }
  681. if (IDList == null || IDList.Count == 0)
  682. {
  683. ICSBaseSimpleCode.AppshowMessageBox("请选择数据");
  684. return;
  685. }
  686. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定审核吗?") != DialogResult.OK)
  687. {
  688. return;
  689. }
  690. ICSDeliveryPlanBLL.Check(IDList, AppConfig.AppConnectString);
  691. ICSBaseSimpleCode.AppshowMessageBox("审核成功");
  692. btnFalsh_Click(null, null);
  693. }
  694. catch (Exception ex)
  695. {
  696. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  697. }
  698. }
  699. #endregion
  700. #region 弃审
  701. private void btBack_Click(object sender, EventArgs e)
  702. {
  703. try
  704. {
  705. SimpleButton btntemp = (SimpleButton)sender;
  706. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  707. {
  708. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  709. return;
  710. }
  711. List<string> IDList = new List<string>();
  712. for (int i = 0; i < grvDetail.RowCount; i++)
  713. {
  714. if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect)))
  715. {
  716. IDList.Add(grvDetail.GetRowCellValue(i, colID).ToString());
  717. }
  718. }
  719. if (IDList == null || IDList.Count == 0)
  720. {
  721. ICSBaseSimpleCode.AppshowMessageBox("请选择数据");
  722. return;
  723. }
  724. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定弃审吗?") != DialogResult.OK)
  725. {
  726. return;
  727. }
  728. ICSDeliveryPlanBLL.RefuseCheck(IDList, AppConfig.AppConnectString);
  729. ICSBaseSimpleCode.AppshowMessageBox("弃审成功");
  730. btnFalsh_Click(null, null);
  731. }
  732. catch (Exception ex)
  733. {
  734. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  735. }
  736. }
  737. #endregion
  738. #region 复审
  739. private void btnReview_Click(object sender, EventArgs e)
  740. {
  741. try
  742. {
  743. SimpleButton btntemp = (SimpleButton)sender;
  744. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  745. {
  746. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  747. return;
  748. }
  749. List<string> IDList = new List<string>();
  750. for (int i = 0; i < grvDetail.RowCount; i++)
  751. {
  752. if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect)))
  753. {
  754. IDList.Add(grvDetail.GetRowCellValue(i, colID).ToString());
  755. }
  756. }
  757. if (IDList == null || IDList.Count == 0)
  758. {
  759. ICSBaseSimpleCode.AppshowMessageBox("请选择数据");
  760. return;
  761. }
  762. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定复审吗?") != DialogResult.OK)
  763. {
  764. return;
  765. }
  766. ICSDeliveryPlanBLL.Review(IDList, AppConfig.AppConnectString);
  767. ICSBaseSimpleCode.AppshowMessageBox("复审成功");
  768. btnFalsh_Click(null, null);
  769. }
  770. catch (Exception ex)
  771. {
  772. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  773. }
  774. }
  775. #endregion
  776. #region 取消复审
  777. private void btnReviewBack_Click(object sender, EventArgs e)
  778. {
  779. try
  780. {
  781. SimpleButton btntemp = (SimpleButton)sender;
  782. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  783. {
  784. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  785. return;
  786. }
  787. List<string> IDList = new List<string>();
  788. for (int i = 0; i < grvDetail.RowCount; i++)
  789. {
  790. if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect)))
  791. {
  792. IDList.Add(grvDetail.GetRowCellValue(i, colID).ToString());
  793. if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colUploadErp)))
  794. throw new Exception("单据:" + grvDetail.GetRowCellValue(i, colDeliveryPlanNO).ToString() + " 已上传,不能取消复审!");
  795. }
  796. }
  797. if (IDList == null || IDList.Count == 0)
  798. {
  799. ICSBaseSimpleCode.AppshowMessageBox("请选择数据");
  800. return;
  801. }
  802. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定取消复审吗?") != DialogResult.OK)
  803. {
  804. return;
  805. }
  806. ICSDeliveryPlanBLL.ReviewBack(IDList, AppConfig.AppConnectString);
  807. ICSBaseSimpleCode.AppshowMessageBox("取消复审成功");
  808. btnFalsh_Click(null, null);
  809. }
  810. catch (Exception ex)
  811. {
  812. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  813. }
  814. }
  815. #endregion
  816. #region 子表展开
  817. private void grvDetail_MasterRowExpanded(object sender, DevExpress.XtraGrid.Views.Grid.CustomMasterRowEventArgs e)
  818. {
  819. //try
  820. //{
  821. // //只展开当前行
  822. // for (int i = 0; i < grvDetail.RowCount; i++)
  823. // {
  824. // if (i != e.RowHandle)
  825. // {
  826. // grvDetail.SetMasterRowExpanded(i, false);
  827. // }
  828. // }
  829. // //隐藏由于行列转换出现的null字段
  830. // gridView = grvDetail.GetDetailView(e.RowHandle, e.RelationIndex) as DevExpress.XtraGrid.Views.Grid.GridView;
  831. // foreach (DevExpress.XtraGrid.Columns.GridColumn col in gridView.Columns)
  832. // {
  833. // if (!col.FieldName.Contains("-"))
  834. // continue;
  835. // for (int i = 0; i < gridView.RowCount; i++)
  836. // {
  837. // if (string.IsNullOrEmpty(gridView.GetRowCellValue(i, col).ToString()))
  838. // {
  839. // col.Visible = false;
  840. // }
  841. // else
  842. // {
  843. // col.Visible = true;
  844. // }
  845. // }
  846. // }
  847. // gridView.Columns["DeliveryPlanID"].Visible = false;
  848. // gridView.Columns["InvCode"].Caption = "物料编码";
  849. // gridView.Columns["materialmnecode"].Caption = "客户料号";
  850. // gridView.Columns["安全库存数量"].VisibleIndex = 2;
  851. // gridView.Columns["之前欠缺数量"].VisibleIndex = 3;
  852. // gridView.BestFitColumns();
  853. //}
  854. //catch (Exception ex)
  855. //{
  856. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  857. //}
  858. }
  859. #endregion
  860. #region 变更
  861. private void btnVersion_Click(object sender, EventArgs e)
  862. {
  863. try
  864. {
  865. SimpleButton btntemp = (SimpleButton)sender;
  866. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  867. {
  868. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  869. return;
  870. }
  871. int count = 0;
  872. string id = "";
  873. for (int i = 0; i < grvDetail.RowCount; i++)
  874. {
  875. if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect)))
  876. {
  877. count++;
  878. id = grvDetail.GetRowCellValue(i, colID).ToString();
  879. if (string.IsNullOrWhiteSpace(grvDetail.GetRowCellValue(i, colChecker).ToString()))
  880. throw new Exception("单据未审核,不能变更!");
  881. //if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colUploadErp)))
  882. // throw new Exception("单据:" + grvDetail.GetRowCellValue(i, colDeliveryPlanNO).ToString() + " 已上传,不能变更!");
  883. }
  884. }
  885. if (count != 1)
  886. {
  887. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  888. return;
  889. }
  890. try
  891. {
  892. FormICSDeliveryPlanEdit add = new FormICSDeliveryPlanEdit(id, "Version");
  893. add.ShowDialog();
  894. btnFalsh_Click(null, null);
  895. }
  896. catch (Exception ex)
  897. {
  898. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  899. }
  900. }
  901. catch (Exception ex)
  902. {
  903. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  904. }
  905. }
  906. #endregion
  907. #region 上传ERP
  908. private void btnUpload_Click(object sender, EventArgs e)
  909. {
  910. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在上传...请稍等...");
  911. try
  912. {
  913. SimpleButton btntemp = (SimpleButton)sender;
  914. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  915. {
  916. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  917. _wait.Close();
  918. return;
  919. }
  920. _wait.Show();
  921. string ids = "";
  922. for (int i = 0; i < grvDetail.RowCount; i++)
  923. {
  924. if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect)))
  925. {
  926. string dcode = grvDetail.GetRowCellValue(i, colDeliveryPlanNO).ToString();
  927. ids = "'" + grvDetail.GetRowCellValue(i, colID).ToString() + "',";
  928. //if (string.IsNullOrWhiteSpace(grvDetail.GetRowCellValue(i, colReviewer).ToString()))
  929. // throw new Exception(dcode + "单据未复审,不能上传!");
  930. if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colUploadErp)))
  931. throw new Exception(dcode + "单据已上传,不能重复上传!");
  932. }
  933. }
  934. ids = ids.TrimEnd(',');
  935. if (string.IsNullOrWhiteSpace(ids))
  936. {
  937. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!!!");
  938. _wait.Close();
  939. return;
  940. }
  941. ICSDeliveryPlanBLL.UploadErp(ids, AppConfig.AppConnectString);
  942. _wait.Close();
  943. ICSBaseSimpleCode.AppshowMessageBox("上传成功");
  944. btnFalsh_Click(null, null);
  945. #region old
  946. // string sql = @"SELECT InvCode,Period,SUM(Quantity) AS Quantity
  947. // FROM ICSDeliveryPlanDetail
  948. // WHERE Quantity>0 AND DeliveryPlanID IN ({0})
  949. // GROUP BY InvCode,Period";
  950. // sql = string.Format(sql, ids.TrimEnd(','));
  951. // DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  952. // NcApiInputArguments inputInfo = new NcApiInputArguments();
  953. // inputInfo.datasource = "design";
  954. // inputInfo.usercode = "mestoerp";// AppConfig.UserCode;
  955. // inputInfo.password = "sH05R21u1";// AppConfig.FromMd5(AppConfig.UserPwd);
  956. // inputInfo.list = new List<object>();
  957. // inputInfo.list.Clear();
  958. // foreach (DataRow dr in dt.Rows)
  959. // {
  960. // string[] period = dr["Period"].ToString().Split('-');
  961. // if (period == null || period.Length != 2)
  962. // continue;
  963. // CreateDeliveryPlanEntity DeliveryPlan = new CreateDeliveryPlanEntity();
  964. // DeliveryPlan.pk_org = "01P1";//AppConfig.WorkPointCode;
  965. // DateTime time = Convert.ToDateTime(dr["Period"].ToString() + "-01");
  966. // DeliveryPlan.cbegindate = time.ToString("yyyy-MM-dd");
  967. // DeliveryPlan.cenddate = time.AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd");
  968. // DeliveryPlan.periodyear = period[0];
  969. // DeliveryPlan.periodcode = Convert.ToInt32(period[1]).ToString();
  970. // DeliveryPlan.vchangerate = "1/1";
  971. // DeliveryPlan.cmaterialid = dr["InvCode"].ToString();
  972. // DeliveryPlan.nnum = dr["Quantity"].ToString();
  973. // inputInfo.list.Add(DeliveryPlan);
  974. // }
  975. // string inputJson = JsonConvert.SerializeObject(inputInfo);
  976. // string resStrCreatDeliveryPlan = HttpPost(urlCreatDeliveryPlan, inputJson);
  977. // NcApiOutArguments res = new NcApiOutArguments();
  978. // res = JsonConvert.DeserializeObject<NcApiOutArguments>(resStrCreatDeliveryPlan);
  979. // if (res.flat != "0")
  980. // {
  981. // throw new Exception("生成预测单失败:" + res.list_info);
  982. // }
  983. // else
  984. // {
  985. // ICSBaseSimpleCode.AppshowMessageBox("上传成功");
  986. // //btnFalsh_Click(null, null);
  987. // }
  988. #endregion
  989. }
  990. catch (Exception ex)
  991. {
  992. _wait.Close();
  993. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  994. }
  995. }
  996. public static string HttpPost(string url, string body)
  997. {
  998. try
  999. {
  1000. Encoding encoding = Encoding.UTF8;
  1001. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  1002. request.Method = "POST";
  1003. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  1004. request.ContentType = "application/json; charset=utf-8";
  1005. byte[] buffer = encoding.GetBytes(body);
  1006. request.ContentLength = buffer.Length;
  1007. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  1008. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  1009. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  1010. {
  1011. return reader.ReadToEnd();
  1012. }
  1013. }
  1014. catch (WebException ex)
  1015. {
  1016. throw new Exception(ex.Message);
  1017. }
  1018. }
  1019. #endregion
  1020. }
  1021. }