using System; using System.Collections.Generic; using System.Text; using System.Data; namespace DAL { public class ClsXs_SellInvoiceSpecBill_K3 : DBUtility.ClsXt_BaseBill { public Model.ClsXs_SellInvoiceSpecBillMain_K3 omodel = new Model.ClsXs_SellInvoiceSpecBillMain_K3(); public List DetailColl = new List(); public ClsXs_SellInvoiceSpecBill_K3() { base.MvarItemKeySub = "ICSaleEntry"; base.MvarItemKeySub2 = ""; base.MvarItemKeySub3 = ""; base.MvarItemKeySub4 = ""; base.MvarItemKey = "ICSale"; base.MvarReportTitle = "KD销售发票(专用)"; base.BillType = "80"; } #region 固定代码 ~ClsXs_SellInvoiceSpecBill_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 ICSale where FTranType='" + BillType + "' and FBillNo ='" + sBillNo + "'"; } else { sSql = "Select FInterID from ICSale where FTranType='" + BillType + "' and FBillNo ='" + sBillNo + "' and FInterID<>" + lngBillKey.ToString(); } DataSet Ds; Ds = oK3Cn.RunProcReturn(sSql, "ICSale"); 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 ICSaleEntry where FInterID=" + lngBillKey.ToString()); } //删除主表 public void DeleteBillMain(Int64 lngBillKey) { oK3Cn.RunProc("Delete From ICSale 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(); //删除主表 DeleteBillMain(lngBillKey); //删除子表 DeleteBillSub(lngBillKey); // //更新主表 oK3Cn.RunProc("Insert Into ICSale " + "(FInterID,FBillNo,FBrNo,FTranType,FCancellation" + ",FStatus,FROB,Fdate" + ",FCheckDate,FBillerID,FMultiCheckDate1,FMultiCheckDate2" + ",FMultiCheckDate3,FMultiCheckDate4,FMultiCheckDate5,FMultiCheckDate6" + ",FCustID,FSettleDate,FSaleStyle,FCussentAcctID" + ",FCurrencyID,FExchangeRate,FDeptID,FManagerID,FEmpID" + ",Fnote,FBank,FSettleID,FAddress,FTaxNum" + ") " + " values(" + lngBillKey.ToString() + ",'" + omodel.HBillNo + "','0'," + this.BillType + ",0" + ",0," + omodel.HRedBlueFlag.ToString() + ",'" + omodel.HDate.ToShortDateString() + "'" + ",Null," + omodel.HBillerID.ToString() + ",Null,Null" + ",Null,Null,Null,Null" + ", " + omodel.HCustID.ToString() + ",'" + omodel.HSettleDate.ToShortDateString() + "'," + omodel.HSaleStyle.ToString() + "," + omodel.HCussentAcctID.ToString() + ", " + omodel.HCurrencyID.ToString() + "," + omodel.HExchangeRate.ToString() + "," + omodel.HDeptID.ToString() + "," + omodel.HManagerID.ToString() + "," + omodel.HEmpID.ToString() + ",'" + omodel.HRemark + "'," + omodel.HBank.ToString() + "," + omodel.HSettleID.ToString() + ",'" + omodel.HAddress + "','" + omodel.HTaxNum + "'" + ") "); //插入子表 foreach (Model.ClsXs_SellInvoiceSpecBillSub_K3 oSub in DetailColl) { oK3Cn.RunProc("Insert into ICSaleEntry " + " (FInterID,FEntryID,FBrNo,Fnote" + ",FSourceBillNo,FSourceTranType,FSourceInterId,FSourceEntryID" + ",FItemID,FAuxPropID,FUnitID,Fauxqty,FSecQty" + ",Fauxprice,FSecCoefficient,FDiscountRate,FAmtDiscount,FStdAmtDiscount" + ",FAuxPriceDiscount,FBatchNo,Famount,FStdAmount,FTaxRate" + ",FTaxAmount,FStdTaxAmount,FAllAmount,FStdAllAmount" + ",FOrderBillNo,FOrderInterID,FOrderEntryID,FAuxTaxPrice" + ") values(" + omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + ",'0','" + oSub.HRemark + "'" + ",'" + oSub.HSourceBillNo + "','" + oSub.HSourceBillType + "'," + oSub.HSourceInterID.ToString() + "," + oSub.HSourceEntryID.ToString() + ", " + oSub.HMaterID.ToString() + "," + oSub.HPropertyID.ToString() + "," + oSub.HUnitID.ToString() + "," + oSub.Hauxqty.ToString() + "," + oSub.HSecQty.ToString() + ", " + oSub.Hauxprice.ToString() + "," + oSub.HSecCoefficient.ToString() + "," + oSub.HDiscountRate.ToString() + "," + oSub.HAmtDiscount.ToString() + "," + oSub.HStdAmtDiscount.ToString() + ", " + oSub.HAuxPriceDiscount.ToString() + ",'" + oSub.HBatchNo + "'," + oSub.Hamount.ToString() + "," + oSub.HStdAmount.ToString() + "," + oSub.HTaxRate.ToString() + ", " + oSub.HTaxAmount.ToString() + "," + oSub.HStdTaxAmount.ToString() + "," + oSub.HAllAmount.ToString() + "," + oSub.HStdAllAmount.ToString() + ",'" + oSub.HOrderBillNo + "'," + oSub.HOrderInterID.ToString() + "," + oSub.HOrderEntryID.ToString() + "," + oSub.HAuxTaxPrice.ToString() + ") "); } 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 'ICSale', @InterID output, 1, 16394 select ltrim(@InterID)", "GetICMaxNum"); omodel.HInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0][0]); //若MAINDI重复则重新获取 oK3Cn.BeginTran(); //主表 oK3Cn.RunProc("Insert Into ICSale " + "(FInterID,FBillNo,FBrNo,FTranType,FCancellation" + ",FStatus,FROB,Fdate" + ",FCheckDate,FBillerID,FMultiCheckDate1,FMultiCheckDate2" + ",FMultiCheckDate3,FMultiCheckDate4,FMultiCheckDate5,FMultiCheckDate6" + ",FCustID,FSettleDate,FSaleStyle,FCussentAcctID" + ",FCurrencyID,FExchangeRate,FDeptID,FManagerID,FEmpID" + ",Fnote,FBank,FSettleID,FAddress,FTaxNum" + ") " + " values(" + omodel.HInterID.ToString() + ",'" + omodel.HBillNo + "','0'," + this.BillType + ",0" + ",0," + omodel.HRedBlueFlag.ToString() + ",'" + omodel.HDate.ToShortDateString() + "'" + ",Null," + omodel.HBillerID.ToString() + ",Null,Null" + ",Null,Null,Null,Null" + ", " + omodel.HCustID.ToString() + ",'" + omodel.HSettleDate.ToShortDateString() + "'," + omodel.HSaleStyle.ToString() + "," + omodel.HCussentAcctID.ToString() + ", " + omodel.HCurrencyID.ToString() + "," + omodel.HExchangeRate.ToString() + "," + omodel.HDeptID.ToString() + "," + omodel.HManagerID.ToString() + "," + omodel.HEmpID.ToString() + ",'" + omodel.HRemark + "'," + omodel.HBank.ToString() + "," + omodel.HSettleID.ToString() + ",'" + omodel.HAddress + "','" + omodel.HTaxNum + "'" + ") "); //插入子表 foreach (Model.ClsXs_SellInvoiceSpecBillSub_K3 oSub in DetailColl) { oK3Cn.RunProc("Insert into ICSaleEntry " + " (FInterID,FEntryID,FBrNo,Fnote" + ",FSourceBillNo,FSourceTranType,FSourceInterId,FSourceEntryID" + ",FItemID,FAuxPropID,FUnitID,Fauxqty,FSecQty" + ",Fauxprice,FSecCoefficient,FDiscountRate,FAmtDiscount,FStdAmtDiscount" + ",FAuxPriceDiscount,FBatchNo,Famount,FStdAmount,FTaxRate" + ",FTaxAmount,FStdTaxAmount,FAllAmount,FStdAllAmount" + ",FOrderBillNo,FOrderInterID,FOrderEntryID,FAuxTaxPrice" + ") values(" + omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + ",'0','" + oSub.HRemark + "'" + ",'" + oSub.HSourceBillNo + "','" + oSub.HSourceBillType + "'," + oSub.HSourceInterID.ToString() + "," + oSub.HSourceEntryID.ToString() + ", " + oSub.HMaterID.ToString() + "," + oSub.HPropertyID.ToString() + "," + oSub.HUnitID.ToString() + "," + oSub.Hauxqty.ToString() + "," + oSub.HSecQty.ToString() + ", " + oSub.Hauxprice.ToString() + "," + oSub.HSecCoefficient.ToString() + "," + oSub.HDiscountRate.ToString() + "," + oSub.HAmtDiscount.ToString() + "," + oSub.HStdAmtDiscount.ToString() + ", " + oSub.HAuxPriceDiscount.ToString() + ",'" + oSub.HBatchNo + "'," + oSub.Hamount.ToString() + "," + oSub.HStdAmount.ToString() + "," + oSub.HTaxRate.ToString() + ", " + oSub.HTaxAmount.ToString() + "," + oSub.HStdTaxAmount.ToString() + "," + oSub.HAllAmount.ToString() + "," + oSub.HStdAllAmount.ToString() + ",'" + oSub.HOrderBillNo + "'," + oSub.HOrderInterID.ToString() + "," + oSub.HOrderEntryID.ToString() + "," + oSub.HAuxTaxPrice.ToString() + ") "); } 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 ICSale Where FInterID=" + lngBillKey.ToString(), "ICSale"); 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]["FBillNo"].ToString().Trim(); omodel.HDate = Convert.ToDateTime(Ds.Tables[0].Rows[0]["Fdate"].ToString().Trim()); omodel.HMaker = Ds.Tables[0].Rows[0]["FBillerID"].ToString().Trim(); omodel.HMakeDate = Ds.Tables[0].Rows[0]["Fdate"].ToString().Trim(); omodel.HCheckDate = Ds.Tables[0].Rows[0]["FCheckDate"].ToString().Trim(); omodel.HChecker = Ds.Tables[0].Rows[0]["FCheckerID"].ToString().Trim(); omodel.HRemark = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["Fnote"]); // omodel.HCustID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FCustID"]); omodel.HBank = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FBank"]); //omodel.HPayCondition = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FPayCondition"]); omodel.HSettleDate = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["FSettleDate"]); omodel.HSaleStyle = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FSaleStyle"]); omodel.HSettleID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FSettleID"]); omodel.HAddress = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["FAddress"]); omodel.HCussentAcctID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FCussentAcctID"]); omodel.HTaxNum = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["FTaxNum"]); omodel.HCurrencyID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FCurrencyID"]); omodel.HExchangeRate = DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["FExchangeRate"]); omodel.HDeptID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FDeptID"]); omodel.HManagerID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FManagerID"]); omodel.HEmpID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FEmpID"]); omodel.HBillerID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FBillerID"]); omodel.HRedBlueFlag = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FROB"]); //循环 DataSet DsSub; DsSub = oK3Cn.RunProcReturn("Select * from ICSaleEntry Where FInterID=" + lngBillKey.ToString() + " order by HEntryID ", "ICSaleEntry"); DetailColl.Clear();//清空 for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++) { Model.ClsXs_SellInvoiceSpecBillSub_K3 oSub = new Model.ClsXs_SellInvoiceSpecBillSub_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.HMaterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FItemID"].ToString()); oSub.HPropertyID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FAuxPropID"].ToString()); oSub.HUnitID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FUnitID"].ToString()); oSub.Hauxqty = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["Fauxqty"].ToString()); oSub.HSecQty = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FSecQty"].ToString()); oSub.Hauxprice = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["Fauxprice"].ToString()); oSub.HSecCoefficient = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FSecCoefficient"].ToString()); oSub.HDiscountRate = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FDiscountRate"].ToString()); oSub.HAmtDiscount = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FAmtDiscount"].ToString()); oSub.HStdAmtDiscount = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FStdAmtDiscount"].ToString()); oSub.HAuxTaxPrice = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FAuxTaxPrice"].ToString()); oSub.HAuxPriceDiscount = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FAuxPriceDiscount"].ToString()); oSub.HBatchNo = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["FBatchNo"].ToString()); oSub.Hamount = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["Famount"].ToString()); oSub.HStdAmount = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FStdAmount"].ToString()); oSub.HTaxRate = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FTaxRate"].ToString()); oSub.HTaxAmount = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FTaxAmount"].ToString()); oSub.HStdTaxAmount = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FStdTaxAmount"].ToString()); oSub.HAllAmount = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FAllAmount"].ToString()); oSub.HStdAllAmount = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FStdAllAmount"].ToString()); oSub.HRemark = DsSub.Tables[0].Rows[i]["Fnote"].ToString().Trim(); oSub.HOrderInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FOrderInterID"].ToString()); oSub.HOrderEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FOrderEntryID"].ToString()); oSub.HOrderBillNo = DsSub.Tables[0].Rows[i]["FOrderBillNo"].ToString().Trim(); // oSub.HSourceInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FSourceInterID"].ToString()); oSub.HSourceEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FSourceEntryID"].ToString()); oSub.HSourceBillType = DsSub.Tables[0].Rows[i]["FSourceTranType"].ToString().Trim(); oSub.HSourceBillNo = DsSub.Tables[0].Rows[i]["FSourceBillNo"].ToString().Trim(); DetailColl.Add(oSub); } sReturn = "显示单据成功!"; return true; } catch (Exception e) { sReturn = e.Message; throw (e); } } } }