using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Pub_Class; using SQLHelper; namespace WorkM { public partial class Sc_ICMOBillList_CLDDlgBOM : Form { public Sc_ICMOBillList_CLDDlgBOM() { InitializeComponent(); } public long HICMOInterID = 0; public string HICMOBillNo = ""; public long HMaterID = 0; public long HDeptID = 0; public double HPlanQty = 0; // public int HQtyCol = 0; public int HCountCol = 0; public int IsOk; private void cmdCancel_Click(object sender, EventArgs e) { IsOk = 2; this.Visible = false; } private bool AllowOK() { return true; } private void cmdOK_Click(object sender, EventArgs e) { label4.Focus(); int sCount = 0; if (!AllowOK()) { return; } // int t = 0; for (int i = 0; i <= grdMain.Rows.Count - 1; i++) { if (DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[Fun_GetCol("Ñ¡Ôñ")].Value) == "¡Ì") { sCount = DBUtility.ClsPub.isInt(grdMain.Rows[i].Cells[Fun_GetCol("Éú³ÉÕÅÊý")].Value); for (int c = 0; c <= sCount - 1; c++) { WriteClass(i); } t++; } } if (t == 0) { MessageBox.Show("ÇëÑ¡ÔñÐèÒªÏÂÍÆµÄÁ÷ת¿¨"); return; } else { MessageBox.Show("Éú³ÉÁ÷ת¿¨³É¹¦£¡"); } // IsOk = 1; this.Visible = false; } private void WriteClass(int irow) { ClsCN oCn = new ClsCN(); DataSet Ds; DataSet oDsNo; DAL.ClsSc_ProcessExchangeBill BillNew = new DAL.ClsSc_ProcessExchangeBill(); Int64 HKeyMaterID = 0; Int64 HMainMaterID = 0; Int64 HMaterID = 0; Int64 HUnitID = 0; Int64 HBomID = 0; DateTime HPlanCommitDate = DateTime.Now; DateTime HPlanFinishDate = DateTime.Now; Int64 HRoutingID = 0; double HQty = 0; HMainMaterID = DBUtility.ClsPub.isLong(txtHMater.Tag); HMaterID = DBUtility.ClsPub.isLong(grdMain.Rows[irow].Cells[Fun_GetCol("hmaterid")].Value); HUnitID = DBUtility.ClsPub.isLong(grdMain.Rows[irow].Cells[Fun_GetCol("HUnitID")].Value); //HPlanCommitDate = DBUtility.ClsPub.isDate(grdMain.Rows[irow].Cells[Fun_GetCol("¼Æ»®¿ª¹¤ÈÕÆÚ")].Value); //HPlanFinishDate = DBUtility.ClsPub.isDate(grdMain.Rows[irow].Cells[Fun_GetCol("¼Æ»®Í깤ÈÕÆÚ")].Value); HQty = DBUtility.ClsPub.isDoule(grdMain.Rows[irow].Cells[Fun_GetCol("Á÷ת¿¨ÊýÁ¿")].Value); //HNum Á¬½ÓµÄÊÇ ¹¤ÒÕ×éµÄ´úÂë Ds = oCn.RunProcReturn("select * from h_v_Gy_RoutingBillList where HMaterID=" + HMaterID , "h_v_Gy_RoutingBillList"); if (Ds.Tables[0].Rows.Count > 0) { BillNew.omodel.HYear = 0; BillNew.omodel.HPeriod = 0; string sNo = ""; //»ñÈ¡µ±Ç°¸ÄÈÎÎñµ¥ ×î´óÁ÷ת¿¨ºÅ£¬²¢ÀÛ¼ÆÔö¼Ó1¡£ string sOldNo=""; oDsNo = oCn.RunProcReturn("select top 1 HBillNo from Sc_ProcessExchangeBillmain where hicmointerid=" + HICMOInterID + " order by LEN(HBillno) desc, HbillNo desc ", "Sc_ProcessExchangeBillmain"); if (oDsNo == null || oDsNo.Tables[0].Rows.Count == 0) { sNo = "00001"; } else { sOldNo = DBUtility.ClsPub.isStrNull(oDsNo.Tables[0].Rows[0]["HBillNo"]); sOldNo = sOldNo.Substring(sOldNo.Length - 3, 3); if (sOldNo.Substring(0, 1) == "0" || sOldNo.Substring(0, 1) == "-") { sOldNo = sOldNo.Substring(sOldNo.Length - 2, 2); if (sOldNo.Substring(0, 1) == "0") { sOldNo = sOldNo.Substring(sOldNo.Length - 1, 1); } } sNo = "0000" + DBUtility.ClsPub.isStrNull(DBUtility.ClsPub.isLong(sOldNo) + 1); } //oDsNo = oCn.RunProcReturn("select hicmointerid,sum(1) HNo from Sc_ProcessExchangeBillmain where hicmointerid=" + HICMOInterID + " group by hicmointerid ", "Sc_ProcessExchangeBillmain"); //if (oDsNo == null || oDsNo.Tables[0].Rows.Count == 0) //{ // sNo = "00001"; //} //else //{ // sNo = "0000" + DBUtility.ClsPub.isStrNull(DBUtility.ClsPub.isLong(oDsNo.Tables[0].Rows[0]["HNo"]) + 1); //} sNo = sNo.Substring(sNo.Length - 3, 3); //initGrid(); //initGrid_Sub(); string sBillNo = HICMOBillNo; sBillNo = sBillNo.Replace("WORKX", ""); sBillNo = sBillNo.Replace("WORK", ""); sBillNo = sBillNo.Replace("_", "-"); sBillNo = sBillNo + "-" + sNo; //¹Ì¶¨¸³Öµ================================= BillNew.omodel.HBillNo = sBillNo; BillNew.omodel.HDate = DBUtility.ClsPub.isDate(ClsPub.GetServerDate(0)); BillNew.omodel.HRemark = ""; //==================================================== BillNew.omodel.HWWOrderInterID = 0; BillNew.omodel.HWWOrderEntryID = 0; if (irow == 0) { BillNew.omodel.HICMOInterID = HICMOInterID; BillNew.omodel.HICMOBillNo = HICMOBillNo; BillNew.omodel.HWWOrderBillNo = ""; } else { BillNew.omodel.HICMOInterID = HICMOInterID; BillNew.omodel.HICMOBillNo = HICMOBillNo; BillNew.omodel.HWWOrderBillNo = HICMOBillNo; } BillNew.omodel.HMaterID = HMaterID; BillNew.omodel.HMaterID2 = HMainMaterID; BillNew.omodel.HMaterNumber = ""; BillNew.omodel.HBatchNo = ""; BillNew.omodel.HUnitID = HUnitID; BillNew.omodel.HUnitNumber = ""; BillNew.omodel.HPlanQty = HQty; BillNew.omodel.HQty = HQty; BillNew.omodel.HPlanBeginDate = HPlanCommitDate; BillNew.omodel.HPlanEndDate = HPlanFinishDate; BillNew.omodel.HExplanation = ""; BillNew.omodel.HInnerBillNo = ""; BillNew.omodel.HWorkShopID = HDeptID; BillNew.omodel.HSupID = 0; BillNew.omodel.HWorkTypeNum = "lX1"; //Á÷ת¿¨ÀàÐÍ BillNew.omodel.HMainMaterID = HMainMaterID; BillNew.omodel.HKeyMaterID = HKeyMaterID; //¹Ø¼üÎïÁÏ ¸ù¾Ýϼ¶BOM »ñÈ¡¹Ø¼ü¼þ //Ã÷ϸÀำֵ BillNew.DetailColl = new List(); for (int r = 0; r <= Ds.Tables[0].Rows.Count - 1; r++) { Model.ClsSc_ProcessExchangeBillSub oSub = new Model.ClsSc_ProcessExchangeBillSub(); //¹Ì¶¨¸³Öµ======================================== oSub.HEntryID = r + 1; oSub.HRemark = ""; oSub.HRelationQty = 0; oSub.HRelationMoney = 0; oSub.HCloseMan = ""; oSub.HEntryCloseDate = DBUtility.ClsPub.isDate("1990-01-01"); oSub.HCloseType = false; // if (irow == 0) { oSub.HSourceInterID = HICMOInterID; oSub.HSourceEntryID = 0; oSub.HSourceBillType = "85"; oSub.HSourceBillNo = HICMOBillNo; oSub.HICMOBillNo = HICMOBillNo; oSub.HICMOInterID = HICMOInterID; } else { oSub.HSourceInterID = HICMOInterID; oSub.HSourceEntryID = 1; oSub.HSourceBillType = "85"; oSub.HSourceBillNo = HICMOBillNo; oSub.HICMOBillNo = HICMOBillNo; oSub.HICMOInterID = HICMOInterID; } //============================= oSub.HQty = HQty; oSub.HProcNo = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[r]["¹¤ÐòºÅ"]); oSub.HProcID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[r]["hprocid"]); oSub.HProcNumber = ""; oSub.HWorkRemark = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[r]["±íÍ·±¸×¢"]); oSub.HCenterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[r]["HCenterID"]); oSub.HDeptID = 0; oSub.HDeptNumber = ""; oSub.HGroupID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[r]["HGroupID"]); oSub.HGroupNumber = ""; oSub.HWorkerID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[r]["HWorkerID"]); oSub.HWorkerNumber = ""; oSub.HSourceID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[r]["HSourceID"]); oSub.HTimeUnit = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[r]["ʱ¼äµ¥Î»"]); oSub.HPlanWorkTimes = 0; oSub.HPlanBeginDate = HPlanCommitDate; oSub.HPlanEndDate = HPlanFinishDate; oSub.HRelBeginDate = DBUtility.ClsPub.isDate("1990-01-01"); oSub.HRelEndDate = DBUtility.ClsPub.isDate("1990-01-01"); oSub.HReadyTime = 0; oSub.HQueueTime = 0; oSub.HMoveTime = 0; oSub.HBeginDayQty = 0; oSub.HBeginFixQty = 0; oSub.HFixWorkDays = 0; oSub.HTrunWorkDays = 0; oSub.HReadyTimes = 0; oSub.HMyWorkDays = 0; oSub.HOutPrice = DBUtility.ClsPub.isSingle(Ds.Tables[0].Rows[r]["¼Ó¹¤µ¥¼Û"]); oSub.HOutMoney = 0; oSub.HLastProc = "·ñ"; oSub.HFstProc = "·ñ"; oSub.HKeyProc = "·ñ"; oSub.HSeOrderInterID = 0; oSub.HSeOrderEntryID = 0; oSub.HSeOrderBillNo = ""; oSub.HWWOrderInterID = 0; oSub.HWWOrderEntryID = 0; oSub.HWWOrderBillNo = ""; BillNew.DetailColl.Add(oSub); } //ÐÂÔö if (!BillNew.AddBill(ref ClsPub.sExeReturnInfo)) { MessageBox.Show("±£´æÊ§°Ü!Ô­Òò:" + ClsPub.sExeReturnInfo, "Ìáʾ"); return; } } } private void Sc_ICMOBillList_CLDDlgBOM_Activated(object sender, EventArgs e) { IsOk = 0; } private void timer1_Tick(object sender, EventArgs e) { } private void initGrid() { DBUtility.Xt_BaseBillFun.initGridList(grdMain, this.Name); grdMain.ReadOnly = false; } private void Display() { ClsCN SubCn = new ClsCN(); DataSet DSet; string sSql = ""; string sWhere = ""; //¹ýÂËÌõ¼þ sSql = "exec h_p_Sc_GetBomMulLevQueryToLZK_CLD " + HICMOInterID.ToString(); // DSet = SubCn.RunProcReturn(sSql, "Gy_czygl", ref DBUtility.ClsPub.sExeReturnInfo); //Éú³ÉÊ×ÐбêÌâ if (DSet == null) { MessageBox.Show("ûÓвéѯµ½BOMÐÅÏ¢£¡" + DBUtility.ClsPub.sExeReturnInfo); return; } //ÊͷŶ³½á DBUtility.Xt_BaseBillFun.CancelFrozenCol(grdMain); // grdMain.DataSource = DSet.Tables[0].DefaultView; //ÉèÖúϼÆÁÐ //string sTotalCol = ""; //sTotalCol = DBUtility.Gy_BaseFun.GetTotalCols(DSet); //string[] sT; //sT = sTotalCol.Split(Convert.ToChar(",")); //oSumGrid.BuildTotalCols(sT); // //¶³½á int FrCol = 4; string s = "ÊÇ"; DBUtility.Xt_BaseBillFun.DisplayGrid(grdMain, this.Name, s, FrCol); for (int i = 0; i < grdMain.ColumnCount; i++) { grdMain.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; //ÁÐ ÅÅÐòģʽ } // HQtyCol = Fun_GetCol("Á÷ת¿¨ÊýÁ¿"); HCountCol = Fun_GetCol("Éú³ÉÕÅÊý"); } private Int32 Fun_GetCol(string sCol) { return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdMain); } private void GraphicsGrid() { DBUtility.Xt_BaseBillFun.GraphicsGrid(grdMain); } private void Sc_ICMOBillList_CLDDlgBOM_Load(object sender, EventArgs e) { DAL.ClsCLD_Material_View oMater = new DAL.ClsCLD_Material_View(); txtHICMOBillNo.Tag = HICMOInterID; txtHICMOBillNo.Text = HICMOBillNo; if (oMater.GetInfoByID(HMaterID)) { txtHMater.Tag = HMaterID; txtHMater.Text = oMater.omodel.HName; txtHModel.Text = oMater.omodel.HModel; } else { txtHMater.Tag = 0; txtHMater.Text = ""; txtHModel.Text = ""; } initGrid(); Display(); txtHPlanQty.Text = DBUtility.ClsPub.isDoule(HPlanQty, 0); } private void grdMain_Paint(object sender, PaintEventArgs e) { GraphicsGrid(); } private void grdMain_DoubleClick(object sender, EventArgs e) { if (DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.CurrentCell.RowIndex].Cells[Fun_GetCol("Ñ¡Ôñ")].Value) == "") { grdMain.Rows[grdMain.CurrentCell.RowIndex].Cells[Fun_GetCol("Ñ¡Ôñ")].Value = "¡Ì"; } else { grdMain.Rows[grdMain.CurrentCell.RowIndex].Cells[Fun_GetCol("Ñ¡Ôñ")].Value = ""; } } private void txtHPlanQty_TextChanged(object sender, EventArgs e) { if (DBUtility.ClsPub.isDoule(txtHPlanQty.Text) <= 0) { return; } double HConsultAuxQty = 0; double HQty = DBUtility.ClsPub.isDoule(txtHPlanQty.Text); for (int i = 0; i <= grdMain.RowCount - 1; i++) { HConsultAuxQty = DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells[Fun_GetCol("HConsultAuxQty")].Value); grdMain.Rows[i].Cells[Fun_GetCol("²ÎÕÕÊýÁ¿")].Value = DBUtility.ClsPub.isDoule(HQty * HConsultAuxQty, 0); grdMain.Rows[i].Cells[Fun_GetCol("Á÷ת¿¨ÊýÁ¿")].Value = DBUtility.ClsPub.isDoule(HQty * HConsultAuxQty, 0); } } private void grdMain_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) { int i = grdMain.CurrentCell.ColumnIndex; if (i != HQtyCol && i != HCountCol) { e.Cancel = true; } } private void grdMain_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e) { DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name); } } }