Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Windows.Forms;
- namespace KL
- {
- public partial class Form1 : Form
- {
- Produkt p;
- List<String> le = new List<String>();
- List<String> auswahl = new List<String>();
- string path = @"Produkt.txt";
- double gesamtSumme = 0;
- public Form1()
- {
- InitializeComponent();
- }
- private void button_save_Click(object sender, EventArgs e)
- {
- p = new Produkt(tb_pnr.Text, tb_pName.Text, Convert.ToDouble(tbPrice.Text), Convert.ToInt32(tb_Count.Text));
- FileStream fs = new FileStream(path, FileMode.Append, FileAccess.Write);
- StreamWriter sw = new StreamWriter(fs);
- sw.WriteLine(p.toStr());
- sw.Close();
- fs.Close();
- refresh();
- } // erstellt neues Objekt p von Produkt, schreibt in Datei, ruft refresh auf
- private void Form1_Load(object sender, EventArgs e)
- {
- refresh();
- } // ruft refresh auf
- private void leereForm()
- {
- listBox2.Items.Clear();
- tb_anz.Text = "";
- } // leert zweite Listbox und TextBox
- private void refresh()
- {
- listBox1.Items.Clear();
- le.Clear();
- FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
- StreamReader sr = new StreamReader(fs);
- while (sr.Peek() != -1)
- {
- le.Add(sr.ReadLine());
- }
- sr.Close();
- fs.Close();
- foreach (String li in le)
- {
- listBox1.Items.Add(li);
- }
- } // leer erste Listbox und leert Liste Le, liest von Datei, fuellt Liste le, fuellt Listbox1 mit Listeneinträgen
- private double berechneGesamtPreis()
- {
- string value = Convert.ToString(le[listBox1.SelectedIndex]);
- char delimitier = ';';
- string[] substring = value.Split(delimitier);
- double sum = Convert.ToInt32(tb_anz.Text) * Convert.ToDouble(substring[2]);
- createListandFillListbox(sum,substring[1],Convert.ToInt32(tb_anz.Text), Convert.ToInt32(substring[3]));
- return sum;
- } // Teilt Listeneintrag le in Substrings und verteilt in Array, Berechnet Summe pro Auswahl, ruft Funktion auf
- private double createListandFillListbox(double sum, string name, int count, int lagerbestand)
- {
- if (Convert.ToInt32(tb_anz.Text) <= lagerbestand)
- {
- lagerbestand = lagerbestand - Convert.ToInt32(tb_anz.Text);
- listBox2.Items.Clear();
- auswahl.Add(count + ";" + name + ";" + Convert.ToString(sum) );
- gesamtSumme += sum;
- foreach (String li in auswahl)
- {
- listBox2.Items.Add(li);
- }
- }
- // else MessageBox.Show("Anzahl zu hoch. Maximal " + p.getCount() + " Stk verfuegbar");
- else
- {
- MessageBox.Show("Anzahl zu hoch.");
- }
- return gesamtSumme;
- } // leert Listbox 2, fuegt neue auswahleinträge der Liste auswahl hinzu, errechnet Gesamtsumme
- private int getMenge(int vorhanden,int bestellt)
- {
- return vorhanden - bestellt;
- }
- private void button_calc_Click(object sender, EventArgs e)
- {
- if (tb_anz.Text != "" && listBox1.SelectedIndex != -1)
- {
- berechneGesamtPreis();
- label7.Text = Convert.ToString(gesamtSumme);
- }
- else
- {
- MessageBox.Show("Bitte Listenelement auswählen und Anzahl angeben:");
- }
- } // Gibt Gesamtsumme als String aus
- private void button_new_Click(object sender, EventArgs e)
- {
- leereForm();
- listBox2.Items.Clear();
- auswahl.Clear();
- label7.Text = Convert.ToString(gesamtSumme = 0);
- } // ---
- }
- }
Add Comment
Please, Sign In to add comment