using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using System.Data;
|
|
namespace DAL
|
{
|
public class ClsXs_OutDoorBill : DBUtility.ClsXt_BaseBill
|
{
|
public Model.ClsXs_OutDoorBillMain omodel = new Model.ClsXs_OutDoorBillMain();
|
public List<Model.ClsXs_OutDoorBillSub> DetailColl = new List<Model.ClsXs_OutDoorBillSub>();
|
|
public ClsXs_OutDoorBill()
|
{
|
base.MvarItemKeySub = "Xs_OutDoorBillSub";
|
base.MvarItemKeySub2 = "";
|
base.MvarItemKeySub3 = "";
|
base.MvarItemKeySub4 = "";
|
base.MvarItemKey = "Xs_OutDoorBillMain";
|
base.MvarReportTitle = "出门确认单";
|
base.BillType = "1427";
|
base.HBillSubType = "1427";
|
|
}
|
|
#region 固定代码
|
|
~ClsXs_OutDoorBill()
|
{
|
DetailColl = null;
|
}
|
|
#endregion 自定义方法
|
//修改单据
|
public override bool ModifyBill(Int64 lngBillKey, ref string sReturn)
|
{
|
try
|
{
|
//保存前控制=========================================
|
string HBillNote = "";
|
DataSet ds = oCn.RunProcReturn("Exec h_p_Xs_OutDoorBill_BeforeSaveCtrl " + omodel.HInterID.ToString() + ", '" + omodel.HBillNo + "','" + HBillNote + "',1 ", "h_p_Xs_OutDoorBill_BeforeSaveCtrl");
|
if (ds == null)
|
{
|
sReturn = "保存前判断失败!";
|
return false;
|
}
|
if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) != "0")
|
{
|
sReturn = "保存失败!" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
|
return false;
|
}
|
//=========================================================
|
|
oCn.BeginTran();
|
string mainSql = "UpDate Xs_OutDoorBillMain set " +
|
" HBillSubType='" + omodel.HBillSubType + "'" +
|
",HBillNo='" + omodel.HBillNo + "'" + //固定赋值===============
|
",HDate='" + omodel.HDate + "'" +
|
",HYear='" + omodel.HDate.Year + "'" +
|
",HPeriod='" + omodel.HDate.Month + "'" +
|
",HRemark='" + omodel.HRemark + "'" +
|
",HUpDater='" + omodel.HUpDater + "'" +
|
",HUpDateDate=getdate()" +
|
",HStockOrgID=" + omodel.HStockOrgID +
|
//========================================
|
",HCusID=" + omodel.HCusID.ToString() +
|
",HEmpID=" + omodel.HEmpID + "" +
|
",HShipper='" + omodel.HShipper + "'" +
|
",HCarNumber='" + omodel.HCarNumber + "'" +
|
",HPhone='" + omodel.HPhone + "'" +
|
",HOutReason='" + omodel.HOutReason + "'" +
|
",HOutAddress='" + omodel.HOutAddress + "'" +
|
",HMaterName='" + omodel.HMaterName + "'" +
|
" where HInterID=" + lngBillKey.ToString();
|
|
oCn.RunProc(mainSql);
|
//删除关联
|
DeleteRelation(ref sReturn, lngBillKey);
|
//删除子表
|
DeleteBillSub(lngBillKey);
|
//插入子表
|
omodel.HInterID = lngBillKey;
|
foreach (Model.ClsXs_OutDoorBillSub oSub in DetailColl)
|
{
|
string subSql = "Insert into Xs_OutDoorBillSub" +
|
"(HInterID,HBillNo_bak,HEntryID,HRemark,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney,HMaterID,HQty,HPieceQty" +
|
") " +
|
"values(" +
|
"" + omodel.HInterID + "" +
|
",'" + omodel.HBillNo + "'" +
|
"," + oSub.HEntryID + "" +
|
",'" + oSub.HRemark + "'" +
|
"," + oSub.HSourceInterID + "" +
|
"," + oSub.HSourceEntryID + "" +
|
",'" + (oSub.HSourceBillNo == null ? "" : oSub.HSourceBillNo) + "'" +
|
",'" + (oSub.HSourceBillType == null ? "" : oSub.HSourceBillType) + "'" +
|
"," + oSub.HRelationQty + "" +
|
"," + oSub.HRelationMoney + "" +
|
"," + oSub.HMaterID + "" +
|
"," + oSub.HQty + "" +
|
"," + oSub.HPieceQty + "" +
|
")";
|
oCn.RunProc(subSql);
|
}
|
|
//=========================保存后控制
|
DataSet ds2 = oCn.RunProcReturn("h_p_Xs_OutDoorBill_AfterSaveCtrl " + omodel.HInterID.ToString() + ", '" + omodel.HBillNo + "',1 ", "h_p_Xs_OutDoorBill_AfterSaveCtrl");
|
if (ds2 == null)
|
{
|
sReturn = "保存后控制判断失败!";
|
oCn.RollBack();
|
return false;
|
}
|
if (DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBack"]) != "0")
|
{
|
sReturn = "保存失败2!" + DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBackRemark"]);
|
oCn.RollBack();
|
return false;
|
}
|
//==============================================================================
|
|
//反写源单关联数量
|
oCn.RunProc("exec h_p_Xs_OutDoorBill_RewriteSellOutBill " + omodel.HInterID.ToString());
|
|
sReturn = "修改单据成功!";
|
oCn.Commit();
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
oCn.RollBack();
|
throw (e);
|
}
|
}
|
//新增单据
|
public override bool AddBill(ref string sReturn)
|
{
|
try
|
{
|
//保存前控制=========================================
|
string HBillNote = "";
|
DataSet ds = oCn.RunProcReturn("Exec h_p_Xs_OutDoorBill_BeforeSaveCtrl " + omodel.HInterID.ToString() + ", '" + omodel.HBillNo + "','" + HBillNote + "',1 ", "h_p_Xs_OutDoorBill_BeforeSaveCtrl");
|
if (ds == null)
|
{
|
sReturn = "保存前判断失败!";
|
return false;
|
}
|
if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) != "0")
|
{
|
sReturn = "保存失败!" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
|
return false;
|
}
|
//=========================================================
|
|
oCn.BeginTran();
|
|
//检查主表内码是否重复,若重复则重新生成并继续检查,直到不再重复
|
while (true)
|
{
|
ds = oCn.RunProcReturn("select * from Xs_OutDoorBillMain where HInterID = " + omodel.HInterID, "Xs_OutDoorBillMain");
|
if (ds != null && ds.Tables[0].Rows.Count > 0)
|
{
|
omodel.HInterID = DBUtility.ClsPub.CreateBillID(BillType, ref DBUtility.ClsPub.sExeReturnInfo);
|
}
|
else
|
{
|
break;
|
}
|
}
|
|
//插入主表
|
string mainSql = "Insert Into Xs_OutDoorBillMain" +
|
"(HYear,HPeriod,HBillType,HBillSubType,HInterID,HBillNo,HDate,HBillStatus,HMaker,HMakeDate,HRemark,HStockOrgID" +
|
",HCusID,HEmpID,HShipper,HCarNumber,HPhone,HOutReason,HOutAddress,HMaterName) " +
|
"values(" +
|
"" + omodel.HDate.Year + "" +
|
"," + omodel.HDate.Month + "" +
|
",'" + this.BillType + "'" +
|
",'" + omodel.HBillSubType + "'" +
|
"," + omodel.HInterID + "" +
|
",'" + omodel.HBillNo + "'" +
|
",'" + omodel.HDate + "'" +
|
"," + "1" + "" +
|
",'" + omodel.HMaker + "'" +
|
"," + "getdate()" + "" +
|
",'" + omodel.HRemark + "'" +
|
"," + omodel.HStockOrgID + "" +
|
|
"," + omodel.HCusID + "" +
|
"," + omodel.HEmpID + "" +
|
",'" + omodel.HShipper + "'" +
|
",'" + omodel.HCarNumber + "'" +
|
",'" + omodel.HPhone + "'" +
|
",'" + omodel.HOutReason + "'" +
|
",'" + omodel.HOutAddress + "'" +
|
",'" + omodel.HMaterName + "'" +
|
")";
|
|
oCn.RunProc(mainSql);
|
//插入子表
|
foreach (Model.ClsXs_OutDoorBillSub oSub in DetailColl)
|
{
|
string subSql = "Insert into Xs_OutDoorBillSub" +
|
"(HInterID,HBillNo_bak,HEntryID,HRemark,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney,HMaterID,HQty,HPieceQty" +
|
") " +
|
"values(" +
|
"" + omodel.HInterID + "" +
|
",'" + omodel.HBillNo + "'" +
|
"," + oSub.HEntryID + "" +
|
",'" + oSub.HRemark + "'" +
|
"," + oSub.HSourceInterID + "" +
|
"," + oSub.HSourceEntryID + "" +
|
",'" + (oSub.HSourceBillNo == null ? "" : oSub.HSourceBillNo) + "'" +
|
",'" + (oSub.HSourceBillType == null ? "" : oSub.HSourceBillType) + "'" +
|
"," + oSub.HRelationQty + "" +
|
"," + oSub.HRelationMoney + "" +
|
"," + oSub.HMaterID + "" +
|
"," + oSub.HQty + "" +
|
"," + oSub.HPieceQty + "" +
|
")";
|
oCn.RunProc(subSql);
|
}
|
|
//=========================保存后控制
|
DataSet ds2 = oCn.RunProcReturn("h_p_Xs_OutDoorBill_AfterSaveCtrl " + omodel.HInterID.ToString() + ", '" + omodel.HBillNo + "',1 ", "h_p_Xs_OutDoorBill_AfterSaveCtrl");
|
if (ds2 == null)
|
{
|
sReturn = "保存后控制判断失败!";
|
oCn.RollBack();
|
return false;
|
}
|
if (DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBack"]) != "0")
|
{
|
sReturn = "保存失败2!" + DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBackRemark"]);
|
oCn.RollBack();
|
return false;
|
}
|
//===============================================================
|
|
//反写源单关联数量
|
oCn.RunProc("exec h_p_Xs_OutDoorBill_RewriteSellOutBill " + omodel.HInterID.ToString());
|
|
sReturn = "新增单据成功!";
|
oCn.Commit();
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
oCn.RollBack();
|
throw (e);
|
}
|
}
|
//显示单据
|
public override bool ShowBill(Int64 lngBillKey, ref string sReturn)
|
{
|
try
|
{
|
//查询主表
|
DataSet Ds;
|
Ds = oCn.RunProcReturn("Select * from Xs_OutDoorBillMain Where HInterID=" + lngBillKey.ToString(), "Xs_OutDoorBillMain");
|
if (Ds.Tables[0].Rows.Count == 0)
|
{
|
sReturn = "单据未找到!";
|
return false;
|
}
|
//固定赋值===========================================
|
omodel.HYear = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HYear"]);
|
omodel.HPeriod = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HPeriod"]);
|
omodel.HBillType = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBillType"]);
|
omodel.HBillSubType = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBillSubType"]);
|
omodel.HInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"]);
|
omodel.HDate = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["HDate"]);
|
omodel.HBillNo = Ds.Tables[0].Rows[0]["HBillNo"].ToString().Trim();
|
omodel.HBillStatus = DBUtility.ClsPub.isInt(Ds.Tables[0].Rows[0]["HBillStatus"]);
|
omodel.HCheckItemNowID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HCheckItemNowID"]);
|
omodel.HCheckItemNextID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HCheckItemNextID"]);
|
omodel.HCheckFlowID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HCheckFlowID"]);
|
omodel.HRemark = Ds.Tables[0].Rows[0]["HRemark"].ToString().Trim();
|
omodel.HBackDate = Ds.Tables[0].Rows[0]["HBackDate"].ToString().Trim();
|
omodel.HBacker = Ds.Tables[0].Rows[0]["HBacker"].ToString().Trim();
|
omodel.HCheckDate = Ds.Tables[0].Rows[0]["HCheckDate"].ToString().Trim();
|
omodel.HChecker = Ds.Tables[0].Rows[0]["HChecker"].ToString().Trim();
|
omodel.HMaker = Ds.Tables[0].Rows[0]["HMaker"].ToString().Trim();
|
omodel.HMakeDate = Ds.Tables[0].Rows[0]["HMakeDate"].ToString().Trim();
|
omodel.HUpDateDate = Ds.Tables[0].Rows[0]["HUpDateDate"].ToString().Trim();
|
omodel.HUpDater = Ds.Tables[0].Rows[0]["HUpDater"].ToString().Trim();
|
omodel.HCloseDate = Ds.Tables[0].Rows[0]["HCloseDate"].ToString().Trim();
|
omodel.HCloseMan = Ds.Tables[0].Rows[0]["HCloseMan"].ToString().Trim();
|
omodel.HCloseType = DBUtility.ClsPub.isBool(Ds.Tables[0].Rows[0]["HCloseType"]);
|
omodel.HDeleteDate = Ds.Tables[0].Rows[0]["HDeleteDate"].ToString().Trim();
|
omodel.HDeleteMan = Ds.Tables[0].Rows[0]["HDeleteMan"].ToString().Trim();
|
omodel.HPrintQty = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HPrintQty"]);
|
|
|
omodel.HStockOrgID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HStockOrgID"]);
|
//========================================================
|
omodel.HCusID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HCusID"]);
|
omodel.HEmpID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HEmpID"]);
|
omodel.HShipper = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HShipper"]);
|
omodel.HCarNumber = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HCarNumber"]);
|
omodel.HPhone = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HPhone"]);
|
omodel.HOutReason = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HOutReason"]);
|
omodel.HOutAddress = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HOutAddress"]);
|
omodel.HMaterName = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HMaterName"]);
|
omodel.HOutCheckMan = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HOutCheckMan"]);
|
omodel.HOutCheckDate = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HOutCheckDate"]);
|
//
|
|
//循环
|
DataSet DsSub;
|
DsSub = oCn.RunProcReturn("Select * from Xs_OutDoorBillSub Where HInterID=" + lngBillKey.ToString(), "Xs_OutDoorBillSub");
|
DetailColl.Clear();//清空
|
for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++)
|
{
|
Model.ClsXs_OutDoorBillSub oSub = new Model.ClsXs_OutDoorBillSub();
|
// 固定赋值===============================================
|
oSub.HInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HInterID"]);
|
oSub.HEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HEntryID"]);
|
oSub.HBillNo_bak = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HBillNo_bak"]);
|
oSub.HSourceInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSourceInterID"]);
|
oSub.HSourceEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSourceEntryID"]);
|
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"]);
|
oSub.HRelationMoney = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HRelationMoney"]);
|
oSub.HCloseMan = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HCloseMan"]);
|
oSub.HCloseType = DBUtility.ClsPub.isBool(DsSub.Tables[0].Rows[i]["HCloseType"]);
|
oSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DsSub.Tables[0].Rows[i]["HEntryCloseDate"]);
|
oSub.HRemark = DsSub.Tables[0].Rows[i]["HRemark"].ToString().Trim();
|
//===================================================
|
oSub.HMaterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HMaterID"]);
|
oSub.HQty = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HQty"]);
|
oSub.HPieceQty = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HPieceQty"]);
|
|
DetailColl.Add(oSub);
|
}
|
sReturn = "显示单据成功!";
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
throw (e);
|
}
|
}
|
public void BackPrintQty(Int64 sInterID)
|
{
|
//回填打印次数
|
oCn.RunProc("update " + this.MvarItemKey + " set HPrintQty=HPrintQty + 1 Where HInterID= " + sInterID.ToString());
|
}
|
|
//发起审批
|
public bool startCheckFlow(Int64 lngBillKey, Int64 HCheckFlowID_select, ref string sReturn)
|
{
|
try
|
{
|
string HBillNo = ""; //单据号
|
string HCheckFlowID = ""; //审批流ID
|
string HCheckItemNowID = ""; //当前审核项目ID
|
string HCheckItemNextID = ""; //待审核项目ID
|
|
//判断是否已经发起审批
|
string sql0 = "select * from Xt_BillCheckFlowStatus where HBillInterID = " + lngBillKey + " and HBillTypeID = '" + this.BillType + "'";
|
DataSet ds0 = oCn.RunProcReturn(sql0, "Xt_BillCheckFlowStatus");
|
if (ds0 != null && ds0.Tables[0].Rows.Count > 0)
|
{
|
sReturn = "单据已发起审批,不可重复审批!";
|
return false;
|
}
|
|
//获取单据数据
|
string sql = "select * from " + this.MvarItemKey + " where HInterID = " + lngBillKey;
|
DataSet ds = oCn.RunProcReturn(sql, this.MvarItemKey);
|
if (ds == null || ds.Tables[0].Rows.Count == 0)
|
{
|
sReturn = "单据不存在!";
|
return false;
|
}
|
HBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();
|
|
//获取单据类型对应的默认审批流
|
string sql1 = "select b.HInterID,b.HCheckItemID from Xt_CheckFlowMain as a " +
|
"inner join Xt_CheckFlowSub as b on a.HInterID = b.HInterID " +
|
"where a.HBillTypeID = '" + this.BillType + "' " +
|
"and a.HInterID = " + HCheckFlowID_select + " " +
|
"order by b.HFlowNo asc";
|
DataSet ds1 = oCn.RunProcReturn(sql1, "Xt_CheckFlowMain");
|
if (ds1 == null || ds1.Tables[0].Rows.Count == 0)
|
{
|
sReturn = "默认审批流不存在!";
|
return false;
|
}
|
|
HCheckFlowID = ds1.Tables[0].Rows[0]["HInterID"].ToString();
|
HCheckItemNowID = ds1.Tables[0].Rows[0]["HCheckItemID"].ToString();
|
if (ds1.Tables[0].Rows.Count >= 2)
|
{
|
HCheckItemNextID = ds1.Tables[0].Rows[1]["HCheckItemID"].ToString();
|
}
|
else
|
{
|
HCheckItemNextID = "0";
|
}
|
|
oCn.BeginTran();
|
//增加 单据审批状态表 数据
|
for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
|
{
|
string sql2 = "insert into Xt_BillCheckFlowStatus" +
|
"(HBillTypeID,HBillInterID,HBillNo,HCheckFlowID,HCheckItemID,HChecker,HCheckDate,HCheckNote) " +
|
"values(" +
|
"'" + this.BillType + "'," +
|
"" + lngBillKey + "," +
|
"'" + HBillNo + "'," +
|
"" + ds1.Tables[0].Rows[i]["HInterID"].ToString() + "," +
|
"" + ds1.Tables[0].Rows[i]["HCheckItemID"].ToString() + "," +
|
"" + "''" + "," +
|
"" + "''" + "," +
|
"" + "''" + "" +
|
")";
|
|
oCn.RunProc(sql2);
|
}
|
|
//更新主表 审批流 数据
|
string sql3 = "update " + this.MvarItemKey + " set HCheckFlowID = " + HCheckFlowID + ",HCheckItemNowID=" + HCheckItemNowID + ",HCheckItemNextID=" + HCheckItemNextID + " where HInterID = " + lngBillKey;
|
oCn.RunProc(sql3);
|
|
|
oCn.Commit();
|
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn += e.Message;
|
return false;
|
}
|
}
|
}
|
|
}
|