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

533 lines
21 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.Base.Log;
  27. namespace ICSSoft.Frame.APP
  28. {
  29. public partial class FormICSONWIPReports : DevExpress.XtraEditors.XtraForm
  30. {
  31. private string sqltxt = "";
  32. private string sqlconn = "";
  33. String guid = AppConfig.GetGuid();
  34. private DataTable dataSource = null;
  35. #region 构造函数
  36. public FormICSONWIPReports()
  37. {
  38. InitializeComponent();
  39. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  40. this.WindowState = FormWindowState.Maximized;
  41. }
  42. #endregion
  43. #region 操作权限
  44. public DataTable RightOfExute()
  45. {
  46. DataTable rData = new DataTable();
  47. rData.Columns.Add("BtnName");
  48. rData.Columns.Add("ActionName");
  49. //查看权限(必须有)
  50. DataRow seeRow = rData.NewRow();
  51. seeRow["BtnName"] = "see";
  52. seeRow["ActionName"] = "查看";
  53. rData.Rows.Add(seeRow);
  54. List<Control> ControlList = new List<Control>();
  55. ControlList.Add(simpleButton2);
  56. ControlList.Add(simpleButton1);
  57. ControlList.Add(btnOutPut);
  58. foreach (Control ctr in ControlList)
  59. {
  60. if (ctr.GetType() == typeof(SimpleButton))
  61. {
  62. DataRow dr = rData.NewRow();
  63. dr["BtnName"] = ctr.Name;
  64. dr["ActionName"] = ctr.Text;
  65. rData.Rows.Add(dr);
  66. }
  67. }
  68. rData.AcceptChanges();
  69. return rData;
  70. }
  71. public DataTable RightOfData()// 数据权限
  72. {
  73. DataTable rData = new DataTable();
  74. rData.Columns.Add("BodyName");
  75. rData.Columns.Add("ControlName");
  76. rData.Columns.Add("ControlCaption");
  77. rData.AcceptChanges();
  78. return rData;
  79. }
  80. #endregion
  81. #region 退出
  82. private void btnClose_Click(object sender, EventArgs e)
  83. {
  84. AppConfig.CloseFormShow(this.Text);
  85. this.Close();
  86. }
  87. private void btnExit_Click(object sender, EventArgs e)
  88. {
  89. AppConfig.CloseFormShow(this.Text);
  90. this.Close();
  91. }
  92. #endregion
  93. #region 移动窗体
  94. private const int WM_NCHITTEST = 0x84;
  95. private const int HTCLIENT = 0x1;
  96. private const int HTCAPTION = 0x2;
  97. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  98. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  99. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  100. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  101. //重写窗体,使窗体可以不通过自带标题栏实现移动
  102. protected override void WndProc(ref Message m)
  103. {
  104. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  105. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  106. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  107. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  108. switch (m.Msg)
  109. {
  110. case WM_NCHITTEST:
  111. base.WndProc(ref m);
  112. if ((int)m.Result == HTCLIENT)
  113. m.Result = (IntPtr)HTCAPTION;
  114. return;
  115. }
  116. //拦截双击标题栏、移动窗体的系统消息
  117. if (m.Msg != 0xA3)
  118. {
  119. base.WndProc(ref m);
  120. }
  121. }
  122. #endregion
  123. #region 列表
  124. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  125. {
  126. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  127. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  128. }
  129. #endregion
  130. #region 过滤
  131. private string tempTableName = "";
  132. private void btnFilter_Click(object sender, EventArgs e)
  133. {
  134. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  135. filter.OldTempTableName = tempTableName;
  136. if (filter.ShowDialog() == DialogResult.OK)
  137. {
  138. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  139. try
  140. {
  141. _wait.Show();
  142. tempTableName = filter.NewTempTableName;
  143. sqltxt = filter.SqlText;
  144. sqlconn = filter.FilterConnectString;
  145. dataSource = filter.FilterData.Tables[0];
  146. grdDetail.DataSource = dataSource;
  147. grvDetail.BestFitColumns();
  148. rptPage.RecordNum = dataSource.Rows.Count;
  149. rptPage.PageSize = 499;
  150. rptPage.PageIndex = 1;
  151. rptPage.ReLoad();
  152. rptPage.PageSize = 500;
  153. rptPage.PageIndex = 1;
  154. rptPage.ReLoad();
  155. _wait.Close();
  156. }
  157. catch (Exception ex)
  158. {
  159. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  160. _wait.Close();
  161. }
  162. }
  163. }
  164. #endregion
  165. #region 绑定数据源
  166. private void btnConfig_Click(object sender, EventArgs e)
  167. {
  168. //if (AppConfig.UserCode.ToLower() != "demo")
  169. //{
  170. // ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  171. // return;
  172. //}
  173. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  174. fdata.ShowDialog();
  175. }
  176. #endregion
  177. #region 分页
  178. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  179. {
  180. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  181. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  182. grdDetail.DataSource = data;
  183. }
  184. #endregion
  185. #region 过滤方法
  186. private void FormContainerManager_FormClosing(object sender, FormClosingEventArgs e)
  187. {
  188. AppConfig.DropTemTable(tempTableName);
  189. }
  190. #endregion
  191. #region 全选
  192. private void btnSelectAll_Click(object sender, EventArgs e)
  193. {
  194. grvDetail.PostEditor();
  195. this.Validate();
  196. for (int i = 0; i < grvDetail.RowCount; i++)
  197. {
  198. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  199. }
  200. }
  201. #endregion
  202. #region 全消
  203. private void btnCancelAll_Click(object sender, EventArgs e)
  204. {
  205. grvDetail.PostEditor();
  206. this.Validate();
  207. for (int i = 0; i < grvDetail.RowCount; i++)
  208. {
  209. grvDetail.SetRowCellValue(i, colisSelect, "");
  210. }
  211. }
  212. #endregion
  213. #region 双击
  214. private void grvDetail_DoubleClick(object sender, EventArgs e)
  215. {
  216. if (grvDetail.FocusedRowHandle < 0)
  217. {
  218. return;
  219. }
  220. if (grvDetail.FocusedColumn == colisSelect)
  221. {
  222. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  223. {
  224. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  225. }
  226. else
  227. {
  228. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  229. }
  230. }
  231. }
  232. #endregion
  233. #region 导出
  234. private void btnOutPut_Click(object sender, EventArgs e)
  235. {
  236. }
  237. #endregion
  238. #region 刷新
  239. private void btnRefresh_Click(object sender, EventArgs e)
  240. {
  241. if (sqlconn == null || sqlconn == "")
  242. {
  243. return;
  244. }
  245. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  246. try
  247. {
  248. _wait.Show();
  249. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  250. filter.OldTempTableName = tempTableName;
  251. //tempTableName = filter.NewTempTableName;
  252. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  253. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  254. grdDetail.DataSource = dataSource;
  255. grvDetail.BestFitColumns();
  256. rptPage.RecordNum = dataSource.Rows.Count;
  257. rptPage.PageIndex = 1;
  258. rptPage.ReLoad();
  259. _wait.Close();
  260. }
  261. catch (Exception ex)
  262. {
  263. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  264. _wait.Close();
  265. }
  266. }
  267. #endregion
  268. #region 新增
  269. private void btnCreate_Click(object sender, EventArgs e)
  270. {
  271. //SimpleButton btntemp = (SimpleButton)sender;
  272. //if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  273. //{
  274. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  275. // return;
  276. //}
  277. //FormICSONWIPCheckAdd add = new FormICSONWIPCheckAdd();
  278. //add.ShowDialog();
  279. //btnRefresh_Click(null, null);
  280. }
  281. #endregion
  282. #region 页面加载
  283. private void grdDetail_Load(object sender, EventArgs e)
  284. {
  285. btnFilter_Click(null, null);
  286. }
  287. #endregion
  288. #region 修改
  289. //private void btnModify_Click(object sender, EventArgs e)
  290. //{
  291. // try
  292. // {
  293. // SimpleButton btntemp = (SimpleButton)sender;
  294. // if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  295. // {
  296. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  297. // }
  298. // List<ICSLOTONWIPCheck> editList = new List<ICSLOTONWIPCheck>();
  299. // for (int i = 0; i < grvDetail.RowCount; i++)
  300. // {
  301. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y" && !string.IsNullOrWhiteSpace(grvDetail.GetRowCellValue(i, Result).ToString()))
  302. // {
  303. // ICSLOTONWIPCheck check = new ICSLOTONWIPCheck();
  304. // check.ID = grvDetail.GetRowCellValue(i, ID).ToString();
  305. // check.ONWIPID = grvDetail.GetRowCellValue(i, ONWIPID).ToString();
  306. // check.Result = grvDetail.GetRowCellValue(i, Result).ToString();
  307. // editList.Add(check);
  308. // }
  309. // }
  310. // if (editList.Count <=0)
  311. // {
  312. // ICSBaseSimpleCode.AppshowMessageBox("请选择数据!!!");
  313. // return;
  314. // }
  315. // ICSCollectBLL.Result(AppConfig.AppConnectString,editList);
  316. // btnRefresh_Click(null, null);
  317. // }
  318. // catch (Exception ex)
  319. // {
  320. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  321. // }
  322. //}
  323. #endregion
  324. private void ICSItemLot_FormClosing(object sender, FormClosingEventArgs e)
  325. {
  326. AppConfig.DropTemTable(tempTableName);
  327. }
  328. private void FormICSCREW_Load(object sender, EventArgs e)
  329. {
  330. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  331. filter.OldTempTableName = tempTableName;
  332. if (filter.ShowDialog() == DialogResult.OK)
  333. {
  334. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  335. try
  336. {
  337. _wait.Show();
  338. tempTableName = filter.NewTempTableName;
  339. sqltxt = filter.SqlText;
  340. sqlconn = filter.FilterConnectString;
  341. dataSource = filter.FilterData.Tables[0];
  342. grdDetail.DataSource = dataSource;
  343. grvDetail.BestFitColumns();
  344. rptPage.RecordNum = dataSource.Rows.Count;
  345. rptPage.PageSize = 499;
  346. rptPage.PageIndex = 1;
  347. rptPage.ReLoad();
  348. rptPage.PageSize = 500;
  349. rptPage.PageIndex = 1;
  350. rptPage.ReLoad();
  351. _wait.Close();
  352. }
  353. catch (Exception ex)
  354. {
  355. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  356. _wait.Close();
  357. }
  358. }
  359. }
  360. #region 上传下载PDF
  361. //上传事件
  362. private void repositoryItemButtonEdit1_Click(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  363. {
  364. OpenFileDialog openFileDialog1 = new OpenFileDialog(); //显示选择文件对话框
  365. openFileDialog1.InitialDirectory = "c:\\";
  366. openFileDialog1.Filter = "pdf files (*.pdf)|*.pdf"; //所有的文件格式
  367. //openFileDialog1.Filter = "pdf files (*.pdf)|*.pdf|All files (*.*)|*.*"; //所有的文件格式
  368. openFileDialog1.FilterIndex = 2;
  369. openFileDialog1.RestoreDirectory = true;
  370. string Pid = grvDetail.GetFocusedRowCellValue(ID).ToString();
  371. string filePath = "";
  372. if (openFileDialog1.ShowDialog() == DialogResult.OK)
  373. {
  374. filePath = openFileDialog1.FileName; //显示文件路径
  375. }
  376. else
  377. return;
  378. string connectionString = AppConfig.GetDataBaseConnectStringByKey("[DB.FTP]");
  379. string[] ftps = connectionString.Split(';');
  380. string ftpServerIP = ftps[0].Split('=')[1];
  381. string ftpRemotePath = ftps[1].Split('=')[1];
  382. string ftpUserID = ftps[2].Split('=')[1];
  383. string ftpPassword = ftps[3].Split('=')[1];
  384. FtpWeb ftpWeb = new FtpWeb(ftpServerIP, ftpRemotePath, ftpUserID, ftpPassword);
  385. try
  386. {
  387. try
  388. {
  389. Log.WriteLogForVisit(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType + "." + System.Reflection.MethodBase.GetCurrentMethod().Name,
  390. filePath, "");
  391. int cout = filePath.Split('\\').Length;
  392. string fname = filePath.Split('\\')[cout - 1];
  393. Log.WriteLogForVisit(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType + "." + System.Reflection.MethodBase.GetCurrentMethod().Name,
  394. fname, "");
  395. fname = fname.Split('.')[0];
  396. Log.WriteLogForVisit(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType + "." + System.Reflection.MethodBase.GetCurrentMethod().Name,
  397. fname, "");
  398. ftpWeb.Upload(filePath, fname, fname);
  399. Log.WriteLogForVisit(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType + "." + System.Reflection.MethodBase.GetCurrentMethod().Name,
  400. Pid, "");
  401. Log.WriteLogForVisit(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType + "." + System.Reflection.MethodBase.GetCurrentMethod().Name,
  402. AppConfig.AppConnectString, "");
  403. ICSCollectBLL.AddPDF(Pid, fname, AppConfig.AppConnectString);
  404. }
  405. catch (Exception ex)
  406. {
  407. throw new Exception(ex.Message + " 上传出错!");
  408. Log.WriteLogForException(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "", ex.ToString());
  409. }
  410. string filename = "";
  411. string ftpURL = "ftp://" + ftpServerIP + "/" + ftpRemotePath + "/";
  412. string[] list = filePath.Split('\\');
  413. filename = list[list.Length - 1];
  414. ICSBaseSimpleCode.AppshowMessageBox("上传成功 !");
  415. btnRefresh_Click(null, null);
  416. }
  417. catch (Exception ex)
  418. {
  419. throw new Exception(ex.Message);
  420. }
  421. }
  422. //下载事件
  423. private void repositoryItemButtonEdit2_Click(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  424. {
  425. //string connectionString = AppConfig.GetDataBaseConnectStringByKey("[DB.FTP]");
  426. //string[] ftps = connectionString.Split(';');
  427. //string ftpServerIP = ftps[0].Split('=')[1];
  428. //string ftpRemotePath = ftps[1].Split('=')[1];
  429. //string ftpUserID = ftps[2].Split('=')[1];
  430. //string ftpPassword = ftps[3].Split('=')[1];
  431. //FtpWeb ftpWeb = new FtpWeb(ftpServerIP, ftpRemotePath, ftpUserID, ftpPassword);
  432. //try
  433. //{
  434. // ICSLOTONWIPCheck model = ICSCollectBLL.GetModel(grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, ID).ToString(), AppConfig.AppConnectString);
  435. // if (string.IsNullOrEmpty(model.EATTRIBUTE1))
  436. // {
  437. // ICSBaseSimpleCode.AppshowMessageBox("暂无文档!");
  438. // return;
  439. // }
  440. // string path = System.Windows.Forms.Application.StartupPath + @"\PDF";
  441. // DirectoryInfo directoryInfo = new DirectoryInfo(path);
  442. // if (!Directory.Exists(path))
  443. // {
  444. // Directory.CreateDirectory(path);
  445. // }
  446. // string filePaths = path + @"\" + model.EATTRIBUTE1 + ".pdf";
  447. // ftpWeb.Download(path, model.EATTRIBUTE1 + ".pdf", model.EATTRIBUTE1);
  448. // FileDrawing.LoadPDF(filePaths);
  449. // ////string filePaths = @"C:\Users\Administrator.UX7663JVU2X64C5\Desktop\123.pdf";
  450. // //AxAcroPDFLib.AxAcroPDF axAcroPDF = new AxAcroPDFLib.AxAcroPDF();
  451. // //((System.ComponentModel.ISupportInitialize)(axAcroPDF)).BeginInit();
  452. // //axAcroPDF.Dock = DockStyle.Fill;
  453. // //this.Controls.Add(axAcroPDF);
  454. // //axAcroPDF.Location = new System.Drawing.Point(0, 24);
  455. // //((System.ComponentModel.ISupportInitialize)(axAcroPDF)).EndInit();
  456. // //axAcroPDF.LoadFile(filePaths);
  457. // //axAcroPDF.setShowToolbar(true);
  458. // //axAcroPDF.setPageMode("thumbs");
  459. // //axAcroPDF.setPageMode("none");
  460. // //axAcroPDF.Show();
  461. // ////System.Diagnostics.Process.Start(filePaths);
  462. //}
  463. //catch (Exception ex)
  464. //{
  465. // throw new Exception(ex.Message);
  466. //}
  467. }
  468. #endregion
  469. private void btnOutPut_Click_1(object sender, EventArgs e)
  470. {
  471. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  472. foe.ShowDialog();
  473. }
  474. }
  475. }