private void BtnAdd_Click(object sender, EventArgs e) { MasterForm master = (this.Parent.Parent as MasterForm); try { //Input data gathered here to improve readability and centralize any processing //that needs to be done before insertion string firstName = this.txtFirstNameInput.Text.Trim(); string lastName = this.txtLastNameInput.Text.Trim(); string phoneNumber = this.mtxtPhoneNumberInput.Text.Trim(); int collectorTypeID = (int)this.cbxTypeInput.SelectedValue; string status = ""; if (String.IsNullOrEmpty(status = DBCollector.Validate(firstName, lastName, phoneNumber))) { object insertedID = DBCollector.InsertCollector(collectorTypeID, firstName, lastName, phoneNumber); if (insertedID != null) { status = "Collector " + firstName + " " + lastName + " has been added." + Environment.NewLine; List <int> bookTagValues = DBControlHelper.GetValuesFromCheckedControls(this.tlpBookTagsSelection); if (bookTagValues.Count > 0 && DBCollector.InsertInterests((int)insertedID, 1, bookTagValues)) { status += "Book interests added." + Environment.NewLine; } List <int> mapTagValues = DBControlHelper.GetValuesFromCheckedControls(this.tlpMapTagsSelection); if (mapTagValues.Count > 0 && DBCollector.InsertInterests((int)insertedID, 2, mapTagValues)) { status += "Map interests added." + Environment.NewLine; } List <int> periodicalTagValues = DBControlHelper.GetValuesFromCheckedControls(this.tlpPeriodicalTagsSelection); if (periodicalTagValues.Count > 0 && DBCollector.InsertInterests((int)insertedID, 3, periodicalTagValues)) { status += "Periodical interests added." + Environment.NewLine; } } } master.SetStatus(status); } catch (Exception ex) { master.SetStatus("Error! Add failed: " + ex.Message); } }
private void BtnUpdate_Click(object sender, EventArgs e) { MasterForm master = (this.Parent.Parent as MasterForm); try { //Input data gathered here to improve readability and centralize any processing //that needs to be done before insertion int collectorID = (int)nudCollectorId.Value; string firstName = txtFirstName.Text.Trim(); string lastName = txtLastName.Text.Trim(); int collectorTypeID = (int)cbxType.SelectedValue; string phoneNumber = mtxtPhoneNumber.Text.Trim(); string status = ""; if (String.IsNullOrEmpty(status = DBCollector.Validate(firstName, lastName, phoneNumber))) { if (DBCollector.UpdateCollector(collectorID, collectorTypeID, firstName, lastName, phoneNumber)) { status = "Collector " + firstName + " " + lastName + " has been saved." + Environment.NewLine; } } if (DBCollector.UpdateInterests(collectorID, 1, DBControlHelper.GetValuesFromCheckedControls(this.tlpTagsBookSelection))) { status += "Book interests have been updated." + Environment.NewLine; } if (DBCollector.UpdateInterests(collectorID, 2, DBControlHelper.GetValuesFromCheckedControls(this.tlpTagsMapSelection))) { status += "Map interests have been updated." + Environment.NewLine; } if (DBCollector.UpdateInterests(collectorID, 3, DBControlHelper.GetValuesFromCheckedControls(this.tlpTagsPeriodicalSelection))) { status += "Periodical interests have been updated." + Environment.NewLine; } master.SetStatus(status); } catch (Exception ex) { master.SetStatus("Error! Save failed: " + ex.Message); } }