using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using System.Data;
|
|
namespace DAL
|
{
|
public class ClsYS_ReceiveBackBill_K3 : DBUtility.ClsXt_BaseBill
|
{
|
public Model.ClsYS_ReceiveBackBillMain_K3 omodel = new Model.ClsYS_ReceiveBackBillMain_K3();
|
public List<Model.ClsYS_ReceiveBackBillSub_K3> DetailColl = new List<Model.ClsYS_ReceiveBackBillSub_K3>();
|
|
public ClsYS_ReceiveBackBill_K3()
|
{
|
base.MvarItemKeySub = "t_rp_ARBillOfSH";
|
base.MvarItemKeySub2 = "";
|
base.MvarItemKeySub3 = "";
|
base.MvarItemKeySub4 = "";
|
base.MvarItemKey = "t_RP_NewReceiveBill";
|
base.MvarReportTitle = "KD应收退款单";
|
base.BillType = "1000015";
|
}
|
|
#region 固定代码
|
|
~ClsYS_ReceiveBackBill_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 FBillID from t_RP_NewReceiveBill where FClassTypeID='" + BillType + "' and FBillNo ='" + sBillNo + "'";
|
}
|
else
|
{
|
sSql = "Select FBillID from t_RP_NewReceiveBill where FClassTypeID='" + BillType + "' and FBillNo ='" + sBillNo + "' and FBillID<>" + lngBillKey.ToString();
|
}
|
DataSet Ds;
|
Ds = oK3Cn.RunProcReturn(sSql, "t_RP_NewReceiveBill");
|
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 t_rp_ARBillOfSH where FBillID=" + lngBillKey.ToString());
|
}
|
//删除主表
|
public void DeleteBillMain(Int64 lngBillKey)
|
{
|
oK3Cn.RunProc("Delete From t_RP_NewReceiveBill where FBillID=" + 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 t_RP_NewReceiveBill " +
|
"(FBillID,FNumber,FBillType,FPre,FRP,FClassTypeID,FDate" +
|
",FFincDate,FItemClassID,FRPBank_Pay,FBankAcct_Pay,faccountid" +
|
",FRPBank,FBankAcct,FCurrencyID,FExchangeRate,FReceiveCyID" +
|
",FAmount,FAmountFor,FReceiveAmount,FReceiveAmountFor,FDiscountAmount" +
|
",FDiscountAmountFor,FContractID,FContractNo,FCustomer,FDepartment" +
|
",FEmployee,FExplanation" +
|
") " +
|
" values(" + lngBillKey.ToString() + ",'" + omodel.HBillNo + "',0,-1,1," + this.BillType + ",'" + omodel.HDate.ToShortDateString() + "'" +
|
",'" + omodel.HFincDate.ToShortDateString() + "'," + omodel.HItemClassID.ToString() + ",'" + omodel.HRPBank_Pay + "','" + omodel.HBankAcct_Pay + "'," + omodel.HAccountid.ToString() +
|
",'" + omodel.HRPBank + "','" + omodel.HBankAcct + "'," + omodel.HCurrencyID.ToString() + "," + omodel.HExchangeRate.ToString() + "," + omodel.HReceiveCyID.ToString() +
|
", " + omodel.HAmount.ToString() + "," + omodel.HAmountFor.ToString() + "," + omodel.HReceiveAmount.ToString() + "," + omodel.HReceiveAmountFor.ToString() + "," + omodel.HDiscountAmount.ToString() +
|
", " + omodel.HDiscountAmountFor.ToString() + "," + omodel.HContractID.ToString() + ",'" + omodel.HContractNo + "'," + omodel.HCustomer.ToString() + "," + omodel.HDepartment.ToString() +
|
", " + omodel.HEmployee.ToString() + ",'" + omodel.HExplanation + "'" +
|
") ");
|
//插入子表
|
foreach (Model.ClsYS_ReceiveBackBillSub_K3 oSub in DetailColl)
|
{
|
oK3Cn.RunProc("Insert into t_rp_ARBillOfSH " +
|
" (FBillID,FContractNo" +
|
",FItemID,FAuxPropID,funitid,FQuantity,FTaxPrice" +
|
",FAccountID,FReceiveCyID,FReceiveCyName,FReceiveExchangeRate,FReceiveAmount" +
|
",FReceiveAmountFor,FSettleCyID,FSettleCyName,FSettleExchangeRate,FSettleQuantity" +
|
",FSettleAmount,FSettleAmountFor,FDiscount,FDiscountFor" +
|
") values("
|
+ omodel.HInterID.ToString() + ",'" + oSub.HContractNo + "'" +
|
", " + oSub.HMaterID.ToString() + "," + oSub.HPropertyID.ToString() + "," + oSub.HUnitID.ToString() + "," + oSub.HQuantity.ToString() + "," + oSub.HTaxPrice.ToString() +
|
", " + oSub.HAccountID.ToString() + "," + oSub.HReceiveCyID.ToString() + ",'" + oSub.HReceiveCyName + "'," + oSub.HReceiveExchangeRate.ToString() + "," + oSub.HReceiveAmount.ToString() +
|
", " + oSub.HReceiveAmountFor.ToString() + "," + oSub.HSettleCyID.ToString() + ",'" + oSub.HSettleCyName + "'," + oSub.HSettleExchangeRate.ToString() + "," + oSub.HSettleQuantity.ToString() +
|
", " + oSub.HSettleAmount.ToString() + "," + oSub.HSettleAmountFor.ToString() + "," + oSub.HDiscount.ToString() + "," + oSub.HDiscountFor.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 't_RP_NewReceiveBill', @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 t_RP_NewReceiveBill " +
|
"(FBillID,FNumber,FBillType,FPre,FRP,FClassTypeID,FDate" +
|
",FFincDate,FItemClassID,FRPBank_Pay,FBankAcct_Pay,faccountid" +
|
",FRPBank,FBankAcct,FCurrencyID,FExchangeRate,FReceiveCyID" +
|
",FAmount,FAmountFor,FReceiveAmount,FReceiveAmountFor,FDiscountAmount" +
|
",FDiscountAmountFor,FContractID,FContractNo,FCustomer,FDepartment" +
|
",FEmployee,FExplanation" +
|
") " +
|
" values(" + omodel.HInterID.ToString() + ",'" + omodel.HBillNo + "',0,-1,1," + this.BillType + ",'" + omodel.HDate.ToShortDateString() + "'" +
|
",'" + omodel.HFincDate.ToShortDateString() + "'," + omodel.HItemClassID.ToString() + ",'" + omodel.HRPBank_Pay + "','" + omodel.HBankAcct_Pay + "'," + omodel.HAccountid.ToString() +
|
",'" + omodel.HRPBank + "','" + omodel.HBankAcct + "'," + omodel.HCurrencyID.ToString() + "," + omodel.HExchangeRate.ToString() + "," + omodel.HReceiveCyID.ToString() +
|
", " + omodel.HAmount.ToString() + "," + omodel.HAmountFor.ToString() + "," + omodel.HReceiveAmount.ToString() + "," + omodel.HReceiveAmountFor.ToString() + "," + omodel.HDiscountAmount.ToString() +
|
", " + omodel.HDiscountAmountFor.ToString() + "," + omodel.HContractID.ToString() + ",'" + omodel.HContractNo + "'," + omodel.HCustomer.ToString() + "," + omodel.HDepartment.ToString() +
|
", " + omodel.HEmployee.ToString() + ",'" + omodel.HExplanation + "'" +
|
") ");
|
//插入子表
|
foreach (Model.ClsYS_ReceiveBackBillSub_K3 oSub in DetailColl)
|
{
|
oK3Cn.RunProc("Insert into t_rp_ARBillOfSH " +
|
" (FBillID,FContractNo" +
|
",FItemID,FAuxPropID,funitid,FQuantity,FTaxPrice" +
|
",FAccountID,FReceiveCyID,FReceiveCyName,FReceiveExchangeRate,FReceiveAmount" +
|
",FReceiveAmountFor,FSettleCyID,FSettleCyName,FSettleExchangeRate,FSettleQuantity" +
|
",FSettleAmount,FSettleAmountFor,FDiscount,FDiscountFor" +
|
") values("
|
+ omodel.HInterID.ToString() + ",'" + oSub.HContractNo + "'" +
|
", " + oSub.HMaterID.ToString() + "," + oSub.HPropertyID.ToString() + "," + oSub.HUnitID.ToString() + "," + oSub.HQuantity.ToString() + "," + oSub.HTaxPrice.ToString() +
|
", " + oSub.HAccountID.ToString() + "," + oSub.HReceiveCyID.ToString() + ",'" + oSub.HReceiveCyName + "'," + oSub.HReceiveExchangeRate.ToString() + "," + oSub.HReceiveAmount.ToString() +
|
", " + oSub.HReceiveAmountFor.ToString() + "," + oSub.HSettleCyID.ToString() + ",'" + oSub.HSettleCyName + "'," + oSub.HSettleExchangeRate.ToString() + "," + oSub.HSettleQuantity.ToString() +
|
", " + oSub.HSettleAmount.ToString() + "," + oSub.HSettleAmountFor.ToString() + "," + oSub.HDiscount.ToString() + "," + oSub.HDiscountFor.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 t_RP_NewReceiveBill Where FBillID=" + lngBillKey.ToString(), "t_RP_NewReceiveBill");
|
if (Ds.Tables[0].Rows.Count == 0)
|
{
|
sReturn = "单据未找到!";
|
return false;
|
}
|
//赋值
|
omodel.HInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FBillID"]);
|
omodel.HBillNo = Ds.Tables[0].Rows[0]["FNumber"].ToString().Trim();
|
omodel.HDate = Convert.ToDateTime(Ds.Tables[0].Rows[0]["FDate"].ToString().Trim());
|
//
|
omodel.HFincDate = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["FFincDate"]);
|
omodel.HItemClassID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FItemClassID"]);
|
omodel.HRPBank_Pay = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["FRPBank_Pay"]);
|
omodel.HBankAcct_Pay = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["FBankAcct_Pay"]);
|
omodel.HAccountid = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["Faccountid"]);
|
omodel.HRPBank = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["FRPBank"]);
|
omodel.HBankAcct = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["FBankAcct"]);
|
omodel.HCurrencyID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FCurrencyID"]);
|
omodel.HExchangeRate = DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["FExchangeRate"]);
|
omodel.HReceiveCyID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FReceiveCyID"]);
|
omodel.HAmount = DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["FAmount"]);
|
omodel.HAmountFor = DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["FAmountFor"]);
|
omodel.HReceiveAmount = DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["FReceiveAmount"]);
|
omodel.HReceiveAmountFor = DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["FReceiveAmountFor"]);
|
omodel.HDiscountAmount = DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["FDiscountAmount"]);
|
omodel.HDiscountAmountFor = DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["FDiscountAmountFor"]);
|
omodel.HContractID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FContractID"]);
|
omodel.HContractNo = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["FContractNo"]);
|
omodel.HCustomer = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FCustomer"]);
|
omodel.HDepartment = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FDepartment"]);
|
omodel.HEmployee = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FEmployee"]);
|
omodel.HExplanation = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["FExplanation"]);
|
//循环
|
DataSet DsSub;
|
DsSub = oK3Cn.RunProcReturn("Select * from t_rp_ARBillOfSH Where FBillID=" + lngBillKey.ToString() + " order by HEntryID ", "t_rp_ARBillOfSH");
|
DetailColl.Clear();//清空
|
for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++)
|
{
|
Model.ClsYS_ReceiveBackBillSub_K3 oSub = new Model.ClsYS_ReceiveBackBillSub_K3();
|
oSub.HInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FBillID"].ToString());
|
oSub.HEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FEntryID"].ToString());
|
oSub.HContractNo = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["FContractNo"].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.HQuantity = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FQuantity"].ToString());
|
oSub.HTaxPrice = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FTaxPrice"].ToString());
|
oSub.HAccountID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FAccountID"].ToString());
|
oSub.HReceiveCyID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FReceiveCyID"].ToString());
|
oSub.HReceiveCyName = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["FReceiveCyName"].ToString());
|
oSub.HReceiveExchangeRate = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FReceiveExchangeRate"].ToString());
|
oSub.HReceiveAmount = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FReceiveAmount"].ToString());
|
oSub.HReceiveAmountFor = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FReceiveAmountFor"].ToString());
|
oSub.HSettleCyID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FSettleCyID"].ToString());
|
oSub.HSettleCyName = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["FSettleCyName"].ToString());
|
oSub.HSettleExchangeRate = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FSettleExchangeRate"].ToString());
|
oSub.HSettleQuantity = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FSettleQuantity"].ToString());
|
oSub.HSettleAmount = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FSettleAmount"].ToString());
|
oSub.HSettleAmountFor = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FSettleAmountFor"].ToString());
|
oSub.HDiscount = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FDiscount"].ToString());
|
oSub.HDiscountFor = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FDiscountFor"].ToString());
|
//
|
DetailColl.Add(oSub);
|
}
|
sReturn = "显示单据成功!";
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
throw (e);
|
}
|
}
|
|
|
}
|
|
}
|