/// <summary> /// Checks if given login information is correct and returns value /// </summary> /// <param name="name">Username input</param> /// <param name="pwd">Password input</param> /// <returns>true if given login infomation is correct</returns> private bool CheckLoginInfo(string name, char[] pwd) { try { string query = "SELECT password FROM user WHERE username LIKE @name"; MySqlCommand cmd = new MySqlCommand(query, Connection) { CommandTimeout = 60 }; Connect(); cmd.Parameters.AddWithValue("@name", name); cmd.Prepare(); string retVal = cmd.ExecuteScalar() == null ? "." : cmd.ExecuteScalar().ToString(); CloseConnection(); return(!retVal.Equals(".") && Hash.CheckPassword(GetStringFromChar(pwd), retVal)); } catch (Exception ex) { Buchhaltung.Log(ex.Message); Buchhaltung.SaveErrorMsg(ex); } return(false); }
/// <summary> /// Gets if the user is an admin /// </summary> /// <param name="name"></param> /// <returns>1 if admin/0 if user/2 if error</returns> private int GetIsAdmin(string name) { try { string query = "SELECT isAdmin FROM user WHERE @name LIKE username"; MySqlCommand cmd = new MySqlCommand(query, Connection) { CommandTimeout = 60 }; Connect(); cmd.Parameters.AddWithValue("@name", name); cmd.Prepare(); string retVal = cmd.ExecuteScalar().ToString(); CloseConnection(); return(Convert.ToInt32(retVal)); } catch (Exception ex) { Buchhaltung.SaveErrorMsg(ex); Buchhaltung.Log(ex.Message); } return(2); }
/// <summary> /// Saves all Product /// </summary> public static void SaveProductIntoSql(Product p) { try { string query = "INSERT INTO `Product`(`Id`, `Name`, `Price`, `Tax`, `Amount`, `KindOfAmount`, `GroupOfProduct`) VALUES(@id,@name,@price,@tax,@amount,@kindofamount,@groupofproduct)"; CreateConnection(); _connection.Open(); MySqlCommand cmd = new MySqlCommand(query, _connection); cmd.Parameters.AddWithValue("@id", p.Id); cmd.Parameters.AddWithValue("@name", p.Name); cmd.Parameters.AddWithValue("@price", p.Price); cmd.Parameters.AddWithValue("@tax", p.Tax); cmd.Parameters.AddWithValue("@amount", p.Amount); cmd.Parameters.AddWithValue("@kindofamount", p.KindOfAmount); cmd.Parameters.AddWithValue("@groupofproduct", p.Group); cmd.Prepare(); cmd.ExecuteScalar(); CloseConnection(); } catch (Exception ex) { Buchhaltung.SaveErrorMsg(ex); Buchhaltung.Log(ex.Message); } }
/// <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> /// Checks input and adds to the Bank in the current day /// </summary> private void Save() { try { if (ToBankInput.Text != "") { string toBank = ToBankInput.Text; if (toBank.Contains("€")) { toBank = toBank.Replace("€", ""); } Buchhaltung.CurrWeek.GetCurrentDay().AddBank(Convert.ToDouble(toBank)); Close(); } else { Buchhaltung.Log("Felder sind leer!"); } } catch (Exception ex) { Buchhaltung.Log(ex.Message); Buchhaltung.SaveErrorMsg(ex); } }
public OutputOfProducts() { try { InitializeComponent(); LoadDataInWpfWindow(); } catch (Exception e) { Buchhaltung.Log(e.Message); Buchhaltung.SaveErrorMsg(e); } Topmost = true; }
/// <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> /// For a new Entry to add it to the correct Day /// </summary> /// <param name="e"></param> public void GetCurrentDayAndAddEntry(Entry e) { try { foreach (Day d in DaysInWeek) { if (d.Name == Buchhaltung.CurrDay) { d.AddEntry(e); break; } } } catch (Exception x) { Buchhaltung.SaveErrorMsg(x); } }
/// <summary> /// Loads groups into dropdown /// </summary> private void LoadGroupDropBox() { try { for (int i = 0; i < _allProductsSplitted.GetLength(0) - 1; i++) { if (!GroupDropDown.Items.Contains(_allProductsSplitted[i, 6])) { GroupDropDown.Items.Add(_allProductsSplitted[i, 6]); } } } catch (Exception e) { Buchhaltung.Log(e.Message); Buchhaltung.SaveErrorMsg(e); } }
/// <summary> /// Load kind of amount into dropdown /// </summary> private void LoadChangeOfAmount() { try { for (int i = 0; i < _allProductsSplitted.GetLength(0) - 1; i++) { if (!KindOfAmoutDropDown.Items.Contains(_allProductsSplitted[i, 5])) { KindOfAmoutDropDown.Items.Add(_allProductsSplitted[i, 5]); } } } catch (Exception e) { Buchhaltung.Log(e.Message); Buchhaltung.SaveErrorMsg(e); } }
private static MySqlConnection _connection; //sql connection #endregion public NewProduct() { InitializeComponent(); try { IdOfProduct.Text += Buchhaltung.Products.Count.Equals(0) ? 1 : Buchhaltung.Products[Buchhaltung.Products.Count - 1].Id + 1; LoadProducts(); LoadTaxDropDown(); LoadKindOfAmounDropBox(); LoadGroupDropBox(); Topmost = true; } catch (Exception e) { Buchhaltung.SaveErrorMsg(e); Buchhaltung.Log(e.Message); } }
/// <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> /// Gets total sales /// </summary> /// <returns></returns> private static double GetSales() { try { double sales = 0; foreach (Day d in Buchhaltung.CurrWeek.DaysInWeek) { foreach (Entry e in d.Entrys) { sales += e.Price; } } return(sales); } catch (Exception ex) { Buchhaltung.Log(ex.Message); Buchhaltung.SaveErrorMsg(ex); } return(0); //error }
/// <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); } }
/// <summary> /// Checks the input and saves it into Buchhaltung /// </summary> public void ProgressProductAndCallSave() { try { //removes the % and € symbol from the input string tax = TaxOfProduct.Text, price = PriceOfProduct.Text; if (tax.Contains("%")) { tax = tax.Replace("%", ""); } if (price.Contains("€")) { price = price.Replace("€", ""); } if (tax.Contains(".")) { tax = tax.Replace(".", ","); } if (price.Contains(".")) { price = price.Replace(".", ","); } //trims them down tax = tax.Trim(); price = price.Trim(); double dTax = Convert.ToDouble(tax); if (dTax > 0 && dTax < 101) { Product p = Buchhaltung.Products.Count.Equals(0) ? new Product(NameOfTheProdukt.Text, Convert.ToDouble(price), Convert.ToInt32(tax), Convert.ToDouble(AmountOfProduct.Text), KindOfAmount.Text, 1, Group.Text) : new Product(NameOfTheProdukt.Text, Convert.ToDouble(price), Convert.ToInt32(tax), Convert.ToDouble(AmountOfProduct.Text), KindOfAmount.Text, Buchhaltung.Products.Max().Id + 1, Group.Text); if (CheckIfProductExists(p)) { if (Buchhaltung.ShowYesNoMessageBox( "Das Produkt existiert bereits! Bist du sicher das du es trotzdem hinzufügen möchtest?", "Produkt existiert schon")) { Buchhaltung.Products.Add(p); SaveProductIntoSql(p); } } else { Buchhaltung.Products.Add(p); SaveProductIntoSql(p); } Close(); } else { Buchhaltung.Log("Steuer ist nicht im 0 - 100% Bereich!"); } } catch (Exception e) { Buchhaltung.SaveErrorMsg(e); Buchhaltung.Log(e.Message); } }
/// <summary> /// Checks the input and saves it into Buchhaltung /// </summary> public void SaveProduct() { bool taxCheck = false; bool closeCheck = false; try { //removes the % and € symbol from the input string tax = TaxOfProduct.Text, price = PriceOfProduct.Text; if (tax.Contains("%")) { tax = tax.Replace("%", ""); } if (price.Contains("€")) { price = price.Replace("€", ""); } if (tax.Contains(".")) { tax = tax.Replace(".", ","); } if (price.Contains(".")) { price = price.Replace(".", ","); } //trims them down tax = tax.Trim(); price = price.Trim(); double dTax = Convert.ToDouble(tax); if (dTax > 0 && dTax < 101) { taxCheck = true; } //adds the product (Checks the product id) if (Buchhaltung.Products.Max() != null && taxCheck) { Product p = new Product(NameOfTheProdukt.Text, Convert.ToDouble(price), Convert.ToInt32(tax), Convert.ToDouble(AmountOfProduct.Text), KindOfAmount.Text, Buchhaltung.Products.Max().Id, Group.Text); if (CheckIfProductExists(p)) { if (Buchhaltung.ShowYesNoMessageBox( "Das Produkt existiert bereits! Bist du sicher das du es trotzdem hinzufügen möchtest?", "Produkt existiert schon")) { Buchhaltung.Products.Add(p); closeCheck = true; } } else { Buchhaltung.Products.Add(p); closeCheck = true; } } else if (taxCheck) { Product p = new Product(NameOfTheProdukt.Text, Convert.ToDouble(price), Convert.ToInt32(tax), Convert.ToDouble(AmountOfProduct.Text), KindOfAmount.Text, 0, Group.Text); if (CheckIfProductExists(p)) { if (Buchhaltung.ShowYesNoMessageBox( "Das Produkt existiert bereits! Bist du sicher das du es trotzdem hinzufügen möchtest?", "Produkt existiert schon")) { Buchhaltung.Products.Add(p); closeCheck = true; } } else { Buchhaltung.Products.Add(p); closeCheck = true; } } if (taxCheck && closeCheck) { Buchhaltung.SaveProducts(); Close(); } else { Buchhaltung.Log("Ungültige Prozente!"); } } catch (Exception e) { Buchhaltung.Log(e.Message); Buchhaltung.SaveErrorMsg(e); } }