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

3210 lines
151 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.Base.Language.Tool;
  10. using ICSSoft.Base.Config.AppConfig;
  11. using ICSSoft.Base.UserControl.MessageControl;
  12. using ICSSoft.Base.Config.DBHelper;
  13. using ICSSoft.Base.Report.Filter;
  14. using ICSSoft.Base.UserControl.FormControl;
  15. using ICSSoft.Base.Report.GridReport;
  16. using ICSSoft.Base.ReferForm.AppReferForm;
  17. using ICSSoft.Frame.Data.BLL;
  18. using Newtonsoft.Json;
  19. using System.Net;
  20. using System.Configuration;
  21. using ICSSoft.Entity.PU_AppVouch;
  22. using ICSSoft.Frame.Data.Entity.WWModel;
  23. using ICSSoft.Frame.Data.DAL;
  24. using System.Reflection;
  25. using DevExpress.XtraGrid.Views.Grid;
  26. using DevExpress.Data.Filtering;
  27. using System.Linq;
  28. using ICSSoft.Frame.Data.Entity;
  29. using System.Data.SqlClient;
  30. using System.IO;
  31. using System.Linq.Expressions;
  32. namespace ICSSoft.Frame.APP
  33. {
  34. public partial class FormICSMO2UserSendNew : DevExpress.XtraEditors.XtraForm
  35. {
  36. private string sqltxt = "";
  37. private string sqlconn = "";
  38. String guid = AppConfig.GetGuid();
  39. private DataTable dataUser = null;
  40. private DataTable data = null;
  41. private DataTable dtSend = null;
  42. private DataTable dtLotno = null;
  43. private bool isQueryCloseUp = false;
  44. private bool isQueryCloseUpEQP = false;
  45. //WorkPointBLL workBll = new WorkPointBLL();
  46. static string APIURL = System.Configuration.ConfigurationSettings.AppSettings["APIURL"].ToString();
  47. //static string APIURL = "http://localhost:51182/api/";
  48. static string DataCollectWW = APIURL + "APICreateInventory_PU_AppVouch";
  49. //static string DataCollectWW = "http://localhost:51182/api/" + "APICreateInventory_PU_AppVouch";
  50. string PoKey = ConfigurationManager.AppSettings["PoKey"];
  51. string DjIp = ConfigurationManager.AppSettings["WorkHourIp"];
  52. string EntId = ConfigurationManager.AppSettings["WorkHourEntId"];
  53. string CompanyId = ConfigurationManager.AppSettings["WorkHourCompanyId"];
  54. string VendorView = ConfigurationManager.AppSettings["VendorView"];
  55. string PoDocNo= ConfigurationManager.AppSettings["PoDocNo"];
  56. string DjAddress= ConfigurationManager.AppSettings["WorkHourIpAddress"];
  57. #region 构造函数
  58. public FormICSMO2UserSendNew(Dictionary<string, string> sendMes)
  59. {
  60. InitializeComponent();
  61. dateTimePicker1.Checked = false;
  62. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  63. this.WindowState = FormWindowState.Maximized;
  64. splitContainer1.Enabled = true;
  65. SearchMO(sendMes);
  66. //SearchItemLotInfo(MOID);
  67. }
  68. public FormICSMO2UserSendNew()
  69. {
  70. InitializeComponent();
  71. dateTimePicker1.Checked = false;
  72. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  73. this.WindowState = FormWindowState.Maximized;
  74. }
  75. #endregion
  76. #region 移动窗体
  77. private const int WM_NCHITTEST = 0x84;
  78. private const int HTCLIENT = 0x1;
  79. private const int HTCAPTION = 0x2;
  80. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  81. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  82. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  83. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  84. //重写窗体,使窗体可以不通过自带标题栏实现移动
  85. protected override void WndProc(ref Message m)
  86. {
  87. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  88. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  89. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  90. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  91. switch (m.Msg)
  92. {
  93. case WM_NCHITTEST:
  94. base.WndProc(ref m);
  95. if ((int)m.Result == HTCLIENT)
  96. m.Result = (IntPtr)HTCAPTION;
  97. return;
  98. }
  99. //拦截双击标题栏、移动窗体的系统消息
  100. if (m.Msg != 0xA3)
  101. {
  102. base.WndProc(ref m);
  103. }
  104. }
  105. #endregion
  106. #region SystemOptition
  107. /// <summary>
  108. /// 操作权限
  109. /// </summary>
  110. /// <returns></returns>
  111. public DataTable RightOfExute()
  112. {
  113. DataTable rData = new DataTable();
  114. rData.Columns.Add("BtnName");
  115. rData.Columns.Add("ActionName");
  116. //查看权限(必须有)
  117. DataRow seeRow = rData.NewRow();
  118. seeRow["BtnName"] = "see";
  119. seeRow["ActionName"] = "查看";
  120. rData.Rows.Add(seeRow);
  121. List<Control> ControlList = new List<Control>();
  122. ControlList.Add(btnSave);
  123. ControlList.Add(btnSelect);
  124. ControlList.Add(btnCanSelect);
  125. ControlList.Add(txtcancelSend);
  126. ControlList.Add(btnPrint);
  127. ControlList.Add(btnOutPut);
  128. ControlList.Add(btnExit);
  129. ControlList.Add(BtnCreatePR);
  130. ControlList.Add(BtnWWCancel);
  131. ControlList.Add(BtnWWSave);
  132. //ControlList.Add(btnDelLable);
  133. foreach (Control ctr in ControlList)
  134. {
  135. if (ctr.GetType() == typeof(SimpleButton))
  136. {
  137. DataRow dr = rData.NewRow();
  138. dr["BtnName"] = ctr.Name;
  139. dr["ActionName"] = ctr.Text;
  140. rData.Rows.Add(dr);
  141. }
  142. }
  143. rData.AcceptChanges();
  144. return rData;
  145. }
  146. /// <summary>
  147. /// 数据权限
  148. /// </summary>
  149. /// <returns></returns>
  150. public DataTable RightOfData()
  151. {
  152. DataTable rData = new DataTable();
  153. rData.Columns.Add("BodyName");
  154. rData.Columns.Add("ControlName");
  155. rData.Columns.Add("ControlCaption");
  156. rData.AcceptChanges();
  157. return rData;
  158. }
  159. #endregion
  160. #region 退出
  161. private void btnClose_Click(object sender, EventArgs e)
  162. {
  163. //AppConfig.CloseFormShow(this.Text);
  164. this.Close();
  165. }
  166. private void btnExit_Click(object sender, EventArgs e)
  167. {
  168. //AppConfig.CloseFormShow(this.Text);
  169. this.Close();
  170. }
  171. #endregion
  172. //#region 过滤
  173. //private string tempTableName = "";
  174. //private void btnFilter_Click(object sender, EventArgs e)
  175. //{
  176. // FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  177. // filter.OldTempTableName = tempTableName;
  178. // if (filter.ShowDialog() == DialogResult.OK)
  179. // {
  180. // DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  181. // try
  182. // {
  183. // _wait.Show();
  184. // tempTableName = filter.NewTempTableName;
  185. // sqltxt = filter.SqlText;
  186. // sqlconn = filter.FilterConnectString;
  187. // dataSource = filter.FilterData.Tables[0];
  188. // grdDetail.DataSource = dataSource;
  189. // grvDetail.BestFitColumns();
  190. // rptPage.RecordNum = dataSource.Rows.Count;
  191. // rptPage.PageSize = 500;
  192. // rptPage.PageIndex = 1;
  193. // rptPage.ReLoad();
  194. // _wait.Close();
  195. // }
  196. // catch (Exception ex)
  197. // {
  198. // MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  199. // _wait.Close();
  200. // }
  201. // }
  202. //}
  203. //#endregion
  204. #region 全选
  205. private void btnSelect_Click(object sender, EventArgs e)
  206. {
  207. for (int i = 0; i < gridView1.RowCount; i++)
  208. {
  209. gridView1.SetRowCellValue(i, colisSelect, "Y");
  210. }
  211. }
  212. #endregion
  213. #region 全消
  214. private void btnCanSelect_Click(object sender, EventArgs e)
  215. {
  216. for (int i = 0; i < gridView1.RowCount; i++)
  217. {
  218. gridView1.SetRowCellValue(i, colisSelect, "");
  219. }
  220. }
  221. #endregion
  222. #region 刷新
  223. private void btnFalsh_Click(object sender, EventArgs e)
  224. {
  225. FormICSFACTORY_Load(null, null);
  226. }
  227. #endregion
  228. #region 列表
  229. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  230. {
  231. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  232. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  233. }
  234. #endregion
  235. #region 双击选择
  236. private void gridView1_DoubleClick(object sender, EventArgs e)
  237. {
  238. List<string> lotNO = new List<string>();
  239. if (gridView1.FocusedRowHandle < 0)
  240. {
  241. return;
  242. }
  243. if (gridView1.FocusedColumn == colisSelect)
  244. {
  245. if (gridView1.GetRowCellValue(gridView1.FocusedRowHandle, colisSelect).ToString() == "")
  246. {
  247. gridView1.SetRowCellValue(gridView1.FocusedRowHandle, colisSelect, "Y");
  248. //txtMOCODE.Text = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, moCode).ToString();
  249. //this.txtLotNo.Text = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, colLOTNO).ToString();
  250. //this.txtMOSEQ.Text = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, colMOSEQ).ToString();
  251. //this.txtITEMCODE.Text = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, itemCode).ToString();
  252. }
  253. else
  254. {
  255. gridView1.SetRowCellValue(gridView1.FocusedRowHandle, colisSelect, "");
  256. //txtMOCODE.Text ="";
  257. //this.txtLotNo.Text ="";
  258. //this.txtMOSEQ.Text = "";
  259. //this.txtITEMCODE.Text = "";
  260. }
  261. BoundGridLookUpData();
  262. BoundEQPData();
  263. }
  264. }
  265. public void LoadGrd()
  266. {
  267. string sql = "";
  268. DataTable dt = null;
  269. // sql = @" SELECT top 1
  270. // '' as Stime,
  271. // '' AS [isSelect],
  272. // '' AS ID,
  273. // c.OPCODE AS OPCODE,
  274. // c.OPSEQ AS OPSEQ,
  275. // d.OPDESC AS OPDESC,
  276. // '' AS USERCODE,
  277. // '' AS USERName,
  278. // '' AS EQPCode,
  279. // '' AS EQPName,
  280. // '' AS MUSERName,
  281. // '' AS MTIME,e.EQPTypeCode AS EQPType,
  282. // getdate() AS SendPlanDate
  283. // FROM
  284. // ICSMO a
  285. // LEFT JOIN ICSMO2ROUTE b ON a.MOCODE=b.MOCODE
  286. // LEFT JOIN ICSITEMROUTE2OP c ON b.ROUTECODE=c.ROUTECODE and a.ITEMCODE=c.ITEMCODE
  287. // LEFT JOIN ICSOP d ON c.OPID = d.ID
  288. //LEFT JOIN ICSEQPSTP e ON c.ITEMCODE=e.ITEMCODE AND c.OPCODE=e.OPCODE
  289. // AND e.ISREF='是'
  290. // WHERE
  291. // a.MOCODE = '{0}'
  292. // ORDER BY c.OPSEQ"; ;
  293. // sql = string.Format(sql, txtMOCODE.Text);
  294. // dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  295. // if (dt.Rows.Count != 0)
  296. // {
  297. // if (dt.Rows[0]["OPCODE"].ToString() == "")
  298. // {
  299. // sql = @" SELECT top 1
  300. // '' as Stime,
  301. // '' AS [isSelect],
  302. // '' AS ID,
  303. // c.OPCODE AS OPCODE,
  304. // c.OPSEQ AS OPSEQ,
  305. // d.OPDESC AS OPDESC,
  306. // '' AS USERCODE,
  307. // '' AS USERName,
  308. // '' AS EQPCode,
  309. // '' AS EQPName,
  310. // '' AS MUSERName,
  311. // '' AS MTIME,f.EQPTypeCode AS EQPType,
  312. // getdate() AS SendPlanDate
  313. // FROM
  314. // ICSMO a
  315. // LEFT JOIN ICSMO2ROUTE b ON a.MOCODE=b.MOCODE
  316. // LEFT JOIN Base_Inventory e ON a.ITEMCODE=e.ItemCode
  317. // LEFT JOIN ICSMODELROUTE2OP c ON b.ROUTECODE=c.ROUTECODE and e.ItemMainCategoryCode=c.MODELCODE
  318. // LEFT JOIN ICSOP d ON c.OPID = d.ID
  319. //LEFT JOIN ICSEQPSTP f ON e.ITEMCODE=f.ITEMCODE AND c.OPCODE=f.OPCODE
  320. // AND f.ISREF='是'
  321. // WHERE
  322. // a.MOCODE = '{0}'
  323. // ORDER BY c.OPSEQ";
  324. // sql = string.Format(sql, txtMOCODE.Text);
  325. // dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  326. // }
  327. DataTable table = new DataTable();
  328. table.Columns.Add(new DataColumn("USERName"));
  329. table.Columns.Add(new DataColumn("USERCODE"));
  330. table.Columns.Add(new DataColumn("EQPCode"));
  331. table.Columns.Add(new DataColumn("EQPName"));
  332. table.Columns.Add(new DataColumn("SendPlanDate"));
  333. table.Columns.Add(new DataColumn("Stime"));
  334. DataRow row = table.NewRow();
  335. row["USERName"] = "";
  336. row["USERCODE"] = "";
  337. row["EQPCode"] = "";
  338. row["EQPName"] = "";
  339. row["SendPlanDate"] = DateTime.Now.ToString("yyyy/MM/dd");
  340. row["Stime"] = "";
  341. table.Rows.Add(row);
  342. dt = table;
  343. grdDetail.DataSource = dt;
  344. BoundEQPData();
  345. BoundGridLookUpData();
  346. }
  347. #endregion
  348. //#region 绑定数据源
  349. //private void btnConfig_Click(object sender, EventArgs e)//绑定数据源
  350. //{
  351. // if (AppConfig.UserCode.ToLower() != "demo")
  352. // {
  353. // //ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  354. // return;
  355. // }
  356. // FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  357. // fdata.ShowDialog();
  358. //}
  359. //#endregion
  360. #region 加载
  361. private void FormICSFACTORY_Load(object sender, EventArgs e)
  362. {
  363. LoadOp();
  364. }
  365. #endregion
  366. #region 数据源
  367. private void SearchMO(Dictionary<string, string> sendMes)
  368. {
  369. try
  370. {
  371. txtMOCODE.Text = sendMes["moCode"];
  372. txtMoLotCode.Text = sendMes["MoLotCode"];
  373. txtITEMCODE.Text = sendMes["itemCode"];
  374. txtMOSEQ.Text = sendMes["MOSEQ"];
  375. string sql = string.Format("select INVNAME,INVSTD from ICSINVENTORY where INVCODE='{0}'", sendMes["itemCode"]);
  376. SqlDataReader reader = DBHelper.ExecuteReader(AppConfig.AppConnectString, CommandType.Text, sql);
  377. while (reader.Read())
  378. {
  379. txtItemName.Text = reader["INVNAME"].ToString();
  380. textItemStd.Text = reader["INVSTD"].ToString();
  381. }
  382. }
  383. catch (Exception ex)
  384. {
  385. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  386. }
  387. }
  388. private void SearchItemLotInfo(string MOID)
  389. {
  390. try
  391. {
  392. string sql = @"select LOTNO,LOTQTY
  393. from ICSMO2Lot
  394. where MOID = '{0}' order by LOTNO";
  395. sql = string.Format(sql, MOID);
  396. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  397. //txtLOTNO.DisplayMember = "LOTNO"; //显示名称
  398. //txtLOTNO.ValueMember = "LOTQTY"; //value 值
  399. //txtLOTNO.DataSource = data.DefaultView;
  400. //if (txtLOTNO.Items.Count > 0)
  401. //{
  402. // txtLOTNO.SelectedIndex = 0;
  403. //}
  404. }
  405. catch (Exception ex)
  406. {
  407. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  408. }
  409. }
  410. #endregion
  411. #region 保存
  412. private void btnSave_Click(object sender, EventArgs e)
  413. {
  414. string lotno = "";
  415. List<string> lotnoList = new List<string>();
  416. List<FormICSMO2UserUIModel> MO2UserInfoList = new List<FormICSMO2UserUIModel>();
  417. for (int i = 0; i < gridView1.RowCount; i++)
  418. {
  419. if (gridView1.GetRowCellValue(i, colisSelect).ToString() == "Y")
  420. {
  421. lotno = gridView1.GetRowCellValue(i, colLOTNO).ToString();
  422. lotnoList.Add(lotno);
  423. }
  424. }
  425. if (lotnoList.Count < 1)
  426. {
  427. ICSBaseSimpleCode.AppshowMessageBox("请选择需要下发的产品跟踪码!!!");
  428. return;
  429. }
  430. for (int i = 0; i < gridView1.RowCount; i++)
  431. {
  432. if (gridView1.GetRowCellValue(i, colisSelect).ToString() == "Y")
  433. {
  434. if (gridView1.GetRowCellValue(i, pgstatus).ToString() != "未派工")
  435. {
  436. ICSBaseSimpleCode.AppshowMessageBox("批号:" + gridView1.GetRowCellValue(i, colLOTNO).ToString() + ",工序:" + gridView1.GetRowCellValue(i, opCode).ToString() + ",已经派工,请勿重复操作!");
  437. return;
  438. }
  439. #region 20210728已经开工的工序不能再操作
  440. string sqlCheck = @"SELECT COUNT(*) FROM ICSLOTONWIP WHERE LOTNO='" + gridView1.GetRowCellValue(i, colLOTNO).ToString() + "' AND OPCODE='" + gridView1.GetRowCellValue(i, opCode).ToString() + "'";
  441. DataTable DTCheck = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqlCheck).Tables[0];
  442. if (DTCheck != null && DTCheck.Rows.Count > 0)
  443. {
  444. int a = Int32.Parse(DTCheck.Rows[0][0].ToString());
  445. if (a > 0)
  446. {
  447. ICSBaseSimpleCode.AppshowMessageBox("批号:" + gridView1.GetRowCellValue(i, colLOTNO).ToString() + ",工序:" + gridView1.GetRowCellValue(i, opCode).ToString() + ",已经开工,不能保存!");
  448. return;
  449. }
  450. }
  451. #endregion
  452. FormICSMO2UserUIModel MO2UserInfo = new FormICSMO2UserUIModel();
  453. MO2UserInfo.ID = "";
  454. MO2UserInfo.MOCODE = gridView1.GetRowCellValue(i, moCode).ToString();
  455. MO2UserInfo.LOTNO = gridView1.GetRowCellValue(i, colLOTNO).ToString();
  456. //MO2UserInfo.SEGCODE = txtDepart.Text.ToString();
  457. //if (!string.IsNullOrWhiteSpace(txtMOSEQ.Text.ToString()))
  458. //{
  459. // MO2UserInfo.MOSEQ = Int32.Parse(txtMOSEQ.Text.ToString());
  460. //}
  461. //else
  462. //{
  463. // MO2UserInfo.MOSEQ = Int32.Parse(gridView1.GetRowCellValue(i, colMOSEQ).ToString());
  464. //}
  465. if (!string.IsNullOrWhiteSpace(gridView1.GetRowCellValue(i, colMOSEQ).ToString()))
  466. MO2UserInfo.MOSEQ = Int32.Parse(gridView1.GetRowCellValue(i, colMOSEQ).ToString());
  467. MO2UserInfo.StartPlanDate=Convert.ToDateTime(gridView1.GetRowCellValue(i, gridColumn11).ToString());//开工日期9.3
  468. MO2UserInfo.EndPlanDate= Convert.ToDateTime(gridView1.GetRowCellValue(i, gridColumn12).ToString());//完工日期9.3
  469. MO2UserInfo.RouteCode = gridView1.GetRowCellValue(i, routeCode).ToString();
  470. MO2UserInfo.OPCODE = gridView1.GetRowCellValue(i, opCode).ToString();
  471. MO2UserInfo.USERCODE = grvDetail.GetRowCellValue(0, colUSERCODE).ToString();
  472. MO2UserInfo.USERName = grvDetail.GetRowCellValue(0, colUSERName).ToString();
  473. MO2UserInfo.EQPCode = grvDetail.GetRowCellValue(0, colEQPCode).ToString();
  474. MO2UserInfo.EQPName = grvDetail.GetRowCellValue(0, colEQPName).ToString();
  475. MO2UserInfo.MUSER = AppConfig.UserCode;
  476. MO2UserInfo.MUSERName = AppConfig.UserName;
  477. MO2UserInfo.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  478. MO2UserInfo.WorkPoint = AppConfig.WorkPointCode;
  479. MO2UserInfo.EATTRIBUTE1 = "0";
  480. MO2UserInfo.PlanDate = int.Parse(AppConfig.GetSeverDateTime("yyyy-MM-dd").ToString("yyyyMMdd"));
  481. MO2UserInfo.SEGCODE =Convert.ToBoolean(gridView1.GetRowCellValue(i, ISAGV))==true?"1":"0";
  482. if (string.IsNullOrEmpty(grvDetail.GetRowCellValue(0, colPlanDate).ToString()) == false)
  483. {
  484. MO2UserInfo.SendPlanDate = Convert.ToDateTime(grvDetail.GetRowCellValue(0, colPlanDate).ToString());
  485. }
  486. MO2UserInfoList.Add(MO2UserInfo);
  487. if (string.IsNullOrEmpty(MO2UserInfo.USERCODE) || string.IsNullOrEmpty(MO2UserInfo.EQPCode))
  488. {
  489. ICSBaseSimpleCode.AppshowMessageBox("请分配员工和设备后再保存!");
  490. return;
  491. }
  492. //if (string.IsNullOrEmpty(MO2UserInfo.EQPCode) || string.IsNullOrEmpty(MO2UserInfo.EQPName))
  493. //{
  494. // ICSBaseSimpleCode.AppshowMessageBox("设备代码、设备名称 均不能为空!");
  495. // return;
  496. //}
  497. }
  498. }
  499. try
  500. {
  501. ICSMO2UserBLL.Add(MO2UserInfoList, AppConfig.AppConnectString);
  502. ICSBaseSimpleCode.AppshowMessageBox(0, "保存成功");
  503. simpleSearch_Click(null, null);
  504. }
  505. catch (Exception ex)
  506. {
  507. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  508. }
  509. btnFalsh_Click(null, null);
  510. }
  511. #endregion
  512. #region 删除
  513. private void btnDel_Click(object sender, EventArgs e)
  514. {
  515. //SimpleButton btntemp = (SimpleButton)sender;
  516. //if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  517. //{
  518. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  519. // return;
  520. //}
  521. List<string> IDList = new List<string>();
  522. for (int i = 0; i < grvDetail.RowCount; i++)
  523. {
  524. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  525. {
  526. IDList.Add(grvDetail.GetRowCellValue(i, colID).ToString());
  527. }
  528. }
  529. if (IDList.Count == 0 || IDList == null)
  530. {
  531. ICSBaseSimpleCode.AppshowMessageBox("请选择数据");
  532. return;
  533. }
  534. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除吗?删除后无法恢复,确定吗?") != DialogResult.OK)
  535. {
  536. btnCanSelect_Click(sender, e);
  537. return;
  538. }
  539. ICSMO2UserBLL.deleteInfo(IDList, AppConfig.AppConnectString);
  540. ICSBaseSimpleCode.AppshowMessageBox("删除成功");
  541. btnFalsh_Click(null, null);
  542. }
  543. #endregion
  544. #region 导出
  545. private void btnOutPut_Click(object sender, EventArgs e)
  546. {
  547. try
  548. {
  549. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  550. foe.ShowDialog();
  551. }
  552. catch (Exception ex)
  553. {
  554. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  555. }
  556. //FormOutExcel foe = new FormOutExcel();
  557. //if (foe.ShowDialog() == DialogResult.OK)
  558. //{
  559. // try
  560. // {
  561. // string outtype = foe._OutType;
  562. // string exceltype = foe._ExcelType;
  563. // string filename = foe._FileName;
  564. // string url = foe._Url;
  565. // string sheetname = foe._SheetName;
  566. // if (outtype.ToLower() == "excel")
  567. // {
  568. // DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions();
  569. // op.SheetName = sheetname;
  570. // grdDetail.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op);
  571. // }
  572. // else
  573. // {
  574. // grdDetail.MainView.ExportToPdf(url + "\\" + filename + ".pdf");
  575. // }
  576. // MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  577. // }
  578. // catch (Exception ex)
  579. // {
  580. // MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  581. // }
  582. //}
  583. }
  584. #endregion
  585. // #region 批号改变
  586. // private void txtLOTNO_SelectedIndexChanged(object sender, EventArgs e)
  587. // {
  588. // txtLOTQTY.Text = txtLOTNO.SelectedValue.ToString();
  589. // try
  590. // {
  591. // string sql = @" SELECT
  592. // '' AS [isSelect],
  593. // e.ID AS ID,
  594. // b.OPCODE AS OPCODE,
  595. // b.OPSEQ AS OPSEQ,
  596. // d.OPDESC AS OPDESC,
  597. // e.USERCODE AS USERCODE,
  598. // e.USERName AS USERName,
  599. // e.EQPCode AS EQPCode,
  600. // e.EQPName AS EQPName,
  601. // e.MUSERName AS MUSERName,
  602. // e.MTIME AS MTIME
  603. // FROM
  604. // ICSMO a
  605. // RIGHT JOIN ICSITEMROUTE2OP b ON a.ITEMCODE = b.ITEMCODE
  606. // LEFT JOIN ICSMO2Lot c ON a.MOCODE = c.MOCODE
  607. // LEFT JOIN ICSOP d ON b.OPID = d.ID
  608. // LEFT JOIN ICSMO2User e ON b.OPCODE = e.OPCODE
  609. // AND c.LOTNO = e.LOTNO
  610. // WHERE
  611. // c.LOTNO = '{0}'
  612. // ORDER BY b.OPSEQ";
  613. // sql = string.Format(sql, txtLOTNO.Text);
  614. // DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  615. // grdDetail.DataSource = dt;
  616. // sqltxt = sql;
  617. // sqlconn = AppConfig.AppConnectString;
  618. // }
  619. // catch (Exception ex)
  620. // {
  621. // MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  622. // }
  623. // }
  624. // #endregion
  625. #region 下发人员按钮
  626. private void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  627. {
  628. string code = "";
  629. for (int i = 0; i < gridView1.RowCount; i++)
  630. {
  631. if (gridView1.GetRowCellValue(i, colisSelect).ToString() == "Y")
  632. {
  633. code = gridView1.GetRowCellValue(i, opCode).ToString();
  634. break;
  635. }
  636. }
  637. if (code == "")
  638. {
  639. ICSBaseSimpleCode.AppshowMessageBox("请先选择工序!");
  640. return;
  641. }
  642. //根据批次信息里的工序编码,获得派工信息的人员代码,人员名称
  643. string sql = "select USERCODE as [人员代码],USERName as [人员名称] from dbo.ICSOP2User with(nolock) WHERE OPCODE='{0}'";
  644. sql = string.Format(sql, code);
  645. //object obj = AppConfig.InvokeWebservice(AppConfig.BaseServiceUri, "WebBaseService", "BaseService", "GetHuaRongErpConnectString", new object[] { });
  646. //if (obj == null)
  647. //{
  648. // ICSBaseSimpleCode.AppshowMessageBox(1, "ERP数据库连接取得失败!");
  649. //}
  650. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  651. FormDataRefer reForm = new FormDataRefer();
  652. reForm.FormTitle = "人员信息";
  653. DataTable menuData = data;
  654. reForm.DataSource = menuData;
  655. reForm.MSelectFlag = false;
  656. reForm.RowIndexWidth = 35;
  657. //reForm.HideCols.Add("设备ID");
  658. reForm.FormWidth = 500;
  659. reForm.FormHeight = 500;
  660. //reForm.FilterKey = btn.Text;
  661. //grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, grvDetail.FocusedColumn).ToString().Trim();
  662. if (reForm.ShowDialog() == DialogResult.OK)
  663. {
  664. DataTable retData = reForm.ReturnData;
  665. foreach (DataRow dr in retData.Rows)
  666. {
  667. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colUSERCODE, dr["人员代码"].ToString());
  668. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colUSERName, dr["人员名称"].ToString());
  669. }
  670. }
  671. }
  672. #endregion
  673. #region 设备代码按钮
  674. private void repositoryItemButtonEdit2_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  675. {
  676. //if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() != "Y")
  677. //{
  678. // ICSBaseSimpleCode.AppshowMessageBox("请选择当前数据后再进行编辑!!!");
  679. // return;
  680. //}
  681. ButtonEdit btn = (ButtonEdit)sender;
  682. string sql = "select EQPCode as [设备代码],EQPName as [设备名称] from dbo.ICSEquipment with(nolock)";
  683. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  684. FormDataRefer reForm = new FormDataRefer();
  685. reForm.FormTitle = "设备信息";
  686. DataTable menuData = data;
  687. reForm.DataSource = menuData;
  688. reForm.MSelectFlag = false;
  689. reForm.RowIndexWidth = 35;
  690. //reForm.HideCols.Add("设备ID");
  691. reForm.FormWidth = 500;
  692. reForm.FormHeight = 500;
  693. //reForm.FilterKey = btn.Text;
  694. //grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, grvDetail.FocusedColumn).ToString().Trim();
  695. if (reForm.ShowDialog() == DialogResult.OK)
  696. {
  697. DataTable retData = reForm.ReturnData;
  698. foreach (DataRow dr in retData.Rows)
  699. {
  700. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colEQPCode, dr["设备代码"].ToString());
  701. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colEQPName, dr["设备名称"].ToString());
  702. }
  703. }
  704. }
  705. #endregion
  706. private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
  707. {
  708. //List<string> lotList = new List<string>();
  709. //string sql = @" SELECT LOTNO FROM ICSMO2User WHERE MOCODE='{0}' ";
  710. //sql = string.Format(sql, txtMOCODE.Text);
  711. //DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  712. //if (dt != null && dt.Rows.Count > 0)
  713. //{
  714. // foreach (DataRow dr1 in dt.Rows)
  715. // {
  716. // lotList.Add(dr1["LOTNO"].ToString());
  717. // }
  718. //}
  719. //int hand = e.RowHandle;
  720. //if (hand < 0)
  721. // return;
  722. //DataRow dr = this.gridView1.GetDataRow(hand);
  723. //if (dr == null)
  724. // return;
  725. //if (gridView1.GetRowCellValue(e.RowHandle, colLOTNO).ToString() != "")
  726. //{
  727. // if (lotList.Contains(gridView1.GetRowCellValue(e.RowHandle, colLOTNO).ToString()))
  728. // {
  729. // e.Appearance.BackColor = Color.Blue;
  730. // }
  731. //}
  732. }
  733. #region 打开的子窗体
  734. //private void BoundData()
  735. //{
  736. // try
  737. // {
  738. // string OPCODEs = "";
  739. // for (int i = 0; i < grvDetail.DataRowCount; i++)
  740. // {
  741. // string OPCODE = grvDetail.GetRowCellValue(i, colOPCODE).ToString();
  742. // if (!string.IsNullOrEmpty(OPCODE))
  743. // {
  744. // OPCODEs += "'"+ OPCODE + "', ";
  745. // }
  746. // }
  747. // string sql = "select OPCODE AS [工序代码], USERCODE as [人员代码],USERName as [人员名称] from dbo.ICSOP2User with(nolock)";
  748. // if (!string.IsNullOrEmpty(OPCODEs))
  749. // {
  750. // OPCODEs = OPCODEs.Substring(0, OPCODEs.LastIndexOf(","));
  751. // sql += " WHERE OPCODE IN (" + OPCODEs + ") ";
  752. // }
  753. // sql += " ORDER BY OPCODE,USERCODE";
  754. // sql = string.Format(sql);
  755. // dataUser = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  756. // if (dataUser != null)
  757. // {
  758. // int rows = dataUser.Rows.Count;
  759. // //DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit repositoryItemLookUpEdit = new DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit();
  760. // #region LookUpEdit
  761. // repositoryItemLookUpEdit1.ValueMember = "人员代码";
  762. // repositoryItemLookUpEdit1.DisplayMember = "人员代码";
  763. // repositoryItemLookUpEdit1.DataSource = dataUser;
  764. // repositoryItemLookUpEdit1.NullText = "";//空时的值
  765. // repositoryItemLookUpEdit1.DropDownRows = 10;//下拉框行数
  766. // repositoryItemLookUpEdit1.ImmediatePopup = true;//输入值是否马上弹出窗体
  767. // repositoryItemLookUpEdit1.ValidateOnEnterKey = true;//回车确认
  768. // repositoryItemLookUpEdit1.SearchMode = DevExpress.XtraEditors.Controls.SearchMode.AutoFilter;//自动过滤掉不需要显示的数据,可以根据需要变化
  769. // repositoryItemLookUpEdit1.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
  770. // repositoryItemLookUpEdit1.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  771. // //自适应宽度
  772. // repositoryItemLookUpEdit1.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  773. // //填充列
  774. // repositoryItemLookUpEdit1.PopulateColumns();
  775. // //控制选择项的总宽度
  776. // repositoryItemLookUpEdit1.PopupWidth = 300;
  777. // //设置列属性
  778. // //repositoryItemLookUpEdit1.Columns["工序代码"].Visible = false;
  779. // //列格式设置
  780. // repositoryItemLookUpEdit1.Columns[0].FormatString = "000000";
  781. // ////实现用户自由输入
  782. // repositoryItemLookUpEdit1.ProcessNewValue += LookUpEdit1_ProcessNewValue;
  783. // #endregion
  784. // }
  785. // }
  786. // catch (Exception ex)
  787. // {
  788. // ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  789. // }
  790. //}
  791. //private void repositoryItemButtonEdit1_EditValueChanged(object sender, EventArgs e)
  792. //{
  793. // ButtonEdit btn = (ButtonEdit)sender;
  794. // string USERCODE = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colUSERCODE).ToString();
  795. // string UserCode = btn.Text.Trim();// grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, grvDetail.FocusedColumn).ToString();
  796. // string sql = "select USERCODE as [人员代码],USERName as [人员名称] from dbo.ICSOP2User with(nolock) WHERE OPCODE='{0}' AND USERCODE LIKE '%{1}%'";
  797. // sql = string.Format(sql, OPCODE, UserCode);
  798. // DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  799. // FormDataView reForm = new FormDataView(this);
  800. // reForm.FormTitle = "人员信息";
  801. // DataTable menuData = data;
  802. // reForm.DataSource = menuData;
  803. // reForm.MSelectFlag = false;
  804. // reForm.RowIndexWidth = 35;
  805. // reForm.FormWidth = 200;
  806. // reForm.FormHeight = 200;
  807. // Point p = Control.MousePosition;
  808. // Control control = this.GetChildAtPoint(btn.Location); //检索位置指定位置的子控件
  809. // Point clientPoint = control.PointToClient(System.Windows.Forms.Control.MousePosition); //将屏幕坐标点的位置计算称工作区域的位置
  810. // Point screenPoint = control.PointToScreen(clientPoint); //将工作区域的位置计算吃呢个屏幕坐标的位置
  811. // reForm.Location = pointToScreen(btn); //control.PointToClient(btn.Location);// System.Windows.Forms.Cursor.Position;
  812. // reForm.Show();
  813. // 弹出图纸对话框
  814. // ShowChildrenForm();
  815. // reForm.HideCols.Add("选择");
  816. // reForm.Show(this);
  817. // if (reForm.ShowDialog() == DialogResult.OK)
  818. // {
  819. // DataTable retData = reForm.ReturnData;
  820. // foreach (DataRow dr in retData.Rows)
  821. // {
  822. // grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colUSERCODE, dr["人员代码"].ToString());
  823. // grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colUSERName, dr["人员名称"].ToString());
  824. // }
  825. // }
  826. //}
  827. /// <summary>
  828. /// 实现用户自由输入
  829. /// </summary>
  830. /// <param name="sender"></param>
  831. /// <param name="e"></param>
  832. //private void LookUpEdit1_ProcessNewValue(object sender, DevExpress.XtraEditors.Controls.ProcessNewValueEventArgs e)
  833. //{
  834. // //DataRow Row;
  835. // ////RepositoryItemLookUpEdit Edit = ((LookUpEdit)sender).Properties;
  836. // //if (e.DisplayValue == null || this.repositoryItemLookUpEdit1.NullText.Equals(e.DisplayValue) || string.Empty.Equals(e.DisplayValue))
  837. // // return;
  838. // //Row = dataUser.NewRow();
  839. // //Row["人员代码"] = e.DisplayValue;
  840. // //dataUser.Rows.Add(Row);
  841. // //e.Handled = true;
  842. // if (!this.DesignMode)
  843. // {
  844. // DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit Edit = ((LookUpEdit)sender).Properties;
  845. // string displayName = Edit.DisplayMember;
  846. // string valueName = Edit.ValueMember;
  847. // string display = e.DisplayValue.ToString();
  848. // DataTable dtTemp = this.repositoryItemLookUpEdit1.DataSource as DataTable;
  849. // if (dtTemp != null)
  850. // {
  851. // string OPCODE = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colOPCODE).ToString();
  852. // DataRow[] selectedRows = dtTemp.Select(string.Format("{0}='{1}' AND {2}='{3}'", displayName, display.Replace("'", "‘"), "工序代码", OPCODE));
  853. // if (selectedRows == null || selectedRows.Length == 0)
  854. // {
  855. // DataRow row = dtTemp.NewRow();
  856. // row[displayName] = display;
  857. // row[valueName] = display;
  858. // dtTemp.Rows.Add(row);
  859. // dtTemp.AcceptChanges();
  860. // }
  861. // }
  862. // e.Handled = true;
  863. // }
  864. //}
  865. //public void SetRowCellValue(DataTable retData)
  866. //{
  867. // foreach (DataRow dr in retData.Rows)
  868. // {
  869. // grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colUSERCODE, dr["人员代码"].ToString());
  870. // grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colUSERName, dr["人员名称"].ToString());
  871. // }
  872. // //ShowChildrenForm();
  873. //}
  874. Point point = new Point(0, 0);
  875. /// <summary>
  876. /// 获取控件在屏幕中的位置
  877. /// </summary>
  878. /// <param name="control"></param>
  879. /// <returns></returns>
  880. private Point pointToScreen(Control control)
  881. {
  882. point.Offset(control.Location);
  883. var parent = control.Parent;
  884. if (parent is Form)
  885. {
  886. return point;
  887. }
  888. else
  889. {
  890. pointToScreen(parent);
  891. }
  892. point.Offset(0, 10);
  893. return point;
  894. }
  895. #region 判断是否有打开的子窗体
  896. public void ShowChildrenForm()
  897. {
  898. foreach (Form f1 in this.OwnedForms)
  899. {
  900. if (f1 is FormDataView)
  901. f1.Close();
  902. }
  903. }
  904. #endregion
  905. #endregion
  906. private void BoundEQPData()
  907. {
  908. try
  909. {
  910. string condition = "";
  911. string cc="";
  912. List<string> opcode = new List<string>();
  913. List<string> itemcode = new List<string>();
  914. for (int i = 0; i < gridView1.RowCount; i++)
  915. {
  916. if (gridView1.GetRowCellValue(i, colisSelect).ToString() == "Y")
  917. {
  918. if (opcode.Exists(a => a == gridView1.GetRowCellValue(i, opCode).ToString()) == false)
  919. {
  920. opcode.Add(gridView1.GetRowCellValue(i, opCode).ToString());
  921. itemcode.Add(gridView1.GetRowCellValue(i, itemCode).ToString());
  922. }
  923. }
  924. }
  925. for (int i = 0; i < opcode.Count; i++)
  926. {
  927. if (i == 0)
  928. {
  929. condition += string.Format(" and (opcode='{0}' and itemcode='{1}' )", opcode[i], itemcode[i]);
  930. }
  931. else
  932. {
  933. condition += string.Format(" or (opcode='{0}' and itemcode='{1} ') ", opcode[i], itemcode[i]);
  934. }
  935. }
  936. // string sql = @"
  937. // if exists(SELECT * FROM tempdb..sysobjects where id=object_id('tempDB..#tempa'))
  938. // DROP TABLE #tempa
  939. // IF EXISTS (SELECT * FROM tempdb..sysobjects where id=object_id('tempDB..#TempStime'))
  940. // drop table #TempStime
  941. // select * into #tempa from
  942. // (select EQPCode as [设备代码],EQPName as [设备名称],Type as [设备类型] from dbo.ICSEquipment with(nolock)
  943. // where type in (select eqptypecode from ICSEQPSTP WHERE 1=1 {0} GROUP BY eqptypecode HAVING COUNT(*)>={1} ))A
  944. // SELECT * INTO #TempStime from(
  945. //select icsmo.itemcode,icsmo2user.lotno,icsmo2user.OPCODE,g.routecode,(ICSEQPSTPEMODEL.stime*ICSMO2Lot.LOTQTY)/60 AS STIME,icsmo2user.EQPCode,ICSMO2Lot.LOTQTY AS 数量
  946. //from icsmo2user
  947. // LEFT join icsmo on icsmo.MOCODE=ICSMO2User.MOCODE
  948. // LEFT JOIN ICSMO2Lot ON ICSMO2Lot.LOTNO=ICSMO2User.LOTNO
  949. // LEFT join ICSROUTE2OP g on icsmo2user.RouteCode = g.RouteCode and g.opcode=icsmo2user.OPCODE
  950. // LEFT join ICSEQPSTPEMODEL on ICSEQPSTPEMODEL.ITEMCODE=icsmo.ITEMCODE and ICSEQPSTPEMODEL.eqpcode=g.MainResources and icsmo2user.OPCODE=ICSEQPSTPEMODEL.opcode
  951. // where not EXISTS (select 1 from ICSLOTONWIP ww where ww.lotno =ICSMO2User.lotno and isnull(ww.EndTime,'')!='' AND WW.OPCODE=icsmo2user.OPCODE)
  952. //)a
  953. // select #tempa.设备类型,#tempa.设备名称,#tempa.设备代码,isnull(a.工时,0) as 工时 from #tempa left join (select sum(stime) AS 工时,EQPCode from #TempStime GROUP BY EQPCode)A on #tempa.设备代码=A.EQPCode
  954. //";
  955. //0911注释
  956. string sql = @" select EQPCode as [设备代码],EQPName as [设备名称],Type as [设备类型] from dbo.ICSEquipment with(nolock) ";
  957. // string USERCODEs = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colUSERCODE).ToString();
  958. // string sql = @"select a.EQPCode as [设备代码],a.EQPName as [设备名称],Type as [设备类型] from dbo.ICSEquipment a with(nolock)
  959. // left join ICSSkillMatrix b on b.equipmentType=a.EQPCode
  960. // where b.WorkNo='" + USERCODEs + "'";
  961. sql = string.Format(sql, condition , opcode.Count());
  962. data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  963. if (data != null)
  964. {
  965. int rows = data.Rows.Count;
  966. repositoryItemGridLookUpEdit2.ValueMember = "设备代码";
  967. repositoryItemGridLookUpEdit2.DisplayMember = "设备代码";
  968. repositoryItemGridLookUpEdit2.DataSource = data;
  969. repositoryItemGridLookUpEdit2.AutoComplete = true;
  970. repositoryItemGridLookUpEdit2.NullText = "";//空时的值
  971. //repositoryItemGridLookUpEdit2.DropDownRows = 10;//下拉框行数
  972. repositoryItemGridLookUpEdit2.ImmediatePopup = true;//输入值是否马上弹出窗体
  973. repositoryItemGridLookUpEdit2.ValidateOnEnterKey = true;//回车确认
  974. //repositoryItemGridLookUpEdit2.SearchMode = DevExpress.XtraEditors.Controls.SearchMode.AutoFilter;//自动过滤掉不需要显示的数据,可以根据需要变化
  975. repositoryItemGridLookUpEdit2.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;//要使用户可以输入,这里须设为Standard
  976. repositoryItemGridLookUpEdit2.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  977. //自适应宽度
  978. repositoryItemGridLookUpEdit2.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  979. }
  980. }
  981. catch (Exception ex)
  982. {
  983. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  984. }
  985. }
  986. private void BoundGridLookUpData()
  987. {
  988. try
  989. {
  990. string condition = "";
  991. List<string> opcode = new List<string>();
  992. for (int i = 0; i < gridView1.RowCount; i++)
  993. {
  994. if (gridView1.GetRowCellValue(i, colisSelect).ToString() == "Y")
  995. {
  996. if (opcode.Exists(a => a == gridView1.GetRowCellValue(i, opCode).ToString()) == false)
  997. {
  998. opcode.Add(gridView1.GetRowCellValue(i, opCode).ToString());
  999. }
  1000. }
  1001. }
  1002. for (int i = 0; i < opcode.Count; i++)
  1003. {
  1004. if (i == 0)
  1005. {
  1006. condition += string.Format(" and opcode='{0}'", opcode[i]);
  1007. }
  1008. else
  1009. {
  1010. condition += string.Format(" or opcode='{0}'", opcode[i]);
  1011. }
  1012. }
  1013. // string sql = @"select ICSOP2User.USERCODE as [人员代码],USERName as [人员名称],工时 from dbo.ICSOP2User
  1014. // left join (select sum(加工工时) AS 工时, usercode from (select username,usercode,eqpname,opname,plandate,BeginDate,EndDate,icsmo2user.lotno,
  1015. //case
  1016. //when BeginDate is not null then '开工中'
  1017. //else '未开工'
  1018. //end 状态,isnull(p.stime,0) as 标准工时,ICSMO2Lot.lotqty as 数量, convert(decimal(10,2),isnull(p.stime,0)*ICSMO2Lot.lotqty/60) as 加工工时
  1019. //from icsmo2user
  1020. //left join ICSOP on ICSOP.OPCODE=ICSMO2User.OPCODE
  1021. //left join icsmo on icsmo2user.mocode=icsmo.MOCODE
  1022. //LEFT join ICSLOTONWIP on ICSLOTONWIP.OPCODE=ICSMO2User.opcode and ICSLOTONWIP.lotno=icsmo2user.lotno AND ICSLOTONWIP.action='good'
  1023. //left join ICSROUTE2OP g on icsmo2user.RouteCode = g.RouteCode and icsmo2user.OPCODE=g.OPCODE
  1024. //left join ICSMO2Lot on ICSMO2Lot.LOTNO=ICSMO2User.LOTNO
  1025. //left join ICSEQPSTPEMODEL p on p.ITEMCODE=ICSMO.ITEMCODE and p.OPCODE=ICSMO2User.OPCODE and p.EQPCODE=g.MainResources
  1026. // where not EXISTS (select 1 from ICSLOTONWIP ww where ww.lotno =ICSMO2User.lotno and isnull(ww.EndTime,'')!='' and ww.opcode=ICSMO2User.opcode))A
  1027. // GROUP BY USERCODE)a on a.usercode=ICSOP2User.usercode
  1028. //
  1029. // where 1=1 ";
  1030. string sql = @"select ICSOP2User.USERCODE as [人员代码],USERName as [人员名称],工时 from dbo.ICSOP2User
  1031. left join (select sum() AS , usercode from (select username,usercode,eqpname,opname,
  1032. icsmo2user.StartPlanDate plandate,
  1033. icsmo2user.EndPlanDate EndDate,icsmo2user.lotno,
  1034. case
  1035. when StartPlanDate is not null then ''
  1036. else ''
  1037. end ,
  1038. --isnull(p.stime,0) as ,
  1039. 0 as ,
  1040. ICSITEMLot.lotqty as ,
  1041. --convert(decimal(10,2),isnull(p.stime,0)*ICSITEMLot.lotqty/60) as
  1042. 0 as
  1043. from icsmo2user
  1044. left join ICSOP on ICSOP.OPCODE=ICSMO2User.OPCODE
  1045. left join icsmo on icsmo2user.mocode=icsmo.MOCODE
  1046. LEFT join ICSLOTONWIP on ICSLOTONWIP.OPCODE=icsmo2user.opcode and ICSLOTONWIP.lotno=icsmo2user.lotno AND ICSLOTONWIP.action='good'
  1047. left join ICSROUTE2OP g on icsmo2user.RouteCode = g.RouteCode and icsmo2user.OPCODE=g.OPCODE
  1048. left join ICSITEMLot on ICSITEMLot.LOTNO=ICSMO2User.LOTNO
  1049. --left join ICSEQPSTPEMODEL p on p.ITEMCODE=ICSMO.ITEMCODE and p.OPCODE=ICSMO2User.OPCODE and p.EQPCODE=g.MainResources
  1050. where not EXISTS (select 1 from ICSLOTONWIP ww where ww.lotno =ICSMO2User.lotno and isnull(ww.EndTime,'')!='' and ww.opcode=ICSMO2User.opcode))A
  1051. GROUP BY USERCODE)a on a.usercode=ICSOP2User.usercode
  1052. where 1=1 ";
  1053. sql = string.Format(sql + condition + "group by ICSOP2User.usercode,username,工时 having count(*)>={0}", opcode.Count);
  1054. dataUser = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  1055. if (dataUser != null)
  1056. {
  1057. int rows = dataUser.Rows.Count;
  1058. #region LookUpEdit
  1059. repositoryItemGridLookUpEdit1.ValueMember = "人员代码";
  1060. repositoryItemGridLookUpEdit1.DisplayMember = "人员代码";
  1061. repositoryItemGridLookUpEdit1.DataSource = dataUser;
  1062. repositoryItemGridLookUpEdit1.NullText = "";//空时的值
  1063. //repositoryItemGridLookUpEdit1.DropDownRows = 10;//下拉框行数
  1064. repositoryItemGridLookUpEdit1.ImmediatePopup = true;//输入值是否马上弹出窗体
  1065. repositoryItemGridLookUpEdit1.ValidateOnEnterKey = true;//回车确认
  1066. //repositoryItemGridLookUpEdit1.SearchMode = DevExpress.XtraEditors.Controls.SearchMode.AutoFilter;//自动过滤掉不需要显示的数据,可以根据需要变化
  1067. repositoryItemGridLookUpEdit1.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
  1068. repositoryItemGridLookUpEdit1.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  1069. //自适应宽度
  1070. repositoryItemGridLookUpEdit1.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  1071. #endregion
  1072. }
  1073. }
  1074. catch (Exception ex)
  1075. {
  1076. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  1077. }
  1078. }
  1079. /// <summary>
  1080. /// 绑定过滤条件
  1081. /// </summary>
  1082. /// <param name="sender"></param>
  1083. private void FilterLookup(object sender)
  1084. {
  1085. try
  1086. {
  1087. GridLookUpEdit edit = sender as GridLookUpEdit;
  1088. if (edit == null)
  1089. return;
  1090. GridView gridView = edit.Properties.View as GridView;
  1091. //FieldInfo fi = gridView.GetType().GetField("extraFilter", BindingFlags.NonPublic | BindingFlags.Instance);
  1092. ////List<BinaryOperator> listBinary = new List<BinaryOperator>();
  1093. //for (int i = 0; i < gridView1.RowCount; i++) {
  1094. // if (gridView1.GetRowCellValue(i, colisSelect).ToString() == "Y") {
  1095. // listBinary.Add(new BinaryOperator("工序代码", gridView1.GetRowCellValue(i, opCode).ToString(), BinaryOperatorType.Equal));
  1096. // }
  1097. //}
  1098. //BinaryOperator op2 = new BinaryOperator("人员代码", "%" + edit.AutoSearchText + "%", BinaryOperatorType.Like);
  1099. //listBinary.Add(op2);
  1100. //List<CriteriaOperator> condition = new List<CriteriaOperator>();
  1101. //for (int i = 0; i < listBinary.Count; i++) {
  1102. // condition.Add(listBinary[i]);
  1103. //}
  1104. //CriteriaOperator [] conditionArray = condition.ToArray();
  1105. //string filterCondition = new GroupOperator(GroupOperatorType.And, conditionArray).ToString();
  1106. //////BinaryOperator op3 = new BinaryOperator("Name", "%" + edit.AutoSearchText + "%", BinaryOperatorType.Like);
  1107. ////string filterCondition = new GroupOperator(GroupOperatorType.Or, new CriteriaOperator[] { op1, op2, op3 }).ToString();
  1108. //fi.SetValue(gridView, filterCondition);
  1109. MethodInfo mi = gridView.GetType().GetMethod("ApplyColumnsFilterEx", BindingFlags.NonPublic | BindingFlags.Instance);
  1110. mi.Invoke(gridView, null);
  1111. }
  1112. catch (Exception ex)
  1113. {
  1114. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  1115. }
  1116. }
  1117. //每次输入字符都会触发(在自动关联后面的字符串的情况下)
  1118. private void repositoryItemGridLookUpEdit1_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
  1119. {
  1120. BeginInvoke(new MethodInvoker(delegate()
  1121. {
  1122. FilterLookup(sender);
  1123. }));
  1124. }
  1125. //对应的工序查询不到信息(输入框未自动关联后面的字符串)
  1126. private void repositoryItemGridLookUpEdit1_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
  1127. {
  1128. BeginInvoke(new MethodInvoker(delegate ()
  1129. {
  1130. FilterLookup(sender);
  1131. }));
  1132. }
  1133. private void repositoryItemGridLookUpEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  1134. {
  1135. BeginInvoke(new MethodInvoker(delegate()
  1136. {
  1137. FilterLookup(sender);
  1138. }));
  1139. }
  1140. private void repositoryItemGridLookUpEdit1_EditValueChanged(object sender, EventArgs e)
  1141. {
  1142. try
  1143. {
  1144. #region 0911
  1145. TextEdit txt = sender as TextEdit;
  1146. string value = txt.EditValue.ToString();
  1147. // string USERCODEs = grvDetail.GetRowCellValue(0, colUSERCODE).ToString();
  1148. string sql = @"select a.EQPCode as [设备代码],a.EQPName as [设备名称],Type as [设备类型] from dbo.ICSEquipment a with(nolock)
  1149. left join ICSSkillMatrix b on b.equipmentType=a.EQPCode
  1150. where b.WorkNo='" + value + "' order by EQPCode ";
  1151. //where b.WorkNo='" + USERCODEs + "'
  1152. sql = string.Format(sql);
  1153. data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  1154. if (data != null)
  1155. {
  1156. int rows = data.Rows.Count;
  1157. repositoryItemGridLookUpEdit2.ValueMember = "设备代码";
  1158. repositoryItemGridLookUpEdit2.DisplayMember = "设备代码";
  1159. repositoryItemGridLookUpEdit2.DataSource = data;
  1160. repositoryItemGridLookUpEdit2.AutoComplete = true;
  1161. repositoryItemGridLookUpEdit2.NullText = "";//空时的值
  1162. //repositoryItemGridLookUpEdit2.DropDownRows = 10;//下拉框行数
  1163. repositoryItemGridLookUpEdit2.ImmediatePopup = true;//输入值是否马上弹出窗体
  1164. repositoryItemGridLookUpEdit2.ValidateOnEnterKey = true;//回车确认
  1165. //repositoryItemGridLookUpEdit2.SearchMode = DevExpress.XtraEditors.Controls.SearchMode.AutoFilter;//自动过滤掉不需要显示的数据,可以根据需要变化
  1166. repositoryItemGridLookUpEdit2.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;//要使用户可以输入,这里须设为Standard
  1167. repositoryItemGridLookUpEdit2.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  1168. //自适应宽度
  1169. repositoryItemGridLookUpEdit2.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  1170. if (data.Rows.Count > 0)
  1171. {
  1172. grvDetail.SetRowCellValue(0, colEQPCode, data.Rows[0]["设备代码"]);
  1173. grvDetail.SetRowCellValue(0, colEQPName, data.Rows[0]["设备名称"]);
  1174. }
  1175. }
  1176. #endregion 0911
  1177. string code = "";
  1178. GridLookUpEdit edit = sender as GridLookUpEdit;
  1179. //0911注释的
  1180. //if (isQueryCloseUp)
  1181. // return;
  1182. if (edit.EditValue != null || edit.EditValue.ToString() != "" || edit.EditValue.ToString() != "nulltext")
  1183. {
  1184. var o = edit.Properties.GetRowByKeyValue(edit.EditValue);
  1185. if (o is DataRowView)
  1186. {
  1187. DataRowView RowView = o as DataRowView;
  1188. string USERCODE = RowView.Row["人员代码"].ToString();
  1189. string USERNAME = RowView.Row["人员名称"].ToString();
  1190. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colUSERCODE, USERCODE);
  1191. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colUSERName, USERNAME);
  1192. }
  1193. else
  1194. {
  1195. // grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colUSERCODE, "");
  1196. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colUSERName, "");
  1197. }
  1198. }
  1199. else
  1200. {
  1201. //grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colUSERCODE, "");
  1202. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colUSERName, "");
  1203. }
  1204. }
  1205. catch (Exception ex)
  1206. {
  1207. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  1208. }
  1209. }
  1210. private void repositoryItemGridLookUpEdit1_QueryCloseUp(object sender, CancelEventArgs e)
  1211. {
  1212. try
  1213. {
  1214. string code = "";
  1215. GridLookUpEdit edit = sender as GridLookUpEdit;
  1216. if (edit.EditValue != null || edit.EditValue.ToString() != "" || edit.EditValue.ToString() != "nulltext")
  1217. {
  1218. var o = edit.Properties.View.GetDataRow(edit.Properties.View.FocusedRowHandle);
  1219. if (o is DataRow)
  1220. {
  1221. DataRow RowView = o as DataRow;
  1222. string USERCODE = RowView["人员代码"].ToString();
  1223. string USERNAME = RowView["人员名称"].ToString();
  1224. for (int i = 0; i < gridView1.RowCount; i++)
  1225. {
  1226. if (gridView1.GetRowCellValue(i, colisSelect).ToString() == "Y")
  1227. {
  1228. code = gridView1.GetRowCellValue(i, opCode).ToString();
  1229. }
  1230. }
  1231. //grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colUSERCODE, USERCODE);
  1232. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colUSERName, USERNAME);
  1233. isQueryCloseUp = true;
  1234. getPerson(USERCODE);
  1235. }
  1236. else
  1237. {
  1238. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colUSERCODE, "");
  1239. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colUSERName, "");
  1240. }
  1241. }
  1242. else
  1243. {
  1244. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colUSERCODE, "");
  1245. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colUSERName, "");
  1246. }
  1247. }
  1248. catch (Exception ex)
  1249. {
  1250. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  1251. }
  1252. }
  1253. private void repositoryItemGridLookUpEdit2_EditValueChanged(object sender, EventArgs e)
  1254. {
  1255. try
  1256. {
  1257. GridLookUpEdit edit = sender as GridLookUpEdit;
  1258. if (edit.EditValue != null || edit.EditValue.ToString() != "" || edit.EditValue.ToString() != "nulltext")
  1259. {
  1260. var o = edit.Properties.GetRowByKeyValue(edit.EditValue);
  1261. if (o is DataRowView)
  1262. {
  1263. DataRowView RowView = o as DataRowView;
  1264. string CODE = RowView.Row["设备类型"].ToString();
  1265. string EQPCode = RowView.Row["设备代码"].ToString();
  1266. string EQPName = RowView.Row["设备名称"].ToString();
  1267. string eqpcode = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colEQPCode).ToString();
  1268. if (string.IsNullOrWhiteSpace(eqpcode) || CODE.Equals(eqpcode))
  1269. {
  1270. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colEQPName, EQPName);
  1271. }
  1272. else
  1273. {
  1274. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colEQPName, "");
  1275. }
  1276. }
  1277. else
  1278. {
  1279. //grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colEQPCode, "");
  1280. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colEQPName, "");
  1281. //dtSend.Rows[grvDetail.FocusedRowHandle]["EQPName"] = "";
  1282. }
  1283. }
  1284. }
  1285. catch (Exception ex)
  1286. {
  1287. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  1288. }
  1289. }
  1290. private void repositoryItemGridLookUpEdit1_QueryPopUp(object sender, CancelEventArgs e)
  1291. {
  1292. isQueryCloseUp = false;
  1293. }
  1294. private void btnPrint_Click(object sender, EventArgs e)
  1295. {
  1296. List<string> lotno = new List<string>();
  1297. for (int i = 0; i < gridView1.RowCount; i++)
  1298. {
  1299. if (gridView1.GetRowCellValue(i, colisSelect).ToString() == "Y")
  1300. {
  1301. lotno.Add(gridView1.GetRowCellValue(i, colLOTNO).ToString());
  1302. }
  1303. }
  1304. if (lotno.Count <= 0)
  1305. {
  1306. ICSBaseSimpleCode.AppshowMessageBox("请选择需要打印的产品跟踪码!!!");
  1307. return;
  1308. }
  1309. FormICSProductTrackingList form = new FormICSProductTrackingList(lotno);
  1310. form.Show();
  1311. }
  1312. //取消派工
  1313. private void txtcancelSend_Click(object sender, EventArgs e)
  1314. {
  1315. List<string> lotno = new List<string>();
  1316. List<string> opcode = new List<string>();
  1317. List<FormICSMO2UserUIModel> MO2UserInfoList = new List<FormICSMO2UserUIModel>();
  1318. for (int i = 0; i < gridView1.RowCount; i++)
  1319. {
  1320. //if (gridView1.GetRowCellValue(i, colisSelect).ToString() == "Y" && gridView1.GetRowCellValue(i, isSend).ToString() == "是")
  1321. if (gridView1.GetRowCellValue(i, colisSelect).ToString() == "Y" && gridView1.GetRowCellValue(i, isSend).ToString() == "True")
  1322. {
  1323. lotno.Add(gridView1.GetRowCellValue(i, colLOTNO).ToString());
  1324. opcode.Add(gridView1.GetRowCellValue(i, opCode).ToString());
  1325. }
  1326. }
  1327. if (lotno.Count < 1)
  1328. {
  1329. ICSBaseSimpleCode.AppshowMessageBox("未选择产品追踪码或选中项还未派单!!!");
  1330. return;
  1331. }
  1332. try
  1333. {
  1334. ICSMO2UserBLL.cancelSend(lotno, opcode, AppConfig.AppConnectString);
  1335. ICSBaseSimpleCode.AppshowMessageBox(0, "取消成功");
  1336. }
  1337. catch (Exception ex)
  1338. {
  1339. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  1340. }
  1341. simpleSearch_Click(null, null);
  1342. }
  1343. /// <summary>
  1344. /// 绑定过滤条件
  1345. /// </summary>
  1346. /// <param name="sender"></param>
  1347. private void FilterLookupEQP(object sender)
  1348. {
  1349. try
  1350. {
  1351. GridLookUpEdit edit = sender as GridLookUpEdit;
  1352. if (edit == null)
  1353. return;
  1354. //string CODE = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colEQPType).ToString();
  1355. GridView gridView = edit.Properties.View as GridView;
  1356. //FieldInfo fi = gridView.GetType().GetField("extraFilter", BindingFlags.NonPublic | BindingFlags.Instance);
  1357. //BinaryOperator op2 = new BinaryOperator("设备代码", "%" + edit.AutoSearchText + "%", BinaryOperatorType.Like);
  1358. //string filterCondition = new GroupOperator(GroupOperatorType.And, new CriteriaOperator[] { op2 }).ToString();
  1359. ////BinaryOperator op3 = new BinaryOperator("Name", "%" + edit.AutoSearchText + "%", BinaryOperatorType.Like);
  1360. //string filterCondition = new GroupOperator(GroupOperatorType.Or, new CriteriaOperator[] { op1, op2, op3 }).ToString();
  1361. //fi.SetValue(gridView, filterCondition);
  1362. MethodInfo mi = gridView.GetType().GetMethod("ApplyColumnsFilterEx", BindingFlags.NonPublic | BindingFlags.Instance);
  1363. mi.Invoke(gridView, null);
  1364. }
  1365. catch (Exception ex)
  1366. {
  1367. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  1368. }
  1369. }
  1370. private void repositoryItemGridLookUpEdit2_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  1371. {
  1372. BeginInvoke(new MethodInvoker(delegate()
  1373. {
  1374. FilterLookupEQP(sender);
  1375. }));
  1376. }
  1377. private void repositoryItemGridLookUpEdit2_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
  1378. {
  1379. BeginInvoke(new MethodInvoker(delegate()
  1380. {
  1381. FilterLookupEQP(sender);
  1382. }));
  1383. }
  1384. private void repositoryItemGridLookUpEdit2_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
  1385. {
  1386. BeginInvoke(new MethodInvoker(delegate()
  1387. {
  1388. FilterLookupEQP(sender);
  1389. }));
  1390. }
  1391. private void GetStime(string eqpcode)
  1392. {
  1393. SqlParameter[] param = new SqlParameter[] {
  1394. new SqlParameter("EQPCode",eqpcode),
  1395. new SqlParameter("sumStime",SqlDbType.NVarChar,20)
  1396. };
  1397. param[1].Direction = ParameterDirection.Output;
  1398. DBHelper.ExecuteReader(AppConfig.AppConnectString, CommandType.StoredProcedure, "PC_Stime", param);
  1399. if (param[1].Value == null)
  1400. {
  1401. grvDetail.SetRowCellValue(0, wTime, "");
  1402. }
  1403. else
  1404. {
  1405. grvDetail.SetRowCellValue(0, wTime, param[1].Value.ToString());
  1406. }
  1407. }
  1408. private void getPerson(string userCode)
  1409. {
  1410. string sql = string.Format(@"
  1411. select username,eqpname,opname,
  1412. --plandate,BeginDate,EndDate,
  1413. icsmo2user.StartPlanDate plandate,
  1414. --BeginDate,
  1415. icsmo2user.EndPlanDate EndDate,
  1416. icsmo2user.lotno,
  1417. case
  1418. when StartPlanDate is not null then ''
  1419. else ''
  1420. end ,
  1421. --isnull(p.stime,0) as ,
  1422. ICSITEMLot.lotqty as ,
  1423. --convert(decimal(10,2),isnull(p.stime,0)*ICSMO2Lot.lotqty/60) as
  1424. 0 AS
  1425. from icsmo2user
  1426. left join ICSOP on ICSOP.OPCODE=ICSMO2User.OPCODE
  1427. left join icsmo on icsmo2user.mocode=icsmo.MOCODE
  1428. LEFT join ICSLOTONWIP on ICSLOTONWIP.OPCODE=ICSMO2User.opcode and ICSLOTONWIP.lotno=icsmo2user.lotno AND ICSLOTONWIP.action='good'
  1429. left join ICSROUTE2OP g on icsmo2user.RouteCode = g.RouteCode and icsmo2user.OPCODE=g.OPCODE
  1430. left join ICSITEMLot on ICSITEMLot.LOTNO=ICSMO2User.LOTNO
  1431. --left join ICSEQPSTPEMODEL p on p.ITEMCODE=ICSMO.ITEMCODE and p.OPCODE=ICSMO2User.OPCODE and p.EQPCODE=g.MainResources
  1432. where not EXISTS (select 1 from ICSLOTONWIP ww where ww.lotno =ICSMO2User.lotno and isnull(ww.EndTime,'')!='' and ww.opcode=ICSMO2User.opcode)
  1433. and usercode='{0}' ", userCode);
  1434. DataTable personSend = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  1435. int allstime = 0;
  1436. gridControl2.DataSource = personSend;
  1437. }
  1438. private void repositoryItemGridLookUpEdit2_QueryCloseUp(object sender, CancelEventArgs e)
  1439. {
  1440. try
  1441. {
  1442. isQueryCloseUpEQP = true;
  1443. GridLookUpEdit edit = sender as GridLookUpEdit;
  1444. if (edit.EditValue != null || edit.EditValue.ToString() != "" || edit.EditValue.ToString() != "nulltext")
  1445. {
  1446. var o = edit.Properties.View.GetDataRow(edit.Properties.View.FocusedRowHandle);
  1447. if (o is DataRow)
  1448. {
  1449. DataRow RowView = o as DataRow;
  1450. string CODE = RowView["设备类型"].ToString();
  1451. string EQPCODE = RowView["设备代码"].ToString();
  1452. string EQPNAME = RowView["设备名称"].ToString();
  1453. if (string.IsNullOrWhiteSpace(CODE) == false)
  1454. {
  1455. //grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colEQPCode, EQPCODE);
  1456. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colEQPName, EQPNAME);
  1457. GetStime(RowView["设备代码"].ToString());
  1458. }
  1459. else
  1460. {
  1461. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colEQPCode, "");
  1462. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colEQPName, "");
  1463. }
  1464. }
  1465. else
  1466. {
  1467. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colEQPCode, "");
  1468. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colEQPName, "");
  1469. }
  1470. }
  1471. }
  1472. catch (Exception ex)
  1473. {
  1474. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  1475. }
  1476. }
  1477. private void repositoryItemGridLookUpEdit2_QueryPopUp(object sender, CancelEventArgs e)
  1478. {
  1479. isQueryCloseUpEQP = false;
  1480. }
  1481. private void groupControl2_Paint(object sender, PaintEventArgs e)
  1482. {
  1483. }
  1484. private void simpleSearch_Click(object sender, EventArgs e)
  1485. {
  1486. try
  1487. {
  1488. // string sql = string.Format(@"select '' as isSelect,
  1489. // A.ProjectCode as 项目号, E.ROUTECODE as routeCode, A.MOCODE as 工单号, A.ITEMCODE as 料号, B.LOTNO as 产品跟踪单号,
  1490. // C.ItemName AS 料品名称, c.ItemStd as 料品图纸,f.OPcode as 工序编码, f.OPdesc as 工序, e.OPSEQ as 工序次序,
  1491. //A.modept as 生产部门, p.STIME as 工时, MOPLANSTARTDATE as 预计开工时间, MOPLANENDDATE AS 预计完工时间,b.lotqty as 数量,
  1492. //case
  1493. // when icsmo2user.OPCODE is null then '否'
  1494. // else '是'
  1495. // end as 是否已派工
  1496. //FROM ICSMO A
  1497. //INNER join ICSMO2Lot B ON B.MOCODE = A.MOCODE
  1498. //left join Base_Inventory c on c.ItemCode = A.ITEMCODE
  1499. //LEFT JOIN ICSMO2ROUTE d on d.MOCODE = a.MOCODE
  1500. //left join icsroute2op e on e.ROUTECODE = d.ROUTECODE
  1501. //left join ICSOP f on f.opcode = e.OPCODE
  1502. //left join ICSEQPSTPEMODEL p on p.ItemCode = a.ItemCode and p.OPCODE = f.opcode and p.EQPCODE = e.MainResources and p.ISREF = '是'
  1503. //left join icsmo2user on icsmo2user.lotno=b.LOTNO and icsmo2user.OPCODE=f.opcode
  1504. //left join ICSITEMROUTE2OP h on h.ITEMCODE=a.ITEMCODE and h.ROUTECODE=d.ROUTECODE and h.OPCODE=f.OPCODE
  1505. //where H.IDMERGERULE!=1
  1506. // ");
  1507. // string sql = string.Format(@"SELECT DISTINCT
  1508. // '' AS isSelect,
  1509. // --A.ProjectCode AS 项目号,
  1510. // E.ROUTECODE AS routeCode,
  1511. // A.MOCODE AS 工单号,a.MOSEQ 工单行号,
  1512. // A.ITEMCODE AS 料号,
  1513. // B.LOTNO AS 产品跟踪单号,
  1514. // C.INVNAME AS 料品名称,
  1515. // --c.INVShelfLife as 料品图纸,
  1516. // f.OPcode AS 工序编码,
  1517. // f.OPdesc AS 工序,
  1518. // e.OPSEQ AS 工序次序,
  1519. // A.MDeptCode AS 生产部门,
  1520. // '' as pictureSee,
  1521. // --p.STIME AS 工时,
  1522. // 0 AS 工时,
  1523. // --0908修改
  1524. // A.MOPLANSTARTDATE AS 预计开工时间,
  1525. // A.MOPLANENDDATE AS 预计完工时间,
  1526. // cast(b.lotqty as int) AS 数量,
  1527. // --b.lotqty AS 数量,
  1528. // --CAST(CASE WHEN icsmo2user.OPCODE IS NULL or icsmo2user.EATTRIBUTE1!='1' THEN '0' ELSE '1' END AS BIT) AS 是否已派工,
  1529. // CAST(CASE WHEN (icsmo2user.OPCODE IS NOT NULL or icsmo2user.EATTRIBUTE1='1' ) THEN '1' ELSE '0' END AS BIT) AS 是否已派工,
  1530. // CAST(CASE WHEN icsmo2user.EATTRIBUTE1 ='1' THEN '1' ELSE '0' END AS BIT) AS 已委外,
  1531. // case
  1532. // when i.ACTIONRESULT = 'COLLECT_BEGIN' then '开工未完工'
  1533. // when icsmo2user.OPCODE is null then '未派工'
  1534. // when i.ACTIONRESULT IS NULL THEN '未开工'
  1535. // when i.ACTIONRESULT = 'COLLECT_END' and g.Result is null then '完工未检验'
  1536. // when i.ACTIONRESULT = 'COLLECT_END' and g.Result = '合格' then '检验合格'
  1537. // wheN i.ACTIONRESULT = 'COLLECT_END' and g.Result = '不合格' then '检验不合格'
  1538. // end as status
  1539. // FROM
  1540. // ICSMO A
  1541. // INNER JOIN ICSITEMLot B ON B.TransNO = A.MOCODE AND a.MOSEQ=b.TransLine-- B.MCODE = A.MOCODE -- ICSMO2Lot
  1542. // -- left join Base_Inventory c on c.ItemCode = A.ITEMCODE
  1543. // LEFT JOIN ICSINVENTORY c ON c.INVCODE = A.ITEMCODE
  1544. // LEFT JOIN ICSMO2ROUTE d ON d.MOCODE = a.MOCODE
  1545. // LEFT JOIN icsroute2op e ON e.ROUTECODE = d.ROUTECODE
  1546. // LEFT JOIN ICSOP f ON f.opcode = e.OPCODE
  1547. // -- LEFT JOIN ICSEQPSTPEMODEL p ON p.ItemCode = a.ItemCode
  1548. // -- AND p.OPCODE = f.opcode
  1549. // -- AND p.EQPCODE = e.MainResources
  1550. // -- AND p.ISREF = '是'
  1551. // LEFT JOIN icsmo2user ON icsmo2user.lotno = b.LOTNO
  1552. // AND icsmo2user.OPCODE = f.opcode
  1553. // LEFT JOIN ICSITEMROUTE2OP h ON h.ITEMCODE = a.ITEMCODE
  1554. // AND h.ROUTECODE = d.ROUTECODE
  1555. // AND h.OPCODE = f.OPCODE
  1556. // left join ICSLOTONWIP i on i.lotno=b.lotno and i.opcode=f.OPcode
  1557. // left join ICSLOTONWIPCheck g on g.ONWIPID=i.id
  1558. // WHERE
  1559. // H.IDMERGERULE != 1
  1560. //");
  1561. string erpconstr = GetERPConn();
  1562. string sql = string.Format(@"select * from (
  1563. SELECT DISTINCT
  1564. '' AS isSelect,
  1565. A.OrderNo AS ,
  1566. E.ROUTECODE AS routeCode,
  1567. A.MOCODE AS ,a.MOSEQ ,
  1568. A.ITEMCODE AS ,
  1569. a.MOVER,
  1570. B.LOTNO AS ,
  1571. C.INVNAME AS ,
  1572. --c.INVShelfLife as ,
  1573. f.OPcode AS ,
  1574. f.OPdesc AS ,
  1575. e.OPSEQ AS ,
  1576. A.MDeptCode AS ,
  1577. '' as pictureSee,
  1578. --p.STIME AS ,
  1579. 0 AS ,
  1580. --0908
  1581. A.MOPLANSTARTDATE AS ,
  1582. A.MOPLANENDDATE AS ,
  1583. CAST(case when ISNULL(icsmo2user.SEGCODE,'1')='' THEN '0' ELSE ISNULL(icsmo2user.SEGCODE,'0') END AS Bit) AS ISAGV,
  1584. cast(b.lotqty as int) AS ,
  1585. --b.lotqty AS ,
  1586. --CAST(CASE WHEN icsmo2user.OPCODE IS NULL or icsmo2user.EATTRIBUTE1!='1' THEN '0' ELSE '1' END AS BIT) AS ,
  1587. CAST(CASE WHEN (icsmo2user.OPCODE IS NOT NULL or icsmo2user.EATTRIBUTE1='1' ) THEN '1' ELSE '0' END AS BIT) AS ,
  1588. CAST(CASE WHEN icsmo2user.EATTRIBUTE1 ='1' THEN '1' ELSE '0' END AS BIT) AS ,
  1589. case
  1590. when i.ACTIONRESULT = 'COLLECT_BEGIN' then ''
  1591. when icsmo2user.OPCODE is null then ''
  1592. when i.ACTIONRESULT IS NULL THEN ''
  1593. when i.ACTIONRESULT = 'COLLECT_END' and g.Result is null and ncr.ID is not null then ''
  1594. when i.ACTIONRESULT = 'COLLECT_END' and g.Result is null and ncr.ID is null then ''
  1595. when i.ACTIONRESULT = 'COLLECT_END' and g.Result = '' then ''
  1596. wheN i.ACTIONRESULT = 'COLLECT_END' and g.Result = '' then ''
  1597. end as status,
  1598. icsmo2user.prlineid as prline,
  1599. po.pocode
  1600. FROM
  1601. ICSMO A
  1602. INNER JOIN ICSITEMLot B ON B.TransNO = A.MOCODE AND a.MOSEQ=b.TransLine-- B.MCODE = A.MOCODE -- ICSMO2Lot
  1603. -- left join Base_Inventory c on c.ItemCode = A.ITEMCODE
  1604. LEFT JOIN ICSINVENTORY c ON c.INVCODE = A.ITEMCODE
  1605. inner JOIN ICSITEMROUTE2OPLot e ON e.LotNo = b.LotNO
  1606. LEFT JOIN ICSOP f ON f.opcode = e.OPCODE
  1607. -- LEFT JOIN ICSEQPSTPEMODEL p ON p.ItemCode = a.ItemCode
  1608. -- AND p.OPCODE = f.opcode
  1609. -- AND p.EQPCODE = e.MainResources
  1610. -- AND p.ISREF = '是'
  1611. LEFT JOIN icsmo2user ON icsmo2user.lotno = b.LOTNO
  1612. AND icsmo2user.OPCODE = f.opcode
  1613. left join ICSLOTONWIP i on i.lotno=b.lotno and i.opcode=f.OPcode
  1614. left join ICSLOTONWIPCheck g on g.ONWIPID=i.id
  1615. left join ICSPO_PoMain po on po.free1=icsmo2user.prlineid
  1616. left join ICSNCRDoc ncr on ncr.LOTNO=i.LotNO and ncr.OPCode=i.OPCODE and ncr.ErrorType=''
  1617. --left join {0}.dbo.PU_AppVouchs u on u.autoid=icsmo2user.prlineid
  1618. -- left join {0}.dbo.PU_AppVouch v on v.id=u.id
  1619. where a.mobiosver=''
  1620. )a
  1621. where 1=1 ", erpconstr);
  1622. string sqlwhere = "";
  1623. if (txtMoLotCode.Text != "")
  1624. {
  1625. sqlwhere += string.Format(" and A.MOVER like '%{0}%'", txtMoLotCode.Text);
  1626. }
  1627. if (txtMOCODE.Text != "")
  1628. {
  1629. sqlwhere += string.Format(" and A.工单号 like '%{0}%'", txtMOCODE.Text);
  1630. }
  1631. if (txtLotNo.Text != "")
  1632. {
  1633. sqlwhere += string.Format(" AND A.产品跟踪单号 like '%{0}%'", txtLotNo.Text);
  1634. }
  1635. if (txtITEMCODE.Text != "")
  1636. {
  1637. sqlwhere += string.Format(" AND A.料号 LIKE '%{0}%'", txtITEMCODE.Text);
  1638. }
  1639. if (txtItemName.Text != "")
  1640. {
  1641. sqlwhere += string.Format(" and A.料品名称 LIKE '%{0}%'", txtItemName.Text);
  1642. }
  1643. if (txtDepart.Text != "")
  1644. {
  1645. sqlwhere += string.Format("and A.生产部门 like '%{0}%'", txtDepart.Text);
  1646. }
  1647. if (txtOpDesc.Text != "")
  1648. {
  1649. sqlwhere += string.Format(" and A.工序编码 like '%{0}%' ", txtOpDesc.Text);
  1650. }
  1651. if (txtOrderNo.Text != "")
  1652. {
  1653. sqlwhere += string.Format(" and A.项目号 like '%{0}%' ", txtOrderNo.Text);
  1654. }
  1655. //if (textItemStd.Text != "")
  1656. //{
  1657. // sqlwhere += string.Format(" and c.INVSTD like '%{0}%'", textItemStd.Text);
  1658. //}
  1659. //if (dateTimePicker1.Checked)
  1660. //{
  1661. // sqlwhere += string.Format(" AND Convert(varchar(12),icsmo2user.MTIME,23) between '{0}' AND '{1}'", dateTimePicker1.Value.ToString("YYYY-MM-DD"), dateTimePicker2.Value.ToString("YYYY-MM-DD"));
  1662. //}
  1663. sql += sqlwhere + "order by a.工序次序";
  1664. DataTable lotMessage = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  1665. dtLotno = lotMessage;
  1666. gridControl1.DataSource = lotMessage;
  1667. gridView1.BestFitColumns();
  1668. LoadGrd();
  1669. }
  1670. catch (Exception ex)
  1671. {
  1672. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  1673. }
  1674. }
  1675. private void gridControl1_Click(object sender, EventArgs e)
  1676. {
  1677. }
  1678. #region 已派工
  1679. private void button2_Click(object sender, EventArgs e)
  1680. {
  1681. try
  1682. {
  1683. DataView dv = dtLotno.DefaultView;
  1684. //dv.RowFilter = "是否已派工='是'";
  1685. dv.RowFilter = "是否已派工='True' and 已委外='False'";
  1686. gridControl1.DataSource = dv;
  1687. gridView1.BestFitColumns();
  1688. }
  1689. catch (Exception EX)
  1690. {
  1691. ICSBaseSimpleCode.AppshowMessageBox("请先查询数据!");
  1692. }
  1693. }
  1694. #endregion
  1695. private void button1_Click(object sender, EventArgs e)
  1696. {
  1697. try
  1698. {
  1699. DataView dv = dtLotno.DefaultView;
  1700. //dv.RowFilter = "是否已派工='否'";
  1701. dv.RowFilter = "是否已派工='False'";
  1702. gridControl1.DataSource = dv;
  1703. gridView1.BestFitColumns();
  1704. }
  1705. catch (Exception EX)
  1706. {
  1707. ICSBaseSimpleCode.AppshowMessageBox("请先查询数据!");
  1708. }
  1709. }
  1710. private void gridView1_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
  1711. {
  1712. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  1713. {
  1714. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  1715. }
  1716. }
  1717. private void gridView2_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
  1718. {
  1719. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  1720. {
  1721. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  1722. }
  1723. }
  1724. private void repositoryItemButtonEdit4_Click(object sender, EventArgs e)
  1725. {
  1726. Dictionary<string, string> dic = new Dictionary<string, string>();
  1727. dic.Add("routeCode", gridView1.GetRowCellValue(gridView1.FocusedRowHandle, routeCode).ToString());
  1728. dic.Add("OPNAME", gridView1.GetRowCellValue(gridView1.FocusedRowHandle, colopname).ToString());
  1729. dic.Add("ITEMCODE", gridView1.GetRowCellValue(gridView1.FocusedRowHandle, itemCode).ToString());
  1730. dic.Add("opseq", gridView1.GetRowCellValue(gridView1.FocusedRowHandle, colopSeq).ToString());
  1731. dic.Add("Pic", gridView1.GetRowCellValue(gridView1.FocusedRowHandle, colpic).ToString());
  1732. FormICSPicture pic = new FormICSPicture(dic);
  1733. pic.ShowDialog();
  1734. }
  1735. private void repositoryItemButtonEdit4_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  1736. {
  1737. try
  1738. {
  1739. string url = @"http://172.16.12.155:8999/api/GetPLMToken";
  1740. //string url = @"http://localhost:51182/api/GetPLMToken";
  1741. FormICSProductionReport.SearchPart Bills = new FormICSProductionReport.SearchPart();
  1742. //Bills.ItemCode = "20100003035";
  1743. //Bills.ItemCode = "20100000670";
  1744. //Bills.ItemCode = "20800001904";
  1745. Bills.ItemCode = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, itemCode).ToString();
  1746. Bills.size = 100;
  1747. Bills.extra = "DWGSW";
  1748. string JsonData = JsonConvert.SerializeObject(Bills);
  1749. //try
  1750. //{
  1751. // //Bills = JsonConvert.DeserializeObject<List<SearchPart>>(JsonData.ToString());
  1752. // Bills = JsonConvert.DeserializeObject<SearchPart>(JsonData.ToString());
  1753. //}
  1754. #region MyRegion
  1755. ICSSoft.Frame.APP.FormICSProductionReport.BaseModel rtn = PLMMap(url, JsonData);
  1756. if (rtn.code == "200")
  1757. {
  1758. #region MyRegion
  1759. string connectionString = AppConfig.GetDataBaseConnectStringByKey("[DB.FTP]");
  1760. if (string.IsNullOrWhiteSpace(connectionString))
  1761. {
  1762. ICSBaseSimpleCode.AppshowMessageBox("没有获取到FTP链接,请在数据源中先配置FTP");
  1763. return;
  1764. }
  1765. string[] ftps = connectionString.Split(';');
  1766. string ftpServerIP = ftps[0].Split('=')[1];
  1767. //string ftpRemotePath = ftps[1].Split('=')[1];
  1768. string ftpRemotePath = "";
  1769. string ftpUserID = ftps[2].Split('=')[1];
  1770. string ftpPassword = ftps[3].Split('=')[1];
  1771. FtpWeb ftpWeb = new FtpWeb(ftpServerIP, ftpRemotePath, ftpUserID, ftpPassword);
  1772. //FtpWeb ftpWeb = new FtpWeb(ftpServerIP, ftpRemotePath, ftpUserID, ftpPassword);
  1773. //string filePath = System.IO.Path.GetTempPath() + "\\Drawing";
  1774. string filePath = AppDomain.CurrentDomain.BaseDirectory + "\\Drawing";
  1775. if (!Directory.Exists(filePath))
  1776. {
  1777. Directory.CreateDirectory(filePath);
  1778. }
  1779. string fileName = Bills.ItemCode + ".pdf";
  1780. ftpWeb.Download(filePath + "\\", fileName);
  1781. string filePathName = filePath + "\\" + fileName;
  1782. //string fileName = logAdress + Bills.ItemCode + ".pdf";
  1783. string ftpURL = "ftp://" + ftpServerIP + "/" + fileName;
  1784. //if (!string.IsNullOrEmpty(fileName))
  1785. if (!string.IsNullOrEmpty(filePathName))
  1786. {
  1787. FileDrawing.LoadPDF(filePathName);
  1788. }
  1789. #endregion
  1790. }
  1791. else
  1792. {
  1793. ICSBaseSimpleCode.AppshowMessageBox("调用PLM接口返回异常:" + rtn.code + ";" + rtn.msg);
  1794. return;
  1795. }
  1796. #endregion
  1797. }
  1798. catch (Exception ex)
  1799. {
  1800. MessageBox.Show(ex.Message);
  1801. }
  1802. }
  1803. public static ICSSoft.Frame.APP.FormICSProductionReport.BaseModel PLMMap(string URL, string JsonData)
  1804. {
  1805. try
  1806. {
  1807. //调用接口获取返回信息
  1808. //string ContentType = "application/json;charset=UTF-8;";
  1809. string ContentType = "application/json";
  1810. WebRequest request = WebRequest.Create(URL);
  1811. request.Method = "POST";
  1812. byte[] bytes = System.Text.Encoding.UTF8.GetBytes(JsonData);
  1813. request.ContentType = ContentType;
  1814. request.ContentLength = bytes.Length;
  1815. //using (Stream postStream = request.GetRequestStream())
  1816. //{
  1817. // postStream.Write(bytes, 0, bytes.Length);
  1818. //}
  1819. using (Stream postStream = request.GetRequestStream())
  1820. {
  1821. postStream.Write(bytes, 0, bytes.Length);
  1822. }
  1823. request.Credentials = CredentialCache.DefaultCredentials;
  1824. string str = string.Empty;
  1825. WebResponse response = null;
  1826. try
  1827. {
  1828. response = request.GetResponse();
  1829. }
  1830. catch (WebException ex)
  1831. {
  1832. if (ex.Status == WebExceptionStatus.ProtocolError)
  1833. response = (WebResponse)ex.Response;
  1834. }
  1835. if (response != null)
  1836. {
  1837. using (StreamReader st = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
  1838. {
  1839. str = System.Web.HttpUtility.UrlDecode(st.ReadToEnd());
  1840. }
  1841. }
  1842. //将返回的string类型转换成model
  1843. ICSSoft.Frame.APP.FormICSProductionReport.BaseModel obj = (ICSSoft.Frame.APP.FormICSProductionReport.BaseModel)Newtonsoft.Json.JsonConvert.DeserializeObject(str, typeof(ICSSoft.Frame.APP.FormICSProductionReport.BaseModel));
  1844. //string obj = (string)Newtonsoft.Json.JsonConvert.DeserializeObject(str, typeof(string));
  1845. return obj;
  1846. }
  1847. catch (Exception ex)
  1848. {
  1849. throw new Exception("调用MES接口错误:" + ex.Message);
  1850. }
  1851. }
  1852. /// <summary>
  1853. /// 清空
  1854. /// </summary>
  1855. /// <param name="sender"></param>
  1856. /// <param name="e"></param>
  1857. private void buttonclear_Click(object sender, EventArgs e)
  1858. {
  1859. foreach (Control a in groupControl2.Controls)
  1860. {
  1861. if (a is TextEdit && a is LookUpEdit == false)
  1862. {
  1863. TextEdit edit = a as TextEdit;
  1864. edit.Text = "";
  1865. }
  1866. else if (a is LookUpEdit)
  1867. {
  1868. LookUpEdit edit = a as LookUpEdit;
  1869. edit.EditValue = null;
  1870. }
  1871. }
  1872. }
  1873. private void txtDepart_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  1874. {
  1875. FormDataRefer refer = new FormDataRefer();
  1876. //string sql = "select modept as 部门名称 from icsmo group by modept having len(modept)>0";
  1877. string sql = "select MDeptCode as 部门名称 from icsmo group by MDeptCode having len(MDeptCode)>0";
  1878. DataTable source = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  1879. refer.FormTitle = "生产部门";
  1880. refer.FormWidth = 500;
  1881. refer.FormHeight = 500;
  1882. refer.RowIndexWidth = 35;
  1883. refer.MSelectFlag = false;
  1884. refer.DataSource = source;
  1885. if (refer.ShowDialog() == DialogResult.OK)
  1886. {
  1887. DataTable table = refer.ReturnData;
  1888. foreach (DataRow a in table.Rows)
  1889. {
  1890. txtDepart.Text = a["部门名称"].ToString();
  1891. }
  1892. }
  1893. }
  1894. public void LoadOp()
  1895. {
  1896. //string sql = "select a.OPCODE as 工序代码,a.OPDESC as 工序名称 from ICSOP a";
  1897. //DataTable source = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  1898. //txtOpDesc.Properties.ValueMember = "工序代码";
  1899. //txtOpDesc.Properties.DisplayMember = "工序代码";
  1900. //txtOpDesc.Properties.DataSource = source;
  1901. //txtOpDesc.Properties.NullText = "";
  1902. //txtOpDesc.Properties.ValidateOnEnterKey = true;//回车确认
  1903. //txtOpDesc.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
  1904. //txtOpDesc.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  1905. //txtOpDesc.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  1906. }
  1907. #region 委外保存
  1908. private void BtnWWSave_Click(object sender, EventArgs e)
  1909. {
  1910. string lotno = "";
  1911. List<string> lotnoList = new List<string>();
  1912. List<FormICSMO2UserUIModel> MO2UserInfoList = new List<FormICSMO2UserUIModel>();
  1913. for (int i = 0; i < gridView1.RowCount; i++)
  1914. {
  1915. if (gridView1.GetRowCellValue(i, colisSelect).ToString() == "Y")
  1916. {
  1917. lotno = gridView1.GetRowCellValue(i, colLOTNO).ToString();
  1918. lotnoList.Add(lotno);
  1919. }
  1920. }
  1921. if (lotnoList.Count < 1)
  1922. {
  1923. ICSBaseSimpleCode.AppshowMessageBox("请选择需要委外的数据!!!");
  1924. return;
  1925. }
  1926. for (int i = 0; i < gridView1.RowCount; i++)
  1927. {
  1928. if (gridView1.GetRowCellValue(i, colisSelect).ToString() == "Y")
  1929. {
  1930. if (gridView1.GetRowCellValue(i, pgstatus).ToString() != "未派工")
  1931. {
  1932. ICSBaseSimpleCode.AppshowMessageBox("批号:" + gridView1.GetRowCellValue(i, colLOTNO).ToString() + ",工序:" + gridView1.GetRowCellValue(i, opCode).ToString() + ",已经派工,请勿重复操作!");
  1933. return;
  1934. }
  1935. #region 20210728已经开工的工序不能再操作
  1936. string sqlCheck = @"SELECT COUNT(*) FROM ICSLOTONWIP WHERE LOTNO='" + gridView1.GetRowCellValue(i, colLOTNO).ToString() + "' AND OPCODE='" + gridView1.GetRowCellValue(i, opCode).ToString() + "'";
  1937. DataTable DTCheck = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqlCheck).Tables[0];
  1938. if (DTCheck != null && DTCheck.Rows.Count > 0)
  1939. {
  1940. int a = Int32.Parse(DTCheck.Rows[0][0].ToString());
  1941. if (a > 0)
  1942. {
  1943. ICSBaseSimpleCode.AppshowMessageBox("批号:" + gridView1.GetRowCellValue(i, colLOTNO).ToString() + ",工序:" + gridView1.GetRowCellValue(i, opCode).ToString() + ",已经开工,不能保存!");
  1944. return;
  1945. }
  1946. }
  1947. #endregion
  1948. FormICSMO2UserUIModel MO2UserInfo = new FormICSMO2UserUIModel();
  1949. MO2UserInfo.ID = "";
  1950. MO2UserInfo.MOCODE = gridView1.GetRowCellValue(i, moCode).ToString();
  1951. MO2UserInfo.LOTNO = gridView1.GetRowCellValue(i, colLOTNO).ToString();
  1952. //MO2UserInfo.SEGCODE = txtDepart.Text.ToString();
  1953. //if (!string.IsNullOrWhiteSpace(txtMOSEQ.Text.ToString()))
  1954. //{
  1955. // MO2UserInfo.MOSEQ = Int32.Parse(txtMOSEQ.Text.ToString());
  1956. //}
  1957. //else
  1958. //{
  1959. // MO2UserInfo.MOSEQ = Int32.Parse(gridView1.GetRowCellValue(i, colMOSEQ).ToString());
  1960. //}
  1961. if (!string.IsNullOrWhiteSpace(gridView1.GetRowCellValue(i, colMOSEQ).ToString()))
  1962. MO2UserInfo.MOSEQ = Int32.Parse(gridView1.GetRowCellValue(i, colMOSEQ).ToString());
  1963. MO2UserInfo.RouteCode = gridView1.GetRowCellValue(i, routeCode).ToString();
  1964. MO2UserInfo.OPCODE = gridView1.GetRowCellValue(i, opCode).ToString();
  1965. MO2UserInfo.USERCODE = grvDetail.GetRowCellValue(0, colUSERCODE).ToString();
  1966. MO2UserInfo.USERName = grvDetail.GetRowCellValue(0, colUSERName).ToString();
  1967. MO2UserInfo.EQPCode = grvDetail.GetRowCellValue(0, colEQPCode).ToString();
  1968. MO2UserInfo.EQPName = grvDetail.GetRowCellValue(0, colEQPName).ToString();
  1969. MO2UserInfo.MUSER = AppConfig.UserCode;
  1970. MO2UserInfo.MUSERName = AppConfig.UserName;
  1971. MO2UserInfo.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  1972. MO2UserInfo.WorkPoint = AppConfig.WorkPointCode;
  1973. MO2UserInfo.EATTRIBUTE1 = "1";
  1974. MO2UserInfo.PlanDate = int.Parse(AppConfig.GetSeverDateTime("yyyy-MM-dd").ToString("yyyyMMdd"));
  1975. MO2UserInfo.SEGCODE= Convert.ToBoolean(gridView1.GetRowCellValue(i, ISAGV)) == true ? "1" : "0";
  1976. if (string.IsNullOrEmpty(grvDetail.GetRowCellValue(0, colPlanDate).ToString()) == false)
  1977. {
  1978. MO2UserInfo.SendPlanDate = Convert.ToDateTime(grvDetail.GetRowCellValue(0, colPlanDate).ToString());
  1979. }
  1980. MO2UserInfoList.Add(MO2UserInfo);
  1981. //if (string.IsNullOrEmpty(MO2UserInfo.USERCODE) || string.IsNullOrEmpty(MO2UserInfo.EQPCode))
  1982. //{
  1983. // ICSBaseSimpleCode.AppshowMessageBox("请分配员工和设备后再保存!");
  1984. // return;
  1985. //}
  1986. }
  1987. }
  1988. try
  1989. {
  1990. ICSMO2UserBLL.Add(MO2UserInfoList, AppConfig.AppConnectString);
  1991. ICSBaseSimpleCode.AppshowMessageBox(0, "委外保存成功");
  1992. simpleSearch_Click(null, null);
  1993. }
  1994. catch (Exception ex)
  1995. {
  1996. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  1997. }
  1998. btnFalsh_Click(null, null);
  1999. }
  2000. #endregion
  2001. #region 委外撤销 0917+同时取消派工 如果已产生鼎捷采购单则同时删除单据
  2002. private void BtnWWCancel_Click(object sender, EventArgs e)
  2003. {
  2004. string lotno = "";
  2005. List<string> lotnoList = new List<string>();
  2006. List<FormICSMO2UserUIModel> MO2UserInfoList = new List<FormICSMO2UserUIModel>();
  2007. List<string> lotnos = new List<string>();
  2008. List<string> opcode = new List<string>();
  2009. // List<FormICSMO2UserUIModel> MO2UserInfoLists = new List<FormICSMO2UserUIModel>();
  2010. List<DDMaster> dmasters = new List<DDMaster>();
  2011. List<string> pos = new List<string>();
  2012. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("委外撤销会删除鼎捷委外采购单,确认吗") != DialogResult.OK)
  2013. return;
  2014. for (int i = 0; i < gridView1.RowCount; i++)
  2015. {
  2016. if (gridView1.GetRowCellValue(i, colisSelect).ToString() == "Y")
  2017. {
  2018. lotno = gridView1.GetRowCellValue(i, colLOTNO).ToString();
  2019. lotnoList.Add(lotno);
  2020. }
  2021. if (gridView1.GetRowCellValue(i, colisSelect).ToString() == "Y" && gridView1.GetRowCellValue(i, isSend).ToString() == "True")
  2022. {
  2023. lotnos.Add(gridView1.GetRowCellValue(i, colLOTNO).ToString());
  2024. opcode.Add(gridView1.GetRowCellValue(i, opCode).ToString());
  2025. var po = gridView1.GetRowCellValue(i, prline).ToString();
  2026. if (!String.IsNullOrEmpty(po)&&po.Contains("-"))
  2027. {
  2028. if (!pos.Contains(po.Substring(0,po.LastIndexOf("-"))))
  2029. {
  2030. DDMaster dmaster = new DDMaster();
  2031. dmaster.dflag = "Y";
  2032. dmaster.pmdldocno = po.Substring(0, po.LastIndexOf("-"));
  2033. dmasters.Add(dmaster);
  2034. pos.Add(po.Substring(0, po.LastIndexOf("-")));
  2035. }
  2036. }
  2037. }
  2038. }
  2039. if (lotnoList.Count < 1)
  2040. {
  2041. ICSBaseSimpleCode.AppshowMessageBox("请选择需要委外撤销的数据!!!");
  2042. return;
  2043. }
  2044. if (lotnos.Count < 1)
  2045. {
  2046. ICSBaseSimpleCode.AppshowMessageBox("未选择产品追踪码或选中项还未派单!!!");
  2047. return;
  2048. }
  2049. for (int i = 0; i < gridView1.RowCount; i++)
  2050. {
  2051. if (gridView1.GetRowCellValue(i, colisSelect).ToString() == "Y")
  2052. {
  2053. #region OLD
  2054. ////if (!string.IsNullOrEmpty(gridView1.GetRowCellValue(i, prline).ToString())) {
  2055. //// ICSBaseSimpleCode.AppshowMessageBox("追踪单号:"+ gridView1.GetRowCellValue(i, colLOTNO).ToString()+",工序:"+ gridView1.GetRowCellValue(i, opCode).ToString()+"已产生委外请购单,无法撤销!");
  2056. //// return;
  2057. ////}
  2058. //FormICSMO2UserUIModel MO2UserInfo = new FormICSMO2UserUIModel();
  2059. //MO2UserInfo.ID = "";
  2060. //MO2UserInfo.MOCODE = gridView1.GetRowCellValue(i, moCode).ToString();
  2061. //MO2UserInfo.LOTNO = gridView1.GetRowCellValue(i, colLOTNO).ToString();
  2062. //MO2UserInfo.SEGCODE = txtDepart.Text.ToString();
  2063. ////if (!string.IsNullOrWhiteSpace(txtMOSEQ.Text.ToString()))
  2064. ////{
  2065. //// MO2UserInfo.MOSEQ = Int32.Parse(txtMOSEQ.Text.ToString());
  2066. ////}
  2067. ////else
  2068. ////{
  2069. //// MO2UserInfo.MOSEQ = 0;
  2070. ////}
  2071. //if (!string.IsNullOrWhiteSpace(gridView1.GetRowCellValue(i, colMOSEQ).ToString()))
  2072. // MO2UserInfo.MOSEQ = Int32.Parse(gridView1.GetRowCellValue(i, colMOSEQ).ToString());
  2073. //MO2UserInfo.RouteCode = gridView1.GetRowCellValue(i, routeCode).ToString();
  2074. //MO2UserInfo.OPCODE = gridView1.GetRowCellValue(i, opCode).ToString();
  2075. //MO2UserInfo.USERCODE = grvDetail.GetRowCellValue(0, colUSERCODE).ToString();
  2076. //MO2UserInfo.USERName = grvDetail.GetRowCellValue(0, colUSERName).ToString();
  2077. //MO2UserInfo.EQPCode = grvDetail.GetRowCellValue(0, colEQPCode).ToString();
  2078. //MO2UserInfo.EQPName = grvDetail.GetRowCellValue(0, colEQPName).ToString();
  2079. //MO2UserInfo.MUSER = AppConfig.UserCode;
  2080. //MO2UserInfo.MUSERName = AppConfig.UserName;
  2081. //MO2UserInfo.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  2082. //MO2UserInfo.WorkPoint = AppConfig.WorkPointCode;
  2083. //MO2UserInfo.EATTRIBUTE1 = "0";
  2084. //MO2UserInfo.PlanDate = int.Parse(AppConfig.GetSeverDateTime("yyyy-MM-dd").ToString("yyyyMMdd"));
  2085. //if (string.IsNullOrEmpty(grvDetail.GetRowCellValue(0, colPlanDate).ToString()) == false)
  2086. //{
  2087. // MO2UserInfo.SendPlanDate = Convert.ToDateTime(grvDetail.GetRowCellValue(0, colPlanDate).ToString());
  2088. //}
  2089. ////判断该单据是否已生成u8请购单
  2090. //MO2UserInfoList.Add(MO2UserInfo);
  2091. #endregion
  2092. }
  2093. }
  2094. try
  2095. {
  2096. //ICSMO2UserBLL.Add(MO2UserInfoList, AppConfig.AppConnectString);
  2097. //ICSBaseSimpleCode.AppshowMessageBox(0, "委外撤销成功");
  2098. DOutSourceDto dto = new DOutSourceDto();
  2099. dto.key = PoKey;
  2100. dto.type = "sync";
  2101. DHost host = new DHost();
  2102. host.prod = "APP";
  2103. host.lang = "zh_CN";
  2104. host.timestamp = DateTime.Now.ToString("yyyyMMddHHmmssfff");
  2105. host.acct = "tiptop";
  2106. host.ip = WebHelper.GetIp();//ip地址
  2107. DService service = new DService();
  2108. service.prod = "T100";
  2109. service.name = "CPurchaseOrderCreate";
  2110. service.ip = "172.16.11.152";
  2111. service.id = "topprd";
  2112. Datakey datakey = new Datakey();
  2113. datakey.CompanyId = CompanyId;
  2114. datakey.EntId = EntId;
  2115. DPayload pay = new DPayload();
  2116. DStd_data std = new DStd_data();
  2117. DDParameter param = new DDParameter();
  2118. param.master = dmasters;
  2119. std.parameter = param;
  2120. pay.std_data = std;
  2121. dto.datakey = datakey;
  2122. dto.host = host;
  2123. dto.service = service;
  2124. dto.payload = pay;
  2125. DReturn rtn = WebHelper.HttpPost<DReturn>(DjAddress, JsonConvert.SerializeObject(dto));
  2126. var errormes = "";
  2127. if (rtn.payload.std_data.execution.code != "0")
  2128. {
  2129. errormes = string.Join("\r\n", rtn.payload.std_data.parameter.fail_return.Select(a => a.error_msg).ToList());
  2130. }
  2131. ICSMO2UserDAL.WriteLogFile("Params:" + JsonConvert.SerializeObject(dto) + "\r\n" + "returns:" + JsonConvert.SerializeObject(rtn), "鼎捷委外采购单");
  2132. if (!string.IsNullOrEmpty(errormes))
  2133. throw new Exception(errormes);
  2134. ICSMO2UserBLL.cancelSendWW(lotnos, opcode, AppConfig.AppConnectString);
  2135. ICSBaseSimpleCode.AppshowMessageBox(0, "委外撤销成功");
  2136. //ICSBaseSimpleCode.AppshowMessageBox(0, "取消成功");
  2137. simpleSearch_Click(null, null);
  2138. }
  2139. catch (Exception ex)
  2140. {
  2141. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  2142. }
  2143. btnFalsh_Click(null, null);
  2144. }
  2145. #endregion
  2146. #region 创建ERP PR
  2147. private void BtnCreatePR_Click(object sender, EventArgs e)
  2148. {
  2149. try
  2150. {
  2151. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定产生委外请购单吗?") != DialogResult.OK)
  2152. {
  2153. return;
  2154. }
  2155. else
  2156. {
  2157. int count = 0;
  2158. for(int i = 0;i< gridView1.RowCount; i++){
  2159. if (gridView1.GetRowCellValue(i, colisSelect).ToString() == "Y") {
  2160. count++;
  2161. }
  2162. }
  2163. if (count <= 0) {
  2164. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  2165. return;
  2166. }
  2167. FormICSVenDorChoose v = new FormICSVenDorChoose();
  2168. if (v.ShowDialog() != DialogResult.OK)
  2169. return;
  2170. string Vencode = v.Vencode;
  2171. string VenNAME = v.VenName;
  2172. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在创建...请稍等...");
  2173. try
  2174. {
  2175. _wait.Show();
  2176. #region 老
  2177. //从配置中获取
  2178. // string _EnumKey = "00010";
  2179. // string sqlcInvCCode = @"SELECT DISTINCT EnumText from Sys_EnumValues WHERE EnumKey='" + _EnumKey + "' ";
  2180. // DataTable dtcInvCCode = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqlcInvCCode).Tables[0];
  2181. // string _cInvCCode = string.Empty;
  2182. // if (dtcInvCCode != null && dtcInvCCode.Rows.Count > 0)
  2183. // {
  2184. // _cInvCCode = dtcInvCCode.Rows[0][0].ToString();
  2185. // }
  2186. // List<PU_AppVouchs> contextsWWList = new List<PU_AppVouchs>();
  2187. // List<PU_AppVouch> listcontextWW = new List<PU_AppVouch>();
  2188. // List<string> de = new List<string>();
  2189. // PU_AppVouch contextWW = new PU_AppVouch();
  2190. // contextWW.UserCode = AppConfig.UserCode;
  2191. // contextWW.UserName = AppConfig.UserName;
  2192. // contextWW.TargetAccount = ConfigurationManager.AppSettings["TargetAccountU8"];
  2193. // string sqladdress = "select '['+DBIPADDRESS+']'+'.'+DBNAME as address from Sys_DataBase where dbsourcename='ERP'";
  2194. // string ipaddress = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqladdress).Tables[0].Rows[0]["address"].ToString();
  2195. // for (int i = 0; i < gridView1.RowCount; i++) {
  2196. // if (gridView1.GetRowCellValue(i, colisSelect).ToString() == "Y") {
  2197. // string lotNO = gridView1.GetRowCellValue(i, colLOTNO).ToString();
  2198. // string MOCode = gridView1.GetRowCellValue(i, moCode).ToString();
  2199. // string MOSEQ = gridView1.GetRowCellValue(i, colMOSEQ).ToString();
  2200. // string MCODE = gridView1.GetRowCellValue(i, itemCode).ToString();
  2201. // string opcode = gridView1.GetRowCellValue(i, opCode).ToString();
  2202. // string sql = @"SELECT DISTINCT PRLineID from ICSMO2User WHERE MOCODE='" + MOCode + "' AND LOTNO='" + lotNO + "' AND EATTRIBUTE1=1 and opcode='" + opcode + "' and prlineid is not null ";
  2203. // DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  2204. // if (dt.Rows.Count > 0) {
  2205. // _wait.Close();
  2206. // ICSBaseSimpleCode.AppshowMessageBox("追踪单:" + lotNO + " 工序:" + opcode + "已产生委外请购单!");
  2207. // return;
  2208. // }
  2209. // sql = @"SELECT * FROM ICSMO2USER WHERE MOCODE='"+ MOCode + "' and lotno='"+lotNO+ "' and EATTRIBUTE1=1 and opcode='" + opcode + "'";
  2210. // dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  2211. // if (dt.Rows.Count<=0)
  2212. // {
  2213. // _wait.Close();
  2214. // ICSBaseSimpleCode.AppshowMessageBox("追踪单:" + lotNO + " 工序:" + opcode + "不是委外工序或未派工无法生成委外请购单!");
  2215. // return;
  2216. // }
  2217. // //查询工单部门
  2218. // string sqldepart = @"SELECT MDeptCode,b.closetime
  2219. // FROM "+ ipaddress+ @".dbo.mom_order a
  2220. // INNER JOIN " + ipaddress + @".dbo.mom_orderdetail b ON a.MoId = b.MoId
  2221. // WHERE a.MoCode = '" + MOCode + "' and b.SortSeq='" + MOSEQ + "'";
  2222. // DataTable depart = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqldepart).Tables[0];
  2223. // if (depart.Rows.Count > 0)
  2224. // {
  2225. // if (!de.Contains(depart.Rows[0]["MDeptCode"].ToString())) {
  2226. // de.Add(depart.Rows[0]["MDeptCode"].ToString());
  2227. // }
  2228. // if (!String.IsNullOrEmpty(depart.Rows[0]["closetime"].ToString()))
  2229. // {
  2230. // ICSBaseSimpleCode.AppshowMessageBox("工单号:" + MOCode + ",工单行:" + MOSEQ + "已关闭!");
  2231. // _wait.Close();
  2232. // return;
  2233. // }
  2234. // }
  2235. // if (de.Count == 0) {
  2236. // ICSBaseSimpleCode.AppshowMessageBox("获取工单部门失败!");
  2237. // return;
  2238. // }
  2239. // if (de.Count > 1) {
  2240. // ICSBaseSimpleCode.AppshowMessageBox("请选择相同部门的条码!");
  2241. // return;
  2242. // }
  2243. // contextWW.cDepCode = depart.Rows[0]["MDeptCode"].ToString();
  2244. // #region
  2245. // string sqlQty = @"
  2246. //SELECT A.MOCODE, B.MCODE AS MCODE,dd.INVNAME, A.OPCODE, D.OPDESC AS PRLineID, SUM (B.LOTQTY) AS PRQty,a.lotno,a.MOSEQ,
  2247. //ISNULL(MIN(A.StartPlanDate), GETDATE()) StartPlanDate, ISNULL(MAX(A.EndPlanDate), GETDATE()) EndPlanDate
  2248. //FROM ICSMO2User A LEFT JOIN ICSITEMLot B ON A.LOTNO = B.LotNO LEFT JOIN ICSOP D ON D.OPCODE = A.OPCODE
  2249. //LEFT JOIN ICSINVENTORY dd ON b.MCODE =dd.INVCODE
  2250. //WHERE A.MOCODE = '" + MOCode + "' AND B.MCODE = '" + MCODE + "' AND A.MOSEQ = '" + MOSEQ + @"' AND A.EATTRIBUTE1 = 1 and a.lotno='" + lotNO + @"' and a.opcode='" + opcode + @"'
  2251. //AND (A.PRLineID IS NULL OR A.PRLineID = '') GROUP BY A.MOCODE, dd.INVNAME, A.OPCODE, B.MCODE, D.OPDESC,a.lotno,a.MOSEQ ";//UPDATE BY SUMMER 2020.06.17
  2252. // #endregion
  2253. // DataTable dtQty = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqlQty).Tables[0];
  2254. // if (dtQty != null && dtQty.Rows.Count > 0)
  2255. // {
  2256. // foreach (DataRow _dr in dtQty.Rows)
  2257. // {
  2258. // PU_AppVouchs contextsWW = new PU_AppVouchs();
  2259. // contextsWW.cInvCCode = _cInvCCode;//物料大类
  2260. // contextsWW.cInvCode = _dr["MCODE"].ToString();//料号
  2261. // contextsWW.cInvName = _dr["INVNAME"].ToString();//料号名称
  2262. // contextsWW.OPCode = _dr["OPCODE"].ToString();//工序
  2263. // contextsWW.iQuantity = Decimal.Parse(_dr["PRQty"].ToString());
  2264. // contextsWW.iNum = Convert.ToInt32(MOSEQ);// lotinfo.LOTQTY * Convert.ToDecimal(lotinfo.EATTRIBUTE3);
  2265. // //contextsWW.cBatch = lotinfo.VenderLotNO;
  2266. // contextsWW.MOCode = _dr["MOCODE"].ToString();//工单号
  2267. // contextsWW.PRLine = _dr["PRLineID"].ToString();
  2268. // contextsWW.dArriveDate = Convert.ToDateTime(_dr["StartPlanDate"].ToString()).ToShortDateString();
  2269. // contextsWW.dRequirDate = Convert.ToDateTime(_dr["EndPlanDate"].ToString()).ToShortDateString();
  2270. // //contextsWW.LotNo = _dr["LOTNO"].ToString();//产品产品跟踪单号 2020.7.13 delete by summer
  2271. // contextsWW.LotNo = lotNO;//产品产品跟踪单号
  2272. // contextsWWList.Add(contextsWW);
  2273. // }
  2274. // }
  2275. // }
  2276. // }
  2277. // contextWW.list = contextsWWList;
  2278. // listcontextWW.Add(contextWW);
  2279. // string WWPR = JsonConvert.SerializeObject(listcontextWW);
  2280. // string iresultMO = HttpPost(DataCollectWW, WWPR);
  2281. // U8Result INVINResultMO = new U8Result();
  2282. // INVINResultMO = JsonConvert.DeserializeObject<U8Result>(iresultMO);
  2283. // StringBuilder str = new StringBuilder();
  2284. // str.AppendLine("创建U8委外请购单接口:" + WWPR);
  2285. // str.AppendLine("接口返回结果:" + INVINResultMO.code);
  2286. // str.AppendLine("接口返回数据:" + INVINResultMO.msg);
  2287. // ICSMO2UserDAL.WriteLogFile(str.ToString(), "创建U8委外请购单接口");
  2288. // if (INVINResultMO.code != "200")
  2289. // {
  2290. // _wait.Close();
  2291. // ICSBaseSimpleCode.AppshowMessageBox(INVINResultMO.msg);
  2292. // return;
  2293. // }
  2294. // List<PU_AppVouchs> _list = new List<PU_AppVouchs>();
  2295. // if (!string.IsNullOrWhiteSpace(INVINResultMO.msg))
  2296. // {
  2297. // _list = JsonConvert.DeserializeObject<List<PU_AppVouchs>>(INVINResultMO.msg.ToString());
  2298. // }
  2299. // else
  2300. // {
  2301. // _wait.Close();
  2302. // throw new Exception("未获取到请购单数据!");
  2303. // }
  2304. // //U8返回的PR单行ID回写ICSMO2User表中PRLineID
  2305. // foreach (var item in _list)
  2306. // {
  2307. // string UpdateSql = @"UPDATE ICSMO2User SET PRLineID='" + item.PRLine + "' WHERE MOCODE = '" + item.MOCode + "' AND OPCODE = '" + item.OPCode + "' AND lotno = '" +item.LotNo+ "' AND EATTRIBUTE1 = 1 and moseq='"+item.iNum+"'";//AND LOTNO = '" + item.LotNo + "' "; //update by summer 2020.07.13
  2308. // UpdateSql = string.Format(UpdateSql);
  2309. // DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, UpdateSql);
  2310. // }
  2311. #endregion
  2312. List<DMaster> masters = new List<DMaster>();
  2313. DMaster master = new DMaster();
  2314. master.source_no = AppConfig.GetGuid();
  2315. master.pmdl001 = "0";
  2316. master.pmdldocno = PoDocNo;
  2317. master.pmdl002 = AppConfig.UserCode;
  2318. master.pmdl003 = "10000";
  2319. master.pmdl004 = Vencode;//供应商编号
  2320. master.pmdl005 = "2";
  2321. master.pmdl007 = "4";
  2322. master.pmdl008 = "";
  2323. master.pmdl009 = "";
  2324. master.pmdl010 = "";
  2325. master.pmdl011 = "";
  2326. master.pmdl012 = "";
  2327. master.pmdl013 = "";
  2328. master.pmdl015 = "";
  2329. master.pmdl016 = "";
  2330. master.pmdl017 = "";
  2331. master.pmdl033 = "";
  2332. master.pmdl040 = "0";
  2333. master.pmdl041 = "0";
  2334. master.pmdl042 = "0";
  2335. master.pmdl054 = "";
  2336. master.detail = new List<DDetail>();
  2337. masters.Add(master);
  2338. count =1;
  2339. Dictionary<string, string> opcodes = new Dictionary<string, string>();
  2340. for (int i = 0; i < gridView1.RowCount; i++)
  2341. {
  2342. if (gridView1.GetRowCellValue(i, colisSelect).ToString() == "Y")
  2343. {
  2344. string lotNO = gridView1.GetRowCellValue(i, colLOTNO).ToString();
  2345. string MOCode = gridView1.GetRowCellValue(i, moCode).ToString();
  2346. string MOSEQ = gridView1.GetRowCellValue(i, colMOSEQ).ToString();
  2347. string MCODE = gridView1.GetRowCellValue(i, itemCode).ToString();
  2348. string opcode = gridView1.GetRowCellValue(i, opCode).ToString();
  2349. string opseq= gridView1.GetRowCellValue(i, colopSeq).ToString();
  2350. string lotqty= gridView1.GetRowCellValue(i, gridColumn8).ToString();
  2351. string sql = @"SELECT DISTINCT PRLineID from ICSMO2User WHERE MOCODE='" + MOCode + "' AND LOTNO='" + lotNO + "' AND EATTRIBUTE1=1 and opcode='" + opcode + "' and prlineid is not null ";
  2352. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  2353. if (dt.Rows.Count > 0)
  2354. {
  2355. _wait.Close();
  2356. ICSBaseSimpleCode.AppshowMessageBox("追踪单:" + lotNO + " 工序:" + opcode + "已产生委外请购单!");
  2357. return;
  2358. }
  2359. sql = @"SELECT * FROM ICSMO2USER WHERE MOCODE='" + MOCode + "' and lotno='" + lotNO + "' and EATTRIBUTE1=1 and opcode='" + opcode + "'";
  2360. dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  2361. if (dt.Rows.Count <= 0)
  2362. {
  2363. _wait.Close();
  2364. ICSBaseSimpleCode.AppshowMessageBox("追踪单:" + lotNO + " 工序:" + opcode + "不是委外工序或未派工无法生成委外请购单!");
  2365. return;
  2366. }
  2367. DDetail detail = new DDetail();
  2368. detail.pmdn001 = MCODE; ;
  2369. detail.pmdn004 = opcode.Substring(0,opcode.LastIndexOf('-'));
  2370. detail.pmdn005 = opseq;
  2371. detail.pmdn006 = "";
  2372. detail.pmdn007 = lotqty;
  2373. detail.pmdn010 = "";
  2374. detail.pmdn011 = lotqty;
  2375. detail.pmdn012 = DateTime.Now.ToString("yyyy-MM-dd");
  2376. detail.pmdn015 = "0";
  2377. detail.pmdn016 = "";
  2378. detail.pmdn017 = "";
  2379. detail.pmdp003 = MOCode;
  2380. detail.pmdp004 = "0";
  2381. detail.pmdp005 = "0";
  2382. detail.pmdp006 = "0";
  2383. detail.pmdn050 = lotNO;
  2384. if(AppConfig.GetDataBaseNameByConnectString(AppConfig.AppConnectString)== "ICSMES_GT_DJ")
  2385. detail.pmdn028 = "HG01";
  2386. else
  2387. detail.pmdn028 = "HH01";
  2388. detail.source_seq = count.ToString();
  2389. detail.pmdnseq = count.ToString();
  2390. opcodes.Add(lotNO+ detail.pmdn004 + detail.pmdn005, opcode);
  2391. //var masterIn = masters.Where(a => a.pmdl008 == MOCode).FirstOrDefault();
  2392. //if (masterIn == null)
  2393. //{
  2394. // masterIn = master;
  2395. // masters.Add(masterIn);
  2396. //}
  2397. //if (masterIn.detail == null)
  2398. //{
  2399. // detail.pmdnseq = "1";
  2400. // detail.source_seq = "1";
  2401. // masterIn.detail = new List<DDetail>();
  2402. //}
  2403. //else
  2404. //{
  2405. // detail.pmdnseq = (masterIn.detail.Max(a => Convert.ToDecimal(a.pmdnseq)) + 1).ToString();
  2406. // detail.source_seq = detail.pmdnseq;
  2407. //}
  2408. //masterIn.detail.Add(detail);
  2409. master.detail.Add(detail);
  2410. count++;
  2411. }
  2412. }
  2413. if (masters.Count <= 0)
  2414. throw new Exception("请选择要委外的数据!");
  2415. OutSourceDto dto = new OutSourceDto();
  2416. dto.key = PoKey;
  2417. dto.type = "sync";
  2418. DHost host = new DHost();
  2419. host.prod = "APP";
  2420. host.lang = "zh_CN";
  2421. host.timestamp = DateTime.Now.ToString("yyyyMMddHHmmssfff");
  2422. host.acct = "tiptop";
  2423. host.ip = WebHelper.GetIp();//ip地址
  2424. DService service = new DService();
  2425. service.prod = "T100";
  2426. service.name = "CPurchaseOrderCreate";
  2427. service.ip = "172.16.11.152";
  2428. service.id = "topprd";
  2429. Datakey datakey = new Datakey();
  2430. datakey.CompanyId = CompanyId;
  2431. datakey.EntId = EntId;
  2432. Payload pay = new Payload();
  2433. Std_data std = new Std_data();
  2434. DParameter param = new DParameter();
  2435. param.master = masters;
  2436. std.parameter = param;
  2437. pay.std_data = std;
  2438. dto.datakey = datakey;
  2439. dto.host = host;
  2440. dto.service = service;
  2441. dto.payload = pay;
  2442. DReturn rtn = WebHelper.HttpPost<DReturn>(DjAddress, JsonConvert.SerializeObject(dto));
  2443. var errormes = "";
  2444. if (rtn.payload.std_data.execution.code != "0")
  2445. {
  2446. errormes = string.Join("\r\n", rtn.payload.std_data.parameter.fail_return.Select(a => a.error_msg).ToList());
  2447. }
  2448. ICSMO2UserDAL.WriteLogFile("Params:"+ JsonConvert.SerializeObject(dto)+"\r\n"+"returns:"+ JsonConvert.SerializeObject(rtn), "鼎捷委外采购单");
  2449. if (!string.IsNullOrEmpty(errormes))
  2450. throw new Exception(errormes);
  2451. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  2452. db.Connection.Open();
  2453. db.Transaction = db.Connection.BeginTransaction();
  2454. try
  2455. {
  2456. foreach (var sucess in rtn.payload.std_data.parameter.success_return)
  2457. {
  2458. var poCode = sucess.success_msg;//采购单号
  2459. var sourceno = sucess.source_no;//对应的mes单号 唯一需要加上传入的行号
  2460. List<ICSPO_PoMain> pos = new List<ICSPO_PoMain>();
  2461. dto.payload.std_data.parameter.master.Where(a => a.source_no == sourceno).ToList().ForEach(a =>
  2462. {
  2463. a.detail.ForEach(b =>
  2464. {
  2465. ICSPO_PoMain po = new ICSPO_PoMain();
  2466. po.POCode = poCode;
  2467. po.PORow = b.pmdnseq;
  2468. var ops = opcodes.Where(c => c.Key == b.pmdn050 + b.pmdn004 + b.pmdn005).FirstOrDefault();
  2469. po.InvCode = b.pmdn001 + "_" + (ops.Value==null?(b.pmdn004+"-"+b.pmdn005):ops.Value);
  2470. po.PODate = DateTime.Now;
  2471. po.VenCode =Vencode;
  2472. po.VenName = VenNAME;
  2473. po.POType = "采购";
  2474. po.ProjectType = "工序委外采购";
  2475. po.Price = "0";
  2476. po.Status = '1';
  2477. po.CreatePerson = AppConfig.UserCode;
  2478. po.Quantity =Convert.ToDecimal(b.pmdn007);
  2479. po.ISUrgent = "";
  2480. po.ServerModel = "BS";
  2481. po.Free1 =po.POCode+"-"+po.PORow;
  2482. po.Free5 = a.source_no + "-" + b.source_seq;
  2483. po.WorkPoint = AppConfig.WorkPointCode;
  2484. po.MUSERName = AppConfig.UserName;
  2485. po.MTIME = DateTime.Now;
  2486. var newPo = db.ICSPO_PoMain.Where(c => c.POCode ==po.POCode && c.PORow == po.PORow).FirstOrDefault();
  2487. if (newPo != null)
  2488. {
  2489. throw new Exception("采购单号:" + po.POCode + ",行号:" + po.PORow + "已存在!");
  2490. }
  2491. newPo = po;
  2492. db.ICSPO_PoMain.InsertOnSubmit(newPo);
  2493. db.SubmitChanges();
  2494. var op = opcodes.Where(c => c.Key == b.pmdn050 + b.pmdn004 + b.pmdn005).FirstOrDefault();
  2495. var mo2=db.ICSMO2User.Where(mo2user => mo2user.LOTNO == b.pmdn050 && mo2user.OPCODE == op.Value).FirstOrDefault();
  2496. if (mo2 == null)
  2497. throw new Exception("获取派工记录失败!");
  2498. mo2.PRLineID= po.POCode + "-" + po.PORow;
  2499. var inv = db.ICSINVENTORY.Where(i => i.INVCODE == po.InvCode).FirstOrDefault();
  2500. if (inv == null)
  2501. {
  2502. var oldInv = db.ICSINVENTORY.Where(i => i.INVCODE == b.pmdn001).FirstOrDefault();
  2503. if (oldInv == null)
  2504. throw new Exception("获取物料信息:"+b.pmdn001+"失败!");
  2505. inv = JsonConvert.DeserializeObject<ICSINVENTORY>(JsonConvert.SerializeObject(oldInv));
  2506. inv.ID = AppConfig.GetGuid();
  2507. inv.INVCODE = po.InvCode;
  2508. inv.MUSER = AppConfig.UserCode;
  2509. inv.MUSERName = AppConfig.UserName;
  2510. inv.MTIME = DateTime.Now;
  2511. db.ICSINVENTORY.InsertOnSubmit(inv);
  2512. }
  2513. });
  2514. });
  2515. }
  2516. db.SubmitChanges();
  2517. db.Transaction.Commit();
  2518. }
  2519. catch (Exception ex)
  2520. {
  2521. db.Transaction.Rollback();
  2522. throw ex;
  2523. }
  2524. _wait.Close();
  2525. ICSBaseSimpleCode.AppshowMessageBox("产生委外采购单成功!");
  2526. simpleSearch_Click(null, null);
  2527. }
  2528. catch (Exception _ex)
  2529. {
  2530. _wait.Close();
  2531. ICSBaseSimpleCode.AppshowMessageBox(_ex.Message);
  2532. }
  2533. }
  2534. }
  2535. catch (Exception ex)
  2536. {
  2537. throw new Exception(ex.ToString());
  2538. }
  2539. }
  2540. public static string HttpPost(string url, string body)
  2541. {
  2542. try
  2543. {
  2544. Encoding encoding = Encoding.UTF8;
  2545. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  2546. request.Method = "POST";
  2547. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  2548. request.ContentType = "application/json; charset=utf-8";
  2549. byte[] buffer = encoding.GetBytes(body);
  2550. request.ContentLength = buffer.Length;
  2551. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  2552. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  2553. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  2554. {
  2555. return reader.ReadToEnd();
  2556. }
  2557. }
  2558. catch (WebException ex)
  2559. {
  2560. var res = (HttpWebResponse)ex.Response;
  2561. StringBuilder sb = new StringBuilder();
  2562. StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
  2563. sb.Append(sr.ReadToEnd());
  2564. throw new Exception(sb.ToString());
  2565. }
  2566. }
  2567. #endregion
  2568. private void txtOpDesc_EditValueChanged(object sender, EventArgs e)
  2569. {
  2570. //var o = txtOpDesc.Properties.GetRowByKeyValue(txtOpDesc.EditValue);
  2571. //var o = txtOpDesc.Properties.GetRowByKeyValue(txtOpDesc.EditValue);
  2572. //if (o is DataRowView)
  2573. //{
  2574. // DataRowView RowView = o as DataRowView;
  2575. // if (RowView != null && RowView.DataView.Count > 0)
  2576. // {
  2577. // txtOpDesc.Text = RowView.Row["工序编码"].ToString();
  2578. // //txtOpName.Text = RowView.Row["工序名称"].ToString();
  2579. // }
  2580. //}
  2581. }
  2582. private void BtnWW_Click(object sender, EventArgs e)
  2583. {
  2584. try
  2585. {
  2586. DataView dv = dtLotno.DefaultView;
  2587. //dv.RowFilter = "是否已派工='是'";
  2588. dv.RowFilter = "已委外='True'";
  2589. gridControl1.DataSource = dv;
  2590. gridView1.BestFitColumns();
  2591. }
  2592. catch (Exception EX)
  2593. {
  2594. ICSBaseSimpleCode.AppshowMessageBox("请先查询数据!");
  2595. }
  2596. }
  2597. //键盘回车键按下
  2598. private void txtLotNo_KeyPress(object sender, KeyPressEventArgs e)
  2599. {
  2600. if (e.KeyChar == 13)
  2601. {
  2602. try
  2603. {
  2604. string erpconstr = GetERPConn();
  2605. string sql = string.Format(@"select * from (
  2606. SELECT DISTINCT
  2607. '' AS isSelect,
  2608. --A.ProjectCode AS ,
  2609. E.ROUTECODE AS routeCode,
  2610. A.MOCODE AS ,a.MOSEQ ,
  2611. A.ITEMCODE AS ,
  2612. a.MOVER,
  2613. B.LOTNO AS ,
  2614. C.INVNAME AS ,
  2615. --c.INVShelfLife as ,
  2616. f.OPcode AS ,
  2617. f.OPdesc AS ,
  2618. e.OPSEQ AS ,
  2619. A.MDeptCode AS ,
  2620. '' as pictureSee,
  2621. --p.STIME AS ,
  2622. 0 AS ,
  2623. --0908
  2624. A.MOPLANSTARTDATE AS ,
  2625. A.MOPLANENDDATE AS ,
  2626. CAST(case when ISNULL(icsmo2user.SEGCODE,'1')='' THEN '0' ELSE ISNULL(icsmo2user.SEGCODE,'0') END AS Bit) AS ISAGV,
  2627. cast(b.lotqty as int) AS ,
  2628. --b.lotqty AS ,
  2629. --CAST(CASE WHEN icsmo2user.OPCODE IS NULL or icsmo2user.EATTRIBUTE1!='1' THEN '0' ELSE '1' END AS BIT) AS ,
  2630. CAST(CASE WHEN (icsmo2user.OPCODE IS NOT NULL or icsmo2user.EATTRIBUTE1='1' ) THEN '1' ELSE '0' END AS BIT) AS ,
  2631. CAST(CASE WHEN icsmo2user.EATTRIBUTE1 ='1' THEN '1' ELSE '0' END AS BIT) AS ,
  2632. case
  2633. when i.ACTIONRESULT = 'COLLECT_BEGIN' then ''
  2634. when icsmo2user.OPCODE is null then ''
  2635. when i.ACTIONRESULT IS NULL THEN ''
  2636. when i.ACTIONRESULT = 'COLLECT_END' and g.Result is null and ncr.ID is not null then ''
  2637. when i.ACTIONRESULT = 'COLLECT_END' and g.Result is null and ncr.ID is null then ''
  2638. when i.ACTIONRESULT = 'COLLECT_END' and g.Result = '' then ''
  2639. wheN i.ACTIONRESULT = 'COLLECT_END' and g.Result = '' then ''
  2640. end as status,
  2641. icsmo2user.PrlineID as prline,
  2642. po.pocode
  2643. FROM
  2644. ICSMO A
  2645. INNER JOIN ICSITEMLot B ON B.TransNO = A.MOCODE AND a.MOSEQ=b.TransLine-- B.MCODE = A.MOCODE -- ICSMO2Lot
  2646. -- left join Base_Inventory c on c.ItemCode = A.ITEMCODE
  2647. LEFT JOIN ICSINVENTORY c ON c.INVCODE = A.ITEMCODE
  2648. inner JOIN ICSITEMROUTE2OPLot e ON e.LotNo = b.LotNO
  2649. LEFT JOIN ICSOP f ON f.opcode = e.OPCODE
  2650. -- LEFT JOIN ICSEQPSTPEMODEL p ON p.ItemCode = a.ItemCode
  2651. -- AND p.OPCODE = f.opcode
  2652. -- AND p.EQPCODE = e.MainResources
  2653. -- AND p.ISREF = '是'
  2654. LEFT JOIN icsmo2user ON icsmo2user.lotno = b.LOTNO
  2655. AND icsmo2user.OPCODE = f.opcode
  2656. left join ICSLOTONWIP i on i.lotno=b.lotno and i.opcode=f.OPcode
  2657. left join ICSLOTONWIPCheck g on g.ONWIPID=i.id
  2658. left join ICSPO_PoMain po on po.free1=icsmo2user.prlineid
  2659. --left join {0}.dbo.PU_AppVouchs u on u.autoid=icsmo2user.prlineid
  2660. --left join {0}.dbo.PU_AppVouch v on v.id=u.id
  2661. left join ICSNCRDoc ncr on ncr.LOTNO=i.LotNO and ncr.OPCode=i.OPCODE and ncr.ErrorType=''
  2662. )a
  2663. where 1=1 ", erpconstr);
  2664. string sqlwhere = "";
  2665. if (txtMoLotCode.Text != "")
  2666. {
  2667. sqlwhere += string.Format(" and A.MOVER like '%{0}%'", txtMoLotCode.Text);
  2668. }
  2669. if (txtMOCODE.Text != "")
  2670. {
  2671. sqlwhere += string.Format(" and A.工单号 like '%{0}%'", txtMOCODE.Text);
  2672. }
  2673. if (txtLotNo.Text != "")
  2674. {
  2675. sqlwhere += string.Format(" AND A.产品跟踪单号 like '%{0}%'", txtLotNo.Text);
  2676. }
  2677. if (txtITEMCODE.Text != "")
  2678. {
  2679. sqlwhere += string.Format(" AND A.料号 LIKE '%{0}%'", txtITEMCODE.Text);
  2680. }
  2681. if (txtItemName.Text != "")
  2682. {
  2683. sqlwhere += string.Format(" and A.料品名称 LIKE '%{0}%'", txtItemName.Text);
  2684. }
  2685. if (txtDepart.Text != "")
  2686. {
  2687. sqlwhere += string.Format("and A.生产部门 like '%{0}%'", txtDepart.Text);
  2688. }
  2689. if (txtOpDesc.Text != "")
  2690. {
  2691. sqlwhere += string.Format(" and A.工序编码 like '%{0}%' ", txtOpDesc.Text);
  2692. }
  2693. //if (textItemStd.Text != "")
  2694. //{
  2695. // sqlwhere += string.Format(" and c.INVSTD like '%{0}%'", textItemStd.Text);
  2696. //}
  2697. //if (dateTimePicker1.Checked)
  2698. //{
  2699. // sqlwhere += string.Format(" AND Convert(varchar(12),icsmo2user.MTIME,23) between '{0}' AND '{1}'", dateTimePicker1.Value.ToString("YYYY-MM-DD"), dateTimePicker2.Value.ToString("YYYY-MM-DD"));
  2700. //}
  2701. sql += sqlwhere + "order by a.工序次序";
  2702. DataTable lotMessage = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  2703. dtLotno = lotMessage;
  2704. gridControl1.DataSource = lotMessage;
  2705. gridView1.BestFitColumns();
  2706. LoadGrd();
  2707. }
  2708. catch (Exception ex)
  2709. {
  2710. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  2711. }
  2712. }
  2713. }
  2714. private void groupControl4_Paint(object sender, PaintEventArgs e)
  2715. {
  2716. }
  2717. // repositoryItemGridLookUpEdit1
  2718. private void repositoryItemButtonEdit1_EditValueChanged(object sender, EventArgs e)
  2719. {
  2720. ButtonEdit btn = (ButtonEdit)sender;
  2721. string USERCODEs = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colUSERCODE).ToString();
  2722. string sql = @"select a.EQPCode as [设备代码],a.EQPName as [设备名称],Type as [设备类型] from dbo.ICSEquipment a with(nolock)
  2723. left join ICSSkillMatrix b on b.equipmentType=a.EQPCode
  2724. where b.WorkNo='" + USERCODEs + "'";
  2725. sql = string.Format(sql);
  2726. data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  2727. if (data != null)
  2728. {
  2729. int rows = data.Rows.Count;
  2730. repositoryItemGridLookUpEdit2.ValueMember = "设备代码";
  2731. repositoryItemGridLookUpEdit2.DisplayMember = "设备代码";
  2732. repositoryItemGridLookUpEdit2.DataSource = data;
  2733. repositoryItemGridLookUpEdit2.NullText = "";//空时的值
  2734. //repositoryItemGridLookUpEdit2.DropDownRows = 10;//下拉框行数
  2735. repositoryItemGridLookUpEdit2.ImmediatePopup = true;//输入值是否马上弹出窗体
  2736. repositoryItemGridLookUpEdit2.ValidateOnEnterKey = true;//回车确认
  2737. //repositoryItemGridLookUpEdit2.SearchMode = DevExpress.XtraEditors.Controls.SearchMode.AutoFilter;//自动过滤掉不需要显示的数据,可以根据需要变化
  2738. /*repositoryItemGridLookUpEdit2.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;*///要使用户可以输入,这里须设为Standard
  2739. repositoryItemGridLookUpEdit2.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  2740. //自适应宽度
  2741. repositoryItemGridLookUpEdit2.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  2742. }
  2743. }
  2744. private void txtOpDesc_EditValueChanged_1(object sender, EventArgs e)
  2745. {
  2746. }
  2747. private string GetERPConn() {
  2748. string sql = "select dbipaddress,dbname from Sys_DataBase where dbsourcename='ERP'";
  2749. DataTable table = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  2750. string dbip = table.Rows[0]["dbipaddress"].ToString();
  2751. string dbname= table.Rows[0]["dbname"].ToString();
  2752. string constr="["+dbip+"].["+dbname+"]";
  2753. return constr;
  2754. }
  2755. private void grdDetail_DataSourceChanged(object sender, EventArgs e)
  2756. {
  2757. grvDetail.BestFitColumns();
  2758. }
  2759. private void InsertPo(List<ICSPO_PoMain> poS, FramDataContext db)
  2760. {
  2761. try
  2762. {
  2763. poS.ForEach(a => {
  2764. var po = db.ICSPO_PoMain.Where(b => b.POCode == a.POCode && b.PORow == a.PORow).FirstOrDefault();
  2765. if (po != null)
  2766. {
  2767. throw new Exception("采购单号:"+po.POCode+",行号:"+po.PORow+"已存在!");
  2768. }
  2769. db.ICSPO_PoMain.InsertOnSubmit(a);
  2770. });
  2771. }
  2772. catch (Exception ex)
  2773. {
  2774. throw ex;
  2775. }
  2776. }
  2777. }
  2778. }