public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
WindowState = WindowState.Maximized;
WindowStyle = WindowStyle.None;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
textbox.Clear();
txtpassword.Clear();
combobox.SelectedItem = null;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (textbox.Text == "")
{
MessageBox.Show("Please enter username", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
textbox.Focus();
}
else if (txtpassword.Password.ToString() == "")
{
MessageBox.Show("Please enter the password", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
txtpassword.Focus();
}
else if (combobox.Text == "")
{
MessageBox.Show("Please select usertype", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
combobox.Focus();
}
else if (textbox.Text != "admin")
{
MessageBox.Show("Please check username", "Alert Message", MessageBoxButton.OK, MessageBoxImage.Information);
}
else if (txtpassword.Password.ToString() != "admin")
{
MessageBox.Show("Please check the password", "Alert Message", MessageBoxButton.OK, MessageBoxImage.Information);
}
else if (combobox.Text != "Admin")
{
MessageBox.Show("Please check the usertype", "Alert Message", MessageBoxButton.OK, MessageBoxImage.Information);
}
else
{
Employe_page m = new Employe_page();
m.ShowDialog();
}
}
public partial class Employe_page : Window
{
string ConnectionString = @"Data Source=DESKTOP-89MGP64;Initial Catalog=new_restaurant_application;Integrated Security=True";
public Employe_page()
{
InitializeComponent();
WindowState = WindowState.Maximized;
WindowStyle = WindowStyle.None;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
try
{
SqlConnection con = new SqlConnection(ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("user_insert", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("user_id", SqlDbType.NVarChar).Value = string.IsNullOrWhiteSpace(txtUserId.Text) ? DBNull.Value : (object)txtUserId.Text;
cmd.Parameters.AddWithValue("emp_id", SqlDbType.NVarChar).Value = string.IsNullOrWhiteSpace(cmboSelEmp.Text) ? DBNull.Value : (object)cmboSelEmp.SelectedValue;
cmd.Parameters.AddWithValue("emp_name", SqlDbType.NVarChar).Value = string.IsNullOrWhiteSpace(cmboSelEmp.Text) ? DBNull.Value : (object)cmboSelEmp.Text;
cmd.Parameters.AddWithValue("user_type", SqlDbType.NVarChar).Value = string.IsNullOrWhiteSpace(cmboSelUser.Text) ? DBNull.Value : (object)cmboSelUser.Text;
cmd.Parameters.AddWithValue("privilege", SqlDbType.NVarChar).Value = string.IsNullOrWhiteSpace(cmboSelUser.Text) ? DBNull.Value : (object)cmboSelUser.SelectedValue;
cmd.Parameters.AddWithValue("user_name", SqlDbType.NVarChar).Value = string.IsNullOrWhiteSpace(txtUsername.Text) ? DBNull.Value : (object)txtUsername.Text;
cmd.Parameters.AddWithValue("password", SqlDbType.NVarChar).Value = string.IsNullOrWhiteSpace(txtPassword.Password) ? DBNull.Value : (object)txtPassword.Password;
cmd.Parameters.AddWithValue("branch", SqlDbType.NVarChar).Value = string.IsNullOrWhiteSpace(cmboBranch.Text) ? DBNull.Value : (object)cmboBranch.Text;
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Saved");
}
catch ( SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
}
What I have tried:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
WindowState = WindowState.Maximized;
WindowStyle = WindowStyle.None;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
textbox.Clear();
txtpassword.Clear();
combobox.SelectedItem = null;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (textbox.Text == "")
{
MessageBox.Show("Please enter username", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
textbox.Focus();
}
else if (txtpassword.Password.ToString() == "")
{
MessageBox.Show("Please enter the password", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
txtpassword.Focus();
}
else if (combobox.Text == "")
{
MessageBox.Show("Please select usertype", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
combobox.Focus();
}
else if (textbox.Text != "admin")
{
MessageBox.Show("Please check username", "Alert Message", MessageBoxButton.OK, MessageBoxImage.Information);
}
else if (txtpassword.Password.ToString() != "admin")
{
MessageBox.Show("Please check the password", "Alert Message", MessageBoxButton.OK, MessageBoxImage.Information);
}
else if (combobox.Text != "Admin")
{
MessageBox.Show("Please check the usertype", "Alert Message", MessageBoxButton.OK, MessageBoxImage.Information);
}
else
{
Employe_page m = new Employe_page();
m.ShowDialog();
}
}
public partial class Employe_page : Window
{
string ConnectionString = @"Data Source=DESKTOP-89MGP64;Initial Catalog=new_restaurant_application;Integrated Security=True";
public Employe_page()
{
InitializeComponent();
WindowState = WindowState.Maximized;
WindowStyle = WindowStyle.None;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
try
{
SqlConnection con = new SqlConnection(ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("user_insert", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("user_id", SqlDbType.NVarChar).Value = string.IsNullOrWhiteSpace(txtUserId.Text) ? DBNull.Value : (object)txtUserId.Text;
cmd.Parameters.AddWithValue("emp_id", SqlDbType.NVarChar).Value = string.IsNullOrWhiteSpace(cmboSelEmp.Text) ? DBNull.Value : (object)cmboSelEmp.SelectedValue;
cmd.Parameters.AddWithValue("emp_name", SqlDbType.NVarChar).Value = string.IsNullOrWhiteSpace(cmboSelEmp.Text) ? DBNull.Value : (object)cmboSelEmp.Text;
cmd.Parameters.AddWithValue("user_type", SqlDbType.NVarChar).Value = string.IsNullOrWhiteSpace(cmboSelUser.Text) ? DBNull.Value : (object)cmboSelUser.Text;
cmd.Parameters.AddWithValue("privilege", SqlDbType.NVarChar).Value = string.IsNullOrWhiteSpace(cmboSelUser.Text) ? DBNull.Value : (object)cmboSelUser.SelectedValue;
cmd.Parameters.AddWithValue("user_name", SqlDbType.NVarChar).Value = string.IsNullOrWhiteSpace(txtUsername.Text) ? DBNull.Value : (object)txtUsername.Text;
cmd.Parameters.AddWithValue("password", SqlDbType.NVarChar).Value = string.IsNullOrWhiteSpace(txtPassword.Password) ? DBNull.Value : (object)txtPassword.Password;
cmd.Parameters.AddWithValue("branch", SqlDbType.NVarChar).Value = string.IsNullOrWhiteSpace(cmboBranch.Text) ? DBNull.Value : (object)cmboBranch.Text;
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Saved");
}
catch ( SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
}