using DatenDB; using Deckungsbeitrag.AA_Forms; using Deckungsbeitrag.AA_Klassen; using Microsoft.VisualBasic; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using static System.Net.WebRequestMethods; namespace Deckungsbeitrag.UserControls { public partial class UCTabPageLKW : UserControl { public UCTabPageLKW() { InitializeComponent(); } private void FlowLayout_DragEnter(object sender, DragEventArgs e) { // Unterscheiden zwischen Clone und Move KundenControl // Wenn KundenControl innerhalb eines Tages bewegt wird ist Move // sonst ist Clone. if (e.Data.GetDataPresent("KundeData")) // Custom Format e.Effect = DragDropEffects.Copy; if (e.Data.GetDataPresent(typeof(UCKunde))) e.Effect = DragDropEffects.Move; } private void FlowLayout_DragOver(object sender, DragEventArgs e) { // Unterscheiden zwischen Clone und Move KundenControl // Wenn KundenControl innerhalb eines Tages bewegt wird ist Move // sonst ist Clone. if (e.Data.GetDataPresent("KundeData")) // Custom Format e.Effect = DragDropEffects.Copy; if (e.Data.GetDataPresent(typeof(UCKunde))) e.Effect = DragDropEffects.Move; } private void FlowLayout_DragDrop(object sender, DragEventArgs e) { bool toClone = true; string saison = string.Empty; int saisonrhythmus = 0; FlowLayoutPanel dropTarget = sender as FlowLayoutPanel; DayOfWeek dropDay = DayOfWeek.Sunday; switch (dropTarget.Tag.ToString()) { case "MO": dropDay = DayOfWeek.Monday; break; case "DI": dropDay = DayOfWeek.Tuesday; break; case "MI": dropDay = DayOfWeek.Wednesday; break; case "DO": dropDay = DayOfWeek.Thursday; break; case "FR": dropDay = DayOfWeek.Friday; break; default: break; } FormTourenplanung tourenplanung = (FormTourenplanung)this.ParentForm; foreach (RadioButton rb in tourenplanung.Controls.OfType()) if (rb.Checked) saison = rb.Text; if (e.Data.GetDataPresent("KundeData")) { UCKunde kundectr = e.Data.GetData("KundeData") as UCKunde; Kunde kunde = (Kunde)kundectr.Tag; if (saison == "Sommer") saisonrhythmus = kunde.SommerLieferRhythmus; else saisonrhythmus = kunde.WinterLieferRhythmus; if (kundectr != null) { Liefertage neuerRhythmus = GetKompatiblenRhythmus(dropDay, (Liefertage)saisonrhythmus); if (neuerRhythmus != (Liefertage)saisonrhythmus) { Meldungen meldung = new Meldungen(); if (meldung.GetFrage(null, $"Rhythmus von {Lieferrhythmen.GetAnzeigeText((Liefertage)saisonrhythmus)} auf {Lieferrhythmen.GetAnzeigeText((Liefertage)neuerRhythmus)} ändern?", false) == DialogResult.No) return; else { if (saison == "Sommer") kunde.SommerLieferRhythmus = (int)neuerRhythmus; else kunde.WinterLieferRhythmus = (int)neuerRhythmus; kunde.Save(); kundectr.Tag = kunde; FormTourenplanung.KundenControlToDelete(tourenplanung, kundectr); } } // Überprüfung ob KundenControl geclont werden kann if (neuerRhythmus == Lieferrhythmen.Unbekannt || !FormTourenplanung.KundenControlToClone(tourenplanung, kundectr)) toClone = false; if (toClone) { // Kunde klonen (nicht original bewegen) UCKunde kundeKopie = (UCKunde)kundectr.Clone(); kundeKopie.Tag = kundectr.Tag; kundeKopie.Parent = dropTarget; dropTarget.Controls.Add(kundeKopie); } } GetGesamtContainer(dropTarget); } // Move statt Clone KundenControl if (e.Data.GetDataPresent(typeof(UCKunde))) { UCKunde draggedControl = e.Data.GetData(typeof(UCKunde)) as UCKunde; if (draggedControl == null || dropTarget == null || draggedControl.Parent.Tag != dropTarget.Tag) return; dropTarget.SuspendLayout(); try { // Drop-Position berechnen Point dropPoint = dropTarget.PointToClient(new Point(e.X, e.Y)); int dropIndex = GetDropIndex(dropTarget, dropPoint); // Reihenfolge ändern dropTarget.Controls.SetChildIndex(draggedControl, dropIndex); // Gesamt-Labels aktualisieren GetGesamtContainer(dropTarget); } finally { dropTarget.ResumeLayout(true); } } } private int GetDropIndex(FlowLayoutPanel flp, Point dropPoint) { for (int i = 0; i < flp.Controls.Count; i++) { if (flp.Controls[i].Bounds.Contains(dropPoint)) return i; } return flp.Controls.Count; // Am Ende anhängen } private void GetGesamtContainer(FlowLayoutPanel dropTarget) { int[] gesamt = { 0, 0, 0 }; foreach (UCKunde kndctrl in dropTarget.Controls.OfType()) { for (int i = 0; i < Math.Min(kndctrl.ContAnzahl.Length, gesamt.Length); i++) { gesamt[i] += kndctrl.ContAnzahl[i]; } } foreach (Label ctr in tableLayoutPanelTage.Controls.OfType