public void GetStocksByUserId_UserDoNotHaveAnyStock_ReturnsNull() { string userId = "#TestUserId#"; List <Stock> userStocks = StockProvider.GetStocksByUserId(userId); Assert.AreEqual(userStocks, null); }
public bool UpdateProductStockAmount(string productNumber, int productAmount) { try { StockEntityModel.ProductStock productStock = ParseProductStockDataToProductStock(RetrieveProductStock(productNumber)); if (productStock == null) { return(false); } else { productStock.Amount += productAmount; } using (StockProvider database = new StockProvider()) { var context = ((System.Data.Entity.Infrastructure.IObjectContextAdapter)database).ObjectContext; context.ExecuteStoreCommand("UPDATE ProductStocks SET Amount= {0} WHERE Number= {1}", productStock.Amount, productNumber); database.SaveChanges(); } } catch { return(false); } return(true); }
public bool DeleteProductStock(string productNumber) { try { using (StockProvider database = new StockProvider()) { ProductStockData productStockData = RetrieveProductStock(productNumber); if (productStockData == null) { return(false); } else { var context = ((System.Data.Entity.Infrastructure.IObjectContextAdapter)database).ObjectContext; context.ExecuteStoreCommand("DELETE FROM ProductStocks WHERE Number= {0}", productNumber); database.SaveChanges(); } } } catch { return(false); } return(true); }
public User(DataRow argDataRow) { Id = (string)Utility.IsNull(argDataRow["Id"], string.Empty); Username = (string)Utility.IsNull(argDataRow["Username"], string.Empty); Password = (string)Utility.IsNull(argDataRow["Pass"], string.Empty); StockList = StockProvider.GetStocksByUserId(Id); }
/// <summary> /// 绑定Staff信息的数据源 /// </summary> private void BindSource(Stock stock, int start) { DataTable table = new DataTable(); int index = this.ddl_QueryCategory.SelectedIndex; this.GridView1.Columns[3].Visible = true; this.GridView1.Columns[4].Visible = true; this.GridView1.Columns[5].Visible = true; this.GridView1.Columns[6].Visible = true; this.GridView1.Columns[7].Visible = true; StockProvider provider = new StockProvider(); switch (index) { case 0: table = provider.SelectRec(stock, start, this.ListPager1.PageSize); break; case 1: table = provider.SelectRecPurchase(stock, start, this.ListPager1.PageSize); break; case 2: table = provider.SelectRecSale(stock, start, this.ListPager1.PageSize); break; } this.GridView1.DataSource = table.DefaultView; this.GridView1.DataBind(); switch (index) { case 0: this.GridView1.Columns[3].Visible = true; this.GridView1.Columns[4].Visible = true; this.GridView1.Columns[5].Visible = true; this.GridView1.Columns[7].Visible = false; this.GridView1.Columns[6].Visible = false; break; case 1: this.GridView1.Columns[3].Visible = false; this.GridView1.Columns[4].Visible = false; this.GridView1.Columns[5].Visible = false; this.GridView1.Columns[6].Visible = true; this.GridView1.Columns[7].Visible = false; break; case 2: this.GridView1.Columns[3].Visible = false; this.GridView1.Columns[4].Visible = false; this.GridView1.Columns[5].Visible = false; this.GridView1.Columns[6].Visible = false; this.GridView1.Columns[7].Visible = true; break; } }
public void GetStock_InvalidArgument_ReturnsNull() { string userId = "#TestUserId#"; string stockCode = "#TestStockCode#"; Stock userStock = StockProvider.GetStock(stockCode, userId); Assert.AreEqual(userStock, null); }
public void GetStock_ValidArgument_ReturnsStock() { string userId = "#TestUserId#"; string stockCode = "#TestStockCode#"; StockDAL.SaveStock(stockCode, userId); Stock userStock = StockProvider.GetStock(stockCode, userId); StockDAL.RemoveStock(stockCode, userId); Assert.AreNotEqual(userStock, null); }
public void GetStocksByUserId_UserHaveStocks_ReturnsStocks() { string userId = "#TestUserId#"; string stockCode = "#TestStockCode#"; StockDAL.SaveStock(stockCode, userId); List <Stock> userStocks = StockProvider.GetStocksByUserId(userId); StockDAL.RemoveStock(stockCode, userId); Assert.AreNotEqual(userStocks, null); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { StockProvider provider = new StockProvider(); this.ListPager1.RecordCount = provider.GetSize(); this.BindSource(0); } this.account.Text = GetAccout();//Session["LOGINED"].ToString(); this.datetime.Text = this.BindDayWeek(); this.ListPager1.PageChange += new PagerEventHandler(ListPager1_PageChange); }
protected void ddl_GoodId_SelectedIndexChanged(object sender, EventArgs e) { Good good = new Good(); GoodProvider provider = new GoodProvider(); String good_name = ""; good.Good_Num = this.ddl_GoodId.SelectedValue.ToString(); DataTable table = provider.Select(good); if (table != null && table.Rows.Count == 1) { good_name = table.Rows[0]["good_name"].ToString(); } StockProvider provider1 = new StockProvider(); table = provider1.GetStocks(this.ddl_GoodId.SelectedValue.ToString()); int min = 0; int max = 0; int sum = 0; int price = 0; for (int i = 0; i < table.Rows.Count; i++) { sum += Convert.ToInt32(table.Rows[i]["stock_num"]); price = Convert.ToInt32(table.Rows[i]["purchase_price"]); if (i == 0) { min = max = price; continue; } if (price < min) { min = price; } else if (price > max) { max = price; } } this.lbl_PriceRange.Text = " 采购价格最低为:" + min.ToString() + " 最高为:" + max.ToString(); this.lbl_StockNum.Text = "库存还剩:" + sum.ToString(); Session["STOCKSUM"] = sum.ToString(); this.txt_goodname.Text = good_name; this.txt_goodname.Enabled = false; }
private void BindText() { Stock stock = new Stock(); stock.Stock_Id = Convert.ToInt32(id); StockProvider provider = new StockProvider(); DataTable table = new DataTable(); table = provider.Select(stock); this.txt_goodid.Text = table.Rows[0]["good_id"].ToString(); this.txt_price.Text = table.Rows[0]["purchase_price"].ToString(); this.txt_num.Text = table.Rows[0]["stock_num"].ToString(); this.txt_datetime.Text = table.Rows[0]["purchase_datetime"].ToString(); }
protected void btn_Result_Click(object sender, EventArgs e) { Stock stock = new Stock(); stock.Good_Id = ""; if (this.txt_Position.Text != "") { stock.Good_Id = txt_Position.Text.ToString(); } StockProvider provider = new StockProvider(); this.ListPager1.RecordCount = provider.GetSize(); this.BindSource(stock, 0); this.ListPager1.PageChange += new PagerEventHandler(ListPager1_PageChange); }
public List <Stock> GetUserStocks() { List <Stock> stockList = null; if (System.Web.HttpContext.Current.Session["UserId"] != null && DoesUserHaveAccess(UserProvider.GetUserById(System.Web.HttpContext.Current.Session["UserId"].ToString()))) { stockList = StockProvider.GetStocksByUserId(System.Web.HttpContext.Current.Session["UserId"].ToString()); } else { throw new AuthenticationException("You do not have access! Sorry :("); } return(stockList); }
public bool CreateProductStock(StockEntityModel.ProductStock productStock) { try { using (StockProvider database = new StockProvider()) { database.ProductsStock.Add(productStock); database.SaveChanges(); } } catch { return(false); } return(true); }
public ProductStockData RetrieveProductStock(string productNumber) { ProductStockData productStockData = null; try { using (StockProvider database = new StockProvider()) { StockEntityModel.ProductStock productStock = database.ProductsStock.First( p => String.Compare(p.Number, productNumber) == 0); productStockData = ParseProductStockToProductStockData(productStock); } } catch { //TODO: Should be implemented in future } return(productStockData); }
private bool IsRecValid() { StockProvider provider = new StockProvider(); DataTable table = provider.GetStocks(this.ddl_GoodId.SelectedValue.ToString()); int price = 0; int num = 0; if (this.txt_price.Text != "") { price = Convert.ToInt32(this.txt_price.Text); } if (this.txt_num.Text != "") { num = Convert.ToInt32(this.txt_num.Text); } for (int i = 0; i < table.Rows.Count; i++) { if (price > Convert.ToInt32(table.Rows[i]["purchase_price"])) { if (num <= Convert.ToInt32(table.Rows[i]["stock_num"])) { purchase_price = Convert.ToInt32(table.Rows[i]["purchase_price"]); return(true); } else { num -= Convert.ToInt32(table.Rows[i]["stock_num"]); } } } string WarningMessage = "销售价不能小于采购价且数量不能大于库存:" + "!!!!!!"; this.Alert(WarningMessage); return(false); }
protected void btn_sure_Click(object sender, EventArgs e) { Stock stocks = this.AddStock(); StockProvider provider = new StockProvider(); switch (this.OperationFlag) { case Operation.Add: if (false == String.IsNullOrEmpty(stocks.Good_Id)) { this.Alert("ÉÌÆ·±àºÅûÉèÖã¬Ìí¼Óʧ°Ü!!!"); break; } if (this.IsSame() == 1) { break; } if (provider.Insert(stocks)) { this.Alert("Ìí¼Ó³É¹¦!!!"); this.TextCancel(); } break; case Operation.Update: if (false == String.IsNullOrEmpty(stocks.Good_Id)) { this.Alert("²ÎÊý´íÎó£¬ÐÞ¸Äʧ°Ü!!!"); break; } if (provider.Update(stocks)) { this.Alert("Ð޸ijɹ¦!!!"); this.BindText(); } break; } }
public Stock AddNewStock(string argStockCode) { Stock stock = null; if (System.Web.HttpContext.Current.Session["UserId"] != null && DoesUserHaveAccess(UserProvider.GetUserById(System.Web.HttpContext.Current.Session["UserId"].ToString()))) { if (StockProvider.GetStock(argStockCode, System.Web.HttpContext.Current.Session["UserId"].ToString()) == null) { stock = new Stock(argStockCode); StockDAL.SaveStock(argStockCode, System.Web.HttpContext.Current.Session["UserId"].ToString()); } else { throw new Exception("Stock code already exist"); } } else { throw new AuthenticationException("You do not have access! Sorry :("); } return(stock); }
public List <string> RetrieveAllProductsStock() { List <string> productsStockDataName = new List <string>(); try { using (StockProvider database = new StockProvider()) { List <StockEntityModel.ProductStock> productsStock = (from productStock in database.ProductsStock select productStock).ToList(); foreach (StockEntityModel.ProductStock productStock in productsStock) { productsStockDataName.Add(productStock.Name); } } } catch { //TODO: Should be implemented in future } return(productsStockDataName); }
protected void btn_sure_Click(object sender, EventArgs e) { Purchase purchases = this.AddPurchase(); PurchaseProvider provider = new PurchaseProvider(); switch (this.OperationFlag) { case Operation.Add: if (purchases.Good_Id == "") { this.Alert("ÉÌÆ·±àºÅûÉèÖã¬Ìí¼Óʧ°Ü!!!"); break; } if (purchases.Staffinfo_Id == 0) { this.Alert("Ô±¹¤±àºÅΪ0£¬Ìí¼Óʧ°Ü!!!"); break; } if (this.IsSame() == 1) { break; } if (this.IsRang() == false) { break; } if (provider.Insert(purchases)) { StockProvider stockProvider = new StockProvider(); Stock stock = new Stock(); stock.Stock_Num = purchases.Purchase_Num; stock.Good_Id = purchases.Good_Id; stock.Stock_Oper = 1; stock.Staffinfo_Id = purchases.Staffinfo_Id; stock.Purchase_Price = purchases.Purchase_Price; stock.Purchase_Datetime = DateTime.Now.ToString("yyyyMMdd"); if (stockProvider.Insert(stock)) { this.Alert("Ìí¼Ó³É¹¦!!!"); this.TextCancel(); } } break; case Operation.Update: if (false == String.IsNullOrEmpty(purchases.Good_Id)) { this.Alert("²ÎÊý´íÎó£¬ÐÞ¸Äʧ°Ü!!!"); break; } if (this.IsRang() == false) { break; } if (provider.Update(purchases)) { this.Alert("Ð޸ijɹ¦!!!"); this.BindText(); } break; } }
public Tests() { stockController = new StockController(mockProvider.Object); stockProvider = new StockProvider(mockRepo.Object); }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["id"] != null) { id = Request.QueryString["id"].ToString(); if (!IsPostBack) { this.BindText(); } this.OperationFlag = Operation.Update; } else { this.txt_datetime.Text = DateTime.Now.ToString("yyyyMMdd"); } if (!IsPostBack) { this.ddl_GoodId.DataSource = Good_Record; this.ddl_GoodId.Width = 100; this.ddl_GoodId.DataValueField = "good_num"; this.ddl_GoodId.DataBind(); this.ddl_buyerid.DataSource = Buyer_Record; this.ddl_buyerid.Width = 100; this.ddl_buyerid.DataValueField = "buyer_bh"; this.ddl_buyerid.DataBind(); StockProvider provider = new StockProvider(); DataTable table = provider.GetStocks(this.ddl_GoodId.SelectedValue.ToString()); int min = 0; int max = 0; int sum = 0; int price = 0; for (int i = 0; i < table.Rows.Count; i++) { sum += Convert.ToInt32(table.Rows[i]["stock_num"]); price = Convert.ToInt32(table.Rows[i]["purchase_price"]); if (i == 0) { min = max = price; continue; } if (price < min) { min = price; } else if (price > max) { max = price; } } this.lbl_PriceRange.Text = " 采购价格最低为:" + min.ToString() + " 最高为:" + max.ToString(); this.lbl_StockNum.Text = "库存还剩:" + sum.ToString(); //stock_sum = sum; Session["STOCKSUM"] = sum.ToString(); Good good = new Good(); GoodProvider provider1 = new GoodProvider(); String good_name = ""; good.Good_Num = this.ddl_GoodId.SelectedValue.ToString(); DataTable table1 = provider1.Select(good); if (table1 != null && table1.Rows.Count == 1) { good_name = table1.Rows[0]["good_name"].ToString(); } this.txt_goodname.Text = good_name; } if (Request.QueryString["staffid"] != null) { staffinfo_id = Convert.ToInt32(Request.QueryString["staffid"].ToString()); } this.txt_datetime.Enabled = false; this.txt_goodname.Enabled = false; this.account.Text = GetAccout(); //Session["LOGINED"].ToString(); this.datetime.Text = this.BindDayWeek(); }
protected void btn_sure_Click(object sender, EventArgs e) { Sale sales = this.AddSale(); SaleProvider provider = new SaleProvider(); switch (this.OperationFlag) { case Operation.Add: if (true == String.IsNullOrEmpty(sales.Good_Id)) { this.Alert("商品编号没设置,添加失败!!!"); break; } if (sales.Staffinfo_Id == 0) { this.Alert("员工编号为0,添加失败!!!"); break; } if (this.IsSame() == 1) { break; } if (this.IsRecValid() == false) { break; } sales.Purchase_Price = purchase_price.ToString(); if (provider.Insert(sales)) { StockProvider stockProvider = new StockProvider(); Stock stock = new Stock(); stock.Stock_Num = sales.Sale_Num; stock.Good_Id = sales.Good_Id; stock.Stock_Oper = -1; stock.Staffinfo_Id = sales.Staffinfo_Id; stock.Purchase_Price = sales.Purchase_Price; stock.Purchase_Datetime = DateTime.Now.ToString("yyyyMMdd"); if (stockProvider.Insert(stock)) { this.Alert("添加成功!!!"); this.TextCancel(); int sum = Convert.ToInt32(Session["STOCKSUM"].ToString()); sum -= Convert.ToInt32(sales.Sale_Num); Session["STOCKSUM"] = sum.ToString(); this.lbl_StockNum.Text = "库存还剩:" + sum.ToString(); } } break; case Operation.Update: if (false == String.IsNullOrEmpty(sales.Good_Id)) { this.Alert("参数错误,修改失败!!!"); break; } sales.Purchase_Price = Session["PURCHASEPRICE"].ToString(); if (provider.Update(sales)) { this.Alert("修改成功!!!"); this.BindText(); } break; } }