华恒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.

453 lines
18 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 FormICSIQCSearch : 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 FormICSIQCSearch()
  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(btnSelect);
  60. ControlList.Add(btnCanSelect);
  61. ControlList.Add(btnFalsh);
  62. foreach (Control ctr in ControlList)
  63. {
  64. if (ctr.GetType() == typeof(SimpleButton))
  65. {
  66. DataRow dr = rData.NewRow();
  67. dr["BtnName"] = ctr.Name;
  68. dr["ActionName"] = ctr.Text;
  69. rData.Rows.Add(dr);
  70. }
  71. }
  72. rData.AcceptChanges();
  73. return rData;
  74. }
  75. public DataTable RightOfData()// 数据权限
  76. {
  77. DataTable rData = new DataTable();
  78. rData.Columns.Add("BodyName");
  79. rData.Columns.Add("ControlName");
  80. rData.Columns.Add("ControlCaption");
  81. rData.AcceptChanges();
  82. return rData;
  83. }
  84. #endregion
  85. #region 退出
  86. private void btnClose_Click(object sender, EventArgs e)
  87. {
  88. AppConfig.CloseFormShow(this.Text);
  89. this.Close();
  90. }
  91. private void btnExit_Click(object sender, EventArgs e)
  92. {
  93. AppConfig.CloseFormShow(this.Text);
  94. this.Close();
  95. }
  96. #endregion
  97. #region 移动窗体
  98. private const int WM_NCHITTEST = 0x84;
  99. private const int HTCLIENT = 0x1;
  100. private const int HTCAPTION = 0x2;
  101. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  102. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  103. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  104. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  105. //重写窗体,使窗体可以不通过自带标题栏实现移动
  106. protected override void WndProc(ref Message m)
  107. {
  108. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  109. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  110. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  111. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  112. switch (m.Msg)
  113. {
  114. case WM_NCHITTEST:
  115. base.WndProc(ref m);
  116. if ((int)m.Result == HTCLIENT)
  117. m.Result = (IntPtr)HTCAPTION;
  118. return;
  119. }
  120. //拦截双击标题栏、移动窗体的系统消息
  121. if (m.Msg != 0xA3)
  122. {
  123. base.WndProc(ref m);
  124. }
  125. }
  126. #endregion
  127. #region 列表
  128. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  129. {
  130. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  131. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  132. }
  133. private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  134. {
  135. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  136. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  137. }
  138. #endregion
  139. #region 过滤
  140. private string tempTableName = "";
  141. #endregion
  142. #region 过滤方法
  143. private void FormContainerManager_FormClosing(object sender, FormClosingEventArgs e)
  144. {
  145. AppConfig.DropTemTable(tempTableName);
  146. }
  147. #endregion
  148. #region 刷新
  149. private void btnRefresh_Click(object sender, EventArgs e)
  150. {
  151. if (sqlconn == null || sqlconn == "")
  152. {
  153. return;
  154. }
  155. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  156. try
  157. {
  158. _wait.Show();
  159. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  160. filter.OldTempTableName = tempTableName;
  161. //tempTableName = filter.NewTempTableName;
  162. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  163. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  164. grdDetail.DataSource = dataSource;
  165. grvDetail.BestFitColumns();
  166. rptPage.RecordNum = dataSource.Rows.Count;
  167. rptPage.PageIndex = 1;
  168. rptPage.ReLoad();
  169. _wait.Close();
  170. }
  171. catch (Exception ex)
  172. {
  173. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  174. _wait.Close();
  175. }
  176. }
  177. #endregion
  178. #region 页面加载
  179. private void ICSItemLot_FormClosing(object sender, FormClosingEventArgs e)
  180. {
  181. AppConfig.DropTemTable(tempTableName);
  182. }
  183. private void FormICSCREW_Load(object sender, EventArgs e)
  184. {
  185. btnFilter_Click(null, null);
  186. }
  187. #endregion
  188. private void grvDetail_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
  189. {
  190. int hand = e.RowHandle;
  191. if (hand < 0) return;
  192. DataRow dr = this.grvDetail.GetDataRow(hand);
  193. }
  194. #region 绑定数据源
  195. private void btnConfig_Click(object sender, EventArgs e)
  196. {
  197. if (AppConfig.UserCode.ToLower() != "demo")
  198. {
  199. //ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  200. return;
  201. }
  202. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  203. fdata.ShowDialog();
  204. }
  205. #endregion
  206. #region 过滤
  207. private void btnFilter_Click(object sender, EventArgs e)
  208. {
  209. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  210. filter.OldTempTableName = tempTableName;
  211. if (filter.ShowDialog() == DialogResult.OK)
  212. {
  213. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  214. try
  215. {
  216. _wait.Show();
  217. tempTableName = filter.NewTempTableName;
  218. sqltxt = filter.SqlText;
  219. sqlconn = filter.FilterConnectString;
  220. dataSource = filter.FilterData.Tables[0];
  221. grdDetail.DataSource = dataSource;
  222. grvDetail.BestFitColumns();
  223. rptPage.RecordNum = dataSource.Rows.Count;
  224. rptPage.PageSize = 499;
  225. rptPage.PageIndex = 1;
  226. rptPage.ReLoad();
  227. rptPage.PageSize = 500;
  228. rptPage.PageIndex = 1;
  229. rptPage.ReLoad();
  230. _wait.Close();
  231. }
  232. catch (Exception ex)
  233. {
  234. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  235. _wait.Close();
  236. }
  237. }
  238. }
  239. #endregion
  240. #region 全选
  241. private void btnSelectAll_Click(object sender, EventArgs e)
  242. {
  243. grvDetail.PostEditor();
  244. this.Validate();
  245. for (int i = 0; i < grvDetail.RowCount; i++)
  246. {
  247. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  248. }
  249. }
  250. #endregion
  251. #region 全消
  252. private void btnCancelAll_Click(object sender, EventArgs e)
  253. {
  254. grvDetail.PostEditor();
  255. this.Validate();
  256. for (int i = 0; i < grvDetail.RowCount; i++)
  257. {
  258. grvDetail.SetRowCellValue(i, colisSelect, "");
  259. }
  260. }
  261. #endregion
  262. #region 双击
  263. private void grvDetail_DoubleClick(object sender, EventArgs e)
  264. {
  265. if (grvDetail.FocusedRowHandle < 0)
  266. {
  267. return;
  268. }
  269. if (grvDetail.FocusedColumn == colisSelect)
  270. {
  271. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  272. {
  273. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  274. }
  275. else
  276. {
  277. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  278. }
  279. }
  280. }
  281. #endregion
  282. private void btnDownLoad_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  283. {
  284. #region 下载逻辑
  285. string connectionString = AppConfig.GetDataBaseConnectStringByKey("[DB.FTP]");
  286. string[] ftps = connectionString.Split(';');
  287. string ftpServerIP = ftps[0].Split('=')[1];
  288. string ftpRemotePath = ftps[1].Split('=')[1];
  289. string ftpUserID = ftps[2].Split('=')[1];
  290. string ftpPassword = ftps[3].Split('=')[1];
  291. FtpWeb ftpWeb = new FtpWeb(ftpServerIP, ftpRemotePath, ftpUserID, ftpPassword);
  292. try
  293. {
  294. string ftpURL = "ftp://" + ftpServerIP + "/" + ftpRemotePath + "/" + grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, coltFileName).ToString() + "/";
  295. ICSITEMLot model = GetModel(grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colID).ToString(), AppConfig.AppConnectString);
  296. if (string.IsNullOrEmpty(model.tFileName))
  297. {
  298. ICSBaseSimpleCode.AppshowMessageBox("暂无文档!");
  299. return;
  300. }
  301. string path = System.Windows.Forms.Application.StartupPath + @"\PDF";
  302. DirectoryInfo directoryInfo = new DirectoryInfo(path);
  303. if (!Directory.Exists(path))
  304. {
  305. Directory.CreateDirectory(path);
  306. }
  307. #region 现逻辑
  308. string filePaths = path + @"\" + model.tFileName + ".pdf";
  309. ftpWeb.Download(path, grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, coltFileName).ToString() + ".pdf", grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, coltFileName).ToString());
  310. //string filePaths = @"C:\Users\Administrator.UX7663JVU2X64C5\Desktop\123.pdf";
  311. AxAcroPDFLib.AxAcroPDF axAcroPDF = new AxAcroPDFLib.AxAcroPDF();
  312. ((System.ComponentModel.ISupportInitialize)(axAcroPDF)).BeginInit();
  313. axAcroPDF.Dock = DockStyle.Fill;
  314. this.Controls.Add(axAcroPDF);
  315. axAcroPDF.Location = new System.Drawing.Point(0, 24);
  316. ((System.ComponentModel.ISupportInitialize)(axAcroPDF)).EndInit();
  317. axAcroPDF.LoadFile(filePaths);
  318. axAcroPDF.setShowToolbar(true);
  319. axAcroPDF.setPageMode("thumbs");
  320. axAcroPDF.setPageMode("none");
  321. axAcroPDF.Show();
  322. System.Diagnostics.Process.Start(filePaths);
  323. #endregion
  324. }
  325. catch (Exception ex)
  326. {
  327. throw new Exception(ex.Message);
  328. }
  329. #endregion
  330. }
  331. public static ICSITEMLot GetModel(string ID, string Appconstr)
  332. {
  333. FramDataContext db = new FramDataContext(Appconstr);
  334. db.Connection.Open();
  335. db.Transaction = db.Connection.BeginTransaction();
  336. try
  337. {
  338. ICSITEMLot model = new ICSITEMLot();
  339. var line = db.ICSITEMLot.SingleOrDefault(a => a.ID == ID);
  340. if (line != null)
  341. model = line;
  342. return model;
  343. }
  344. catch (Exception ex)
  345. {
  346. throw new Exception(ex.Message);
  347. }
  348. }
  349. private void btnHeatTreatment_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  350. {
  351. if (grvDetail.FocusedRowHandle < 0)
  352. {
  353. return;
  354. }
  355. if (grvDetail.FocusedColumn == colHeatTreatment)
  356. {
  357. string MOVER = "";
  358. string sql = @"
  359. SELECT '' AS isSelect, A.ID AS ID, A.TransNO AS TransNo, A.MOCODE AS MOCODE, B.MOVER AS MOVER, A.LOTNOs AS LOTNO,
  360. A.EQPCode AS EQPCode, C.EQPName AS EQPName, A.MUSERName AS MuserName, A.MTIME AS Mtime FROM ICSOpFile A
  361. LEFT JOIN ICSMO B ON A.MOCODE = B.MOCODE AND A.MOSEQ = B.MOSEQ LEFT JOIN ICSEquipment C ON A.EQPCode = C.EQPCode
  362. WHERE ISNULL(A.EATTRIBUTE2, '') LIKE '{0}' ORDER BY A.TransNO
  363. SELECT DISTINCT B.ID AS ID, A.TransNO AS TransNO, A.EnumText AS FileType, B.FileName, B.FileType, B.MUSERName AS MuserName,
  364. B.MTIME AS Mtime FROM (SELECT A.TransNO AS TransNO, B.EnumText, A.ID AS ID FROM ICSOpFile A,
  365. (SELECT DISTINCT EnumText FROM Sys_EnumValues WHERE EnumKey = '00007') B) A
  366. LEFT JOIN ICSOpFileDetail B ON A.TransNO = B.TransNO AND A.EnumText = B.FileType ";
  367. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colVenderLotNO).ToString() == "")
  368. {
  369. MOVER = "";
  370. }
  371. else
  372. {
  373. MOVER = "%" + grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colVenderLotNO).ToString() + "%";
  374. }
  375. sql = string.Format(sql, MOVER);
  376. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  377. if (dt.Rows.Count > 0 && dt != null)
  378. {
  379. FormICSHeatTreatment add = new FormICSHeatTreatment(grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colLotNO).ToString(), grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colVenderLotNO).ToString());
  380. add.ShowDialog();
  381. }
  382. else
  383. {
  384. ICSBaseSimpleCode.AppshowMessageBox("未查询到对应信息");
  385. return;
  386. }
  387. }
  388. }
  389. private void btnINFile_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  390. {
  391. if (grvDetail.FocusedRowHandle < 0)
  392. {
  393. return;
  394. }
  395. if (grvDetail.FocusedColumn == colINFile)
  396. {
  397. string MOVER = "";
  398. string sql = @"
  399. SELECT '' AS isSelect, A.ID AS ID, A.INCode, A.VenBatch, A.VenderLotNO MOVER, A.LOTNOs,
  400. '' UpLoad, '' DownLoad, '' Del, A.tFileName, A.MUSER, A.MUSERName, A.MTIME FROM ICSINFile A
  401. WHERE 1=1 AND ISNULL(A.VenderLotNO, '') LIKE '{0}' ";
  402. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colVenderLotNO).ToString() == "")
  403. {
  404. MOVER = "";
  405. }
  406. else
  407. {
  408. MOVER = "%" + grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colVenderLotNO).ToString() + "%";
  409. }
  410. sql = string.Format(sql, MOVER);
  411. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  412. if (dt.Rows.Count > 0 && dt != null)
  413. {
  414. FormICSINLoad add = new FormICSINLoad(grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colLotNO).ToString(), grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colVenderLotNO).ToString());
  415. add.ShowDialog();
  416. }
  417. else
  418. {
  419. ICSBaseSimpleCode.AppshowMessageBox("未查询到对应信息");
  420. return;
  421. }
  422. }
  423. }
  424. }
  425. }