private void SaveButton_Click(object sender, EventArgs e) { try { if (IMEITextBox.Text.Equals("") && IMEITextBox.Text.Length != 15) { MessageBox.Show("Invalid Input!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { bool IsExistsIMEi = _mobileManager.IsExists(IMEITextBox.Text); if (IsExistsIMEi) { MessageBox.Show("IMEI Exists!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (IMEITextBox.Text.Length != 15) { MessageBox.Show("IMEI Number Must be 15 digit!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (nameTextBox.Text.Equals("")) { MessageBox.Show("Invalid Name Input!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (PriceTextBox.Text.Equals("")) { MessageBox.Show("Invalid Price Input!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Mobile mobile = new Mobile(); mobile.Name = nameTextBox.Text; mobile.IMEI = IMEITextBox.Text; mobile.Price = Convert.ToDouble(PriceTextBox.Text); _mobileManager.Insert(mobile); button1_Click(sender, e); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void SearchButton_Click(object sender, EventArgs e) { try { if (SearchIMEITextBox.Text.Equals("")) { MessageBox.Show("Invalid Input!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (SearchIMEITextBox.Text.Length != 15) { MessageBox.Show("IMEI Number Must be 15 digit!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { bool IsExistsIMEi = _mobileManager.IsExists(SearchIMEITextBox.Text); if (!IsExistsIMEi) { MessageBox.Show("No data found!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } Mobile mobile; string IMEI = SearchIMEITextBox.Text; mobile = _mobileManager.SearchByIMEI(IMEI); IMEITextBox.Text = mobile.IMEI; nameTextBox.Text = mobile.Name; priceTextBox.Text = mobile.Price.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }