/// <summary> /// Updates customer data in db based on corresponding customer object [Eric] /// </summary> /// <param name="editedCustomer"></param> public static void Update(Customer editedCustomer) { // Connect to db TravelExpertsContext db = new TravelExpertsContext(); // Grab the original record Customer custRecord = db.Customers.Single(c => c.CustomerId == editedCustomer.CustomerId); // Assign updated props to the record custRecord.CustFirstName = editedCustomer.CustFirstName; custRecord.CustLastName = editedCustomer.CustLastName; custRecord.CustAddress = editedCustomer.CustAddress; custRecord.CustCity = editedCustomer.CustCity; custRecord.CustProv = editedCustomer.CustProv; custRecord.CustPostal = editedCustomer.CustPostal; custRecord.CustCountry = editedCustomer.CustCountry; custRecord.CustHomePhone = editedCustomer.CustHomePhone; custRecord.CustBusPhone = editedCustomer.CustBusPhone; custRecord.CustEmail = editedCustomer.CustEmail; custRecord.UserLogin = editedCustomer.UserLogin; custRecord.UserPass = editedCustomer.UserPass; // Update DB db.SaveChanges(); }
public static void Add(Customer customer) { var db = new TravelExpertsContext(); db.Customers.Add(customer); db.SaveChanges(); }
//-------------------ADD SUPPLIER-------------------------------------------------- private void btnAdd_Click(object sender, EventArgs e) { //create second form frmAddModifySupplier addModifySupplier = new frmAddModifySupplier(); addModifySupplier.isAdd = true; addModifySupplier.supplier = null; DialogResult result = addModifySupplier.ShowDialog();//accept returns ok //if dialogresult is ok, save supplier, and display items in list view if (result == DialogResult.OK) { selectedSupplier = addModifySupplier.supplier; selectedSuppliersIds = addModifySupplier.selectedSuppliersIds; //selectedSupplierIds = addModifySupplier.selectedSupplierIds; try { var newSupplier = context.Suppliers.Add(selectedSupplier); context.SaveChanges(); DisplayLVSuppliers(); } //catch (DbUpdateConcurrencyException ex) //{ // HandleConcurrencyError(ex); //} catch (DbUpdateException ex) { HandleDataError(ex); } catch (Exception ex) { HandleGeneralError(ex); } } }
private void btnAdd_Click(object sender, EventArgs e) { //create second form frmAddModifyProduct addModifyProduct = new frmAddModifyProduct(); // setting isAdd to true to pass it to the second form addModifyProduct.isAdd = true; addModifyProduct.product = null; //no package //show it modal DialogResult result = addModifyProduct.ShowDialog();//accept returns ok //if dialogresult is ok, save package, and display items in list view if (result == DialogResult.OK) { selectedProduct = addModifyProduct.product; selectedProductsIds = addModifyProduct.selectedProductsIds; try { var newProduct = context.Products.Add(selectedProduct); context.SaveChanges(); //adding associated products DisplayLVProducts(); } catch (DbUpdateException ex) { HandleDataError(ex); } catch (Exception ex) { HandleGeneralError(ex); } } }
//Adding new package private void btnAdd_Click(object sender, EventArgs e) { HideForm(); //create second form frmAddModifyPackage addModPkg = new frmAddModifyPackage(); //create products form frmAddMultiProd addProd = new frmAddMultiProd(); // setting isAdd to true to pass it to the second form addModPkg.isAdd = true; addModPkg.package = null; //no package //show it modal DialogResult result = addModPkg.ShowDialog();//accept returns ok //if dialogresult is ok, save package, and display items in list view if (result == DialogResult.OK) { selectedPackage = addModPkg.package; selectedProductsIds = addModPkg.updated_Product_Selections; try { var newPackage = context.Packages.Add(selectedPackage); context.SaveChanges(); //adding associated products only if added if (selectedProductsIds != null) { foreach (var item in selectedProductsIds) { //creating the corresponding entry for each selected product //in the PackagesProductsSuppliers table PackagesProductsSuppliers pkgProdsup = new PackagesProductsSuppliers(); pkgProdsup.ProductSupplierId = item; int id = selectedPackage.PackageId; pkgProdsup.PackageId = id; context.PackagesProductsSuppliers.Add(pkgProdsup); } context.SaveChanges(); } DisplayLVPackages(); } catch (DbUpdateException ex) { HandleDataError(ex); } catch (Exception ex) { HandleGeneralError(ex); } } ShowForm(); ClearSelection(); }
private void RemoveBtn_Click(object sender, EventArgs e) { DialogResult button = MessageBox.Show( "Are you sure that you want to remove the selected record?", "Remove Item", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (button == DialogResult.OK) { context.Packages.Remove(currentPackage); context.SaveChanges(); Display(); } }
private void saveSupplierBtn_Click(object sender, EventArgs e) { supplier = new Supplier { SupplierId = Convert.ToInt32(SupplierIdTxt.Text), SupName = supNameTxt.Text }; if (AddButton == true) { context.Suppliers.Add(supplier); } else { context.Suppliers.Update(supplier); } context.SaveChanges(); MessageBox.Show("Record inserted successfully"); this.Close(); //supplier = new Supplier(); //context.Suppliers.Update(supplier); //MessageBox.Show("Supplier details updated"); //context.SaveChanges(); //Display(); //this.Close(); //supplier = new Supplier(); //supplier.SupplierId = Convert.ToInt32(SupplierIdTxt.Text); //supplier.SupName = supNameTxt.Text; //context.Suppliers.Add(supplier); //MessageBox.Show("Supplier added"); //context.SaveChanges(); //this.Close(); }
private void saveBtn_Click(object sender, EventArgs e) { productsupplier = new ProductsSupplier(); productsupplier.ProductSupplierId = Convert.ToInt32(ProdSupIDTxt.Text); productsupplier.ProductId = Convert.ToInt32(ProductIDTxt.Text); productsupplier.SupplierId = Convert.ToInt32(SupplierIdTxt.Text); if (AddButton == true) { context.ProductsSuppliers.Add(productsupplier); } else { context.ProductsSuppliers.Update(productsupplier); } context.SaveChanges(); MessageBox.Show("Record inserted succesfully"); this.Close(); }
private void saveBtn_Click(object sender, EventArgs e) { package = new Package(); package.PackageId = Convert.ToInt32(IDtxt.Text); package.PkgName = nameTxt.Text; package.PkgStartDate = Convert.ToDateTime(startDateTxt.Text); package.PkgEndDate = Convert.ToDateTime(endDateTxt.Text); package.PkgDesc = descriptionTxt.Text; package.PkgBasePrice = Convert.ToDecimal(packagebasepriceTxt.Text); package.PkgAgencyCommission = Convert.ToDecimal(commissionTxt.Text); if (buttonstatadd == true) //add a package { context.Packages.Add(package); } else //modify a package { context.Packages.Update(package); } DialogResult save = MessageBox.Show( $"Saving this Entry:\nID: {IDtxt.Text}\nName: {nameTxt.Text}\nStart Date: {startDateTxt.Text}\n" + $"End Date: {endDateTxt.Text}", "Confirm Entry", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (save == DialogResult.OK) { context.SaveChanges(); this.Close(); } }
private void saveBtn_Click(object sender, EventArgs e) { product = new Product { ProductId = Convert.ToInt32(IDtxt.Text), ProdName = productnameTxt.Text }; if (buttonstatusadd == true) // user clicked Add button { context.Products.Add(product); } else { context.Products.Update(product); } context.SaveChanges(); MessageBox.Show("Record Inserted Succefully"); this.Close(); }
private void RemoveBtn_Click(object sender, EventArgs e) { context.PackagesProductsSuppliers.Remove(currentPPS); context.SaveChanges(); Display(); }