using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Linq; using System.Linq; using System.Drawing; using System.Text; using System.Windows.Forms; using DevExpress.XtraEditors; using DevExpress.XtraGrid.Views.BandedGrid; using DevExpress.XtraGrid.Columns; using DevExpress.XtraGrid; using System.IO; using System.Threading; using ICSSoft.Base.Language.Tool; using ICSSoft.Base.Config.AppConfig; using ICSSoft.Base.UserControl.MessageControl; using ICSSoft.Base.Config.DBHelper; using ICSSoft.Base.Report.Filter; using ICSSoft.Base.UserControl.FormControl; using ICSSoft.Base.Report.GridReport; using ICSSoft.Base.ReferForm.AppReferForm; using ICSSoft.Frame.Data.BLL; using Newtonsoft.Json; using System.Net; using System.Configuration; using ICSSoft.Entity.PU_AppVouch; using ICSSoft.Frame.Data.Entity.WWModel; using ICSSoft.Frame.Data.DAL; using ICSSoft.Frame.Data.Entity; using ICSSoft.Base.Lable.PrintTool; namespace ICSSoft.Frame.APP { public partial class FormICSMO : DevExpress.XtraEditors.XtraForm { private string sqltxt = ""; private string sqlconn = ""; String guid = AppConfig.GetGuid(); private DataTable dataSource = null; static string APIURL = System.Configuration.ConfigurationSettings.AppSettings["APIURL"].ToString(); static string DataCollectWW = APIURL + "APICreatePR"; //static string DataCollectWW = "http://localhost:51182/api/"+ "APICreatePR"; private DataSet ds = new DataSet(); private DataTable body = null; #region 构造函数 public FormICSMO() { InitializeComponent(); this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height); this.WindowState = FormWindowState.Maximized; foreach (DevExpress.XtraGrid.Columns.GridColumn col in grvDetail.Columns) { if (col.Name == "picturesee") { col.OptionsColumn.ReadOnly = false; } else col.OptionsColumn.ReadOnly = true; col.OptionsColumn.AllowEdit = true; if (col.Name == "colisSelect") col.OptionsColumn.AllowEdit = false; // col.OptionsColumn.ReadOnly = true; } } #endregion #region 操作权限 public DataTable RightOfExute() { DataTable rData = new DataTable(); rData.Columns.Add("BtnName"); rData.Columns.Add("ActionName"); //查看权限(必须有) DataRow seeRow = rData.NewRow(); seeRow["BtnName"] = "see"; seeRow["ActionName"] = "查看"; rData.Rows.Add(seeRow); List ControlList = new List(); ControlList.Add(btnCreatePR); ControlList.Add(btnModify); ControlList.Add(btnDel); ControlList.Add(btnOutPut); ControlList.Add(BtnCancelCloseMO); ControlList.Add(btnCancelAll); ControlList.Add(btnRefresh); ControlList.Add(txtsend); ControlList.Add(txtcancelSend); ControlList.Add(btnBatch); ControlList.Add(btnExit); ControlList.Add(txtstop); ControlList.Add(txtcancelStop); ControlList.Add(txtcloseDan); ControlList.Add(btnLot1); ControlList.Add(btnprint); foreach (Control ctr in ControlList) { if (ctr.GetType() == typeof(SimpleButton)) { DataRow dr = rData.NewRow(); dr["BtnName"] = ctr.Name; dr["ActionName"] = ctr.Text; rData.Rows.Add(dr); } } rData.AcceptChanges(); return rData; } public DataTable RightOfData()// 数据权限 { DataTable rData = new DataTable(); rData.Columns.Add("BodyName"); rData.Columns.Add("ControlName"); rData.Columns.Add("ControlCaption"); rData.AcceptChanges(); return rData; } #endregion #region 退出 private void btnClose_Click(object sender, EventArgs e) { AppConfig.CloseFormShow(this.Text); this.Close(); } private void btnExit_Click(object sender, EventArgs e) { AppConfig.CloseFormShow(this.Text); this.Close(); } #endregion #region 移动窗体 private const int WM_NCHITTEST = 0x84; private const int HTCLIENT = 0x1; private const int HTCAPTION = 0x2; //首先必须了解Windows的消息传递机制,当有鼠标活动消息时, //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION , //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。 //重写窗体,使窗体可以不通过自带标题栏实现移动 protected override void WndProc(ref Message m) { //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息, //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体, //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。 //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。 switch (m.Msg) { case WM_NCHITTEST: base.WndProc(ref m); if ((int)m.Result == HTCLIENT) m.Result = (IntPtr)HTCAPTION; return; } //拦截双击标题栏、移动窗体的系统消息 if (m.Msg != 0xA3) { base.WndProc(ref m); } } #endregion #region 列表 private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e) { if (e.Info.IsRowIndicator && e.RowHandle >= 0) e.Info.DisplayText = (e.RowHandle + 1).ToString(); } #endregion #region 过滤 private string tempTableName = ""; private void btnFilter_Click(object sender, EventArgs e) { FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name)); filter.OldTempTableName = tempTableName; if (filter.ShowDialog() == DialogResult.OK) { DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等..."); try { _wait.Show(); tempTableName = filter.NewTempTableName; sqltxt = filter.SqlText; sqlconn = filter.FilterConnectString; dataSource = filter.FilterData.Tables[0]; grdDetail.DataSource = dataSource; grvDetail.BestFitColumns(); rptPage.RecordNum = dataSource.Rows.Count; rptPage.PageSize = 499; rptPage.PageIndex = 1; rptPage.ReLoad(); rptPage.PageSize = 500; rptPage.PageIndex = 1; rptPage.ReLoad(); _wait.Close(); //_wait.Show(); //ds.Reset(); //dataSource = null; //body = null; //tempTableName = filter.NewTempTableName; //sqltxt = filter.SqlText; //sqlconn = filter.FilterConnectString; //dataSource = filter.FilterData.Tables[0].Copy(); //dataSource.TableName = "Hand"; //ds.Tables.Add(dataSource); //body = ICSMOBLL.GetMOBOM(sqltxt).Copy(); //body.TableName = "Body"; //ds.Tables.Add(body); //DataRelation dr = new DataRelation("子件资料", new DataColumn[] { ds.Tables["Hand"].Columns["MOCODE"], ds.Tables["Hand"].Columns["MOSEQ"] }, new DataColumn[] { ds.Tables["Body"].Columns["MOCODE"], ds.Tables["Body"].Columns["SEQ"] }); //ds.Relations.Add(dr); //grdDetail.DataSource = ds.Tables["Hand"]; //grvDetail.BestFitColumns(); //rptPage.RecordNum = dataSource.Rows.Count; //rptPage.PageSize = 499; //rptPage.PageIndex = 1; //rptPage.ReLoad(); //rptPage.PageSize = 500; //rptPage.PageIndex = 1; ////rptPage.ReLoad(); //_wait.Close(); } catch (Exception ex) { MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); _wait.Close(); } } } #endregion #region 绑定数据源 private void btnConfig_Click(object sender, EventArgs e) { if (AppConfig.UserCode.ToLower() != "demo") { ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!"); return; } FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name); fdata.ShowDialog(); } #endregion #region 分页 private void rptPage_PageIndexChanged(object Sender, EventArgs e) { DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy(); //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count); grdDetail.DataSource = data; } #endregion #region 过滤方法 private void FormContainerManager_FormClosing(object sender, FormClosingEventArgs e) { AppConfig.DropTemTable(tempTableName); } #endregion #region 全选 private void btnSelectAll_Click(object sender, EventArgs e) { grvDetail.PostEditor(); this.Validate(); for (int i = 0; i < grvDetail.RowCount; i++) { grvDetail.SetRowCellValue(i, colisSelect, "Y"); } } #endregion #region 全消 private void btnCancelAll_Click(object sender, EventArgs e) { grvDetail.PostEditor(); this.Validate(); for (int i = 0; i < grvDetail.RowCount; i++) { grvDetail.SetRowCellValue(i, colisSelect, ""); } } #endregion #region 双击 private void grvDetail_DoubleClick(object sender, EventArgs e) { if (grvDetail.FocusedRowHandle < 0) { return; } if (grvDetail.FocusedColumn == colisSelect) { if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "") { grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y"); } else { grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, ""); } } } #endregion #region 批次删除 private void btnDel_Click(object sender, EventArgs e) { #region //SimpleButton btntemp = (SimpleButton)sender; //if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) //{ // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); // return; //} //List moidList = new List(); //for (int i = 0; i < grvDetail.RowCount; i++) //{ // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") // { // string moid; // if (grvDetail.GetRowCellValue(i, colMOTYPE).ToString() == "1") // { // moidList.Add(grvDetail.GetRowCellValue(i, colID).ToString()); // } // else // { // ICSBaseSimpleCode.AppshowMessageBox("非返程工单,不能删除!!!"); // return; // } // } //} //if (moidList.Count == 0 || moidList == null) //{ // ICSBaseSimpleCode.AppshowMessageBox("请选择数据"); // return; //} //if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除工单吗?删除后无法恢复,确定吗?") != DialogResult.OK) //{ // btnCancelAll_Click(sender, e); // return; //} //try //{ // ICSMOBLL.deleteInfo(moidList, AppConfig.AppConnectString); // ICSBaseSimpleCode.AppshowMessageBox("删除成功"); //} //catch (Exception ex) //{ // ICSBaseSimpleCode.AppshowMessageBox(ex.Message); //} //btnRefresh_Click(null, null); #endregion //批次删除 if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确认删除批次信息吗?删除后无法恢复!")==DialogResult.OK) { int count = 0; List list = new List(); for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect) == "Y") { count++; string mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString(); string moseq = grvDetail.GetRowCellValue(i, colMOSEQ).ToString(); string status = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString(); if (ICSMO2LotBLL.IsKG(grvDetail.GetRowCellValue(i, colMOCODE).ToString(), grvDetail.GetRowCellValue(i, colMOSEQ).ToString())) { ICSBaseSimpleCode.AppshowMessageBox("工单: " + grvDetail.GetRowCellValue(i, colMOCODE).ToString() + " 已开工,无法删除批次!"); return; } if (ICSMO2LotBLL.IsPG(grvDetail.GetRowCellValue(i, colMOCODE).ToString(), grvDetail.GetRowCellValue(i, colMOSEQ).ToString())) { ICSBaseSimpleCode.AppshowMessageBox("工单: " + grvDetail.GetRowCellValue(i, colMOCODE).ToString() + " 已派工,请先取消派工!"); return; } ICSMO mo = new ICSMO(); mo.MOCODE = mocode; mo.MOSEQ = moseq; list.Add(mo); } } if (count <= 0) { ICSBaseSimpleCode.AppshowMessageBox("请选择要删除批次信息的工单!"); } try { ICSMOBLL.DeleteLotno(list); ICSBaseSimpleCode.AppshowMessageBox("删除成功!"); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } } #endregion #region 导出 private void btnOutPut_Click(object sender, EventArgs e) { try { FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail); foe.ShowDialog(); } catch (Exception ex) { MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); } //FormOutExcel foe = new FormOutExcel(); //if (foe.ShowDialog() == DialogResult.OK) //{ // try // { // string outtype = foe._OutType; // string exceltype = foe._ExcelType; // string filename = foe._FileName; // string url = foe._Url; // string sheetname = foe._SheetName; // if (outtype.ToLower() == "excel") // { // DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions(); // op.SheetName = sheetname; // grdDetail.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op); // } // else // { // grdDetail.MainView.ExportToPdf(url + "\\" + filename + ".pdf"); // } // MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // } // catch (Exception ex) // { // MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); // } //} } #endregion #region 刷新 private void btnRefresh_Click(object sender, EventArgs e) { DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等..."); try { _wait.Show(); FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false); filter.OldTempTableName = tempTableName; //tempTableName = filter.NewTempTableName; //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0]; if (!string.IsNullOrWhiteSpace(sqlconn)) { dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0]; grdDetail.DataSource = dataSource; grvDetail.BestFitColumns(); rptPage.RecordNum = dataSource.Rows.Count; rptPage.PageIndex = 1; rptPage.ReLoad(); } _wait.Close(); } catch (Exception ex) { MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); _wait.Close(); } } #endregion #region 新增 private void btnCreate_Click(object sender, EventArgs e) { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } try { if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定产生委外请购单吗?") != DialogResult.OK) { return; } else { DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在创建...请稍等..."); try { _wait.Show(); bool isright = true; List listcontextWW = new List(); List contextsWWList = new List(); PU_AppVouch contextWW = new PU_AppVouch(); contextWW.UserCode = AppConfig.UserCode; contextWW.UserName = AppConfig.UserName; //contextWW.TargetAccount =AppConfig.GetDataBaseNameByConnectString(AppConfig.GetDataBaseConnectStringByKey("[]")); contextWW.TargetAccount = ConfigurationManager.AppSettings["TargetAccountU8"]; List dept = new List(); string sqladdress = "select '['+DBIPADDRESS+']'+'.'+DBNAME as address from Sys_DataBase where dbsourcename='ERP'"; string ipaddress = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqladdress).Tables[0].Rows[0]["address"].ToString(); for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { #region MyRegion //工单工号 string MOCode = grvDetail.GetRowCellValue(i, colMOCODE).ToString(); string MCODE = grvDetail.GetRowCellValue(i, colITEMCODE).ToString(); string MOSEQ = grvDetail.GetRowCellValue(i, colMOSEQ).ToString(); string MOSTATUS = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString(); string ItemName = grvDetail.GetRowCellValue(i, colITEMNAME).ToString(); string MOPLANQTY = grvDetail.GetRowCellValue(i, colMOPLANQTY).ToString(); string MOPLANENDDATE = grvDetail.GetRowCellValue(i, colMOPLANENDDATE).ToString(); string deptname = grvDetail.GetRowCellValue(i, colcDepName).ToString(); if (!dept.Contains(deptname)) { dept.Add(deptname); } if (dept.Count > 1) { ICSBaseSimpleCode.AppshowMessageBox("请选择相同部门的工单行!"); return; } string U8Sql = @"SELECT COUNT( c.IssQty) FROM "+ipaddress+ @".dbo.mom_order a INNER JOIN " + ipaddress + @".dbo.mom_orderdetail b ON a.MoId = b.MoId INNER JOIN " + ipaddress + @".dbo.mom_moallocate c ON b.MoDId = c.MoDId WHERE a.MoCode = '" + MOCode + "' and b.SortSeq='" + MOSEQ + "' and c.IssQty>0"; DataTable U8Dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, U8Sql).Tables[0]; if (U8Dt != null && U8Dt.Rows.Count > 0) { string IssQty = U8Dt.Rows[0][0].ToString(); int _IssQty = 0; if (string.IsNullOrWhiteSpace(IssQty)) { _IssQty = Int32.Parse(IssQty); if (_IssQty > 0) { _wait.Close(); ICSBaseSimpleCode.AppshowMessageBox("工单:" + MOCode + ",行号:" + MOSEQ + "在U8中已经领料,不能创建请购单!!!"); return; } } } string u8sql = "select cDefine22 from " + ipaddress + @".dbo.PU_AppVouchs where cDefine22='" + MOCode + "' and cDefine24='"+MOSEQ+"'"; DataTable dt1 = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, u8sql).Tables[0]; if (dt1.Rows.Count > 0) { _wait.Close(); ICSBaseSimpleCode.AppshowMessageBox("工单:" + MOCode + ",行号:" + MOSEQ + "在U8中已创建请购单,请不要重复创建!!"); return; } if (MOSTATUS != "初始") { _wait.Close(); ICSBaseSimpleCode.AppshowMessageBox("工单:" + MOCode + ",行号:" + MOSEQ + "不是初始状态,不能创建请购单!!!"); return; } string lotNO = string.Empty; string sqlCheck = @"SELECT bPurchase FROM ICSINVENTORY WHERE INVCODE='" + MCODE + "' "; DataTable dtCheck = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqlCheck).Tables[0]; string bPurchase = string.Empty; if (dtCheck != null && dtCheck.Rows.Count > 0) { bPurchase = dtCheck.Rows[0]["bPurchase"].ToString(); } if (bPurchase != "1") { _wait.Close(); //throw new Exception("料号:" + MCODE + "的外购标识是false,不允许请购!"); ICSBaseSimpleCode.AppshowMessageBox("料号:" + MCODE + "的外购标识是false,不允许请购!!!"); return; } string sql = @"SELECT DISTINCT MOSTATUS from ICSMO WHERE MOCODE='" + MOCode + "' AND MOSEQ='" + MOSEQ + "' "; DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0]; if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr1 in dt.Rows) { string PRLineID = dr1["MOSTATUS"].ToString(); if (PRLineID == "关闭") { _wait.Close(); ICSBaseSimpleCode.AppshowMessageBox("该工单已经关闭,不能生成请购单!!!"); return; } } } #region // string sqlQty = @" //SELECT A.MOCODE, B.MCODE AS MCODE, C.INVNAME, A.OPCODE, D.OPDESC AS PRLineID, COUNT (B.LOTQTY) AS PRQty, //ISNULL(MIN(A.StartPlanDate), GETDATE()) StartPlanDate, ISNULL(MAX(A.EndPlanDate), GETDATE()) EndPlanDate //FROM ICSMO2User A LEFT JOIN ICSITEMLot B ON A.LOTNO = B.LotNO LEFT JOIN ICSOP D ON D.OPCODE = A.OPCODE //LEFT JOIN ICSINVENTORY C ON B.MCODE = C.INVCODE WHERE A.MOCODE = '" + MOCode + "' AND B.MCODE = '" + MCODE + @"' //AND A.MOSEQ = '" + MOSEQ + @"' AND A.EATTRIBUTE1 = 1 AND (A.PRLineID IS NULL OR A.PRLineID = '') //GROUP BY A.MOCODE, A.OPCODE, B.MCODE, C.INVNAME, D.OPDESC ";//UPDATE BY SUMMER 2020.06.17 #endregion //DataTable dtQty = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqlQty).Tables[0]; string _EnumKey = "00010"; string sqlcInvCCode = @"SELECT DISTINCT EnumText from Sys_EnumValues WHERE EnumKey='" + _EnumKey + "' "; DataTable dtcInvCCode = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqlcInvCCode).Tables[0]; string _cInvCCode = string.Empty; if (dtcInvCCode != null && dtcInvCCode.Rows.Count > 0) { _cInvCCode = dtcInvCCode.Rows[0][0].ToString(); } string sqldepart = @"SELECT MDeptCode FROM " + ipaddress + @".dbo.mom_order a INNER JOIN " + ipaddress + @".dbo.mom_orderdetail b ON a.MoId = b.MoId WHERE a.MoCode = '" + MOCode + "' and b.SortSeq='" + MOSEQ + "'"; DataTable depart = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqldepart).Tables[0]; if (depart.Rows.Count > 0) { contextWW.cDepCode = depart.Rows[0]["MDeptCode"].ToString(); } else contextWW.cDepCode = ""; PU_AppVouchs contextsWW = new PU_AppVouchs(); contextsWW.cInvCCode = _cInvCCode;//物料大类 contextsWW.cInvCode = MCODE;// _dr["MCODE"].ToString();//料号 contextsWW.cInvName = ItemName;//_dr["INVNAME"].ToString();//料号名称 contextsWW.OPCode = null;// _dr["OPCODE"].ToString();//工序 contextsWW.iQuantity = Decimal.Parse(MOPLANQTY);// Decimal.Parse(_dr["PRQty"].ToString()); contextsWW.iNum = Int32.Parse(MOSEQ);// lotinfo.LOTQTY * Convert.ToDecimal(lotinfo.EATTRIBUTE3); contextsWW.MOCode = MOCode;//工单号 contextsWW.PRLine = "";//_dr["PRLineID"].ToString();//工序 contextsWW.dArriveDate = null;// Convert.ToDateTime(_dr["StartPlanDate"].ToString()).ToShortDateString(); if (string.IsNullOrWhiteSpace(MOPLANENDDATE)) { contextsWW.dRequirDate = null; ;// Convert.ToDateTime(_dr["EndPlanDate"].ToString()).ToShortDateString(); } else { contextsWW.dRequirDate = MOPLANENDDATE; } contextsWW.LotNo = "";//产品产品跟踪单号 contextsWWList.Add(contextsWW); #endregion } } contextWW.list = contextsWWList; listcontextWW.Add(contextWW); string WWPR = JsonConvert.SerializeObject(listcontextWW); string iresultMO = HttpPost(DataCollectWW, WWPR); U8Result INVINResultMO = new U8Result(); INVINResultMO = JsonConvert.DeserializeObject(iresultMO); StringBuilder str = new StringBuilder(); str.AppendLine("创建U8请购单接口:" + WWPR); str.AppendLine("接口返回结果:" + INVINResultMO.code); str.AppendLine("接口返回数据:" + INVINResultMO.msg); ICSMO2UserDAL.WriteLogFile(str.ToString(), "创建U8请购单接口"); if (INVINResultMO.code != "200") { _wait.Close(); throw new Exception(INVINResultMO.msg); } List _list = new List(); if (!string.IsNullOrWhiteSpace(INVINResultMO.msg)) { _list = JsonConvert.DeserializeObject>(INVINResultMO.msg.ToString()); } else { _wait.Close(); throw new Exception("未获取到请购单数据!"); } //--MOBIOSVER string code = ""; foreach (PU_AppVouchs vouch in _list) { string sqlUpdate = @"UPDATE ICSMO SET MOSTATUS='关闭',PRDate='"+ DateTime.Now + "' WHERE MOCODE='"+vouch.MOCode+"' AND MOSEQ='"+vouch.iNum+"' "; DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, sqlUpdate); code = vouch.Code; } _wait.Close(); ICSBaseSimpleCode.AppshowMessageBox("产生请购单:"+code+"成功!"); btnRefresh_Click(null, null); } catch (Exception _ex) { _wait.Close(); throw new Exception(_ex.ToString()); } } } catch (Exception ex) { throw new Exception(ex.ToString()); } btnRefresh_Click(null, null); } #endregion public static string HttpPost(string url, string body) { try { Encoding encoding = Encoding.UTF8; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*"; request.ContentType = "application/json; charset=utf-8"; byte[] buffer = encoding.GetBytes(body); request.ContentLength = buffer.Length; request.GetRequestStream().Write(buffer, 0, buffer.Length); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding)) { return reader.ReadToEnd(); } } catch (WebException ex) { var res = (HttpWebResponse)ex.Response; StringBuilder sb = new StringBuilder(); StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8); sb.Append(sr.ReadToEnd()); throw new Exception(sb.ToString()); } } #region 修改 private void btnModify_Click(object sender, EventArgs e) { //已经分批的不能修改途程20190717ZM SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } int count = 0; for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { count++; } } if (count != 1) { ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!"); return; } try { string moid; for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { moid = grvDetail.GetRowCellValue(i, colID).ToString(); bool issplit = ChechIsSplit(moid); if (issplit) { ICSBaseSimpleCode.AppshowMessageBox("已经分批过的不能进行修改"); return; } else { FormICSMOAdd add = new FormICSMOAdd(moid); add.ShowDialog(); } //} //else //{ // ICSBaseSimpleCode.AppshowMessageBox("非返程工单,不能修改!!!"); // return; //} } } btnRefresh_Click(null, null); } catch (Exception ex) { //throw ex; ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion private bool ChechIsSplit(string moid) { bool isSplit = false; string mocode = string.Empty; ; string MOSEQ = string.Empty; string sql = @" SELECT MOCODE,MOSEQ FROM ICSMO WHERE ID='" + moid + "' "; sql = string.Format(sql); DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0]; if (data != null && data.Rows.Count > 0) { mocode = data.Rows[0][0].ToString(); MOSEQ = data.Rows[0][1].ToString(); } string _sql = @" SELECT COUNT(*) AS num FROM ICSITEMLot b WHERE b.TransNO='" + mocode + "' AND B.TransLine='" + MOSEQ + "' "; _sql = string.Format(_sql); DataTable _data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, _sql).Tables[0]; if (_data != null || _data.Rows.Count > 0) { int a = Int32.Parse(_data.Rows[0][0].ToString()); if (a > 0) { isSplit = true; } } return isSplit; //if (isSplit) //{ // ICSBaseSimpleCode.AppshowMessageBox("已经分批过的不能进行修改"); // return; //} } private void ICSItemLot_FormClosing(object sender, FormClosingEventArgs e) { AppConfig.DropTemTable(tempTableName); } private void FormICSMO_Load(object sender, EventArgs e) { btnFilter_Click(sender, e); } private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) { if (e.RowHandle >= 0 && e.Column.FieldName == "DCTCODE") { //e.DisplayText = FormatHelper. e.CellValue = "cccc"; } if (e.RowHandle > 0 && e.Column.FieldName == "isexpection" && e.CellValue.ToString() == "是") { e.Appearance.BackColor = Color.Red; } } //生成序列号 private void newRcard_Click(object sender, EventArgs e) { //SimpleButton btntemp = (SimpleButton)sender; //if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) //{ // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); // return; //} //int count = 0; //for (int i = 0; i < grvDetail.RowCount; i++) //{ // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") // { // count++; // } //} //if (count != 1) //{ // ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!"); // return; //} //try //{ // string moID; // string moCode; // decimal qty = 0.00m; // for (int i = 0; i < grvDetail.RowCount; i++) // { // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") // { // moID = grvDetail.GetRowCellValue(i, colID).ToString(); // moCode = grvDetail.GetRowCellValue(i, colMOCODE).ToString(); // qty = decimal.Parse(grvDetail.GetRowCellValue(i, colMOPLANQTY).ToString()); // FormICSMO2RCARDAdd rec = new FormICSMO2RCARDAdd(moID, moCode, qty); // rec.ShowDialog(); // } // } // btnRefresh_Click(null, null); //} //catch (Exception ex) //{ // //throw ex; // ICSBaseSimpleCode.AppshowMessageBox(ex.Message); //} } private void repSerialButtonEdit_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { } /// /// 下发 /// /// /// private void txtsend_Click(object sender, EventArgs e) { #region 工艺路线默认匹配 自控参考 //SimpleButton btntemp = (SimpleButton)sender; //if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) //{ // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); // return; //} //int count = 0; //List docNoList = new List(); //for (int i = 0; i < grvDetail.RowCount; i++) //{ // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") // { // string docNo = grvDetail.GetRowCellValue(i, colMOCODE).ToString(); // docNoList.Add(docNo); // count++; // } //} //if (count <= 0) //{ // ICSBaseSimpleCode.AppshowMessageBox("请选择数据!!!"); // return; //} //try //{ // string msg = ""; // List mocodeList = new List(); // List MORouteList = new List(); // for (int i = 0; i < grvDetail.RowCount; i++) // { // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") // { // string mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString(); // string moseq = grvDetail.GetRowCellValue(i, colMOSEQ).ToString(); // string itemCode = grvDetail.GetRowCellValue(i, colITEMCODE).ToString(); // string state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString(); // bool IsHasRoute = ICSMOBLL.IshasROUTE(mocode, AppConfig.AppConnectString);//icsmo2route 是否有值 // bool hasRoute = ICSMOBLL.hasROUTE(mocode, itemCode, AppConfig.AppConnectString); // // if (!IsHasRoute && !hasRoute) // { // msg += "工单代码:" + mocode + " 没有关联工艺路线,不能下发!\n"; // } // ICSROUTE Route = ICSMOBLL.hasIsRefROUTE(itemCode, AppConfig.AppConnectString); // if (!IsHasRoute && Route == null)//判断是否无默认工艺路线 // { // msg += "工单代码:" + mocode + " 无默认工艺路线,不能下发!\n"; // } // if (string.IsNullOrEmpty(msg)) // { // FormICSMORoute_IsRef item = new FormICSMORoute_IsRef(); // item.MOCODE = mocode; // item.MOSEQ = moseq; // item.Route = Route; // item.isRef = "是"; // mocodeList.Add(mocode); // if (!IsHasRoute) // { // MORouteList.Add(item); // } // } // } // } // if (msg != "") // { // ICSBaseSimpleCode.AppshowMessageBox(msg); // return; // } // //直接下发 // foreach (string code in mocodeList) // { // ICSMOBLL.Sends(code, MOSEQ, AppConfig.AppConnectString); // } // if (MORouteList != null && MORouteList.Count > 0) // { // ICSMOBLL.ADDIsRefRoute(MORouteList, AppConfig.AppConnectString); // } // ICSBaseSimpleCode.AppshowMessageBox("下发成功"); // btnRefresh_Click(null, null); //} //catch (Exception ex) //{ // ICSBaseSimpleCode.AppshowMessageBox(ex.Message); //} #endregion 匹配默认 #region 081 GJ 下发 SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } int count = 0; for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { count++; } } if (count == 0) { ICSBaseSimpleCode.AppshowMessageBox("请至少选择一条数据进行下发操作!!!"); return; } try { string mocode = ""; string moseq = ""; string status = ""; List moinfolist = new List(); for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { string id = grvDetail.GetRowCellValue(i, MOID1).ToString(); mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString(); moseq = grvDetail.GetRowCellValue(i, colMOSEQ).ToString(); status = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString(); string itemCode = grvDetail.GetRowCellValue(i, colITEMCODE).ToString(); #region 判断工单是否是初始状态 if (status != "初始") { ICSBaseSimpleCode.AppshowMessageBox("选中工单:" + mocode + "对应行:" + moseq + "不是初始状态,无法下发!!!"); return; } #endregion #region 0827 string IsHasRoute = string.Empty; if (string.IsNullOrWhiteSpace(id)) { IsHasRoute = ICSMOBLL.IshasROUTE(id, AppConfig.AppConnectString);//icsmo2route 返回工单的工艺路线 } if (string.IsNullOrWhiteSpace(IsHasRoute)) { string Route = ICSMOBLL.hasIsRefROUTE(itemCode, AppConfig.AppConnectString);//存货是否有默认路线 FormICSMOUIModel mo = new FormICSMOUIModel(); mo.ID = grvDetail.GetRowCellValue(i, colID).ToString(); mo.MOCODE = grvDetail.GetRowCellValue(i, colMOCODE).ToString(); // mo.MOMEMO = grvDetail.GetRowCellValue(i, colMOMEMO).ToString(); //mo.MOTYPE = txtMOTYPE.Text; //mo.MODESC = grvDetail.GetRowCellValue(i, colMODESC).ToString(); mo.MOTYPE = "1";//工单类型默认为1 mo.MOPLANQTY = Convert.ToDecimal(grvDetail.GetRowCellValue(i, colMOPLANQTY).ToString()); mo.MOPLANSTARTDATE = Convert.ToDateTime(grvDetail.GetRowCellValue(i, colMOPLANSTARTDATE).ToString()); mo.MOPLANENDDATE = Convert.ToDateTime(grvDetail.GetRowCellValue(i, colMOPLANENDDATE).ToString()); mo.FACTORY = grvDetail.GetRowCellValue(i, colFACTORY).ToString(); // mo.CUSORDERNO = grvDetail.GetRowCellValue(i, colCUSORDERNO).ToString(); // mo.MOUSER = grvDetail.GetRowCellValue(i, colMOUSER).ToString(); mo.MODOWNDATE = Convert.ToDateTime(grvDetail.GetRowCellValue(i, colMOPLANSTARTDATE).ToString()); mo.MOSTATUS = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString(); // GetRowCellValue(i, colMOMEMO).ToString(); grvDetail.GetRowCellValue(i, colMODESC).ToString(); //mo.ISCONINPUT = txtISCONINPUT.Text; //if (txtISCONINPUT.Checked) // mo.ISCONINPUT = "是"; //else // mo.ISCONINPUT = "否"; //mo. mo.ITEMCODE = grvDetail.GetRowCellValue(i, colITEMCODE).ToString(); mo.MOSEQ = grvDetail.GetRowCellValue(i, colMOSEQ).ToString(); // mo.MOPENDINGCAUSE = grvDetail.GetRowCellValue(i, colMOPENDINGCAUSE).ToString(); // 9.1注释 mo.OFFMOQTY = Convert.ToDecimal(txtOFFMOQTY.Text.Equals("") ? "0" : txtOFFMOQTY.Text); mo.MOBOM = grvDetail.GetRowCellValue(i, colITEMCODE).ToString(); // mo.MORemark = grvDetail.GetRowCellValue(i, colMORemark).ToString(); // mo.MOVER =grvDetail.GetRowCellValue(i, colMODESC).ToString(); ICSMOBLL.Add(mo, Route, AppConfig.AppConnectString); //if (flag == 0) //{ //ICSBaseSimpleCode.AppshowMessageBox("匹配成功"); //this.Close(); // this.DialogResult = DialogResult.Yes; //} //else if (flag == 1) //{ // ICSBaseSimpleCode.AppshowMessageBox("修改成功"); // this.Close(); // this.DialogResult = DialogResult.Yes; //} // add.ShowDialog(); // } //} //else //{ // ICSBaseSimpleCode.AppshowMessageBox(" 没有默认工艺路线,不能下发!!!\n"); // return; //} } #region 废弃的 //bool hasRoute = ICSMOBLL.hasROUTE(mocode, itemCode, AppConfig.AppConnectString);//工单号(mocode)是否有路线 //ICSROUTE Route = ICSMOBLL.hasIsRefROUTE(itemCode, AppConfig.AppConnectString);//存货是否有默认路线 //if (!IsHasRoute && !hasRoute) //{ // ICSBaseSimpleCode.AppshowMessageBox("工单代码:" + mocode + " 没有关联工艺路线,不能下发!\n"); // return; //} //if (IsHasRoute && Route != null)//判断是否默认工艺路线 //{ // string moid = grvDetail.GetRowCellValue(i, colID).ToString(); // bool issplit = ChechIsSplit(moid); // if (issplit) // { // ICSBaseSimpleCode.AppshowMessageBox("已经分批过的不能进行修改!!"); // return; // } // else // { // ICSBaseSimpleCode.AppshowMessageBox("有默认的工艺路线\n"); // FormICSMOAdd add = new FormICSMOAdd(moid); // add.ShowDialog(); #endregion #endregion #region 下发前检验工单是否绑定工艺路线 ICSMO2ROUTE morouteinfo = ICSMOBLL.selectmo2routebyid(grvDetail.GetRowCellValue(i, colID).ToString(), AppConfig.AppConnectString); if (morouteinfo == null) { ICSBaseSimpleCode.AppshowMessageBox("选中工单:" + mocode + "对应行:" + moseq + "尚未绑定工艺路线,无法下发!!!"); return; } #endregion ICSMO moinfo = new ICSMO(); moinfo.MOCODE = mocode; moinfo.MOSEQ = moseq; moinfolist.Add(moinfo); } } ICSMOBLL.Send(moinfolist, AppConfig.AppConnectString); ICSBaseSimpleCode.AppshowMessageBox("下发成功"); btnRefresh_Click(null, null); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } #endregion #region 注释的原版0819 // SimpleButton btntemp = (SimpleButton)sender; // if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) // { // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); // return; // } // int count = 0; // for (int i = 0; i < grvDetail.RowCount; i++) // { // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") // { // count++; // } // } // if (count != 1) // { // ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!"); // return; // } // try // { // string mocode = ""; // string moseq = ""; // string state = ""; // string moid = ""; //0819 // for (int i = 0; i < grvDetail.RowCount; i++) // { // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") // { // mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString(); // state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString(); // moseq = grvDetail.GetRowCellValue(i, colMOSEQ).ToString(); // moid = grvDetail.GetRowCellValue(i, colID).ToString(); //0819 // } // } // #region 20210804 下发之后才能分批,不是分批之后在下发。 // string sendSql = @"SELECT * FROM ICSITEMLot WHERE TransNO='" + mocode + "' "; // sendSql = string.Format(sendSql); // DataTable sendData = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sendSql).Tables[0]; // if (sendData == null || sendData.Rows.Count < 1) // { // ICSBaseSimpleCode.AppshowMessageBox("只有分完批次才能下发!"); // return; // } // #endregion // --工艺路线,代码(途程代码)的sql语句 // string _sql = @"SELECT // c.ROUTECODE --工艺路线,代码(途程代码) // FROM // ICSMO a // LEFT JOIN ICSMO2ROUTE c ON a.ID = c.MOID // LEFT JOIN ( // SELECT // b.MOCODE, // CONVERT (INT, b.MOSEQ) AS MOSEQ, // b.ITEMCODE, // COUNT (*) AS IsUse // FROM // ICSMOPickLog a // INNER JOIN ICSMO b ON ( // a.MOCode = b.MOCODE // AND b.MOSEQ = a.MOSEQ // AND a.ITEMCODE = b.ITEMCODE // ) // GROUP BY // b.MOCODE, // b.MOSEQ, // b.ITEMCODE // ) d ON ( // d.MOCODE = a.MOCODE // AND d.MOSEQ = a.MOSEQ // AND d.ITEMCODE = a.ITEMCODE // ) // WHERE 1 = 1 // AND a.MOCODE = '" + mocode + "' AND a.MOSEQ =" + moseq + " ORDER BY a.MOCODE, CONVERT (INT, a.MOSEQ)"; // _sql = string.Format(_sql); // DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, _sql).Tables[0]; // string _ROUTECODE = string.Empty;//--工艺路线,代码(途程代码) // if (data != null && data.Rows.Count > 0) // { // _ROUTECODE = data.Rows[0][0].ToString();//--工艺路线,代码(途程代码) // } // else // { // ICSBaseSimpleCode.AppshowMessageBox("工单尚未绑定工艺路线不能下发!"); // return; // } // if (string.IsNullOrWhiteSpace(_ROUTECODE))//--工艺路线,代码(途程代码) // { // ICSBaseSimpleCode.AppshowMessageBox("工单尚未绑定工艺路线不能下发!!"); // return; // } // 判断是否是初始状态 // if (state.Equals("初始")) // { // //判断是否在工单首检记录表中 // if (ICSMOBLL.isInFirstCheck(mocode, AppConfig.AppConnectString)) // { // //判断(最近的时间)是否合格 // if (ICSMOBLL.isQualified(mocode, AppConfig.AppConnectString)) // { // ICSMOBLL.Send(mocode, moseq, AppConfig.AppConnectString); // ICSBaseSimpleCode.AppshowMessageBox("下发成功"); // } // else // { // ICSBaseSimpleCode.AppshowMessageBox("不合格,不能下发"); // return; // //} // } // else // { // ICSBaseSimpleCode.AppshowMessageBox("不存在工单首检记录中"); // return; // } // } // else // { // ICSBaseSimpleCode.AppshowMessageBox("不是初始状态,不能下发"); // return; // } // btnRefresh_Click(null, null); // } //try // catch (Exception ex) // { // ICSBaseSimpleCode.AppshowMessageBox(ex.Message); // } #endregion } //取消下发 private void txtcancelSend_Click(object sender, EventArgs e) { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { //if (!grvDetail.GetRowCellValue(i, colMOSTATUS).ToString().Equals("下发")) //{ // ICSBaseSimpleCode.AppshowMessageBox("工单: "+grvDetail.GetRowCellValue(i, colMOCODE).ToString()+" 不是下发状态,不能取消下发"); // return; //} if (ICSMO2LotBLL.IsKG(grvDetail.GetRowCellValue(i, colMOCODE).ToString(), grvDetail.GetRowCellValue(i, colMOSEQ).ToString())) { ICSBaseSimpleCode.AppshowMessageBox("工单: " + grvDetail.GetRowCellValue(i, colMOCODE).ToString() + " 已开工,无法取消下发!"); return; } if (ICSMO2LotBLL.IsPG(grvDetail.GetRowCellValue(i, colMOCODE).ToString(), grvDetail.GetRowCellValue(i, colMOSEQ).ToString())) { ICSBaseSimpleCode.AppshowMessageBox("工单: " + grvDetail.GetRowCellValue(i, colMOCODE).ToString() + " 已派工,请先取消派工!"); return; } if (ICSMO2LotBLL.IsIncludingInMO2Lot(grvDetail.GetRowCellValue(i, colID).ToString())) { ICSBaseSimpleCode.AppshowMessageBox("工单: " + grvDetail.GetRowCellValue(i, colMOCODE).ToString() + " 已分批,请先删除分批再取消下发!"); return; } } } try { string mocode = ""; string state = ""; string moseq = ""; for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString(); state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString(); moseq = grvDetail.GetRowCellValue(i, colMOSEQ).ToString(); ICSMOBLL.cancelSend(mocode, moseq, AppConfig.AppConnectString); } } ICSBaseSimpleCode.AppshowMessageBox("取消下发成功"); btnRefresh_Click(null, null); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } //暂停 private void txtstop_Click(object sender, EventArgs e) { //SimpleButton btntemp = (SimpleButton)sender; //if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) //{ // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); // return; //} //int count = 0; //for (int i = 0; i < grvDetail.RowCount; i++) //{ // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") // { // count++; // } //} //if (count != 1) //{ // ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!"); // return; //} //try //{ // string mocode = ""; // string state = ""; // for (int i = 0; i < grvDetail.RowCount; i++) // { // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") // { // mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString(); // state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString(); // } // } // //判断是否是生产中状态 // if (state.Equals("生产中")) // { // ICSMOBLL.stop(mocode, AppConfig.AppConnectString); // ICSBaseSimpleCode.AppshowMessageBox("暂停成功"); // } // else // { // ICSBaseSimpleCode.AppshowMessageBox("不是生产中状态,不能暂停"); // return; // } // btnRefresh_Click(null, null); //} //catch (Exception ex) //{ // ICSBaseSimpleCode.AppshowMessageBox(ex.Message); //} } //取消暂停 private void txtcancelStop_Click(object sender, EventArgs e) { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } int count = 0; for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { count++; } } if (count != 1) { ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!"); return; } try { string mocode = ""; string state = ""; for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString(); state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString(); } } //判断是否是暂停状态 if (state.Equals("暂停")) { ICSMOBLL.cancelStop(mocode, AppConfig.AppConnectString); ICSBaseSimpleCode.AppshowMessageBox("取消暂停成功"); } else { ICSBaseSimpleCode.AppshowMessageBox("不是暂停状态,不能取消暂停"); return; } btnRefresh_Click(null, null); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } //关单 private void txtcloseDan_Click(object sender, EventArgs e) { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { if (grvDetail.GetRowCellValue(i, colMOSTATUS).ToString().Equals("关单")) { ICSBaseSimpleCode.AppshowMessageBox("工单: " + grvDetail.GetRowCellValue(i, colMOCODE).ToString() + " 已经是关单状态,不能关单!"); return; } } } try { List ID = new List(); for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { string id = grvDetail.GetRowCellValue(i, colID).ToString(); ID.Add(id); } } FormICSMOClose add = new FormICSMOClose(ID); add.ShowDialog(); btnRefresh_Click(null, null); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } //批次信息 private void btnBatch_Click(object sender, EventArgs e) { //SimpleButton btntemp = (SimpleButton)sender; //if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) //{ // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); // return; //} //FormICSMO2Lot add = new FormICSMO2Lot(); //add.ShowDialog(); //btnRefresh_Click(null, null); SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } int count = 0; for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { count++; } } if (count != 1) { ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!"); return; } try { string id; string code; int Qty = 0; string itemcode; string dept;//0816新增 DateTime MOPLANSTARTDATE; DateTime MOPLANENDDATE; for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { dept = grvDetail.GetRowCellValue(i, colcDepName).ToString();//0816新增字段 id = grvDetail.GetRowCellValue(i, colID).ToString(); code = grvDetail.GetRowCellValue(i, colMOCODE).ToString(); Qty = (int)Convert.ToDecimal(grvDetail.GetRowCellValue(i, colMOPLANQTY).ToString()); itemcode = grvDetail.GetRowCellValue(i, colITEMCODE).ToString(); string moseq = grvDetail.GetRowCellValue(i, colMOSEQ).ToString(); MOPLANSTARTDATE = Convert.ToDateTime((grvDetail.GetRowCellValue(i, colMOPLANSTARTDATE))); MOPLANENDDATE = Convert.ToDateTime((grvDetail.GetRowCellValue(i, colMOPLANENDDATE))); FormICSMO2LOT1 add = new FormICSMO2LOT1(id, code, Qty, itemcode, moseq, dept, MOPLANSTARTDATE, MOPLANENDDATE); add.ShowDialog(); btnRefresh_Click(null, null); } } //判断是否是关单状态 //if (!(state.Equals("关单"))) //{ //} //else //{ // ICSBaseSimpleCode.AppshowMessageBox("已经是关单状态"); // return; //} btnRefresh_Click(null, null); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #region 取消关单 private void BtnCancelCloseMO_Click(object sender, EventArgs e) { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } int count = 0; for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { count++; } } if (count != 1) { ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!"); return; } try { string ID = ""; string state = ""; for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { ID = grvDetail.GetRowCellValue(i, colID).ToString(); state = grvDetail.GetRowCellValue(i, colMOSTATUS).ToString(); } } if ((state.Equals("关单"))) { //判断是否是关单状态 ICSMOBLL.CancleCloseDan(ID, AppConfig.AppConnectString); ICSBaseSimpleCode.AppshowMessageBox("取消关单成功"); } else { ICSBaseSimpleCode.AppshowMessageBox("非关单状态,不能取消关单"); return; } btnRefresh_Click(null, null); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion /// /// 新增的 [一键分批按钮] 按钮0818 /// /// /// private void btnLot1_Click(object sender, EventArgs e) { try { //根据ICSMOPickLog窜起来查确定是否领料。工单:MOCODE、生产订单行号:MOSEQ、子料:ITEMCODE(根据工单母料看子料) //限制:如果‘是否领料’字段为‘否’,那么无法进行分批操作; SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } int count = 0; for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") // if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect).ToString())) { count++; } } if (count == 0) { ICSBaseSimpleCode.AppshowMessageBox("请至少选择一条数据进行分批!"); return; } else { List lotinfoList = new List(); List oplotinfoList = new List(); for (int i = 0; i < grvDetail.RowCount; i++) { //if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect).ToString())) if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { string ITEMCODE = grvDetail.GetRowCellValue(i, colITEMCODE).ToString(); string mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString(); string moseq = grvDetail.GetRowCellValue(i, colMOSEQ).ToString(); string moplanstartdate= grvDetail.GetRowCellValue(i, colMOPLANSTARTDATE).ToString(); string moplanenddate = grvDetail.GetRowCellValue(i, colMOPLANENDDATE).ToString(); ICSMO moinfo = ICSMOBLL.selectbyid(grvDetail.GetRowCellValue(i, colID).ToString(), AppConfig.AppConnectString); if (moinfo.MOSTATUS != "下发") { ICSBaseSimpleCode.AppshowMessageBox("选中工单:" + mocode + "对应行号:" + moseq + "尚未下发,不能分批!"); return; } string ItemCode = grvDetail.GetRowCellValue(i, colITEMCODE).ToString(); string RouteCode = grvDetail.GetRowCellValue(i, colMOROUTE).ToString(); bool b = ICSMO2LotBLL.IsIncludingInMO2Lot(grvDetail.GetRowCellValue(i, colID).ToString()); if (b) { ICSBaseSimpleCode.AppshowMessageBox("选中工单:" + mocode + "对应行号:" + moseq + "已生成批次,若要重新生成,请先删除原批次信息!"); return; } #region ICSITEMLot表 ICSITEMLot lotinfo = new ICSITEMLot(); lotinfo.MCODE = ITEMCODE;//0827新增 lotinfo.ID = AppConfig.GetGuid(); lotinfo.LotNO = mocode + moseq + "0001"; lotinfo.TransNO = mocode; lotinfo.TransLine = moseq; // lotinfo.ItemCODE = grvDetail.GetRowCellValue(i, colITEMCODE).ToString(); lotinfo.VENDORITEMCODE = ""; lotinfo.VENDORCODE = ""; lotinfo.VenderLotNO = ""; lotinfo.PRODUCTDATE = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss"); lotinfo.LOTQTY = Convert.ToDecimal(grvDetail.GetRowCellValue(i, colMOPLANQTY).ToString()); lotinfo.ACTIVE = "Y"; lotinfo.Exdate = Convert.ToDateTime("2999-12-31 00:00:00.000"); lotinfo.WorkPoint = AppConfig.WorkPointCode; lotinfo.MUSER = AppConfig.UserCode; lotinfo.MUSERName = AppConfig.UserName; lotinfo.MTIME = DateTime.Now; lotinfo.EATTRIBUTE1 = ""; lotinfo.TYPE = "工单"; lotinfo.MOPLANSTARTDATE = moplanstartdate; lotinfo.MOPLANENDDATE = moplanenddate; lotinfoList.Add(lotinfo); #endregion #region 根据Code获取工艺路线信息 List opinfolist = ICSITEMROUTE2OPBLL.selectinfobycode(ItemCode, RouteCode, AppConfig.AppConnectString); #endregion #region 写入ICSItemRoute2OPLot表 foreach (ICSITEMROUTE2OP opinfo in opinfolist) { ICSITEMROUTE2OPLot oplotinfo = new ICSITEMROUTE2OPLot(); oplotinfo.ITEMCODE = ItemCode; oplotinfo.ROUTECODE = RouteCode; oplotinfo.OPCODE = opinfo.OPCODE; oplotinfo.OPSEQ = opinfo.OPSEQ; oplotinfo.OPCONTROL = ""; oplotinfo.OPTIONALOP = ""; oplotinfo.IDMERGERULE = 0; oplotinfo.IDMERGETYPE = ""; oplotinfo.MUSER = AppConfig.UserCode; oplotinfo.MUSERName = AppConfig.UserName; oplotinfo.MTIME = DateTime.Now; oplotinfo.WorkPoint = AppConfig.WorkPointCode; oplotinfo.EATTRIBUTE1 = ""; oplotinfo.LotNo = mocode + moseq + "0001"; oplotinfo.ID = AppConfig.GetGuid(); oplotinfoList.Add(oplotinfo); } #endregion } } ICSMO2LotBLL.OP2LotAdd(lotinfoList, oplotinfoList, AppConfig.AppConnectString); ICSBaseSimpleCode.AppshowMessageBox("分批成功"); btnRefresh_Click(null, null); } } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } private void simpleButton1_Click(object sender, EventArgs e) { AppConfig.CloseFormShow(this.Text); this.Close(); } private void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { try { string url = @"http://172.16.12.155:8999/api/GetPLMToken"; //string url = @"http://localhost:51182/api/GetPLMToken"; FormICSProductionReport.SearchPart Bills = new FormICSProductionReport.SearchPart(); //Bills.ItemCode = "20100003035"; //Bills.ItemCode = "20100000670"; //Bills.ItemCode = "20800001904"; Bills.ItemCode = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colITEMCODE).ToString(); Bills.size = 100; Bills.extra = "DWGSW"; string JsonData = JsonConvert.SerializeObject(Bills); //try //{ // //Bills = JsonConvert.DeserializeObject>(JsonData.ToString()); // Bills = JsonConvert.DeserializeObject(JsonData.ToString()); //} #region MyRegion BaseModel rtn = PLM.PLMMap(url, JsonData); if (rtn.code == "200") { #region MyRegion string connectionString = AppConfig.GetDataBaseConnectStringByKey("[DB.FTP]"); if (string.IsNullOrWhiteSpace(connectionString)) { ICSBaseSimpleCode.AppshowMessageBox("没有获取到FTP链接,请在数据源中先配置FTP"); return; } string[] ftps = connectionString.Split(';'); string ftpServerIP = ftps[0].Split('=')[1]; //string ftpRemotePath = ftps[1].Split('=')[1]; string ftpRemotePath = ""; string ftpUserID = ftps[2].Split('=')[1]; string ftpPassword = ftps[3].Split('=')[1]; FtpWeb ftpWeb = new FtpWeb(ftpServerIP, ftpRemotePath, ftpUserID, ftpPassword); //FtpWeb ftpWeb = new FtpWeb(ftpServerIP, ftpRemotePath, ftpUserID, ftpPassword); //string filePath = System.IO.Path.GetTempPath() + "\\Drawing"; string filePath = AppDomain.CurrentDomain.BaseDirectory + "\\Drawing"; if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } string fileName = Bills.ItemCode + ".pdf"; ftpWeb.Download(filePath + "\\", fileName); string filePathName = filePath + "\\" + fileName; //string fileName = logAdress + Bills.ItemCode + ".pdf"; string ftpURL = "ftp://" + ftpServerIP + "/" + fileName; //if (!string.IsNullOrEmpty(fileName)) if (!string.IsNullOrEmpty(filePathName)) { FileDrawing.LoadPDF(filePathName); } #endregion } else { ICSBaseSimpleCode.AppshowMessageBox("调用PLM接口返回异常:" + rtn.code + ";" + rtn.msg); return; } #endregion } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void grvDetail_Click(object sender, EventArgs e) { } private void simpleButton2_Click(object sender, EventArgs e) { try { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } string para1 = "1 and "; for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { para1 += " (a.mocode='" + grvDetail.GetRowCellValue(i, colMOCODE).ToString() + "' and a.moseq='" + grvDetail.GetRowCellValue(i, colMOSEQ).ToString() + "') OR"; } } if (para1 == "1 and ") { ICSBaseSimpleCode.AppshowMessageBox("请选择要打印的数据!"); return; } para1=para1.TrimEnd("OR".ToCharArray()); List parasList = new List(); PrintPara para = new PrintPara(); para.PrintKey = "1=1"; para.PrintValues = new object[] { para1 }; parasList.Add(para); FormPrintDialog f = new FormPrintDialog("099", this.Text, parasList, false, null); f.ShowDialog(); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } } }