using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using gregn6Lib; using SQLHelper; using DBUtility; using System.Threading; using System.IO; namespace WarM { public partial class Sc_ICMOToBarCode : Form { public Sc_ICMOToBarCode() { InitializeComponent(); } public frmBillQueryCondition_New frmCondition; public string ViewName = "Sc_ICMOBillStatus_Tmp"; public string ModCaption = "快速生成条码"; public const string ModName = "3722"; public const string ModRightName = "Sc_ICMOToBarCode"; public const string ModRightNameEdit = ModRightName + "_Edit"; public const string ModRightNameCheck = ModRightName + "_Check"; public const string ModRightNameClose = ModRightName + "_Close"; public const string ModRightNameDelete = ModRightName + "_Delete"; public DAL.ClsGy_BarCodeBill_Ctl oBar = new DAL.ClsGy_BarCodeBill_Ctl(); SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); //DAL.ClsGy_ICBomBill oBill = new DAL.ClsGy_ICBomBill(); //public Gy_ICBomBill oFrm; public int selectRow = 0; public int selectRow2 = 0; public string sDlgWhere = ""; //外窗体递入 public DBUtility.ClsPub.Enum_BillStatus BillStatus; public Int64 HInterID = 0; public const string ModName1 = "3783"; public Int64 HInterID_TTM = 0; public string HBillNo_TTM = ""; ClsCN SubCn = new ClsCN(); Pub_Class.ClsGridViewSum oSumGrid = new Pub_Class.ClsGridViewSum(); // private void initGrid() { DBUtility.Xt_BaseBillFun.initGridList(grdMain, this.Name); } // private void Display() { DataSet DSet; string sSql = ""; string sFastSQL = ""; //生产订单号 //if (txtHICMOBillNo.Text.Trim() != "") //{ // sFastSQL = sFastSQL + " and HICMOBillNo like '%" + txtHICMOBillNo.Text + "%'"; //} string HICMOBillNo = ""; HICMOBillNo = txtHICMOBillNo.Text.Trim().ToString(); //销售订单号 string HSeOrderBillNo = ""; HICMOBillNo = txtHSeOrderBillNo.Text.Trim().ToString(); //物料 //if (txtHMaterID.Text.Trim() != "") //{ // sFastSQL = sFastSQL + " and HMaterName like '%" + txtHMaterID.Text + "%'"; //} string HMaterName = ""; HMaterName = txtHMaterID.Text.Trim().ToString(); //物料代码 //机台 //if (txtHSourceID.Text.Trim() != "") //{ // sFastSQL = sFastSQL + " and HSourceName like '%" + txtHSourceID.Text + "%'"; //} string HSourceName = ""; HSourceName = txtHSourceID.Text.Trim().ToString(); //职员 string HEmpName = ""; HEmpName = txtHEmpID.Text.Trim().ToString(); //判断开始日期 //if (dtpHBeginDate.Checked) //{ // sFastSQL = sFastSQL + " and 日期>='" + dtpHBeginDate.Value.ToShortDateString() + "'"; //} string HBeginDate = ""; HBeginDate = dtpHBeginDate.Value.ToShortDateString(); //判断结束日期 //if (dtpHEndDate.Checked) //{ // sFastSQL = sFastSQL + " and 日期<='" + dtpHEndDate.Value.ToShortDateString() + "'"; //} //string HEndDate = ""; //HEndDate = dtpHEndDate.Value.ToShortDateString(); //if (sFastSQL.Trim() == "") //{ // MessageBox.Show("没有输入条件!"); // return; //} //过滤条件 // DSet = SubCn.RunProcReturn("exec h_p_KSTMSC '" + HSeOrderBillNo + "' ,'" + HICMOBillNo + "' , '" + HMaterName + "' , '" + HSourceName + "' ,'" + HEmpName + "' ,'" + HBeginDate + "'", "h_p_KSTMSC", ref DBUtility.ClsPub.sExeReturnInfo); //生成首行标题 if (DSet == null) //if (DSet == null|| DSet.Tables[0].Rows.Count == 0) { MessageBox.Show("没有返回任何结果,请在过滤框中点击【恢复】按钮,尝试再次查询!" + DBUtility.ClsPub.sExeReturnInfo); return; } else { grdMain.DataSource = DSet.Tables[0].DefaultView; //把当前单据ID 存到一个按钮里面 刷新时每次存一遍 if (DSet.Tables[0].Rows.Count > 0) { txtHMaterID.Tag = DBUtility.ClsPub.isLong(grdMain.Rows[0].Cells["HInterID"].Value); txtHMiniQty.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[0].Cells["标准装箱"].Value); //txtHMaterID.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[0].Cells["物料编码"].Value); txtHMaterModel.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[0].Cells["规格型号"].Value); txtHMaterName.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[0].Cells["物料名称"].Value); } else { } } // //标准装箱 //for (int i = 0; i < grdMain.SelectedRows.Count; i++) //{ // txtHMiniQty.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.SelectedRows[i].Index].Cells[Fun_GetCol("HMiniQty")].Value); // if (txtHMiniQty.Text.Trim() != "") // { // txtHMiniQty.Enabled = false; // } //} //冻结 //int FrCol = DBUtility.ClsPub.isLong(frmCondition.txtFrozenCol.Text); //string s = frmCondition.cmbHComplete.Text; //DBUtility.Xt_BaseBillFun.DisplayGrid(grdMain, this.Name, s,FrCol); //画线 GraphLine(); // } // private void timer1_Tick(object sender, EventArgs e) { timer1.Enabled = false; initGrid(); Display(); } private void tc_Click(object sender, EventArgs e) { this.Close(); } private void sx_Click(object sender, EventArgs e) { timer1.Enabled = true; } private void dj_Click(object sender, EventArgs e) { Sub_ShowBill(); } //显示单据 private void Sub_ShowBill() { //Int64 lngBillKey = 0; //if (grdMain.CurrentRow == null) // return; //lngBillKey =DBUtility.ClsPub.isLong(grdMain.Rows[grdMain.CurrentRow.Index].Cells[Fun_GetCol("hmainid")].Value); //if (lngBillKey == 0) // return; //DAL.ClsGy_ICBomBill oBill = new DAL.ClsGy_ICBomBill(); //if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo)) //{ // oFrm = new Gy_ICBomBill(); // oFrm.BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_View; // oFrm.BillOld = oBill; // oFrm.ShowDialog(); // if (oFrm.BillChange) // { // if (MessageBox.Show("单据列表已经发生变化,是否刷新", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) // { // timer1.Enabled = true; // } // } //} //else //{ // MessageBox.Show("单据未找到", "提示"); //} //oBill = null; } // private Int32 Fun_GetCol(string sCol) { return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdMain); } private Int32 Fun_GetColList(string sCol) { return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdList); } // private void Sc_ICMOToBarCode_Load(object sender, EventArgs e) { // //frmCondition = new frmBillQueryCondition_New(); oSumGrid.ogrdMain = grdMain; this.Text = ModCaption; //lblCaption.Text = ModCaption; initGrid(); cmbHBarCodeType.SelectedIndex = 0; dtpHBeginDate.Value = DateTime.Today; string HUserName = ""; HUserName = ClsPub.isStrNull(DBUtility.ClsPub.CurUserName); Int64 HUserID = 0; HUserID = ClsPub.isLong(DBUtility.ClsPub.CurUserID); DataSet DSet; DSet = oCn.RunProcReturn("Select HEmpID from gy_czygl Where czymc='" + HUserName + "'", "gy_czygl", ref DBUtility.ClsPub.sExeReturnInfo); if (DSet == null) //if (DSet == null|| DSet.Tables[0].Rows.Count == 0) { MessageBox.Show("没有返回任何结果,请在过滤框中点击【恢复】按钮,尝试再次查询!" + DBUtility.ClsPub.sExeReturnInfo); return; } else { //grdMain.DataSource = DSet.Tables[0].DefaultView; //把当前单据ID 存到一个按钮里面 刷新时每次存一遍 if (DSet.Tables[0].Rows.Count > 0) { txtHEmpID.Tag = DBUtility.ClsPub.isStrNull(DSet.Tables[0].Rows[0]["HEmpID"]); } else { } } } private void grdMain_DblClick(object sender, EventArgs e) { Sub_ShowBill(); } private void cx_Click(object sender, EventArgs e) { //frmCondition = new frmBillQueryCondition_New(); //SetCondition(frmCondition, ViewName, this.Name); //frmCondition.ShowDialog(); //if (frmCondition.Tag.ToString() == "OK") //{ // Display(); //} } //public void SetCondition(frmBillQueryCondition_New frmCondition, string ViewName, string Name) //{ // frmCondition.Tag = ""; // frmCondition.ViewName = ViewName; // frmCondition.ModName = Name; //} private void xz_Click(object sender, EventArgs e) { // //oFrm = new Gy_ICBomBill(); //oFrm.ShowDialog(); } private void sc_Click(object sender, EventArgs e) { Sub_DeleteBill(); } //删除 private void Sub_DeleteBill() { // //编辑权限 if (!DBUtility.ClsPub.Security_Log(ModRightNameEdit, 1, true, DBUtility.ClsPub.CurUserName)) { return; } // //Int64 lngBillKey = 0; //if (grdMain.CurrentRow == null) // return; //lngBillKey = DBUtility.ClsPub.isLong(grdMain.Rows[grdMain.CurrentRow.Index].Cells[Fun_GetCol("hmainid")].Value); //if (lngBillKey == 0) // return; //DAL.ClsGy_BarCodeBill_View oBill = new DAL.ClsGy_BarCodeBill_View(); //DAL.ClsGy_BarCodeBill_Ctl oBillC = new DAL.ClsGy_BarCodeBill_Ctl(); //if (oBill.GetInfoByID(lngBillKey)) //{ // if (MessageBox.Show("确定要删除当前单据?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK) // { // if (!oBillC.DeleteByID(lngBillKey)) // { // MessageBox.Show(DBUtility.ClsPub.sExeReturnInfo, "提示"); // return; // } // else // { // Display(); // } // } //} //else //{ // MessageBox.Show("单据未找到", "提示"); //} Int64 lngBillKey = 0; if (grdMain.CurrentRow == null) return; if (MessageBox.Show("确定要删除所选单据?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { for (int i = 0; i <= grdMain.SelectedRows.Count - 1; i++) { lngBillKey = DBUtility.ClsPub.isLong(grdMain.SelectedRows[i].Cells[Fun_GetCol("hmainid")].Value); if (lngBillKey == 0) return; DAL.ClsGy_BarCodeBill_View oBill = new DAL.ClsGy_BarCodeBill_View(); DAL.ClsGy_BarCodeBill_Ctl oBillC = new DAL.ClsGy_BarCodeBill_Ctl(); if (oBill.GetInfoByID(lngBillKey)) { try { oBillC.DeleteByID(lngBillKey); } catch (Exception ex) { MessageBox.Show("删除失败,条码" + grdMain.SelectedRows[i].Cells[Fun_GetCol("条码编号")].Value + "已被使用", "提示"); Display(); return; } if (oBillC.DeleteByID(lngBillKey) != true) { MessageBox.Show("删除失败,原因:" + DBUtility.ClsPub.sExeReturnInfo, "提示"); return; } } else { MessageBox.Show("单据未找到!", "提示"); return; } } } MessageBox.Show("删除成功!", "提示"); Display(); } private void timer2_Tick(object sender, EventArgs e) { //timer2.Enabled = false; //frmCondition = new frmBillQueryCondition_New(); //SetCondition(frmCondition, ViewName, this.Name); //frmCondition.ShowDialog(); //if (frmCondition.Tag.ToString() == "OK") //{ // timer1.Enabled = true; //} } private void bclk_Click(object sender, EventArgs e) { //保存列宽 DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name); } private void mrlk_Click(object sender, EventArgs e) { DBUtility.Xt_BaseBillFun.DefaultGridView(grdMain, this.Name); } // private void GraphLine() { //int MainIDCol = Fun_GetCol("hmainid"); //int SubIDCol = Fun_GetCol("hsubid"); //string s = frmCondition.cmbHComplete.Text; //long n=0; //DBUtility.Xt_BaseBillFun.GraphLine(grdMain, MainIDCol, SubIDCol, s,ref n); //显示 //lbldj.Text = "查询出 " + n.ToString() + " 张单据"; //lbljl.Text = "共有 " + grdMain.RowCount.ToString() + " 条记录"; } //审核 private void sh_Click(object sender, EventArgs e) { this.Sub_CheckBill(); } //审核单据 private void Sub_CheckBill() { //审核权限 if (!DBUtility.ClsPub.Security_Log(ModRightNameCheck, 1, true, DBUtility.ClsPub.CurUserName)) { return; } // Int64 lngBillKey = 0; if (grdMain.CurrentRow == null) return; lngBillKey = DBUtility.ClsPub.isLong(grdMain.Rows[grdMain.CurrentRow.Index].Cells[Fun_GetCol("hmainid")].Value); if (lngBillKey == 0) return; DAL.ClsGy_ICBomBill oBill = new DAL.ClsGy_ICBomBill(); //查看是否已审核,关闭,作废 if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo)) { if (oBill.omodel.HChecker.Trim() != "") { MessageBox.Show("单据已审核!不能再次审核", "提示"); return; } } else { MessageBox.Show("单据不存在!原因:" + DBUtility.ClsPub.sExeReturnInfo, "提示"); return; } //审核 if (oBill.CheckBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo) == true) { MessageBox.Show("审核成功!", "提示"); return; } else { MessageBox.Show("审核失败!原因:" + DBUtility.ClsPub.sExeReturnInfo, "提示"); return; } } //反审单据 private void Sub_AbandonCheck() { //审核权限 if (!DBUtility.ClsPub.Security_Log(ModRightNameCheck, 1, true, DBUtility.ClsPub.CurUserName)) { return; } // Int64 lngBillKey = 0; if (grdMain.CurrentRow == null) return; lngBillKey = DBUtility.ClsPub.isLong(grdMain.Rows[grdMain.CurrentRow.Index].Cells[Fun_GetCol("hmainid")].Value); if (lngBillKey == 0) return; DAL.ClsGy_ICBomBill oBill = new DAL.ClsGy_ICBomBill(); //查看是否已审核,关闭,作废 if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo)) { if (oBill.omodel.HChecker.Trim() == "") { MessageBox.Show("单据未审核!不需要反审核!", "提示"); return; } } else { MessageBox.Show("单据不存在!原因:" + DBUtility.ClsPub.sExeReturnInfo, "提示"); return; } //反审核 if (oBill.AbandonCheck(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo) == true) { MessageBox.Show("反审核成功!", "提示"); return; } else { MessageBox.Show("反审核失败!原因:" + DBUtility.ClsPub.sExeReturnInfo, "提示"); return; } } //反审核 private void qsh_Click(object sender, EventArgs e) { Sub_AbandonCheck(); } private void GraphicsGrid() { DBUtility.Xt_BaseBillFun.GraphicsGrid(grdMain); } #region //打印设置 GridppReport Report; //预览 int CurRows = 0; private void yl_Click(object sender, EventArgs e) { //选择打印模板 BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp(); oFrm.sBillName = ModName; oFrm.sBillModel = ModCaption; oFrm.ShowDialog(); if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK) { Sub_SetReport(oFrm.sOpenTmp); Report.PrintPreview(false); Thread.Sleep(1000); } } private void Sub_SetReport(string sOpenTmp) { //判断行数 //for (int i = 0; i < grdList.Rows.Count; i++) //{ // grdList.Rows[i].Cells[0].Value = ""; //} //for (int i = 0; i < grdList.SelectedRows.Count; i++) //{ // grdList.Rows[grdMain.SelectedRows[i].Index].Cells[0].Value = "*"; //} // Report = new GridppReport(); Report.LoadFromFile(DBUtility.ClsPub.AppPath + @"\" + sOpenTmp + ".grf"); //here . Report.BeforePostRecord += new _IGridppReportEvents_BeforePostRecordEventHandler(ReportBeforePostRecord); Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTable); } //填入单据表头信息 private void ReportBeforePostRecord()//your report?kao { try { //Report.FieldByName("物料代码").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("物料代码")].Value.ToString(); //Report.FieldByName("物料名称").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("物料名称")].Value.ToString(); //Report.FieldByName("规格型号").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("规格型号")].Value.ToString(); ////Report.FieldByName("自定义规格").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("自定义规格")].Value.ToString(); //Report.FieldByName("条码编号").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("条码编号")].Value.ToString(); //Report.FieldByName("数量").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("数量")].Value.ToString(); //Report.FieldByName("批次").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("批号")].Value.ToString(); //Report.FieldByName("源单单号").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("源单单号")].Value.ToString(); //Report.FieldByName("销售订单号").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("销售订单号")].Value.ToString(); //Report.FieldByName("采购订单号").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("采购订单号")].Value.ToString(); //Report.FieldByName("供应商").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("往来单位")].Value.ToString(); //Report.FieldByName("生产车间").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("生产车间")].Value.ToString(); //Report.FieldByName("备注").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("备注")].Value.ToString(); //Report.FieldByName("总托数").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("总托数")].Value.ToString(); //Report.FieldByName("托号").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("托号")].Value.ToString(); } catch (Exception e) { MessageBox.Show("打印失败!表头:" + e.Message); } //CurRows = CurRows + 1; } private void ReportFetchRecordByDataTable() { try { DataTable ds = new DataTable(); BLL.Utility.FillRecordToReport_Sel(Report, grdList, ds, Fun_GetCol("选择")); } catch (Exception e) { MessageBox.Show("打印失败!表体:" + e.Message); } } #endregion // private void grdMain_Paint(object sender, PaintEventArgs e) { GraphicsGrid(); } private void dy_Click(object sender, EventArgs e) { DAL.ClsGy_BarCodeBill_Ctl oBar = new DAL.ClsGy_BarCodeBill_Ctl(); //打印前判断条码是否已打印过 string sBarCode = ""; string sRelQty = ""; for (int i = 0; i < grdMain.SelectedRows.Count; i++) { sBarCode = sBarCode + "," + DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.SelectedRows[i].Index].Cells[Fun_GetCol("条码编号")].Value); } //if (oBar.Set_BPrintQty(sBarCode.Substring(1), ref sRelQty)) //{ // MessageBox.Show(sRelQty); // return; //} //选择打印模板 BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp(); //DAL.ClsGy_BarCodeBill_Ctl oBar = new DAL.ClsGy_BarCodeBill_Ctl(); oFrm.sBillName = ModName; oFrm.sBillModel = ModCaption; oFrm.ShowDialog(); if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK) { Sub_SetReport(oFrm.sOpenTmp); Report.Print(false); //oBar.Set_PrintQty(DBUtility.ClsPub.isStrNull(grdMain.Rows[CurRows].Cells[Fun_GetCol("条码编号")].Value)); Thread.Sleep(1000); } //批量更新条码打印次数 oBar.Set_EPrintQty(sBarCode.Substring(1)); } private void dy2_Click(object sender, EventArgs e) { //选择打印模板 BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp(); DAL.ClsGy_BarCodeBill_Ctl oBar = new DAL.ClsGy_BarCodeBill_Ctl(); oFrm.sBillName = ModName; oFrm.sBillModel = ModCaption; oFrm.ShowDialog(); if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK) { // for (int i = 0; i <= grdMain.SelectedRows.Count - 1; i++) { selectRow = i; selectRow2 = i + 1; Sub_SetReport(oFrm.sOpenTmp); Report.Print(false); oBar.Set_PrintQty(DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("条码编号")].Value)); // if (selectRow2 > grdMain.SelectedRows.Count - 1) { } else { oBar.Set_PrintQty(DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i + 1].Cells[Fun_GetCol("条码编号")].Value)); } Thread.Sleep(1000); i++; } } } private void yc_Click(object sender, EventArgs e) { DataGridViewToExcel2(grdMain, this.Text, this.Text); } /// /// 网格 导出EXCEL 网格,文件名,标题名 /// public static void DataGridViewToExcel2(DataGridView grdMain, string sText, string sBTText) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Execl文件(*.xls)|*.xls"; saveFileDialog.FilterIndex = 0; saveFileDialog.RestoreDirectory = true; saveFileDialog.CreatePrompt = true; saveFileDialog.Title = "数据视图导出EXCEL文件"; saveFileDialog.FileName = sText; //saveFileDialog.ShowDialog(); if (saveFileDialog.ShowDialog() == DialogResult.OK) { Stream myStream; myStream = saveFileDialog.OpenFile(); StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.GetEncoding("gb2312")); string str = ""; DateTime start = DateTime.Now; try { if (sBTText != "") { sw.WriteLine(sBTText); } //写标题 bool sFirstCol = true; for (int i = 0; i < grdMain.ColumnCount; i++) { if (i > 0 && grdMain.Columns[i].HeaderText.Substring(0, 1) != "h" && grdMain.Columns[i].HeaderText.Substring(0, 1) != "H" && sFirstCol != true) { str += "\t"; } if (grdMain.Columns[i].HeaderText.Substring(0, 1) != "h" && grdMain.Columns[i].HeaderText.Substring(0, 1) != "H") { sFirstCol = false; str += grdMain.Columns[i].HeaderText; } } str = str.Replace("\n", ""); sw.WriteLine(str); //写内容 for (int j = 0; j < grdMain.Rows.Count; j++) { string tempStr = ""; sFirstCol = true; for (int k = 0; k < grdMain.Columns.Count; k++) { if (k > 0 && grdMain.Columns[k].HeaderText.Substring(0, 1) != "h" && grdMain.Columns[k].HeaderText.Substring(0, 1) != "H" && sFirstCol != true) { tempStr += "\t"; } if (grdMain.Columns[k].HeaderText.Substring(0, 1) != "h" && grdMain.Columns[k].HeaderText.Substring(0, 1) != "H") { sFirstCol = false; if (grdMain.Rows[j].Cells[k].Value == null) { tempStr += string.Empty; } else { tempStr += grdMain.Rows[j].Cells[k].Value.ToString(); } } } tempStr = tempStr.Replace("\n", ""); sw.WriteLine(tempStr); } sw.Close(); myStream.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { sw.Close(); myStream.Close(); } MessageBox.Show("将此工作表导出为excel共耗时:" + DateTime.Now.Subtract(start).TotalMilliseconds.ToString() + "毫秒"); } } private void cmdHSaveBill_Click(object sender, EventArgs e) { Display(); } string TTM = ""; //托条码 string HTTMNumber = ""; string HICMOBillNo = ""; //生产订单号 int TLSH = 0; string TLSH2 = ""; string HOrgNumber = ""; //=======生成 唯一码 和 托条码 、组托单 private void Sub_SaveBarCode()//分配时 要考虑 订单剩余数量已经是 负数的情况 { try { string HMaterNumber = ""; string HBatchNo = ""; string HDate = ""; string HYear = ""; string HPeriod = ""; string HDay = ""; string HTMNumber = ""; string HOrgNumber = ""; DataSet Ds; Int64 LSH = 0; //流水号 string LSH2 = ""; //流水号转换成字符 double HZXQty = 0; //装箱数量 double HDDQty = 0; //订单数量 double HBQty = 0; //箱数 int k = 0; int n = 0; //同一批生成条码中的第几条 string WeiShu = ""; //尾数 int LSHlen = 6; //流水号长度 string TM = ""; //条码 string sPackBarCode = ""; string HPrdDate = ""; string HBC = ""; string HDate1 = ""; DataSet Ds99; //箱号 string HXH = ""; //箱号流水号 Int64 LSH3 = 0; //流水号 string LSH4 = ""; //流水号转换成字符 //机台 string HJT = ""; HDate = DateTime.Now.ToString(); //判断当前时间是否在工作时间段内 string _strWorkingDayAM = "07:30";//工作时间上午08:30 string _strWorkingDayPM = "19:30"; string _strWorkingDayTM = "00:00"; string _strWorkingDaySM = "23:59"; TimeSpan dspWorkingDayAM = DateTime.Parse(_strWorkingDayAM).TimeOfDay; TimeSpan dspWorkingDayPM = DateTime.Parse(_strWorkingDayPM).TimeOfDay; TimeSpan dspWorkingDayTM = DateTime.Parse(_strWorkingDayTM).TimeOfDay; TimeSpan dspWorkingDaySM = DateTime.Parse(_strWorkingDaySM).TimeOfDay; //string time1 = "2017-2-17 8:10:00"; DateTime t1 = Convert.ToDateTime(HDate); TimeSpan dspNow = t1.TimeOfDay; HDate1 = Convert.ToDateTime(HDate).ToShortDateString(); //1.正常上班时间 就是白班 如果不是礼拜天 就往前提前一天 if (dspNow > dspWorkingDayAM && dspNow < dspWorkingDayPM) { HBC = "白班"; DataSet DSet2 = oCn.RunProcReturn("select * from Gy_FactoryDayOff Where HFactoryDayOffDate='" + HDate1.ToString() + "'", "Gy_FactoryDayOff", ref DBUtility.ClsPub.sExeReturnInfo); if (DSet2 == null || DSet2.Tables[0].Rows.Count == 0) { HPrdDate = HDate; } else { HPrdDate = DBUtility.ClsPub.isStrNull(DSet2.Tables[0].Rows[0]["HNoFactoryDayOffDate"]); } } //2.大于19:30 小于24:00 夜班 if (dspNow > dspWorkingDayPM && dspNow < dspWorkingDaySM) { HBC = "夜班"; DataSet DSet2 = oCn.RunProcReturn("select * from Gy_FactoryDayOff Where HFactoryDayOffDate='" + HDate1.ToString() + "'", "Gy_FactoryDayOff", ref DBUtility.ClsPub.sExeReturnInfo); if (DSet2 == null || DSet2.Tables[0].Rows.Count == 0) { HPrdDate = HDate; } else { HPrdDate = DBUtility.ClsPub.isStrNull(DSet2.Tables[0].Rows[0]["HNoFactoryDayOffDate"]); } } //3.大于00:00 小于7:30 白班 先减一天 再判断减了一天的日期是不是厂休日期 if (dspNow > dspWorkingDayTM && dspNow < dspWorkingDayAM) { HBC = "夜班"; HDate = DBUtility.ClsPub.isStrNull(DBUtility.ClsPub.isDate(HDate).AddDays(-1)); HDate = DBUtility.ClsPub.isDate(HDate).ToShortDateString(); DataSet DSet2 = oCn.RunProcReturn("select * from Gy_FactoryDayOff Where HFactoryDayOffDate='" + HDate.ToString() + "'", "Gy_FactoryDayOff", ref DBUtility.ClsPub.sExeReturnInfo); if (DSet2 == null || DSet2.Tables[0].Rows.Count == 0) { HPrdDate = HDate; } else { HPrdDate = DBUtility.ClsPub.isStrNull(DSet2.Tables[0].Rows[0]["HNoFactoryDayOffDate"]); } } HYear = ClsPub.isDate(HPrdDate).Year.ToString().Substring(2, 2); HPeriod = "0" + ClsPub.isDate(HPrdDate).Month.ToString(); HPeriod = HPeriod.Substring(HPeriod.Length - 2, 2); HDay = "0" + ClsPub.isDate(HPrdDate).Day.ToString(); HDay = HDay.Substring(HDay.Length - 2, 2); long HTMaterID = 0; HTMaterID = ClsPub.isLong(grdMain.Rows[0].Cells[Fun_GetCol("HMaterID")].Value); string sPackStr = "ZXM" + HYear + HPeriod + HDay + HTMaterID; //外箱码 前缀 //获取处理过的日期跟今天差几天 然后加几个+号 TimeSpan HCY = Convert.ToDateTime(HPrdDate) - Convert.ToDateTime(DateTime.Now.ToString()); int a = 1; while (a <= HCY.Days) //当a 小于 差异天数 循环加上 + 号 { HPrdDate = HPrdDate + "+"; a = a + 1; } DataSet DsTM = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sPackStr + "'", "h_p_WMS_GetMaxNo"); //获取最大流水号 //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'"); Int64 TTM_LSH = ClsPub.isLong(DsTM.Tables[0].Rows[0][0]) + 1; sPackBarCode = sPackStr + TTM_LSH.ToString(); //DataSet DSet3 = oCn.RunProcReturn("select * from Gy_FactoryDayOff Where HFactoryDayOffDate='" + HDate1.ToString() + "'", "Gy_FactoryDayOff", ref DBUtility.ClsPub.sExeReturnInfo); //if (DSet3 == null || DSet3.Tables[0].Rows.Count == 0) //{ // sPackBarCode = sPackStr + TTM_LSH.ToString() ; //} //else //{ // sPackBarCode = sPackStr + TTM_LSH.ToString() + "+"; //} oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sPackStr + "'"); //DataSet DSet1 = oCn.RunProcReturn("select * from Gy_FactoryDayOff Where HFactoryDayOffDate='" + HDate.ToString() + "'", "Gy_FactoryDayOff", ref DBUtility.ClsPub.sExeReturnInfo); // //生成首行标题 // if (DSet1 == null || DSet1.Tables[0].Rows.Count == 0) // { // HDate = DateTime.Now.ToShortDateString(); // HYear = ClsPub.isDate(HDate).Year.ToString().Substring(2, 2); // HPeriod = "0" + ClsPub.isDate(HDate).Month.ToString(); // HPeriod = HPeriod.Substring(HPeriod.Length - 2, 2); // HDay = "0" + ClsPub.isDate(HDate).Day.ToString(); // HDay = HDay.Substring(HDay.Length - 2, 2); // long HTMaterID = 0; // HTMaterID = ClsPub.isLong(grdMain.Rows[0].Cells[Fun_GetCol("HMaterID")].Value); // string sPackStr = "ZXM" + HYear + HPeriod + HDay + HTMaterID; //外箱码 前缀 // DataSet DsTM = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sPackStr + "'", "h_p_WMS_GetMaxNo"); //获取最大流水号 //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'"); // Int64 TTM_LSH = ClsPub.isLong(DsTM.Tables[0].Rows[0][0]) + 1; // sPackBarCode = sPackStr + TTM_LSH.ToString(); // oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sPackStr + "'"); // } // else // { // HDate = DBUtility.ClsPub.isStrNull(DSet1.Tables[0].Rows[0]["HNoFactoryDayOffDate"]); // HYear = ClsPub.isDate(HDate).Year.ToString().Substring(2, 2); // HPeriod = "0" + ClsPub.isDate(HDate).Month.ToString(); // HPeriod = HPeriod.Substring(HPeriod.Length - 2, 2); // HDay = "0" + ClsPub.isDate(HDate).Day.ToString(); // HDay = HDay.Substring(HDay.Length - 2, 2); // long HTMaterID = 0; // HTMaterID = ClsPub.isLong(grdMain.Rows[0].Cells[Fun_GetCol("HMaterID")].Value); // string sPackStr = "ZXM" + HYear + HPeriod + HDay + HTMaterID; //外箱码 前缀 // DataSet DsTM = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sPackStr + "'", "h_p_WMS_GetMaxNo"); //获取最大流水号 //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'"); // Int64 TTM_LSH = ClsPub.isLong(DsTM.Tables[0].Rows[0][0]) + 1; // sPackBarCode = sPackStr + TTM_LSH.ToString() + "+" ; // oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sPackStr + "'"); // } //=============根据界面上已经分配的数据进行条码生成和打印。 //获取本次生成的 主内码 Int64 HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo); HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo); Int64 HInterID_TTM = DBUtility.ClsPub.CreateBillID_Prod(ModName1, ref DBUtility.ClsPub.sExeReturnInfo); //组托单内码 string HBillNo_TTM = DBUtility.ClsPub.CreateBillCode_Prod(ModName1, ref DBUtility.ClsPub.sExeReturnInfo, true);//组托单单号 //0 开启事务 oCn.BeginTran(); //00 先生成 唯一的 托条码 //生成一个外箱码 //long HTMaterID = 0; //HTMaterID = ClsPub.isLong(grdMain.Rows[0].Cells[Fun_GetCol("HMaterID")].Value); //string sPackStr = "ZXM" + HYear + HPeriod + HDay + HTMaterID; //外箱码 前缀 //DataSet DsTM = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sPackStr + "'", "h_p_WMS_GetMaxNo"); //获取最大流水号 //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'"); //Int64 TTM_LSH = ClsPub.isLong(DsTM.Tables[0].Rows[0][0]) + 1; //string sPackBarCode = sPackStr + TTM_LSH.ToString(); //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sPackStr + "'"); //MessageBox.Show("11"); oCn.RunProc("insert into Sc_PackUnionBillMain (HYear,HPeriod,HBillType,HInterID,HDate" + ",HBillNo,HBillStatus,HICMOBillNo,HBarCode_Pack,HMaterID,HUnitID,HWeight" + ",HPWeight,HProdOrgID,HDeptID,HEmpID,HSNum,HPackNum,HBarCode_Cus,HBatchNo " + ") values (" + HYear + "," + HPeriod + ",'3783'," + HInterID_TTM + ",'" + HDate + "'" + ", '" + sPackBarCode.ToString() + "',1,'','" + sPackBarCode.ToString() + "',0,0,0" + ",0,1,0,0,0,0,'','')"); //MessageBox.Show("12"); //1.循环网格,根据 本次数量 列 生成 唯一码 for (int j = 0; j < grdMain.Rows.Count; j++) { if (DBUtility.ClsPub.isDoule(grdMain.Rows[j].Cells[Fun_GetCol("本次数量")].Value) > 0) { HMaterNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("物料代码")].Value); HBatchNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("批次")].Value); HOrgNumber = ClsPub.HOrgNumber; //箱号生成规则 日期 + 机台 + 班次 + 物料 只要获取最大的流水号 string sBoxYear; string sBoxPeriod; string sBoxDay; DateTime HBoxDate = DBUtility.ClsPub.isDate(DBUtility.ClsPub.GetServerDate(0)); sBoxYear = HBoxDate.Year.ToString().Substring(2, 2); sBoxPeriod = "0" + HBoxDate.Month.ToString(); sBoxPeriod = HPeriod.Substring(HPeriod.Length - 2, 2); sBoxDay = "0" + HBoxDate.Day.ToString(); sBoxDay = HDay.Substring(HDay.Length - 2, 2); HJT = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("设备")].Value); HXH = sBoxYear + sBoxPeriod + sBoxDay + HBC + HJT + HMaterNumber; Ds99 = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + HXH + "'", "h_p_WMS_GetMaxNo"); //获取最大流水号 LSH3 = ClsPub.isLong(Ds99.Tables[0].Rows[0][0]) + 1; LSH4 = LSH3.ToString(); //HBQty = HBQty + ClsPub.isLong(txtHBQty.Text); HZXQty = DBUtility.ClsPub.isDoule(grdMain.Rows[j].Cells[Fun_GetCol("本次数量")].Value); HDDQty = DBUtility.ClsPub.isDoule(grdMain.Rows[j].Cells[Fun_GetCol("生产订单数量")].Value); HICMOBillNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("生产订单号")].Value); HTMNumber = HOrgNumber + HMaterNumber + HYear + HPeriod + HDay; Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + HTMNumber + "'", "h_p_WMS_GetMaxNo"); //获取最大流水号 LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]); n = 0; LSH2 = LSH.ToString(); while (LSH2.Length < LSHlen) //如果流水号小于6位数前面补0 { LSH2 = "0" + LSH2; } //条码编号 = 条码前缀 + 流水号 TM = HTMNumber + LSH2; if (TM.Trim() == "") { MessageBox.Show("条形码不能为空,不能生成条码!"); return; } string HWei = ""; //尾数 string HBarCode = ""; string HBarCodeType = ""; Int64 HMaterID1 = 0; Int64 HAuxPropID = 0; Int64 HUnitID = 0; double HQty2 = 0; string HBatchNo2 = ""; Int64 HSupID = 0; Int64 HGroupID = 0; int HPrintQty = 0; Int64 HSourceInterID = 0; Int64 HSourceEntryID = 0; string HSourceBillNo = ""; string HSourceBillType = ""; Int64 HBarcodeNo = 0; //托号 Int64 HBarcodeQtys = 0; //总托数 Int64 HDeptID = 0; Int64 HWhID = 0; Int64 HSPID = 0; string HRemark = ""; string HMaterName = ""; string HMaterModel = ""; string HPinfan = ""; string HMTONo = ""; Int64 HCusID = 0; string HCusType = ""; DateTime HEndDate; string HWorkLineName = ""; string HSeOrderBillNo = ""; string HInnerBillNo = ""; Int64 HSourceID = 0; //毛重 Double HMZQty = 0; HMZQty = HZXQty * ClsPub.isDoule(grdMain.Rows[j].Cells[Fun_GetCol("克重")].Value)/1000; HWei = WeiShu; HBarCode = TM; HBarCodeType = ClsPub.isStrNull(cmbHBarCodeType.Text); HMaterID1 = ClsPub.isLong(grdMain.Rows[j].Cells[Fun_GetCol("HMaterID")].Value); HAuxPropID = 0; HUnitID = 0; HQty2 = HZXQty; HBatchNo2 = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("批次")].Value); HSourceInterID = ClsPub.isLong(grdMain.Rows[j].Cells[Fun_GetCol("HSourceInterID")].Value); HSourceEntryID = ClsPub.isLong(grdMain.Rows[j].Cells[Fun_GetCol("HSourceEntryID")].Value); HSourceBillNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("生产订单号")].Value); HSourceBillType = "3710"; HBarcodeQtys = 0; HBarcodeNo = 0; HSupID = 0; HDeptID = 0; HWhID = 0; HSPID = 0; HRemark = ""; HMaterName = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("物料名称")].Value); HMaterModel = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("规格型号")].Value); HPinfan = ""; HMTONo = ""; HCusID = 0; HCusType = ""; HEndDate = ClsPub.isDate(grdMain.Rows[j].Cells[Fun_GetCol("日期")].Value); HWorkLineName = ""; HSeOrderBillNo = ""; HInnerBillNo = sPackBarCode; HSourceID = ClsPub.isLong(txtHSourceID.Tag); oCn.RunProc("insert into Gy_BarCodeBill (HBarCode,HBarCodeType,HMaterID,HUnitID,HQty,HMaterialMQty" + ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" + ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " + ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " + ",HCusID,HCusType,HEndDate,HWorkLineName,HBarCodeDate " + ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HSourceID,HInterID " + ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HPrdDate,HBC,HXH,HInnerBillNo " + ") values (" + "'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID1.ToString() + "," + HUnitID.ToString() + "," + HQty2.ToString() + ", " + HMZQty.ToString() + ",'" + HBatchNo2 + "'," + HSupID.ToString() + "," + HGroupID.ToString() + ",'" + ClsPub.CurUserName + "',getdate()," + HPrintQty.ToString() + "," + HQty2.ToString() + ", " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "','" + HSourceBillType + "','" + HWei + "'" + ", " + HBarcodeQtys.ToString() + "," + HBarcodeNo.ToString() + "," + HDeptID.ToString() + "," + HWhID.ToString() + "," + HSPID.ToString() + ",'" + HRemark + "'" + ", " + HCusID.ToString() + ",'" + HCusType + "','" + HEndDate.ToShortDateString() + "','" + HWorkLineName + "','" + HDate + "'" + ", " + ClsPub.HOrgID.ToString() + "," + ClsPub.HOrgID.ToString() + ",'" + HSeOrderBillNo + "'," + HSourceID.ToString() + "," + HInterID.ToString() + ",'" + HMaterName + "','" + HMaterModel + "','" + HPinfan + "'," + HAuxPropID.ToString() + ",'" + HMTONo + "','" + HPrdDate + "','" + HBC + "','" + LSH4 + "','" + HInnerBillNo + "')"); oCn.RunProc("exec h_p_WMS_SetMaxNo '" + HTMNumber + "'"); oCn.RunProc("exec h_p_WMS_SetMaxNo '" + HXH + "'"); DisplayTM(); } } //2.循环结束后,根据 本次生成的 主内码,从后台数据库获取 条码列表,生成 组托单 和 托条码, 直接调用存储过程 //根据外箱码 写入 组托单主表,组托单子表,SUM,外箱码档案,SUM档案 oCn.RunProc("exec h_p_WMS_PackUnionBill_AddNew_test '" + sPackBarCode + "'," + HInterID_TTM.ToString() + ",'" + DBUtility.ClsPub.CurUserName + "'," + HInterID.ToString()); //根据箱条码,写入 主表,子表 ,箱条码档案 oCn.RunProc("exec h_p_WMS_PackUnionBill_SumSubBill " + HInterID_TTM.ToString() + ",'" + sPackBarCode + "','3783','" + DBUtility.ClsPub.CurUserName + "'," + HInterID.ToString()); //根据箱条码,写入 SUM表,SUM条码档案 sPackBarCode = ""; DataSet DSet = oCn.RunProcReturn("select * from h_v_IF_BarCodeBillList_CS_Test Where HInterID=" + HInterID.ToString() + " and 条码类型 = '托盘条码'", "h_v_IF_BarCodeBillList_CS_Test", ref DBUtility.ClsPub.sExeReturnInfo); //生成首行标题 if (DSet == null) { MessageBox.Show("没有返回任何结果,条码不存在!" + DBUtility.ClsPub.sExeReturnInfo); return; } // grdList.DataSource = DSet.Tables[0].DefaultView; txtHZXQty.Text = ""; //冻结 int FrCol = 0; string s = "是"; DBUtility.Xt_BaseBillFun.DisplayGrid(grdList, this.Name + "grdList", s, FrCol); oCn.Commit(); //DisplayTM(); MessageBox.Show("条码生成完毕!"); //0结束事务 // //Display(); } catch (Exception e ) { //回滚事务 MessageBox.Show("生成条码失败!" + e.Message); Display(); } } private void button4_Click(object sender, EventArgs e) { ////根据本箱数量 来 分配到 每个生产订单上(分配时 要考虑 订单剩余数量已经是 负数的情况) ////如果有标准装箱数量 先默认取标准装箱数量 没有再取手输的本箱数量 ////1.判断本箱数量 必须大于0 //double HZXQty = 0;//整箱数量 //if (txtHZXQty.Text.Trim() != "") //{ // HZXQty = ClsPub.isDoule(txtHZXQty.Text); //} //else //{ // HZXQty = ClsPub.isDoule(txtHMiniQty.Text); //} //if (HZXQty <= 0) //{ // MessageBox.Show("请输入整箱数量!"); // return; //} ////2.刷新网格 ////Display(); ////3.把整箱数量 分配到 网格下面的每一个 生产订单上去。 循环网格 //for(int i =0;i 0) // { // if (HZXQty > DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["生产订单数量"].Value)) // { // HZXQty = HZXQty - DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["生产订单数量"].Value); // grdMain.Rows[i].Cells["本次数量"].Value = DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["生产订单数量"].Value); // //MessageBox.Show("请点击超额生产按钮生成条码!"); // //return; // } // else if (HZXQty == 0) // { // return; // } // else // { // grdMain.Rows[i].Cells["本次数量"].Value = HZXQty; // // // //HZXQty = HZXQty - DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["生产订单数量"].Value); // //grdMain.Rows[i].Cells["本次数量"].Value = DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["生产订单数量"].Value); // } // } // else // { // break; // } //} //Sub_SaveBarCode(); //// //bool flag = this.txtHZXQty.Text.Trim() != ""; //double num; //double HICMOQty = 0; //if (flag) //{ // num = Pub_Class.ClsPub.isDoule(this.txtHZXQty.Text); //} //else //{ // num = Pub_Class.ClsPub.isDoule(this.txtHMiniQty.Text); //} //bool flag2 = num <= 0.0; //if (flag2) //{ // MessageBox.Show("请输入整箱数量!"); //} //else //{ // for (int i = 0; i < this.grdMain.Rows.Count; i++) // { // for (int i1 = 0; i1 < this.grdMain.Rows.Count; i1++) // { // HICMOQty += Pub_Class.ClsPub.isDoule(this.grdMain.Rows[i1].Cells["生产订单数量"].Value); // } // if (HICMOQty < num) // { // MessageBox.Show("请点击超额生产按钮生成条码!"); // break; // } // bool flag3 = num > 0.0; // if (!flag3) // { // break; // } // bool flag4 = num > Pub_Class.ClsPub.isDoule(this.grdMain.Rows[i].Cells["生产订单数量"].Value); // if (!flag4) // { // this.grdMain.Rows[i].Cells["本次数量"].Value = num; // break; // } // num -= Pub_Class.ClsPub.isDoule(this.grdMain.Rows[i].Cells["生产订单数量"].Value); // this.grdMain.Rows[i].Cells["本次数量"].Value = Pub_Class.ClsPub.isDoule(this.grdMain.Rows[i].Cells["生产订单数量"].Value); // } // this.Sub_SaveBarCode(); bool flag = this.txtHZXQty.Text.Trim() != ""; double HICMOQty = 0.0; bool flag5 = flag; double num; if (flag5) { num = ClsPub.isDoule(this.txtHZXQty.Text); } else { num = ClsPub.isDoule(this.txtHMiniQty.Text); } bool flag2 = num <= 0.0; bool flag6 = flag2; if (flag6) { MessageBox.Show("请输入整箱数量!"); } else { for (int i = 0; i < this.grdMain.Rows.Count; i++) { for (int i2 = 0; i2 < this.grdMain.Rows.Count; i2++) { HICMOQty += ClsPub.isDoule(this.grdMain.Rows[i2].Cells["生产订单数量"].Value); } bool flag7 = HICMOQty < num; if (flag7) { MessageBox.Show("请点击超额生产按钮生成条码!"); break; } bool flag3 = num > 0.0; bool flag8 = !flag3; if (flag8) { break; } bool flag4 = num > ClsPub.isDoule(this.grdMain.Rows[i].Cells["生产订单数量"].Value); bool flag9 = !flag4; if (flag9) { this.grdMain.Rows[i].Cells["本次数量"].Value = num; break; } num -= ClsPub.isDoule(this.grdMain.Rows[i].Cells["生产订单数量"].Value); this.grdMain.Rows[i].Cells["本次数量"].Value = ClsPub.isDoule(this.grdMain.Rows[i].Cells["生产订单数量"].Value); } this.Sub_SaveBarCode(); } } private void Sub_SaveBill() { HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo); string HMaterNumber = ""; string HBatchNo = ""; string HDate = ""; string HYear = ""; string HPeriod = ""; string HDay = ""; string HTMNumber = ""; string HOrgNumber = ""; DataSet Ds; Int64 LSH = 0; //流水号 string LSH2 = ""; //流水号转换成字符 double HZXQty = 0; //装箱数量 double HDDQty = 0; //订单数量 double HBQty = 0; //箱数 int k = 0; int n = 0; //同一批生成条码中的第几条 string WeiShu = ""; //尾数 int LSHlen = 6; //流水号长度 string TM = ""; //条码 for (int j = 0; j < grdMain.Rows.Count; j++) { HMaterNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("物料代码")].Value); HBatchNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("批次")].Value); HDate = DateTime.Now.ToShortDateString(); HYear = ClsPub.isDate(HDate).Year.ToString().Substring(2, 2); HPeriod = "0" + ClsPub.isDate(HDate).Month.ToString(); HPeriod = HPeriod.Substring(HPeriod.Length - 2, 2); HDay = "0" + ClsPub.isDate(HDate).Day.ToString(); HDay = HDay.Substring(HDay.Length - 2, 2); HOrgNumber = ClsPub.HOrgNumber; //HBQty = HBQty + ClsPub.isLong(txtHBQty.Text); HZXQty = ClsPub.isDoule(txtHZXQty.Text); HDDQty = DBUtility.ClsPub.isDoule(grdMain.Rows[j].Cells[Fun_GetCol("订单数量")].Value); if (cmbHBarCodeType.Text == "唯一条码") { HTMNumber = HOrgNumber + HMaterNumber + HYear + HPeriod + HDay; Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + HTMNumber + "'", "h_p_WMS_GetMaxNo"); //获取最大流水号 LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]); } else if (cmbHBarCodeType.Text == "批次条码") { TM = HOrgNumber + HMaterNumber + HBatchNo; } n = 0; LSH2 = LSH.ToString(); while (LSH2.Length < LSHlen) //如果流水号小于6位数前面补0 { LSH2 = "0" + LSH2; } if (cmbHBarCodeType.Text == "唯一条码") { //条码编号 = 条码前缀 + 流水号 TM = HTMNumber + LSH2; } if (TM.Trim() == "") { MessageBox.Show("条形码不能为空,不能生成条码!"); return; } string HWei = ""; //尾数 string HBarCode = ""; string HBarCodeType = ""; Int64 HMaterID1 = 0; Int64 HAuxPropID = 0; Int64 HUnitID = 0; double HQty2 = 0; string HBatchNo2 = ""; Int64 HSupID = 0; Int64 HGroupID = 0; int HPrintQty = 0; Int64 HSourceInterID = 0; Int64 HSourceEntryID = 0; string HSourceBillNo = ""; string HSourceBillType = ""; Int64 HBarcodeNo = 0; //托号 Int64 HBarcodeQtys = 0; //总托数 Int64 HDeptID = 0; Int64 HWhID = 0; Int64 HSPID = 0; string HRemark = ""; string HMaterName = ""; string HMaterModel = ""; string HPinfan = ""; string HMTONo = ""; Int64 HCusID = 0; string HCusType = ""; DateTime HEndDate; string HWorkLineName = ""; string HSeOrderBillNo = ""; string HInnerBillNo = ""; try { oCn.BeginTran(); HWei = WeiShu; HBarCode = TM; HBarCodeType = ClsPub.isStrNull(cmbHBarCodeType.Text); HMaterID1 = ClsPub.isLong(grdMain.Rows[j].Cells[Fun_GetCol("HMaterID")].Value); HAuxPropID = 0; HUnitID = 0; HQty2 = HZXQty; HBatchNo2 = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("批次")].Value); HSourceInterID = 0; HSourceEntryID = 0; HSourceBillNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("生产订单号")].Value); HSourceBillType = "3710"; HBarcodeQtys = 0; HBarcodeNo = 0; HSupID = 0; HDeptID = 0; HWhID = 0; HSPID = 0; HRemark = ""; HMaterName = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("物料名称")].Value); HMaterModel = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("规格型号")].Value); HPinfan = ""; HMTONo = ""; HCusID = 0; HCusType = ""; HEndDate = ClsPub.isDate(grdMain.Rows[j].Cells[Fun_GetCol("日期")].Value); HWorkLineName = ""; HSeOrderBillNo = ""; HInnerBillNo = ""; oCn.RunProc("insert into Gy_BarCodeBill (HBarCode,HBarCodeType,HMaterID,HUnitID,HQty" + ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" + ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " + ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " + ",HCusID,HCusType,HEndDate,HWorkLineName,HBarCodeDate " + ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID " + ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo " + ") values (" + "'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID1.ToString() + "," + HUnitID.ToString() + "," + HQty2.ToString() + ",'" + HBatchNo2 + "'," + HSupID.ToString() + "," + HGroupID.ToString() + ",'" + ClsPub.CurUserName + "',getdate()," + HPrintQty.ToString() + "," + HQty2.ToString() + ", " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "','" + HSourceBillType + "','" + HWei + "'" + ", " + HBarcodeQtys.ToString() + "," + HBarcodeNo.ToString() + "," + HDeptID.ToString() + "," + HWhID.ToString() + "," + HSPID.ToString() + ",'" + HRemark + "'" + ", " + HCusID.ToString() + ",'" + HCusType + "','" + HEndDate.ToShortDateString() + "','" + HWorkLineName + "','" + HDate + "'" + ", " + ClsPub.HOrgID.ToString() + "," + ClsPub.HOrgID.ToString() + ",'" + HSeOrderBillNo + "'," + HInterID.ToString() + ",'" + HMaterName + "','" + HMaterModel + "','" + HPinfan + "'," + HAuxPropID.ToString() + ",'" + HMTONo + "','" + HInnerBillNo + "')"); oCn.Commit(); MessageBox.Show("条码生成完毕!"); //grdSub.RowCount = 0; DisplayTM(); } catch (Exception e1) { oCn.RollBack(); MessageBox.Show("条码生成失败!" + e1.Message); } } } private void Sub_SaveBill_TTM() { HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo); HInterID_TTM = DBUtility.ClsPub.CreateBillID_Prod(ModName1, ref DBUtility.ClsPub.sExeReturnInfo); HBillNo_TTM = DBUtility.ClsPub.CreateBillCode_Prod(ModName1, ref DBUtility.ClsPub.sExeReturnInfo, true);//得到新单号 string HMaterNumber = ""; string HBatchNo = ""; string HDate = ""; string HYear = ""; string HPeriod = ""; string HDay = ""; string HTMNumber = ""; string HOrgNumber = ""; DataSet Ds; Int64 LSH = 0; //流水号 string LSH2 = ""; //流水号转换成字符 double HZXQty = 0; //装箱数量 double HDDQty = 0; //订单数量 double HBQty = 0; //箱数 int k = 0; int n = 0; //同一批生成条码中的第几条 string WeiShu = ""; //尾数 int LSHlen = 6; //流水号长度 string TM = ""; //条码 for (int j = 0; j < grdMain.Rows.Count; j++) { HMaterNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("物料代码")].Value); HBatchNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("批次")].Value); HDate = DateTime.Now.ToShortDateString(); HYear = ClsPub.isDate(HDate).Year.ToString().Substring(2, 2); HPeriod = "0" + ClsPub.isDate(HDate).Month.ToString(); HPeriod = HPeriod.Substring(HPeriod.Length - 2, 2); HDay = "0" + ClsPub.isDate(HDate).Day.ToString(); HDay = HDay.Substring(HDay.Length - 2, 2); HOrgNumber = ClsPub.HOrgNumber; //HBQty = HBQty + ClsPub.isLong(txtHBQty.Text); HZXQty = ClsPub.isDoule(txtHZXQty.Text); HDDQty = DBUtility.ClsPub.isDoule(grdMain.Rows[j].Cells[Fun_GetCol("订单数量")].Value); HICMOBillNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("生产订单号")].Value); if (cmbHBarCodeType.Text == "唯一条码") { HTMNumber = HOrgNumber + HMaterNumber + HYear + HPeriod + HDay; Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + HTMNumber + "'", "h_p_WMS_GetMaxNo"); //获取最大流水号 LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]); } else if (cmbHBarCodeType.Text == "批次条码") { TM = HOrgNumber + HMaterNumber + HBatchNo; } n = 0; LSH2 = LSH.ToString(); while (LSH2.Length < LSHlen) //如果流水号小于6位数前面补0 { LSH2 = "0" + LSH2; } if (cmbHBarCodeType.Text == "唯一条码") { HDate = DateTime.Now.ToShortDateString(); DataSet DSet = oCn.RunProcReturn("select * from Gy_FactoryDayOff Where HFactoryDayOffDate='" + HDate.ToString() + "'", "Gy_FactoryDayOff", ref DBUtility.ClsPub.sExeReturnInfo); //生成首行标题 if (DSet == null || DSet.Tables[0].Rows.Count == 0) { HDate = DateTime.Now.ToShortDateString(); HYear = ClsPub.isDate(HDate).Year.ToString().Substring(2, 2); HPeriod = "0" + ClsPub.isDate(HDate).Month.ToString(); HPeriod = HPeriod.Substring(HPeriod.Length - 2, 2); HDay = "0" + ClsPub.isDate(HDate).Day.ToString(); HDay = HDay.Substring(HDay.Length - 2, 2); HTMNumber = HOrgNumber + HMaterNumber + HYear + HPeriod + HDay; Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + HTMNumber + "'", "h_p_WMS_GetMaxNo"); //获取最大流水号 LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]); TM = HTMNumber + LSH2; } else { HDate = DBUtility.ClsPub.isStrNull(DSet.Tables[0].Rows[0]["HNoFactoryDayOffDate"]); HYear = ClsPub.isDate(HDate).Year.ToString().Substring(2, 2); HPeriod = "0" + ClsPub.isDate(HDate).Month.ToString(); HPeriod = HPeriod.Substring(HPeriod.Length - 2, 2); HDay = "0" + ClsPub.isDate(HDate).Day.ToString(); HDay = HDay.Substring(HDay.Length - 2, 2); HTMNumber = HOrgNumber + HMaterNumber + HYear + HPeriod + HDay; Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + HTMNumber + "'", "h_p_WMS_GetMaxNo"); //获取最大流水号 LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]); TM = HTMNumber + LSH2 + "+"; } //HYear = ClsPub.isDate(HDate).Year.ToString().Substring(2, 2); //HPeriod = "0" + ClsPub.isDate(HDate).Month.ToString(); //HPeriod = HPeriod.Substring(HPeriod.Length - 2, 2); //HDay = "0" + ClsPub.isDate(HDate).Day.ToString(); //HDay = HDay.Substring(HDay.Length - 2, 2); //HTMNumber = HOrgNumber + HMaterNumber + HYear + HPeriod + HDay; //Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + HTMNumber + "'", "h_p_WMS_GetMaxNo"); //获取最大流水号 //LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]); } //if (cmbHBarCodeType.Text == "唯一条码") //{ // //条码编号 = 条码前缀 + 流水号 // TM = HTMNumber + LSH2; //} if (TM.Trim() == "") { MessageBox.Show("条形码不能为空,不能生成条码!"); return; } string HWei = ""; //尾数 string HBarCode = ""; string HBarCodeType = ""; Int64 HMaterID1 = 0; Int64 HAuxPropID = 0; Int64 HUnitID = 0; double HQty2 = 0; string HBatchNo2 = ""; Int64 HSupID = 0; Int64 HGroupID = 0; int HPrintQty = 0; Int64 HSourceInterID = 0; Int64 HSourceEntryID = 0; string HSourceBillNo = ""; string HSourceBillType = ""; Int64 HBarcodeNo = 0; //托号 Int64 HBarcodeQtys = 0; //总托数 Int64 HDeptID = 0; Int64 HWhID = 0; Int64 HSPID = 0; string HRemark = ""; string HMaterName = ""; string HMaterModel = ""; string HPinfan = ""; string HMTONo = ""; Int64 HCusID = 0; string HCusType = ""; DateTime HEndDate; string HWorkLineName = ""; string HSeOrderBillNo = ""; string HInnerBillNo = ""; try { oCn.BeginTran(); HWei = WeiShu; HBarCode = TM; HBarCodeType = ClsPub.isStrNull(cmbHBarCodeType.Text); HMaterID1 = ClsPub.isLong(grdMain.Rows[j].Cells[Fun_GetCol("HMaterID")].Value); HAuxPropID = 0; HUnitID = 0; HQty2 = HZXQty; HBatchNo2 = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("批次")].Value); HSourceInterID = 0; HSourceEntryID = 0; HSourceBillNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("生产订单号")].Value); HSourceBillType = "3710"; HBarcodeQtys = 0; HBarcodeNo = 0; HSupID = 0; HDeptID = 0; HWhID = 0; HSPID = 0; HRemark = ""; HMaterName = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("物料名称")].Value); HMaterModel = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("规格型号")].Value); HPinfan = ""; HMTONo = ""; HCusID = 0; HCusType = ""; HEndDate = ClsPub.isDate(grdMain.Rows[j].Cells[Fun_GetCol("日期")].Value); HWorkLineName = ""; HSeOrderBillNo = ""; HInnerBillNo = ""; oCn.RunProc("insert into Gy_BarCodeBill (HBarCode,HBarCodeType,HMaterID,HUnitID,HQty" + ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" + ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " + ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " + ",HCusID,HCusType,HEndDate,HWorkLineName,HBarCodeDate " + ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID " + ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo " + ") values (" + "'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID1.ToString() + "," + HUnitID.ToString() + "," + HQty2.ToString() + ",'" + HBatchNo2 + "'," + HSupID.ToString() + "," + HGroupID.ToString() + ",'" + ClsPub.CurUserName + "',getdate()," + HPrintQty.ToString() + "," + HQty2.ToString() + ", " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "','" + HSourceBillType + "','" + HWei + "'" + ", " + HBarcodeQtys.ToString() + "," + HBarcodeNo.ToString() + "," + HDeptID.ToString() + "," + HWhID.ToString() + "," + HSPID.ToString() + ",'" + HRemark + "'" + ", " + HCusID.ToString() + ",'" + HCusType + "','" + HEndDate.ToShortDateString() + "','" + HWorkLineName + "','" + HDate + "'" + ", " + ClsPub.HOrgID.ToString() + "," + ClsPub.HOrgID.ToString() + ",'" + HSeOrderBillNo + "'," + HInterID.ToString() + ",'" + HMaterName + "','" + HMaterModel + "','" + HPinfan + "'," + HAuxPropID.ToString() + ",'" + HMTONo + "','" + HInnerBillNo + "')"); oCn.RunProc("insert into Sc_PackUnionBillSub (HInterID,HEntryID,HSourceInterID,HSourceEntryID,HSourceBillNo" + ",HSourceBillType,HMaterID,HUnitID,HQty,HSourceID,HEquipID,HGroupID" + ",HWorkerID,HScanDate,HBarCode,HBarCode_Pack,HStatus,HICMOEntryID " + ") values (" + HInterID_TTM + "," + j + ",0,0,''" + ",'3710'," + HMaterID1.ToString() + "," + HUnitID.ToString() + "," + HQty2.ToString() + ",0,0,0" + ", 0,getdate(),'" + HBarCode + "','" + TTM + "',0,0)"); DataSet DSet = oCn.RunProcReturn("select * from h_v_IF_BarCodeBillList Where HInterID=" + HInterID.ToString() + " and HBarCode like '%ZXM&' order by HItemID", "h_v_IF_BarCodeBillList", ref DBUtility.ClsPub.sExeReturnInfo); //生成首行标题 if (DSet == null) { MessageBox.Show("没有返回任何结果,条码不存在!" + DBUtility.ClsPub.sExeReturnInfo); return; } // grdList.DataSource = DSet.Tables[0].DefaultView; oCn.Commit(); MessageBox.Show("条码生成完毕!"); //grdSub.RowCount = 0; //DisplayTM(); } catch (Exception e1) { oCn.RollBack(); MessageBox.Show("条码生成失败!" + e1.Message); } } } private void DisplayTM() { //HInterID = DBUtility.ClsPub.isLong(txtHMaterID.Tag); DataSet DSet = oCn.RunProcReturn("select * from h_v_IF_BarCodeBillList_test Where HinterID=" + HInterID.ToString() + " and 条码类型 = '托盘条码' order by HItemID", "h_v_IF_BarCodeBillList_test", ref DBUtility.ClsPub.sExeReturnInfo); //生成首行标题 if (DSet == null) { MessageBox.Show("没有返回任何结果,条码不存在!" + DBUtility.ClsPub.sExeReturnInfo); return; } // grdList.DataSource = DSet.Tables[0].DefaultView; //冻结 int FrCol = 0; string s = "是"; DBUtility.Xt_BaseBillFun.DisplayGrid(grdList, this.Name + "grdList", s, FrCol); //画线 //GraphLine(); // } //private void button5_Click(object sender, EventArgs e) //{ // //判断是否已经生成条码 // for (int j = 0; j < grdMain.SelectedRows.Count; j++) // { // if (DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[j].Cells[Fun_GetCol("HBarCode")].Value) == "") // { // MessageBox.Show("条码未生成,请先生成条码后再预览!"); // return; // } // //打印前判断条码是否已打印过 // if (ReportPrintBegin()) // { // return; // } // //选择打印模板 // BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp(); // oFrm.sBillName = ModName; // oFrm.sBillModel = ModCaption; // oFrm.ShowDialog(); // if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK) // { // Sub_SetReport(oFrm.sOpenTmp); // Report.PrintPreview(false); // Thread.Sleep(1000); // } // } //} //打印前判断条码是否已打印过 //private bool ReportPrintBegin() //{ // string sRelQty = ""; // if (oBar.Set_BPrintQty(DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[j].Cells[Fun_GetCol("HBarCode")].Value), ref sRelQty)) // { // MessageBox.Show("条码已经打印过,不可重复打印!"); // return true; // } // else // { // return false; // } //} private void button1_Click(object sender, EventArgs e) { DAL.ClsGy_BarCodeBill_Ctl oBar = new DAL.ClsGy_BarCodeBill_Ctl(); //打印前判断条码是否已打印过 string sBarCode = ""; string sRelQty = ""; for (int i = 0; i < grdSub.SelectedRows.Count; i++) { sBarCode = sBarCode + "," + DBUtility.ClsPub.isStrNull(grdSub.Rows[grdSub.SelectedRows[i].Index].Cells[Fun_GetCol("HBarcode")].Value); } //if (oBar.Set_BPrintQty(sBarCode.Substring(1), ref sRelQty)) //{ // MessageBox.Show(sRelQty); // return; //} //选择打印模板 BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp(); //DAL.ClsGy_BarCodeBill_Ctl oBar = new DAL.ClsGy_BarCodeBill_Ctl(); oFrm.sBillName = ModName; oFrm.sBillModel = ModCaption; oFrm.ShowDialog(); if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK) { Sub_SetReport(oFrm.sOpenTmp); Report.Print(false); //oBar.Set_PrintQty(DBUtility.ClsPub.isStrNull(grdMain.Rows[CurRows].Cells[Fun_GetCol("条码编号")].Value)); Thread.Sleep(1000); } //批量更新条码打印次数 oBar.Set_EPrintQty(sBarCode.Substring(1)); } private void cmdHSaveBill1_Click(object sender, EventArgs e) { Display1(); } private void Display1() { ClsCN SubCn = new ClsCN(); DataSet DSet; string sSql = ""; string sFastSQL = ""; //生产订单号 //if (txtHICMOBillNo.Text.Trim() != "") //{ // sFastSQL = sFastSQL + " and HICMOBillNo like '%" + txtHICMOBillNo.Text + "%'"; //} string HICMOBillNo = ""; HICMOBillNo = txtHICMOBillNo1.Text.Trim().ToString(); //物料 //if (txtHMaterID.Text.Trim() != "") //{ // sFastSQL = sFastSQL + " and HMaterName like '%" + txtHMaterID.Text + "%'"; //} string HMaterName = ""; HMaterName = txtHMaterID1.Text.Trim().ToString(); //判断开始日期 //if (dtpHBeginDate.Checked) //{ // sFastSQL = sFastSQL + " and 日期>='" + dtpHBeginDate.Value.ToShortDateString() + "'"; //} string HBeginDate = ""; HBeginDate = dtpHBeginDate1.Value.ToShortDateString(); //判断结束日期 //if (dtpHEndDate.Checked) //{ // sFastSQL = sFastSQL + " and 日期<='" + dtpHEndDate.Value.ToShortDateString() + "'"; //} string HEndDate = ""; HEndDate = dtpHEndDate1.Value.ToShortDateString(); //if (sFastSQL.Trim() == "") //{ // MessageBox.Show("没有输入条件!"); // return; //} //过滤条件 // DSet = SubCn.RunProcReturn("exec h_p_KSTMCX '" + HICMOBillNo + "' , '" + HMaterName + "' ,'" + HBeginDate + "', '" + HEndDate + "'", "h_p_KSTMCX", ref DBUtility.ClsPub.sExeReturnInfo); //生成首行标题 if (DSet == null) { MessageBox.Show("没有返回任何结果,请在过滤框中点击【恢复】按钮,尝试再次查询!" + DBUtility.ClsPub.sExeReturnInfo); return; } // grdSub.DataSource = DSet.Tables[0].DefaultView; //冻结 //int FrCol = DBUtility.ClsPub.isLong(frmCondition.txtFrozenCol.Text); //string s = frmCondition.cmbHComplete.Text; //DBUtility.Xt_BaseBillFun.DisplayGrid(grdSub, this.Name, s, FrCol); //画线 GraphLine(); // } private void cmdHSourceID_Click(object sender, EventArgs e) { Int64 HEmpID = 0; HEmpID = Convert.ToInt64(txtHEmpID.Tag); //MessageBox.Show(ClsPub.isStrNull(HEmpID)); //string HEmpName = ""; //HEmpName = ClsPub.isStrNull(txtHEmpID.Text); DAL.ClsGy_Source_View oSource = new DAL.ClsGy_Source_View(); if (HEmpID != 0) { if (oSource.GetInfoByID_AoBang(HEmpID)) { this.txtHSourceID.Text = oSource.oModel.HName; this.txtHSourceID.Tag = oSource.oModel.HItemID.ToString(); // Display(); } else { this.txtHSourceID.Text = ""; } } else { if (oSource.RefreshView()) { this.txtHSourceID.Text = oSource.oModel.HName; this.txtHSourceID.Tag = oSource.oModel.HItemID.ToString(); // Display(); } else { this.txtHSourceID.Text = ""; } } //if (oSource.RefreshView()) //{ // this.txtHSourceID.Text = oSource.oModel.HName; // this.txtHSourceID.Tag = oSource.oModel.HItemID.ToString(); // // // Display(); //} //DAL.ClsGy_WorkCenter_View oWork = new DAL.ClsGy_WorkCenter_View(); //if (oWork.RefreshView()) //{ // this.txtHSourceID.Text = oWork.oModel.HName; // this.txtHSourceID.Tag = oWork.oModel.HItemID.ToString(); // // // Display(); // // //} //else //{ // this.txtHSourceID.Text = ""; //} } private void cmdHEmpID_Click(object sender, EventArgs e) { DAL.ClsGy_Employee_View oEmp = new DAL.ClsGy_Employee_View(); if (oEmp.RefreshView()) { this.txtHEmpID.Text = oEmp.oModel.HName; this.txtHEmpID.Tag = oEmp.oModel.HItemID.ToString(); } else { this.txtHEmpID.Text = ""; } } private void cmdHMaterID_Click(object sender, EventArgs e) { DAL.ClsGy_Material_View oMater = new DAL.ClsGy_Material_View(); if (oMater.RefreshView()) { this.txtHMaterID.Text = oMater.oModel.HName; this.txtHMaterID.Tag = oMater.oModel.HItemID.ToString(); } else { this.txtHMaterID.Text = ""; } } private void cmdHMaterID1_Click(object sender, EventArgs e) { DAL.ClsGy_Material_View oMater = new DAL.ClsGy_Material_View(); if (oMater.RefreshView()) { this.txtHMaterID1.Text = oMater.oModel.HName; this.txtHMaterID1.Tag = oMater.oModel.HItemID.ToString(); } else { this.txtHMaterID1.Text = ""; } } private void txtHMiniQty_TextChanged(object sender, EventArgs e) { //double HMiniQty = 0; //double HBQty = 0; //HMiniQty = DBUtility.ClsPub.isDoule(txtHMiniQty.Text.Trim()); //HBQty = } private void txtHBQty_TextChanged(object sender, EventArgs e) { double HICMOQty = 0; double HMiniQty = 0; double HBQty = 0; for (int i = 0; i < grdMain.SelectedRows.Count; i++) { txtHZXQty.Text = DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("订单数量")].Value); } HICMOQty = DBUtility.ClsPub.isDoule(txtHZXQty.Text.Trim()); HMiniQty = DBUtility.ClsPub.isDoule(txtHMiniQty.Text.Trim()); if (HMiniQty == 0) { HBQty = 0; } else { HBQty = HICMOQty / HMiniQty; } HBQty = Math.Ceiling(HBQty); txtHBQty.Text = DBUtility.ClsPub.isStrNull(HBQty); } private void button5_Click(object sender, EventArgs e) { //判断是否已经生成条码 for (int i = 0; i < grdList.SelectedRows.Count; i++) { if (DBUtility.ClsPub.isStrNull(grdList.SelectedRows[i].Cells[Fun_GetColList("条码编号")].Value) == "") { MessageBox.Show("条码未生成,请先生成条码后再预览!"); return; } } //打印前判断条码是否已打印过 if (ReportPrintBegin()) { return; } //选择打印模板 BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp(); oFrm.sBillName = ModName; oFrm.sBillModel = ModCaption; oFrm.ShowDialog(); if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK) { Sub_SetReport(oFrm.sOpenTmp); Report.PrintPreview(false); Thread.Sleep(1000); } } private bool ReportPrintBegin() { string sRelQty = ""; if (oBar.Set_BPrintQty(DBUtility.ClsPub.isStrNull(grdList.Rows[0].Cells[Fun_GetColList("条码编号")].Value), ref sRelQty)) { MessageBox.Show("条码已经打印过,不可重复打印!"); return true; } else { return false; } } private void button6_Click(object sender, EventArgs e) { //判断是否已经生成条码 if (DBUtility.ClsPub.isStrNull(grdList.Rows[0].Cells[Fun_GetColList("条码编号")].Value) == "") { MessageBox.Show("条码未生成,请先生成条码后再预览!"); return; } //打印前判断条码是否已打印过 if (ReportPrintBegin()) { return; } //选择打印模板 BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp(); oFrm.sBillName = ModName; oFrm.sBillModel = ModCaption; oFrm.ShowDialog(); if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK) { Sub_SetReport(oFrm.sOpenTmp); Report.PrintPreview(false); Thread.Sleep(1000); } } private void cz_Click(object sender, EventArgs e) { txtHBQty.Text = ""; txtHEmpID.Text = ""; txtHICMOBillNo.Text = ""; txtHICMOBillNo1.Text = ""; txtHZXQty.Text = ""; txtHMaterID.Text = ""; txtHMaterID1.Text = ""; txtHMiniQty.Text = ""; txtHSourceID.Text = ""; cmbHBarCodeType.Items.Clear(); grdList.DataSource = null; grdSub.DataSource = null; grdMain.DataSource = null; txtHEmpID.Tag = 0; } private void button2_Click(object sender, EventArgs e) { //获取网格第一行HInterID的值 Int64 HInterID = 0; HInterID = DBUtility.ClsPub.isLong(txtHMaterID.Tag); DataSet DSBefore; DSBefore = SubCn.RunProcReturn("exec h_p_PreviousMater "+ HInterID, "h_p_PreviousMater", ref DBUtility.ClsPub.sExeReturnInfo); grdMain.DataSource = DSBefore.Tables[0].DefaultView; //if (DSBefore.Tables[0].Rows.Count > 0) //{ // txtHMaterID.Tag = DBUtility.ClsPub.isLong(grdMain.Rows[0].Cells["HInterID"].Value); //} //else //{ //} if (DSBefore == null || DSBefore.Tables[0].Rows.Count == 0) //if (DSet == null|| DSet.Tables[0].Rows.Count == 0) { MessageBox.Show("没有上一个物料,如果需要请找机修!" + DBUtility.ClsPub.sExeReturnInfo); return; } else { grdMain.DataSource = DSBefore.Tables[0].DefaultView; txtHMaterID.Tag = DBUtility.ClsPub.isLong(grdMain.Rows[0].Cells["HInterID"].Value); txtHMiniQty.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[0].Cells["标准装箱"].Value); txtHMaterModel.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[0].Cells["规格型号"].Value); txtHMaterName.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[0].Cells["物料名称"].Value); } } private void button3_Click(object sender, EventArgs e) { //根据 Int64 HInterID = 0; //HInterID = DBUtility.ClsPub.isLong(grdMain.Rows[0].Cells[Fun_GetCol("HInterID")].Value); HInterID = DBUtility.ClsPub.isLong(txtHMaterID.Tag); DataSet DSBefore; DSBefore = SubCn.RunProcReturn("exec h_p_NextMater " + HInterID, "h_p_NextMater", ref DBUtility.ClsPub.sExeReturnInfo); if (DSBefore == null || DSBefore.Tables[0].Rows.Count == 0) //if (DSet == null|| DSet.Tables[0].Rows.Count == 0) { MessageBox.Show("没有下一个物料,如果需要请找机修!" + DBUtility.ClsPub.sExeReturnInfo); return; } else { grdMain.DataSource = DSBefore.Tables[0].DefaultView; txtHMaterID.Tag = DBUtility.ClsPub.isLong(grdMain.Rows[0].Cells["HInterID"].Value); txtHMiniQty.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[0].Cells["标准装箱"].Value); txtHMaterModel.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[0].Cells["规格型号"].Value); txtHMaterName.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[0].Cells["物料名称"].Value); } //txtHMaterID.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[0].Cells["HInterID"].Value); } //超额打印 private void button7_Click(object sender, EventArgs e) { //根据本箱数量 来 分配到 每个生产订单上,并且允许超过订单数量 (分配时 要考虑 订单剩余数量已经是 负数的情况) //1.判断本箱数量 必须大于0 double HZXQty = 0;//整箱数量 HZXQty = ClsPub.isDoule(txtHZXQty.Text); if (HZXQty <= 0) { MessageBox.Show("请输入整箱数量!"); return; } //2.刷新网格 //Display(); //3.循环网格,累计全部剩余数量,判断是否 剩余数量 小于 本箱数量;如果 大于则报错 退出。 double sumLeftQty = 0; for (int i = 0; i < grdMain.Rows.Count; i++) { if ( DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["生产订单数量"].Value)>0) { sumLeftQty = sumLeftQty + DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["生产订单数量"].Value); } else { } } if(sumLeftQty>= HZXQty ) { MessageBox.Show("剩余数量大于本箱数量,不能超额打印,请用普通打印功能。"); return; } //4.把整箱数量 分配到 网格下面的每一个 生产订单上去。 循环网格 for (int i = 0; i < grdMain.Rows.Count; i++) { if (HZXQty > DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["生产订单数量"].Value)) { if (i == grdMain.Rows.Count - 1) { grdMain.Rows[i].Cells["本次数量"].Value = HZXQty; } else { HZXQty = HZXQty - DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["生产订单数量"].Value); grdMain.Rows[i].Cells["本次数量"].Value = DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["生产订单数量"].Value); } } else { //grdMain.Rows[i].Cells["本次数量"].Value = HZXQty; break; } } Sub_SaveBarCode(); // } private void cmdESOP_Click(object sender, EventArgs e) { Sc_MESNowWorkBill_Fast oSc_MESNowWorkBill_Fast = new Sc_MESNowWorkBill_Fast(); oSc_MESNowWorkBill_Fast.txtHICMOBillNo.Text = ""; oSc_MESNowWorkBill_Fast.txtHMaterID.Text =txtHMaterID.Text; oSc_MESNowWorkBill_Fast.txtHName.Text = ClsPub.isStrNull(grdMain.Rows[0].Cells[Fun_GetCol("物料名称")].Value); oSc_MESNowWorkBill_Fast.txtHModel.Text = ClsPub.isStrNull(grdMain.Rows[0].Cells[Fun_GetCol("规格型号")].Value); oSc_MESNowWorkBill_Fast.Show(); } private void txtHBarCode_KeyDown(object sender, KeyEventArgs e) { if(e.KeyCode==Keys.Enter) { // //获取第一行条形码进行打印 DataSet DSet = oCn.RunProcReturn("select * from h_v_IF_BarCodeBillList_CS Where 条码编号='"+ txtHBarCode.Text +"' and 条码类型 = '托盘条码'", "h_v_IF_BarCodeBillList_CS", ref DBUtility.ClsPub.sExeReturnInfo); //生成首行标题 if (DSet == null) { MessageBox.Show("没有返回任何结果,条码不存在!" + DBUtility.ClsPub.sExeReturnInfo); return; } // grdList.DataSource = DSet.Tables[0].DefaultView; //冻结 int FrCol = 0; string s = "是"; DBUtility.Xt_BaseBillFun.DisplayGrid(grdList, this.Name + "grdList", s, FrCol); // //判断是否已经生成条码 if (DBUtility.ClsPub.isStrNull(grdList.Rows[0].Cells[Fun_GetColList("条码编号")].Value) == "") { MessageBox.Show("条码未生成,请先生成条码后再预览!"); return; } //选择打印模板 Sub_SetReport("注塑物料标签"); Report.Print(false); Thread.Sleep(1000); } } private void label14_Click(object sender, EventArgs e) { } } }