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

661 lines
26 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.Linq;
  6. using System.Linq;
  7. using System.Drawing;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using DevExpress.XtraEditors;
  11. using DevExpress.XtraGrid.Views.BandedGrid;
  12. using DevExpress.XtraGrid.Columns;
  13. using DevExpress.XtraGrid;
  14. using System.IO;
  15. using System.Threading;
  16. using ICSSoft.Base.Language.Tool;
  17. using ICSSoft.Base.Config.AppConfig;
  18. using ICSSoft.Base.UserControl.MessageControl;
  19. using ICSSoft.Base.Config.DBHelper;
  20. using ICSSoft.Base.Report.Filter;
  21. using ICSSoft.Base.UserControl.FormControl;
  22. using ICSSoft.Base.Report.GridReport;
  23. using ICSSoft.Base.ReferForm.AppReferForm;
  24. using ICSSoft.Frame.Data.BLL;
  25. using ICSSoft.Frame.Data.Entity;
  26. using ICSSoft.Frame.Data.DAL;
  27. namespace ICSSoft.Frame.APP
  28. {
  29. public partial class FormPhysicalInventoryERP : DevExpress.XtraEditors.XtraForm
  30. {
  31. private string sqltxt = "";
  32. private string sqlconn = "";
  33. string path = "";
  34. List<string> barList = new List<string>();
  35. string errorBar = "";
  36. String guid = AppConfig.GetGuid();
  37. private DataTable dataSource = null;
  38. private DataTable BodySource = null;
  39. DataSet ds = new DataSet();
  40. DataTable HandDt;
  41. DataTable BodyDt;
  42. #region 构造函数
  43. public FormPhysicalInventoryERP()
  44. {
  45. InitializeComponent();
  46. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  47. this.WindowState = FormWindowState.Maximized;
  48. }
  49. #endregion
  50. #region SystemOptition
  51. /// <summary>
  52. /// 操作权限
  53. /// </summary>
  54. /// <returns></returns>
  55. public DataTable RightOfExute()
  56. {
  57. DataTable rData = new DataTable();
  58. rData.Columns.Add("BtnName");
  59. rData.Columns.Add("ActionName");
  60. //查看权限(必须有)
  61. DataRow seeRow = rData.NewRow();
  62. seeRow["BtnName"] = "see";
  63. seeRow["ActionName"] = "查看";
  64. rData.Rows.Add(seeRow);
  65. List<Control> ControlList = new List<Control>();
  66. //ControlList.Add(btnCreate);
  67. ControlList.Add(simpleButton1);
  68. ControlList.Add(btnERPQty);
  69. ControlList.Add(btnDel);
  70. ControlList.Add(btnOutPut);
  71. ControlList.Add(btnCheckIn);
  72. foreach (Control ctr in ControlList)
  73. {
  74. if (ctr.GetType() == typeof(SimpleButton))
  75. {
  76. DataRow dr = rData.NewRow();
  77. dr["BtnName"] = ctr.Name;
  78. dr["ActionName"] = ctr.Text;
  79. rData.Rows.Add(dr);
  80. }
  81. }
  82. rData.AcceptChanges();
  83. return rData;
  84. }
  85. /// <summary>
  86. /// 数据权限
  87. /// </summary>
  88. /// <returns></returns>
  89. public DataTable RightOfData()
  90. {
  91. DataTable rData = new DataTable();
  92. rData.Columns.Add("BodyName");
  93. rData.Columns.Add("ControlName");
  94. rData.Columns.Add("ControlCaption");
  95. rData.AcceptChanges();
  96. return rData;
  97. }
  98. #endregion
  99. #region 退出
  100. private void btnClose_Click(object sender, EventArgs e)
  101. {
  102. AppConfig.CloseFormShow(this.Text);
  103. this.Close();
  104. }
  105. private void btnExit_Click(object sender, EventArgs e)
  106. {
  107. AppConfig.CloseFormShow(this.Text);
  108. this.Close();
  109. }
  110. #endregion
  111. #region 移动窗体
  112. private const int WM_NCHITTEST = 0x84;
  113. private const int HTCLIENT = 0x1;
  114. private const int HTCAPTION = 0x2;
  115. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  116. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  117. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  118. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  119. //重写窗体,使窗体可以不通过自带标题栏实现移动
  120. protected override void WndProc(ref Message m)
  121. {
  122. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  123. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  124. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  125. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  126. switch (m.Msg)
  127. {
  128. case WM_NCHITTEST:
  129. base.WndProc(ref m);
  130. if ((int)m.Result == HTCLIENT)
  131. m.Result = (IntPtr)HTCAPTION;
  132. return;
  133. }
  134. //拦截双击标题栏、移动窗体的系统消息
  135. if (m.Msg != 0xA3)
  136. {
  137. base.WndProc(ref m);
  138. }
  139. }
  140. #endregion
  141. #region 过滤
  142. private string tempTableName = "";
  143. private void btnFilter_Click(object sender, EventArgs e)
  144. {
  145. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  146. filter.OldTempTableName = tempTableName;
  147. if (filter.ShowDialog() == DialogResult.OK)
  148. {
  149. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  150. try
  151. {
  152. _wait.Show();
  153. BodyDt = null;
  154. BodySource = null;
  155. ds.Reset();
  156. tempTableName = filter.NewTempTableName;
  157. sqltxt = filter.SqlText;
  158. sqlconn = filter.FilterConnectString;
  159. dataSource = filter.FilterData.Tables[0];
  160. DataSet Hset = new DataSet();
  161. dataSource.TableName = "Hsource";
  162. DataTable Hsource = dataSource.Copy();
  163. Hset.Tables.Add(Hsource);
  164. DataTable Hdt = dataSource.Copy();
  165. Hdt.Clear();
  166. BodySource = FormPhysicalInventoryBLL.FindAll(AppConfig.AppConnectString);
  167. DataSet Bset = new DataSet();
  168. dataSource.TableName = "Bsource";
  169. DataTable Bsource = BodySource.Copy();
  170. Bset.Tables.Add(Bsource);
  171. DataTable Bdt = BodySource.Copy();
  172. Bdt.Clear();
  173. DataSet dset = dataSetTool(Hdt, Bdt);
  174. dataSource = filter.FilterData.Tables[0];
  175. foreach (DataRow row in Hset.Tables[0].Rows)
  176. {
  177. dset.Tables["Hand"].Rows.Add(row.ItemArray);
  178. }
  179. foreach (DataRow row in Bset.Tables[0].Rows)
  180. {
  181. dset.Tables["Body"].Rows.Add(row.ItemArray);
  182. }
  183. grdDetail.DataSource = dset.Tables["Hand"];
  184. grvDetail.BestFitColumns();
  185. gridView1.BestFitColumns();
  186. rptPage.RecordNum = dataSource.Rows.Count;
  187. rptPage.PageSize = 499;
  188. rptPage.PageIndex = 1;
  189. rptPage.ReLoad();
  190. rptPage.PageSize = 500;
  191. rptPage.PageIndex = 1;
  192. //rptPage.ReLoad();
  193. _wait.Close();
  194. }
  195. catch (Exception ex)
  196. {
  197. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  198. _wait.Close();
  199. }
  200. }
  201. }
  202. #endregion
  203. #region dataSet绑定
  204. private DataSet dataSetTool(DataTable hand,DataTable body)
  205. {
  206. DataColumn[] relations_dt, relations_ds;
  207. hand.TableName = "Hand";
  208. body.TableName = "Body";
  209. HandDt = hand.Copy();
  210. BodyDt = body.Copy();
  211. ds.Tables.Add(HandDt);
  212. ds.Tables.Add(BodyDt);
  213. relations_dt = new DataColumn[] { ds.Tables["Hand"].Columns["ItemCode"], ds.Tables["Hand"].Columns["ToCheckNO"],ds.Tables["Hand"].Columns["StorageCode"] };
  214. relations_ds = new DataColumn[] { ds.Tables["Body"].Columns["ItemCode"], ds.Tables["Body"].Columns["ToCheckNO"], ds.Tables["Body"].Columns["StorageCode"] };
  215. ds.Relations.Add("详情", relations_dt, relations_ds);
  216. return ds;
  217. }
  218. #endregion
  219. #region 绑定数据源
  220. private void btnConfig_Click(object sender, EventArgs e)
  221. {
  222. if (AppConfig.UserCode.ToLower() != "demo")
  223. {
  224. ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  225. return;
  226. }
  227. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  228. fdata.ShowDialog();
  229. }
  230. #endregion
  231. #region 分页
  232. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  233. {
  234. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  235. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  236. grdDetail.DataSource = data;
  237. }
  238. #endregion
  239. #region 过滤方法
  240. private void FormContainerManager_FormClosing(object sender, FormClosingEventArgs e)
  241. {
  242. AppConfig.DropTemTable(tempTableName);
  243. }
  244. #endregion
  245. #region 全选
  246. private void btnSelectAll_Click(object sender, EventArgs e)
  247. {
  248. grvDetail.PostEditor();
  249. this.Validate();
  250. for (int i = 0; i < grvDetail.RowCount; i++)
  251. {
  252. grvDetail.SetRowCellValue(i, colSelect, "Y");
  253. }
  254. }
  255. #endregion
  256. #region 全消
  257. private void btnCancelAll_Click(object sender, EventArgs e)
  258. {
  259. grvDetail.PostEditor();
  260. this.Validate();
  261. for (int i = 0; i < grvDetail.RowCount; i++)
  262. {
  263. grvDetail.SetRowCellValue(i, colSelect, "");
  264. }
  265. }
  266. #endregion
  267. #region 双击
  268. private void grvDetail_DoubleClick(object sender, EventArgs e)
  269. {
  270. if (grvDetail.FocusedRowHandle < 0)
  271. {
  272. return;
  273. }
  274. if (grvDetail.FocusedColumn == colSelect)
  275. {
  276. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colSelect).ToString() == "")
  277. {
  278. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colSelect, "Y");
  279. }
  280. else
  281. {
  282. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colSelect, "");
  283. }
  284. }
  285. }
  286. #endregion
  287. #region 删除
  288. private void btnDel_Click(object sender, EventArgs e)
  289. {
  290. grvDetail.PostEditor();
  291. this.Validate();
  292. if (grvDetail.RowCount == 0)
  293. return;
  294. SimpleButton btntemp = (SimpleButton)sender;
  295. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  296. {
  297. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  298. }
  299. string ItemNO = "";
  300. for (int i = 0; i < grvDetail.RowCount; i++)
  301. {
  302. if (grvDetail.GetRowCellValue(i, colSelect).ToString() == "Y")
  303. {
  304. ItemNO = grvDetail.GetRowCellValue(i, ToCheckNO).ToString();
  305. break;
  306. }
  307. }
  308. if (ItemNO == "")
  309. {
  310. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  311. return;
  312. }
  313. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除该单据吗?单据删除后无法恢复,确定吗?") != DialogResult.OK)
  314. return;
  315. try
  316. {
  317. FormPhysicalInventoryBLL.delete(ItemNO, AppConfig.AppConnectString);
  318. ICSBaseSimpleCode.AppshowMessageBox(0, "删除成功");
  319. btnRefresh_Click(null, null);
  320. }
  321. catch (Exception ex)
  322. {
  323. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  324. }
  325. }
  326. #endregion
  327. #region 导出
  328. private void btnOutPut_Click(object sender, EventArgs e)
  329. {
  330. SimpleButton btntemp = (SimpleButton)sender;
  331. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  332. {
  333. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  334. }
  335. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  336. foe.ShowDialog();
  337. }
  338. #endregion
  339. #region 刷新
  340. private void btnRefresh_Click(object sender, EventArgs e)
  341. {
  342. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  343. try
  344. {
  345. _wait.Show();
  346. BodyDt = null;
  347. BodySource = null;
  348. ds.Reset();
  349. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  350. filter.OldTempTableName = tempTableName;
  351. //tempTableName = filter.NewTempTableName;
  352. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  353. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  354. DataSet Hset = new DataSet();
  355. dataSource.TableName = "Hsource";
  356. DataTable Hsource = dataSource.Copy();
  357. Hset.Tables.Add(Hsource);
  358. DataTable Hdt = dataSource.Copy();
  359. Hdt.Clear();
  360. BodySource = FormPhysicalInventoryBLL.FindAll(AppConfig.AppConnectString);
  361. DataSet Bset = new DataSet();
  362. dataSource.TableName = "Bsource";
  363. DataTable Bsource = BodySource.Copy();
  364. Bset.Tables.Add(Bsource);
  365. DataTable Bdt = BodySource.Copy();
  366. Bdt.Clear();
  367. DataSet dset = dataSetTool(Hdt, Bdt);
  368. dataSource = filter.FilterData.Tables[0];
  369. foreach (DataRow row in Hset.Tables[0].Rows)
  370. {
  371. dset.Tables["Hand"].Rows.Add(row.ItemArray);
  372. }
  373. foreach (DataRow row in Bset.Tables[0].Rows)
  374. {
  375. dset.Tables["Body"].Rows.Add(row.ItemArray);
  376. }
  377. grdDetail.DataSource = dset.Tables["Hand"];
  378. grvDetail.BestFitColumns();
  379. gridView1.BestFitColumns();
  380. rptPage.RecordNum = dataSource.Rows.Count;
  381. rptPage.PageIndex = 1;
  382. //rptPage.ReLoad();
  383. _wait.Close();
  384. }
  385. catch (Exception ex)
  386. {
  387. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  388. _wait.Close();
  389. }
  390. }
  391. #endregion
  392. #region 更新U8实盘数
  393. private void btnCreate_Click(object sender, EventArgs e)
  394. {
  395. SimpleButton btntemp = (SimpleButton)sender;
  396. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  397. {
  398. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  399. return;
  400. }
  401. try
  402. {
  403. CheckContext context = new CheckContext();
  404. context.UserName = AppConfig.UserName;
  405. context.ERPDataName = ICSBaseSimpleCode.GetWorkPointErpData();
  406. int count = 0;
  407. for (int i = 0; i < grvDetail.RowCount; i++)
  408. {
  409. if (grvDetail.GetRowCellValue(i, colSelect).ToString() == "Y")
  410. {
  411. count++;
  412. context.ckNO = grvDetail.GetRowCellValue(i, ToCheckNO).ToString();
  413. context.whCode = grvDetail.GetRowCellValue(i, colStorageCode).ToString();
  414. context.itemCode = grvDetail.GetRowCellValue(i, ItemCode).ToString();
  415. }
  416. }
  417. if (count != 1)
  418. {
  419. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行更新!!!");
  420. return;
  421. }
  422. FormPhysicalInventoryBLL.ERPCheckVouch(context, AppConfig.AppConnectString);
  423. }
  424. catch (Exception ex)
  425. {
  426. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  427. }
  428. }
  429. #endregion
  430. #region 修改
  431. private void btnModify_Click(object sender, EventArgs e)
  432. {
  433. String id = "";
  434. SimpleButton btntemp = (SimpleButton)sender;
  435. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  436. {
  437. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  438. }
  439. List<string> editList = new List<string>();
  440. List<string> guidList1 = new List<string>();
  441. for (int i = 0; i < grvDetail.RowCount; i++)
  442. {
  443. if (grvDetail.GetRowCellValue(i, colSelect).ToString() == "Y")
  444. {
  445. id = grvDetail.GetRowCellValue(i, colSerial).ToString();
  446. editList.Add(id);
  447. }
  448. }
  449. if (editList.Count != 1)
  450. {
  451. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  452. return;
  453. }
  454. try
  455. {
  456. FormPhysicalInventoryAdd add = new FormPhysicalInventoryAdd(id);
  457. add.ShowDialog();
  458. btnRefresh_Click(null, null);
  459. }
  460. catch (Exception ex)
  461. {
  462. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  463. }
  464. }
  465. #endregion
  466. private void FormICSItemLot_FormClosing(object sender, FormClosingEventArgs e)
  467. {
  468. AppConfig.DropTemTable(tempTableName);
  469. }
  470. private void FormICSItemLot_Load(object sender, EventArgs e)
  471. {
  472. btnFilter_Click(sender, e);
  473. }
  474. private void grvDetail_MasterRowExpanded(object sender, DevExpress.XtraGrid.Views.Grid.CustomMasterRowEventArgs e)
  475. {
  476. DevExpress.XtraGrid.Views.Grid.GridView aView = grvDetail.GetDetailView(e.RowHandle, e.RelationIndex) as DevExpress.XtraGrid.Views.Grid.GridView;
  477. }
  478. private void gridView1_MasterRowExpanded(object sender, DevExpress.XtraGrid.Views.Grid.CustomMasterRowEventArgs e)
  479. {
  480. DevExpress.XtraGrid.Views.Grid.GridView aView = grvDetail.GetDetailView(e.RowHandle, e.RelationIndex) as DevExpress.XtraGrid.Views.Grid.GridView;
  481. }
  482. private void btnCheckIn_Click(object sender, EventArgs e)
  483. {
  484. SimpleButton btntemp = (SimpleButton)sender;
  485. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  486. {
  487. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  488. return;
  489. }
  490. FormPhysicalInventoryCheck add = new FormPhysicalInventoryCheck();
  491. add.ShowDialog();
  492. btnRefresh_Click(null, null);
  493. }
  494. private void btnIN_Click(object sender, EventArgs e)
  495. {
  496. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  497. try {
  498. _wait.Show();
  499. barList.Clear();
  500. path = Application.StartupPath + @"\盘点条码.txt";
  501. if (!File.Exists(path))
  502. {
  503. ICSBaseSimpleCode.AppshowMessageBox(path + "文件不存在!!");
  504. return;
  505. }
  506. StreamReader sr = new StreamReader(path, Encoding.Default);
  507. string line;
  508. while ((line = sr.ReadLine()) != null)
  509. {
  510. if (line != "" && line != "\r\n")
  511. {
  512. string barCode = line.Substring(line.IndexOf(": ") + 2);
  513. if (barCode.Substring(0, 1) != "M" && barCode.Substring(0, 1) != "B")
  514. {
  515. continue;
  516. }
  517. string CSql = @"SELECT BarCode FROM [dbo].ICSMOBarCode WHERE BarCode = '" + barCode + "'";
  518. DataTable MDt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, CSql).Tables[0];
  519. CSql = @"SELECT BarCode FROM [dbo].ICSStockBarCode WHERE BarCode = '" + barCode + "'";
  520. DataTable BDt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, CSql).Tables[0];
  521. if ((MDt == null || MDt.Rows.Count == 0) && (BDt == null || BDt.Rows.Count == 0))
  522. {
  523. errorBar += barCode + "\r\n";
  524. }
  525. else
  526. {
  527. if (!barList.Contains(barCode))
  528. {
  529. barList.Add(barCode);
  530. }
  531. }
  532. }
  533. }
  534. ICSStorageInfoBLL.import(barList);
  535. _wait.Close();
  536. ICSBaseSimpleCode.AppshowMessageBox("导入成功");
  537. sr.Close();
  538. ICSBaseSimpleCode.AppshowMessageBox(barList.Count.ToString());
  539. FileStream fs = new FileStream(path, FileMode.Create);
  540. //获得字节数组
  541. byte[] data = System.Text.Encoding.Default.GetBytes(errorBar);
  542. //开始写入
  543. fs.Write(data, 0, data.Length);
  544. //清空缓冲区、关闭流
  545. fs.Flush();
  546. fs.Close();
  547. }catch(Exception ex){
  548. _wait.Close();
  549. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  550. }
  551. }
  552. private void simpleButton1_Click(object sender, EventArgs e)
  553. {
  554. SimpleButton btntemp = (SimpleButton)sender;
  555. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  556. {
  557. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  558. return;
  559. }
  560. try
  561. {
  562. string sql = @"UPDATE [dbo].[ICSToCheck]
  563. SET ItemCode = b.cInvCode,ItemName = d.cInvName,CurrentQty = c.qty,
  564. StorageCode = a.cWhCode
  565. FROM {0}.dbo.CheckVouch a
  566. INNER JOIN {0}.dbo.CheckVouchs b ON a.ID = b.ID
  567. INNER JOIN (SELECT cWhCode,cInvCode,SUM(iQuantity) AS qty FROM {0}.dbo.CurrentStock GROUP BY cInvCode,cWhCode) c
  568. ON b.cInvCode = c.cInvCode AND a.cWhCode = c.cWhCode
  569. INNER JOIN {0}.dbo.Inventory d ON b.cInvCode = d.cInvCode
  570. LEFT JOIN [dbo].[ICSToCheck] e
  571. ON a.cCVCode = e.ToCheckNO AND a.cWhCode = e.StorageCode AND b.cInvCode = e.ItemCode
  572. WHERE e.ToCheckNO IS NOT NULL AND e.cFree1 <> a.dnmodifytime
  573. INSERT INTO [dbo].[ICSToCheck]
  574. ([Serial],[ToCheckNO],[ToCheckDate],[ItemCode],[ItemName]
  575. ,[CurrentQty],[ActualQty],[Muser],[MuserName],[Mtime]
  576. ,[WorkPoint],[cFree1],[ItemType],[CheckSource],[StorageCode])
  577. SELECT NEWID(),a.cCVCode ,dCVDate,b.cInvCode,d.cInvName,c.qty,'0',
  578. a.cMaker,a.cMaker,GETDATE(),'{1}',a.dnmodifytime,'','ERP',a.cWhCode FROM {0}.dbo.CheckVouch a
  579. INNER JOIN {0}.dbo.CheckVouchs b ON a.ID = b.ID
  580. INNER JOIN (SELECT cWhCode,cInvCode,SUM(iQuantity) AS qty FROM {0}.dbo.CurrentStock GROUP BY cInvCode,cWhCode) c
  581. ON b.cInvCode = c.cInvCode AND a.cWhCode = c.cWhCode
  582. INNER JOIN {0}.dbo.Inventory d ON b.cInvCode = d.cInvCode
  583. LEFT JOIN [dbo].[ICSToCheck] e
  584. ON a.cCVCode = e.ToCheckNO AND a.cWhCode = e.StorageCode AND b.cInvCode = e.ItemCode
  585. WHERE e.ToCheckNO IS NULL
  586. ";
  587. sql = string.Format(sql, ICSBaseSimpleCode.GetWorkPointErpData(), AppConfig.WorkPointCode);
  588. DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, sql);
  589. ICSBaseSimpleCode.AppshowMessageBox("同步成功");
  590. }
  591. catch (Exception ex)
  592. {
  593. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  594. }
  595. }
  596. }
  597. }