/// <summary> /// Handles the Click event of the buttonSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> private void buttonSave_Click(object sender, RoutedEventArgs e) { if (Ticket != null) { textBoxCode.GetBindingExpression(TextBox.TextProperty).UpdateSource(); textBoxName.GetBindingExpression(TextBox.TextProperty).UpdateSource(); textBoxStreet.GetBindingExpression(TextBox.TextProperty).UpdateSource(); textBoxZip.GetBindingExpression(TextBox.TextProperty).UpdateSource(); textBoxCity.GetBindingExpression(TextBox.TextProperty).UpdateSource(); textBoxPhone.GetBindingExpression(TextBox.TextProperty).UpdateSource(); textBoxMail.GetBindingExpression(TextBox.TextProperty).UpdateSource(); Ticket.IsRedeemed = checkBoxRedeemed.IsChecked.Value; Ticket.IsOnlineTicket = checkBoxOnline.IsChecked.Value; Ticket.Type = (TicketType)comboBoxType.SelectedItem; DateTime result; Ticket.RedeemDate = textBoxRedeemDate.Text.Length < 8 ? (DateTime?)null : (DateTime.TryParse(textBoxRedeemDate.Text, out result) ? result : new DateTime()); Ticket.Save(); } else { ImportTicket ticket = new ImportTicket(); ticket.IsOnlineTicket = checkBoxOnline.IsChecked.Value; ticket.Type = comboBoxType.SelectedItem == null ? TicketType.Normal : (TicketType)comboBoxType.SelectedItem; ticket.Code = textBoxCode.Text; ticket.Name = textBoxName.Text; ticket.Street = textBoxStreet.Text; ticket.Zip = textBoxZip.Text; ticket.City = textBoxCity.Text; ticket.Phone = textBoxPhone.Text; ticket.EMail = textBoxMail.Text; ticket.IsRedeemed = checkBoxRedeemed.IsChecked.Value; DateTime result; ticket.RedeemDate = textBoxRedeemDate.Text.Length < 8 ? (DateTime?)null : (DateTime.TryParse(textBoxRedeemDate.Text, out result) ? result : new DateTime()); OnTicketCreated(new TicketEventArgs(ticket)); } }
/// <summary> /// Handles the Click event of the buttonImport control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> private void buttonImport_Click(object sender, RoutedEventArgs e) { string file = textBoxFile.Text; bool hasHeader = checkBoxHeader.IsChecked.HasValue && checkBoxHeader.IsChecked.Value; string separator = comboBoxSeparator.Text; Thread importThread = new Thread(new ThreadStart(delegate() { Dispatcher.Invoke((Action) delegate() { textBlockStatus.Text = Properties.Import.ImportStatusReadingFile; progressBarStatus.Value = 0; progressBarStatus.Visibility = System.Windows.Visibility.Visible; busyIndicator.IsBusy = true; }); List <string> lines; using (TextReader reader = File.OpenText(file)) { if (hasHeader) { reader.ReadLine(); } string content = reader.ReadToEnd(); lines = new List <string>(content.Split(new string[] { content.Contains("\r\n") ? "\r\n" : "\n" }, StringSplitOptions.RemoveEmptyEntries)); reader.Close(); } int i = 0; foreach (string row in lines) { Dispatcher.Invoke((Action) delegate() { textBlockStatus.Text = String.Format(Properties.Import.ImportStatusImporting, ++i, lines.Count); progressBarStatus.Value = (i * 100.0) / lines.Count; }); List <string> rowValues = SplitLine(row, separator); ImportTicket ticket = new ImportTicket(); Dispatcher.Invoke((Action) delegate() { ticket.IsOnlineTicket = (comboBoxTicketMode.SelectedItem as IsOnlineComboBoxItem).IsOnlineTicket; ticket.Type = (comboBoxTicketType.SelectedItem as TicketTypeComboBoxItem).TicketType; ticket.Code = comboBoxCodeColumn.Text.Length > 0 && rowValues.Count > comboBoxCodeColumn.SelectedIndex ? rowValues[comboBoxCodeColumn.SelectedIndex] : null; ticket.Name = comboBoxNameColumn.Text.Length > 0 && rowValues.Count > comboBoxNameColumn.SelectedIndex ? rowValues[comboBoxNameColumn.SelectedIndex] : null; ticket.Street = comboBoxStreetColumn.Text.Length > 0 && rowValues.Count > comboBoxStreetColumn.SelectedIndex ? rowValues[comboBoxStreetColumn.SelectedIndex] : null; ticket.Zip = comboBoxZipColumn.Text.Length > 0 && rowValues.Count > comboBoxZipColumn.SelectedIndex ? rowValues[comboBoxZipColumn.SelectedIndex] : null; ticket.City = comboBoxCityColumn.Text.Length > 0 && rowValues.Count > comboBoxCityColumn.SelectedIndex ? rowValues[comboBoxCityColumn.SelectedIndex] : null; ticket.Phone = comboBoxPhoneColumn.Text.Length > 0 && rowValues.Count > comboBoxPhoneColumn.SelectedIndex ? rowValues[comboBoxPhoneColumn.SelectedIndex] : null; ticket.EMail = comboBoxMailColumn.Text.Length > 0 && rowValues.Count > comboBoxMailColumn.SelectedIndex ? rowValues[comboBoxMailColumn.SelectedIndex] : null; }); TicketSource.AddTicket(ticket, Dispatcher); } Dispatcher.Invoke((Action) delegate() { textBlockStatus.Text = Properties.Import.ImportStatusReady; progressBarStatus.Visibility = System.Windows.Visibility.Hidden; busyIndicator.IsBusy = false; }); })); importThread.Start(); }