using System; using System.Data.Odbc; using System.IO; using System.Windows; using System.Windows.Input; using GCHR.Mandantenschnittstelle; using GCHR.Model; namespace GCHR.View { public partial class Einstellungen { private GchrConfig _gchrConfig; public Einstellungen() { InitializeComponent(); KonfigurationLaden(); } private void ButtonClick(object sender, RoutedEventArgs e) { Close(); } private void KonfigurationLaden() { if (File.Exists(Constants.ConfigDatei)) { _gchrConfig = GchrConfig.GetInstance(Constants.ConfigDatei); } cbMandant.Text = _gchrConfig.Einstellungen.Mandantenname.ToString(); txtHnr.Text = _gchrConfig.Einstellungen.Haendlernummer; txtHändlerKontenrahmen.Text = _gchrConfig.Einstellungen.Haendlerkontenrahmen.ToString(); txtHerstellerKontenrahmen.Text = _gchrConfig.Einstellungen.Herstellerkontenrahmen.ToString(); txtHauptmarke.Text = _gchrConfig.Einstellungen.Hauptmarke; txtHauptbetrieb.Text = _gchrConfig.Einstellungen.Hauptbetrieb; txtGeschäftsjahr.Text = _gchrConfig.Einstellungen.Geschaeftsjahr; cbAktiviert.IsChecked = _gchrConfig.Einstellungen.Update.IsActive; txtUpdateadresse.Text = Constants.Decrypt(_gchrConfig.Einstellungen.Update.Dateipfad); txtProxyAdresse.Text = Constants.Decrypt(_gchrConfig.Einstellungen.Update.Proxy.Adresse); txtProxyPort.Text = Constants.Decrypt(_gchrConfig.Einstellungen.Update.Proxy.Port); txtProxyBenutzer.Text = Constants.Decrypt(_gchrConfig.Einstellungen.Update.Proxy.Benutzer); txtProxyPasswort.Password = Constants.Decrypt(_gchrConfig.Einstellungen.Update.Proxy.Passwort); txtProxyDomäne.Text = Constants.Decrypt(_gchrConfig.Einstellungen.Update.Proxy.Domaene); txtODBCName.Text = _gchrConfig.Einstellungen.Odbc; txtUser.Text = Constants.Decrypt(_gchrConfig.Einstellungen.OdbcUsername); txtPwd.Password = Constants.Decrypt(_gchrConfig.Einstellungen.OdbcPassword); cbTyp.Text = _gchrConfig.Einstellungen.Steuerungsdateien.Typ; txtPfad.Text = _gchrConfig.Einstellungen.Steuerungsdateien.Pfad; foreach (var eintrag in _gchrConfig.Einstellungen.DepartmentUebersetzung) { lbÜbersetzungen.Items.Add(eintrag.Von + ": " + eintrag.Nach); } /* IEnumerable Verrechnungsktos = Einstellungen.Element("Verrechnungskonten").Elements("Konto"); foreach (XElement element in Verrechnungsktos) { lbÜbersetzungen2.Items.Add(element.Attribute("von").Value + ": " + element.Attribute("nach").Value); } */ } private void ButtonClick1(object sender, RoutedEventArgs e) { _gchrConfig.Einstellungen.Mandantenname = (Mandanten)Enum.Parse(typeof(Mandanten), cbMandant.Text); _gchrConfig.Einstellungen.Haendlernummer = txtHnr.Text; _gchrConfig.Einstellungen.Haendlerkontenrahmen = Int32.Parse(txtHändlerKontenrahmen.Text); _gchrConfig.Einstellungen.Herstellerkontenrahmen = Int32.Parse(txtHerstellerKontenrahmen.Text); _gchrConfig.Einstellungen.Hauptmarke = txtHauptmarke.Text; _gchrConfig.Einstellungen.Hauptbetrieb = txtHauptbetrieb.Text; _gchrConfig.Einstellungen.Geschaeftsjahr = txtGeschäftsjahr.Text; if (cbAktiviert.IsChecked != null) _gchrConfig.Einstellungen.Update.IsActive = (bool)cbAktiviert.IsChecked; _gchrConfig.Einstellungen.Update.Dateipfad = Constants.Encrypt(txtUpdateadresse.Text); _gchrConfig.Einstellungen.Update.Proxy.Adresse = Constants.Encrypt(txtProxyAdresse.Text); _gchrConfig.Einstellungen.Update.Proxy.Port = Constants.Encrypt(txtProxyPort.Text); _gchrConfig.Einstellungen.Update.Proxy.Benutzer = Constants.Encrypt(txtProxyBenutzer.Text); _gchrConfig.Einstellungen.Update.Proxy.Passwort = Constants.Encrypt(txtProxyPasswort.Password); _gchrConfig.Einstellungen.Update.Proxy.Domaene = Constants.Encrypt(txtProxyDomäne.Text); _gchrConfig.Einstellungen.Odbc = txtODBCName.Text; _gchrConfig.Einstellungen.OdbcUsername = Constants.Encrypt(txtUser.Text); _gchrConfig.Einstellungen.OdbcPassword = Constants.Encrypt(txtPwd.Password); _gchrConfig.Einstellungen.Steuerungsdateien.Typ = cbTyp.Text; _gchrConfig.Einstellungen.Steuerungsdateien.Pfad = txtPfad.Text; _gchrConfig.Einstellungen.DepartmentUebersetzung.Clear(); foreach (var eintrag in lbÜbersetzungen.Items) { var split = eintrag.ToString().Split(':'); _gchrConfig.Einstellungen.DepartmentUebersetzung.Add(new UebersetzungXml() { Von = split[0].Trim(), Nach = split[1].Trim() }); } _gchrConfig.Save(); Close(); } private void ButtonClick2(object sender, RoutedEventArgs e) { lbÜbersetzungen.Items.Add(txtVon.Text + ": " + txtNach.Text); txtVon.Clear(); txtNach.Clear(); txtVon.Focus(); } private void TxtVonGotFocus(object sender, RoutedEventArgs e) { txtVon.SelectAll(); } private void TxtNachGotFocus(object sender, RoutedEventArgs e) { txtNach.SelectAll(); } private void TxtVonKeyDown(object sender, KeyEventArgs e) { if (e.Key != Key.Return) return; if (!txtVon.Text.Trim().Equals("")) txtNach.Focus(); else { MessageBox.Show("Das \"Von\"-Feld darf nicht leer sein.", "Hinweis", MessageBoxButton.OK, MessageBoxImage.Information); } } private void TxtNachKeyDown(object sender, KeyEventArgs e) { if (e.Key != Key.Return || e.IsRepeat) return; if (!txtNach.Text.Trim().Equals("")) if (!txtVon.Text.Trim().Equals("")) ButtonClick2(sender, e); else { MessageBox.Show("Das \"Von\"-Feld darf nicht leer sein.", "Hinweis", MessageBoxButton.OK, MessageBoxImage.Information); txtVon.Focus(); } else { MessageBox.Show("Das \"Nach\"-Feld darf nicht leer sein.", "Hinweis", MessageBoxButton.OK, MessageBoxImage.Information); } } private void ButMinusClick(object sender, RoutedEventArgs e) { if (lbÜbersetzungen.SelectedIndex > -1) { lbÜbersetzungen.Items.RemoveAt(lbÜbersetzungen.SelectedIndex); } } private void ButtonClick3(object sender, RoutedEventArgs e) { if (_gchrConfig.Konten != null) _gchrConfig.Konten.Clear(); } private void TxtVon2KeyDown(object sender, KeyEventArgs e) { /* if (e.Key == Key.Return) if (!txtVon2.Text.Trim().Equals("")) txtNach2.Focus(); else { MessageBox.Show("Das \"Von\"-Feld darf nicht leer sein.", "Hinweis", MessageBoxButton.OK, MessageBoxImage.Information); } */ } private void TxtNach2KeyDown(object sender, KeyEventArgs e) { /* if (e.Key == Key.Return && !e.IsRepeat) if (!txtNach2.Text.Trim().Equals("")) if (!txtVon2.Text.Trim().Equals("")) butPlus2_Click(sender, e); else { MessageBox.Show("Das \"Von\"-Feld darf nicht leer sein.", "Hinweis", MessageBoxButton.OK, MessageBoxImage.Information); txtVon.Focus(); } else { MessageBox.Show("Das \"Nach\"-Feld darf nicht leer sein.", "Hinweis", MessageBoxButton.OK, MessageBoxImage.Information); } */ } private void ButPlus2Click(object sender, RoutedEventArgs e) { /* lbÜbersetzungen2.Items.Add(txtVon2.Text + ": " + txtNach2.Text); txtVon2.Clear(); txtNach2.Clear(); txtVon2.Focus(); */ } private void ButMinus2Click(object sender, RoutedEventArgs e) { /* if (lbÜbersetzungen2.SelectedIndex > -1) { lbÜbersetzungen2.Items.RemoveAt(lbÜbersetzungen2.SelectedIndex); } */ } private void BtnOdbcVerbindungTestenClick(object sender, RoutedEventArgs e) { try { var con = new OdbcConnection(OdbcConnectionString()); con.Open(); con.Close(); MessageBox.Show("Verbindung erfolgreich."); } catch (Exception exc) { MessageBox.Show("Verbindung fehlgeschlagen.\nDetails:\n" + exc.Message); } } private string OdbcConnectionString() { return (string.Format("DSN={0};UID={1};PWD={2};", txtODBCName.Text, txtUser.Text, txtPwd.Password)); } } }