Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <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);
            }
        }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
        /// <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);
            }
        }
Exemplo n.º 5
0
        /// <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);
            }
        }
Exemplo n.º 6
0
        /// <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);
            }
        }
Exemplo n.º 7
0
        /// <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);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Logs you in with the correct login information
        /// </summary>
        private void Login()
        {
            if (CheckInput())
            {
                if (CheckLoginInfo(UsernameInput.Text, PasswordInput.Password.ToCharArray()))
                {
                    SetLoggedIn();
                    IsAdmin  = GetIsAdmin(UsernameInput.Text);
                    Username = UsernameInput.Text;

                    if (IsAdmin.Equals(2))
                    {
                        Buchhaltung.Log("Es ist ein error bei der Admin authentifizierung aufgetreten! Sie sind jetzt ein User.");
                    }
                }
                else
                {
                    Buchhaltung.Log("Es konnte keine Benutzername/Passwort kombination gefunden werden");
                }
            }
            else
            {
                Buchhaltung.Log("Keine vollständige Eingabe");
            }
        }
Exemplo n.º 9
0
 /// <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!");
     }
 }
        public OutputOfProducts()
        {
            try
            {
                InitializeComponent();
                LoadDataInWpfWindow();
            }
            catch (Exception e)
            {
                Buchhaltung.Log(e.Message);
                Buchhaltung.SaveErrorMsg(e);
            }

            Topmost = true;
        }
Exemplo n.º 11
0
        /// <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);
            }
        }
Exemplo n.º 12
0
        /// <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!");
            }
        }
Exemplo n.º 13
0
 /// <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);
     }
 }
Exemplo n.º 14
0
 /// <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);
     }
 }
Exemplo n.º 15
0
        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);
            }
        }
Exemplo n.º 16
0
        /// <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();
            }
        }
Exemplo n.º 17
0
        /// <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>
        /// Seaarches the input
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SearchFunc(object sender, TextChangedEventArgs e)
        {
            try
            {
                ProductTable.Items.Filter = o =>
                {
                    if (SearchBox.Text == "")
                    {
                        return(true);
                    }

                    using (Product p = o as Product)
                    {
                        if (p != null && p.Id.ToString() == SearchBox.Text.Trim()
                            | (SearchBox.Text.ToLower().Contains((p.Name).ToLower()))
                            | (SearchBox.Text.ToLower()
                               .Contains(Convert.ToString(p.Price, CultureInfo.CurrentCulture).ToLower()))
                            | (SearchBox.Text.ToLower().Contains(Convert.ToString(p.Tax).ToLower()))
                            | (SearchBox.Text.ToLower().Contains(Convert.ToString(p.Group).ToLower()))
                            | (p.Name.ToLower().Contains(SearchBox.Text.ToLower()))
                            | (Convert.ToString(p.Price, CultureInfo.CurrentCulture).ToLower()
                               .Contains(SearchBox.Text.ToLower()))
                            | (Convert.ToString(p.Tax).ToLower().Contains(SearchBox.Text.ToLower()))
                            | (Convert.ToString(p.Group).ToLower().Contains(SearchBox.Text.ToLower()))
                            | (Convert.ToString(p.KindOfAmount).ToLower().Contains(SearchBox.Text.ToLower())))
                        {
                            return(true);
                        }
                    }

                    return(false);
                };
            }
            catch (Exception ex)
            {
                Buchhaltung.Log(ex.Message + ex.StackTrace);
            }
        }
Exemplo n.º 19
0
        /// <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
        }
Exemplo n.º 20
0
        /// <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);
            }
        }
Exemplo n.º 21
0
        /// <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);
            }
        }