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 { } }
private void btnAddProduct_Click(object sender, EventArgs e) { try { Products prod = new Products { ProductName = txtProductName.Text, CategoryID = (int)cbAddCategories.SelectedValue, QuantityPerUnit = txtProductUnit.Text, UnitPrice = Convert.ToDecimal(txtProductPrice.Text), UnitsInStock = (int)nUdUnitsInStock.Value }; ProductORM prodORM = new ProductORM(); bool result = prodORM.Insert(prod); if (result) { MessageBox.Show("Ürün Ekleme İşleminiz Başarıyla Gerçekleştirildi", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); ListViewProductFill(Convert.ToInt32(cbAddCategories.SelectedValue)); cbCategories.SelectedIndex = cbAddCategories.SelectedIndex; tabControlProducts.SelectedIndex = 0; ProductControlsClear(true); } 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ı"); txtProductPrice.Clear(); txtProductPrice.Focus(); } }
private void btnAdd_Click(object sender, EventArgs e) { Products p = new Products(); p.Name = txtName.Text; p.Quantity = (double)numQuantity.Value; p.Price = numPrice.Value; p.UnitTypeID = (int)combUnit.SelectedValue; p.CategoryID = (int)combCategory.SelectedValue; bool result = pOrm.Insert(p); if (result) { MessageBox.Show("Added successful!"); dataGridView1.DataSource = pOrm.Select(); } else { MessageBox.Show("Added not successful!"); } }