// Deleting Packages from Package private void pkgdelete_Click(object sender, EventArgs e) { Packages pkgDel = new Packages(); Packages_Products_Suppliers pkgPrdDel = new Packages_Products_Suppliers(); List <Packages> pack = PackagesDB.GetPackages(); if ( Validation.IsListSelected(lstPkg, "Available Packages", lblError) ) { // delete confirmaiton message box with ok or cancel if (MessageBox.Show("Delete Package?", "Delete Confirmation", MessageBoxButtons.OKCancel) == DialogResult.OK) { lblError.Text = ""; foreach (var item in pack) { if (item.PackageId == Convert.ToInt32(txtpkgID.Text)) // txt box is one number ahead of newly added items { pkgDel.PackageId = item.PackageId; pkgDel.PkgName = item.PkgName; pkgDel.PkgStartDate = item.PkgStartDate; pkgDel.PkgEndDate = item.PkgEndDate; pkgDel.PkgDesc = item.PkgDesc; pkgDel.PkgBasePrice = item.PkgBasePrice; pkgDel.PkgAgencyCommission = item.PkgAgencyCommission; } } var productSupplierid = from item in Products_SuppliersDB.GetProductsSuppliers() where item.PackageId == Convert.ToInt32(txtpkgID.Text) select new { item.ProductSupplierId }; Packages_Products_Suppliers pkgDelPro = new Packages_Products_Suppliers(); var id = productSupplierid.ToList(); foreach (var item in id) { pkgDelPro.ProductSupplierId = item.ProductSupplierId; } pkgDelPro.PackageId = Convert.ToInt32(txtpkgID.Text); Packages_Products_SuppliersDB.DeletePackagePro(pkgDelPro); PackagesDB.DeletePackage(pkgDel); lstPkg.Items.Clear(); List <Packages> packupdatedel = PackagesDB.GetPackages(); foreach (var pkg in packupdatedel) { lstPkg.Items.Add(pkg.PkgName); } ResetPackage(); } } }
public void ResetProductSupllierList() { lstPkg.Items.Clear(); List <Packages> packupdated = PackagesDB.GetPackages(); foreach (var pkg in packupdated) { lstPkg.Items.Add(pkg.PkgName); } lstPkg.SelectedIndex = 0; productSupplierList = Products_SuppliersDB.GetProductsSuppliers(); var distinctPrd = productSupplierList.Select(o => o.ProdName).Distinct().ToList(); comboPrdPack.DataSource = distinctPrd; comboProduct.DataSource = product; comboSupplier.DataSource = supplier; listSuppPkg.Items.Clear(); foreach (var supname in productSupplierList) { if (supname.ProdName == comboPrdPack.SelectedItem.ToString()) { listSuppPkg.Items.Add(supname.SupName); } } }
//Package List load method public void PackageListLoad() { var pack = PackagesDB.GetPackages(); foreach (var item in pack) { if (item.PkgName == lstPkg.SelectedItem.ToString()) { var pkgId = item.PackageId; txtPkgName.Text = item.PkgName; txtpkgID.Text = item.PackageId.ToString(); txtDesc.Text = item.PkgDesc; txtBasePrice.Text = item.PkgBasePrice.ToString("c"); txtCommission.Text = item.PkgAgencyCommission.ToString("c"); if (item.PkgStartDate.HasValue) { dtpPkgStrt.Text = item.PkgStartDate.Value.ToShortDateString(); } else { dtpPkgStrt.Format = DateTimePickerFormat.Short; } if (item.PkgEndDate.HasValue) { dtpPkgEndDate.Text = item.PkgEndDate.Value.ToShortDateString(); } else { dtpPkgEndDate.Format = DateTimePickerFormat.Short; } } } }
// Save Edit Packages private void saveEdit_Click(object sender, EventArgs e) { if ( Validation.IsPresent(txtPkgName, "Package Name", lblError) && Validation.IsPresent(txtBasePrice, "Base Price", lblError) && Validation.NotNegativeDeciaml(txtBasePrice, "Base Price", lblError) && Validation.IsPresent(txtCommission, "Commission", lblError) && Validation.NotNegativeDeciaml(txtCommission, "Commission", lblError) && Validation.IsPresent(txtDesc, "Description", lblError) ) { var pack = PackagesDB.GetPackages(); Packages oldPck = new Packages(); foreach (var item in pack) { if (item.PackageId == Convert.ToInt32(txtpkgID.Text)) { oldPck.PackageId = item.PackageId; oldPck.PkgName = item.PkgName; oldPck.PkgStartDate = item.PkgStartDate; oldPck.PkgEndDate = item.PkgEndDate; oldPck.PkgDesc = item.PkgDesc; oldPck.PkgBasePrice = item.PkgBasePrice; oldPck.PkgAgencyCommission = item.PkgAgencyCommission; } } DateTime?StartDate = string.IsNullOrWhiteSpace(dtpPkgStrt.Text) ? (DateTime?)null : DateTime.Parse(dtpPkgStrt.Text); DateTime?EndDate = string.IsNullOrWhiteSpace(dtpPkgEndDate.Text) ? (DateTime?)null : DateTime.Parse(dtpPkgEndDate.Text); var duration = (EndDate.Value - StartDate.Value).TotalDays; if (duration < 0 | duration == 0) { lblError.Text = "Package End Date must be greater than Package Start Date"; return; } if (Convert.ToDecimal(txtCommission.Text.Replace("$", "")) >= Convert.ToDecimal(txtBasePrice.Text.Replace("$", ""))) { lblError.Text = "Commission Should be less than Package Price"; return; } Packages updtPck = new Packages(); updtPck.PackageId = Convert.ToInt32(txtpkgID.Text); updtPck.PkgName = txtPkgName.Text; updtPck.PkgStartDate = StartDate; updtPck.PkgEndDate = EndDate; updtPck.PkgDesc = txtDesc.Text; updtPck.PkgBasePrice = Convert.ToDecimal(txtBasePrice.Text.Replace("$", "")); updtPck.PkgAgencyCommission = Convert.ToDecimal(txtCommission.Text.Replace("$", "")); PackagesDB.UpdatePackage(oldPck, updtPck); lstPkg.Items.Clear(); List <Packages> packupdated = PackagesDB.GetPackages(); foreach (var pkg in packupdated) { lstPkg.Items.Add(pkg.PkgName); } lstPkg.SelectedIndex = 0; ResetPackage(); } }
// saving Added Packges private void pkgSave_Click(object sender, EventArgs e) { if ( Validation.IsPresent(txtPkgName, "Package Name", lblError) && Validation.IsPresent(txtBasePrice, "Base Price", lblError) && Validation.NotNegativeDeciaml(txtBasePrice, "Base Price", lblError) && Validation.IsPresent(txtCommission, "Commission", lblError) && Validation.NotNegativeDeciaml(txtCommission, "Commission", lblError) && Validation.IsPresent(txtDesc, "Description", lblError) ) { lblError.Text = ""; DateTime?StartDate = string.IsNullOrWhiteSpace(dtpPkgStrt.Text) ? (DateTime?)null : DateTime.Parse(dtpPkgStrt.Text); DateTime?EndDate = string.IsNullOrWhiteSpace(dtpPkgEndDate.Text) ? (DateTime?)null : DateTime.Parse(dtpPkgEndDate.Text); var duration = (EndDate.Value - StartDate.Value).TotalDays; if (duration < 0 | duration == 0) { lblError.Text = "Package End Date must be greater than Package Start Date"; return; } if (Convert.ToDecimal(txtCommission.Text.Replace("$", "")) >= Convert.ToDecimal(txtBasePrice.Text.Replace("$", ""))) { lblError.Text = "Commission Should be less than Package Price"; return; } Packages pckAdd = new Packages(); pckAdd.PkgName = txtPkgName.Text; pckAdd.PkgStartDate = StartDate; pckAdd.PkgEndDate = EndDate; pckAdd.PkgDesc = txtDesc.Text; pckAdd.PkgBasePrice = Convert.ToDecimal(txtBasePrice.Text.Replace("$", "")); pckAdd.PkgAgencyCommission = Convert.ToDecimal(txtCommission.Text.Replace("$", "")); PackagesDB.AddPackage(pckAdd); lstPkg.Items.Clear(); List <Packages> packlstAdd = PackagesDB.GetPackages(); foreach (var pkg in packlstAdd) { lstPkg.Items.Add(pkg.PkgName); } lstPkg.SelectedIndex = 0; lstPkg.Enabled = true; lstPkg.Items.Clear(); List <Packages> packupdated = PackagesDB.GetPackages(); foreach (var pkg in packupdated) { lstPkg.Items.Add(pkg.PkgName); } lstPkg.SelectedIndex = 0; ResetPackage(); //disable the Date Time Pickers dtpPkgStrt.Enabled = false; dtpPkgEndDate.Enabled = false; } }