ClientRoom.xaml.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Shapes;
  14. using System.Windows.Threading;
  15. using System.Data;
  16. using System.Data.SqlClient;
  17. namespace HotelCalifornia
  18. {
  19. /// <summary>
  20. /// Логика взаимодействия для ClientRoom.xaml
  21. /// </summary>
  22. public partial class ClientRoom : Window
  23. {
  24. public ClientRoom()
  25. {
  26. InitializeComponent();
  27. DispatcherTimer timer = new DispatcherTimer();
  28. timer.Tick += new EventHandler(Update_Timer_Tick);
  29. timer.Interval = new TimeSpan(0, 0, 1);
  30. timer.Start();
  31. }
  32. SqlConnection con = new SqlConnection("Data Source=localhost;Initial Catalog=kursah;Integrated Security=True");
  33. private void Update_Timer_Tick(object sender, EventArgs e)
  34. {
  35. timetxt.Text = DateTime.Now.ToString();
  36. }
  37. private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
  38. {
  39. DragMove();
  40. }
  41. private void Close(object sender, RoutedEventArgs e)
  42. {
  43. Application.Current.Shutdown();
  44. }
  45. private void WindMin_Click(object sender, RoutedEventArgs e)
  46. {
  47. this.WindowState = WindowState.Minimized;
  48. }
  49. private void Back(object sender, RoutedEventArgs e)
  50. {
  51. MessageBoxResult result = MessageBox.Show("Вы хотите вернуться к предыдущему окну?", "Предупреждение", MessageBoxButton.YesNo, MessageBoxImage.Question);
  52. switch (result)
  53. {
  54. case MessageBoxResult.Yes:
  55. Variant variant = new Variant();
  56. this.Close();
  57. variant.Show();
  58. break;
  59. case MessageBoxResult.No:
  60. break;
  61. }
  62. }
  63. private void dataClientRoom_SelectionChanged(object sender, SelectionChangedEventArgs e)
  64. {
  65. }
  66. private void Add_Click(object sender, RoutedEventArgs e)
  67. {
  68. }
  69. private void Update_Click(object sender, RoutedEventArgs e)
  70. {
  71. }
  72. private void Delete_Click(object sender, RoutedEventArgs e)
  73. {
  74. }
  75. private void Window_Loaded(object sender, RoutedEventArgs e)
  76. {
  77. fillroomcombo();
  78. }
  79. void fillroomcombo()
  80. {
  81. try
  82. {
  83. roomcombo.Items.Clear();
  84. con.Open();
  85. SqlCommand sql = con.CreateCommand();
  86. sql.CommandType = CommandType.Text;
  87. sql.CommandText = "Select Number_Room from Room";
  88. sql.ExecuteNonQuery();
  89. DataTable dt = new DataTable();
  90. SqlDataAdapter da = new SqlDataAdapter(sql);
  91. da.Fill(dt);
  92. foreach (DataRow dr in dt.Rows)
  93. {
  94. roomcombo.Items.Add(dr["Number_Room"].ToString());
  95. }
  96. con.Close();
  97. }
  98. catch (Exception ex)
  99. {
  100. con.Close();
  101. MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
  102. }
  103. }
  104. }
  105. }