274 lines
8.0 KiB
C#
274 lines
8.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using VirtualKeyboard;
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
using DatenDB;
|
|
using Deckungsbeitrag.AA_Forms;
|
|
|
|
namespace Deckungsbeitrag
|
|
{
|
|
public partial class FormGeschaeftMain : Form
|
|
{
|
|
private string kundetyp = "Bestandskunde";
|
|
private QwertzKeyboard keyboard;
|
|
private Screen screen = Screen.PrimaryScreen;
|
|
private Kunde kunde;
|
|
|
|
private bool _keyboardVisible;
|
|
public bool KeyBoardVisible
|
|
{
|
|
get { return _keyboardVisible; }
|
|
set
|
|
{
|
|
_keyboardVisible = value;
|
|
if (KeyBoardVisible)
|
|
{
|
|
this.Width = screen.WorkingArea.Width;
|
|
this.Height = (int)(screen.WorkingArea.Height * 0.55);
|
|
this.Location = new Point(0, 0);
|
|
this.ScrollControlIntoView(this.ActiveControl);
|
|
}
|
|
else
|
|
{
|
|
this.Width = screen.WorkingArea.Width;
|
|
this.Height = screen.WorkingArea.Height;
|
|
this.Location = new Point(0, 0);
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
public FormGeschaeftMain()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void FormGeschaeftMain_Load(object sender, EventArgs e)
|
|
{
|
|
this.buttonEdit.Visible = false;
|
|
|
|
this.dTPAbholtag.Value = DateTime.Today.AddDays(2);
|
|
this.dTPAbholtag.Checked = false;
|
|
|
|
StartKndAuswahl();
|
|
|
|
RadioButtonsKunde_CheckedChanged(rBAltKunde, null);
|
|
RadioButtonsKunde_CheckedChanged(rBEigenNetze, null);
|
|
}
|
|
private void StartKndAuswahl()
|
|
{
|
|
FormGeschaeftKndAuswahl auswahl = new FormGeschaeftKndAuswahl();
|
|
if (auswahl.ShowDialog() == DialogResult.OK)
|
|
{
|
|
this.kundetyp = auswahl.kundetyp;
|
|
if (this.kundetyp == "Bestandskunde") rBAltKunde.Checked = true;
|
|
else rBNeuKunde.Checked = true; ;
|
|
}
|
|
}
|
|
private void RadioButtonsKunde_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
RadioButton rb = (RadioButton)sender;
|
|
rb.ForeColor = rb.Checked ? Program.Wirlblau : Color.White;
|
|
|
|
// RadioButtons für Kundenauswahl.
|
|
if (rb.AccessibleName.Contains("kunde"))
|
|
{
|
|
kundetyp = rb.AccessibleName;
|
|
|
|
// TextBoxen werden je nach Kundentyp Enabled und BackColor gesetzt.
|
|
//foreach (TextBox txt in this.tLPKontakt.Controls.OfType<TextBox>()) { txt.Enabled = (rb.Checked & kundetyp == "Neukunde"); txt.BackColor = !txt.Enabled ? Color.Silver : Color.White; }
|
|
//foreach (TextBox txt in this.tLPAdresse.Controls.OfType<TextBox>()) { txt.Enabled = (rb.Checked & kundetyp == "Neukunde"); txt.BackColor = !txt.Enabled ? Color.Silver : Color.White; }
|
|
foreach (TextBox txt in this.tLPKundeNr.Controls.OfType<TextBox>()) { txt.Enabled = (rb.Checked & kundetyp == "Bestandskunde"); txt.BackColor = !txt.Enabled ? Color.Silver : Color.White; }
|
|
|
|
buttonEdit.Enabled = (rb.Checked & kundetyp == "Bestandskunde");
|
|
if (buttonEdit.Enabled)
|
|
{
|
|
buttonEdit.BackColor = Color.White;
|
|
}
|
|
else buttonEdit.BackColor = Color.Gray;
|
|
|
|
return;
|
|
}
|
|
|
|
// Wenn Eigene Netze verwendet werden.
|
|
if (rb.Checked & rb.AccessibleName == "EigeneNetze")
|
|
{
|
|
fLPNetzeScan.Enabled = false;
|
|
fLPNetzeScan.BackColor = Color.Silver;
|
|
pictureBoxPlus.Enabled = false;
|
|
pictureBoxPlus.BackColor = Color.Gray;
|
|
return;
|
|
}
|
|
|
|
// Wenn Wirl Netze verwendet werden.
|
|
if (rb.Checked & rb.AccessibleName == "WirlNetze")
|
|
{
|
|
fLPNetzeScan.Enabled = true;
|
|
fLPNetzeScan.BackColor = Color.White;
|
|
pictureBoxPlus.Enabled = true;
|
|
pictureBoxPlus.BackColor = Color.FromArgb(0, 192, 0);
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
private void ButtonEdit_Click(object sender, EventArgs e)
|
|
{
|
|
Button btn = (Button)sender;
|
|
|
|
foreach (TextBox txt in this.tLPKontakt.Controls.OfType<TextBox>()) { txt.Enabled = true; txt.BackColor = !txt.Enabled ? Color.Silver : Color.White; }
|
|
foreach (TextBox txt in this.tLPAdresse.Controls.OfType<TextBox>()) { txt.Enabled = true; txt.BackColor = !txt.Enabled ? Color.Silver : Color.White; }
|
|
|
|
}
|
|
|
|
private void TextBoxKunde_Leave(object sender, EventArgs e)
|
|
{
|
|
TextBox txt = (TextBox)sender;
|
|
|
|
if (kundetyp == "Neukunde") return;
|
|
|
|
//TODO: Kunde suchen und aus DB holen. Eventuell alle möglichen Namen durchsuchen. Eventuell DropDown mit Auswahl?
|
|
}
|
|
|
|
private void TextBox_Enter(object sender, EventArgs e)
|
|
{
|
|
TextBox tb = (TextBox)sender;
|
|
tb.BackColor = Color.White;
|
|
tb.ForeColor = Color.Black;
|
|
|
|
keyboard = Funktionen.OpenVirtualKeyboard(sender);
|
|
keyboard.KeyBoardShown += KeyBoardShown;
|
|
keyboard.KeyBoardClosed += KeyBoardClosed;
|
|
|
|
this.BeginInvoke(new Action(() =>
|
|
{
|
|
if (!tb.IsDisposed && tb.CanFocus)
|
|
{
|
|
tb.Focus();
|
|
tb.SelectAll();
|
|
}
|
|
}));
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Wenn die virtuelle Tastatur geschlossen wird, wird KeyBoardVisible aktualisiert.
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void KeyBoardClosed(object sender, EventArgs e)
|
|
{
|
|
KeyBoardVisible = false;
|
|
}
|
|
/// <summary>
|
|
/// Wenn die virtuelle Tastatur geschlossen wird, wird KeyBoardVisible aktualisiert.
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void KeyBoardShown(object sender, EventArgs e)
|
|
{
|
|
KeyBoardVisible = true;
|
|
}
|
|
|
|
private void ButtonSpeichern_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetRedTextBoxes(this).Count > 0) { MessageBox.Show("Alle Pflichtfelder müssen ausgefüllt sein.", "FEHLER"); return; }
|
|
|
|
// RadioButtons beide Checked false. Auswahl des Kundentyps geht über die FormGefschaeftKndAuswahl.
|
|
this.rBNeuKunde.Checked = false;
|
|
this.rBAltKunde.Checked = false;
|
|
|
|
MessageBox.Show("Speichern möglich");
|
|
|
|
StartKndAuswahl();
|
|
}
|
|
private List<TextBox> GetRedTextBoxes(Control parent)
|
|
{
|
|
var result = new List<TextBox>();
|
|
|
|
foreach (Control c in parent.Controls)
|
|
{
|
|
if (c is TextBox tb && tb.BackColor == Color.Red)
|
|
result.Add(tb);
|
|
|
|
if (c.HasChildren)
|
|
result.AddRange(GetRedTextBoxes(c));
|
|
}
|
|
|
|
return result;
|
|
}
|
|
private void Pflichtfelder_Validating(object sender, CancelEventArgs e)
|
|
{
|
|
|
|
if (sender is TextBox txt)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(txt.Text))
|
|
{
|
|
txt.BackColor = Color.Red;
|
|
txt.ForeColor = Color.White;
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
if (txt.AccessibleName.Contains("Numeric"))
|
|
{
|
|
if (!int.TryParse(txt.Text, out _))
|
|
{
|
|
txt.BackColor = Color.Red;
|
|
txt.ForeColor = Color.White;
|
|
return;
|
|
}
|
|
}
|
|
e.Cancel = false;
|
|
txt.BackColor = Color.White;
|
|
txt.ForeColor = Color.Black;
|
|
}
|
|
//TODO: Testen wie die Validierung abläuft.
|
|
}
|
|
}
|
|
|
|
private void ButtonAbbrechen_Click(object sender, EventArgs e)
|
|
{
|
|
if (MessageBox.Show("Möchtest du die Eingabe wirklich abbrechen?", "FRAGE", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
|
|
else
|
|
{
|
|
kunde = null;
|
|
this.dTPAbholtag.Checked = false;
|
|
|
|
CheckAllTextBoxes(this);
|
|
|
|
// RadioButtons beide Checked false. Auswahl des Kundentyps geht über die FormGefschaeftKndAuswahl.
|
|
this.rBAltKunde.Checked = false;
|
|
this.rBNeuKunde.Checked = false;
|
|
|
|
StartKndAuswahl();
|
|
}
|
|
}
|
|
private void CheckAllTextBoxes(Control parent)
|
|
{
|
|
foreach (Control c in parent.Controls)
|
|
{
|
|
if (c is TextBox tb)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(tb.Text))
|
|
{
|
|
tb.Clear();
|
|
}
|
|
}
|
|
|
|
if (c.HasChildren)
|
|
{
|
|
CheckAllTextBoxes(c);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|