public override void Delete() { try { var item = DataBase.CustomerList.SingleOrDefault(x => x.ID == int.Parse(TxtIDCli.Text)); if (item != null) { MessageBox.Show(TxtNaCli.Text + " Has been Successfully deleted"); DataBase.CustomerList.Remove(item); TxtIDCli.Text = ""; TxtNaCli.Text = ""; TxtAdCli.Text = ""; TxtIDCli.Focus(); } else { MessageBox.Show(TxtNaCli.Text + " Is not in Our Database"); TxtIDCli.Text = ""; TxtNaCli.Text = ""; TxtAdCli.Text = ""; TxtIDCli.Focus(); } } catch (Exception error) { MessageBox.Show("Error" + error); TxtIDCli.Text = ""; TxtNaCli.Text = ""; TxtAdCli.Text = ""; TxtIDCli.Focus(); } //DataBase.ProductsList.RemoveAll(x => x.ID == int.Parse(TxtIdPro.Text)); /*foreach (var c in DataBase.ProductsList) { if (c.ID == int.Parse(TxtIdPro.Text)) { MessageBox.Show(TxtDesPro.Text + " Has been Successfully deleted"); DataBase.ProductsList.Remove(c); } else { MessageBox.Show(TxtDesPro.Text + " Is not in Our stock"); } }*/ }
public override Boolean Save() { if (string.IsNullOrWhiteSpace(TxtIDCli.Text) || string.IsNullOrWhiteSpace(TxtNaCli.Text) || string.IsNullOrWhiteSpace(TxtAdCli.Text)) { MessageBox.Show("All fields are mandatory", "error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } else { var item = DataBase.CustomerList.SingleOrDefault(x => x.ID == int.Parse(TxtIDCli.Text)); if (item == null) { try { DataBase.CustomerList.Add(new Customer(int.Parse(TxtIDCli.Text), TxtNaCli.Text, TxtAdCli.Text)); MessageBox.Show(TxtNaCli.Text + " has been successfully saved "); TxtIDCli.Text = ""; TxtNaCli.Text = ""; TxtAdCli.Text = ""; TxtIDCli.Focus(); return true; } catch (Exception error) { MessageBox.Show("Error" + error); TxtIDCli.Text = ""; TxtNaCli.Text = ""; TxtAdCli.Text = ""; TxtIDCli.Focus(); return false; } } else { MessageBox.Show("The custumer with ID " + TxtIDCli.Text + "Already is in the DataBase"); TxtIDCli.Text = ""; TxtNaCli.Text = ""; TxtAdCli.Text = ""; return false; } } }
private void button4_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(TxtIDCli.Text) || string.IsNullOrWhiteSpace(TxtNaCli.Text) || string.IsNullOrWhiteSpace(TxtAdCli.Text)) { MessageBox.Show("All fields are mandatory", "error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { var item = DataBase.CustomerList.SingleOrDefault(x => x.ID == int.Parse(TxtIDCli.Text)); if (item != null) { try { item.Name = TxtNaCli.Text; item.Address = TxtAdCli.Text; MessageBox.Show(TxtNaCli.Text + " has been successfully updated"); TxtIDCli.Text = ""; TxtNaCli.Text = ""; TxtAdCli.Text = ""; TxtIDCli.Focus(); } catch (Exception error) { MessageBox.Show("Error" + error); TxtIDCli.Text = ""; TxtNaCli.Text = ""; TxtAdCli.Text = ""; TxtIDCli.Focus(); } } else { MessageBox.Show("You cannot Update or change the customer ID"); TxtIDCli.Text = ""; TxtNaCli.Text = ""; TxtAdCli.Text = ""; } } }