Example #1
0
        public void InsertStock(Stock stock, IDbConnection conn, IDbTransaction trans)
        {
            string sql = @"
            INSERT INTO MD_Stock(Storehouse_ID,Goods_ID,Count) 
            VALUES(@StorehouseID,@GoodsID,@Count)";
            List <SqlParameter> paramList = new List <SqlParameter>();

            paramList.Add(new SqlParameter("@StorehouseID", stock.Storehouse.ID));
            paramList.Add(new SqlParameter("@GoodsID", stock.Goods.ID));
            paramList.Add(new SqlParameter("@Count", stock.Count));
            DataAccessUtil.ExecuteNonQuery(sql, paramList, (SqlTransaction)trans);
            object idObj = DataAccessUtil.ExecuteScalar("SELECT @@IDENTITY", new List <SqlParameter>(), (SqlTransaction)trans);

            if (idObj != null)
            {
                stock.ID = int.Parse(idObj.ToString());
            }
        }
Example #2
0
        public void InsertBill(StockBill bill, IDbConnection conn, IDbTransaction trans)
        {
            string sql = @"
            INSERT INTO MD_Bill(Storehouse_ID,BillType_ID,Maker,MakeDate,Actived,IsCancelOut,IsRedBill,Company_ID,Remark) 
            VALUES(@StorehouseID,@BillTypeID,@Maker,@MakeDate,@Actived,@IsCancelOut,@IsRedBill,@CompanyID,@Remark)";
            List <SqlParameter> paramList = new List <SqlParameter>();

            paramList.Add(new SqlParameter("@StorehouseID", bill.Storehouse.ID));
            paramList.Add(new SqlParameter("@BillTypeID", bill.BillType.ID));
            paramList.Add(new SqlParameter("@Maker", bill.Maker));
            paramList.Add(new SqlParameter("@MakeDate", bill.MakeDate));
            paramList.Add(new SqlParameter("@Actived", bill.Actived));
            paramList.Add(new SqlParameter("@IsCancelOut", bill.IsCancelOut));
            paramList.Add(new SqlParameter("@IsRedBill", bill.IsRedBill));
            paramList.Add(new SqlParameter("@CompanyID", bill.Company.ID));
            paramList.Add(new SqlParameter("@Remark", bill.Remark));
            DataAccessUtil.ExecuteNonQuery(sql, paramList, (SqlTransaction)trans);
            object idObj = DataAccessUtil.ExecuteScalar("SELECT @@IDENTITY", new List <SqlParameter>(), (SqlTransaction)trans);
            int    newID = int.Parse(idObj.ToString());


            foreach (StockBillItem item in bill.Items)
            {
                sql       = @"
                INSERT INTO MD_BillItem(Bill_ID,Goods_ID,UnitPrice,Count,Remark) 
                VALUES(@BillID,@GoodsID,@UnitPrice,@Count,@Remark)";
                paramList = new List <SqlParameter>();
                paramList.Add(new SqlParameter("@BillID", newID));
                paramList.Add(new SqlParameter("@GoodsID", item.Goods.ID));
                paramList.Add(new SqlParameter("@UnitPrice", item.UnitPrice));
                paramList.Add(new SqlParameter("@Count", item.Count));
                paramList.Add(new SqlParameter("@Remark", ""));
                DataAccessUtil.ExecuteNonQuery(sql, paramList, (SqlTransaction)trans);
            }
            bill.ID = newID;
        }