华恒Mes鼎捷代码
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.

953 lines
39 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. namespace ICSSoft.Frame.APP
  27. {
  28. public partial class FormICSArrivalVIQC : DevExpress.XtraEditors.XtraForm
  29. {
  30. private string sqltxt = "";
  31. private string sqlconn = "";
  32. private DataTable dataSource = null;
  33. String guid = AppConfig.GetGuid();
  34. //string where = "(RECSTATUS=''待检'' or RECSTATUS=''已检'' and ISALLINSTORAGE=''N'') ";
  35. string autoRefreshTime = System.Configuration.ConfigurationManager.AppSettings["AutoRefreshTime"].ToString();
  36. string isAutoRefresh = System.Configuration.ConfigurationManager.AppSettings["IsAutoRefresh"].ToString();
  37. System.Timers.Timer t = new System.Timers.Timer();
  38. #region 构造函数
  39. public FormICSArrivalVIQC()
  40. {
  41. InitializeComponent();
  42. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  43. this.WindowState = FormWindowState.Maximized;
  44. //label2.BackColor = Color.White;
  45. }
  46. #endregion
  47. #region 操作权限
  48. public DataTable RightOfExute()
  49. {
  50. DataTable rData = new DataTable();
  51. rData.Columns.Add("BtnName");
  52. rData.Columns.Add("ActionName");
  53. //查看权限(必须有)
  54. DataRow seeRow = rData.NewRow();
  55. seeRow["BtnName"] = "see";
  56. seeRow["ActionName"] = "查看";
  57. rData.Rows.Add(seeRow);
  58. List<Control> ControlList = new List<Control>();
  59. ControlList.Add(simpleButton2);
  60. ControlList.Add(btnOutPut);
  61. ControlList.Add(simpleButton1);
  62. ControlList.Add(simpleButton3);
  63. ControlList.Add(simpleButton4);
  64. foreach (Control ctr in ControlList)
  65. {
  66. if (ctr.GetType() == typeof(SimpleButton))
  67. {
  68. DataRow dr = rData.NewRow();
  69. dr["BtnName"] = ctr.Name;
  70. dr["ActionName"] = ctr.Text;
  71. rData.Rows.Add(dr);
  72. }
  73. }
  74. rData.AcceptChanges();
  75. return rData;
  76. }
  77. public DataTable RightOfData()// 数据权限
  78. {
  79. DataTable rData = new DataTable();
  80. rData.Columns.Add("BodyName");
  81. rData.Columns.Add("ControlName");
  82. rData.Columns.Add("ControlCaption");
  83. rData.AcceptChanges();
  84. return rData;
  85. }
  86. #endregion
  87. #region 退出
  88. private void btnClose_Click(object sender, EventArgs e)
  89. {
  90. AppConfig.CloseFormShow(this.Text);
  91. this.Close();
  92. }
  93. private void btnExit_Click(object sender, EventArgs e)
  94. {
  95. AppConfig.CloseFormShow(this.Text);
  96. this.Close();
  97. }
  98. #endregion
  99. #region 移动窗体
  100. private const int WM_NCHITTEST = 0x84;
  101. private const int HTCLIENT = 0x1;
  102. private const int HTCAPTION = 0x2;
  103. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  104. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  105. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  106. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  107. //重写窗体,使窗体可以不通过自带标题栏实现移动
  108. protected override void WndProc(ref Message m)
  109. {
  110. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  111. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  112. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  113. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  114. switch (m.Msg)
  115. {
  116. case WM_NCHITTEST:
  117. base.WndProc(ref m);
  118. if ((int)m.Result == HTCLIENT)
  119. m.Result = (IntPtr)HTCAPTION;
  120. return;
  121. }
  122. //拦截双击标题栏、移动窗体的系统消息
  123. if (m.Msg != 0xA3)
  124. {
  125. base.WndProc(ref m);
  126. }
  127. }
  128. #endregion
  129. #region 列表
  130. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  131. {
  132. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  133. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  134. }
  135. private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  136. {
  137. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  138. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  139. }
  140. #endregion
  141. #region 过滤
  142. private string tempTableName = "";
  143. #endregion
  144. #region 过滤方法
  145. private void FormContainerManager_FormClosing(object sender, FormClosingEventArgs e)
  146. {
  147. AppConfig.DropTemTable(tempTableName);
  148. }
  149. #endregion
  150. #region 刷新
  151. private void btnRefresh_Click(object sender, EventArgs e)
  152. {
  153. if (sqlconn == null || sqlconn == "")
  154. {
  155. return;
  156. }
  157. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  158. try
  159. {
  160. _wait.Show();
  161. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  162. filter.OldTempTableName = tempTableName;
  163. //tempTableName = filter.NewTempTableName;
  164. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  165. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  166. grdDetail.DataSource = dataSource;
  167. grvDetail.BestFitColumns();
  168. rptPage.RecordNum = dataSource.Rows.Count;
  169. rptPage.PageIndex = 1;
  170. rptPage.ReLoad();
  171. _wait.Close();
  172. }
  173. catch (Exception ex)
  174. {
  175. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  176. _wait.Close();
  177. }
  178. }
  179. #endregion
  180. #region 新增
  181. private void btnCreate_Click(object sender, EventArgs e)
  182. {
  183. SimpleButton btn = ((SimpleButton)sender);
  184. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btn.Name) == false)
  185. {
  186. ICSBaseSimpleCode.AppshowMessageBox(1, "对不起您无" + btn.Text + "权限,请联系管理员!");
  187. return;
  188. }
  189. try
  190. {
  191. string ERPSql = @"SELECT a.ID, [ReceiptNO] AS 入库单号
  192. ,b.StorageName AS
  193. ,c.VendorName AS
  194. ,[RECTYPE] AS
  195. ,[MEMO] AS
  196. ,a.[MUSERName] AS
  197. ,a.[MTIME] AS
  198. FROM [ICSINVReceipt] a LEFT JOIN ICSStorage b ON a.StorageID=b.Serial
  199. LEFT JOIN ICSVendor c ON a.[VENDORCODE]=c.ID
  200. WHERE [ReceiptNO] NOT IN
  201. (SELECT DISTINCT STNO FROM dbo.ICSASNIQC)
  202. and a.WorkPoint='" + AppConfig.WorkPointCode + "' ";
  203. DataTable czData = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, ERPSql).Tables[0];
  204. FormDataRefer reForm = new FormDataRefer();
  205. reForm.FormTitle = "入库单列表";
  206. reForm.DataSource = czData;
  207. reForm.MSelectFlag = true;
  208. reForm.RowIndexWidth = 35;
  209. reForm.HideCols.Add("ID");
  210. reForm.Width = this.Width - 10;
  211. reForm.Height = this.Height - 10;
  212. if (reForm.ShowDialog() != DialogResult.OK)
  213. {
  214. return;
  215. }
  216. DataTable retData = reForm.ReturnData;
  217. if (retData.Rows.Count == 0)
  218. {
  219. return;
  220. }
  221. ICSASNIQCBLL.save(retData, AppConfig.AppConnectString);
  222. ICSBaseSimpleCode.AppshowMessageBox("生成成功");
  223. btnRefresh_Click(null, null);
  224. }
  225. catch (Exception ex)
  226. {
  227. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  228. }
  229. }
  230. #endregion
  231. #region 页面加载
  232. private void ICSItemLot_FormClosing(object sender, FormClosingEventArgs e)
  233. {
  234. AppConfig.DropTemTable(tempTableName);
  235. }
  236. private void FormICSCREW_Load(object sender, EventArgs e)
  237. {
  238. btnFilter_Click(null, null);
  239. }
  240. #endregion
  241. #region 导出
  242. private void btnOutPut_Click_1(object sender, EventArgs e)
  243. {
  244. try
  245. {
  246. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  247. foe.ShowDialog();
  248. }
  249. catch (Exception ex)
  250. {
  251. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  252. }
  253. //FormOutExcel foe = new FormOutExcel();
  254. //if (foe.ShowDialog() == DialogResult.OK)
  255. //{
  256. // try
  257. // {
  258. // string outtype = foe._OutType;
  259. // string exceltype = foe._ExcelType;
  260. // string filename = foe._FileName;
  261. // string url = foe._Url;
  262. // string sheetname = foe._SheetName;
  263. // if (outtype.ToLower() == "excel")
  264. // {
  265. // DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions();
  266. // op.SheetName = sheetname;
  267. // grdDetail.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op);
  268. // }
  269. // else
  270. // {
  271. // grdDetail.MainView.ExportToPdf(url + "\\" + filename + ".pdf");
  272. // }
  273. // MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  274. // }
  275. // catch (Exception ex)
  276. // {
  277. // MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  278. // }
  279. //}
  280. }
  281. #endregion
  282. #region 合格不合格判定事件
  283. private void repositoryItemButtonEdit1_Click(object sender, EventArgs e)
  284. {
  285. try
  286. {
  287. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisInput).ToString() == "否")
  288. {
  289. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colEATTRIBUTE2).ToString() == "")
  290. {
  291. //DataRow df = CheckStatus("合格");
  292. UpdateStatus(grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colcCode).ToString(), grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colirowno).ToString(), grvDetail.FocusedRowHandle, "合格", grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colLotNO).ToString());
  293. btnRefresh_Click(null, null);
  294. }
  295. else
  296. {
  297. MessageBox.Show("条码已检,不能进行此操作!");
  298. return;
  299. }
  300. }
  301. else
  302. {
  303. MessageBox.Show("条码已入库,不能进行此操作!");
  304. return;
  305. }
  306. }
  307. catch (Exception ex)
  308. { return; }
  309. }
  310. private void repositoryItemButtonEdit2_Click(object sender, EventArgs e)
  311. {
  312. try
  313. {
  314. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisInput).ToString() == "否")
  315. {
  316. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colEATTRIBUTE2).ToString() == "")
  317. {
  318. //DataRow df = CheckStatus("不合格");
  319. UpdateStatus(grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colcCode).ToString(), grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colirowno).ToString(), grvDetail.FocusedRowHandle, "不合格", grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colLotNO).ToString());
  320. btnRefresh_Click(null, null);
  321. }
  322. else
  323. {
  324. MessageBox.Show("条码已检,不能进行此操作!");
  325. return;
  326. }
  327. }
  328. else
  329. {
  330. MessageBox.Show("条码已入库,不能进行此操作!");
  331. return;
  332. }
  333. }
  334. catch (Exception ex)
  335. { return; }
  336. }
  337. private DataRow CheckStatus(string Status)
  338. {
  339. try
  340. {
  341. if (grvDetail.FocusedRowHandle < 0)
  342. { throw new Exception("error"); }
  343. DataRow df = grvDetail.GetDataRow(grvDetail.FocusedRowHandle);
  344. if (df == null)
  345. { throw new Exception("error"); }
  346. if (df["检验状态"].ToString() == Status)
  347. throw new Exception("error");
  348. df["检验状态"] = Status;
  349. return df;
  350. }
  351. catch (Exception ex) { throw ex; }
  352. }
  353. private void UpdateStatus(string RcvNo, string LineNo, int num, string Status, string lotno)
  354. {
  355. #region
  356. //grvDetail.SetRowCellValue(num, CreateUser, AppConfig.UserName);
  357. //grvDetail.SetRowCellValue(num, CreateTime, AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss").ToString("yyyy-MM-dd HH:mm:ss"));
  358. //修改行状态
  359. #endregion
  360. string sql = @"UPDATE ICSITEMLot SET EATTRIBUTE2 = '{2}', VENDORITEMCODE='{3}', VENDORCODE = '{4}', EATTRIBUTE5 = '{6}'
  361. WHERE TransNO = '{0}' AND TransLine = '{1}'AND LotNO = '{5}' ";
  362. sql = string.Format(sql, RcvNo, LineNo, Status, AppConfig.UserName, AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss").ToString("yyyy-MM-dd HH:mm:ss"), lotno, "已检");
  363. DBHelper.ExecuteDataset(AppConfig.GetDataBaseConnectStringByKey("[DB.SYS]"), CommandType.Text, sql);
  364. #region
  365. //修改头状态
  366. // sql = @"select * from ICSINVReceiptDetail
  367. // where ReceiptNO='{0}' and IQCStatus='{1}'";
  368. // sql = string.Format(sql, RcvNo,"待检");
  369. // DataTable dt=DBHelper.ExecuteDataset(AppConfig.GetDataBaseConnectStringByKey("[DB.SYS]"), CommandType.Text, sql).Tables[0];
  370. // if (dt == null || dt.Rows.Count == 0)
  371. // {
  372. // sql = @"update ICSINVReceipt set RECSTATUS='{1}',MUSERName='{2}',MTIME='{3}'
  373. // where ReceiptNO='{0}'";
  374. // sql = string.Format(sql, RcvNo, "已检",AppConfig.UserName,AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss"));
  375. // DBHelper.ExecuteDataset(AppConfig.GetDataBaseConnectStringByKey("[DB.SYS]"), CommandType.Text, sql);
  376. // }
  377. //修改子状态
  378. // sql = @"select * from ICSITEMLot
  379. // where TransNO='{0}' and EATTRIBUTE5=''";
  380. // sql = string.Format(sql, RcvNo);
  381. // DataTable dt1 = DBHelper.ExecuteDataset(AppConfig.GetDataBaseConnectStringByKey("[DB.SYS]"), CommandType.Text, sql).Tables[0];
  382. // if (dt1 == null || dt1.Rows.Count == 0)
  383. // {
  384. // sql = @"update ICSITEMLot set EATTRIBUTE5='{1}',MUSERName='{2}',MTIME='{3}'
  385. // where TransNO='{0}'";
  386. // sql = string.Format(sql, RcvNo, "已检", AppConfig.UserName, AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss"));
  387. // DBHelper.ExecuteDataset(AppConfig.GetDataBaseConnectStringByKey("[DB.SYS]"), CommandType.Text, sql);
  388. // }
  389. #endregion
  390. //btnRefresh_Click(null, null);
  391. }
  392. private void simpleButton1_Click(object sender, EventArgs e)
  393. {
  394. int count = 0;
  395. for (int i = 0; i < grvDetail.RowCount; i++)
  396. {
  397. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  398. {
  399. count++;
  400. }
  401. }
  402. if (count == 0)
  403. {
  404. MessageBox.Show("请选择数据");
  405. return;
  406. }
  407. if (MessageBox.Show("确认要全判定合格吗?", "合格确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  408. {
  409. #region
  410. //DataRow[] drs = dataSource.Select("条码是否入库='是'");
  411. //if (drs.Length > 0)
  412. //{
  413. // MessageBox.Show("存在入库条码,不能判定!");
  414. // return;
  415. //}
  416. #endregion
  417. for (int i = 0; i < grvDetail.RowCount; i++)
  418. {
  419. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  420. {
  421. if (grvDetail.GetRowCellValue(i, colisInput).ToString() == "是")
  422. {
  423. MessageBox.Show("存在入库条码,不能判定!");
  424. return;
  425. }
  426. if (grvDetail.GetRowCellValue(i, colEATTRIBUTE2).ToString() != "")
  427. {
  428. MessageBox.Show("存在已经检验条码,不能判定!");
  429. return;
  430. }
  431. }
  432. }
  433. for (int i = 0; i < grvDetail.RowCount; i++)
  434. {
  435. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  436. {
  437. if (grvDetail.GetRowCellValue(i, colisInput).ToString() == "否")
  438. {
  439. DataRow df = grvDetail.GetDataRow(i);
  440. if (df == null) continue;
  441. UpdateStatus(df["cCode"].ToString(), df["irowno"].ToString(), i, "合格", df["LotNO"].ToString());
  442. }
  443. }
  444. }
  445. }
  446. btnRefresh_Click(null, null);
  447. }
  448. private void simpleButton2_Click(object sender, EventArgs e)
  449. {
  450. int count = 0;
  451. for (int i = 0; i < grvDetail.RowCount; i++)
  452. {
  453. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  454. {
  455. count++;
  456. }
  457. }
  458. if (count == 0)
  459. {
  460. MessageBox.Show("请选择数据");
  461. return;
  462. }
  463. if (MessageBox.Show("确认要全判定不合格吗?", "不合格确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  464. {
  465. for (int i = 0; i < grvDetail.RowCount; i++)
  466. {
  467. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  468. {
  469. if (grvDetail.GetRowCellValue(i, colisInput).ToString() == "是")
  470. {
  471. MessageBox.Show("存在入库条码,不能判定!");
  472. return;
  473. }
  474. if (grvDetail.GetRowCellValue(i, colEATTRIBUTE2).ToString() != "")
  475. {
  476. MessageBox.Show("存在已经检验条码,不能判定!");
  477. return;
  478. }
  479. }
  480. }
  481. for (int i = 0; i < grvDetail.RowCount; i++)
  482. {
  483. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  484. {
  485. if (grvDetail.GetRowCellValue(i, colisInput).ToString() == "否")
  486. {
  487. DataRow df = grvDetail.GetDataRow(i);
  488. if (df == null) continue;
  489. UpdateStatus(df["cCode"].ToString(), df["irowno"].ToString(), i, "不合格", df["LotNO"].ToString());
  490. }
  491. }
  492. }
  493. }
  494. btnRefresh_Click(null, null);
  495. }
  496. #endregion
  497. #region 备注修改
  498. private void repositoryItemButtonEdit3_Click(object sender, EventArgs e)
  499. {
  500. FormRtn rtn = new FormRtn();
  501. if (rtn.ShowDialog() == DialogResult.OK)
  502. {
  503. if (grvDetail.FocusedRowHandle < 0) return;
  504. DataRow dm = grvDetail.GetDataRow(grvDetail.FocusedRowHandle);
  505. if (dm == null) return;
  506. if (!string.IsNullOrEmpty(rtn.Remark))
  507. {
  508. UpdateMEMO(dm, rtn.Remark);
  509. }
  510. else
  511. {
  512. if (MessageBox.Show("备注为空,请确认?", "备注确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  513. {
  514. UpdateMEMO(dm, rtn.Remark);
  515. }
  516. }
  517. }
  518. }
  519. private void UpdateMEMO(DataRow dm, string Memo)
  520. {
  521. string sql = @"update ICSPOArrive set Free1='{2}'
  522. where cCode='{0}' and irowno='{1}'";
  523. sql = string.Format(sql, dm["cCode"].ToString(), dm["irowno"].ToString(), Memo);
  524. DBHelper.ExecuteDataset(AppConfig.GetDataBaseConnectStringByKey("[DB.SYS]"), CommandType.Text, sql);
  525. }
  526. #endregion
  527. #region 让步
  528. private void repositoryItemButtonEdit4_Click(object sender, EventArgs e)
  529. {
  530. try
  531. {
  532. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisInput).ToString() == "否")
  533. {
  534. DataRow df = CheckStatus("让步");
  535. UpdateStatus(df["到货单号"].ToString(), df["行号"].ToString(), grvDetail.FocusedRowHandle, "让步", df["物料条码"].ToString());
  536. }
  537. else
  538. {
  539. MessageBox.Show("条码已入库,不能进行此操作!");
  540. return;
  541. }
  542. }
  543. catch (Exception ex)
  544. { return; }
  545. }
  546. #endregion
  547. private void grvDetail_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
  548. {
  549. int hand = e.RowHandle;
  550. if (hand < 0) return;
  551. DataRow dr = this.grvDetail.GetDataRow(hand);
  552. //if (dr == null) return;
  553. //if (dr["橡胶件"].ToString() == "True")
  554. //{
  555. // //e.Appearance.ForeColor = Color.Red;// 改变行字体颜色
  556. // e.Appearance.BackColor = Color.Red;// 改变行背景颜色
  557. // //根据需求
  558. //}
  559. }
  560. #region 绑定数据源
  561. private void btnConfig_Click(object sender, EventArgs e)
  562. {
  563. if (AppConfig.UserCode.ToLower() != "demo")
  564. {
  565. //ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  566. return;
  567. }
  568. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  569. fdata.ShowDialog();
  570. }
  571. #endregion
  572. #region 过滤
  573. private void btnFilter_Click(object sender, EventArgs e)
  574. {
  575. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  576. filter.OldTempTableName = tempTableName;
  577. if (filter.ShowDialog() == DialogResult.OK)
  578. {
  579. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  580. try
  581. {
  582. _wait.Show();
  583. tempTableName = filter.NewTempTableName;
  584. sqltxt = filter.SqlText;
  585. sqlconn = filter.FilterConnectString;
  586. dataSource = filter.FilterData.Tables[0];
  587. grdDetail.DataSource = dataSource;
  588. grvDetail.BestFitColumns();
  589. rptPage.RecordNum = dataSource.Rows.Count;
  590. rptPage.PageSize = 499;
  591. rptPage.PageIndex = 1;
  592. rptPage.ReLoad();
  593. rptPage.PageSize = 500;
  594. rptPage.PageIndex = 1;
  595. rptPage.ReLoad();
  596. _wait.Close();
  597. }
  598. catch (Exception ex)
  599. {
  600. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  601. _wait.Close();
  602. }
  603. }
  604. }
  605. #endregion
  606. #region 全选
  607. private void btnSelectAll_Click(object sender, EventArgs e)
  608. {
  609. grvDetail.PostEditor();
  610. this.Validate();
  611. for (int i = 0; i < grvDetail.RowCount; i++)
  612. {
  613. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  614. }
  615. }
  616. #endregion
  617. #region 全消
  618. private void btnCancelAll_Click(object sender, EventArgs e)
  619. {
  620. grvDetail.PostEditor();
  621. this.Validate();
  622. for (int i = 0; i < grvDetail.RowCount; i++)
  623. {
  624. grvDetail.SetRowCellValue(i, colisSelect, "");
  625. }
  626. }
  627. #endregion
  628. #region 双击
  629. private void grvDetail_DoubleClick(object sender, EventArgs e)
  630. {
  631. if (grvDetail.FocusedRowHandle < 0)
  632. {
  633. return;
  634. }
  635. if (grvDetail.FocusedColumn == colisSelect)
  636. {
  637. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  638. {
  639. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  640. }
  641. else
  642. {
  643. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  644. }
  645. }
  646. }
  647. #endregion
  648. private void simpleButton3_Click(object sender, EventArgs e)
  649. {
  650. if (MessageBox.Show("确认要全部让步吗?", "让步确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  651. {
  652. for (int i = 0; i < grvDetail.RowCount; i++)
  653. {
  654. if (grvDetail.GetRowCellValue(i, colisInput).ToString() == "是")
  655. {
  656. MessageBox.Show("存在入库条码,不能判定!");
  657. return;
  658. }
  659. }
  660. for (int i = 0; i < grvDetail.RowCount; i++)
  661. {
  662. if (grvDetail.GetRowCellValue(i, colisInput).ToString() == "否")
  663. {
  664. DataRow df = grvDetail.GetDataRow(i);
  665. if (df == null) continue;
  666. UpdateStatus(df["到货单号"].ToString(), df["行号"].ToString(), i, "让步", df["物料条码"].ToString());
  667. }
  668. }
  669. }
  670. btnRefresh_Click(null, null);
  671. }
  672. private void repositoryItemButtonEdit1_Click(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  673. {
  674. }
  675. private void btnUpLoad_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  676. {
  677. OpenFileDialog openFileDialog1 = new OpenFileDialog(); //显示选择文件对话框
  678. openFileDialog1.InitialDirectory = "c:\\";
  679. openFileDialog1.Filter = "pdf files (*.pdf)|*.pdf|All files (*.*)|*.*"; //所有的文件格式
  680. openFileDialog1.FilterIndex = 2;
  681. openFileDialog1.RestoreDirectory = true;
  682. string filePath = "";
  683. if (openFileDialog1.ShowDialog() == DialogResult.OK)
  684. {
  685. filePath = openFileDialog1.FileName; //显示文件路径
  686. }
  687. else
  688. return;
  689. string connectionString = AppConfig.GetDataBaseConnectStringByKey("[DB.FTP]");
  690. string[] ftps = connectionString.Split(';');
  691. string ftpServerIP = ftps[0].Split('=')[1];
  692. string ftpRemotePath = ftps[1].Split('=')[1];
  693. string ftpUserID = ftps[2].Split('=')[1];
  694. string ftpPassword = ftps[3].Split('=')[1];
  695. FtpWeb ftpWeb = new FtpWeb(ftpServerIP, ftpRemotePath, ftpUserID, ftpPassword);
  696. try
  697. {
  698. string filename = "";
  699. string ftpURL = "ftp://" + ftpServerIP + "/" + ftpRemotePath + "/";
  700. string[] list = filePath.Split('\\');
  701. filename = list[list.Length - 1];
  702. list = filename.Split('.');
  703. filename = list[list.Length - 2];
  704. try
  705. {
  706. ftpWeb.Upload(filePath, filename, filename);
  707. }
  708. catch (Exception ex)
  709. {
  710. throw new Exception(ex.Message + " 上传出错!");
  711. }
  712. ICSITEMLot model = GetModel(grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colID).ToString(), AppConfig.AppConnectString);
  713. model.tFileName = filename;
  714. Uptdate(model, AppConfig.AppConnectString);
  715. ICSBaseSimpleCode.AppshowMessageBox("上传成功 !");
  716. btnRefresh_Click(null, null);
  717. }
  718. catch (Exception ex)
  719. {
  720. throw new Exception(ex.Message);
  721. }
  722. }
  723. private void btnDownLoad_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  724. {
  725. #region 下载逻辑
  726. string connectionString = AppConfig.GetDataBaseConnectStringByKey("[DB.FTP]");
  727. string[] ftps = connectionString.Split(';');
  728. string ftpServerIP = ftps[0].Split('=')[1];
  729. string ftpRemotePath = ftps[1].Split('=')[1];
  730. string ftpUserID = ftps[2].Split('=')[1];
  731. string ftpPassword = ftps[3].Split('=')[1];
  732. FtpWeb ftpWeb = new FtpWeb(ftpServerIP, ftpRemotePath, ftpUserID, ftpPassword);
  733. try
  734. {
  735. string ftpURL = "ftp://" + ftpServerIP + "/" + ftpRemotePath + "/" + grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, coltFileName).ToString() + "/";
  736. ICSITEMLot model = GetModel(grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colID).ToString(), AppConfig.AppConnectString);
  737. if (string.IsNullOrEmpty(model.tFileName))
  738. {
  739. ICSBaseSimpleCode.AppshowMessageBox("暂无文档!");
  740. return;
  741. }
  742. string path = System.Windows.Forms.Application.StartupPath + @"\PDF";
  743. DirectoryInfo directoryInfo = new DirectoryInfo(path);
  744. if (!Directory.Exists(path))
  745. {
  746. Directory.CreateDirectory(path);
  747. }
  748. #region 现逻辑
  749. string filePaths = path + @"\" + model.tFileName + ".pdf";
  750. ftpWeb.Download(path, grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, coltFileName).ToString() + ".pdf", grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, coltFileName).ToString());
  751. //string filePaths = @"C:\Users\Administrator.UX7663JVU2X64C5\Desktop\123.pdf";
  752. AxAcroPDFLib.AxAcroPDF axAcroPDF = new AxAcroPDFLib.AxAcroPDF();
  753. ((System.ComponentModel.ISupportInitialize)(axAcroPDF)).BeginInit();
  754. axAcroPDF.Dock = DockStyle.Fill;
  755. this.Controls.Add(axAcroPDF);
  756. axAcroPDF.Location = new System.Drawing.Point(0, 24);
  757. ((System.ComponentModel.ISupportInitialize)(axAcroPDF)).EndInit();
  758. axAcroPDF.LoadFile(filePaths);
  759. axAcroPDF.setShowToolbar(true);
  760. axAcroPDF.setPageMode("thumbs");
  761. axAcroPDF.setPageMode("none");
  762. axAcroPDF.Show();
  763. System.Diagnostics.Process.Start(filePaths);
  764. #endregion
  765. }
  766. catch (Exception ex)
  767. {
  768. throw new Exception(ex.Message);
  769. }
  770. #endregion
  771. }
  772. public static void Uptdate(ICSITEMLot data, string dsconn)
  773. {
  774. FramDataContext db = new FramDataContext(dsconn);
  775. db.Connection.Open();
  776. db.Transaction = db.Connection.BeginTransaction();
  777. try
  778. {
  779. var line = db.ICSITEMLot.SingleOrDefault(a => a.ID == data.ID);
  780. line.tFileName = data.tFileName;
  781. //db.ICSITEMLot.InsertOnSubmit(line);
  782. db.SubmitChanges();
  783. db.Transaction.Commit();
  784. }
  785. catch (Exception ex)
  786. {
  787. db.Transaction.Rollback();
  788. throw ex;
  789. }
  790. }
  791. public static ICSITEMLot GetModel(string ID, string Appconstr)
  792. {
  793. FramDataContext db = new FramDataContext(Appconstr);
  794. db.Connection.Open();
  795. db.Transaction = db.Connection.BeginTransaction();
  796. try
  797. {
  798. ICSITEMLot model = new ICSITEMLot();
  799. var line = db.ICSITEMLot.SingleOrDefault(a => a.ID == ID);
  800. if (line != null)
  801. model = line;
  802. return model;
  803. }
  804. catch (Exception ex)
  805. {
  806. throw new Exception(ex.Message);
  807. }
  808. }
  809. private void simpleButton4_Click(object sender, EventArgs e)
  810. {
  811. SimpleButton btntemp = (SimpleButton)sender;
  812. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  813. {
  814. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  815. return;
  816. }
  817. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定清除该文件吗?清除后无法恢复") != DialogResult.OK)
  818. {
  819. for (int i = 0; i < grvDetail.RowCount; i++)
  820. {
  821. grvDetail.SetRowCellValue(i, colisSelect, "");
  822. }
  823. return;
  824. }
  825. int count = 0;
  826. for (int i = 0; i < grvDetail.RowCount; i++)
  827. {
  828. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  829. {
  830. count++;
  831. }
  832. }
  833. if (count == 0)
  834. {
  835. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  836. return;
  837. }
  838. string connectionString = AppConfig.GetDataBaseConnectStringByKey("[DB.FTP]");
  839. string[] ftps = connectionString.Split(';');
  840. string ftpServerIP = ftps[0].Split('=')[1];
  841. string ftpRemotePath = ftps[1].Split('=')[1];
  842. string ftpUserID = ftps[2].Split('=')[1];
  843. string ftpPassword = ftps[3].Split('=')[1];
  844. FtpWeb ftpWeb = new FtpWeb(ftpServerIP, ftpRemotePath, ftpUserID, ftpPassword);
  845. try
  846. {
  847. for (int i = 0; i < grvDetail.RowCount; i++)
  848. {
  849. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  850. {
  851. ICSITEMLot model = GetModel(grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colID).ToString(), AppConfig.AppConnectString);
  852. if (string.IsNullOrEmpty(model.tFileName))
  853. {
  854. ICSBaseSimpleCode.AppshowMessageBox("暂无文档!");
  855. return;
  856. }
  857. ftpWeb.Delete(model.tFileName, model.tFileName + ".pdf");
  858. ftpWeb.RemoveDirectory(model.tFileName);
  859. DeletePDF(grvDetail.GetRowCellValue(i, colLotNO).ToString(), AppConfig.AppConnectString);
  860. }
  861. }
  862. ICSBaseSimpleCode.AppshowMessageBox("清除成功 !");
  863. btnRefresh_Click(null, null);
  864. }
  865. catch (Exception ex)
  866. {
  867. throw new Exception(ex.Message);
  868. }
  869. }
  870. public static void DeletePDF(string LotNO, string dsconn)
  871. {
  872. FramDataContext db = new FramDataContext(dsconn);
  873. db.Connection.Open();
  874. db.Transaction = db.Connection.BeginTransaction();
  875. try
  876. {
  877. var line = db.ICSITEMLot.SingleOrDefault(a => a.LotNO == LotNO);
  878. if (line != null)
  879. {
  880. line.tFileName = null;
  881. }
  882. db.SubmitChanges();
  883. db.Transaction.Commit();
  884. }
  885. catch (Exception ex)
  886. {
  887. db.Transaction.Rollback();
  888. throw new Exception(ex.Message);
  889. }
  890. }
  891. }
  892. }