using System; using System.Collections.Generic; using System.Text; using System.Data; namespace DAL { public class ClsGy_ICBomBill_K3 : DBUtility.ClsXt_BaseBill { public Model.ClsGy_ICBomBillMain_K3 omodel = new Model.ClsGy_ICBomBillMain_K3(); public List DetailColl = new List(); public ClsGy_ICBomBill_K3() { base.MvarItemKeySub = "ICBomChild"; base.MvarItemKeySub2 = ""; base.MvarItemKeySub3 = ""; base.MvarItemKeySub4 = ""; base.MvarItemKey = "ICBom"; base.MvarReportTitle = "生产BOM"; base.BillType = "50"; } #region 固定代码 ~ClsGy_ICBomBill_K3() { DetailColl = null; } #endregion 自定义方法 //单据号是否重复 public bool IsExistBillNo(ref string sReturn, string sBillNo, DBUtility.ClsPub.Enum_BillStatus oBillStatus, Int64 lngBillKey) { try { string sSql = ""; if (oBillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew) { sSql = "Select FInterID from ICBom where FTranType='" + BillType + "' and FBomNumber ='" + sBillNo + "'"; } else { sSql = "Select FInterID from ICBom where FTranType='" + BillType + "' and FBomNumber ='" + sBillNo + "' and FInterID<>" + lngBillKey.ToString(); } DataSet Ds; Ds = oK3Cn.RunProcReturn(sSql, "ICBom"); if (Ds.Tables[0].Rows.Count != 0) { sReturn = "单号重复"; return true; } sReturn = "单号未重复"; return false; } catch (Exception e) { sReturn = e.Message; return false; } } //删除子表 public void DeleteBillSub(Int64 lngBillKey) { oK3Cn.RunProc("Delete From ICBomChild where FInterID=" + lngBillKey.ToString()); } //删除主表 public void DeleteBillMain(Int64 lngBillKey) { oK3Cn.RunProc("Delete From ICBom where FInterID=" + lngBillKey.ToString()); } //删除单据 public bool DeleteBill(Int64 lngBillKey, ref string sReturn) { DataSet Ds = new DataSet(); try { oK3Cn.BeginTran(); //删除关联 //DeleteRelation(ref sReturn, lngBillKey); //删除明细表 DeleteBillSub(lngBillKey); //删除主表 DeleteBillMain(lngBillKey); //删除关联 sReturn = "删除单据成功!"; oK3Cn.Commit(); return true; } catch (Exception e) { sReturn = e.Message; oK3Cn.RollBack(); return false; } } //修改单据 public override bool ModifyBill(Int64 lngBillKey, ref string sReturn) { try { oK3Cn.BeginTran(); omodel.HBillerID = DBUtility.ClsPub.GetUser_K3(DBUtility.ClsPub.CurUserName); if (omodel.HBillerID == 0) { sReturn = "错误用户,未在K3中设置用户!"; oK3Cn.RollBack(); return false; } //删除主表 DeleteBillMain(lngBillKey); //删除子表 DeleteBillSub(lngBillKey); // //更新主表 oK3Cn.RunProc("Insert Into ICBom " + "(FInterID,FBomNumber,FBrNo,FTranType,FCancellation" + ",FStatus,FVersion,FUseStatus,FItemID,FUnitID,FAuxPropID,FAuxQty,FYield" + ",FNote,FCheckID,FCheckDate,FOperatorID,FEntertime,FRoutingID,FBomType" + ",FCustID,FParentID,FAudDate,FImpMode,FPDMImportDate,FBOMSkip" + ") " + " values(" + omodel.HInterID.ToString() + ",'" + omodel.HBillNo + "','0'," + this.BillType + ",0" + ",0,'" + omodel.HVersion + "','1073'," + omodel.HMaterID.ToString() + "," + omodel.HUnitID.ToString() + ",0," + omodel.HQty.ToString() + "," + omodel.HProdRate.ToString() + ",'" + omodel.HRemark + "'," + omodel.HMaker + ",'" + omodel.HMakeDate + "'," + omodel.HBillerID + ",'" + DBUtility.ClsPub.GetServerDate(-1) + "',0,0" + ",0," + omodel.HParentID.ToString() + ",null,0,null,'" + omodel.HJump + "'" + ") "); //插入子表 foreach (Model.ClsGy_ICBomBillSub_K3 oSub in DetailColl) { oK3Cn.RunProc("Insert into ICBomChild " + " (FInterID,FEntryID,FBrNo,FItemID,FAuxPropID" + ",FUnitID,FMaterielType,FMarshalType,FQty,FAuxQty,FBeginDay,FEndDay" + ",FPercent,FScrap,FPositionNo,FItemSize,FItemSuite,FOperSN,FOperID" + ",FMachinePos,FOffSetDay,FBackFlush,FStockID,FSPID,FHasChar" + ",FNote,FNote1,FNote2,FNote3,FPDMImportDate,FDetailID" + ") values(" + omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + ",'0'," + oSub.HMaterID.ToString() + ",0" + "," + oSub.HUnitID.ToString() + ",371,385," + oSub.HQty.ToString() + "," + oSub.HRelQty.ToString() + ",convert(varchar(10),getdate(),120),'2100-01-01'" + ",100," + oSub.HWasteRate.ToString() + ",'','','',0," + oSub.HProcID.ToString() + ",'',0,1059," + oSub.HWhID.ToString() + "," + oSub.HSPID.ToString() + ",0" + ",'" + oSub.HRemark + "','" + oSub.HRemark2 + "','" + oSub.HRemark3 + "','" + oSub.HRemark4 + "',null,NEWID()" + ") "); } oK3Cn.RunProc("INSERT INTO t_Log (FDate,FUserID,FFunctionID,FStatement,FDescription,FMachineName,FIPAddress) VALUES (getdate()," + omodel.HBillerID + ",'K810030',3,'编号为" + omodel.HBillNo + "的单据修改成功','CHINA-52B459496','127.0.0.1')"); oK3Cn.RunProc("EXEC h_p_K3_Gy_ICBomCheckAndUsed " + omodel.HInterID.ToString() + "," + omodel.HBillerID + ""); oK3Cn.RunProc("INSERT INTO t_Log (FDate,FUserID,FFunctionID,FStatement,FDescription,FMachineName,FIPAddress) VALUES (getdate()," + omodel.HBillerID + ",'K810030',3,'编号为" + omodel.HBillNo + "的单据使用成功','CHINA-52B459496','127.0.0.1')"); sReturn = "修改单据成功!"; oK3Cn.Commit(); return true; } catch (Exception e) { sReturn = e.Message; oK3Cn.RollBack(); throw (e); } } //新增单据 public override bool AddBill(ref string sReturn) { try { DataSet Ds; //得到mainid Ds = oK3Cn.RunProcReturn("declare @InterID int set @InterID=0 exec GetICMaxNum 'ICBom', @InterID output, 1, 16394 select ltrim(@InterID)", "GetICMaxNum"); omodel.HInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0][0]) + 10000000; //若MAINDI重复则重新获取 omodel.HBillerID = DBUtility.ClsPub.GetUser_K3(DBUtility.ClsPub.CurUserName); if (omodel.HBillerID == 0) { sReturn = "错误用户,未在K3中设置用户!"; return false; } oK3Cn.BeginTran(); //主表 oK3Cn.RunProc("Insert Into ICBom " + "(FInterID,FBomNumber,FBrNo,FTranType,FCancellation" + ",FStatus,FVersion,FUseStatus,FItemID,FUnitID,FAuxPropID,FAuxQty,FYield" + ",FNote,FCheckID,FCheckDate,FOperatorID,FEntertime,FRoutingID,FBomType" + ",FCustID,FParentID,FAudDate,FImpMode,FPDMImportDate,FBOMSkip" + ") " + " values(" + omodel.HInterID.ToString() + ",'" + omodel.HBillNo + "','0'," + this.BillType + ",0" + ",0,'" + omodel.HVersion + "','1073'," + omodel.HMaterID.ToString() + "," + omodel.HUnitID.ToString() + ",0," + omodel.HQty.ToString() + "," + omodel.HProdRate.ToString() + ",'" + omodel.HRemark + "'," + omodel.HBillerID + ",'" + DBUtility.ClsPub.GetServerDate(-1) + "'," + omodel.HBillerID + ",'" + DBUtility.ClsPub.GetServerDate(-1) + "',0,0" + ",0," + omodel.HParentID.ToString() + ",null,0,null,'" + omodel.HJump + "'" + ") "); //插入子表 foreach (Model.ClsGy_ICBomBillSub_K3 oSub in DetailColl) { oK3Cn.RunProc("Insert into ICBomChild " + " (FInterID,FEntryID,FBrNo,FItemID,FAuxPropID" + ",FUnitID,FMaterielType,FMarshalType,FQty,FAuxQty,FBeginDay,FEndDay" + ",FPercent,FScrap,FPositionNo,FItemSize,FItemSuite,FOperSN,FOperID" + ",FMachinePos,FOffSetDay,FBackFlush,FStockID,FSPID,FHasChar" + ",FNote,FNote1,FNote2,FNote3,FPDMImportDate,FDetailID" + ") values(" + omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + ",'0'," + oSub.HMaterID.ToString() + ",0" + "," + oSub.HUnitID.ToString() + ",371,385," + oSub.HQty.ToString() + "," + oSub.HRelQty.ToString() + ",convert(varchar(10),getdate(),120),'2100-01-01'" + ",100," + oSub.HWasteRate.ToString() + ",'','','',0," + oSub.HProcID.ToString() + ",'',0,1059," + oSub.HWhID.ToString() + ","+ oSub.HSPID.ToString() +",0" + ",'" + oSub.HRemark + "','" + oSub.HRemark2 + "','" + oSub.HRemark3 + "','" + oSub.HRemark4 + "',null,NEWID()" + ") "); } oK3Cn.RunProc("INSERT INTO t_Log (FDate,FUserID,FFunctionID,FStatement,FDescription,FMachineName,FIPAddress) VALUES (getdate()," + omodel.HBillerID + ",'K810030',3,'编号为" + omodel.HBillNo + "的单据保存成功','CHINA-52B459496','127.0.0.1')"); oK3Cn.RunProc("EXEC h_p_K3_Gy_ICBomCheckAndUsed " + omodel.HInterID.ToString() + "," + omodel.HBillerID + ""); oK3Cn.RunProc("INSERT INTO t_Log (FDate,FUserID,FFunctionID,FStatement,FDescription,FMachineName,FIPAddress) VALUES (getdate()," + omodel.HBillerID + ",'K810030',3,'编号为" + omodel.HBillNo + "的单据使用成功','CHINA-52B459496','127.0.0.1')"); sReturn = "新增单据成功!"; oK3Cn.Commit(); return true; } catch (Exception e) { sReturn = e.Message; oK3Cn.RollBack(); throw (e); } } //显示单据 public override bool ShowBill(Int64 lngBillKey, ref string sReturn) { try { //查询主表 DataSet Ds; Ds = oK3Cn.RunProcReturn("Select * from ICBom Where FInterID=" + lngBillKey.ToString(), "ICBom"); if (Ds.Tables[0].Rows.Count == 0) { sReturn = "单据未找到!"; return false; } //赋值 omodel.HInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FInterID"]); omodel.HBillNo = Ds.Tables[0].Rows[0]["FBOMNumber"].ToString().Trim(); omodel.HDate = Convert.ToDateTime(Ds.Tables[0].Rows[0]["FCheckDate"].ToString().Trim()); omodel.HRemark = Ds.Tables[0].Rows[0]["FNote"].ToString().Trim(); // omodel.HParentID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FParentID"]); omodel.HVersion = Ds.Tables[0].Rows[0]["FVersion"].ToString(); //omodel.HMaterTypeID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HMaterTypeID"]); omodel.HStatus = Ds.Tables[0].Rows[0]["FStatus"].ToString(); omodel.HMaterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FItemID"]); //omodel.HPicNo = Ds.Tables[0].Rows[0]["FChartNumber"].ToString(); omodel.HUnitID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FUnitID"]); omodel.HQty = DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["FAuxQty"]); omodel.HProdRate = DBUtility.ClsPub.isSingle(Ds.Tables[0].Rows[0]["FYield"]); omodel.HJump = Ds.Tables[0].Rows[0]["FBOMSkip"].ToString(); // omodel.HMaker = Ds.Tables[0].Rows[0]["FCheckID"].ToString().Trim(); omodel.HMakeDate = Ds.Tables[0].Rows[0]["FCheckDate"].ToString().Trim(); omodel.HUpDater = Ds.Tables[0].Rows[0]["FOperatorID"].ToString().Trim(); omodel.HUpDateDate = Ds.Tables[0].Rows[0]["FEntertime"].ToString().Trim(); //omodel.HBackDate = Ds.Tables[0].Rows[0]["HBackDate"].ToString().Trim(); //omodel.HBacker = Ds.Tables[0].Rows[0]["HBacker"].ToString().Trim(); omodel.HChecker = Ds.Tables[0].Rows[0]["FCheckerID"].ToString().Trim(); omodel.HCheckDate = Ds.Tables[0].Rows[0]["FAudDate"].ToString().Trim(); //omodel.HCloseDate = Ds.Tables[0].Rows[0]["HCloseDate"].ToString().Trim(); //omodel.HCloseMan = Ds.Tables[0].Rows[0]["HCloseMan"].ToString().Trim(); //omodel.HDeleteDate = Ds.Tables[0].Rows[0]["HDeleteDate"].ToString().Trim(); //omodel.HDeleteMan = Ds.Tables[0].Rows[0]["HDeleteMan"].ToString().Trim(); //循环 DataSet DsSub; DsSub = oK3Cn.RunProcReturn("Select * from ICBomChild Where FInterID=" + lngBillKey.ToString() + " order by HEntryID ", "ICBomChild"); DetailColl.Clear();//清空 for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++) { Model.ClsGy_ICBomBillSub_K3 oSub = new Model.ClsGy_ICBomBillSub_K3(); oSub.HInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FInterID"].ToString()); oSub.HEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FEntryID"].ToString()); oSub.HWhID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FStockID"].ToString()); oSub.HSPID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FSPID"].ToString()); oSub.HWasteRate = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["FScrap"].ToString()); oSub.HMaterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FItemID"].ToString()); oSub.HUnitID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FUnitID"].ToString()); oSub.HRelQty = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["FAuxQty"].ToString()); oSub.HQty = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FQty"].ToString()); oSub.HProcID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FOperID"].ToString()); //oSub.HCloseMan = DsSub.Tables[0].Rows[i]["HCloseMan"].ToString().Trim(); //oSub.HCloseType = (bool)DsSub.Tables[0].Rows[i]["HCloseType"]; oSub.HChildType = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["FMaterielType"]); oSub.HRemark = DsSub.Tables[0].Rows[i]["FNote"].ToString().Trim(); oSub.HRemark2 = DsSub.Tables[0].Rows[i]["FNote1"].ToString().Trim(); oSub.HRemark3 = DsSub.Tables[0].Rows[i]["FNote2"].ToString().Trim(); oSub.HRemark4 = DsSub.Tables[0].Rows[i]["FNote3"].ToString().Trim(); // //oSub.HSourceInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSourceInterID"].ToString()); //oSub.HSourceEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSourceEntryID"].ToString()); //oSub.HSourceBillType = DsSub.Tables[0].Rows[i]["HSourceBillType"].ToString().Trim(); //oSub.HSourceBillNo = DsSub.Tables[0].Rows[i]["HSourceBillNo"].ToString().Trim(); //oSub.HRelationQty = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HRelationQty"].ToString()); //oSub.HRelationMoney = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HRelationMoney"].ToString()); DetailColl.Add(oSub); } sReturn = "显示单据成功!"; return true; } catch (Exception e) { sReturn = e.Message; throw (e); } } public bool Get_BOMIDByMaterID(long HMaterID,ref long HBOMID,ref string HBOMNumber) { try { //查询主表 DataSet Ds; Ds = oCnK3.RunProcReturn("Select FInterID,FBOMNumber from icbom Where FItemID=" + HMaterID.ToString() + " and FUseStatus=1072", "icbom"); if (Ds.Tables[0].Rows.Count == 0) { return false; } //固定赋值=========================================== // HBOMID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FInterID"]); HBOMNumber = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["FBOMNumber"]); return true; } catch (Exception e) { throw (e); } } public bool CheckBomMater(long HInterID, ref string sReturn) { try { //查询主表 DataSet Ds; Ds = oCn.RunProcReturn("exec h_p_Sc_ICBomBill_Tmp_MaterCheck " + HInterID.ToString(), "xt_xtgnb"); if (Ds.Tables[0].Rows.Count == 0) { return true; } // sReturn = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0][0]); if (sReturn == "") { return true; } else { return false; } } catch (Exception e) { throw (e); } } public bool AddBomBill(long HInterID, ref string sReturn) { //查询主表 DataSet Ds; long NewInterID = 0; string NewBillNo = ""; Int64 K3UserID = DBUtility.ClsPub.GetUser_K3(DBUtility.ClsPub.CurUserName); if (K3UserID == 0) { sReturn = "当前用户无效,金蝶中未添加"; return false; } Ds = oK3Cn.RunProcReturn("declare @InterID int set @InterID=0 exec GetICMaxNum 'ICBom', @InterID output, 1, 16394 select ltrim(@InterID)", "GetICMaxNum"); NewInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0][0]) + 10000000; Ds = oK3Cn.RunProcReturn("exec HX_GetICBillNo 1," + BillType, "t_billcodeby"); NewBillNo = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0][0]); long HBillerID = DBUtility.ClsPub.GetUser_K3(DBUtility.ClsPub.CurUserName); try { oCn.BeginTran(); Ds = oCn.RunProcReturn("exec h_p_Sc_ICBomBill_Add " + HInterID.ToString() + "," + NewInterID.ToString() + ",'" + NewBillNo + "'," + K3UserID.ToString(), "xt_xtgnb"); oCn.RunProc("EXEC h_p_K3_Gy_ICBomCheckAndUsed " + NewInterID.ToString() + "," + HBillerID + ""); oCn.Commit(); sReturn = ""; return true; } catch (Exception e) { oCn.RollBack(); sReturn = e.Message; throw (e); } } //判断 修改人和制单人 是否同一人 public bool Fun_CheckMakerIsSame(Int64 iBomInterID) { try { DataSet Ds; Int64 K3UserID =DBUtility.ClsPub.GetUser_K3(DBUtility.ClsPub.CurUserName); if (K3UserID == 0) { return false; } Ds = oCn.RunProcReturn("exec h_p_Sc_CheckMakerIsSame " + iBomInterID.ToString() + "," + K3UserID.ToString(), "h_p_Sc_CheckMakerIsSame"); if (Ds == null || Ds.Tables[0].Rows.Count == 0) { return false; } else { if (DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0][0]) == 1) { return true; } else { return false; } } return false; } catch (Exception e) { return false; } } } }