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

499 lines
20 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 ICSSoft.Frame.User.BLL;
  10. using ICSSoft.Base.Language.Tool;
  11. using ICSSoft.Base.UserControl.MessageControl;
  12. using System.Data.SqlClient;
  13. using ICSSoft.Base.Config.AppConfig;
  14. using ICSSoft.Base.Report.Filter;
  15. using ICSSoft.Base.Config.DBHelper;
  16. using ICSSoft.Base.UserControl.FormControl;
  17. using ICSSoft.Base.ReferForm.AppReferForm;
  18. using ICSSoft.Base.Lable.PrintTool;
  19. using ICSSoft.Frame.Data.DAL;
  20. using ICSSoft.Frame.Data.BLL;
  21. using ICSSoft.Frame.Data.Entity;
  22. using System.IO;
  23. using System.Xml;
  24. using System.Reflection;
  25. using System.Linq;
  26. namespace ICSSoft.Frame.APP
  27. {
  28. public partial class FormICSCOM : DevExpress.XtraEditors.XtraForm
  29. {
  30. private const string ENDSTATUS = "COLLECT_END";
  31. private const string STARTSTATUS = "COLLECT_BEGIN";
  32. private string sqltxt = "";
  33. private string sqlconn = "";
  34. String guid = AppConfig.GetGuid();
  35. private DataTable dataSource = null;
  36. string itemname = "";
  37. string time = "";
  38. #region 构造函数
  39. public FormICSCOM()
  40. {
  41. InitializeComponent();
  42. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  43. this.WindowState = FormWindowState.Maximized;
  44. foreach (DevExpress.XtraGrid.Columns.GridColumn col in grvDetail.Columns)
  45. {
  46. col.OptionsColumn.AllowEdit = col.Name == colSerial.Name;
  47. // col.OptionsColumn.ReadOnly = true;
  48. }
  49. }
  50. #endregion
  51. #region 操作权限
  52. public DataTable RightOfExute()
  53. {
  54. DataTable rData = new DataTable();
  55. rData.Columns.Add("BtnName");
  56. rData.Columns.Add("ActionName");
  57. //查看权限(必须有)
  58. DataRow seeRow = rData.NewRow();
  59. seeRow["BtnName"] = "see";
  60. seeRow["ActionName"] = "查看";
  61. rData.Rows.Add(seeRow);
  62. foreach (Control ctr in panelControl3.Controls)
  63. {
  64. if (ctr.Name == btnFilter.Name || ctr.Name == btnConfig.Name ||
  65. ctr.Name == btnSelectAll.Name || ctr.Name == btnCancelAll.Name ||
  66. ctr.Name == btnOutPut.Name || ctr.Name == btnRefresh.Name || ctr.Name == MOTitle.Name || ctr.Name == btnClose.Name)
  67. continue;
  68. DataRow dr = rData.NewRow();
  69. dr["BtnName"] = ctr.Name;
  70. dr["ActionName"] = ctr.Text;
  71. rData.Rows.Add(dr);
  72. }
  73. //List<Control> ControlList = new List<Control>();
  74. //ControlList.Add(btnCreate);
  75. //ControlList.Add(btnModify);
  76. //ControlList.Add(btnDel);
  77. //ControlList.Add(btnOutPut);
  78. //foreach (Control ctr in ControlList)
  79. //{
  80. // if (ctr.GetType() == typeof(SimpleButton))
  81. // {
  82. // DataRow dr = rData.NewRow();
  83. // dr["BtnName"] = ctr.Name;
  84. // dr["ActionName"] = ctr.Text;
  85. // rData.Rows.Add(dr);
  86. // }
  87. //}
  88. rData.AcceptChanges();
  89. return rData;
  90. }
  91. public DataTable RightOfData()// 数据权限
  92. {
  93. DataTable rData = new DataTable();
  94. rData.Columns.Add("BodyName");
  95. rData.Columns.Add("ControlName");
  96. rData.Columns.Add("ControlCaption");
  97. rData.AcceptChanges();
  98. return rData;
  99. }
  100. #endregion
  101. #region 退出
  102. private void btnClose_Click(object sender, EventArgs e)
  103. {
  104. AppConfig.CloseFormShow(this.Text);
  105. this.Close();
  106. }
  107. private void btnExit_Click(object sender, EventArgs e)
  108. {
  109. AppConfig.CloseFormShow(this.Text);
  110. this.Close();
  111. }
  112. #endregion
  113. #region 移动窗体
  114. private const int WM_NCHITTEST = 0x84;
  115. private const int HTCLIENT = 0x1;
  116. private const int HTCAPTION = 0x2;
  117. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  118. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  119. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  120. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  121. //重写窗体,使窗体可以不通过自带标题栏实现移动
  122. protected override void WndProc(ref Message m)
  123. {
  124. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  125. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  126. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  127. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  128. switch (m.Msg)
  129. {
  130. case WM_NCHITTEST:
  131. base.WndProc(ref m);
  132. if ((int)m.Result == HTCLIENT)
  133. m.Result = (IntPtr)HTCAPTION;
  134. return;
  135. }
  136. //拦截双击标题栏、移动窗体的系统消息
  137. if (m.Msg != 0xA3)
  138. {
  139. base.WndProc(ref m);
  140. }
  141. }
  142. #endregion
  143. #region 列表
  144. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  145. {
  146. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  147. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  148. }
  149. #endregion
  150. #region 过滤
  151. private string tempTableName = "";
  152. private void btnFilter_Click(object sender, EventArgs e)
  153. {
  154. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  155. filter.OldTempTableName = tempTableName;
  156. if (filter.ShowDialog() == DialogResult.OK)
  157. {
  158. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  159. try
  160. {
  161. _wait.Show();
  162. tempTableName = filter.NewTempTableName;
  163. sqltxt = filter.SqlText;
  164. sqlconn = filter.FilterConnectString;
  165. dataSource = filter.FilterData.Tables[0];
  166. grdDetail.DataSource = dataSource;
  167. grvDetail.BestFitColumns();
  168. rptPage.RecordNum = dataSource.Rows.Count;
  169. rptPage.PageSize = 500000;
  170. rptPage.PageIndex = 1;
  171. rptPage.ReLoad();
  172. _wait.Close();
  173. }
  174. catch (Exception ex)
  175. {
  176. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  177. _wait.Close();
  178. }
  179. }
  180. }
  181. #endregion
  182. #region 绑定数据源
  183. private void btnConfig_Click(object sender, EventArgs e)
  184. {
  185. if (AppConfig.UserCode.ToLower() != "demo")
  186. {
  187. ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  188. return;
  189. }
  190. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  191. fdata.ShowDialog();
  192. }
  193. #endregion
  194. #region 分页
  195. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  196. {
  197. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  198. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  199. grdDetail.DataSource = data;
  200. }
  201. #endregion
  202. #region 过滤方法
  203. private void FormContainerManager_FormClosing(object sender, FormClosingEventArgs e)
  204. {
  205. AppConfig.DropTemTable(tempTableName);
  206. }
  207. #endregion
  208. #region 全选
  209. private void btnSelectAll_Click(object sender, EventArgs e)
  210. {
  211. grvDetail.PostEditor();
  212. this.Validate();
  213. for (int i = 0; i < grvDetail.RowCount; i++)
  214. {
  215. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  216. }
  217. }
  218. #endregion
  219. #region 全消
  220. private void btnCancelAll_Click(object sender, EventArgs e)
  221. {
  222. grvDetail.PostEditor();
  223. this.Validate();
  224. for (int i = 0; i < grvDetail.RowCount; i++)
  225. {
  226. grvDetail.SetRowCellValue(i, colisSelect, "");
  227. }
  228. }
  229. #endregion
  230. #region 双击
  231. private void grvDetail_DoubleClick(object sender, EventArgs e)
  232. {
  233. if (grvDetail.FocusedRowHandle < 0)
  234. {
  235. return;
  236. }
  237. if (grvDetail.FocusedColumn == colisSelect)
  238. {
  239. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  240. {
  241. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  242. }
  243. else
  244. {
  245. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  246. }
  247. }
  248. }
  249. #endregion
  250. #region 导出
  251. private void btnOutPut_Click(object sender, EventArgs e)
  252. {
  253. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  254. foe.ShowDialog();
  255. }
  256. #endregion
  257. #region 刷新
  258. private void btnRefresh_Click(object sender, EventArgs e)
  259. {
  260. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  261. try
  262. {
  263. if (sqlconn == null || sqlconn == "" || sqltxt == "")
  264. {
  265. return;
  266. }
  267. _wait.Show();
  268. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  269. filter.OldTempTableName = tempTableName;
  270. //tempTableName = filter.NewTempTableName;
  271. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  272. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  273. grdDetail.DataSource = dataSource;
  274. grvDetail.BestFitColumns();
  275. rptPage.RecordNum = dataSource.Rows.Count;
  276. rptPage.PageIndex = 1;
  277. rptPage.ReLoad();
  278. _wait.Close();
  279. }
  280. catch (Exception ex)
  281. {
  282. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  283. _wait.Close();
  284. }
  285. }
  286. #endregion
  287. #region 开启
  288. private void btnCreate_Click(object sender, EventArgs e)
  289. {
  290. SimpleButton btntemp = (SimpleButton)sender;
  291. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  292. {
  293. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  294. return;
  295. }
  296. try
  297. {
  298. //FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  299. //db.Connection.Open();
  300. //db.Transaction = db.Connection.BeginTransaction();
  301. //try
  302. //{
  303. // for (int i = 0; i < grvDetail.RowCount; i++)
  304. // {
  305. // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  306. // {
  307. // string MOID = grvDetail.GetRowCellValue(i, colID).ToString();
  308. // string ITEMCODE = grvDetail.GetRowCellValue(i, colITEMCODE).ToString();
  309. // string ROUTECODE = grvDetail.GetRowCellValue(i, colROUTECODE).ToString();
  310. // string lotNo = grvDetail.GetRowCellValue(i, colLOTNO).ToString();
  311. // string msg = "";
  312. // var itemroute2ops = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo == lotNo && a.ITEMCODE == ITEMCODE && a.ROUTECODE == ROUTECODE && a.WorkPoint == AppConfig.WorkPointCode);
  313. // if (itemroute2ops == null || itemroute2ops.Count() <= 0)
  314. // {
  315. // msg += "产品跟踪单号:" + lotNo + ",存货编码:" + ITEMCODE + ",途程代码:" + ROUTECODE +
  316. // ",不存在!" + Environment.NewLine;
  317. // }
  318. // //循环产品工艺路线工序里面的工序,是否全部采集完成,采集完成更新ICSLOTSIMULATION
  319. // foreach (var itemroute2op in itemroute2ops)
  320. // {
  321. // //判断工序是否报工
  322. // var onwips = db.ICSLOTONWIP.Where(a => a.LOTNO == lotNo && a.OPCODE == itemroute2op.OPCODE && a.ACTION == "GOOD" && a.WorkPoint == AppConfig.WorkPointCode);
  323. // if (onwips == null || onwips.Count() <= 0)
  324. // {
  325. // msg += "产品跟踪单号:" + lotNo + ",存货编码:" + ITEMCODE + ",工序代码:" + itemroute2op.OPCODE +
  326. // ",未开工!" + Environment.NewLine;
  327. // }
  328. // else
  329. // {
  330. // foreach(ICSLOTONWIP onwip in onwips)
  331. // {
  332. // if (onwip.ACTIONRESULT == STARTSTATUS)
  333. // {
  334. // msg += "产品跟踪单号:" + lotNo + ",存货编码:" + ITEMCODE + ",工序代码:" + itemroute2op.OPCODE +
  335. // ",未完工!" + Environment.NewLine;
  336. // }
  337. // else
  338. // {
  339. // var check = db.ICSLOTONWIPCheck.SingleOrDefault(a => a.ONWIPID == onwip.ID);
  340. // if (check == null || check.Result != "合格")
  341. // {
  342. // msg += "产品跟踪单号:" + lotNo + ",存货编码:" + ITEMCODE + ",工序代码:" + itemroute2op.OPCODE +
  343. // ",未检验或检验不合格!" + Environment.NewLine;
  344. // }
  345. // }
  346. // }
  347. // }
  348. // }
  349. // if (!string.IsNullOrWhiteSpace(msg)) //更新完工状态
  350. // {
  351. // throw new Exception(msg);
  352. // }
  353. // else
  354. // {
  355. // DateTime time = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  356. // var simulation = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == lotNo);
  357. // if (simulation.LOTStatus == "暂停")
  358. // throw new Exception("产品跟踪单号:" + lotNo + ",处于暂停状态,无法完工!");
  359. // simulation.ISCOM = "1";
  360. // simulation.CollectStatus = ENDSTATUS;
  361. // simulation.MTIME = time;
  362. // simulation.EndTime = time;
  363. // }
  364. // }
  365. // }
  366. // db.SubmitChanges();
  367. // db.Transaction.Commit();
  368. // ICSBaseSimpleCode.AppshowMessageBox("工单完工成功!");
  369. // btnRefresh_Click(null, null);
  370. //}
  371. //catch (Exception ex)
  372. //{
  373. // db.Transaction.Rollback();
  374. // throw new Exception(ex.Message);
  375. //}
  376. }
  377. catch (Exception ex)
  378. {
  379. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  380. }
  381. }
  382. #endregion
  383. #region 关闭
  384. private void btnModify_Click(object sender, EventArgs e)
  385. {
  386. SimpleButton btntemp = (SimpleButton)sender;
  387. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  388. {
  389. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  390. return;
  391. }
  392. try
  393. {
  394. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  395. db.Connection.Open();
  396. db.Transaction = db.Connection.BeginTransaction();
  397. try
  398. {
  399. for (int i = 0; i < grvDetail.RowCount; i++)
  400. {
  401. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  402. {
  403. string lotNo = grvDetail.GetRowCellValue(i, colLOTNO).ToString();
  404. var simulation = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == lotNo);
  405. if (simulation != null && simulation.ISCOM=="1") //更新完工状态
  406. {
  407. DateTime time = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  408. simulation.ISCOM = "0";
  409. //simulation.CollectStatus = STARTSTATUS;
  410. simulation.MTIME = time;
  411. }
  412. else
  413. {
  414. throw new Exception("批次:" + lotNo + " 不是完工状态,不能取消完工!");
  415. }
  416. }
  417. }
  418. db.SubmitChanges();
  419. db.Transaction.Commit();
  420. ICSBaseSimpleCode.AppshowMessageBox("工单取消完工成功!");
  421. btnRefresh_Click(null, null);
  422. }
  423. catch (Exception ex)
  424. {
  425. db.Transaction.Rollback();
  426. throw new Exception(ex.Message);
  427. }
  428. }
  429. catch (Exception ex)
  430. {
  431. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  432. }
  433. }
  434. #endregion
  435. private void ICSItemLot_FormClosing(object sender, FormClosingEventArgs e)
  436. {
  437. AppConfig.DropTemTable(tempTableName);
  438. }
  439. private void FormICSCOM_Load(object sender, EventArgs e)
  440. {
  441. btnFilter_Click(sender, e);
  442. }
  443. }
  444. }