Esempio n. 1
0
        public void AddChectInitSheet(global::Model.ic_t_check_init check_init, out string sheet_no)
        {
            sheet_no = "";
            var db = new DB.DBByHandClose(Appsetting.conn);

            DB.IDB d = db;
            try
            {
                db.Open();
                db.BeginTran();

                check_init.sheet_no    = sheet_no = MaxCode(d, "PC");
                check_init.create_time = DateTime.Now;
                check_init.update_time = DateTime.Now;

                d.Insert(check_init);

                //备份仓库
                DataTable tb = d.ExecuteToTable(@"select * 
from ic_t_branch_stock s
left join  bi_t_item_info i on i.item_no=s.item_no
where branch_no='" + check_init.branch_no + "'", null);

                foreach (DataRow dr in tb.Rows)
                {
                    ic_t_check_bak bak = new ic_t_check_bak()
                    {
                        sheet_no    = check_init.sheet_no,
                        branch_no   = check_init.branch_no,
                        item_no     = dr["item_no"].ToString(),
                        stock_qty   = Conv.ToDecimal(dr["stock_qty"]),
                        cost_price  = Conv.ToDecimal(dr["cost_price"]),
                        price       = Conv.ToDecimal(dr["last_price"]),
                        sale_price  = Conv.ToDecimal(dr["sale_price"]),
                        create_time = DateTime.Now,
                        update_time = DateTime.Now
                    };
                    d.Insert(bak);
                }


                db.CommitTran();
            }
            catch (Exception ex)
            {
                LogHelper.writeLog("CheckBLL.AddChectInitSheet()", ex.ToString(), check_init.sheet_no);
                db.RollBackTran();
                throw ex;
            }
            finally
            {
                db.Close();
            }
        }
Esempio n. 2
0
        public void UpdateChectInitSheet(global::Model.ic_t_check_init init)
        {
            var db = new DB.DBByHandClose(Appsetting.conn);

            DB.IDB d = db;
            try
            {
                db.Open();
                db.BeginTran();
                //
                string sql  = "select * from ic_t_check_init where sheet_no='" + init.sheet_no + "'";
                var    item = d.ExecuteToModel <ic_t_check_init>(sql, null);
                if (item == null || string.IsNullOrEmpty(item.sheet_no))
                {
                    throw new Exception("单据不存在[" + init.sheet_no + "]");
                }
                else
                {
                    if (item.approve_flag.Equals("1"))
                    {
                        throw new Exception("单据已审核[" + init.sheet_no + "]");
                    }
                    if (item.update_time > init.update_time)
                    {
                        throw new Exception("单据已被他人修改[" + init.sheet_no + "]");
                    }
                }
                sql = "delete from ic_t_check_init where sheet_no='" + init.sheet_no + "'";
                d.ExecuteScalar(sql, null);
                //
                init.update_time = DateTime.Now;
                d.Insert(init);

                //
                db.CommitTran();
            }
            catch (Exception ex)
            {
                Log.writeLog("CheckBLL.UpdateChectInitSheet()", ex.ToString(), init.sheet_no);
                db.RollBackTran();
                throw ex;
            }
            finally
            {
                db.Close();
            }
        }
Esempio n. 3
0
        public void AddChectInitSheet(global::Model.ic_t_check_init check_init, out string sheet_no)
        {
            sheet_no = "";
            var db = new DB.DBByHandClose(Appsetting.conn);

            DB.IDB d = db;
            try
            {
                db.Open();
                db.BeginTran();

                string sql   = $@"SELECT COUNT(1) 
FROM dbo.ic_t_check_init
WHERE branch_no='{check_init.branch_no}' AND check_status='0'";
                int    count = d.ExecuteScalar(sql, null).ToInt32();
                if (count > 0)
                {
                    throw new Exception("该仓库存在未结束盘点单,不可创建新盘点单");
                }

                check_init.sheet_no    = sheet_no = MaxCode(d, "PC");
                check_init.create_time = DateTime.Now;
                check_init.update_time = DateTime.Now;

                d.Insert(check_init);

                //备份仓库
                DataTable tb = d.ExecuteToTable(@"select * 
from ic_t_branch_stock s
left join  bi_t_item_info i on i.item_no=s.item_no
where branch_no='" + check_init.branch_no + "'", null);

                foreach (DataRow dr in tb.Rows)
                {
                    ic_t_check_bak bak = new ic_t_check_bak()
                    {
                        sheet_no    = check_init.sheet_no,
                        branch_no   = check_init.branch_no,
                        item_no     = dr["item_no"].ToString(),
                        stock_qty   = Conv.ToDecimal(dr["stock_qty"]),
                        cost_price  = Conv.ToDecimal(dr["cost_price"]),
                        price       = Conv.ToDecimal(dr["last_price"]),
                        sale_price  = Conv.ToDecimal(dr["sale_price"]),
                        create_time = DateTime.Now,
                        update_time = DateTime.Now
                    };
                    d.Insert(bak);
                }


                db.CommitTran();
            }
            catch (Exception ex)
            {
                Log.writeLog("CheckBLL.AddChectInitSheet()", ex.ToString(), check_init.sheet_no);
                db.RollBackTran();
                throw ex;
            }
            finally
            {
                db.Close();
            }
        }