/// <summary> /// Calculates the Price /// </summary> private void CalcPrice() { if (InputId.Text.Length <= 0 || InputAmount.Text.Length <= 0) { return; } PriceOutput.Text = "Preis: "; try { foreach (Product p in Buchhaltung.Products) { if (Convert.ToInt32(InputId.Text) == p.Id) { _priceInUse = p.Price * Convert.ToInt32(InputAmount.Text); PriceOutput.Text += " " + (_priceInUse) + "€"; break; } } } catch (Exception e) { Buchhaltung.Log(e.Message); Buchhaltung.SaveErrorMsg(e); } }
/// <summary> /// Searches the product with the given id /// </summary> /// <returns>true if prouduct was found</returns> private bool SearchForProduct() { if (InputId.Text.Length <= 0) { return(false); } ProductOutput.Text = "Produkt:"; try { foreach (Product p in Buchhaltung.Products) { if (p.Id == Convert.ToInt32(InputId.Text)) { ProductOutput.Text += " " + p.Name; return(true); } } return(false); } catch (Exception e) { Buchhaltung.Log(e.Message); Buchhaltung.SaveErrorMsg(e); return(false); } }
/// <summary> /// Gets the sales value of all 10% tax items /// </summary> /// <returns>the tax</returns> private double GetTenPercentValue() { double sales = 0; try { foreach (Day d in Buchhaltung.CurrWeek.DaysInWeek) { foreach (Entry e in d.Entrys) { if (e.Tax.Equals(10)) { sales += e.Price; } } } } catch (Exception ex) { Buchhaltung.SaveErrorMsg(ex); Buchhaltung.Log(ex.Message); } return(sales / 110 * 10); }
/// <summary> /// Deletes CurrEntry in Table and Data /// </summary> private void DeleteCurrEntry() { GetCurrEntry(); if (IdInput.Text != "" && AmountInput.Text != "" && OnTheHouseInput.Text != "" && NumInput.Text != "") { bool suc = false; //to stop the loop foreach (Day d in Buchhaltung.CurrWeek.DaysInWeek) { if (d.Name == Buchhaltung.CurrDay) { for (int i = 0; i < d.Entrys.Count; i++) { //compares the original entry with the entrys in the mainProgramm if (_originalEntry.ProductForEntry.Id == (d.Entrys[i].ProductForEntry.Id) && _originalEntry.Amount == (d.Entrys[i].Amount)) { d.Entrys.RemoveAt(i); suc = true; break; } } } if (suc) { break; } } Buchhaltung.SaveEntrys(); Close(); } }
//Calls delete function private void Delete_Click(object sender, RoutedEventArgs e) { if (Buchhaltung.ShowYesNoMessageBox("Bist du sicher das du diesen Eintrag löschen willst?", "Löschen")) { DeleteCurrEntry(); } }
/// <summary> /// Checks if everything is ok and saves it /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OkBtn_Click(object sender, RoutedEventArgs e) { if (NameTextBox.Text != "" && (WeekNrTextBox.Text != "" && Convert.ToInt32(WeekNrTextBox.Text) > 0 && Convert.ToInt32(WeekNrTextBox.Text) < 53) && DateTextBox.Text != "" && OldCashTextBox.Text != "") { UpdateWeek(); Close(); } else { Buchhaltung.Log("Fehlerhafte Eingabe!"); } }
/// <summary> /// Starts the programm with the data needed /// </summary> private void StartProgramm() { try { if (Convert.ToInt32(WeekNrTextBox.Text) > 0 && Convert.ToInt32(WeekNrTextBox.Text) < 56) //Week in year { if (File.Exists(@"Data\" + WeekNrTextBox.Text + @".week")) //Week does exist { Buchhaltung b = new Buchhaltung(WeekNrTextBox.Text, Username, IsAdmin); b.Show(); } else { //If one if is not correct writes error and returns if (OldCashDesk.Text.Length == 0) { Buchhaltung.Log("Kein alter Kassenstand eingetragen!"); return; } if (NameInput.Text.Length == 0) { Buchhaltung.Log("Kein Name eingetragen!"); return; } //end of return if string oldCashDeskStr = OldCashDesk.Text; if (oldCashDeskStr.Contains("€")) { oldCashDeskStr = oldCashDeskStr.Replace('€', ' ').Trim(); } Buchhaltung b = new Buchhaltung(WeekNrTextBox.Text, NameInput.Text, Convert.ToDateTime(DateTextBox.Text), Convert.ToDouble(oldCashDeskStr), Username, IsAdmin); b.Show(); } Close(); } else { Buchhaltung.Log("Ungültige Woche"); } } catch (Exception e) { Buchhaltung.SaveErrorMsg(e); Buchhaltung.Log(e.Message); } }
/// <summary> /// Checks if id is ok /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnTextInput_ID(object sender, KeyEventArgs e) { string input = InputId.Text; try { int dummy = Convert.ToInt32(input); _idIsOk = SearchForProduct(); } catch (Exception ex) { _idIsOk = false; Buchhaltung.SaveErrorMsg(ex); } }
/// <summary> /// Checks if amount is ok /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void InputAmount_keyDown(object sender, KeyEventArgs e) { try { string t = InputAmount.Text; double dummy = Convert.ToDouble(t); _amountIsOk = true; CalcPrice(); } catch (Exception ex) { _amountIsOk = false; Buchhaltung.SaveErrorMsg(ex); } }
/// <summary> /// Edits data In Table and Data /// </summary> private void EditDataAndSave() { if (IdInput.Text != "" && AmountInput.Text != "" && OnTheHouseInput.Text != "" && NumInput.Text != "") { bool stopIt = false; //to stop the loop try { foreach (Day dummy in Buchhaltung.CurrWeek.DaysInWeek) { foreach (Product t in Buchhaltung.Products) { if (IdInput.Text == Convert.ToString(t.Id)) //Checks the id of the product { //Gives the newEntry the correct information Product pNew = t; _newEntry.ProductForEntry = pNew; _newEntry.Amount = Convert.ToInt32(AmountInput.Text); _newEntry.AmountOnTheHouse = Convert.ToInt32(OnTheHouseInput.Text); _newEntry.Price = _originalEntry.Amount * _originalEntry.ProductForEntry.Price; stopIt = true; break; } } if (stopIt) //stopsLoop { break; } } OverridesEntryInMainProgramm(); Buchhaltung.SaveEntrys(); Close(); } catch (Exception e) { Buchhaltung.Log(e.Message); Buchhaltung.SaveErrorMsg(e); } } else { Buchhaltung.Log("Es wurden Felder leer gelassen!"); } }
/// <summary> /// Displays all Entrys in this week (DBG) /// </summary> public void ShowDays() { try { foreach (Day d in DaysInWeek) { MessageBox.Show(d.Name.ToString()); foreach (Entry t in d.Entrys) { MessageBox.Show("Name: " + t.ProductForEntry.Name + "; Menge: " + t.Amount + "; Preis: " + t.Price); } } } catch (Exception e) { Buchhaltung.SaveErrorMsg(e); } }
/// <summary> /// Checks if OnTheHouse is ok /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void InputOnTheHouse_keyDown(object sender, KeyEventArgs e) { try { double dummy; string t = InputAmountOnTheHouse.Text; if (t.Length > 0) { dummy = Convert.ToDouble(t); } _onTheHouseIsOk = true; } catch (Exception ex) { _onTheHouseIsOk = false; Buchhaltung.SaveErrorMsg(ex); } }
/// <summary> /// Saves Entry /// </summary> private void SaveEntry() { try { foreach (Product p in Buchhaltung.Products) { if (p.Id != Convert.ToInt32(InputId.Text)) { continue; } Entry e; int actualAmount = 0; if (InputAmountOnTheHouse.Text == "") { actualAmount = Convert.ToInt32(InputAmount.Text); e = new Entry(p, actualAmount, 0, _priceInUse); } else { actualAmount = Convert.ToInt32(Convert.ToInt32(InputAmount.Text) + Convert.ToInt32(InputAmountOnTheHouse.Text)); e = new Entry(p, actualAmount, Convert.ToInt32(InputAmountOnTheHouse.Text), _priceInUse); } //Adds at the currentWeek and the current Day the entry Buchhaltung.CurrWeek.GetCurrentDayAndAddEntry(e); break; } } catch (Exception e) { Buchhaltung.Log(e.Message); Buchhaltung.SaveErrorMsg(e); } finally { Buchhaltung.SaveEntrys(); } }
/// <summary> /// Update Data /// </summary> private void UpdateWeek() { try { string oldCashDeskStr = (OldCashTextBox.Text); if (oldCashDeskStr.Contains("€")) { oldCashDeskStr = oldCashDeskStr.Replace("€", ""); } Buchhaltung.CurrWeek.WeekNr = WeekNrTextBox.Text; Buchhaltung.CurrWeek.EditName = NameTextBox.Text; Buchhaltung.CurrWeek.LastChashDesk = Convert.ToDouble(oldCashDeskStr); Buchhaltung.CurrWeek.ExactTime = Convert.ToDateTime(DateTextBox.Text); } catch (Exception ex) { Buchhaltung.Log(ex.Message); Buchhaltung.SaveErrorMsg(ex); } }
/// <summary> /// Fills the TextField when the Num_input is changed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TextBox_TextChanged(object sender, TextChangedEventArgs e) { bool suc = false; try { foreach (DataBoxForGrid d in Buchhaltung.Db) { if (NumInput.Text == Convert.ToString(d.C)) { IdInput.Text = Convert.ToString(d.Id); OutputName.Text = d.Name; AmountInput.Text = Convert.ToString(d.Amount); OnTheHouseInput.Text = Convert.ToString(d.OnTheHouse); suc = true; break; } IdInput.Text = ""; OutputName.Text = ""; AmountInput.Text = ""; OnTheHouseInput.Text = ""; } GetCurrEntry(); if (!suc) { _originalEntry = null; _newEntry = null; } } catch (Exception ex) { Buchhaltung.SaveErrorMsg(ex); } }