Beispiel #1
0
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            var _db = new ProductContext();

            btnEdit.OnClientClick = "Confirm()";
            string confirmValue = Request.Form["confirm_value"];

            if (confirmValue == "Yes")
            {
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked YES!')", true);

                EditProducts editproduct = new EditProducts();
                Product      product     = CreateFood();

                if (!String.IsNullOrWhiteSpace(Request.QueryString["id"]))
                {
                    int id = Convert.ToInt32(Request.QueryString["id"]);
                    LabelStatus.Text = editproduct.UpdateFood(id, product);
                }
                else
                {
                    LabelStatus.Text = editproduct.InsertFood(product);
                }

                Response.Redirect("~/Admin/EditList.aspx");
            }
            else
            {
            }
        }
        public ActionResult Edit(EditProducts obje)
        {
            int id = (int)TempData["ProductID"];
            using (ShoppingDBEntities objDBedt = new ShoppingDBEntities())
            {

                var result = objDBedt.tblProducts.Where(y => y.ProductID == id).FirstOrDefault();

                //result.ProductName = obje.ProductName;
                result.Description = obje.ProductDesc;
                result.UnitPrice = Convert.ToInt32(obje.ProductUnitPrice);
                result.Unit = obje.ProductUnit;
                //result.Category = obje.CategoryId;

                objDBedt.Entry(result).State = EntityState.Modified;
                objDBedt.SaveChanges();

                TempData["editStatus"] = "Successful";

            }
            if (TempData["dtlpage"] == null)
            {
                return RedirectToAction("ShowProduct");
            }
            else
            {
                int lid = id;
                return RedirectToAction("Details", "Product", new { id = lid });
            }
        }
Beispiel #3
0
        protected void EditProductButton_Click(object sender, EventArgs e)
        {
            Boolean fileOK = false;
            String  path   = Server.MapPath("~/Catalog/Images/");

            if (ProductImage.HasFile)
            {
                String   fileExtension     = System.IO.Path.GetExtension(ProductImage.FileName).ToLower();
                String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
                for (int i = 0; i < allowedExtensions.Length; i++)
                {
                    if (fileExtension == allowedExtensions[i])
                    {
                        fileOK = true;
                    }
                }
            }

            if (fileOK)
            {
                try
                {
                    // Save to Images folder.
                    ProductImage.PostedFile.SaveAs(path + ProductImage.FileName);
                    // Save to Images/Thumbs folder.
                    ProductImage.PostedFile.SaveAs(path + "Thumbs/" + ProductImage.FileName);
                }
                catch (Exception ex)
                {
                    LabelAddStatus.Text = ex.Message;
                }

                // Add product data to DB.
                EditProducts products   = new EditProducts();
                bool         addSuccess = products.EditProduct(AddProductName.Text, AddProductDescription.Text,
                                                               AddProductPrice.Text, DropDownAddCategory.SelectedValue, ProductImage.FileName);
                if (addSuccess)
                {
                    // Reload the page.
                    string pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count());
                    Response.Redirect(pageUrl + "?ProductAction=edit");
                }
                else
                {
                    LabelAddStatus.Text = "Unable to add new product to database.";
                }
            }
            else
            {
                LabelAddStatus.Text = "Unable to accept file type.";
            }
        }
 private void go_edit(object sender, RoutedEventArgs e)
 {
     if (productlist.SelectedIndex != -1) // Магия / не трогать
     {
         EditProducts ed = new EditProducts(productlist.SelectedItem as Service);
         ed.Show();
         this.Hide();
     }
     else
     {
         MessageBox.Show("Выберите услугу!", "Error");
     }
 }
        private void btnEdit_Click(object sender, EventArgs e)
        {
            EditProducts etPct = new EditProducts();

            if (ltPct.dataGridListProducts.SelectedRows.Count > 0)
            {
                etPct.txtId.Text          = ltPct.dataGridListProducts.CurrentRow.Cells[0].Value.ToString();
                etPct.txtProductName.Text = ltPct.dataGridListProducts.CurrentRow.Cells[1].Value.ToString();
                etPct.txtCategory.Text    = ltPct.dataGridListProducts.CurrentRow.Cells[2].Value.ToString();
                etPct.txtDescription.Text = ltPct.dataGridListProducts.CurrentRow.Cells[3].Value.ToString();
                etPct.txtPrice.Text       = ltPct.dataGridListProducts.CurrentRow.Cells[4].Value.ToString();
                etPct.txtStock.Text       = ltPct.dataGridListProducts.CurrentRow.Cells[5].Value.ToString();
                this.OpenForms(etPct);
            }
            else
            {
                MessageBox.Show("You need to select a row to edit a product.");
            }
            this.btnProductList.Enabled = true;
            this.btnEdit.Enabled        = false;
        }
Beispiel #6
0
        private void FillForm(int id)
        {
            try
            {
                EditProducts editproduct = new EditProducts();


                Product product = editproduct.GetProduct(id);

                txtDescription.Text = product.Description;
                txtName.Text        = product.ProductName;
                txtPrice.Text       = product.UnitPrice.ToString();

                ddlImage.SelectedValue = product.ImagePath;
                ddlType.SelectedIndex  = Convert.ToInt32(product.CategoryID.ToString());
            }
            catch (Exception ex)
            {
                LabelStatus.Text = ex.ToString();
            }
        }
        //edit a product through form
        private void btnEditProducts_Click(object sender, EventArgs e)
        {
            var editProductForm = new EditProducts(this, ProductList);

            editProductForm.ShowDialog();
        }