protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["logout"] == "true") { Application["count_user"] = ((int)Application["count_user"]) - 1; Session.Clear(); HttpCookie authUser = Request.Cookies["auth_user"]; if (authUser != null) { authUser.Value = ""; authUser.Expires = DateTime.Now.AddYears(-1); Response.SetCookie(authUser); } Response.Redirect("Index.aspx"); } using (WatchShopEntities db = new WatchShopEntities()) { int count = db.Product.Count(); if (count > 0) { products = db.Product.ToList(); } } }
public static Product FindById(int id) { using (WatchShopEntities db = new WatchShopEntities()) { db.Configuration.ProxyCreationEnabled = false; return(db.Product.Find(new object[] { id })); } }
public static HeaderTransaction InsertHeaderTransaction(HeaderTransaction headerTransaction) { using (WatchShopEntities db = new WatchShopEntities()) { db.HeaderTransaction.Add(headerTransaction); db.SaveChanges(); return(headerTransaction); } }
public static void DecreaseStock(int id, int quantity) { using (WatchShopEntities db = new WatchShopEntities()) { Product product = db.Product.Where(x => x.id == id).FirstOrDefault(); product.stock -= quantity; db.SaveChanges(); } }
public static List <HeaderTransaction> FindByUsername(string username) { using (WatchShopEntities db = new WatchShopEntities()) { db.Configuration.ProxyCreationEnabled = false; return(db.HeaderTransaction .Where(x => x.user_id == username) .Select(x => x) .ToList()); } }
public static List <DetailTransaction> FindDetailByTransactionId(int transactionId) { using (WatchShopEntities db = new WatchShopEntities()) { db.Configuration.ProxyCreationEnabled = false; return(db.DetailTransaction .Where(x => x.trans_id == transactionId) .Select(x => x) .ToList()); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string id = Context.Request.QueryString.Get("id"); using (WatchShopEntities db = new WatchShopEntities()) { product = db.Product.Where(x => x.id.ToString() == id).FirstOrDefault(); qtyValidator.MaximumValue = product.stock.ToString(); qtyValidator.ErrorMessage = "Quantity Must Between 1 and " + qtyValidator.MaximumValue; } } }
public static DetailTransaction InsertDetailTransaction(DetailTransaction detailTransaction) { using (WatchShopEntities db = new WatchShopEntities()) { db.DetailTransaction.Add(detailTransaction); db.SaveChanges(); int productId = detailTransaction.product_id; int quantity = detailTransaction.quantity.Value; ProductRepository.DecreaseStock(productId, quantity); return(detailTransaction); } }
protected void DeleteButton_Click(object sender, EventArgs e) { Button currentButton = (Button)sender; int selectedRowIndex = 0; if (int.TryParse(currentButton.ID.Substring(0, currentButton.ID.Length - 2), out selectedRowIndex)) { int productId = int.Parse(((Label)ProductTable.Rows[selectedRowIndex].Cells[6].Controls[0]).Text); using (WatchShopEntities db = new WatchShopEntities()) { Product toDeleteProduct = db.Product.Where(x => x.id == productId).First(); db.Product.Remove(toDeleteProduct); db.SaveChanges(); } Response.Redirect(Request.RawUrl); } }
private BranchDAO() { db = CommonDAO.Instance.Database; }
private UserDAO() { db = CommonDAO.Instance.Database; }
private ProductDAO() { db = CommonDAO.Instance.Database; }
private RoleDAO() { db = CommonDAO.Instance.Database; }
protected void Page_Load(object sender, EventArgs e) { Session.Remove("product_to_edit"); using (WatchShopEntities db = new WatchShopEntities()) { List <Product> products = db.Product.ToList(); for (int i = 0; i < products.Count; i++) { TableRow newRow = new TableRow(); ProductTable.Controls.Add(newRow); TableCell numberCell = new TableCell(); numberCell.Controls.Add(new Label() { Text = (i + 1) + "." }); newRow.Cells.Add(numberCell); TableCell nameCell = new TableCell(); nameCell.Controls.Add(new Label() { Text = products[i].name }); newRow.Cells.Add(nameCell); TableCell priceCell = new TableCell(); priceCell.Controls.Add(new Label() { Text = ((int)products[i].price).ToString() }); newRow.Cells.Add(priceCell); TableCell stockCell = new TableCell(); stockCell.Controls.Add(new Label() { Text = products[i].stock.ToString() }); newRow.Cells.Add(stockCell); TableCell editButtonCell = new TableCell(); Button editButton = new Button() { ID = (i + 1) + "_E", Text = "Edit", CssClass = "btn btn-warning" }; editButton.Click += EditButton_Click; editButtonCell.Controls.Add(editButton); newRow.Cells.Add(editButtonCell); TableCell deleteButtonCell = new TableCell(); Button deleteButton = new Button() { ID = (i + 1) + "_D", Text = "Delete", CssClass = "btn btn-danger" }; deleteButton.Click += DeleteButton_Click; deleteButtonCell.Controls.Add(deleteButton); newRow.Cells.Add(deleteButtonCell); TableCell productIdCell = new TableCell(); productIdCell.Visible = false; productIdCell.Controls.Add(new Label() { Text = products[i].id.ToString() }); newRow.Cells.Add(productIdCell); } } }
private CommonDAO() { database = new WatchShopEntities(); }