Programm_Wirl/UserControls/UCAuftragSuchen.cs

103 lines
3.9 KiB
C#

using DatenDB;
using Deckungsbeitrag.AA_Forms;
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;
namespace Deckungsbeitrag.UserControls
{
public partial class UCAuftragSuchen : UserControl
{
private Benutzer benutzer;
private FormShowUserControl showbox;
public UCAuftragSuchen()
{
InitializeComponent();
}
public UCAuftragSuchen(Benutzer benutzer, object sender) : this()
{
this.benutzer = benutzer;
}
private void UCAuftragSuchen_Load(object sender, EventArgs e)
{
showbox = this.Parent as FormShowUserControl;
}
#region Suchen-GroupBox
private void buttonSuchen_Click(object sender, EventArgs e)
{
List<Auftrag> auftraglist;
string datum = string.Empty;
DateTime date = this.dTPSuchen.Value.Date;
AuftragStatus? status = (AuftragStatus?)this.comboBoxStatus.SelectedItem == null ? null : (AuftragStatus?)this.comboBoxStatus.SelectedItem;
AuftragTyp? typ = (AuftragTyp?)this.comboBoxTyp.SelectedItem == null ? null : (AuftragTyp?)this.comboBoxTyp.SelectedItem;
foreach (RadioButton rb in this.groupBoxSuchen.Controls.OfType<RadioButton>()) if (rb.Checked) { datum = rb.Tag.ToString(); }
if (datum == string.Empty && status == null && typ == null && this.buttonKunde.Tag == null) { MessageBox.Show("Nach was möchtest du suchen?", "ANGABEN FEHLEN", MessageBoxButtons.OK, MessageBoxIcon.Question); return; }
if (this.buttonKunde.Tag != null) auftraglist = Auftrag.FindeAuftragVonKunde((Kunde)this.buttonKunde.Tag, null, datum, date);
else auftraglist = Auftrag.SucheAuftrag(datum, date, status, typ);
if (auftraglist.Count == 0) { MessageBox.Show("Es konnte kein Auftrag gefunden werden.", "FEHLER", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
if (auftraglist.Count > 1)
{
//MessageBox.Show("Es wurden mehrere Aufträge gefunden. Bitte melde das Problem.", "FEHLER", MessageBoxButtons.OK, MessageBoxIcon.Error); return;
showbox.auftragliste = auftraglist;
showbox._toclose = true;
return;
}
FormAuftragDetail auftragDetail = new FormAuftragDetail(auftraglist[0], this.benutzer);
DialogResult result = auftragDetail.ShowDialog();
if (result == DialogResult.OK || result == DialogResult.Cancel)
{
showbox._toclose = true;
}
this.buttonKunde.BackColor = Color.White;
this.buttonKunde.ForeColor = this.buttonKunde.FlatAppearance.BorderColor = Program.Wirlblau;
}
private void radioButtonSuchen_CheckedChanged(object sender, EventArgs e)
{
RadioButton rb = (RadioButton)sender;
if (rb.Checked) { rb.ForeColor = Color.White; }
else { rb.ForeColor = Program.Wirlblau; rb.FlatAppearance.BorderColor = Program.Wirlblau; }
this.dTPSuchen.Enabled = true;
}
private void buttonKunde_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
Kunde kunde = Funktionen.Open_List(null);
if (kunde == null) return;
btn.Tag = kunde;
btn.Text = string.IsNullOrWhiteSpace(kunde.Suchtext) ? kunde.KundeName : kunde.Suchtext;
btn.BackColor = Program.Wirlblau;
btn.ForeColor = Color.White;
}
private void groupBoxSuchen_VisibleChanged(object sender, EventArgs e)
{
this.SuspendLayout();
if (!this.groupBoxSuchen.Visible) return;
this.comboBoxTyp.DataSource = Enum.GetValues(typeof(Priority));
this.comboBoxTyp.SelectedIndex = -1;
this.comboBoxStatus.DataSource = Enum.GetValues(typeof(AuftragStatus));
this.comboBoxStatus.SelectedIndex = -1;
this.ResumeLayout();
}
#endregion
private void groupBoxSuchen_Paint(object sender, PaintEventArgs e)
{
GroupBox gb = (GroupBox)sender;
base.OnPaint(e);
Funktionen.GetGroupBoxBoarder(gb, e);
}
}
}