using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using System.Data;
|
|
namespace DAL
|
{
|
public class ClsCg_PORequestBill_K3 : DBUtility.ClsXt_BaseBill
|
{
|
public Model.ClsCg_PORequestBillMain_K3 omodel = new Model.ClsCg_PORequestBillMain_K3();
|
public List<Model.ClsCg_PORequestBillSub_K3> DetailColl = new List<Model.ClsCg_PORequestBillSub_K3>();
|
|
public ClsCg_PORequestBill_K3()
|
{
|
base.MvarItemKeySub = "PORequestEntry";
|
base.MvarItemKeySub2 = "";
|
base.MvarItemKeySub3 = "";
|
base.MvarItemKeySub4 = "";
|
base.MvarItemKey = "PORequest";
|
base.MvarReportTitle = "采购申请单";
|
base.BillType = "70";
|
}
|
|
#region 固定代码
|
|
~ClsCg_PORequestBill_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 PORequest where FTranType='" + BillType + "' and FBillNo ='" + sBillNo + "'";
|
}
|
else
|
{
|
sSql = "Select FInterID from PORequest where FTranType='" + BillType + "' and FBillNo ='" + sBillNo + "' and FInterID<>" + lngBillKey.ToString();
|
}
|
DataSet Ds;
|
Ds = oK3Cn.RunProcReturn(sSql, "PORequest");
|
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 PORequestEntry where FInterID=" + lngBillKey.ToString());
|
}
|
//删除主表
|
public void DeleteBillMain(Int64 lngBillKey)
|
{
|
oK3Cn.RunProc("Delete From PORequest 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 PORequest " +
|
"(FInterID,FBillNo,FBrNo,FTranType,FCancellation,FStatus" +
|
",Fdate" +
|
",FCheckTime,FDeptID,FBillerID" +
|
",FMultiCheckDate1,FMultiCheckDate2" +
|
",FMultiCheckDate3,FMultiCheckDate4,FMultiCheckDate5,FMultiCheckDate6" +
|
",FSelTranType,FExplanation" +
|
",FPrintCount,FPlanCategory,FBizType,FPlanConfirmed,FRequesterID" +
|
") " +
|
" values(" + omodel.HInterID.ToString() + ",'" + omodel.HBillNo + "','0'," + this.BillType + ",0,0" +
|
",'" + omodel.HDate.ToShortDateString() + "'" +
|
",null," + omodel.HDeptID.ToString() + "," + omodel.HBillerID.ToString() +
|
",null,null" +
|
",null,null,null,null" +
|
",81,'" + omodel.HExplanation +
|
"',0,1,12510,1," + omodel.HEmpID +
|
") ");
|
//插入子表
|
foreach (Model.ClsCg_PORequestBillSub_K3 oSub in DetailColl)
|
{
|
oK3Cn.RunProc("Insert into PORequestEntry " +
|
" (FInterID,FEntryID,FBrNo,FItemID" +
|
",FAuxPropID,FQty,FUnitID,Fauxqty,FSecCoefficient,FSecQty" +
|
",Fauxprice" +
|
",FSourceBillNo,FSourceTranType,FSourceInterId,FSourceEntryID" +
|
",FMrpLockFlag" +
|
",FPlanMode,FMTONo,FFetchTime,FAPurchTime" +
|
") values("
|
+ omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + ",'0'," + oSub.HMaterID.ToString() +
|
",0," + oSub.HQty.ToString() + "," + oSub.HUnitID.ToString() + "," + oSub.HQty.ToString() + ",0,0" +
|
"," + oSub.HPrice.ToString() +
|
",'" + oSub.HSourceBillNo + "'," + oSub.HSourceBillType + "," + oSub.HSourceInterID.ToString() + "," + oSub.HSourceEntryID.ToString() +
|
",0" +
|
",14036,'','" + oSub.HDate.ToShortDateString() + "','" + oSub.HDate.ToShortDateString()+"'"+
|
") ");
|
}
|
sReturn = "修改单据成功!";
|
oK3Cn.Commit();
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
oK3Cn.RollBack();
|
throw (e);
|
}
|
}
|
//新增单据
|
public override bool AddBill(ref string sReturn)
|
{
|
try
|
{
|
DataSet DsBiller;
|
long HBillerID = 0;
|
string HSourceBillType = "";
|
DsBiller = oK3Cn.RunProcReturn("select top 1 fuserid from t_User where fname='" + DBUtility.ClsPub.CurUserName + "'", "t_User");
|
if (DsBiller.Tables[0].Rows.Count != 0)
|
{
|
omodel.HBillerID = DBUtility.ClsPub.isLong(DsBiller.Tables[0].Rows[0][0]);
|
}
|
else
|
{
|
omodel.HBillerID = 16394;
|
}
|
|
DataSet Ds;
|
//得到mainid
|
Ds = oK3Cn.RunProcReturn("declare @InterID int set @InterID=0 exec GetICMaxNum 'PORequest', @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 PORequest " +
|
"(FInterID,FBillNo,FBrNo,FTranType,FCancellation,FStatus" +
|
",Fdate" +
|
",FCheckTime,FDeptID,FBillerID" +
|
",FMultiCheckDate1,FMultiCheckDate2" +
|
",FMultiCheckDate3,FMultiCheckDate4,FMultiCheckDate5,FMultiCheckDate6" +
|
",FSelTranType,FExplanation" +
|
",FPrintCount,FPlanCategory,FBizType,FPlanConfirmed,FRequesterID" +
|
") " +
|
" values(" + omodel.HInterID.ToString() + ",'" + omodel.HBillNo + "','0'," + this.BillType + ",0,0" +
|
",'" + omodel.HDate.ToShortDateString() + "'" +
|
",null," + omodel.HDeptID.ToString() + "," + omodel.HBillerID.ToString() +
|
",null,null" +
|
",null,null,null,null" +
|
",81,'" +omodel.HExplanation +
|
"',0,1,12510,1," +omodel.HEmpID+
|
") ");
|
//插入子表
|
foreach (Model.ClsCg_PORequestBillSub_K3 oSub in DetailColl)
|
{
|
oK3Cn.RunProc("Insert into PORequestEntry " +
|
" (FInterID,FEntryID,FBrNo,FItemID" +
|
",FAuxPropID,FQty,FUnitID,Fauxqty,FSecCoefficient,FSecQty" +
|
",Fauxprice" +
|
",FSourceBillNo,FSourceTranType,FSourceInterId,FSourceEntryID" +
|
",FMrpLockFlag" +
|
",FPlanMode,FMTONo,FFetchTime,FAPurchTime" +
|
") values("
|
+ omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + ",'0'," + oSub.HMaterID.ToString() +
|
",0," + oSub.HQty.ToString() + "," + oSub.HUnitID.ToString() + "," + oSub.HQty.ToString() + ",0,0" +
|
"," + oSub.HPrice.ToString() +
|
",'" + oSub.HSourceBillNo + "'," + oSub.HSourceBillType + "," + oSub.HSourceInterID.ToString() + "," + oSub.HSourceEntryID.ToString() +
|
",0" +
|
",14036,'','" + oSub.HDate.ToShortDateString() + "','" + oSub.HDate.ToShortDateString()+"'"+
|
") ");
|
//更新申请单关联数量
|
//oK3Cn.RunProc("EXEC p_UpdateBillRelateData " + this.BillType + "," + omodel.HInterID.ToString() + ",'PORequest','PORequestEntry'");
|
|
//oK3Cn.RunProc("update porequestentry set fcommitqty=Fqty,fauxcommitqty=Fauxqty,FMRPClosed=1 where FMRPClosed<>1 and Fitemid=" + oSub.HMaterID);
|
}
|
//更新申请单关闭标志
|
|
//oK3Cn.RunProc("EXEC h_p_Cg_PORequestToUpdate_K3 "+ omodel.HInterID.ToString());
|
|
//oK3Cn.RunProc("UPDATE T1 SET T1.FStatus=CASE WHEN NOT EXISTS(SELECT 1 FROM POrequestEntry WHERE FInterID=T1.FInterID AND FCommitQty<>0) THEN 1 " +
|
// "WHEN NOT EXISTS (SELECT 1 FROM POrequestEntry WHERE FInterID=T1.FInterID AND FQty>FCommitQty) THEN 3 ELSE 2 END," +
|
// "T1.FCLOSED=CASE WHEN NOT EXISTS (SELECT 1 FROM POrequestEntry WHERE FInterID=T1.FInterID AND FQty>FCommitQty) THEN 1 ELSE 0 END " +
|
// "FROM POrequest T1 where T1.FStatus in (1,2)");
|
|
|
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 PORequest Where FInterID=" + lngBillKey.ToString(), "PORequest");
|
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.HExplanation = Ds.Tables[0].Rows[0]["FExplanation"].ToString().Trim();
|
//
|
//omodel.HCusID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FCustID"]);
|
//omodel.HCurID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FCurrencyID"]);
|
omodel.HDeptID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FDeptID"]);
|
omodel.HEmpID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FRequesterID"]);
|
//omodel.HMangerID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FMangerID"]);
|
//omodel.HSSID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FSettleID"]);
|
//
|
//omodel.HExRate = DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["FExchangeRate"]);
|
//omodel.HAddress = Ds.Tables[0].Rows[0]["FFetchAdd"].ToString().Trim();
|
//
|
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 = "";
|
}
|
omodel.HBillerID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FBillerID"].ToString());
|
omodel.HMakeDate = Ds.Tables[0].Rows[0]["Fdate"].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]["FCheckDate"].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 PORequestEntry Where FInterID=" + lngBillKey.ToString() + " order by HEntryID ", "PORequestEntry");
|
DetailColl.Clear();//清空
|
for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++)
|
{
|
Model.ClsCg_PORequestBillSub_K3 oSub = new Model.ClsCg_PORequestBillSub_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.HQty = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["Fauxqty"].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.HTaxRate = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FCess"].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.HCloseMan = DsSub.Tables[0].Rows[i]["HCloseMan"].ToString().Trim();
|
//oSub.HCloseType = (bool)DsSub.Tables[0].Rows[i]["HCloseType"];
|
//oSub.HDate = Convert.ToDateTime(DsSub.Tables[0].Rows[i]["FDate"].ToString().Trim());
|
//oSub.HRemark = DsSub.Tables[0].Rows[i]["Fnote"].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();
|
//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);
|
}
|
}
|
|
|
}
|
|
}
|