// changes data displayed when value in combobox changed private void comboBox1_SelectedValueChanged(object sender, EventArgs e) { if (comboBox1.SelectedValue != null) { Package pack = new Package(); // default constructor pack = ViewPackagesDB.GetPackage(comboBox1.Text); packages = pack; txtId.Text = pack.PackageId.ToString(); txtName.Text = pack.PkgName.ToString(); dtStart.Value = pack.PkgStartDate; dtEnd.Value = pack.PkgEndDate; txtPrice.Text = pack.PkgBasePrice.ToString("c"); richTextBox1.Text = pack.PkgDesc.ToString(); } }
private void btnUpdate_CLick(object sender, EventArgs e) { Package update = new Package(); update.PkgName = txtName.Text; update.PkgStartDate = dtStart.Value; update.PkgEndDate = dtEnd.Value; update.PkgBasePrice = Convert.ToDecimal(txtPrice.Text.Substring(1)); update.PkgDesc = richTextBox1.Text; DialogResult dialogResult = MessageBox.Show("Are you sure you want to update package?", "Update", MessageBoxButtons.YesNo); bool updated = false; updated = ViewPackagesDB.UpdatePackage(packages, update); if (updated) { MessageBox.Show("Update Successful!"); GetPackages(); comboBox1.Enabled = true; comboBox1.Focus(); txtName.Enabled = false; dtStart.Enabled = false; dtEnd.Enabled = false; txtPrice.Enabled = false; richTextBox1.Enabled = false; btnUpdate.Visible = false; btnDelete.Visible = false; btnEditProducts.Visible = false; btnEdit.Visible = true; btnCancel.Visible = false; } else { MessageBox.Show("Error. Please update a field."); } }
// binds package names to the combo box private void GetPackages() { comboBox1.DataSource = ViewPackagesDB.GetPackagesName(); // gets names from defined method on ViewPackagesDM.cs }