Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.Navigation;
- using System.Windows.Shapes;
- using System.Data;
- using MySql.Data;
- using MySql.Data.MySqlClient;
- namespace Apkainz
- {
- /// <summary>q
- /// Logika interakcji dla klasy MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public enum Cases { placeType, place };
- DataTable dtT = new DataTable("Type");
- DataTable dtPl = new DataTable("Place");
- DataTable dtG = new DataTable("Guest");
- DataTable dtR = new DataTable("Reservation");
- DataTable dtPa = new DataTable("Payment");
- public MainWindow()
- {
- InitializeComponent();
- }
- private void Grid_Loaded(object sender, RoutedEventArgs e)
- {
- MySqlDataAdapter daType;
- MySqlDataAdapter daPlace;
- MySqlDataAdapter daGuest;
- MySqlDataAdapter daReservation;
- MySqlDataAdapter daPayment;
- //DataSet dsType;
- string connStr = "server=localhost;user=wujja;database=dblease;port=3306;password=!Haslouser654";
- MySqlConnection conn = new MySqlConnection(connStr);
- try
- {
- //MessageBox.Show("Connecting to MySQL...");
- conn.Open();
- string sqlType = "SELECT * FROM placetype";
- string sqlPlace = "Select * FROM place";
- string sqlGuest = "Select * FROM guest";
- string sqlReservation = "Select * FROM reservation";
- string sqlPayment = "Select * FROM payment";
- daType = new MySqlDataAdapter(sqlType, conn);
- daPlace = new MySqlDataAdapter(sqlPlace, conn);
- daGuest = new MySqlDataAdapter(sqlGuest, conn);
- daReservation = new MySqlDataAdapter(sqlReservation, conn);
- daPayment = new MySqlDataAdapter(sqlPayment, conn);
- MySqlCommandBuilder cbT = new MySqlCommandBuilder(daType);
- MySqlCommandBuilder cbPl = new MySqlCommandBuilder(daPlace);
- MySqlCommandBuilder cbG = new MySqlCommandBuilder(daGuest);
- MySqlCommandBuilder cbR = new MySqlCommandBuilder(daReservation);
- MySqlCommandBuilder cbPa = new MySqlCommandBuilder(daPayment);
- //dsType = new DataSet();
- daType.Fill(dtT);
- daPlace.Fill(dtPl);
- daGuest.Fill(dtG);
- daReservation.Fill(dtR);
- daPayment.Fill(dtPa);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- conn.Close();
- //MessageBox.Show("Done.");
- /* for (int i = 0; i < (Convert.ToInt32(dtT.Rows.Count)); i++)
- {
- typeOfPlaceDescriptionValue.Items.Add(dtT.Rows[1]);
- }*/
- /*foreach (DataRow drCurrent in dtT.Rows)
- {
- typeOfPlaceDescriptionValue.Items.Add(drCurrent[1]);
- }*/
- ValueOfComboBox(typeOfPlaceDescriptionValue);
- ValueOfComboBox(reservationGuestValue);
- DateToShow(reservationDateFromValue, 0);
- DateToShow(reservationDateToValue, 1);
- }
- private void Button_showType_Click(object sender, RoutedEventArgs e)
- {
- McDataGrid.ItemsSource = dtT.DefaultView;
- }
- private void Button_showPlace_Click(object sender, RoutedEventArgs e)
- {
- McDataGrid.ItemsSource = dtPl.DefaultView;
- }
- private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- string text = ((sender as ComboBox).SelectedItem as ComboBoxItem).Content as string;
- if (text == "Type")
- {
- addDataPlaceType.Visibility = Visibility.Visible;
- }
- else
- {
- addDataPlaceType.Visibility = Visibility.Hidden;
- }
- if (text == "Place")
- {
- addDataPlace.Visibility = Visibility.Visible;
- }
- else
- {
- addDataPlace.Visibility = Visibility.Hidden;
- }
- if (text == "Guest")
- {
- addDataGuest.Visibility = Visibility.Visible;
- }
- else
- {
- addDataGuest.Visibility = Visibility.Hidden;
- }
- if (text == "Reservation")
- {
- addDataReservation.Visibility = Visibility.Visible;
- }
- else
- {
- addDataReservation.Visibility = Visibility.Hidden;
- }
- if (text == "Payment")
- {
- addDataPayment.Visibility = Visibility.Visible;
- }
- else
- {
- addDataPayment.Visibility = Visibility.Hidden;
- }
- }
- private List<string> ForEachLoop(DataTable datatable, string nameOfRow)
- {
- List<string> strings = new List<string>();
- foreach (DataRow drCurrent in datatable.Rows)
- {
- strings.Add(drCurrent[nameOfRow].ToString());
- }
- return strings;
- }
- private void ValueOfComboBox(object sender)
- {
- List<string> strings1;
- List<string> strings2;
- List<string> strings3;
- string nameOfComboBox = (sender as ComboBox).Name;
- int count = 0;
- switch (nameOfComboBox)
- {
- case "typeOfPlaceDescriptionValue":
- strings1 = ForEachLoop(dtT, "description");
- count = dtT.Rows.Count;
- for (int i = 0; i < count; i++)
- {
- (sender as ComboBox).Items.Add(strings1[i]);
- }
- break;
- case "reservationGuestValue":
- strings1 = ForEachLoop(dtG, "firstName");
- strings2 = ForEachLoop(dtG, "lastName");
- count = dtG.Rows.Count;
- for (int i = 0; i < count; i++)
- {
- (sender as ComboBox).Items.Add(strings1[i] + " " + strings2[i]);
- }
- break;
- case "reservationPlaceValue":
- strings1 = ForEachLoop(dtPl, "description");
- count = dtPl.Rows.Count;
- List<int> sameId;
- for (int i = 0; i < count; i++)
- {
- }
- break;
- case "paymentWhichReservationValue":
- break;
- default:
- MessageBox.Show("Coś się popsuło i nie było mnie słychać");
- break;
- }
- }
- private void DateToShow(object sender, int howManyDays)
- {
- (sender as DatePicker).DisplayDateStart = DateTime.Today.AddDays(howManyDays);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement