private void frmRepairLog_Load(object sender, EventArgs e) { //Fills grid with customer repair details DataSet ds = new DataSet(); grdgetRepairDetails.DataSource = Repair.getRepairDetails(ds).Tables["ss"]; grdgetRepairDetails.AllowUserToAddRows = false; txtRepairID.Text = Repair.nextRepairID().ToString("0000"); //if grid is empty, close if (grdgetRepairDetails.RowCount == 0) { DialogResult result = MessageBox.Show("* * * WARNING * * * \n\n--------------------------------------------------------------\n\nNo Customers have been ADDED to allow REPAIR...\n\n--------------------------------------------------------------\n\nWould you like to ADD a Customer?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { frmCustomerAdd ca = new frmCustomerAdd(); this.Close(); ca.Show(); } else if (result == DialogResult.No) { frmMainMenu mm = new frmMainMenu(); this.Close(); mm.Show(); } } }
private void button1_Click(object sender, EventArgs e) { //Validation Regex characterVal = new Regex("^[a-zA-Z]*$"); Regex characterNumberVal = new Regex("^[a-zA-Z0-9 ]*$"); //////////////////////////Serial////////////////////////// if (txtPhoneSerialNumber.Text.Equals("")) { MessageBox.Show("Field Must Not Be Blank", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPhoneSerialNumber.Focus(); return; } else if (!txtPhoneSerialNumber.Text.All(Char.IsDigit)) { MessageBox.Show("Numbers only!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPhoneSerialNumber.Focus(); txtPhoneSerialNumber.Text = ""; return; } else if (txtPhoneSerialNumber.Text.Length > 20) { MessageBox.Show("Serial Number too long!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPhoneSerialNumber.Focus(); txtPhoneSerialNumber.Text = ""; return; } //////////////////////////Password////////////////////////// else if (txtPassword.Text.Equals("")) { MessageBox.Show("Phone password required, if there is none, then Specify NULL", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPassword.Focus(); return; } else if (!characterNumberVal.IsMatch(txtPassword.Text)) { MessageBox.Show("Name must not contain symbols, Letters and Numbers only!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPassword.Focus(); txtPassword.Text = ""; return; } else if (txtPassword.Text.Length > 20) { MessageBox.Show("Name Too Long!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPassword.Focus(); txtPassword.Text = ""; return; } //////////////////////////PhoneType(CBO)////////////////////////// else if (String.IsNullOrEmpty(cbophonetype.Text)) { MessageBox.Show("Please Select Phone type", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //////////////////////////Description(CBO)////////////////////////// else if (String.IsNullOrEmpty(cbbDescription.Text)) { MessageBox.Show("Please Select Cause of Repair", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //////////////////////////Description(TXT)////////////////////////// else if (!characterNumberVal.IsMatch(txtDescription.Text)) { MessageBox.Show("Please enter a description", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtDescription.Focus(); txtDescription.Text = ""; return; } else if (txtDescription.Text.Length > 75) { MessageBox.Show("Description Too Long!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtDescription.Focus(); txtDescription.Text = ""; return; } ///////////////////////////Cost/////////////////////////// else if (txtCost.Text.Equals("")) { MessageBox.Show("Field Must Not Be Blank", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtCost.Focus(); return; } else if (!txtCost.Text.All(Char.IsDigit)) { MessageBox.Show("Positive, Whole numbers only!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtCost.Focus(); txtCost.Text = ""; return; } else if (txtCost.Text.Length > 5) { MessageBox.Show("Price too long!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtCost.Focus(); txtCost.Text = ""; return; } //Changes description if its empty else if (txtDescription.Text.Equals("")) { txtDescription.Text.Equals("No Details"); return; } //Adds repair to system Repair repair = new Repair(Int32.Parse(txtRepairID.Text), txtPhoneSerialNumber.Text, txtPassword.Text, "In Progress", cbophonetype.Text + " - " + cbbDescription.Text + " - " + txtDescription.Text, Int32.Parse(txtCustomerID.Text), Int32.Parse(txtCost.Text)); repair.addRepair(); //Display success message MessageBox.Show("Repair Added", "Success"); //reset UI txtPhoneSerialNumber.Text = ""; txtPassword.Text = ""; txtCustomerID.Text = ""; lblCustomerName.Text = "Select a Customer..."; txtDescription.Text = ""; txtRepairID.Text = Repair.nextRepairID().ToString("0000"); cbophonetype.Text = ""; cbbDescription.Text = ""; grpRepairDetails.Visible = false; btnSubmit.Visible = false; }