using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Linq; using System.IO; using System.Windows.Forms; using DevExpress.XtraEditors; using ICSSoft.Frame.User.BLL; using ICSSoft.Base.Language.Tool; using ICSSoft.Base.UserControl.MessageControl; using System.Data.SqlClient; using ICSSoft.Base.Config.AppConfig; using ICSSoft.Base.Report.Filter; using ICSSoft.Base.Config.DBHelper; using ICSSoft.Base.UserControl.FormControl; using ICSSoft.Base.ReferForm.AppReferForm; using ICSSoft.Base.Lable.PrintTool; using ICSSoft.Frame.Data.DAL; using ICSSoft.Frame.Data.BLL; using ICSSoft.Frame.Data.Entity; namespace ICSSoft.Frame.APP { public partial class FormICSProductTrackingList : DevExpress.XtraEditors.XtraForm { private string sqltxt = ""; private string sqlconn = ""; String guid = AppConfig.GetGuid(); private DataTable dataSource = null; bool b = false; #region 构造函数 public FormICSProductTrackingList() { 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) { // col.OptionsColumn.AllowEdit = col.Name == colSerial.Name; // col.OptionsColumn.ReadOnly = true; } b = true; } public FormICSProductTrackingList(string mocode) { InitializeComponent(); this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height); this.WindowState = FormWindowState.Maximized; b = false; foreach (DevExpress.XtraGrid.Columns.GridColumn col in grvDetail.Columns) { // col.OptionsColumn.AllowEdit = col.Name == colSerial.Name; // col.OptionsColumn.ReadOnly = true; } searchInfo(mocode); } public FormICSProductTrackingList(string mocode,string moseq) { InitializeComponent(); this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height); this.WindowState = FormWindowState.Maximized; b = false; foreach (DevExpress.XtraGrid.Columns.GridColumn col in grvDetail.Columns) { // col.OptionsColumn.AllowEdit = col.Name == colSerial.Name; // col.OptionsColumn.ReadOnly = true; } searchInfo(mocode,moseq); } /// /// 传入产品追踪单号 /// /// /// public FormICSProductTrackingList(List lotno) { InitializeComponent(); this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height); this.WindowState = FormWindowState.Maximized; b = false; searchInform(lotno); } #endregion private void searchInform(List lotno) { try { this.Tag = "10.24.04"; FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name)); string sql = @"SELECT DISTINCT '' AS [isSelect], e.LOTNO as LOTNO, a.ID AS ID, --a.ProjectCode AS ProjectCode, a.MOCODE AS MOCODE, a.MOTYPE AS MOTYPE, a.MOSEQ AS MOSEQ, b.ROUTECODE AS RouteCode, b.ROUTETYPE AS ROUTETYPE, a.MOPLANQTY AS MOPLANQTY, a.MOPLANSTARTDATE AS MOPLANSTARTDATE, a.MOPLANENDDATE AS MOPLANENDDATE, f.INVSTD as ItemCtrTypeCode FROM --ICSMO2Lot e ICSITEMLot e INNER JOIN ICSMO2User c ON e.LOTNO = c.LOTNO INNER JOIN ICSMO a on e.TransNO=a.MOCODE AND e.TransLine=a.MOSEQ INNER JOIN ICSMO2ROUTE b ON a.MOCODE = b.MOCODE INNER JOIN ICSINVENTORY f ON a.ITEMCODE = f.INVCODE WHERE 1=1 "; for (int i = 0; i < lotno.Count; i++) { if (i == 0) { sql += " and e.LOTNO='" + lotno[i] + "'"; } else { sql += " or e.LOTNO='" + lotno[i] + "'"; } } DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0]; grdDetail.DataSource = data; } catch (Exception ex) { MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void searchInfo(string mocode) { try { this.Tag = "10.24.04"; FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name)); string sql = @"SELECT DISTINCT '' AS [isSelect], e.LOTNO as LOTNO, a.ID AS ID, a.ProjectCode AS ProjectCode, a.MOCODE AS MOCODE, a.MOTYPE AS MOTYPE, a.MOSEQ AS MOSEQ, b.ROUTECODE AS RouteCode, b.ROUTETYPE AS ROUTETYPE, a.MOPLANQTY AS MOPLANQTY, a.MOPLANSTARTDATE AS MOPLANSTARTDATE, a.MOPLANENDDATE AS MOPLANENDDATE, f.ItemCtrTypeCode as ItemCtrTypeCode FROM ICSMO2Lot e INNER JOIN ICSMO2User c ON e.LOTNO = c.LOTNO INNER JOIN ICSMO a on e.MOCODE=a.MOCODE INNER JOIN ICSMO2ROUTE b ON a.MOCODE = b.MOCODE INNER JOIN Base_Inventory f ON a.ITEMCODE = f.ItemCode WHERE a.MOCODE='" + mocode + "' order by e.LOTNO asc"; sql = string.Format(sql); DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0]; grdDetail.DataSource = data; } catch (Exception ex) { MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void searchInfo(string mocode,string moseq) { try { this.Tag = "10.24.04"; FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name)); // string sql = @"SELECT DISTINCT // '' AS [isSelect], // e.LOTNO as LOTNO, // a.ID AS ID, // a.MOVER AS ProjectCode, // a.MOCODE AS MOCODE, // a.MOTYPE AS MOTYPE, // a.MOSEQ AS MOSEQ, // // b.ROUTECODE AS RouteCode, // b.ROUTETYPE AS ROUTETYPE, // a.MOPLANQTY AS MOPLANQTY, // a.MOPLANSTARTDATE AS MOPLANSTARTDATE, // a.MOPLANENDDATE AS MOPLANENDDATE, // '' as ItemCtrTypeCode //FROM //ICSITEMLot e //INNER JOIN ICSMO2User c ON e.LOTNO = c.LOTNO //INNER JOIN ICSMO a on e.TransNO=a.MOCODE AND e.TransLine=a.MOSEQ //INNER JOIN ICSMO2ROUTE b ON a.MOCODE = b.MOCODE //INNER JOIN ICSINVENTORY f ON a.ITEMCODE = f.INVCODE //WHERE // a.MOCODE='" + mocode + "' AND a.MOSEQ='"+moseq+"' order by e.LOTNO asc"; string sql = @" SELECT DISTINCT '' AS [isSelect], f.INVCODE as INVCODE, f.INVNAME as INVNAME, f.INVSTD as INVSTD, e.LOTQTY as QTY, f.INVUOM as INVUOM, a.MOCODE AS MOCODE, a.MOSEQ as MOSEQ, a.MOVER AS MOVER, e.MUSERName as MUSER, e.MTIME as MTIME, CAST(CASE WHEN i.LotNO IS NOT NULL THEN '1' ELSE '0' END AS bit) AS ISPUT, e.LOTNO as LOTNO, cast(e.EATTRIBUTE3 as decimal(18,2)) *cast(e.LOTQTY as decimal(18,2)) as AuxiliaryQTY, f.INVEXPORTIMPORT as AuxiliaryUOM FROM ICSITEMLot e INNER JOIN ICSMO a on e.TransNO=a.MOCODE AND e.TransLine=a.MOSEQ INNER JOIN ICSINVENTORY f ON a.ITEMCODE = f.INVCODE LEFT JOIN ICSWareHouseLotInfo i ON e.LOTNO=i.LotNO WHERE 1=1 AND e.TYPE='工单' AND MOCODE='" + mocode + "' AND MOSEQ='" + moseq + "' order by e.LOTNO asc"; sql = string.Format(sql); DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0]; grdDetail.DataSource = data; } catch (Exception ex) { MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); } } #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); foreach (Control ctr in panelControl3.Controls) { if (ctr.Name == btnFilter.Name || ctr.Name == btnConfig.Name || ctr.Name == btnSelectAll.Name || ctr.Name == btnCancelAll.Name || ctr.Name == btnOutPut.Name || ctr.Name == btnPrint.Name || ctr.Name == txtTarckList.Name || ctr.Name == btnrePrint.Name || ctr.Name == btnRefresh.Name || ctr.Name == btnExit.Name || ctr.Name == MOTitle.Name || ctr.Name == btnClose.Name || ctr.Name == btnDelete.Name || ctr.Name == btnCancelPrint.Name) continue; DataRow dr = rData.NewRow(); dr["BtnName"] = ctr.Name; dr["ActionName"] = ctr.Text; rData.Rows.Add(dr); } //List ControlList = new List(); ////ControlList.Add(btnCreate); ////ControlList.Add(btnModify); ////ControlList.Add(btnDel); //ControlList.Add(btnOutPut); //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 = 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 btnOutPut_Click(object sender, EventArgs e) { FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail); foe.ShowDialog(); } #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]; 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; // } // FormICSMOAdd add = new FormICSMOAdd(); // add.ShowDialog(); // btnRefresh_Click(null, null); //} //#endregion //#region 修改 //private void btnModify_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; // for (int i = 0; i < grvDetail.RowCount; i++) // { // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") // { // moid = grvDetail.GetRowCellValue(i, colID).ToString(); // FormICSMOAdd add = new FormICSMOAdd(moid); // add.ShowDialog(); // } // } // btnRefresh_Click(null, null); // } // catch (Exception ex) // { // //throw ex; // ICSBaseSimpleCode.AppshowMessageBox(ex.Message); // } //} //#endregion //#region 删除 //private void btnDel_Click(object sender, EventArgs e) //{ // 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") // { // moidList.Add(grvDetail.GetRowCellValue(i, colID).ToString()); // } // } // 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 private void ICSItemLot_FormClosing(object sender, FormClosingEventArgs e) { AppConfig.DropTemTable(tempTableName); } private void FormICSMO_Load(object sender, EventArgs e) { if (b == true) { 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"; } } #region 入库条码打印 private void txtPrint_Click(object sender, EventArgs e) { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } if (grvDetail.FocusedRowHandle < 0) { return; } try { string lotno = ""; string mes = ""; string message = ""; for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { if (Convert.ToInt32(grvDetail.GetRowCellValue(i, colTimesPrint).ToString()) > 0) { if (mes == "") { mes = "条码:" + grvDetail.GetRowCellValue(i, colLOTNO).ToString(); } else { mes += ";条码:" + grvDetail.GetRowCellValue(i, colLOTNO).ToString(); } } } } for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { lotno = grvDetail.GetRowCellValue(i, colLOTNO).ToString(); string sql = @"SELECT DISTINCT x.ISCOM FROM ICSLOTSIMULATION x -- INNER JOIN ICSLOTONWIP y ON x.LOTNO=y.LOTNO AND x.OPCODE=y.OPCODE -- INNER JOIN ICSLOTONWIPCheck z ON y.ID=z.ONWIPID WHERE x.ISCOM='1' AND x.LOTNO='{0}' "; sql = string.Format(sql, lotno); DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0]; if (dt == null || dt.Rows.Count <= 0) { if (message == "") { message = "条码:" + grvDetail.GetRowCellValue(i, colLOTNO).ToString(); } else { message += ";条码:" + grvDetail.GetRowCellValue(i, colLOTNO).ToString(); } } else { sql = @" select a.LOTNO,a.OPCODE,b.ID ,c.Result,c.TResult from ICSLOTSIMULATION a inner join ICSLOTONWIP b on b.LOTNO=a.LOTNO and b.OPCODE=a.OPCODE inner join ICSLOTONWIPCheck c on c.ONWIPID=b.ID where a.LOTNO='{0}' "; sql = string.Format(sql, lotno); dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0]; if (dt == null || dt.Rows.Count <= 0) { if (message == "") { message = "条码:" + grvDetail.GetRowCellValue(i, colLOTNO).ToString() + "最后一道工序未检验,无法打印,请先检验;"; } else { message += ";条码:" + grvDetail.GetRowCellValue(i, colLOTNO).ToString() + "最后一道工序未检验,无法打印,请先检验;"; } } else { if (!(dt.Rows[0]["Result"].ToString() == "合格" || dt.Rows[0]["TResult"].ToString() == "让步")) { if (message == "") { message = "条码:" + grvDetail.GetRowCellValue(i, colLOTNO).ToString(); } else { message += ";条码:" + grvDetail.GetRowCellValue(i, colLOTNO).ToString(); } } } } } } if (mes == "") { if (message == "") { List barCodeList = new List(); List InfoList = new List(); for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { string barCode = grvDetail.GetRowCellValue(i, colLOTNO).ToString(); PrintPara printInfo = new PrintPara(); printInfo.PrintKey = "LOTNO"; printInfo.PrintValues = new object[] { barCode }; barCodeList.Add(printInfo); ICSITEMLot Info = new ICSITEMLot(); Info.LotNO = grvDetail.GetRowCellValue(i, colLOTNO).ToString(); //Info.PrintTimes = Convert.ToInt32(grvDetail.GetRowCellValue(i, colPrintTimes).ToString()) + 1; Info.TimesPrint = 1; Info.lastPrintUSERID = AppConfig.UserId; Info.lastPrintTime = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss"); Info.WorkPoint = AppConfig.WorkPointCode; InfoList.Add(Info); } } if (barCodeList.Count == 0) { ICSBaseSimpleCode.AppshowMessageBox("没有选择数据"); return; } FormPrintDialog printDialog = new FormPrintDialog("025", "ICSProduct", barCodeList, false, null); printDialog.ShowDialog(); //更新打印信息 ICSRdrecord2LOTBLL.updateGoodPrint(InfoList, AppConfig.AppConnectString); } else { ICSBaseSimpleCode.AppshowMessageBox(message + "最后一道工序未检验完成,不能打印!"); return; } } else { ICSBaseSimpleCode.AppshowMessageBox(mes + "存在已经打印的合格证,不能再次打印!"); return; } #region // for (int i = 0; i < grvDetail.RowCount; i++) // { // string sql = ""; // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") // { // sql = @"Insert into WM_BarCodePrintLog // Values // (NEWID(),'{0}','0001','{1}','{2}',GetDate(),null,null)"; // sql = string.Format(sql, grvDetail.GetRowCellValue(i, colLOTNO).ToString(), AppConfig.UserCode // , AppConfig.UserName); // DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, sql); // } // } #endregion } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion #region 跟踪单打印 private void txtTarckList_Click(object sender, EventArgs e) { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } if (grvDetail.FocusedRowHandle < 0) { return; } try { List barCodeList = new List(); List InfoList = new List(); for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { string barCode = grvDetail.GetRowCellValue(i, colLOTNO).ToString(); PrintPara printInfo = new PrintPara(); printInfo.PrintKey = "LOTNO"; printInfo.PrintValues = new object[] { barCode }; barCodeList.Add(printInfo); ICSITEMLot Info = new ICSITEMLot(); Info.LotNO = grvDetail.GetRowCellValue(i, colLOTNO).ToString(); //Info.PrintTimes = Convert.ToInt32(grvDetail.GetRowCellValue(i, colPrintTimes).ToString()) + 1; Info.lastPrintUSERID = AppConfig.UserId; Info.lastPrintTime = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss"); Info.WorkPoint = AppConfig.WorkPointCode; InfoList.Add(Info); } } if (barCodeList.Count == 0) { ICSBaseSimpleCode.AppshowMessageBox("没有选择数据"); return; } FormPrintDialog printDialog = new FormPrintDialog("007", "ICSProduct", barCodeList, false, null); printDialog.ShowDialog(); //更新打印信息 ICSRdrecord2LOTBLL.updatePrint(InfoList, AppConfig.AppConnectString); // for (int i = 0; i < grvDetail.RowCount; i++) // { // string sql = ""; // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") // { // sql = @"Insert into WM_BarCodePrintLog // Values // (NEWID(),'{0}','0001','{1}','{2}',GetDate(),null,null)"; // sql = string.Format(sql, grvDetail.GetRowCellValue(i, colLOTNO).ToString(), AppConfig.UserCode // , AppConfig.UserName); // DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, sql); // } // } } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion #region 合格证打印 private void txtQuality_Click(object sender, EventArgs e) { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } if (grvDetail.FocusedRowHandle < 0) { return; } try { List barCodeList = new List(); List InfoList = new List(); for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { string barCode = grvDetail.GetRowCellValue(i, colLOTNO).ToString(); PrintPara printInfo = new PrintPara(); printInfo.PrintKey = "LOTNO"; printInfo.PrintValues = new object[] { barCode }; barCodeList.Add(printInfo); ICSITEMLot Info = new ICSITEMLot(); Info.LotNO = grvDetail.GetRowCellValue(i, colLOTNO).ToString(); //Info.PrintTimes = Convert.ToInt32(grvDetail.GetRowCellValue(i, colPrintTimes).ToString()) + 1; Info.lastPrintUSERID = AppConfig.UserId; Info.lastPrintTime = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss"); Info.WorkPoint = AppConfig.WorkPointCode; InfoList.Add(Info); } } if (barCodeList.Count == 0) { ICSBaseSimpleCode.AppshowMessageBox("没有选择数据"); return; } FormPrintDialog printDialog = new FormPrintDialog("024", "ICSProduct", barCodeList, false, null); printDialog.ShowDialog(); //更新打印信息 ICSRdrecord2LOTBLL.updatePrint(InfoList, AppConfig.AppConnectString); // for (int i = 0; i < grvDetail.RowCount; i++) // { // string sql = ""; // if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") // { // sql = @"Insert into WM_BarCodePrintLog // Values // (NEWID(),'{0}','0001','{1}','{2}',GetDate(),null,null)"; // sql = string.Format(sql, grvDetail.GetRowCellValue(i, colLOTNO).ToString(), AppConfig.UserCode // , AppConfig.UserName); // DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, sql); // } // } } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion #region 上传 private void btnUpLoad_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); //显示选择文件对话框 openFileDialog1.InitialDirectory = "c:\\"; openFileDialog1.Filter = "pdf files (*.pdf)|*.pdf|All files (*.*)|*.*"; //所有的文件格式 openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; string filePath = ""; if (openFileDialog1.ShowDialog() == DialogResult.OK) { filePath = openFileDialog1.FileName; //显示文件路径 } else return; string connectionString = AppConfig.GetDataBaseConnectStringByKey("[DB.FTP]"); string[] ftps = connectionString.Split(';'); string ftpServerIP = ftps[0].Split('=')[1]; string ftpRemotePath = ftps[1].Split('=')[1]; string ftpUserID = ftps[2].Split('=')[1]; string ftpPassword = ftps[3].Split('=')[1]; FtpWeb ftpWeb = new FtpWeb(ftpServerIP, ftpRemotePath, ftpUserID, ftpPassword); try { string filename = ""; string ftpURL = "ftp://" + ftpServerIP + "/" + ftpRemotePath + "/"; string[] list = filePath.Split('\\'); filename = list[list.Length - 1]; list = filename.Split('.'); filename = list[list.Length - 2]; try { ftpWeb.Upload(filePath, filename, filename); } catch (Exception ex) { throw new Exception(ex.Message + " 上传出错!"); } ICSITEMLot model = GetModel(grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colID).ToString(), AppConfig.AppConnectString); model.tFileName = filename; Uptdate(model, AppConfig.AppConnectString); ICSBaseSimpleCode.AppshowMessageBox("上传成功 !"); btnRefresh_Click(null, null); } catch (Exception ex) { throw new Exception(ex.Message); } } #endregion #region 下载 private void btnDownLoad_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { #region 下载逻辑 string connectionString = AppConfig.GetDataBaseConnectStringByKey("[DB.FTP]"); string[] ftps = connectionString.Split(';'); string ftpServerIP = ftps[0].Split('=')[1]; string ftpRemotePath = ftps[1].Split('=')[1]; string ftpUserID = ftps[2].Split('=')[1]; string ftpPassword = ftps[3].Split('=')[1]; FtpWeb ftpWeb = new FtpWeb(ftpServerIP, ftpRemotePath, ftpUserID, ftpPassword); try { string ftpURL = "ftp://" + ftpServerIP + "/" + ftpRemotePath + "/" + grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, coltFileName).ToString() + "/"; ICSITEMLot model = GetModel(grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colID).ToString(), AppConfig.AppConnectString); if (string.IsNullOrEmpty(model.tFileName)) { ICSBaseSimpleCode.AppshowMessageBox("暂无文档!"); return; } //string path = System.Windows.Forms.Application.StartupPath + @"\PDF"; //DirectoryInfo directoryInfo = new DirectoryInfo(path); //if (!Directory.Exists(path)) //{ // Directory.CreateDirectory(path); //} SaveFileDialog save = new SaveFileDialog(); save.FileName = model.tFileName + ".pdf"; save.Filter = "PDF文件(*.pdf)|.pdf"; if (save.ShowDialog() == DialogResult.OK) { string filePaths = save.FileName; ftpWeb.Download(Path.GetDirectoryName(filePaths), Path.GetFileName(filePaths), Path.GetFileNameWithoutExtension(filePaths)); } #region 现逻辑 //string filePaths = path + @"\" + model.tFileName + ".pdf"; //ftpWeb.Download(path, grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, coltFileName).ToString() + ".pdf", grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, coltFileName).ToString()); ////string filePaths = @"C:\Users\Administrator.UX7663JVU2X64C5\Desktop\123.pdf"; //AxAcroPDFLib.AxAcroPDF axAcroPDF = new AxAcroPDFLib.AxAcroPDF(); //((System.ComponentModel.ISupportInitialize)(axAcroPDF)).BeginInit(); //axAcroPDF.Dock = DockStyle.Fill; //this.Controls.Add(axAcroPDF); //axAcroPDF.Location = new System.Drawing.Point(0, 24); //((System.ComponentModel.ISupportInitialize)(axAcroPDF)).EndInit(); //axAcroPDF.LoadFile(filePaths); //axAcroPDF.setShowToolbar(true); //axAcroPDF.setPageMode("thumbs"); //axAcroPDF.setPageMode("none"); //axAcroPDF.Show(); //System.Diagnostics.Process.Start(filePaths); #endregion } catch (Exception ex) { throw new Exception(ex.Message); } #endregion } #endregion public static ICSITEMLot GetModel(string ID, string Appconstr) { FramDataContext db = new FramDataContext(Appconstr); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { ICSITEMLot model = new ICSITEMLot(); var line = db.ICSITEMLot.SingleOrDefault(a => a.ID == ID); if (line != null) model = line; return model; } catch (Exception ex) { throw new Exception(ex.Message); } } public static void Uptdate(ICSITEMLot data, string dsconn) { FramDataContext db = new FramDataContext(dsconn); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { var line = db.ICSITEMLot.SingleOrDefault(a => a.ID == data.ID); line.tFileName = data.tFileName; //db.ICSITEMLot.InsertOnSubmit(line); db.SubmitChanges(); db.Transaction.Commit(); } catch (Exception ex) { db.Transaction.Rollback(); throw ex; } } #region private void btnDelete_Click(object sender, EventArgs e) { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定清除该文件吗?清除后无法恢复") != DialogResult.OK) { for (int i = 0; i < grvDetail.RowCount; i++) { grvDetail.SetRowCellValue(i, colisSelect, ""); } 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; } string connectionString = AppConfig.GetDataBaseConnectStringByKey("[DB.FTP]"); string[] ftps = connectionString.Split(';'); string ftpServerIP = ftps[0].Split('=')[1]; string ftpRemotePath = ftps[1].Split('=')[1]; string ftpUserID = ftps[2].Split('=')[1]; string ftpPassword = ftps[3].Split('=')[1]; FtpWeb ftpWeb = new FtpWeb(ftpServerIP, ftpRemotePath, ftpUserID, ftpPassword); try { for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { ICSITEMLot model = GetModel(grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colID).ToString(), AppConfig.AppConnectString); if (string.IsNullOrEmpty(model.tFileName)) { ICSBaseSimpleCode.AppshowMessageBox("暂无文档!"); return; } ftpWeb.Delete(model.tFileName, model.tFileName + ".pdf"); ftpWeb.RemoveDirectory(model.tFileName); DeletePDF(grvDetail.GetRowCellValue(i, colLOTNO).ToString(), AppConfig.AppConnectString); } } ICSBaseSimpleCode.AppshowMessageBox("清除成功 !"); btnRefresh_Click(null, null); } catch (Exception ex) { throw new Exception(ex.Message); } } #endregion public static void DeletePDF(string LotNO, string dsconn) { FramDataContext db = new FramDataContext(dsconn); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { var line = db.ICSITEMLot.SingleOrDefault(a => a.LotNO == LotNO); if (line != null) { line.tFileName = null; } db.SubmitChanges(); db.Transaction.Commit(); } catch (Exception ex) { db.Transaction.Rollback(); throw new Exception(ex.Message); } } private void btnrePrint_Click(object sender, EventArgs e) { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } if (grvDetail.FocusedRowHandle < 0) { return; } try { string lotno = ""; string message = ""; for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { lotno = grvDetail.GetRowCellValue(i, colLOTNO).ToString(); string sql = @"SELECT DISTINCT x.ISCOM FROM ICSLOTSIMULATION x -- INNER JOIN ICSLOTONWIP y ON x.LOTNO=y.LOTNO AND x.OPCODE=y.OPCODE -- INNER JOIN ICSLOTONWIPCheck z ON y.ID=z.ONWIPID WHERE x.ISCOM='1' AND x.LOTNO='{0}' "; sql = string.Format(sql, lotno); DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0]; if (dt == null || dt.Rows.Count <= 0) { if (message == "") { message = "条码:" + grvDetail.GetRowCellValue(i, colLOTNO).ToString(); } else { message += ";条码:" + grvDetail.GetRowCellValue(i, colLOTNO).ToString(); } } } } if (message == "") { List barCodeList = new List(); List InfoList = new List(); for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { string barCode = grvDetail.GetRowCellValue(i, colLOTNO).ToString(); PrintPara printInfo = new PrintPara(); printInfo.PrintKey = "LOTNO"; printInfo.PrintValues = new object[] { barCode }; barCodeList.Add(printInfo); ICSITEMLot Info = new ICSITEMLot(); Info.LotNO = grvDetail.GetRowCellValue(i, colLOTNO).ToString(); Info.lastPrintUSERID = AppConfig.UserId; Info.lastPrintTime = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss"); Info.WorkPoint = AppConfig.WorkPointCode; InfoList.Add(Info); } } if (barCodeList.Count == 0) { ICSBaseSimpleCode.AppshowMessageBox("没有选择数据"); return; } FormPrintDialog printDialog = new FormPrintDialog("025", "ICSProduct", barCodeList, false, null); printDialog.ShowDialog(); //更新打印信息 ICSRdrecord2LOTBLL.updatePrint(InfoList, AppConfig.AppConnectString); } else { ICSBaseSimpleCode.AppshowMessageBox(message + "最后一道工序未检验完成,不能打印!"); return; } } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } private void btnCancelPrint_Click(object sender, EventArgs e) { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } if (grvDetail.FocusedRowHandle < 0) { return; } try { List barCodeList = new List(); List InfoList = new List(); for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { string sql = @" SELECT A.LotNO, A.TYPE, D.LotNO AS BarCode, A.TransNO, B.MOCODE, E.ISCOM, G.Result, G.TResult FROM ICSITEMLot A LEFT JOIN ICSMO B ON B.MOCODE = A.TransNO AND B.MOSEQ = A.TransLine LEFT JOIN ICSWareHouseLotInfo D ON D.LotNO = A.LotNO LEFT JOIN ICSLOTSIMULATION E ON E.LOTNO = A.LotNO LEFT JOIN ICSLOTONWIP F ON F.LOTNO = E.LOTNO AND F.OPCODE = E.OPCODE LEFT JOIN ICSLOTONWIPCheck G ON G.ONWIPID=F.ID WHERE A.LotNO = '{0}' AND A.WorkPoint = '{1}' AND A.TYPE = '工单' AND F.EATTRIBUTE1 IS NULL "; sql = string.Format(sql, grvDetail.GetRowCellValue(i, colLOTNO).ToString(), AppConfig.WorkPointCode); DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0]; if (dt.Rows.Count > 0 && dt != null) { if (!(dt.Rows[0]["Result"].ToString() == "不合格" && dt.Rows[0]["TResult"].ToString() == "报废")) { ICSBaseSimpleCode.AppshowMessageBox("当前工序检验不为不合格且钉钉状态不为报废,不能打印标签,请确认"); return; } } string barCode = grvDetail.GetRowCellValue(i, colLOTNO).ToString(); PrintPara printInfo = new PrintPara(); printInfo.PrintKey = "LOTNO"; printInfo.PrintValues = new object[] { barCode }; barCodeList.Add(printInfo); ICSITEMLot Info = new ICSITEMLot(); Info.LotNO = grvDetail.GetRowCellValue(i, colLOTNO).ToString(); Info.lastPrintUSERID = AppConfig.UserId; Info.lastPrintTime = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss"); Info.WorkPoint = AppConfig.WorkPointCode; InfoList.Add(Info); } } if (barCodeList.Count == 0) { ICSBaseSimpleCode.AppshowMessageBox("没有选择数据"); return; } FormPrintDialog printDialog = new FormPrintDialog("024", "ICSProduct", barCodeList, false, null); printDialog.ShowDialog(); //更新打印信息 ICSRdrecord2LOTBLL.updatePrint(InfoList, AppConfig.AppConnectString); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } } }