protected void btnProductInsert_Click(object sender, EventArgs e)
        {
            try
            {
                bool result = false;
                if (btnProductInsert.Text == "Güncelle")
                {
                    Entity.Products prod = new Entity.Products
                    {
                        ProductID      = Convert.ToInt32(Session["ProductID"]),
                        ProductName    = txtProductName.Value,
                        Description    = txtProductAciklama.Value,
                        UnitPrice      = Convert.ToDecimal(txtProductPrice.Value),
                        UnitsInStock   = int.Parse(txtProductUnitsInStock.Value),
                        CategoryID     = int.Parse(drpCategory.SelectedItem.Value),
                        SmallPhotoPath = "Content/User/images/small/" + photoUpload.FileName,
                        LargePhotoPath = "Content/User/images/large/" + photoUpload.FileName
                    };
                    ProductORM prodORM = new ProductORM();
                    result = prodORM.Update(prod);
                    photoUpload.SaveAs(Server.MapPath("~/Content/User/images/large/" + photoUpload.FileName));
                }
                else
                {
                    Entity.Products prod = new Entity.Products
                    {
                        ProductName    = txtProductName.Value,
                        Description    = txtProductAciklama.Value,
                        UnitPrice      = Convert.ToDecimal(txtProductPrice.Value),
                        UnitsInStock   = int.Parse(txtProductUnitsInStock.Value),
                        CategoryID     = int.Parse(drpCategory.SelectedItem.Value),
                        SmallPhotoPath = "Content/User/images/small/" + photoUpload.FileName,
                        LargePhotoPath = "Content/User/images/large/" + photoUpload.FileName
                    };
                    ProductORM prodORM = new ProductORM();
                    result = prodORM.Insert(prod);
                    photoUpload.SaveAs(Server.MapPath("~/Content/User/images/large/" + photoUpload.FileName));
                }

                if (result)
                {
                    eklemeBilgi.Visible   = true;
                    eklemeBilgi.InnerText = "İşleminiz Başarıyla Gerçekleştirildi.";
                }
                else
                {
                    eklemeBilgi.Visible   = true;
                    eklemeBilgi.InnerText = "İşleminiz Gerçekleştirilemedi.";
                }
            }
            catch
            {
            }
        }
示例#2
0
        private void btnUpdateProduct_Click(object sender, EventArgs e)
        {
            try
            {
                prod.ProductName     = txtUpdateProductName.Text;
                prod.QuantityPerUnit = txtUpdateUnit.Text;
                prod.UnitPrice       = Convert.ToDecimal((txtUpdateProductPrice.Text));
                prod.UnitsInStock    = (int)nUdUpdateUnitsInStock.Value;
                prod.CategoryID      = (int)cbUpdateCategories.SelectedValue;

                ProductORM prodORM = new ProductORM();
                bool       result  = prodORM.Update(prod);
                if (result)
                {
                    MessageBox.Show("Ürün Güncelleme İşleminiz Başarıyla Gerçekleştirildi", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    ListViewProductFill(Convert.ToInt32(cbUpdateCategories.SelectedValue));
                    cbCategories.SelectedIndex       = cbUpdateCategories.SelectedIndex;
                    tabControlProducts.SelectedIndex = 0;
                    ProductControlsClear(false);
                }
                else
                {
                    MessageBox.Show("İşlem Sırasında Bir Hata Meydana Geldi !", "Uyarı", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch
            {
                MessageBox.Show("Fiyat Girişi Yapılırken Bir Sorunla Karşılaşıldı");
                txtUpdateProductPrice.Clear();
                txtUpdateProductPrice.Focus();
            }
        }