Example #1
0
        /// <summary>
        /// 更新费用单信息
        /// </summary>
        /// <param name="cost">费用单主表对象 Main:id、apply_money、remark
        /// 费用单审批详情列表 ApprovalList:
        /// 费用详情列表 DetailList:cost_type、money</param>
        /// <returns>数据表受影响的行数</returns>
        public int Update(cost cost)
        {
            cost_main          Main       = cost.Main;
            List <cost_detail> DetailList = cost.DetailList;

            //构造sql语句数组
            string[] sqlArray = new string[2 + DetailList.Count];
            //先更新cost_main表
            //更新费用金额信息和状态
            sqlArray[0] = "update cost_main set " +
                          nameof(cost_main.apply_money) + "=" + Main.apply_money + "," +
                          nameof(cost_main.remark) + "='" + Main.remark +
                          "' where id='" + Main.id + "'";
            //再删除cost_detail表数据
            sqlArray[1] = "delete from cost_detail where " + nameof(cost_detail.cost_id) + "='" + Main.id + "'";
            //再插入cost_detail表数据
            int count = 1;

            foreach (cost_detail detail in DetailList)
            {
                detail.cost_id      = Main.id;
                sqlArray[count + 1] = ConditionsToSql <cost_detail> .InsertSql(detail);

                count++;
            }
            //调用方法以事务方式执行sql数组里的语句
            return(sqlArrayToTran.doTran(sqlArray));
        }
Example #2
0
        /// <summary>
        /// 添加费用单
        /// </summary>
        /// <param name="cost">费用单主表对象 Main:apply_id、apply_money、status、apply_time、remark
        /// 费用单审批详情列表 ApprovalList:approval_id
        /// 费用详情列表 DetailList:cost_type、money</param>
        /// <returns>数据表受影响的行数</returns>
        public int Add(cost cost)
        {
            cost_main          Main       = cost.Main;
            List <cost_detail> DetailList = cost.DetailList;

            //先构造所有的sql语句
            string[] sqlArray = new string[2 + DetailList.Count];
            //构造插入cost_main、cost_approval表的语句
            int timeStamp = TimeTools.Timestamp();

            Main.id     = timeStamp;//主键(费用单id)是时间戳
            sqlArray[0] = ConditionsToSql <cost_main> .InsertSql(Main);

            //插入cost_approval表时,鉴于审核逻辑的关系,最多一次插入一个
            cost_approval Approval = cost.ApprovalList.First();

            Approval.cost_id = timeStamp;
            sqlArray[1]      = ConditionsToSql <cost_approval> .InsertSql(Approval);

            //构造插入cost_detail表语句
            int count = 1;

            foreach (cost_detail detail in DetailList)
            {
                detail.cost_id      = timeStamp;
                sqlArray[count + 1] = ConditionsToSql <cost_detail> .InsertSql(detail);

                count++;
            }
            //调用方法以事务方式执行sql数组里的语句
            return(sqlArrayToTran.doTran(sqlArray));
        }
Example #3
0
        /// <summary>
        /// 费用审批添加/修改 、审批状态(待审批,通过,驳回)以及审批意见
        /// </summary>
        /// <param name="cost">费用单主表对象Main:id、status
        /// DetailList 费用详情列表:
        /// ApprovalList 费用审批表列表:详见方法体注释</param>
        /// <returns>数据表受影响行数</returns>
        public int Update(cost cost)
        {
            /*
             * ApprovalList最多只有两个元素(前端并不会将已审核通过的cost_approval对象封装到此列表)
             * 第一个元素是正在审批的cost_approval对象:
             * 第二个元素是需要再提交到上级进行审批的cost_approval对象
             */
            string[] sqlArray = new string[1 + cost.ApprovalList.Count];
            sqlArray[0] = "update cost_main set " +
                          nameof(cost_main.status) + "='" + cost.Main.status + "' where id='" + cost.Main.id + "'";
            cost_approval approvalFirst = cost.ApprovalList.First();

            sqlArray[1] = "update cost_approval set result=" + ((bool)approvalFirst.result?1:0) +
                          ",time='" + approvalFirst.time + "',opinion=N'" + approvalFirst.opinion
                          + "' where cost_id='" + approvalFirst.cost_id + "' and approval_id='" + approvalFirst.approval_id + "'";
            if (sqlArray.Length > 2)
            {
                sqlArray[2] = ConditionsToSql <cost_approval> .InsertSql(cost.ApprovalList[1]);
            }
            return(sqlArrayToTran.doTran(sqlArray));
        }