zrg
2024-08-05 45c1541ca7d2ac7cdfebae0d08fdbc771ca37a41
DBUtility/ÒµÎñµ¥¾Ý/ClsXt_BaseBill.cs
@@ -372,6 +372,166 @@
            }
        }
        //发起多级审批
        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 + ",HBillStatus=" + 6 + " where HInterID = " + lngBillKey;
                oCn.RunProc(sql3);
                oCn.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn += e.Message;
                return false;
            }
        }
        //驳回
        public bool RejectCheckFlowProgress(Int64 lngBillKey, string HBillNo,string sUser, ref string sReturn)
        {
            if (isUse(lngBillKey, ref sReturn))
            {
                return false;
            }
            try
            {
                //开启事务
                oCn.BeginTran();
                //判断是否存在审核过的项目
                string sql0 = "select * from Xt_BillCheckFlowStatus where HBillInterID = " + lngBillKey + " and HBillTypeID = '" + this.BillType + "' and ISNULL(HChecker,'') <> ''";
                DataSet ds0 = oCn.RunProcReturn(sql0, "Xt_BillCheckFlowStatus");
                if (ds0 != null && ds0.Tables[0].Rows.Count == 0)
                {
                    sReturn = "单据不存在已经审核的项目!";
                    return false;
                }
                //获取需要驳回的审核项目
                sql0 = "select c.* from Xt_CheckFlowMain as a " +
                              "inner join Xt_CheckFlowSub as b on a.HInterID = b.HInterID " +
                              "inner join Xt_BillCheckFlowStatus as c on a.HBillTypeID = c.HBillTypeID and b.HCheckItemID = c.HCheckItemID " +
                              "where c.HBillTypeID = '" + this.BillType + "' and c.HBillInterID = " + lngBillKey + " " +
                              "order by b.HFlowNo asc";
                ds0 = oCn.RunProcReturn(sql0, "Xt_BillCheckFlowStatus");
                if (ds0 == null || ds0.Tables[0].Rows.Count == 0)
                {
                    sReturn = "驳回失败!原因:未发起审批!!";
                    return false;
                }
                //获取当前审核项目
                string HCheckFlowID = ds0.Tables[0].Rows[0]["HCheckFlowID"].ToString();             //审批流内码
                sql0 = "select * from " + MvarItemKey + " where HInterID = " + lngBillKey;
                ds0 = oCn.RunProcReturn(sql0, MvarItemKey);
                string HCheckItemNowID = ds0.Tables[0].Rows[0]["HCheckItemNowID"].ToString();       //当前审批项目内码
                //查找是否有权限
                string sql01 = "select * from Xt_CheckUserRight where HUserID = '" + sUser + "' and HCheckFlowInterID = " + HCheckFlowID + " and HCheckItemID = " + HCheckItemNowID + "";
                DataSet ds01 = oCn.RunProcReturn(sql01, "Xt_CheckUserRight");
                if (ds01.Tables[0].Rows.Count == 0)
                {
                    sReturn = "无权限!";
                    return false;
                }
                //更新 é©³å›žåˆ é™¤å®¡æ ¸æµçŠ¶æ€è¡¨
                string sql02 = "Delete Xt_BillCheckFlowStatus where HBillTypeID = '" + this.BillType + "' and HBillInterID=" + lngBillKey + " and HCheckFlowID=" + HCheckFlowID;
                oCn.RunProc(sql02);
                oCn.RunProc(" Update " + MvarItemKey + " set HChecker='',HCheckDate=null,HBillStatus=5 Where HInterID=" + lngBillKey.ToString());
                //写入日志
                string WorkList = "驳回单据,单据号:" + HBillNo;
                string SystemName = "LMES-" + MvarReportTitle + "模块";
                oCn.RunProc("Insert into  System_Log(GeginDate,userid,WorkstationName,WorkList,SystemName,NetUserName,State) values " +
                    "(getdate(),'" + sUser + "','" + ComputerName + "','" + WorkList + "','" + SystemName + "','" + IPAddress + "','驳回')"
                    );
                sReturn = "反审核单据成功!";
                oCn.Commit();
                return true;
            }
            catch (Exception e)
            {
                oCn.RollBack();
                sReturn = e.Message;
                throw (e);
            }
        }
        //审批流-反审核(包含反审核后控制、写入日志)    2024-01-31
        public bool AbandonCheck(SQLHelper.ClsCN oCN,Int64 lngBillKey, string HBillNo, string procName, string sUser, ref string sReturn)
        {