private void UpdateButton_Click(object sender, RoutedEventArgs e) { if (NameBox.Text == "" || BloodgroupBox.Text == "" || AddressBox.Text == "" || PhonenumberBox.Text == "" || CurrentcityBox.Text == "") { MessageBox.Show("Please fill up all the fields", "Error", MessageBoxButton.OK, MessageBoxImage.Error); NameTextBox.Focus(); } if (!Regex.Match(NameBox.Text, @"^([A-Z][a-z]+||[A-Z][a-z]+\s[A-Z][a-z]+||[A-Z][a-z]+\s[A-Z][a-z]+\s[A-Z][a-z]+)$").Success) { MessageBox.Show("Invalid Name", "Message", MessageBoxButton.OK, MessageBoxImage.Error); BloodgroupBox.Focus(); PhonenumberTextBox.Focus(); } else if (!Regex.Match(PhonenumberBox.Text, @"^\d{10}||\d{11}$").Success) { MessageBox.Show("Invalid Phone Number", "Message", MessageBoxButton.OK, MessageBoxImage.Error); AddressTextBox.Focus(); } else if ( !Regex.Match(AddressBox.Text, @"^([A-Z][a-z]+||\d{3}-[A-Z][a-z]+||[A-Z][a-z]+\s[A-Z][a-z]+,[A-Z][a-z]+,[A-Z][a-z]+)$").Success) { MessageBox.Show("Invalid Address", "Message", MessageBoxButton.OK, MessageBoxImage.Error); CurrentcityTextBox.Focus(); } else if (!Regex.Match(CurrentcityBox.Text, @"^[A-Z][a-z]+$").Success) { MessageBox.Show("Invalid Current City Name", "Message", MessageBoxButton.OK, MessageBoxImage.Error); } else if (Activate()) { Conn = DatabaseConnection.GetConnection(); if (Conn.State.ToString() == "Closed") { Conn.Open(); } string query = string.Format("update information set Name='" + NameBox.Text + "',Bloodgroup='" + BloodgroupBox.SelectionBoxItem + "',Phonenumber='" + PhonenumberBox.Text + "',Address='" + AddressBox.Text + "', Currentcity='" + CurrentcityBox.Text + "' wehre Id='" + IdComboBox.SelectionBoxItem + "'"); var cmd = new SqlCommand(query, Conn); cmd.ExecuteNonQuery(); MessageBox.Show("Data is Updated!!"); Conn.Close(); } }
private void SaveButton_Click(object sender, RoutedEventArgs e) { if (Name1TextBox.Text == "" || BloodgroupComboBox.Text == "" || AddressTextBox.Text == "" || PhonenumberTextBox.Text == "" || CurrentcityTextBox.Text == "") { MessageBox.Show("Please fill up all the fields", "Error", MessageBoxButton.OK, MessageBoxImage.Error); NameTextBox.Focus(); } else if (!Regex.Match(Name1TextBox.Text, @"^([A-Z][a-z]+||[A-Z][a-z]+\s[A-Z][a-z]+||[A-Z][a-z]+\s[A-Z][a-z]+\s[A-Z][a-z]+)$").Success) { MessageBox.Show("Invalid Name", "Message", MessageBoxButton.OK, MessageBoxImage.Error); BloodgroupBox.Focus(); PhonenumberTextBox.Focus(); } else if (!Regex.Match(PhonenumberTextBox.Text, @"^\d{10}||\d{11}$").Success) { MessageBox.Show("Invalid Phone Number", "Message", MessageBoxButton.OK, MessageBoxImage.Error); AddressTextBox.Focus(); } else if ( !Regex.Match(AddressTextBox.Text, @"^([A-Z][a-z]+||\d{3}-[A-Z][a-z]+\s[A-Z][a-z]+,[A-Z][a-z]+,[A-Z][a-z]+)$").Success) { MessageBox.Show("Invalid Address", "Message", MessageBoxButton.OK, MessageBoxImage.Error); CurrentcityTextBox.Focus(); } else if (!Regex.Match(CurrentcityTextBox.Text, @"^[A-Z][a-z]+$").Success) { MessageBox.Show("Invalid Current City Name", "Message", MessageBoxButton.OK, MessageBoxImage.Error); } else if (Activate()) { Conn = DatabaseConnection.GetConnection(); if (Conn.State.ToString() == "Closed") { Conn.Open(); } string query = string.Format("insert into information values('{0}','{1}','{2}','{3}','{4}','{5}')", IdTextBox.Text, Name1TextBox.Text, BloodgroupComboBox.SelectionBoxItem, PhonenumberTextBox.Text, AddressTextBox.Text, CurrentcityTextBox.Text); var cmd = new SqlCommand(query, Conn); cmd.ExecuteNonQuery(); MessageBox.Show("Data is Inserted!!"); Conn.Close(); } }