/*Clears all TextBoxes */ protected void clearAllBoxes() { SurnameBox.Clear(); NameBox.Clear(); PhoneBox.Clear(); MailBox.Clear(); CityBox.Clear(); AddressBox.Clear(); NoteBox.Clear(); }
/* * Name, Phone number: * Those two parameters have to be filled to create a new contact * * Sets newContact object as null if values are incorrect */ virtual protected void AddBtn_Click(object sender, EventArgs e) { /*Name and Phone Number fields have to be passed to create new contact*/ bool isPhoneNumberEmpty = string.IsNullOrWhiteSpace(PhoneBox.Text); bool isNameEmpty = string.IsNullOrWhiteSpace(NameBox.Text); if (isPhoneNumberEmpty == true || isNameEmpty == true) { newContact = null; MessageBox.Show("\"Name\" and \"Phone number\" fields have to be filled!"); clearAllBoxes(); } else if (!isNumeric(PhoneBox.Text)) { MessageBox.Show("Type correct phone number!"); newContact = null; PhoneBox.Clear(); } else if (!isMailCorrect(MailBox.Text)) { MessageBox.Show("Type correct Email Address!"); newContact = null; MailBox.Clear(); } else { People person = new People(); person.Surname = SurnameBox.Text; person.Name = NameBox.Text; person.FullName = SurnameBox.Text + " " + NameBox.Text; person.PhoneNumber = PhoneBox.Text; person.EmailAddress = MailBox.Text; person.City = CityBox.Text; person.Address = AddressBox.Text; person.AdditionalInfo = NoteBox.Text; newContact = person; clearAllBoxes(); this.Close(); } }
private void button2_Click(object sender, EventArgs e)//Save (UPDATE) button { if (activeUserId > 0) { User _user = new User(); _user.Name = name.Text; _user.Surname = surname.Text; _user.Username = UsernameBox4.Text; _user.Password = Password.Text; _user.Telephone = maskedTextBox1.Text; _user.Mail = MailBox.Text; _user.StartDateofEmployment = maskedTextBox2.Text; _user.Birthdate = maskedTextBox3.Text; _user.Address = AddressBox.Text; _user.UserRole = (UserRoles)Enum.Parse(typeof(UserRoles), comboBox1.Text); _user.ID = activeUserId; DataBaseConnection _db = new DataBaseConnection(); _db.UpdateUser(_user); FillGrid(_db); int rowIndex = findRowIndex(activeUserId); if (rowIndex >= 0) { dataGridView1.CurrentCell = dataGridView1.Rows[rowIndex].Cells[1]; } } else { try { DataBaseConnection _db = new DataBaseConnection(); User _user = new User(); _user.Name = name.Text; _user.Surname = surname.Text; _user.Username = UsernameBox4.Text; _user.Password = Password.Text; _user.Telephone = maskedTextBox1.Text; _user.Mail = MailBox.Text; _user.StartDateofEmployment = maskedTextBox2.Text; _user.Birthdate = maskedTextBox3.Text; _user.Address = AddressBox.Text; _user.UserRole = (UserRoles)Enum.Parse(typeof(UserRoles), comboBox1.Text); _db.AddUser(_user); FillGrid(_db); MessageBox.Show("Kayıt Başarıyla Eklendi"); name.Clear(); surname.Clear(); UsernameBox4.Clear(); Password.Clear(); maskedTextBox1.Clear(); MailBox.Clear(); maskedTextBox2.Clear(); maskedTextBox3.Clear(); AddressBox.Clear(); } catch (Exception ex) { MessageBox.Show("Kayıt Eklenemedi" + ex.Message); } } }