Example #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string Img_name;

            if (state == "add")
            {
                Img_name = txtFileUpload.PostedFile.FileName;
                string folder_path    = Server.MapPath(@"dist/images/products/");
                string UploadFilePath = folder_path + Img_name;
                txtFileUpload.PostedFile.SaveAs(UploadFilePath);
                HttpCookie AddMsgCookie = new HttpCookie("status");
                AddMsgCookie.Value   = "add";
                AddMsgCookie.Expires = DateTime.Now.AddSeconds(6);
                Response.Cookies.Add(AddMsgCookie);
                BL.AddNewProduct(txtProductName.Value, Convert.ToInt32(txtQty.Value), Convert.ToDouble(txtPrice.Value), Img_name,
                                 txtProductDesc.Value, Convert.ToInt32(drpCategories.SelectedValue), Convert.ToInt32(drpSuppliers.SelectedValue));
            }
            else
            {
                if (txtFileUpload.PostedFile.FileName != "")
                {
                    Img_name = txtFileUpload.PostedFile.FileName;
                    string folder_path    = Server.MapPath(@"dist/images/products/");
                    string UploadFilePath = folder_path + Img_name;
                    txtFileUpload.PostedFile.SaveAs(UploadFilePath);
                }
                else
                {
                    Img_name = img;
                }

                HttpCookie UpdateMsgCookie = new HttpCookie("status");
                UpdateMsgCookie.Value   = "update";
                UpdateMsgCookie.Expires = DateTime.Now.AddSeconds(6);
                Response.Cookies.Add(UpdateMsgCookie);
                BL.UpdateProduct(Convert.ToInt32(Request.QueryString["id"]), txtProductName.Value, Convert.ToInt32(txtQty.Value), Convert.ToDouble(txtPrice.Value), Img_name,
                                 txtProductDesc.Value, Convert.ToInt32(drpCategories.SelectedValue), Convert.ToInt32(drpSuppliers.SelectedValue));
                state = "add";
            }
            Response.Redirect("Products.aspx");
        }