Programm_Wirl/AA-Forms/FormAufgabeVW.cs

116 lines
3.3 KiB
C#

using BrightIdeasSoftware;
using DatenDB;
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 System.Xml.Serialization;
namespace Deckungsbeitrag
{
public partial class FormAufgabeVW : Form
{
Aufgabe aufgabe;
private Meldungen meldung = new Meldungen();
private List<object> list;
bool showMeldung = false;
public FormAufgabeVW()
{
InitializeComponent();
}
private void FormAufgabeVW_Load(object sender, EventArgs e)
{
try
{
list = new List<object>(Aufgabe.GetList(null));
Load_OLV(list);
}
catch (Exception ex)
{
meldung.IsUpdating(ex);
this.Close();
}
}
private void Load_OLV(List<object> list)
{
Generator.GenerateColumns(this.objectListViewAufgabe, typeof(Aufgabe), true);
this.objectListViewAufgabe.SetObjects(list);
OLVColumn sortcolumn = (OLVColumn)this.objectListViewAufgabe.Columns[1];
this.objectListViewAufgabe.Sort(sortcolumn);
this.objectListViewAufgabe.FilterMenuBuildStrategy = new MeinFilterMenu();
this.objectListViewAufgabe = Funktionen.Columns_Resize(null, this.objectListViewAufgabe).olv;
}
/// <summary>
/// BUTTON CLICK EVENTS
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonSpeichern_Click(object sender, EventArgs e)
{
if (this.aufgabe == null) this.aufgabe = new Aufgabe();
if (this.aufgabe.Save() == 1) { FormAufgabeVW_Load(this, e); }
}
private void buttonAbbrechenAufgabe_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
this.Close();
}
private void buttonNeueAufgabe_Click(object sender, EventArgs e)
{
FormNeueAufgabe neueAufgabe = new FormNeueAufgabe();
neueAufgabe.ShowDialog();
}
private void objectListViewAufgabe_SubItemChecking(object sender, SubItemCheckingEventArgs e)
{
Aufgabe aufgabe = (Aufgabe)e.RowObject;
if (aufgabe.Aktiv) aufgabe.Aktiv = false;
else aufgabe.Aktiv = true;
Save_Aufgabe(aufgabe, false);
}
private void objectListViewAufgabe_CellClick(object sender, CellClickEventArgs e)
{
ObjectListView olv = (ObjectListView)sender;
Aufgabe aufgabe = (Aufgabe)e.Model;
if(e.ColumnIndex == 3)
{
ColorDialog dialog = new ColorDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
aufgabe.Farbe = dialog.Color;
Save_Aufgabe(aufgabe, showMeldung);
}
olv.RefreshObject(e);
FormAufgabeVW_Load(this, null);
}
}
private void objectListViewAufgabe_FormatCell(object sender, FormatCellEventArgs e)
{
if (e.ColumnIndex == 3)
{
Aufgabe _aufgabe = (Aufgabe)e.Model;
if (_aufgabe.Farbe != null)
{
e.SubItem.BackColor = _aufgabe.Farbe;
e.SubItem.Text = string.Empty;
}
}
}
private void Save_Aufgabe(Aufgabe _aufgabe, bool show)
{
if (_aufgabe.Save() == 1) { if (show) meldung.Gespeichert(); }
else { if (show) meldung.Speicherfehler(); }
}
}
}