private void custCreateOK_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.OK; // Form input checks: if (!String.IsNullOrWhiteSpace(newCustIdText.Text) && !string.IsNullOrWhiteSpace(newCustNameText.Text) && !string.IsNullOrWhiteSpace(newCustPhoneText.Text) && !string.IsNullOrWhiteSpace(newCustAddressText.Text)) { // ??? === DataManipulation dm = new DataManipulation("customers.txt"); if (dm.CustomerFind(int.Parse(newCustIdText.Text)) == null) { // Customer DOES NOT exist, so Create new: createCustomer(int.Parse(newCustIdText.Text), newCustNameText.Text, int.Parse(newCustPhoneText.Text), newCustAddressText.Text); MessageBox.Show("New customer created: \n\r - ID: " + newCustIdText.Text + "\n\r - Name: " + newCustNameText.Text + "\n\r - Phone: " + newCustPhoneText.Text + "\n\r - Address: " + newCustAddressText.Text + "\n\r", "Success!"); this.Close(); } else this.custCreateResultLbl.Text = "Customer with ID: " + newCustIdText.Text + " already exists!"; } else this.custCreateResultLbl.Text = "No fields should be blank!"; }
private void custSearchBtn_Click(object sender, EventArgs e) { int n; if (!string.IsNullOrWhiteSpace(this.wantedCustomerTXT.Text) && (int.TryParse(this.wantedCustomerTXT.Text, out n))) { // call func to return wanted customersobj DataManipulation dm = new DataManipulation("customers.txt"); Customer cust = dm.CustomerFind(int.Parse(this.wantedCustomerTXT.Text)); if (cust != null) { this.custSearchResultLBL.Text = "Customer found!"; this.customerSearchResult.Enabled = true; this.custSearchIDresult.Text = cust.ID.ToString(); this.custSearchNameResult.Text = cust.Name; this.custSearchPhoneResult.Text = cust.Phone.ToString(); this.custSearchAddressResult.Text = cust.Address; } else { this.customerSearchResult.Enabled = false; this.custSearchResultLBL.Text = "There is no customer with ID: " + this.wantedCustomerTXT.Text + "."; } } else { this.custSearchResultLBL.ForeColor = System.Drawing.Color.Red; this.custSearchResultLBL.Text = "Enter a valid ID!"; } }