// Додавання покупця private void buttonRegister_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(RegName.Text) || string.IsNullOrWhiteSpace(RegPassword.Text)) { if (string.IsNullOrWhiteSpace(RegName.Text)) { RegName.BackColor = Color.MediumSeaGreen; } if (string.IsNullOrWhiteSpace(RegPassword.Text)) { RegPassword.BackColor = Color.MediumSeaGreen; } MessageBox.Show("Fill in the blank space, please"); RegName.BackColor = Color.White; RegPassword.BackColor = Color.White; } else if (RegName.Text.Length < 2 || RegName.Text.Length >= 10) { RegName.BackColor = Color.Red; MessageBox.Show("Name has inappropriate length, try again"); RegName.BackColor = Color.White; RegName.Text = string.Empty; } else if (RegPassword.Text.Length < 2 || RegPassword.Text.Length >= 10) { RegPassword.BackColor = Color.Red; MessageBox.Show("Password has inappropriate length, try again"); RegPassword.BackColor = Color.White; RegPassword.Text = string.Empty; } else { string name = RegName.Text; string pass = RegPassword.Text; cost = comboBoxRegCost.Text; string rooms = RegRooms.Text; string neighb = RegNeighb.Text; string condition = RegCondition.Text; if (store.Buyers.FirstOrDefault(u => u.Name == name || u.Password == pass) == null) { Buyer user = new Buyer(name, pass); Criteria criteria = new Criteria(cost, rooms, neighb, condition); store.Criterias.Add(criteria); store.Buyers.Add(user); MessageBox.Show("We are glad to hear you joined us!"); store.Save(); this.Hide(); } else { MessageBox.Show("Sorry, such buyer already exists in our app("); RegName.Text = string.Empty; RegPassword.Text = string.Empty; } } }
// Закриття форми, збереження даних private void Menu_FormClosing(object sender, FormClosingEventArgs e) { if (!store.IsDirty) { return; } var res = MessageBox.Show("Save data before exit?", "", MessageBoxButtons.YesNoCancel); switch (res) { case DialogResult.Cancel: e.Cancel = true; break; case DialogResult.Yes: store.Save(); break; case DialogResult.No: break; } }