using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using System.Data;
|
|
namespace DAL
|
{
|
public class ClsSc_PPOrderBill_K3 : DBUtility.ClsXt_BaseBill
|
{
|
public Model.ClsSc_PPOrderBillMain_K3 omodel = new Model.ClsSc_PPOrderBillMain_K3();
|
public List<Model.ClsSc_PPOrderBillSub_K3> DetailColl = new List<Model.ClsSc_PPOrderBillSub_K3>();
|
|
public ClsSc_PPOrderBill_K3()
|
{
|
base.MvarItemKeySub = "PPOrderEntry";
|
base.MvarItemKeySub2 = "";
|
base.MvarItemKeySub3 = "";
|
base.MvarItemKeySub4 = "";
|
base.MvarItemKey = "PPOrder";
|
base.MvarReportTitle = "预测单";
|
base.BillType = "87";
|
}
|
|
#region 固定代码
|
|
~ClsSc_PPOrderBill_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 PPOrder where FTranType='" + BillType + "' and FBillNo ='" + sBillNo + "'";
|
}
|
else
|
{
|
sSql = "Select FInterID from PPOrder where FTranType='" + BillType + "' and FBillNo ='" + sBillNo + "' and FInterID<>" + lngBillKey.ToString();
|
}
|
DataSet Ds;
|
Ds = oK3Cn.RunProcReturn(sSql, "PPOrder");
|
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 PPOrderEntry where FInterID=" + lngBillKey.ToString());
|
}
|
//删除主表
|
public void DeleteBillMain(Int64 lngBillKey)
|
{
|
oK3Cn.RunProc("Delete From PPOrder 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 PPOrder " +
|
"(FInterID,FBillNo,FBrNo,FTranType" +
|
",FCancellation,FStatus,FDate,FCheckDate,FBillerID" +
|
",FMultiCheckDate1,FMultiCheckDate2,FMultiCheckDate3" +
|
",FMultiCheckDate4,FMultiCheckDate5,FMultiCheckDate6" +
|
//",FSelTranType" +//,FPlanCategory"+
|
") " +
|
" values(" + lngBillKey.ToString() + ",'" + omodel.HBillNo + "','0'," + this.BillType +
|
",0,0,'" + omodel.HDate.ToShortDateString() + "',null,'" + omodel.HMaker + "'" +
|
",null,null,null" +
|
",null,null,null" +
|
//",0" +//,'1'" +
|
") ");
|
//插入子表
|
foreach (Model.ClsSc_PPOrderBillSub_K3 oSub in DetailColl)
|
{
|
oK3Cn.RunProc("Insert into PPOrderEntry " +
|
" (FInterID,FEntryID,FBrNo,FCustID,FItemID" +
|
",FQty,FSelQty,FSaleQty,FUnitID,FAuxQty,FAuxSelQty,FAuxSaleQty" +
|
",FNeedDate,FNeedDateEnd,FSplitCycleID"+//,FPlanMode,FMTONo" +
|
",FBomInterID,FNote,FMrpLockFlag" +
|
",FSourceEntryID" +
|
") values("
|
+ omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + ",'0'," + oSub.HCusID.ToString() + "," + oSub.HMaterID.ToString() +
|
"," + oSub.HQty.ToString() + ",0,0," + oSub.HUnitID.ToString() + "," + oSub.HQty.ToString() + ",0,0" +
|
",'" + oSub.HBeginDate.ToShortDateString() + "','" + oSub.HEndDate.ToShortDateString() + "',11030"+//,14036,''" +
|
",0,'" + oSub.HRemark + "',0" +
|
"," + oSub.HSourceEntryID.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 'PPOrder', @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 PPOrder " +
|
"(FInterID,FBillNo,FBrNo,FTranType" +
|
",FCancellation,FStatus,FDate,FCheckDate,FBillerID" +
|
",FMultiCheckDate1,FMultiCheckDate2,FMultiCheckDate3" +
|
",FMultiCheckDate4,FMultiCheckDate5,FMultiCheckDate6" +
|
//",FSelTranType,Fplancategory" +
|
") " +
|
" values(" + omodel.HInterID.ToString() + ",'" + omodel.HBillNo + "','0'," + this.BillType +
|
",0,0,'" + omodel.HDate.ToShortDateString() + "',null,'" + omodel.HMaker + "'" +
|
",null,null,null" +
|
",null,null,null" +
|
//",0,'1'" +
|
") ");
|
//插入子表
|
foreach (Model.ClsSc_PPOrderBillSub_K3 oSub in DetailColl)
|
{
|
oK3Cn.RunProc("Insert into PPOrderEntry " +
|
" (FInterID,FEntryID,FBrNo,FCustID,FItemID" +
|
",FQty,FSelQty,FSaleQty,FUnitID,FAuxQty,FAuxSelQty,FAuxSaleQty" +
|
",FNeedDate,FNeedDateEnd,FSplitCycleID" +//,FPlanMode,FMTONo" +
|
",FBomInterID,FNote,FMrpLockFlag" +
|
",FSourceEntryID" +
|
") values("
|
+ omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + ",'0'," + oSub.HCusID.ToString() + "," + oSub.HMaterID.ToString() +
|
"," + oSub.HQty.ToString() + ",0,0," + oSub.HUnitID.ToString() + "," + oSub.HQty.ToString() + ",0,0" +
|
",'" + oSub.HBeginDate.ToShortDateString() + "','" + oSub.HEndDate.ToShortDateString() + "',11030" +//,14036,''" +
|
",0,'" + oSub.HRemark + "',0" +
|
"," + oSub.HSourceEntryID.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 PPOrder Where FInterID=" + lngBillKey.ToString(), "PPOrder");
|
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());
|
//
|
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.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]["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 PPOrderEntry Where FInterID=" + lngBillKey.ToString() + " order by HEntryID ", "PPOrderEntry");
|
DetailColl.Clear();//清空
|
for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++)
|
{
|
Model.ClsSc_PPOrderBillSub_K3 oSub = new Model.ClsSc_PPOrderBillSub_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.HCusID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FCustID"].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.HCloseMan = DsSub.Tables[0].Rows[i]["HCloseMan"].ToString().Trim();
|
//oSub.HCloseType = (bool)DsSub.Tables[0].Rows[i]["HCloseType"];
|
oSub.HBeginDate = Convert.ToDateTime(DsSub.Tables[0].Rows[i]["FNeedDate"].ToString().Trim());
|
oSub.HEndDate = Convert.ToDateTime(DsSub.Tables[0].Rows[i]["FNeedDateEnd"].ToString().Trim());
|
oSub.HRemark = DsSub.Tables[0].Rows[i]["FNote"].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 ConFirmBill(Int64 HInterID, Int64 HEntryID, DateTime HDate, Int64 sType, ref string sReturn)
|
{
|
|
try
|
{
|
string HConFirmer = DBUtility.ClsPub.CurUserName;
|
oCn.RunProc("exec h_p_Sc_PPOrderBill_K3_Check " + HInterID.ToString() + "," + HEntryID.ToString() + ",'" + HDate.ToShortDateString() + "','" + HConFirmer + "'," + sType.ToString());
|
sReturn = "";
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
throw (e);
|
}
|
}
|
|
|
|
}
|
|
}
|