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

678 lines
34 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 FormICSONWIPCheckNCR : DevExpress.XtraEditors.XtraForm
  29. {
  30. string = "";
  31. string = "";
  32. private string sqltxt = "";
  33. private string sqlconn = "";
  34. private DataTable dataSource = null;
  35. public string Code = "";
  36. #region 构造函数
  37. public FormICSONWIPCheckNCR()
  38. {
  39. InitializeComponent();
  40. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  41. this.WindowState = FormWindowState.Maximized;
  42. }
  43. #endregion
  44. #region 操作权限
  45. public DataTable RightOfExute()
  46. {
  47. DataTable rData = new DataTable();
  48. rData.Columns.Add("BtnName");
  49. rData.Columns.Add("ActionName");
  50. //查看权限(必须有)
  51. DataRow seeRow = rData.NewRow();
  52. seeRow["BtnName"] = "see";
  53. seeRow["ActionName"] = "查看";
  54. rData.Rows.Add(seeRow);
  55. List<Control> ControlList = new List<Control>();
  56. ControlList.Add(btnCreate);
  57. ControlList.Add(btnModify);
  58. ControlList.Add(btnOutPut);
  59. foreach (Control ctr in ControlList)
  60. {
  61. if (ctr.GetType() == typeof(SimpleButton))
  62. {
  63. DataRow dr = rData.NewRow();
  64. dr["BtnName"] = ctr.Name;
  65. dr["ActionName"] = ctr.Text;
  66. rData.Rows.Add(dr);
  67. }
  68. }
  69. rData.AcceptChanges();
  70. return rData;
  71. }
  72. public DataTable RightOfData()// 数据权限
  73. {
  74. DataTable rData = new DataTable();
  75. rData.Columns.Add("BodyName");
  76. rData.Columns.Add("ControlName");
  77. rData.Columns.Add("ControlCaption");
  78. rData.AcceptChanges();
  79. return rData;
  80. }
  81. #endregion
  82. #region 退出
  83. private void btnClose_Click(object sender, EventArgs e)
  84. {
  85. AppConfig.CloseFormShow(this.Text);
  86. this.Close();
  87. }
  88. private void btnExit_Click(object sender, EventArgs e)
  89. {
  90. AppConfig.CloseFormShow(this.Text);
  91. this.Close();
  92. }
  93. #endregion
  94. #region 移动窗体
  95. private const int WM_NCHITTEST = 0x84;
  96. private const int HTCLIENT = 0x1;
  97. private const int HTCAPTION = 0x2;
  98. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  99. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  100. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  101. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  102. //重写窗体,使窗体可以不通过自带标题栏实现移动
  103. protected override void WndProc(ref Message m)
  104. {
  105. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  106. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  107. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  108. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  109. switch (m.Msg)
  110. {
  111. case WM_NCHITTEST:
  112. base.WndProc(ref m);
  113. if ((int)m.Result == HTCLIENT)
  114. m.Result = (IntPtr)HTCAPTION;
  115. return;
  116. }
  117. //拦截双击标题栏、移动窗体的系统消息
  118. if (m.Msg != 0xA3)
  119. {
  120. base.WndProc(ref m);
  121. }
  122. }
  123. #endregion
  124. #region 列表
  125. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  126. {
  127. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  128. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  129. }
  130. #endregion
  131. #region 全选
  132. private void btnSelectAll_Click(object sender, EventArgs e)
  133. {
  134. grvDetail.PostEditor();
  135. this.Validate();
  136. for (int i = 0; i < grvDetail.RowCount; i++)
  137. {
  138. grvDetail.SetRowCellValue(i, colisSelect, true);
  139. }
  140. }
  141. #endregion
  142. #region 全消
  143. private void btnCancelAll_Click(object sender, EventArgs e)
  144. {
  145. grvDetail.PostEditor();
  146. this.Validate();
  147. for (int i = 0; i < grvDetail.RowCount; i++)
  148. {
  149. grvDetail.SetRowCellValue(i, colisSelect, false);
  150. }
  151. }
  152. #endregion
  153. #region 导出
  154. private void btnOutPut_Click(object sender, EventArgs e)
  155. {
  156. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  157. foe.ShowDialog();
  158. }
  159. #endregion
  160. #region 刷新
  161. private void btnRefresh_Click(object sender, EventArgs e)
  162. {
  163. SearchData();
  164. }
  165. #endregion
  166. #region 上传OA
  167. private void btnCreate_Click(object sender, EventArgs e)
  168. {
  169. int limitResOPs = 29;
  170. DataRow[] drArr = GetSelectedRows();
  171. if (drArr == null)
  172. {
  173. return;
  174. }
  175. List<string> listNotSelectedMsg = new List<string>();
  176. foreach (DataRow dr in drArr)
  177. {
  178. if (!Convert.ToBoolean(dr["isSelect"]))
  179. {
  180. if (listNotSelectedMsg.Count == 0)
  181. {
  182. listNotSelectedMsg.Add("当前是批量处理,以下不良行未选取,是否选取全部?");
  183. }
  184. listNotSelectedMsg.Add("不良类型:" + dr["UNIT"].ToString() + "数量:" + dr["SetValue"].ToString() + "不良备注:" + dr["不良备注"].ToString());
  185. }
  186. }
  187. if (listNotSelectedMsg.Count > 0)
  188. {
  189. DialogResult drSelectAll = MessageBox.Show(string.Join(Environment.NewLine, listNotSelectedMsg), "提示", MessageBoxButtons.OKCancel);
  190. if (drSelectAll != DialogResult.OK)
  191. {
  192. return;
  193. }
  194. for (int i = 0; i < drArr.Length; i++)
  195. {
  196. if (Convert.ToBoolean(drArr[i]["isSelect"]) == false)
  197. {
  198. drArr[i]["isSelect"] = true;
  199. }
  200. }
  201. }
  202. DialogResult drUpload2OA = MessageBox.Show("确定上传OA吗", "提示", MessageBoxButtons.YesNo);
  203. if (drUpload2OA != DialogResult.Yes)
  204. {
  205. return;
  206. }
  207. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在保存...请稍等...");
  208. _wait.Show();
  209. string LOTNO = drArr[0]["LOTNO"].ToString();
  210. int OPSEQ = Convert.ToInt32(drArr[0]["OPSEQ"]);
  211. try
  212. {
  213. DateTime dt = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  214. List<ICSLOTONWIPCheckNCR> list = new List<ICSLOTONWIPCheckNCR>();
  215. string ncr = "";
  216. foreach (DataRow item in drArr)
  217. {
  218. ICSLOTONWIPCheckNCR Info = new ICSLOTONWIPCheckNCR();
  219. Info.ID = AppConfig.GetGuid();
  220. Info.CheckID = item["ID"].ToString();
  221. Info.Status = "处理中";
  222. Info.UpDateTime = dt;
  223. Info.NCRNo = null;
  224. Info.DownDateTime = null;
  225. Info.Memo = item["Memo"].ToString();
  226. Info.Type = item["CheckMode"].ToString();
  227. Info.IsInput = false;
  228. Info.MUSER = AppConfig.UserCode;
  229. Info.MUSERName = AppConfig.UserName;
  230. Info.MTIME = dt;
  231. Info.WorkPoint = AppConfig.WorkPointCode;
  232. list.Add(Info);
  233. }
  234. string FLOW_ID = ICSLOTONWIPCheckBLL.GetFLOW_ID(AppConfig.AppConnectString, AppConfig.WorkPointCode);//20,25
  235. string Source = ICSSys_EnumValuesBLL.GetNcrNGSource(AppConfig.AppConnectString, AppConfig.WorkPointCode);
  236. DataTable dtOPs = ICSResOPBLL.GetResOPList(LOTNO, OPSEQ, AppConfig.WorkPointCode);
  237. if (dtOPs.Rows.Count > limitResOPs)
  238. {
  239. throw new Exception("途径工序超过" + limitResOPs.ToString() + "道");
  240. }
  241. ICSLOTONWIPCheckBLL.AddNCROA(list, dtOPs, FLOW_ID, Source, AppConfig.AppConnectString);
  242. _wait.Close();
  243. btnRefresh_Click(null, null);
  244. }
  245. catch (Exception ex)
  246. {
  247. _wait.Close();
  248. ICSBaseSimpleCode.AppshowMessageBox("异常:" + ex.Message);
  249. }
  250. }
  251. #endregion
  252. #region 直接判定
  253. public void GetDirectlyResult(string Result, string ErrOP)
  254. {
  255. txtResult.Text = Result;
  256. txtErrOP.Text = ErrOP;
  257. }
  258. private void btnModify_Click(object sender, EventArgs e)
  259. {
  260. try
  261. {
  262. DataRow[] drArr = GetSelectedRows();
  263. if (drArr == null)
  264. {
  265. return;
  266. }
  267. FormICSONWIPCheckNCRSelect FrmSuspend = new FormICSONWIPCheckNCRSelect(drArr);
  268. FrmSuspend.action += new Action<string, string>(GetDirectlyResult);
  269. DialogResult dr = FrmSuspend.ShowDialog();
  270. if (dr != DialogResult.OK)
  271. {
  272. return;
  273. }
  274. string result = txtResult.Text.Trim();
  275. if (string.IsNullOrWhiteSpace(result))
  276. {
  277. ICSBaseSimpleCode.AppshowMessageBox("请选择结果判定!");
  278. return;
  279. }
  280. DialogResult dr2 = MessageBox.Show("确定直接判定:" + result + "?", "提示", MessageBoxButtons.YesNo);
  281. if (dr2 != DialogResult.Yes)
  282. {
  283. return;
  284. }
  285. NcrNotFromOA(drArr, result);
  286. //saveData(result);
  287. btnRefresh_Click(null, null);
  288. }
  289. catch (Exception ex)
  290. {
  291. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  292. }
  293. finally
  294. {
  295. txtResult.Text = "";
  296. txtErrOP.Text = "";
  297. }
  298. }
  299. /// <summary>
  300. /// NCR直接判定
  301. /// </summary>
  302. /// <param name="drArr"></param>
  303. /// <param name="result"></param>
  304. private void NcrNotFromOA(DataRow[] drArr, string result)
  305. {
  306. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在保存...请稍等...");
  307. try
  308. {
  309. _wait.Show();
  310. DateTime timeNow = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  311. List<ICSLOTONWIPCheckNCR> list = new List<ICSLOTONWIPCheckNCR>();
  312. for (int i = 0; i < drArr.Length; i++)
  313. {
  314. string chkmode = drArr[i]["CheckMode"].ToString();
  315. //if (status == "让步接受" && chkmode != "工序检验" && chkmode != "委外检验")
  316. //{
  317. // throw new Exception("过程检验不可让步接受");
  318. //}
  319. ICSLOTONWIPCheckNCR Info = new ICSLOTONWIPCheckNCR();
  320. Info.ID = AppConfig.GetGuid();
  321. Info.NCRNo = null;
  322. Info.CheckID = drArr[i]["ID"].ToString();
  323. Info.Status = result;
  324. Info.UpDateTime = timeNow;
  325. Info.DownDateTime = timeNow;
  326. Info.Memo = drArr[i]["Memo"].ToString();
  327. Info.Type = chkmode;
  328. Info.IsInput = true;//判定和结算工费合并,这里直接true,结算工费是不再更新此字段
  329. Info.MUSER = AppConfig.UserCode;
  330. Info.MUSERName = AppConfig.UserName;
  331. Info.MTIME = timeNow;
  332. Info.WorkPoint = AppConfig.WorkPointCode;
  333. Info.EATTRIBUTE1 = null;
  334. Info.ResOP = txtErrOP.Text;//责任工序
  335. list.Add(Info);
  336. }
  337. ICSLOTONWIPCheckBLL.AddNCR2(list, AppConfig.AppConnectString);
  338. _wait.Close();
  339. }
  340. catch (Exception ex)
  341. {
  342. _wait.Close();
  343. ICSBaseSimpleCode.AppshowMessageBox("异常:" + ex.Message);
  344. }
  345. }
  346. #endregion
  347. /// <summary>
  348. /// 选择,同跟踪单,工序,检验方式,且未处理的行
  349. /// 批量时,是同批次所有行,包含未选取的行
  350. /// </summary>
  351. /// <returns></returns>
  352. private DataRow[] GetSelectedRows()
  353. {
  354. if (dataSource == null)
  355. {
  356. return null;
  357. }
  358. DataRow[] drArr = dataSource.Select("(Status is null or Status='') and isSelect=true");
  359. if (drArr.Count() == 0)
  360. {
  361. return null;
  362. }
  363. if (drArr.GroupBy(a => new { LOTNO = a.Field<string>("LOTNO"), OPCODE = a.Field<string>("OPCODE") }).Count() > 1)
  364. {
  365. throw new Exception("所有行只能选择同一跟踪单,工序");
  366. }
  367. if (drArr.GroupBy(a => a.Field<string>("CheckMode")).Count() > 1)
  368. {
  369. throw new Exception("所有行只能选择一种检验类型,过程/工序/委外");
  370. }
  371. if (Convert.ToBoolean(drArr[0]["IsBatch"]) == true)
  372. {
  373. //只有委外才有批量和非批量,其他全是非批量
  374. string LOTNO = drArr[0]["LOTNO"].ToString();
  375. string OPCODE = drArr[0]["OPCODE"].ToString();
  376. string OPSEQ = drArr[0]["OPSEQ"].ToString();
  377. drArr = dataSource.Select(string.Format("(Status is null or Status='') and CheckMode='委外检验' and LOTNO='{0}' and OPSEQ={1} and OPCODE='{2}' ", LOTNO, OPSEQ, OPCODE));
  378. }
  379. return drArr;
  380. }
  381. #region 加载&查询数据
  382. private void FormICSONWIPCheckNCR_Load(object sender, EventArgs e)
  383. {
  384. try
  385. {
  386. SearchData();
  387. }
  388. catch (Exception ex)
  389. {
  390. ICSBaseSimpleCode.AppshowMessageBox("异常:" + ex.Message);
  391. }
  392. }
  393. private void SearchData()
  394. {
  395. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  396. try
  397. {
  398. _wait.Show();
  399. #region SQL
  400. // string sql = @"SELECT CAST( 0 AS BIT ) AS isSelect,CASE WHEN us.EATTRIBUTE1='0' THEN '工序检验' ELSE '委外检验' END AS CheckMode,
  401. // us.MOCODE,us.MOSEQ,a.ITEMCODE,b.INVNAME,b.INVSTD,a.LOTNO,a.OPCODE,d.OPDESC,ncr.IsInput,ncr.Status,a.LOTQTY AS Quantity,a.EQPCODE,eqp.EQPName,
  402. // chkdet.ID,ncr.ID AS NcrID,ncr.MTIME,ncr.MUSERName,ncr.Memo,NCRNo,chk.Status AS Result,chkdet.SetValue,chkdet.UNIT
  403. // FROM ICSLOTONWIP a
  404. // INNER JOIN ICSINVENTORY b ON a.ITEMCODE=b.INVCODE AND a.WorkPoint=b.WorkPoint
  405. // LEFT JOIN ICSEquipment eqp ON a.EQPCODE=eqp.EQPCode AND a.WorkPoint=eqp.WorkPoint
  406. // INNER JOIN ICSMO2User us ON a.LOTNO=us.LOTNO AND a.OPCODE=us.OPCODE AND a.WorkPoint=us.WorkPoint
  407. // INNER JOIN ICSITEMROUTE2OPLot lot ON a.LOTNO=lot.LOTNO AND a.OPCODE=lot.OPCODE AND a.WorkPoint=lot.WorkPoint
  408. // INNER JOIN ICSOP d ON a.OPCODE=d.OPCODE AND a.WorkPoint=d.WorkPoint
  409. // INNER JOIN ICSLOTONWIPCheck chk ON a.ID=chk.FORTRANID AND a.WorkPoint=chk.WorkPoint AND chk.Enable='1'
  410. //-- INNER JOIN (SELECT WorkPoint,FORTRANID,SUM(CONVERT(DECIMAL,ISNULL(SetValue,0))) AS SetValue, STUFF((SELECT ';'+UNIT FROM (select DISTINCT UNIT from ICSLOTONWIPCheckDetail where Type='不良' AND FORTRANID=b.FORTRANID AND WorkPoint=b.WorkPoint)a for xml path('')),1,1,'') AS UNIT
  411. //-- FROM ICSLOTONWIPCheckDetail b
  412. //-- WHERE Type='不良'
  413. //-- GROUP BY WorkPoint,FORTRANID) det ON chk.ID=det.FORTRANID AND chk.WorkPoint=det.WorkPoint
  414. // INNER JOIN ICSLOTONWIPCheckDetail chkdet ON chkdet.FORTRANID=chk.ID AND chkdet.WorkPoint=chk.WorkPoint AND chkdet.Type='不良'
  415. // LEFT JOIN ICSLOTONWIPCheckNCR ncr ON chkdet.ID=ncr.CheckID AND chkdet.WorkPoint=ncr.WorkPoint
  416. // WHERE a.WorkPoint='{0}' AND chk.Status='不良'
  417. // UNION ALL
  418. // SELECT CAST( 0 AS BIT ) AS isSelect,e.CheckMode,
  419. // us.MOCODE,us.MOSEQ,a.ITEMCODE,b.INVNAME,b.INVSTD,a.LOTNO,a.OPCODE,d.OPDESC,ncr.IsInput,ncr.Status,a.LOTQTY AS Quantity,a.EQPCODE,eqp.EQPName,
  420. // chkdet.ID,ncr.ID AS NcrID,ncr.MTIME,ncr.MUSERName,ncr.Memo,NCRNo,chk.Status AS Result,chkdet.SetValue,chkdet.UNIT
  421. // FROM ICSLOTONWIP a
  422. // INNER JOIN ICSINVENTORY b ON a.ITEMCODE=b.INVCODE AND a.WorkPoint=b.WorkPoint
  423. // LEFT JOIN ICSEquipment eqp ON a.EQPCODE=eqp.EQPCode AND a.WorkPoint=eqp.WorkPoint
  424. // INNER JOIN ICSMO2User us ON a.LOTNO=us.LOTNO AND a.OPCODE=us.OPCODE AND a.WorkPoint=us.WorkPoint
  425. // INNER JOIN ICSITEMROUTE2OPLot lot ON a.LOTNO=lot.LOTNO AND a.OPCODE=lot.OPCODE AND a.WorkPoint=lot.WorkPoint
  426. // INNER JOIN ICSOP d ON a.OPCODE=d.OPCODE AND a.WorkPoint=d.WorkPoint
  427. // INNER JOIN ICSLOTONWIPDetail Wipdet ON Wipdet.LOTNO=a.LOTNO AND Wipdet.OPCode=a.OPCODE AND a.WorkPoint=Wipdet.WorkPoint
  428. // INNER JOIN ICSLOTONWIPInspection e ON Wipdet.ID=e.DetailID AND Wipdet.WorkPoint=e.WorkPoint
  429. // INNER JOIN ICSLOTONWIPCheck chk ON e.ID=chk.FORTRANID AND e.WorkPoint=chk.WorkPoint AND chk.Enable='1'
  430. //-- INNER JOIN (SELECT WorkPoint,FORTRANID,SUM(CONVERT(DECIMAL,ISNULL(SetValue,0))) AS SetValue, STUFF((SELECT ';'+UNIT FROM (select DISTINCT UNIT from ICSLOTONWIPCheckDetail where Type='不良' AND FORTRANID=b.FORTRANID AND WorkPoint=b.WorkPoint)a for xml path('')),1,1,'') AS UNIT
  431. //-- FROM ICSLOTONWIPCheckDetail b
  432. //-- WHERE Type='不良'
  433. //-- GROUP BY WorkPoint,FORTRANID) det ON chk.ID=det.FORTRANID AND chk.WorkPoint=det.WorkPoint
  434. // INNER JOIN ICSLOTONWIPCheckDetail chkdet ON chkdet.FORTRANID=chk.ID AND chkdet.WorkPoint=chk.WorkPoint AND chkdet.Type='不良'
  435. // LEFT JOIN ICSLOTONWIPCheckNCR ncr ON chkdet.ID=ncr.CheckID AND chkdet.WorkPoint=ncr.WorkPoint
  436. // WHERE a.WorkPoint='{0}' AND chk.Status='不良' ORDER BY ncr.MTIME,a.LOTNO
  437. //
  438. // select EnumText as [不合格责任方] from Sys_EnumValues WHERE EnumKey='00102' AND WorkPointCode='{0}'
  439. // select EnumText as [不良起源] from Sys_EnumValues WHERE EnumKey='00101' AND WorkPointCode='{0}'
  440. // select EnumText as [结果判定] from Sys_EnumValues WHERE EnumKey='00103' AND WorkPointCode='{0}'";
  441. string sql = @"
  442. SELECT CAST( 0 AS BIT ) AS isSelect,CASE WHEN us.EATTRIBUTE1='0' THEN '' ELSE '' END AS CheckMode,
  443. us.MOCODE,us.MOSEQ,a.ITEMCODE,b.INVNAME,b.INVSTD,a.LOTNO,a.OPSEQ,a.OPCODE,d.OPDESC,ncr.IsInput,ISNULL(ncr.OAError,ncr.Status)AS Status,a.LOTQTY AS Quantity,a.EQPCODE,eqp.EQPName,
  444. chkdet.ID,ncr.ID AS NcrID,ncr.MTIME,ncr.MUSERName,ncr.Memo,NCRNo,chk.Status AS Result,chkdet.SetValue,chkdet.UNIT,
  445. b.[version] AS ,b.INVMODELGROUP AS ,b.INVGROUPDESC AS ,
  446. mo.MOVER AS ,u.UserName AS ,chkdet.CKGROUPMETH AS ,ISNULL(chk.IsBatch,CONVERT(BIT,0)) IsBatch,ISNULL(lot.ISWWRW,CONVERT(BIT,0)) ISWWRW
  447. FROM ICSLOTONWIP a
  448. INNER JOIN ICSINVENTORY b ON a.ITEMCODE=b.INVCODE AND a.WorkPoint=b.WorkPoint
  449. LEFT JOIN ICSEquipment eqp ON a.EQPCODE=eqp.EQPCode AND a.WorkPoint=eqp.WorkPoint
  450. INNER JOIN ICSMO2User us ON a.LOTNO=us.LOTNO AND a.OPCODE=us.OPCODE AND a.WorkPoint=us.WorkPoint
  451. INNER JOIN dbo.ICSMO mo ON mo.MOCODE=us.MOCODE AND mo.MOSEQ=us.MOSEQ AND mo.WorkPoint=us.WorkPoint
  452. INNER JOIN ICSITEMROUTE2OPLot lot ON a.LOTNO=lot.LOTNO AND a.OPCODE=lot.OPCODE AND a.WorkPoint=lot.WorkPoint
  453. INNER JOIN ICSOP d ON a.OPCODE=d.OPCODE AND a.WorkPoint=d.WorkPoint
  454. INNER JOIN ICSLOTONWIPCheck chk ON a.ID=chk.FORTRANID AND a.WorkPoint=chk.WorkPoint AND chk.Enable='1'
  455. LEFT JOIN Sys_User u ON u.UserCode=chk.EATTRIBUTE1 AND u.WorkPointCode=chk.WorkPoint
  456. -- INNER JOIN (SELECT WorkPoint,FORTRANID,SUM(CONVERT(DECIMAL,ISNULL(SetValue,0))) AS SetValue, STUFF((SELECT ';'+UNIT FROM (select DISTINCT UNIT from ICSLOTONWIPCheckDetail where Type='' AND FORTRANID=b.FORTRANID AND WorkPoint=b.WorkPoint)a for xml path('')),1,1,'') AS UNIT
  457. -- FROM ICSLOTONWIPCheckDetail b
  458. -- WHERE Type=''
  459. -- GROUP BY WorkPoint,FORTRANID) det ON chk.ID=det.FORTRANID AND chk.WorkPoint=det.WorkPoint
  460. INNER JOIN ICSLOTONWIPCheckDetail chkdet ON chkdet.FORTRANID=chk.ID AND chkdet.WorkPoint=chk.WorkPoint AND chkdet.Type=''
  461. LEFT JOIN ICSLOTONWIPCheckNCR ncr ON chkdet.ID=ncr.CheckID AND chkdet.WorkPoint=ncr.WorkPoint
  462. WHERE a.WorkPoint='{0}' AND chk.Status=''
  463. UNION ALL
  464. SELECT CAST( 0 AS BIT ) AS isSelect,e.CheckMode,
  465. us.MOCODE,us.MOSEQ,a.ITEMCODE,b.INVNAME,b.INVSTD,a.LOTNO,a.OPSEQ,a.OPCODE,d.OPDESC,ncr.IsInput,ncr.Status,a.LOTQTY AS Quantity,a.EQPCODE,eqp.EQPName,
  466. chkdet.ID,ncr.ID AS NcrID,ncr.MTIME,ncr.MUSERName,ncr.Memo,NCRNo,chk.Status AS Result,chkdet.SetValue,chkdet.UNIT,
  467. b.[version] AS ,b.INVMODELGROUP AS ,b.INVGROUPDESC AS ,
  468. mo.MOVER AS ,u.UserName AS ,chkdet.CKGROUPMETH AS ,ISNULL(chk.IsBatch,CONVERT(BIT,0)) IsBatch,ISNULL(lot.ISWWRW,CONVERT(BIT,0)) ISWWRW
  469. FROM ICSLOTONWIP a
  470. INNER JOIN ICSINVENTORY b ON a.ITEMCODE=b.INVCODE AND a.WorkPoint=b.WorkPoint
  471. LEFT JOIN ICSEquipment eqp ON a.EQPCODE=eqp.EQPCode AND a.WorkPoint=eqp.WorkPoint
  472. INNER JOIN ICSMO2User us ON a.LOTNO=us.LOTNO AND a.OPCODE=us.OPCODE AND a.WorkPoint=us.WorkPoint
  473. INNER JOIN dbo.ICSMO mo ON mo.MOCODE=us.MOCODE AND mo.MOSEQ=us.MOSEQ AND mo.WorkPoint=us.WorkPoint
  474. INNER JOIN ICSITEMROUTE2OPLot lot ON a.LOTNO=lot.LOTNO AND a.OPCODE=lot.OPCODE AND a.WorkPoint=lot.WorkPoint
  475. INNER JOIN ICSOP d ON a.OPCODE=d.OPCODE AND a.WorkPoint=d.WorkPoint
  476. INNER JOIN ICSLOTONWIPDetail Wipdet ON Wipdet.LOTNO=a.LOTNO AND Wipdet.OPCode=a.OPCODE AND a.WorkPoint=Wipdet.WorkPoint
  477. INNER JOIN ICSLOTONWIPInspection e ON Wipdet.ID=e.DetailID AND Wipdet.WorkPoint=e.WorkPoint
  478. INNER JOIN ICSLOTONWIPCheck chk ON e.ID=chk.FORTRANID AND e.WorkPoint=chk.WorkPoint AND chk.Enable='1'
  479. LEFT JOIN Sys_User u ON u.UserCode=chk.EATTRIBUTE1 AND u.WorkPointCode=chk.WorkPoint
  480. -- INNER JOIN (SELECT WorkPoint,FORTRANID,SUM(CONVERT(DECIMAL,ISNULL(SetValue,0))) AS SetValue, STUFF((SELECT ';'+UNIT FROM (select DISTINCT UNIT from ICSLOTONWIPCheckDetail where Type='' AND FORTRANID=b.FORTRANID AND WorkPoint=b.WorkPoint)a for xml path('')),1,1,'') AS UNIT
  481. -- FROM ICSLOTONWIPCheckDetail b
  482. -- WHERE Type=''
  483. -- GROUP BY WorkPoint,FORTRANID) det ON chk.ID=det.FORTRANID AND chk.WorkPoint=det.WorkPoint
  484. INNER JOIN ICSLOTONWIPCheckDetail chkdet ON chkdet.FORTRANID=chk.ID AND chkdet.WorkPoint=chk.WorkPoint AND chkdet.Type=''
  485. LEFT JOIN ICSLOTONWIPCheckNCR ncr ON chkdet.ID=ncr.CheckID AND chkdet.WorkPoint=ncr.WorkPoint
  486. WHERE a.WorkPoint='{0}' AND chk.Status='' ORDER BY ncr.MTIME,a.LOTNO
  487. select EnumText as [] from Sys_EnumValues WHERE EnumKey='00102' AND WorkPointCode='{0}'
  488. select EnumText as [] from Sys_EnumValues WHERE EnumKey='00101' AND WorkPointCode='{0}'
  489. select EnumText as [] from Sys_EnumValues WHERE EnumKey='00103' AND WorkPointCode='{0}'
  490. ";
  491. #endregion
  492. sql = string.Format(sql, AppConfig.WorkPointCode);
  493. DataSet ds = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql);
  494. dataSource = ds.Tables[0];
  495. grdDetail.DataSource = dataSource;
  496. grvDetail.BestFitColumns();
  497. //#region 不合格责任方
  498. //txtNG.Properties.ValueMember = "不合格责任方";
  499. //txtNG.Properties.DisplayMember = "不合格责任方";
  500. //txtNG.Properties.DataSource = ds.Tables[1];
  501. //txtNG.Properties.NullText = "";//空时的值
  502. //txtNG.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体
  503. //txtNG.Properties.ValidateOnEnterKey = true;//回车确认
  504. //txtNG.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
  505. //txtNG.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  506. ////自适应宽度
  507. //txtNG.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  508. //#endregion
  509. //#region 不良起源
  510. //txtSource.Properties.ValueMember = "不良起源";
  511. //txtSource.Properties.DisplayMember = "不良起源";
  512. //txtSource.Properties.DataSource = ds.Tables[2];
  513. //txtSource.Properties.NullText = "";//空时的值
  514. //txtSource.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体
  515. //txtSource.Properties.ValidateOnEnterKey = true;//回车确认
  516. //txtSource.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
  517. //txtSource.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  518. ////自适应宽度
  519. //txtSource.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  520. //if (ds.Tables[2] == null || ds.Tables[2].Rows.Count <= 0)
  521. // throw new Exception("不良起源未维护!");
  522. //else
  523. // txtSource.Text = ds.Tables[2].Rows[0][0].ToString();
  524. //#endregion
  525. //#region 结果判定
  526. //txtResult.Properties.ValueMember = "结果判定";
  527. //txtResult.Properties.DisplayMember = "结果判定";
  528. //txtResult.Properties.DataSource = ds.Tables[3];
  529. //txtResult.Properties.NullText = "";//空时的值
  530. //txtResult.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体
  531. //txtResult.Properties.ValidateOnEnterKey = true;//回车确认
  532. //txtResult.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
  533. //txtResult.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  534. ////自适应宽度
  535. //txtResult.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  536. //#endregion
  537. _wait.Close();
  538. }
  539. catch (Exception ex)
  540. {
  541. _wait.Close();
  542. ICSBaseSimpleCode.AppshowMessageBox("异常:" + ex.Message);
  543. }
  544. }
  545. #endregion
  546. #region 保存数据
  547. private void saveData(string status)
  548. {
  549. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在保存...请稍等...");
  550. try
  551. {
  552. _wait.Show();
  553. DateTime dt = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  554. List<ICSLOTONWIPCheckNCR> list = new List<ICSLOTONWIPCheckNCR>();
  555. for (int i = 0; i < grvDetail.RowCount; i++)
  556. {
  557. if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect))
  558. && string.IsNullOrWhiteSpace(grvDetail.GetRowCellValue(i, colStatus).ToString()))
  559. {
  560. string chkmode = grvDetail.GetRowCellValue(i, colCheckMode).ToString();
  561. //if (status == "让步接受" && chkmode != "工序检验" && chkmode != "委外检验")
  562. //{
  563. // throw new Exception("过程检验不可让步接受");
  564. //}
  565. ICSLOTONWIPCheckNCR Info = new ICSLOTONWIPCheckNCR();
  566. Info.ID = AppConfig.GetGuid();
  567. Info.CheckID = grvDetail.GetRowCellValue(i, colID).ToString();
  568. Info.Status = status;
  569. Info.UpDateTime = dt;
  570. Info.DownDateTime = dt;
  571. Info.Memo = grvDetail.GetRowCellValue(i, colMemo).ToString();
  572. Info.Type = chkmode;
  573. Info.IsInput = false;
  574. Info.MUSER = AppConfig.UserCode;
  575. Info.MUSERName = AppConfig.UserName;
  576. Info.MTIME = dt;
  577. Info.WorkPoint = AppConfig.WorkPointCode;
  578. Info.EATTRIBUTE1 = null;
  579. Info.ResOP = txtErrOP.Text == "" ? null : txtErrOP.Text;
  580. list.Add(Info);
  581. }
  582. }
  583. if (list.Count == 0)
  584. {
  585. _wait.Close();
  586. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  587. return;
  588. }
  589. ICSLOTONWIPCheckBLL.AddNCR(list, AppConfig.AppConnectString);
  590. _wait.Close();
  591. }
  592. catch (Exception ex)
  593. {
  594. _wait.Close();
  595. ICSBaseSimpleCode.AppshowMessageBox("异常:" + ex.Message);
  596. }
  597. }
  598. #endregion
  599. #region 结算工费
  600. private void btnCalculate_Click(object sender, EventArgs e)
  601. {
  602. List<string> IDs = new List<string>();
  603. for (int i = 0; i < grvDetail.RowCount; i++)
  604. {
  605. if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect))
  606. && grvDetail.GetRowCellValue(i, colCheckMode).ToString().Equals("委外检验")
  607. && grvDetail.GetRowCellValue(i, colStatus).ToString().Equals("让步接受")
  608. && !Convert.ToBoolean(grvDetail.GetRowCellValue(i, colIsInput)))
  609. {
  610. IDs.Add(grvDetail.GetRowCellValue(i, colNcrID).ToString());
  611. }
  612. }
  613. if (IDs.Count <= 0)
  614. {
  615. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  616. return;
  617. }
  618. DialogResult DDR = MessageBox.Show("确定结算工费吗?", "提示", MessageBoxButtons.YesNo);
  619. if (DDR != DialogResult.Yes)
  620. {
  621. return;
  622. }
  623. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在保存...请稍等...");
  624. try
  625. {
  626. _wait.Show();
  627. ICSLOTONWIPCheckBLL.AddNCRNC(IDs, AppConfig.AppConnectString);
  628. _wait.Close();
  629. btnRefresh_Click(null, null);
  630. }
  631. catch (Exception ex)
  632. {
  633. _wait.Close();
  634. ICSBaseSimpleCode.AppshowMessageBox("异常:" + ex.Message);
  635. }
  636. }
  637. #endregion
  638. }
  639. }