protected void Page_Load(object sender, EventArgs e) { if (InsertProductController.isUserLoggedIn()) { if (InsertProductController.isUserAnAdmin(Request.Cookies["user_email"].Value)) { typeDD.DataSource = InsertProductController.getProductType(); typeDD.DataBind(); } else { userWarnLbl.Text = "403. You're not an admin."; nameBox.Enabled = false; priceBox.Enabled = false; stockBox.Enabled = false; insertBtn.Visible = false; } } else { userWarnLbl.Text = "403. You're not logged in"; nameBox.Enabled = false; priceBox.Enabled = false; stockBox.Enabled = false; insertBtn.Visible = false; logoutBtn.Visible = false; } }
protected void Page_Load(object sender, EventArgs e) { User us = (User)Session["user"]; if (Session["user"] != null) { if (us.RoleID == 1) { if (!IsPostBack) { DropDownListType.DataSource = InsertProductController.getAllProductType().Select(p => p.Name).ToList(); DropDownListType.DataBind(); } GridViewInsertProduct.DataSource = ViewProductController.getAllProduct(); GridViewInsertProduct.DataBind(); } else { Response.Redirect("Home.aspx"); } } else { Response.Redirect("Home.aspx"); } }
protected void BtnInsertProduct_Click(object sender, EventArgs e) { String Name = BoxProductName.Text; int Stock = 0; int Price = 0; if (int.TryParse(BoxProductStock.Text.ToString(), out Stock) == true) { Stock = int.Parse(BoxProductStock.Text.ToString()); } if (int.TryParse(BoxProductPrice.Text.ToString(), out Price) == true) { Price = int.Parse(BoxProductPrice.Text.ToString()); } String TypeID = BoxTypeID.Text; int ID = InsertProductController.CountData() + 1; Response response = InsertProductController.DoInsertProduct(TypeID, Name, Price, Stock, ID); if (response.successStatus == false) { LabelInsertProduct.Text = response.message; } else { Response.Redirect("ViewProduct.aspx"); } }
private Boolean ProductValidation(string name, string stock, string price, string typeId) { string errorMessage = ""; if (InsertProductController.ProductValidation(name, stock, price, typeId, out errorMessage) == false) { return(HandleWrongFormat(errorMessage)); } return(true); }
protected void BtnSubmit_Click(object sender, EventArgs e) { string productName = TxtProductName.Text.ToString(); string productStock = TxtProductStock.Text.ToString(); string productPrice = TxtProductPrice.Text.ToString(); string productType = TxtProductType.Text.ToString(); Boolean isFormatCorrect = ProductValidation(productName, productStock, productPrice, productType); if (isFormatCorrect == true) { InsertProductController.InsertNewProductController(productName, Int32.Parse(productType), Int32.Parse(productStock), Int32.Parse(productPrice)); LblError.Text = "Data successfully inputted"; } }
private void SetProductData() { if (!Page.IsPostBack) { TxtProductPrice.Text = "0"; TxtProductStock.Text = "0"; TxtProductType.Text = "0"; } List <ProductType> allType = InsertProductController.GetAllProductTypeController(); GridProductType.DataSource = allType; GridProductType.DataBind(); }
protected void insertBtn_Click(object sender, EventArgs e) { bool stat = true; string productName = nameBox.Text; int stock = Convert.ToInt32(stockBox.Text); int price = Convert.ToInt32(priceBox.Text); String type = typeDD.SelectedItem.Text.ToString(); if (!InsertProductController.isBoxFilled(productName)) { nameValidate.Text = "Name must be filled!"; stat = false; } if (!InsertProductController.isBoxFilled(stockBox.Text)) { stockValidate.Text = "Stock must be filled!"; stat = false; } if (!InsertProductController.isBoxFilled(priceBox.Text)) { priceValidate.Text = "Price must be filled!"; stat = false; } if (!InsertProductController.checkStockReq(stock)) { warningLbl.Text = "Stock must 1 or more!"; } else if (!InsertProductController.checkPriceReq(price)) { warningLbl.Text = "Price must be 1000 or more and multiply of 1000!"; } else if (stat) { InsertProductController.insertNewProduct(productName, stock, price, type); Response.Redirect("./ViewProduct.aspx"); } }
protected void btnInsertP_Click(object sender, EventArgs e) { LabelInvalid.Visible = true; string errorMsg = ""; try { string name = productName.Text.ToString(); int stock = Int32.Parse(productStock.Text.ToString()); int price = Int32.Parse(productPrice.Text.ToString()); string type = DropDownListType.Text.ToString(); bool success = InsertProductController.Insert(name, stock, price, type, out errorMsg); if (!success) { LabelInvalid.Text = errorMsg; } else { var pt = InsertProductController.SearchByName(type); if (success) { LabelInvalid.Text = errorMsg; InsertProductController.doInsert(pt.ProductTypeID, name, price, stock); GridViewInsertProduct.DataSource = ViewProductController.getAllProduct(); GridViewInsertProduct.DataBind(); Response.Redirect("InsertProduct.aspx"); } else { LabelInvalid.Text = errorMsg; } } }catch { LabelInvalid.Text = "Cannot be empty!"; } }