|
@@ -1,5 +1,6 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Data.SqlClient;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
@@ -12,6 +13,7 @@ using System.Windows.Media;
|
|
|
using System.Windows.Media.Imaging;
|
|
|
using System.Windows.Shapes;
|
|
|
using System.Windows.Threading;
|
|
|
+using System.Data;
|
|
|
|
|
|
namespace HotelCalifornia
|
|
|
{
|
|
@@ -29,6 +31,8 @@ namespace HotelCalifornia
|
|
|
timer.Start();
|
|
|
}
|
|
|
|
|
|
+ SqlConnection con = new SqlConnection("Data Source=localhost;Initial Catalog=kursah;Integrated Security=True");
|
|
|
+
|
|
|
private void Update_Timer_Tick(object sender, EventArgs e)
|
|
|
{
|
|
|
timetxt.Text = DateTime.Now.ToString();
|
|
@@ -74,5 +78,223 @@ namespace HotelCalifornia
|
|
|
{
|
|
|
this.WindowState = WindowState.Minimized;
|
|
|
}
|
|
|
+
|
|
|
+ private void familiatxt_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
+ {
|
|
|
+ if (sender is TextBox textBox)
|
|
|
+ {
|
|
|
+ textBox.Text = new string
|
|
|
+ (textBox.Text.Where(ch => (ch >= 'А' && ch <= 'Я') || (ch >= 'а' && ch <= 'я')).ToArray());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void nametxt_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
+ {
|
|
|
+ if (sender is TextBox textBox)
|
|
|
+ {
|
|
|
+ textBox.Text = new string
|
|
|
+ (textBox.Text.Where(ch => (ch >= 'А' && ch <= 'Я') || (ch >= 'а' && ch <= 'я')).ToArray());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void otchestvotxt_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
+ {
|
|
|
+ if (sender is TextBox textBox)
|
|
|
+ {
|
|
|
+ textBox.Text = new string
|
|
|
+ (textBox.Text.Where(ch => (ch >= 'А' && ch <= 'Я') || (ch >= 'а' && ch <= 'я')).ToArray());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void telephonetxt_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
+ {
|
|
|
+ if (sender is TextBox textBox)
|
|
|
+ {
|
|
|
+ textBox.Text = new string
|
|
|
+ (textBox.Text.Where(ch => (ch >= '0' && ch <= '9')).ToArray());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void passporttxt_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
+ {
|
|
|
+ if (sender is TextBox textBox)
|
|
|
+ {
|
|
|
+ textBox.Text = new string
|
|
|
+ (textBox.Text.Where(ch => (ch >= '0' && ch <= '9')).ToArray());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Add_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (nametxt.Text == "" || familiatxt.Text=="" || telephonetxt.Text == "" || otchestvotxt.Text == "" || passporttxt.Text == "")
|
|
|
+ {
|
|
|
+ MessageBox.Show("Заполните все поля!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ }
|
|
|
+ else if (passporttxt.Text.Length < 10 || telephonetxt.Text.Length < 11)
|
|
|
+ {
|
|
|
+ MessageBox.Show("Поле номер телефона и паспорт не полностью заполнены!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ con.Open();
|
|
|
+ string reg = "INSERT INTO Client (LastName_Client,FirstName_Client,MiddleName_Client,Telephone_Client,Passport) VALUES('" + familiatxt.Text + "','" + nametxt.Text + "','" + otchestvotxt.Text + "','" + telephonetxt.Text + "','" + passporttxt.Text + "')";
|
|
|
+ SqlDataAdapter dataAdapter = new SqlDataAdapter(reg, con);
|
|
|
+ dataAdapter.SelectCommand.ExecuteNonQuery();
|
|
|
+ con.Close();
|
|
|
+ idclienttxt.Text = "";
|
|
|
+ nametxt.Text = "";
|
|
|
+ familiatxt.Text = "";
|
|
|
+ otchestvotxt.Text = "";
|
|
|
+ telephonetxt.Text = "";
|
|
|
+ passporttxt.Text = "";
|
|
|
+ showgrid();
|
|
|
+ MessageBox.Show("Клиент добавлен!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ con.Close();
|
|
|
+ MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Update_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ if (idclienttxt.Text == "")
|
|
|
+ {
|
|
|
+ MessageBox.Show("Поле не выбрано! Выберите нужное поле!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ }
|
|
|
+ else if (familiatxt.Text == "" || nametxt.Text == "" || otchestvotxt.Text == "" || telephonetxt.Text == "" || passporttxt.Text == "")
|
|
|
+ {
|
|
|
+ MessageBox.Show("Заполните все поля!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ }
|
|
|
+ else if (passporttxt.Text.Length < 10 || telephonetxt.Text.Length < 11)
|
|
|
+ {
|
|
|
+ MessageBox.Show("Поля не полностью заполены!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ con.Open();
|
|
|
+ string sql = "Update Client set LastName_Client ='" + familiatxt.Text + "', FirstName_Client = '" + nametxt.Text + "', MiddleName_Client = '" + otchestvotxt.Text + "', Telephone_Client = '" + telephonetxt.Text + "', Passport = '" + passporttxt.Text + "' where ID_Client = '" + idclienttxt.Text + "'";
|
|
|
+ SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, con);
|
|
|
+ dataAdapter.SelectCommand.ExecuteNonQuery();
|
|
|
+ con.Close();
|
|
|
+ idclienttxt.Text = "";
|
|
|
+ nametxt.Text = "";
|
|
|
+ familiatxt.Text = "";
|
|
|
+ otchestvotxt.Text = "";
|
|
|
+ telephonetxt.Text = "";
|
|
|
+ passporttxt.Text = "";
|
|
|
+ showgrid();
|
|
|
+ MessageBox.Show("Клиент изменен!", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ con.Close();
|
|
|
+ MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Delete_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ if (idclienttxt.Text == "")
|
|
|
+ {
|
|
|
+ MessageBox.Show("Поле не выбрано! Выберите нужное поле!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ con.Open();
|
|
|
+ string sql = "DELETE FROM Client WHERE ID_Client = '" + idclienttxt.Text + "'";
|
|
|
+ SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, con);
|
|
|
+ dataAdapter.SelectCommand.ExecuteNonQuery();
|
|
|
+ con.Close();
|
|
|
+ idclienttxt.Text = "";
|
|
|
+ nametxt.Text = "";
|
|
|
+ familiatxt.Text = "";
|
|
|
+ otchestvotxt.Text = "";
|
|
|
+ telephonetxt.Text = "";
|
|
|
+ passporttxt.Text = "";
|
|
|
+ showgrid();
|
|
|
+ MessageBox.Show("Клиент удален!", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ con.Close();
|
|
|
+ MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void showgrid()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ con.Open();
|
|
|
+ string sql = "SELECT ID_Client, LastName_Client, FirstName_Client, MiddleName_Client, Telephone_Client, Passport From Client";
|
|
|
+ SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, con);
|
|
|
+ DataTable data = new DataTable("Client");
|
|
|
+ dataAdapter.Fill(data);
|
|
|
+ dataclient.ItemsSource = data.DefaultView;
|
|
|
+ dataAdapter.Update(data);
|
|
|
+ con.Close();
|
|
|
+ dataclient.Columns[0].Header = "ID";
|
|
|
+ dataclient.Columns[1].Header = "Фамилия";
|
|
|
+ dataclient.Columns[2].Header = "Имя";
|
|
|
+ dataclient.Columns[3].Header = "Отчество";
|
|
|
+ dataclient.Columns[4].Header = "Телефон";
|
|
|
+ dataclient.Columns[5].Header = "Паспорт";
|
|
|
+ dataclient.Columns[0].Visibility = Visibility.Collapsed;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ con.Close();
|
|
|
+ MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Grid_Loaded(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ showgrid();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void dataclient_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ DataGrid gd = (DataGrid)sender;
|
|
|
+ DataRowView rowView = gd.SelectedItem as DataRowView;
|
|
|
+ if (rowView != null)
|
|
|
+ {
|
|
|
+ idclienttxt.Text = rowView["ID_Client"].ToString();
|
|
|
+ familiatxt.Text = rowView["LastName_Client"].ToString();
|
|
|
+ nametxt.Text = rowView["FirstName_Client"].ToString();
|
|
|
+ otchestvotxt.Text = rowView["MiddleName_Client"].ToString();
|
|
|
+ telephonetxt.Text = rowView["Telephone_Client"].ToString();
|
|
|
+ passporttxt.Text = rowView["Passport"].ToString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Refresh_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ idclienttxt.Text = "";
|
|
|
+ nametxt.Text = "";
|
|
|
+ familiatxt.Text = "";
|
|
|
+ otchestvotxt.Text = "";
|
|
|
+ telephonetxt.Text = "";
|
|
|
+ passporttxt.Text = "";
|
|
|
+ showgrid();
|
|
|
+ }
|
|
|
}
|
|
|
}
|