11
pzy
2024-08-26 dbbcd506929afda0a85ae23bcb5f88c1dccef387
DAL/ÏúÊÛ¹ÜÀí/ClsXs_SeOrderBill.cs
@@ -62,10 +62,25 @@
                //",HInnerBillNo='" + omodel.HInnerBillNo + "'" +
                //" where HInterID=" + lngBillKey.ToString());
                //保存前控制=========================================
                string HBillNote = "";
                DataSet ds = oCn.RunProcReturn("Exec h_p_Xs_SeOrderBill_BeforeSaveCtrl " + omodel.HInterID.ToString() + ", '" + omodel.HBillNo + "','" + HBillNote + "',1 ", "h_p_Xs_SeOrderBill_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_SeOrderBillMain set  " +
                " HBillNo='" + omodel.HBillNo + "'" +  //固定赋值===============
                " HBillSubType='" + omodel.HBillSubType + "'" +
                ",HBillNo='" + omodel.HBillNo + "'" +  //固定赋值===============
                ",HDate='" + omodel.HDate + "'" +
                ",HYear='" + omodel.HYear.ToString() + "'" +
                ",HPeriod='" + omodel.HPeriod.ToString() + "'" +
@@ -80,6 +95,7 @@
                ",HEmpID=" + omodel.HEmpID.ToString() +
                ",HCurID=" + omodel.HCurID.ToString() +
                ",HExRate=" + omodel.HExRate.ToString() +
                ",HEarnestRate=" + omodel.HEarnestRate.ToString() +
                ",HManagerID=" + omodel.HManagerID.ToString() +
                ",HSellSID=" + omodel.HSellSID.ToString() +
                ",HSSID=" + omodel.HSSID.ToString() +
@@ -87,6 +103,8 @@
                ",HPayCusID=" + omodel.HPayCusID +
                ",HExplanation='" + omodel.HExplanation + "'" +
                ",HLinkMan='" + omodel.HLinkMan + "'" +
                ",HWHID='" + omodel.HWHID + "'" +
                ",HProjectID='" + omodel.HProjectID + "'" +
                ",HLinkPhone='" + omodel.HLinkPhone + "'" +
                " where HInterID=" + lngBillKey.ToString();
@@ -114,8 +132,9 @@
                    //  ") ");
                    string subSql = "Insert into Xs_SeOrderBillSub" +
                        "(HInterID,HEntryID,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney,HMaterID,HUnitID,HQty,HPrice,HTaxPrice,HMoney" +
                        ",HDiscountRate,HRelTaxPrice,HTaxRate,HTaxMoney,HlineTotal,HlineTotalBB,HDate,HOutStockQty,HInvoiceQty,HRemark,HOrderLevID ) " +
                        "(HInterID,HEntryID,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationQty_SellOutCheck,HRelationMoney_SellOutCheck,HRelationQty_ICMO,HRelationQty_SellBack,HRelationQty_SellBackCheck,HRelationMoney,HMaterID,HUnitID,HQty,HPrice,HTaxPrice,HMoney" +
                        ",HDiscountRate,HRelTaxPrice,HTaxRate,HTaxMoney,HlineTotal,HlineTotalBB,HDate,HOutStockQty,HInvoiceQty,HRemark,HOrderLevID" +
                        ",HCusMaterNumber,HCusModel,HCusMaterName,HisStockGoods,HWHID,HRemark_TL,HRemark_SJG) " +
                        "values(" +
                        "" + omodel.HInterID +
                        "," + oSub.HEntryID +
@@ -124,6 +143,11 @@
                        ",'" + (oSub.HSourceBillNo == null ? "" : oSub.HSourceBillNo) +
                        "','" + (oSub.HSourceBillType == null ? "" : oSub.HSourceBillType) +
                        "'," + oSub.HRelationQty +
                        "," + oSub.HRelationQty_SellOutCheck +
                        "," + oSub.HRelationMoney_SellOutCheck +
                        "," + oSub.HRelationQty_ICMO +
                        "," + oSub.HRelationQty_SellBack +
                        "," + oSub.HRelationQty_SellBackCheck +
                        "," + oSub.HRelationMoney +
                        "," + oSub.HMaterID +
                        "," + oSub.HUnitID +
@@ -142,9 +166,33 @@
                        "," + oSub.HInvoiceQty + 
                        ",'" + oSub.HRemark +
                        "','" + oSub.HOrderLevID +
                        "')";
                        "','" + oSub.HCusMaterNumber +
                        "','" + oSub.HCusModel +
                        "','" + oSub.HCusMaterName +
                        "'," + (oSub.HisStockGoods?1:0) +
                         ",'" + oSub.HWhID + "'" +
                         ",'" + oSub.HRemark_TL + "'" +
                         ",'" + oSub.HRemark_SJG + "'" +
                        ")";
                    oCn.RunProc(subSql);
                }
                //=========================保存后控制
                DataSet ds2 = oCn.RunProcReturn("h_p_Xs_SeOrderBill_AfterSaveCtrl " + omodel.HInterID.ToString() + ", '" + omodel.HBillNo + "',1 ", "h_p_Xs_SeOrderBill_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;
                }
                //============================
                //
                //foreach (Model.ClsXs_SeOrderBillSub oSub in DetailColl)
                //{
@@ -173,7 +221,20 @@
        {
            try
            {
                DataSet ds;
                //保存前控制=========================================
                string HBillNote = "";
                DataSet ds = oCn.RunProcReturn("Exec h_p_Xs_SeOrderBill_BeforeSaveCtrl " + omodel.HInterID.ToString() + ", '" + omodel.HBillNo + "','" + HBillNote + "',1 ", "h_p_Xs_SeOrderBill_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;
                }
                //=========================================================
                ////得到mainid
                //omodel.HInterID = DBUtility.ClsPub.CreateBillID(BillType, ref DBUtility.ClsPub.sExeReturnInfo);
@@ -221,13 +282,13 @@
                //插入主表
                string mainSql = "Insert Into Xs_SeOrderBillMain" +
                    "(HYear,HPeriod,HBillType,HBillSubType,HBillStatus,HExplanation" +
                    ",HInterID,HBillNo,HDate,HInnerBillNo,HAddress,HDeptID,HCusID,HEmpID,HCurID,HExRate,HManagerID,HSellSID,HSSID,HSSDate,HPayCusID,HRemark,HOrgID,HMaker,HMakeDate,HLinkMan,HLinkPhone" +
                    ",HERPInterID,HERPBillType,HSALEORGID,HSALEGROUPID,HRECEIVEID,HSETTLEID,HCHARGEID,HHEADLOCID,HRECCONTACTID,HCORRESPONDORGID,HBUSINESSTYPE) " +
                    ",HInterID,HBillNo,HDate,HInnerBillNo,HAddress,HDeptID,HCusID,HEmpID,HCurID,HExRate,HEarnestRate,HManagerID,HSellSID,HSSID,HSSDate,HPayCusID,HRemark,HOrgID,HMaker,HMakeDate,HLinkMan,HLinkPhone" +
                    ",HERPInterID,HERPBillType,HSALEORGID,HSALEGROUPID,HRECEIVEID,HSETTLEID,HCHARGEID,HHEADLOCID,HRECCONTACTID,HCORRESPONDORGID,HBUSINESSTYPE,HProjectID,HWHID) " +
                    "values(" +
                    "" + omodel.HYear +
                    "," + omodel.HPeriod +
                    ",'" + this.BillType +
                    "','" + this.HBillSubType +
                    "','" + omodel.HBillSubType +
                    "'," + omodel.HBillStatus +
                    ",'" + omodel.HExplanation +
@@ -241,6 +302,7 @@
                    "," + omodel.HEmpID +
                    "," + omodel.HCurID +
                    "," + omodel.HExRate +
                    "," + omodel.HEarnestRate +
                    "," + omodel.HManagerID +
                    "," + omodel.HSellSID +
                    "," + omodel.HSSID +
@@ -249,9 +311,9 @@
                    ",'" + omodel.HRemark +
                    "'," + omodel.HOrgID +
                    ",'" + omodel.HMaker +
                    "','" + omodel.HMakeDate +
                    "',getdate()" +
                    "','" + omodel.HLinkMan +
                    ",'" + omodel.HLinkMan +
                    "','" + omodel.HLinkPhone +
                    "'," + omodel.HERPInterID +
@@ -265,6 +327,9 @@
                    "," + omodel.HRECCONTACTID +
                    "," + omodel.HCORRESPONDORGID +
                    ",'" + omodel.HBUSINESSTYPE +
                    "','" + omodel.HProjectID +
                    "','" + omodel.HWHID +
                    "')";
                    
                oCn.RunProc(mainSql);
@@ -285,8 +350,9 @@
                    //  "," + oSub.HTaxPrice.ToString() + "," + oSub.HDiscountRate.ToString() + "," + oSub.HRelTaxPrice.ToString() + "," + oSub.HOutStockQty.ToString() + "," + oSub.HInvoiceQty.ToString() +
                    //  ") ");
                    string subSql = "Insert into Xs_SeOrderBillSub" +
                        "(HInterID,HEntryID,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney,HMaterID,HUnitID,HQty,HPrice,HTaxPrice,HMoney" +
                        ",HDiscountRate,HRelTaxPrice,HTaxRate,HTaxMoney,HlineTotal,HlineTotalBB,HDate,HOutStockQty,HInvoiceQty,HRemark,HOrderLevID) " +
                        "(HInterID,HEntryID,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationQty_SellOutCheck,HRelationMoney_SellOutCheck,HRelationQty_ICMO,HRelationQty_SellBack,HRelationQty_SellBackCheck,HRelationMoney,HMaterID,HUnitID,HQty,HPrice,HTaxPrice,HMoney" +
                        ",HDiscountRate,HRelTaxPrice,HTaxRate,HTaxMoney,HlineTotal,HlineTotalBB,HDate,HOutStockQty,HInvoiceQty,HRemark,HOrderLevID" +
                        ",HCusMaterNumber,HCusModel,HCusMaterName,HisStockGoods,HWHID,HRemark_TL,HRemark_SJG) " +
                        "values(" +
                        "" + omodel.HInterID +
                        "," + oSub.HEntryID +
@@ -295,6 +361,11 @@
                        ",'" + (oSub.HSourceBillNo==null?"":oSub.HSourceBillNo) +
                        "','" + (oSub.HSourceBillType==null?"":oSub.HSourceBillType) +
                        "'," + oSub.HRelationQty +
                        "," + oSub.HRelationQty_SellOutCheck +
                        "," + oSub.HRelationMoney_SellOutCheck +
                        "," + oSub.HRelationQty_ICMO +
                        "," + oSub.HRelationQty_SellBack +
                        "," + oSub.HRelationQty_SellBackCheck +
                        "," + oSub.HRelationMoney +
                        "," + oSub.HMaterID +
                        "," + oSub.HUnitID +
@@ -313,9 +384,34 @@
                        "," + oSub.HInvoiceQty +
                        ",'" + oSub.HRemark +
                        "','" + oSub.HOrderLevID +
                        "')";
                        "','" + oSub.HCusMaterNumber +
                        "','" + oSub.HCusModel +
                        "','" + oSub.HCusMaterName +
                        "'," + (oSub.HisStockGoods?1:0) +
                        ",'" + oSub.HWhID + "'" +
                        ",'" + oSub.HRemark_TL + "'" +
                        ",'" + oSub.HRemark_SJG + "'" +
                        ")";
                    oCn.RunProc(subSql);
                }
                //=========================保存后控制
                DataSet ds2 = oCn.RunProcReturn("h_p_Xs_SeOrderBill_AfterSaveCtrl " + omodel.HInterID.ToString() + ", '" + omodel.HBillNo + "',1 ", "h_p_Xs_SeOrderBill_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;
                }
                //============================
                //
                //foreach (Model.ClsXs_SeOrderBillSub oSub in DetailColl)
                //{
@@ -388,6 +484,7 @@
                omodel.HCusID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HCusID"]);
                omodel.HCurID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HCurID"]);
                omodel.HExRate = DBUtility.ClsPub.isSingle(Ds.Tables[0].Rows[0]["HExRate"]);
                omodel.HEarnestRate = DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["HEarnestRate"]);
                omodel.HEmpID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HEmpID"]);
                omodel.HManagerID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HManagerID"]);
                omodel.HDeptID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HDeptID"]);
@@ -422,6 +519,12 @@
                    oSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DsSub.Tables[0].Rows[i]["HEntryCloseDate"]);
                    oSub.HRemark = DsSub.Tables[0].Rows[i]["HRemark"].ToString().Trim();
                    //===================================================
                    oSub.HRelationQty_SellOutCheck = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HRelationQty_SellOutCheck"]);
                    oSub.HRelationMoney_SellOutCheck = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HRelationMoney_SellOutCheck"]);
                    oSub.HRelationQty_ICMO = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HRelationQty_ICMO"]);
                    oSub.HRelationQty_SellBack = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HRelationQty_SellBack"]);
                    oSub.HRelationQty_SellBackCheck = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HRelationQty_SellBackCheck"]);
                    //===================================================
                    oSub.HMaterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HMaterID"]);
                    oSub.HUnitID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HUnitID"]);
                    oSub.HQty = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HQty"]);
@@ -437,7 +540,11 @@
                    oSub.HRelTaxPrice = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HRelTaxPrice"]);
                    oSub.HOutStockQty = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HOutStockQty"]);
                    oSub.HInvoiceQty = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HInvoiceQty"]);
                    oSub.HisStockGoods = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HisStockGoods"]) == 1 ? true : false;
                    oSub.HRemark_TL = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[0]["HRemark_TL"]);
                    oSub.HRemark_SJG = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[0]["HRemark_SJG"]);
                    DetailColl.Add(oSub);
                }
                sReturn = "显示单据成功!";
@@ -473,7 +580,94 @@
            oCn.RunProc("update Xs_SeOrderBillMain 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;
            }
        }
    }
}