using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data;
namespace Restaurant_Application
{
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;
BindComboBox();
buffercombo();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
try
{
SqlConnection con = new SqlConnection(ConnectionString);
con.Open();
int id = int.Parse(txtUserId.Text);
string branch = cmboBranch.SelectedValuePath, emp_name = cmboSelEmp.Text, user_type = cmboSelUser.Text, user_name = txtUsername.Text, password = txtPassword.Password.ToString();
SqlCommand cmd = new SqlCommand(" insert_user '" + id+"','"+user_name+"','"+password+"','"+user_type+"','"+branch+"','"+ emp_name + "'", con);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Saved");
}
catch ( SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
private void BindComboBox()
{
SqlConnection con = new SqlConnection(ConnectionString);
cmboSelUser.Items.Clear();
con.Open();
SqlCommand cmd = new SqlCommand();
cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select privilege from user_privilege";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
cmboSelUser.Items.Add(dr["privilege"].ToString());
cmboSelUser.ItemsSource = ((IListSource)dt).GetList();
cmboSelUser.DisplayMemberPath = "privilege";
cmboSelUser.SelectedValuePath = "id";
}
con.Close();
}
private void buffercombo()
{
SqlConnection con = new SqlConnection(ConnectionString);
cmboSelEmp.Items.Clear();
con.Open();
SqlCommand cmd = new SqlCommand();
cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select name from add_employee";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
cmboSelEmp.Items.Add(dr["name"].ToString());
cmboSelEmp.DisplayMemberPath = "name";
cmboSelEmp.SelectedValuePath = "eid";
}
con.Close();
}
private void Button_Click1(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}
What I have tried:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data;
namespace Restaurant_Application
{
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;
BindComboBox();
buffercombo();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
try
{
SqlConnection con = new SqlConnection(ConnectionString);
con.Open();
int id = int.Parse(txtUserId.Text);
string branch = cmboBranch.SelectedValuePath, emp_name = cmboSelEmp.Text, user_type = cmboSelUser.Text, user_name = txtUsername.Text, password = txtPassword.Password.ToString();
SqlCommand cmd = new SqlCommand(" insert_user '" + id+"','"+user_name+"','"+password+"','"+user_type+"','"+branch+"','"+ emp_name + "'", con);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Saved");
}
catch ( SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
private void BindComboBox()
{
SqlConnection con = new SqlConnection(ConnectionString);
cmboSelUser.Items.Clear();
con.Open();
SqlCommand cmd = new SqlCommand();
cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select privilege from user_privilege";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
cmboSelUser.Items.Add(dr["privilege"].ToString());
cmboSelUser.ItemsSource = ((IListSource)dt).GetList();
cmboSelUser.DisplayMemberPath = "privilege";
cmboSelUser.SelectedValuePath = "id";
}
con.Close();
}
private void buffercombo()
{
SqlConnection con = new SqlConnection(ConnectionString);
cmboSelEmp.Items.Clear();
con.Open();
SqlCommand cmd = new SqlCommand();
cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select name from add_employee";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
cmboSelEmp.Items.Add(dr["name"].ToString());
cmboSelEmp.DisplayMemberPath = "name";
cmboSelEmp.SelectedValuePath = "eid";
}
con.Close();
}
private void Button_Click1(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}