Programm_Wirl/AA-Forms/FormEinstellung.cs

248 lines
9.7 KiB
C#

using Deckungsbeitrag.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Deckungsbeitrag
{
public partial class FormEinstellung : Form
{
private readonly UserSettingsManager _settings = new UserSettingsManager();
string varkosten = ConfigurationManager.AppSettings["Variabel"];
string fixlohnkosten = ConfigurationManager.AppSettings["FixLohn"];
string fixmietkosten = ConfigurationManager.AppSettings["FixMiete"];
public bool changed = false;
public bool validating = true;
public FormEinstellung()
{
InitializeComponent();
}
public FormEinstellung(object x) : this()
{
if (x.GetType() == typeof(String))
{
if (x.ToString() == "Sortiment") { ButtonPfad_Click(buttonSortiment, null); this.textBoxSortiment.BackColor = Color.Red; }
}
else
{
if (x.GetType() == typeof(FormExpedit))
{
foreach(Control ctr in this.Controls)
{
if (ctr.Name.Contains("Drucker") || ctr.Name.Contains("Speichern") || ctr.Name.Contains("Abbrechen")) ctr.Enabled = true;
else ctr.Enabled = false;
}
}
}
}
private void FormEinstellung_Load(object sender, EventArgs e)
{
// Standard Drucker und Kopieanzahl einstellen.
foreach (string printer in PrinterSettings.InstalledPrinters)
{
this.comboBoxEtikettDrucker.Items.Add(printer);
this.comboBoxSWSDrucker.Items.Add(printer);
}
_settings.Load();
this.comboBoxEtikettDrucker.SelectedText = _settings.DruckerEtikett;
this.comboBoxSWSDrucker.SelectedText = _settings.DruckerSWS;
this.numericUpDownSWSKopien.Value = _settings.CopiesSWS;
Load_Settings();
}
private void Load_Settings()
{
//TODO: Settings hier ändern auf UserSettingsManager Klasse.
this.checkBoxMaxWert.Checked = Settings.Default.MaxChecked;
this.checkBoxMinWert.Checked = Settings.Default.MinChecked;
this.numUpDownAnzahl.Value = Settings.Default.ZAnzahl;
if (checkBoxMaxWert.Checked) { this.numUpDownMaxWert.Value = (int)Settings.Default.RatMax; this.numUpDownMaxWert.Enabled = true; }
if (checkBoxMinWert.Checked) { this.numUpDownMinWert.Value = (int)Settings.Default.RatMin; this.numUpDownMinWert.Enabled = true; }
this.textBoxSortiment.Text = ConfigurationManager.AppSettings["SortimentPfad"];
this.textBoxRatingbild.Text = ConfigurationManager.AppSettings["BildPfad"];
foreach (Button btn in this.groupBoxFarben.Controls.OfType<Button>())
{
if ((Color)Settings.Default[btn.Name.Substring(6)] == Color.Empty) btn.FlatAppearance.BorderColor = DefaultBackColor;
else
{
btn.FlatAppearance.BorderColor = (Color)Settings.Default[btn.Name.Substring(6)];
}
}
}
private void Save_Settings()
{
if (MessageBox.Show("Möchtest du die Einstellungen speichern?", "Frage", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
else
{
//TODO: Hier Settings speichern mit UserSettingsManager Klasse.
//if (changed)
//{
// Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
// config.AppSettings.Settings.Remove("SortimentPfad");
// config.AppSettings.Settings.Add("SortimentPfad", this.textBoxSortiment.Text);
// config.AppSettings.Settings.Remove("BildPfad");
// config.AppSettings.Settings.Add("BildPfad", this.textBoxRatingbild.Text);
// config.Save();
//}
//if (this.checkBoxMaxWert.Checked) Settings.Default.MaxChecked = this.checkBoxMaxWert.Checked;
//if (this.checkBoxMinWert.Checked) Settings.Default.MinChecked = this.checkBoxMinWert.Checked;
//if (this.numUpDownMinWert.Enabled) Settings.Default.RatMin = (double)this.numUpDownMinWert.Value;
//if (this.numUpDownMaxWert.Enabled) Settings.Default.RatMax = (double)this.numUpDownMaxWert.Value;
if (this.comboBoxEtikettDrucker.SelectedItem != null) _settings.DruckerEtikett = this.comboBoxEtikettDrucker.SelectedItem.ToString();
if (this.comboBoxSWSDrucker.SelectedItem != null) { _settings.DruckerSWS = this.comboBoxSWSDrucker.SelectedItem.ToString(); _settings.CopiesSWS = this.numericUpDownSWSKopien.Value; }
//Settings.Default.ZAnzahl = (int)this.numUpDownAnzahl.Value;
//Settings.Default.Save();
_settings.Save();
}
}
//Bei Click erscheint Speichern-Button und gefüllte TextBox mit Kosten-KontoNr
private void buttonVarKost_Click(object sender, EventArgs e)
{
this.buttonVarSpeichern.Visible = this.textBoxVarKosten.Visible = true;
this.textBoxVarKosten.Text = varkosten;
this.textBoxVarKosten.Size = new Size((Point)TextRenderer.MeasureText(this.textBoxVarKosten.Text + 20, this.textBoxVarKosten.Font));
Resize_Form();
}
private void buttonFixMietKosten_Click(object sender, EventArgs e)
{
this.buttonFixMietSpeichern.Visible = this.textBoxFixMietKosten.Visible = true;
this.textBoxFixMietKosten.Text = fixmietkosten;
this.textBoxFixMietKosten.Size = new Size((Point)TextRenderer.MeasureText(this.textBoxFixMietKosten.Text + 20, this.textBoxFixMietKosten.Font));
Resize_Form();
}
private void buttonFixLohnKosten_Click(object sender, EventArgs e)
{
this.buttonFixLohnSpeichern.Visible = this.textBoxFixLohnKosten.Visible = true;
this.textBoxFixLohnKosten.Text = fixlohnkosten;
this.textBoxFixLohnKosten.Size = new Size((Point)TextRenderer.MeasureText(this.textBoxFixLohnKosten.Text + 20, this.textBoxFixLohnKosten.Font));
Resize_Form();
}
//Bei Click wird der Inhalt der TextBox in App.Config gespeichert
private void buttonVarSpeichern_Click(object sender, EventArgs e)
{
varkosten = this.textBoxVarKosten.Text.Replace(", ", ",");
Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
config.AppSettings.Settings.Remove("Variabel");
config.AppSettings.Settings.Add("Variabel", varkosten);
config.Save();
}
private void buttonFixLohnSpeichern_Click(object sender, EventArgs e)
{
fixlohnkosten = this.textBoxFixLohnKosten.Text.Replace(", ", ",");
Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
config.AppSettings.Settings.Remove("FixLohn");
config.AppSettings.Settings.Add("FixLohn", fixlohnkosten);
config.Save();
}
private void buttonFixMietSpeichern_Click(object sender, EventArgs e)
{
fixmietkosten = this.textBoxFixMietKosten.Text.Replace(", ", ",");
Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
config.AppSettings.Settings.Remove("FixMiete");
config.AppSettings.Settings.Add("FixMiete", fixmietkosten);
config.Save();
}
//Bei Click auf Farb-Button wird Farb-Dialog geöffnet
private void Color_button_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
ColorDialog col = new ColorDialog();
if(col.ShowDialog() == DialogResult.OK) Settings.Default[btn.Name.Substring(6)] = btn.FlatAppearance.BorderColor = col.Color;
}
//Ratingwerte individuell einstellen (Wenn ja dann Checked)
private void checkBoxMinWert_CheckedChanged(object sender, EventArgs e)
{
if (((CheckBox)sender).Checked) { this.numUpDownMinWert.Enabled = Properties.Settings.Default.MinChecked = true; }
else this.numUpDownMinWert.Enabled = Properties.Settings.Default.MinChecked = false;
}
private void checkBoxMaxWert_CheckedChanged(object sender, EventArgs e)
{
if (((CheckBox)sender).Checked) this.numUpDownMaxWert.Enabled = Properties.Settings.Default.MaxChecked = true;
else this.numUpDownMaxWert.Enabled = Properties.Settings.Default.MaxChecked = false;
}
//Buttons und TextBoxen für Pfadänderungen.
private void TextBox_Validating(object sender, CancelEventArgs e)
{
TextBox tb = (TextBox)sender;
if (changed)
{
if (MessageBox.Show($"Möchtest du die Änderungen beibehalten?", "Frage", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) return;
else
{
tb.Focus();
tb.ForeColor = Color.Red;
e.Cancel = true;
}
}
}
private void TextBox_TextChanged(object sender, EventArgs e)
{
changed = true;
}
private void ButtonPfad_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
if (btn.Text == "Sortiment") { this.textBoxSortiment.Visible = true; }
if (btn.Text == "Ratingbild") { this.textBoxRatingbild.Visible = true; }
}
private void textBoxSortiment_Enter(object sender, EventArgs e)
{
TextBox tb = (TextBox)sender;
tb.BackColor = SystemColors.Window;
}
//Aktuell nicht verwendet
private void Resize_Form()
{
}
//Button Speichern und Abbrechen (Speichern leitet zu Save_Settings weiter)
private void buttonSpeichern_Click(object sender, EventArgs e)
{
Save_Settings();
this.DialogResult = DialogResult.OK;
this.Close();
}
private void buttonAbbrechen_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Möchtest du die Änderungen verwerfen?", "Frage", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) this.Close();
else return;
}
}
}