Пример #1
0
 protected void btnUpdateP_Click(object sender, EventArgs e)
 {
     LabelPr.Visible = true;
     try
     {
         string name     = UpdatePName.Text.ToString();
         int    stock    = Int32.Parse(UpdateStock.Text.ToString());
         int    price    = Int32.Parse(UpdatePrice.Text.ToString());
         string errorMsg = "";
         bool   success  = UpdateProductController.validateUpdate(name, stock, price, out errorMsg);
         if (!success)
         {
             LabelPr.Text = errorMsg;
         }
         else
         {
             if (success)
             {
                 LabelPr.Text = newID.ToString();
                 UpdateProductController.updateProduct(newID, name, price, stock);
                 Response.Redirect("UpdateProduct.aspx");
             }
             else
             {
                 LabelPr.Text = errorMsg;
             }
         }
     }
     catch
     {
         LabelPr.Text = "Cannot be empty!";
     }
 }
Пример #2
0
        protected void BtnUpdateProduct_Click(object sender, EventArgs e)
        {
            String ProductID = Request.QueryString["id"];
            String Name      = BoxProductName.Text.ToString();
            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());
            }
            Response response = UpdateProductController.UpdateItem(ProductID, Name, Price, Stock);

            if (response.successStatus == false)
            {
                labelUpdateProduct.Text = response.message;
            }
            else
            {
                Response.Redirect("ViewProduct.aspx");
            }
        }
Пример #3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["LoginSession"] == null)
     {
         Response.Redirect("../HomeView/Home.aspx");
     }
     else
     {
         String ID   = Session["LoginSession"].ToString();
         MsUser user = HomeController.FetchDataForHome(ID);
         if (user.RoleID != "RL1")
         {
             Response.Redirect("../HomeView/Home.aspx");
         }
         else
         {
             if (Request.QueryString["id"] == null)
             {
                 Response.Redirect("../HomeView/Home.aspx");
             }
             else
             {
                 if (!IsPostBack)
                 {
                     String    ProductID = Request.QueryString["id"];
                     MsProduct product   = UpdateProductController.GetProductByID(ProductID);
                     BoxProductName.Text  = product.ProductName.ToString();
                     BoxProductPrice.Text = product.ProductPrice.ToString();
                     BoxProductStock.Text = product.ProductStock.ToString();
                 }
             }
         }
     }
 }
Пример #4
0
        private Boolean DataValidation(string name, string stock, string price)
        {
            string errorMessage = "";

            if (UpdateProductController.UpdateProductValidation(name, stock, price, out errorMessage) == false)
            {
                return(HandleWrongFormat(errorMessage));
            }
            return(true);
        }
Пример #5
0
 private void SetProductData()
 {
     productId = Int32.Parse(Request.QueryString["productId"]);
     if (!Page.IsPostBack)
     {
         Product currData = UpdateProductController.GetProductController(productId);
         TxtNewName.Text  = currData.Name;
         TxtNewStock.Text = currData.Stock.ToString();
         TxtNewPrice.Text = currData.Price.ToString();
     }
 }
Пример #6
0
        protected void UpdateData(object sender, EventArgs e)
        {
            string newName  = TxtNewName.Text.ToString();
            string newStock = TxtNewStock.Text.ToString();
            string newPrice = TxtNewPrice.Text.ToString();

            if (DataValidation(newName, newStock, newPrice) == true)
            {
                UpdateProductController.GetUpdateProductController(newName, Int32.Parse(newStock), Int32.Parse(newPrice), productId);
                Response.Redirect("ViewProduct.aspx");
            }
        }
Пример #7
0
        protected void updateBtn_Click(object sender, EventArgs e)
        {
            bool   stat        = true;
            int    id          = Convert.ToInt32(Request.QueryString["Id"]);
            string name        = nameBox.Text;
            int    price       = Convert.ToInt32(priceBox.Text);
            int    stock       = Convert.ToInt32(stockBox.Text);
            string productType = typeDD.SelectedValue;

            if (!UpdateProductController.isBoxFilled(name))
            {
                nameValidate.Text = "Name must be filled!";
                stat = false;
            }
            if (!UpdateProductController.isBoxFilled(priceBox.Text))
            {
                priceValidate.Text = "Price must be filled!";
                stat = false;
            }
            if (!UpdateProductController.isBoxFilled(stockBox.Text))
            {
                stockValidate.Text = "Stock must be filled!";
                stat = false;
            }
            if (!UpdateProductController.isBoxFilled(productType))
            {
                typeValidate.Text = "Type must be chosen!";
                stat = false;
            }

            if (stat)
            {
                if (!UpdateProductController.isValid(id, name, price, stock, productType))
                {
                    if (!UpdateProductController.PriceMeetRequirement(price))
                    {
                        warningLbl.Text = "Price is not valid.";
                    }
                    else if (!UpdateProductController.StockMeetRequirement(stock))
                    {
                        warningLbl.Text = "Stock is not valid.";
                    }
                }
                else
                {
                    Response.Redirect("./ViewProduct.aspx");
                }
            }
        }
Пример #8
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (UpdateProductController.isUserLoggedIn())
     {
         if (UpdateProductController.isUserAnAdmin(Request.Cookies["user_email"].Value))
         {
             if (!IsPostBack)
             {
                 int      id             = Convert.ToInt32(Request.QueryString["Id"]);
                 vProduct currentProduct = UpdateProductController.getProductObject(id);
                 typeDD.DataSource = UpdateProductController.getProductType();
                 typeDD.DataBind();
                 nameBox.Text         = currentProduct.Name;
                 stockBox.Text        = currentProduct.Stock.ToString();
                 priceBox.Text        = currentProduct.Price.ToString();
                 typeDD.SelectedValue = currentProduct.Type;
             }
         }
         else
         {
             userWarnLbl.Text  = "403. You're not an admin.";
             nameBox.Enabled   = false;
             priceBox.Enabled  = false;
             stockBox.Enabled  = false;
             updateBtn.Visible = false;
         }
     }
     else
     {
         userWarnLbl.Text  = "403. You're not logged in";
         nameBox.Enabled   = false;
         priceBox.Enabled  = false;
         stockBox.Enabled  = false;
         updateBtn.Visible = false;
         logoutBtn.Visible = false;
     }
 }
Пример #9
0
 private void update_button_Click(object sender, EventArgs e)
 {
     UpdateProductController.updateProduct(updatedProductValueLabels, bindingNavigator_Products, this, productId);
 }