Advertisement
Guest User

Untitled

a guest
Apr 5th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.49 KB | None | 0 0
  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.Navigation;
  14. using System.Windows.Shapes;
  15. using System.Data;
  16. using MySql.Data;
  17. using MySql.Data.MySqlClient;
  18.  
  19. namespace Apkainz
  20. {
  21.     /// <summary>q
  22.     /// Logika interakcji dla klasy MainWindow.xaml
  23.     /// </summary>
  24.     public partial class MainWindow : Window
  25.     {
  26.         public enum Cases { placeType, place };
  27.         DataTable dtT = new DataTable("Type");
  28.         DataTable dtPl = new DataTable("Place");
  29.         DataTable dtG = new DataTable("Guest");
  30.         DataTable dtR = new DataTable("Reservation");
  31.         DataTable dtPa = new DataTable("Payment");
  32.  
  33.         public MainWindow()
  34.         {
  35.             InitializeComponent();
  36.         }
  37.  
  38.         private void Grid_Loaded(object sender, RoutedEventArgs e)
  39.         {
  40.             MySqlDataAdapter daType;
  41.             MySqlDataAdapter daPlace;
  42.             MySqlDataAdapter daGuest;
  43.             MySqlDataAdapter daReservation;
  44.             MySqlDataAdapter daPayment;
  45.  
  46.             //DataSet dsType;
  47.  
  48.             string connStr = "server=localhost;user=wujja;database=dblease;port=3306;password=!Haslouser654";
  49.             MySqlConnection conn = new MySqlConnection(connStr);
  50.             try
  51.             {
  52.                 //MessageBox.Show("Connecting to MySQL...");
  53.                 conn.Open();
  54.  
  55.                 string sqlType = "SELECT * FROM placetype";
  56.                 string sqlPlace = "Select * FROM place";
  57.                 string sqlGuest = "Select * FROM guest";
  58.                 string sqlReservation = "Select * FROM reservation";
  59.                 string sqlPayment = "Select * FROM payment";
  60.                 daType = new MySqlDataAdapter(sqlType, conn);
  61.                 daPlace = new MySqlDataAdapter(sqlPlace, conn);
  62.                 daGuest = new MySqlDataAdapter(sqlGuest, conn);
  63.                 daReservation = new MySqlDataAdapter(sqlReservation, conn);
  64.                 daPayment = new MySqlDataAdapter(sqlPayment, conn);
  65.                 MySqlCommandBuilder cbT = new MySqlCommandBuilder(daType);
  66.                 MySqlCommandBuilder cbPl = new MySqlCommandBuilder(daPlace);
  67.                 MySqlCommandBuilder cbG = new MySqlCommandBuilder(daGuest);
  68.                 MySqlCommandBuilder cbR = new MySqlCommandBuilder(daReservation);
  69.                 MySqlCommandBuilder cbPa = new MySqlCommandBuilder(daPayment);
  70.                 //dsType = new DataSet();
  71.  
  72.                 daType.Fill(dtT);
  73.                 daPlace.Fill(dtPl);
  74.                 daGuest.Fill(dtG);
  75.                 daReservation.Fill(dtR);
  76.                 daPayment.Fill(dtPa);
  77.             }
  78.             catch (Exception ex)
  79.             {
  80.                 MessageBox.Show(ex.ToString());
  81.             }
  82.  
  83.             conn.Close();
  84.             //MessageBox.Show("Done.");
  85.  
  86.             /* for (int i = 0; i < (Convert.ToInt32(dtT.Rows.Count)); i++)
  87.              {
  88.                  typeOfPlaceDescriptionValue.Items.Add(dtT.Rows[1]);
  89.              }*/
  90.             /*foreach (DataRow drCurrent in dtT.Rows)
  91.             {
  92.                 typeOfPlaceDescriptionValue.Items.Add(drCurrent[1]);
  93.             }*/
  94.             ValueOfComboBox(typeOfPlaceDescriptionValue);
  95.             ValueOfComboBox(reservationGuestValue);
  96.             DateToShow(reservationDateFromValue, 0);
  97.             DateToShow(reservationDateToValue, 1);
  98.         }
  99.  
  100.         private void Button_showType_Click(object sender, RoutedEventArgs e)
  101.         {
  102.             McDataGrid.ItemsSource = dtT.DefaultView;
  103.         }
  104.  
  105.         private void Button_showPlace_Click(object sender, RoutedEventArgs e)
  106.         {
  107.             McDataGrid.ItemsSource = dtPl.DefaultView;
  108.         }
  109.  
  110.         private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  111.         {
  112.             string text = ((sender as ComboBox).SelectedItem as ComboBoxItem).Content as string;
  113.             if (text == "Type")
  114.             {
  115.                 addDataPlaceType.Visibility = Visibility.Visible;
  116.             }
  117.             else
  118.             {
  119.                 addDataPlaceType.Visibility = Visibility.Hidden;
  120.             }
  121.             if (text == "Place")
  122.             {
  123.                 addDataPlace.Visibility = Visibility.Visible;
  124.             }
  125.             else
  126.             {
  127.                 addDataPlace.Visibility = Visibility.Hidden;
  128.             }
  129.             if (text == "Guest")
  130.             {
  131.                 addDataGuest.Visibility = Visibility.Visible;
  132.             }
  133.             else
  134.             {
  135.                 addDataGuest.Visibility = Visibility.Hidden;
  136.             }
  137.             if (text == "Reservation")
  138.             {
  139.                 addDataReservation.Visibility = Visibility.Visible;
  140.             }
  141.             else
  142.             {
  143.                 addDataReservation.Visibility = Visibility.Hidden;
  144.             }
  145.             if (text == "Payment")
  146.             {
  147.                 addDataPayment.Visibility = Visibility.Visible;
  148.             }
  149.             else
  150.             {
  151.                 addDataPayment.Visibility = Visibility.Hidden;
  152.             }
  153.         }
  154.  
  155.         private List<string> ForEachLoop(DataTable datatable, string nameOfRow)
  156.         {
  157.             List<string> strings = new List<string>();
  158.             foreach (DataRow drCurrent in datatable.Rows)
  159.             {
  160.                 strings.Add(drCurrent[nameOfRow].ToString());
  161.             }
  162.             return strings;
  163.         }
  164.  
  165.         private void ValueOfComboBox(object sender)
  166.         {
  167.  
  168.             List<string> strings1;
  169.             List<string> strings2;
  170.             List<string> strings3;
  171.             string nameOfComboBox = (sender as ComboBox).Name;
  172.             int count = 0;
  173.  
  174.             switch (nameOfComboBox)
  175.             {
  176.                 case "typeOfPlaceDescriptionValue":
  177.                     strings1 = ForEachLoop(dtT, "description");
  178.                     count = dtT.Rows.Count;
  179.                     for (int i = 0; i < count; i++)
  180.                     {
  181.                         (sender as ComboBox).Items.Add(strings1[i]);
  182.                     }
  183.                     break;
  184.  
  185.                 case "reservationGuestValue":
  186.                     strings1 = ForEachLoop(dtG, "firstName");
  187.                     strings2 = ForEachLoop(dtG, "lastName");
  188.                     count = dtG.Rows.Count;
  189.                     for (int i = 0; i < count; i++)
  190.                     {
  191.                         (sender as ComboBox).Items.Add(strings1[i] + " " + strings2[i]);
  192.                     }
  193.                     break;
  194.  
  195.                 case "reservationPlaceValue":
  196.                     strings1 = ForEachLoop(dtPl, "description");
  197.                     count = dtPl.Rows.Count;
  198.                     List<int> sameId;
  199.                     for (int i = 0; i < count; i++)
  200.                     {
  201.  
  202.                     }
  203.                     break;
  204.                 case "paymentWhichReservationValue":
  205.  
  206.                     break;
  207.                 default:
  208.                     MessageBox.Show("Coś się popsuło i nie było mnie słychać");
  209.                     break;
  210.             }
  211.  
  212.         }
  213.  
  214.         private void DateToShow(object sender, int howManyDays)
  215.         {
  216.             (sender as DatePicker).DisplayDateStart = DateTime.Today.AddDays(howManyDays);
  217.         }
  218.     }
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement