using BrightIdeasSoftware; using DatenDB; using Deckungsbeitrag.AA_Forms; using Deckungsbeitrag.AA_Klassen; using Deckungsbeitrag.Properties; using Npgsql; using System; using System.Collections.Generic; using System.ComponentModel; using System.Configuration; using System.Data; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Management.Instrumentation; using System.Reflection; using System.Runtime; using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Input; using System.Xml.Serialization; using Timer = System.Windows.Forms.Timer; namespace Deckungsbeitrag { public partial class FormMain : Form { private Benutzer benutzer = null; Meldungen meldung = new Meldungen(); bool open = false; private bool isDragging = false; private Point dragStartPoint; private Point newLocation; private Size _fixedSize; private bool _handlingResize; private readonly UserSettingsManager _settings = new UserSettingsManager(); private bool formloading = false; private Dictionary> auftragliste; private GroupBox draggedBox; private Point dragOffset; private Point dragOffsetButton; private PictureBox ghostImage; private Button draggedButton; private bool isButtonDragging = false; private Timer dragEndTimer; public FormMain() { InitializeComponent(); this.panelMain.AllowDrop = true; this.toolStripMenu.Size = new Size(toolStripButton1.Size.Width + 20, this.Height); } public FormMain(Benutzer benutzer) : this() { this.benutzer = benutzer; this.groupBoxUpdate.Enabled = false; // AKTIVE ELEMENTE JE BENUTZER ROLLE switch (benutzer.Rolle) { case BenutzerRolle.Verwaltung: this.toolStripDB.Enabled = this.toolStripButtonImport.Enabled = this.tSBExpedit.Enabled = false; this.toolStripDB.Visible = this.toolStripButtonImport.Visible = this.tSBExpedit.Enabled = false; break; case BenutzerRolle.Fahrer: // ToolStripButtons werden deaktiviert. foreach(ToolStripButton tsb in this.toolStripMenu.Items) { // Ausgewählter ToolStripButton bleibt aktiv. if(!tsb.Name.Contains("Auftrag")) tsb.Enabled = false; } // Controls im PanelMain werden deaktiviert. foreach(Control ctr in this.panelMain.Controls) { // Ausgewählte Buttons bleiben aktiv. if (ctr.Name.Contains("Auftrag") || ctr.Name.Contains("Tourenliste")) ctr.Visible = true; else { //if (ctr.GetType() == typeof(Button)) ctr.BackColor = Color.Gray; ctr.Visible = false; } } break; case BenutzerRolle.Admin: break; case BenutzerRolle.Waschstrasse: this.toolStripDB.Enabled = this.toolStripButtonImport.Enabled = this.tSBBenutzerVW.Enabled = this.tSBAufgabeVW.Enabled = this.tSBExpedit.Enabled = false; this.groupBoxUpdate.Visible = this.toolStripDB.Visible = this.toolStripButtonImport.Visible = this.tSBBenutzerVW.Enabled = this.tSBAufgabeVW.Enabled = this.tSBExpedit.Enabled = false; break; case BenutzerRolle.Master: this.groupBoxUpdate.Visible = this.groupBoxUpdate.Enabled = true; break; default: break; } ghostImage = new PictureBox { Size = new Size(200, 100), // GroupBox-Größe Visible = false, BackColor = Color.Transparent, SizeMode = PictureBoxSizeMode.StretchImage }; panelMain.Controls.Add(ghostImage); // Zum Panel! } private async void FormMain_Load(object sender, EventArgs e) { formloading = true; _settings.Load(); this.WindowState = FormWindowState.Maximized; this.MaximizedBounds = Screen.PrimaryScreen.WorkingArea; this.panelMain.Width = this.Width - this.toolStripMenu.Right - 20; this.panelMain.Location = new Point(this.toolStripMenu.Right, 0); this.Text += Assembly.GetExecutingAssembly().GetName().Version.ToString(); this.labelKundenDatum.Text = @"N:\TECHNIK\Software\Wirl-Verwaltung\Listen\Kundenstammblatt.csv"; this.labelSoftwareDatum.Text = @"N:\TECHNIK\Software\Wirl-Verwaltung\Setup\SetupVerwaltung*.msi"; this.labelArtikelDatum.Text = @"N:\TECHNIK\Software\Wirl-Verwaltung\Listen\Artikelkurzliste.csv"; GetStatistik(); GetSaison(); // GroupBoxen im PanelMain werden ausgeblendet foreach (GroupBox gb in this.panelMain.Controls.OfType()) { if (!gb.Name.Contains("Update") & !gb.Name.Contains("Statistik") & !gb.Name.Contains("Neuer") & !gb.Name.Contains("Saison") & !gb.Name.Contains("ContAnz")) { gb.Visible = false; gb.Location = new Point(0, 0); gb.Size = new Size(this.panelMain.Width, this.panelMain.Height); } RegisterDragEvents(gb); } if (this.groupBoxContAnz.Visible) { await GetAuftraege(); GetContainerProTag(); } this.Activate(); _fixedSize = this.Size; formloading = false; } private async Task GetAuftraege() { var conn = new NpgsqlConnection(ConfigurationManager.AppSettings["ConnectionString"]); // Pro Task! try { await conn.OpenAsync(); auftragliste = await Auftrag.GetAuftraegeProLiefertagAsync(conn, AuftragTyp.Standart, AuftragStatus.Aufgelegt); } finally { if (conn.State == ConnectionState.Open) conn.Close(); conn.Dispose(); } } private void Paint_Boarder(Size size, Point location, PaintEventArgs e) { e.Graphics.Clear(Color.White); Pen pen = new Pen(Color.FromArgb(1, 53, 101), 4); Rectangle rect = new Rectangle(1, 2, size.Width - 4, size.Height - 4); e.Graphics.DrawRectangle(pen, rect); } private void panelMain_Paint(object sender, PaintEventArgs e) { Paint_Boarder(this.panelMain.Size, this.panelMain.Location, e); } #region ToolStripButton_Click-Events private void tSBBenutzerVW_Click(object sender, EventArgs e) { FormBenutzerVW benutzerVW = new FormBenutzerVW(); benutzerVW.ShowDialog(); } private void toolStripBeenden_Click(object sender, EventArgs e) { Application.Exit(); } private void tSBAufgabeVW_Click(object sender, EventArgs e) { FormAufgabeVW aufgabeVW = new FormAufgabeVW(); aufgabeVW.ShowDialog(); } private void toolStripZaehlscheine_Click(object sender, EventArgs e) { FormKundeVW kundedaten = new FormKundeVW(this.benutzer); if (kundedaten.ShowDialog() == DialogResult.OK) { } } private void toolStripDB_Click(object sender, EventArgs e) { FormNeuDeckungsbeitrag deckungsbeitrag = new FormNeuDeckungsbeitrag(this.benutzer, false); if (deckungsbeitrag.ShowDialog() == DialogResult.OK) { } } private void tSBWaschstrasse_Click(object sender, EventArgs e) { FormAufleger aufleger = new FormAufleger(); aufleger.ShowDialog(); } private void toolStripButtonImport_Click(object sender, EventArgs e) { FormImport import = new FormImport(); import.ShowDialog(); } private void tSBKosten_Click(object sender, EventArgs e) { FormNeuDeckungsbeitrag deckungsbeitrag = new FormNeuDeckungsbeitrag(this.benutzer, true); if (deckungsbeitrag.ShowDialog() == DialogResult.OK) { } } private void tSBEinstellung_Click(object sender, EventArgs e) { FormEinstellung einstellung = new FormEinstellung(); einstellung.ShowDialog(); } private void toolStripStatusLabel2_DoubleClick(object sender, EventArgs e) { FormEinstellung einstellung = new FormEinstellung("Sortiment"); einstellung.ShowDialog(); } private void tSBExpedit_Click(object sender, EventArgs e) { FormExpedit exp = new FormExpedit(benutzer); exp.ShowDialog(); } private void tSBAuftragVW_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; if (!this.groupBoxAuftrag.Visible) { if (benutzer.Rolle == BenutzerRolle.Fahrer) this.rBFertig.Checked = true; else this.rBAlle.Checked = true; // Groupbox einblenden wenn OLV noch nicht sichtbar ist. foreach (GroupBox gb in this.panelMain.Controls.OfType()) gb.Visible = gb.Name.Contains("Auftrag") ? true : false; // PanelMain Buttons ausblenden. foreach (Button btn in this.panelMain.Controls.OfType