using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using System.Data;
|
|
namespace DAL
|
{
|
public class ClsKf_EntrustOrderBill_K3 : DBUtility.ClsXt_BaseBill
|
{
|
public Model.ClsKf_EntrustOrderBillMain_K3 omodel = new Model.ClsKf_EntrustOrderBillMain_K3();
|
public List<Model.ClsKf_EntrustOrderBillSub_K3> DetailColl = new List<Model.ClsKf_EntrustOrderBillSub_K3>();
|
|
public ClsKf_EntrustOrderBill_K3()
|
{
|
base.MvarItemKeyForWeb = "h_v_K3_ICSubContractBillMain_ForWeb";
|
base.MvarItemKeySubForWeb = "h_v_K3_ICSubContractBillSub_ForWeb";
|
base.MvarItemKeySub = "ICSubContractEntry";
|
base.MvarItemKeySub2 = "";
|
base.MvarItemKeySub3 = "";
|
base.MvarItemKeySub4 = "";
|
base.MvarItemKey = "ICSubContract";
|
base.MvarReportTitle = "委外订单";
|
base.BillType = "1007105";
|
}
|
|
#region 固定代码
|
|
~ClsKf_EntrustOrderBill_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 ICSubContract where FTranType='" + BillType + "' and FBillNo ='" + sBillNo + "'";
|
}
|
else
|
{
|
sSql = "Select FInterID from ICSubContract where FTranType='" + BillType + "' and FBillNo ='" + sBillNo + "' and FInterID<>" + lngBillKey.ToString();
|
}
|
DataSet Ds;
|
Ds = oK3Cn.RunProcReturn(sSql, "ICSubContract");
|
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 ICSubContractEntry where FInterID=" + lngBillKey.ToString());
|
}
|
//删除主表
|
public void DeleteBillMain(Int64 lngBillKey)
|
{
|
oK3Cn.RunProc("Delete From ICSubContract 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 ICSubContract " +
|
"(FInterID,FBillNo,FStatus,Fdate" +
|
",FSupplyID,FCurrencyID,FExchangeRate,FEmployee,FMangerID" +
|
",FDepartment,FPOOrdBillNo,FCancellation,FClosed" +
|
") " +
|
" values(" + lngBillKey.ToString() + ",'" + omodel.HBillNo + "',0,'" + omodel.HDate.ToShortDateString() + "'" +
|
", " + omodel.HSupID.ToString() + "," + omodel.HCurID.ToString() + "," + omodel.HExRate.ToString() + "," + omodel.HEmpID.ToString() + "," + omodel.HMangerID.ToString() +
|
", " + omodel.HDeptID.ToString() + ",'" + omodel.HPOOrderBillNo + "'," + DBUtility.ClsPub.BoolToString(omodel.HStopflag) + "," + DBUtility.ClsPub.BoolToString(omodel.HClosedflag) +
|
") ");
|
//插入子表
|
foreach (Model.ClsKf_EntrustOrderBillSub_K3 oSub in DetailColl)
|
{
|
oK3Cn.RunProc("Insert into ICSubContractEntry " +
|
" (FInterID,FEntryID,FFetchDate,Fnote" +
|
",FItemID,FUnitID,FAuxQty,FSecQty,FQty" +
|
",FAuxPrice,FAuxTaxPrice,FAmount,FDiscountRate,FTaxRate" +
|
",FTaxAmount,FAllAmount" +
|
") values("
|
+ omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + ",0,'" + oSub.HRemark + "'" +
|
", " + oSub.HMaterID.ToString() + "," + oSub.HUnitID.ToString() + "," + oSub.HAuxQty.ToString() + "," + oSub.HSecQty.ToString() + "," + oSub.HQty.ToString() +
|
", " + oSub.HPrice.ToString() + "," + oSub.HTaxPrice.ToString() + "," + oSub.HMoney.ToString() + "," + oSub.HDiscountRate.ToString() + "," + oSub.HTaxRate.ToString() +
|
", " + oSub.HTaxMoney.ToString() + "," + oSub.HlineTotal.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 'ICSubContract', @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 ICSubContract " +
|
"(FInterID,FBillNo,FStatus,Fdate" +
|
",FSupplyID,FCurrencyID,FExchangeRate,FEmployee,FMangerID" +
|
",FDepartment,FPOOrdBillNo,FCancellation,FClosed" +
|
") " +
|
" values(" + omodel.HInterID.ToString() + ",'" + omodel.HBillNo + "',0,'" + omodel.HDate.ToShortDateString() + "'" +
|
", " + omodel.HSupID.ToString() + "," + omodel.HCurID.ToString() + "," + omodel.HExRate.ToString() + "," + omodel.HEmpID.ToString() + "," + omodel.HMangerID.ToString() +
|
", " + omodel.HDeptID.ToString() + ",'" + omodel.HPOOrderBillNo + "'," + DBUtility.ClsPub.BoolToString(omodel.HStopflag) + "," + DBUtility.ClsPub.BoolToString(omodel.HClosedflag) +
|
") ");
|
//插入子表
|
foreach (Model.ClsKf_EntrustOrderBillSub_K3 oSub in DetailColl)
|
{
|
oK3Cn.RunProc("Insert into ICSubContractEntry " +
|
" (FInterID,FEntryID,FFetchDate,Fnote" +
|
",FItemID,FUnitID,FAuxQty,FSecQty,FQty" +
|
",FAuxPrice,FAuxTaxPrice,FAmount,FDiscountRate,FTaxRate" +
|
",FTaxAmount,FAllAmount" +
|
") values("
|
+ omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + ",0,'" + oSub.HRemark + "'" +
|
", " + oSub.HMaterID.ToString() + "," + oSub.HUnitID.ToString() + "," + oSub.HAuxQty.ToString() + "," + oSub.HSecQty.ToString() + "," + oSub.HQty.ToString() +
|
", " + oSub.HPrice.ToString() + "," + oSub.HTaxPrice.ToString() + "," + oSub.HMoney.ToString() + "," + oSub.HDiscountRate.ToString() + "," + oSub.HTaxRate.ToString() +
|
", " + oSub.HTaxMoney.ToString() + "," + oSub.HlineTotal.ToString() +
|
") ");
|
//更新申请单关联数量
|
//oK3Cn.RunProc("EXEC p_UpdateBillRelateData " + this.BillType + "," + omodel.HInterID.ToString() + ",'ICSubContract','ICSubContractEntry'");
|
|
//oK3Cn.RunProc("update porequestentry set fcommitqty=Fqty,fauxcommitqty=Fauxqty,FMRPClosed=1 where FMRPClosed<>1 and Fitemid=" + oSub.HMaterID);
|
}
|
sReturn = "新增单据成功!";
|
oK3Cn.Commit();
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
oK3Cn.RollBack();
|
throw (e);
|
}
|
}
|
|
//Web接受
|
public void WebAccept(Int64 lngBillKey, Int64 HBillType, ref string sReturn)
|
{
|
|
try
|
{
|
oCn.RunProc(" exec h_p_Web_WebAccept " + lngBillKey + "," + HBillType);
|
sReturn = "";
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
throw (e);
|
}
|
}
|
|
//Web拒绝
|
public void WebRefuse(Int64 lngBillKey, Int64 HBillType, ref string sReturn)
|
{
|
|
try
|
{
|
oCn.RunProc(" exec h_p_Web_WebRefuse " + lngBillKey + "," + HBillType);
|
sReturn = "";
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
throw (e);
|
}
|
}
|
|
//显示单据
|
public override bool ShowBill(Int64 lngBillKey, ref string sReturn)
|
{
|
try
|
{
|
//查询主表
|
DataSet Ds;
|
Ds = oK3Cn.RunProcReturn("Select * from ICSubContract Where FInterID=" + lngBillKey.ToString(), "ICSubContract");
|
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.HSupID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FSupplyID"]);
|
omodel.HCurID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FCurrencyID"]);
|
omodel.HExRate = DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["FExchangeRate"]);
|
omodel.HEmpID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FEmployee"]);
|
omodel.HMangerID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FMangerID"]);
|
omodel.HDeptID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FDepartment"]);
|
omodel.HPOOrderBillNo = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["FPOOrdBillNo"]);
|
omodel.HStopflag = DBUtility.ClsPub.isBool(Ds.Tables[0].Rows[0]["FCancellation"]);
|
omodel.HClosedflag = DBUtility.ClsPub.isBool(Ds.Tables[0].Rows[0]["FClosed"]);//
|
DataSet Ds1;
|
Ds1 = oCnK3.RunProcReturn("select fname from t_User where fuserid=" + DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FBillerID"]), "t_User");
|
if (Ds1.Tables[0].Rows.Count != 0)
|
{
|
omodel.HMaker = Ds1.Tables[0].Rows[0][0].ToString();
|
}
|
omodel.HCheckDate = Ds.Tables[0].Rows[0]["FCheckDate"].ToString().Trim();
|
if (DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FCheckerID"]) != 0)
|
{
|
DataSet Ds2;
|
Ds2 = oCnK3.RunProcReturn("select fname from t_User where fuserid=" + DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FCheckerID"]), "t_User");
|
if (Ds2.Tables[0].Rows.Count != 0)
|
{
|
omodel.HChecker = Ds2.Tables[0].Rows[0][0].ToString();
|
}
|
}
|
else
|
{
|
omodel.HChecker = "";
|
}
|
//循环
|
DataSet DsSub;
|
DsSub = oK3Cn.RunProcReturn("Select * from ICSubContractEntry Where FInterID=" + lngBillKey.ToString() + " order by HEntryID ", "ICSubContractEntry");
|
DetailColl.Clear();//清空
|
for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++)
|
{
|
Model.ClsKf_EntrustOrderBillSub_K3 oSub = new Model.ClsKf_EntrustOrderBillSub_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.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.HQty = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FQty"].ToString());
|
oSub.HPrice = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["Fauxprice"].ToString());
|
oSub.HTaxPrice = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FAuxTaxPrice"].ToString());
|
oSub.HMoney = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["Famount"].ToString());
|
oSub.HDiscountRate = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FDiscountRate"].ToString());
|
oSub.HTaxRate = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FTaxRate"].ToString());
|
oSub.HTaxMoney = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FTaxAmount"].ToString());
|
oSub.HlineTotal = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FAllAmount"].ToString());
|
oSub.HRemark = DsSub.Tables[0].Rows[i]["Fnote"].ToString().Trim();
|
DetailColl.Add(oSub);
|
}
|
sReturn = "显示单据成功!";
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
throw (e);
|
}
|
}
|
|
|
}
|
|
}
|