using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using System.Data;
|
|
namespace DAL
|
{
|
public class ClsXs_SeOutStockBill_K3 : DBUtility.ClsXt_BaseBill
|
{
|
public Model.ClsXs_SeOutStockBillMain_K3 omodel = new Model.ClsXs_SeOutStockBillMain_K3();
|
public List<Model.ClsXs_SeOutStockBillSub_K3> DetailColl = new List<Model.ClsXs_SeOutStockBillSub_K3>();
|
|
public ClsXs_SeOutStockBill_K3()
|
{
|
base.MvarItemKeySub = "SEOutStockEntry";
|
base.MvarItemKeySub2 = "";
|
base.MvarItemKeySub3 = "";
|
base.MvarItemKeySub4 = "";
|
base.MvarItemKey = "SEOutStock";
|
base.MvarReportTitle = "发货通知单";
|
base.BillType = "83";
|
}
|
|
#region 固定代码
|
|
~ClsXs_SeOutStockBill_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 SEOutStock where FTranType='" + BillType + "' and FBillNo ='" + sBillNo + "'";
|
}
|
else
|
{
|
sSql = "Select FInterID from SEOutStock where FTranType='" + BillType + "' and FBillNo ='" + sBillNo + "' and FInterID<>" + lngBillKey.ToString();
|
}
|
DataSet Ds;
|
Ds = oK3Cn.RunProcReturn(sSql, "SEOutStock");
|
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 SEOutStockEntry where FInterID=" + lngBillKey.ToString());
|
}
|
//删除主表
|
public void DeleteBillMain(Int64 lngBillKey)
|
{
|
oK3Cn.RunProc("Delete From SEOutStock 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 SEOutStock " +
|
"(FInterID,FBillNo,FBrNo,FTranType,FCancellation,FStatus" +
|
",Fdate,FPrintCount,Fnote" +
|
",FCustID,FFetchAdd,FSalType,FSettleID,FCurrencyID,FExchangeRate" +
|
",FStockID,FEmpID,FManagerID,FDeptID,FExplanation" +
|
") " +
|
" values(" + lngBillKey.ToString() + ",'" + omodel.HBillNo + "','0'," + this.BillType + ",0,0" +
|
",'" + omodel.HDate.ToShortDateString() + "'," + omodel.HPrintQty.ToString() + ",'" + omodel.HRemark + "'" +
|
", " + omodel.HCusID.ToString() + ",'" + omodel.HAddress + "'," + omodel.HSellSID.ToString() + "," + omodel.HSSID.ToString() + "," + omodel.HCurID.ToString() + "," + omodel.HExRate.ToString() +
|
", " + omodel.HWHID.ToString() + "," + omodel.HEmpID.ToString() + "," + omodel.HMangerID.ToString() + "," + omodel.HDeptID.ToString() + ",'" + omodel.HExplanation.ToString() + "'" +
|
") ");
|
//插入子表
|
foreach (Model.ClsXs_SeOutStockBillSub_K3 oSub in DetailColl)
|
{
|
oK3Cn.RunProc("Insert into SEOutStockEntry " +
|
" (FInterID,FEntryID,FBrNo,Fnote" +
|
",FSourceBillNo,FSourceTranType,FSourceInterId,FSourceEntryID" +
|
",FItemID,FAuxPropID,FUnitID,FFetchDate" +
|
",FSecCoefficient,FQty,Fauxprice,Famount,FStockID" +
|
") 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.HDate.ToShortDateString() + "'" +
|
", " + oSub.HSecUnitRate.ToString() + "," + oSub.HQty.ToString() + "," + oSub.HPrice.ToString() + "," + oSub.HMoney.ToString() + "," + oSub.HWHID.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 'SEOutStock', @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 SEOutStock " +
|
"(FInterID,FBillNo,FBrNo,FTranType,FCancellation,FStatus" +
|
",Fdate,FPrintCount,Fnote" +
|
",FCustID,FFetchAdd,FSalType,FSettleID,FCurrencyID,FExchangeRate" +
|
",FStockID,FEmpID,FManagerID,FDeptID,FExplanation" +
|
") " +
|
" values(" + omodel.HInterID.ToString() + ",'" + omodel.HBillNo + "','0'," + this.BillType + ",0,0" +
|
",'" + omodel.HDate.ToShortDateString() + "'," + omodel.HPrintQty.ToString() + ",'" + omodel.HRemark + "'" +
|
", " + omodel.HCusID.ToString() + ",'" + omodel.HAddress + "'," + omodel.HSellSID.ToString() + "," + omodel.HSSID.ToString() + "," + omodel.HCurID.ToString() + "," + omodel.HExRate.ToString() +
|
", " + omodel.HWHID.ToString() + "," + omodel.HEmpID.ToString() + "," + omodel.HMangerID.ToString() + "," + omodel.HDeptID.ToString() + ",'" + omodel.HExplanation.ToString() + "'" +
|
") ");
|
//插入子表
|
foreach (Model.ClsXs_SeOutStockBillSub_K3 oSub in DetailColl)
|
{
|
oK3Cn.RunProc("Insert into SEOutStockEntry " +
|
" (FInterID,FEntryID,FBrNo,Fnote" +
|
",FSourceBillNo,FSourceTranType,FSourceInterId,FSourceEntryID" +
|
",FItemID,FAuxPropID,FUnitID,FFetchDate" +
|
",FSecCoefficient,FQty,Fauxprice,Famount,FStockID" +
|
") 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.HDate.ToShortDateString() + "'" +
|
", " + oSub.HSecUnitRate.ToString() + "," + oSub.HQty.ToString() + "," + oSub.HPrice.ToString() + "," + oSub.HMoney.ToString() + "," + oSub.HWHID.ToString() +
|
") ");
|
//更新申请单关联数量
|
//oK3Cn.RunProc("EXEC p_UpdateBillRelateData " + this.BillType + "," + omodel.HInterID.ToString() + ",'SEOutStock','SEOutStockEntry'");
|
|
//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);
|
}
|
}
|
//显示单据
|
public override bool ShowBill(Int64 lngBillKey, ref string sReturn)
|
{
|
try
|
{
|
//查询主表
|
DataSet Ds;
|
Ds = oK3Cn.RunProcReturn("Select * from SEOutStock Where FInterID=" + lngBillKey.ToString(), "SEOutStock");
|
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.HPrintQty = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FPrintCount"]);
|
omodel.HRemark = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["Fnote"]);
|
//
|
omodel.HCusID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FCustID"]);
|
omodel.HAddress = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["FFetchAdd"]);
|
omodel.HSellSID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FSalType"]);
|
omodel.HSSID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FSettleID"]);
|
omodel.HCurID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FCurrencyID"]);
|
omodel.HExRate = DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["FExchangeRate"]);
|
omodel.HWHID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FStockID"]);
|
omodel.HEmpID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FEmpID"]);
|
omodel.HMangerID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FManagerID"]);
|
omodel.HDeptID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FDeptID"]);
|
omodel.HExplanation = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["FExplanation"]);
|
//循环
|
DataSet DsSub;
|
DsSub = oK3Cn.RunProcReturn("Select * from SEOutStockEntry Where FInterID=" + lngBillKey.ToString() + " order by HEntryID ", "SEOutStockEntry");
|
DetailColl.Clear();//清空
|
for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++)
|
{
|
Model.ClsXs_SeOutStockBillSub_K3 oSub = new Model.ClsXs_SeOutStockBillSub_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.HSecUnitID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FSecUnitID"].ToString());
|
oSub.HDate = Convert.ToDateTime(DsSub.Tables[0].Rows[i]["FFetchDate"].ToString().Trim());
|
oSub.HSecUnitRate = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FSecCoefficient"].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.HMoney = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["Famount"].ToString());
|
oSub.HWHID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FStockID"].ToString());
|
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();
|
DetailColl.Add(oSub);
|
}
|
sReturn = "显示单据成功!";
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
throw (e);
|
}
|
}
|
|
|
}
|
|
}
|