根据日期等生成流水码调用的方法

根据日期等生成流水码

/// <summary>
        /// 设置生成记录数,在指定表结构下记录当天生成记录总数
        /// 相应表结构应包含打印日期,打印记录数两个字段
        /// 需要批处理
        /// </summary>
        /// <param name="args">
        /// string : 表名
        /// int : 新增记录数
        /// </param>
        /// <returns>
        /// rtn>=0时设置成功
        /// output:int表示最新记录总数
        /// </returns>
        private static SqlProcessRes SetRcdDateCountEx(SqlCommand sqlCmd, object args)
        {
            //@1044
            string tableName = (string)(args as object[])[0];
            int qty = (int)(args as object[])[1];
            Hashtable htLimitCond = (Hashtable)(args as object[])[2];

            int? qtyFirst = null;
            if ((args as object[]).Length > 3
                && (args as object[])[3] != null
                )
            {
                qtyFirst = (int)(args as object[])[3];
            }

            //@1099
            bool isReturnRcdID = false;
            if ((args as object[]).Length > 4)
            {
                isReturnRcdID = (bool)(args as object[])[4];
            }
            List<string> listCountLimit = null;
            if ((args as object[]).Length > 5)
            {
                listCountLimit = (List<string>)(args as object[])[5];
            }
            if (listCountLimit == null)//若为null,默认为全部限制条件
            {
                listCountLimit = new List<string>();
                foreach (string key in htLimitCond.Keys)
                {
                    listCountLimit.Add(key);
                }
            }

            string limitCmd = "";
            foreach (string key in htLimitCond.Keys)
            {
                limitCmd += " and " + key + "=@" + key;
            }

            //更新计数器
            string strCmd = "update @tablename set"
                + " count=count + @qty"
                + " where 1=1"
                + limitCmd;
            strCmd = strCmd.Replace("@tablename", tableName);
            SetCmdTxt(sqlCmd, strCmd);
            int qtyIncrement = qty;
            sqlCmd.Parameters.AddWithValue("@qty", qtyIncrement);
            foreach (string key in htLimitCond.Keys)
            {
                sqlCmd.Parameters.AddWithValue("@" + key, htLimitCond[key]);
            }

            int rtn = sqlCmd.ExecuteNonQuery();
            if (rtn > 1)
                return new SqlProcessRes(-1, null, "存在重复流水");

            if (rtn == 0)
            {
                string cmdLimitPara = "";
                foreach (string key in htLimitCond.Keys)
                {
                    cmdLimitPara += ", " + key;
                }
                //生成计数器
                strCmd = "insert into @tablename"
                    + " (count" + cmdLimitPara + ")"
                    + " values(@count" + cmdLimitPara.Replace(", ", ",@") + ")";
                strCmd = strCmd.Replace("@tablename", tableName);
                SetCmdTxt(sqlCmd, strCmd);

                qtyIncrement = qtyFirst ?? qty;
                sqlCmd.Parameters.AddWithValue("count", qtyIncrement);
                if (htLimitCond != null)
                {
                    foreach (string key in htLimitCond.Keys)
                    {
                        sqlCmd.Parameters.AddWithValue("@" + key, htLimitCond[key]);
                    }
                }
                sqlCmd.ExecuteNonQuery();
            }
            SqlDataReader dr;
            int idRcd = 0;
            if (isReturnRcdID)
            {
                strCmd = "select id, count from @tablename where 1=1" + limitCmd;
                strCmd = strCmd.Replace("@tablename", tableName);
                SetCmdTxt(sqlCmd, strCmd);
                //sqlCmd.Parameters.AddWithValue("@printDate", printdate);
                foreach (string key in htLimitCond.Keys)
                {
                    sqlCmd.Parameters.AddWithValue("@" + key, htLimitCond[key]);
                }
                dr = sqlCmd.ExecuteReader();
                if (dr.Read())
                {
                    //count = ConvertToInt(dr["count"]);
                    idRcd = ConvertToInt(dr["id"]);
                }
                dr.Close();
            }

            int count = -1;
            strCmd = "select sum(count) as count from @tablename where 1=1";
            strCmd = strCmd.Replace("@tablename", tableName);
            foreach (string key in listCountLimit)
            {
                strCmd += string.Format(" and {0}=@{0}", key);
            }
            sqlCmd.ResetCmdTxt(strCmd);
            foreach (string key in listCountLimit)
            {
                sqlCmd.Parameters.AddWithValue("@" + key, htLimitCond[key]);
            }
            dr = sqlCmd.ExecuteReader();
            if (dr.Read())
            {
                count = ConvertToInt(dr["count"]);
            }
            dr.Close();
            return new SqlProcessRes(qtyIncrement, new object[] { count, idRcd });
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值