using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; 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; namespace veloprokat2 { /// /// Логика взаимодействия для Info_prodaji.xaml /// public partial class Info_prodaji : Window { public Info_prodaji() { InitializeComponent(); SqlConnection connection = new SqlConnection("server=mssql; Trusted_Connection=YES;DataBase=gr692_kaa;"); connection.Open(); string cmd = "select SpisProk.ID as '№', Bikes.Title as 'Название велосипеда', Bikes.[Type] as 'Тип велосипеда', Tarif.NameOfTarif as 'Название тарифа', cast(Tarif.Price as int) as 'Цена', FORMAT(SpisProk.Date, 'dd/MM/yyyy') as 'Дата', FORMAT(SpisProk.Time, N'hh\\:mm') as 'Время', [Count] as 'Количество', SpisProk.Lname as 'Фамилия', InfoRab.Lname as 'Фамилия сотрудника' from SpisProk, Bikes, Tarif, InfoRab " + "where SpisProk.ID_Bikes = Bikes.ID and SpisProk.ID_tarif = Tarif.ID and SpisProk.IdRab = InfoRab.ID"; SqlCommand createcommand = new SqlCommand(cmd, connection); createcommand.ExecuteNonQuery(); SqlDataAdapter sql = new SqlDataAdapter(createcommand); DataTable dt = new DataTable("SpisProk"); sql.Fill(dt); prodinfo.ItemsSource = dt.DefaultView; connection.Close(); } private void Vixod(object sender, RoutedEventArgs e) { MainWindowAdm MWA = new MainWindowAdm(); MWA.Show(); Close(); } private void Button_Search(object sender, RoutedEventArgs e) { if (Search.Text.Length > 0) { SqlConnection connection = new SqlConnection("server=mssql; Trusted_Connection=YES;DataBase=gr692_kaa;"); connection.Open(); string cmd = "select SpisProk.ID as '№', Bikes.Title as 'Название велосипеда', Bikes.[Type] as 'Тип велосипеда', Tarif.NameOfTarif as 'Название тарифа', cast(Tarif.Price as int) as 'Цена', FORMAT(SpisProk.Date, 'dd/MM/yyyy') as 'Дата', FORMAT(Time, N'hh\\:mm') as 'Время', [Count] as 'Количество', SpisProk.Lname as 'Фамилия', InfoRab.Lname as 'Фамилия сотрудника' from SpisProk, Bikes, Tarif, InfoRab where SpisProk.ID_Bikes = Bikes.ID and SpisProk.ID_tarif = Tarif.ID and SpisProk.IdRab = InfoRab.ID" + " and ( SpisProk.ID like '%" + Search.Text + "%' or Bikes.Title like '%" + Search.Text + "%' or Bikes.[Type] like '%" + Search.Text + "%' or Tarif.NameOfTarif like '%" + Search.Text + "%' or cast(Tarif.Price as int) like '%" + Search.Text + "%' or FORMAT(SpisProk.Date, 'dd/MM/yyyy') like '%" + Search.Text + "%' or FORMAT(Time, N'hh\\:mm') like '%" + Search.Text + "%' or[Count] like '%" + Search.Text + "%' or SpisProk.Lname like '%" + Search.Text + "%' or InfoRab.Lname like '%"+ Search.Text +"%' )"; SqlCommand createcommand = new SqlCommand(cmd, connection); createcommand.ExecuteNonQuery(); SqlDataAdapter sql = new SqlDataAdapter(createcommand); DataTable dt = new DataTable("SpisProk"); sql.Fill(dt); prodinfo.ItemsSource = dt.DefaultView; connection.Close(); } else if (Search.Text.Length == 0) { SqlConnection connection = new SqlConnection("server=mssql; Trusted_Connection=YES;DataBase=gr692_kaa;"); connection.Open(); string cmd = "select SpisProk.ID as '№', Bikes.Title as 'Название велосипеда', Bikes.[Type] as 'Тип велосипеда', Tarif.NameOfTarif as 'Название тарифа', cast(Tarif.Price as int) as 'Цена', FORMAT(SpisProk.Date, 'dd/MM/yyyy') as 'Дата', FORMAT(SpisProk.Time, N'hh\\:mm') as 'Время', [Count] as 'Количество', SpisProk.Lname as 'Фамилия', InfoRab.Lname as 'Фамилия сотрудника' from SpisProk, Bikes, Tarif, InfoRab " + "where SpisProk.ID_Bikes = Bikes.ID and SpisProk.ID_tarif = Tarif.ID and SpisProk.IdRab = InfoRab.ID"; SqlCommand createcommand = new SqlCommand(cmd, connection); createcommand.ExecuteNonQuery(); SqlDataAdapter sql = new SqlDataAdapter(createcommand); DataTable dt = new DataTable("SpisProk"); sql.Fill(dt); prodinfo.ItemsSource = dt.DefaultView; connection.Close(); } } } }