You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

164 lines
5.1 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 System.IO;
namespace Übungen_LF6_WinFormanwendung
{
public partial class Klassenarbeit_030517_AlexanderDegen : Form
{
int anzahlDatensätze = 0;
string fileName;
//Datenspeicher
List<OrderDetails> Bestellungen = new List<OrderDetails>();
List<string> VorhandeneOrderIDs = new List<string>();
public Klassenarbeit_030517_AlexanderDegen()
{
InitializeComponent();
}
private void button_ende_Click(object sender, EventArgs e)
{
this.Close();
}
private void CSVLesen_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "CSV-Datei (*.csv)|*.csv|Textdatei (*.txt)|*.txt|Alle Dateien(*.*)|*.*";
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
fileName = openFileDialog1.FileName;
textBoxFileName.Text = openFileDialog1.FileName;
}
}
private void buttonAnzeige_Click(object sender, EventArgs e)
{
try
{
//Dateileseroutine
StreamReader tr = new StreamReader(fileName);
// Header überlesen
string zeile = tr.ReadLine();
String[] CSVHeader = zeile.Split(';');
//Header Füllen
textBox_Header_OrderID.Text = CSVHeader[0];
textBox_Header_ProductID.Text = CSVHeader[1];
textBox_Header_UnitPrize.Text = CSVHeader[2];
textBox_Header_Quantity.Text = CSVHeader[3];
textBox_Header_Discount.Text = CSVHeader[4];
while (!tr.EndOfStream)
{
zeile = "";
zeile = tr.ReadLine();
string[] CSVREADLINE = zeile.Split(';');
OrderDetails obj = new OrderDetails(CSVREADLINE);
if(!VorhandeneOrderIDs.Contains(obj.ORDERID))
{
VorhandeneOrderIDs.Add(obj.ORDERID);
}
anzahlDatensätze += 1;
Bestellungen.Add(obj);
//Listboxen füllen
listBoxOrderID.Items.Add(CSVREADLINE[0]);
listBoxProductID.Items.Add(CSVREADLINE[1]);
listBox_UnitPrize.Items.Add(CSVREADLINE[2]);
listBox_Quantity.Items.Add(CSVREADLINE[3]);
listBox_Discount.Items.Add(CSVREADLINE[4]);
}
// close the stream
tr.Close();
}
catch (Exception ex)
{
Console.WriteLine("Fehler: {0}", ex.ToString());
}
}
private void button_GesUmsatz_Click(object sender, EventArgs e)
{
double gesUmsatz = 0f;
foreach(OrderDetails obj in Bestellungen)
{
gesUmsatz += Convert.ToDouble(obj.UNITPRIZE) * Convert.ToDouble(obj.QUANTITY);
}
textBox_GesUmsatz.Text = gesUmsatz.ToString();
}
private void button_SalePerProduct_Click(object sender, EventArgs e)
{
}
private void button_RechnungProOrder_Click(object sender, EventArgs e)
{
}
private void button_UmsatzNetto_Click(object sender, EventArgs e)
{
double nettoUmsatz = 0f;
double bruttoUmsatz = 0f;
foreach (OrderDetails obj in Bestellungen)
{
bruttoUmsatz = Convert.ToDouble(obj.UNITPRIZE) * Convert.ToDouble(obj.QUANTITY);
nettoUmsatz += bruttoUmsatz - bruttoUmsatz * Convert.ToDouble(obj.DISCOUNT);
}
nettoUmsatz = Math.Round(nettoUmsatz, 2);
textBox_UmsatzNetto.Text = nettoUmsatz.ToString();
}
private void button_SummeSales_Click(object sender, EventArgs e)
{
int summeSales = 0;
foreach (OrderDetails obj in Bestellungen)
{
summeSales += Convert.ToInt32(obj.QUANTITY);
}
textBox_SummeSales.Text = summeSales.ToString();
}
private void button_Summe_Bestellung_Click(object sender, EventArgs e)
{
int anzahlBestellungen = 0;
foreach (OrderDetails obj in Bestellungen)
{
if(VorhandeneOrderIDs.Contains(obj.ORDERID))
anzahlBestellungen += Convert.ToInt32(obj.QUANTITY);
}
textBox_Summe_Bestellung.Text = anzahlBestellungen.ToString();
}
}
}