Ejemplo n.º 1
0
        /// <summary>
        ///   <para>Deletes selected product from the database</para>
        /// </summary>
        /// <param name="row">The row.</param>
        private async void DeleteProduct(DataRowView row)
        {
            try
            {
                string message = "Er du sikker du vil slette dette produkt?";
                string caption = "Advarsel";
                System.Windows.MessageBoxButton buttons = System.Windows.MessageBoxButton.YesNo;
                System.Windows.MessageBoxResult result;

                // Displays the MessageBox.
                result = MessageBox.Show(message, caption, buttons);
                switch (result == System.Windows.MessageBoxResult.Yes)
                {
                case true:
                {
                    var query = $"DELETE FROM `girozilla`.`products` WHERE `Product_ID` = {row.Row.ItemArray[0].ToString()}";

                    AsyncMySqlHelper.UpdateDataToDatabase(query, "ConnString").Wait();

                    MessageBox.Show($"Produktet nr:{row.Row.ItemArray[0].ToString()} er nu slettet");

                    Log.Information($"Successfully deleted product #{row.Row.ItemArray[0].ToString()}");
                    break;
                }
                }
                await Task.FromResult(true);
            }
            catch (Exception ex)
            {
                await Task.FromResult(false);

                MessageBox.Show("En uventet fejl er sket", "FEJL");
                Log.Error(ex, "Unexpected Error");
            }
        }
Ejemplo n.º 2
0
        /// <summary>Marks the selected service data as payed.</summary>
        private async void MarkServiceDataAsPayed(DataRowView row)
        {
            try
            {
                switch (string.IsNullOrWhiteSpace(row["Betaling"].ToString()) || row["Betaling"].ToString() != PaymentMethod.SelectedValue.ToString())
                {
                case true:
                {
                    var id = row["ID"].ToString();
                    var paymentFormIndex = PaymentMethod.SelectedIndex;

                    switch (paymentFormIndex != 0 && paymentFormIndex != -1)
                    {
                    case true:
                    {
                        var paymentForm = PaymentMethod.SelectedValue;

                        var query = $"UPDATE `GiroZilla`.`services` SET `service_PAYMENTFORM` = '{paymentForm}' WHERE (`service_ID` = '{id}');";

                        AsyncMySqlHelper.UpdateDataToDatabase(query, "ConnString").Wait();

                        UpdateServiceData();

                        MessageBox.Show($"Betaling til fejning nr:{id} er nu opdateret");

                        Log.Information($"Successfully set service #{id} as payed with: {paymentForm}");
                        break;
                    }

                    default:
                    {
                        MessageBox.Show($"Venligst vælg en betalingsform");
                        break;
                    }
                    }
                    break;
                }

                default:
                {
                    MessageBox.Show($"Denne Fejning allerede står som betalt");
                    break;
                }
                }
                await Task.FromResult(true);
            }
            catch (Exception ex)
            {
                await Task.FromResult(false);

                MessageBox.Show("Venligst vælg en fejning");
                Log.Warning(ex, "No service picked");
            }
        }
Ejemplo n.º 3
0
        /// <summary>Updates data to the database.</summary>
        private async void UpdateData()
        {
            try
            {
                AsyncMySqlHelper.UpdateSetToDatabase("SELECT * FROM `all_products`", data.Tables[0].DataSet, "ConnString");
                await Task.FromResult(true);

                Log.Information($"Successfully updated product data");
            }
            catch (Exception ex)
            {
                await Task.FromResult(false);

                Log.Error(ex, "An error occured while updating data");
            }
        }
Ejemplo n.º 4
0
        /// <summary>Updates the database with the changes made to the ServiceGrid.</summary>
        private async void UpdateServiceData()
        {
            try
            {
                AsyncMySqlHelper.UpdateSetToDatabase($"SELECT * FROM `user_services`", data.Tables[0].DataSet, "ConnString");
                await Task.FromResult(true);

                Log.Information("Successfully updated service data");
            }
            catch (Exception ex)
            {
                await Task.FromResult(false);

                Log.Error(ex, "Something went wrong updating the service data");
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        ///   <para>Add new product data to the database</para>
        /// </summary>
        /// <returns>success</returns>
        private async Task <bool> AddNewProductData()
        {
            try
            {
                switch (!string.IsNullOrWhiteSpace(ProductNameTextBox.Text) &&
                        !string.IsNullOrWhiteSpace(ProductPriceTextBox.Text))
                {
                case true:
                {
                    var query = $"INSERT INTO `products` " +
                                $"(" +
                                $"`Product_NAME`, " +
                                $"`Product_PRICE`, " +
                                $"`Product_DESCRIPTION` " +
                                $") " +
                                $"VALUES " +
                                $"(" +
                                $"'{ProductNameTextBox.Text}', " +
                                $"'{ProductPriceTextBox.Text.Replace(",", ".")}', " +
                                $"'{ProductDescriptionTextBox.Text}' " +
                                $");";

                    AsyncMySqlHelper.SetDataToDatabase(query, "ConnString").Wait();

                    await Task.FromResult(true);

                    Log.Information($"Successfully added a new product");
                    return(true);
                }

                default:
                {
                    MessageBox.Show("Data Mangler");
                    break;
                }
                }
            }
            catch (Exception ex)
            {
                await Task.FromResult(false);

                Log.Error(ex, "Unexpected Error");
            }

            return(false);
        }
Ejemplo n.º 6
0
        private async void InsertInvoiceCustomerInfo(DataRowView rowView)
        {
            try
            {
                CustomerInfoAddress.Text        = "";
                CustomerInfoFirstname.Text      = "";
                CustomerInfoLastname.Text       = "";
                CustomerInfoID.Text             = "";
                CustomerInfoNeededServices.Text = "";
                CustomerInfoMail.Text           = "";
                CustomerInfoMobile.Text         = "";
                CustomerInfoHome.Text           = "";
                CustomerInfoServicesGotten.Text = "";

                var query = $"SELECT * FROM `customers` WHERE `Customer_ID` = {rowView.Row.ItemArray[1].ToString()}";

                customerExists = await AsyncMySqlHelper.CheckDataFromDatabase(query, "ConnString");

                var userData = await AsyncMySqlHelper.GetDataFromDatabase <Customer>(query, "ConnString");

                foreach (Customer row in userData)
                {
                    CustomerInfoAddress.Text        = row.Customer_ADDRESS;                    // 1
                    CustomerInfoFirstname.Text      = row.Customer_FIRSTNAME;                  // 2
                    CustomerInfoLastname.Text       = row.Customer_LASTNAME;                   // 3
                    CustomerInfoID.Text             = row.Customer_ID.ToString();              // 4
                    CustomerInfoNeededServices.Text = row.Customer_SERVICES_NEEDED.ToString(); // 5
                    CustomerInfoMail.Text           = row.Customer_EMAIL;                      // 6
                    CustomerInfoMobile.Text         = row.Customer_PHONE_MOBILE;               // 7
                    CustomerInfoHome.Text           = row.Customer_PHONE_HOME;                 // 8
                }

                query = $"SELECT * FROM `services` WHERE `Customer_ID` = {rowView.Row.ItemArray[1].ToString()} AND `Service_YEAR` = {DateTime.Now.Year}";

                var serviceData = await AsyncMySqlHelper.GetDataFromDatabase <Service>(query, "ConnString");

                CustomerInfoServicesGotten.Text = serviceData.Count.ToString();
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Unexpected Error");
            }
        }
Ejemplo n.º 7
0
        /// <summary>Deletes the selected service from ServiceGrid.</summary>
        /// <param name="row">The row.</param>
        private async void DeleteSelectedServices(DataRowView[] rows)
        {
            try
            {
                string message = $"Er du sikker du vil slette {rows.Count()} fejninger?";
                string caption = "Advarsel";
                System.Windows.MessageBoxButton buttons = System.Windows.MessageBoxButton.YesNo;
                System.Windows.MessageBoxResult result;

                // Displays the MessageBox.
                result = MessageBox.Show(message, caption, buttons);
                switch (result == System.Windows.MessageBoxResult.Yes)
                {
                case true:
                {
                    foreach (DataRowView row in rows)
                    {
                        var query = $"DELETE FROM `girozilla`.`service-products` WHERE `Service-Product_SERVICEID` = {row.Row.ItemArray[0].ToString()}";

                        AsyncMySqlHelper.UpdateDataToDatabase(query, "ConnString").Wait();

                        query = $"DELETE FROM `girozilla`.`services` WHERE `Service_ID` = {row.Row.ItemArray[0].ToString()}";

                        AsyncMySqlHelper.UpdateDataToDatabase(query, "ConnString").Wait();

                        Log.Information($"Successfully deleted service #{row.Row.ItemArray[0]}");
                    }
                    MessageBox.Show($"{rows.Length} Fejninger blev slettet");
                    break;
                }
                }
                await Task.FromResult(true);
            }
            catch (Exception ex)
            {
                await Task.FromResult(false);

                MessageBox.Show("En uventet fejl er sket", "FEJL");
                Log.Error(ex, "Unexpected Error");
            }
        }
Ejemplo n.º 8
0
        /// <summary>Sets the products from the selected service to ProductsGrid.</summary>
        /// <param name="row">The Selected Row in the ServiceGrid.</param>
        private async void SetProductsInGrid(DataRowView row)
        {
            try
            {
                var query = $"SELECT * FROM `all_service-products` WHERE `Fejnings ID` = {row.Row.ItemArray[0].ToString()}";

                productData = AsyncMySqlHelper.GetSetFromDatabase(query, "ConnString").Result;

                ProductGrid.ItemsSource = productData.Tables[0].DefaultView;

                await Task.FromResult(true);

                Log.Information($"Successfully filled ProductGrid ItemSource");
            }
            catch (Exception ex)
            {
                await Task.FromResult(false);

                Log.Error(ex, "Unexpected Error");
            }
        }
Ejemplo n.º 9
0
        /// <summary>Sets data from the database to ProductGrid.</summary>
        private async void SetData()
        {
            try
            {
                var input = ClearTextSearch.Text;
                var query = "SELECT * FROM `all_products`";

                switch (!string.IsNullOrWhiteSpace(input))
                {
                case true:
                {
                    query +=
                        "WHERE " +
                        "(" +
                        "ID  " +
                        "LIKE " +
                        $"'%{input}%'" +
                        $") " +

                        $"UNION " +

                        "SELECT * FROM `all_products` " +
                        $"WHERE " +
                        "(" +
                        "Navn " +
                        "LIKE " +
                        $"'%{input}%'" +
                        $") " +

                        $"UNION " +

                        "SELECT * FROM `all_products` " +
                        $"WHERE " +
                        "(" +
                        "Pris " +
                        "LIKE " +
                        $"'%{input}%'" +
                        $") " +

                        $"UNION " +

                        "SELECT * FROM `all_products` " +
                        $"WHERE " +
                        "(" +
                        "Beskrivelse " +
                        "LIKE " +
                        $"'%{input}%'" +
                        $") ";
                    break;
                }
                }

                data = await AsyncMySqlHelper.GetSetFromDatabase(query, "ConnString");

                ProductGrid.ItemsSource = data.Tables[0].DefaultView;

                Log.Information($"Successfully filled ProductsGrid ItemSource");
            }
            catch (Exception ex)
            {
                await Task.FromResult(false);

                Log.Warning(ex, "Something went wrong setting the data for the ProductGrid");
            }
        }
Ejemplo n.º 10
0
        /// <summary>Sets the data to the ServiceGrid.</summary>
        private async void SetData()
        {
            try
            {
                var input = ClearTextSearch.Text;
                var query = "SELECT * FROM `user_services` ";

                switch (!string.IsNullOrWhiteSpace(input))
                {
                case true:
                {
                    query +=
                        $"WHERE " +
                        "(" +
                        "`ID` " +
                        "LIKE " +
                        $"'%{input}%'" +
                        $") " +

                        $"UNION " +

                        "SELECT * FROM `user_services` " +
                        $"WHERE " +
                        "(" +
                        "`Kunde ID` " +
                        "LIKE " +
                        $"'%{input}%'" +
                        $") " +

                        $"UNION " +

                        "SELECT * FROM `user_services` " +
                        "WHERE " +
                        "(" +
                        "`Nummer` " +
                        "LIKE " +
                        $"'%{input}%'" +
                        $") ";

                    UnpayedOnlyCheck.IsEnabled = true;
                    switch (PaySearch.SelectedIndex != 0 && PaySearch.SelectedIndex != -1)
                    {
                    case true:
                    {
                        UnpayedOnlyCheck.IsEnabled = false;
                        UnpayedOnlyCheck.IsChecked = false;
                        query = query.Replace(") ", $" AND Betaling = '{PaySearch.SelectedItem.ToString()}') ");
                        break;
                    }

                    default:
                    {
                        switch (UnpayedOnlyCheck.IsChecked == true)
                        {
                        case true:
                        {
                            query = query.Replace(") ", $" AND Betaling = '') ");
                            break;
                        }
                        }
                        break;
                    }
                    }

                    switch (ThisYearOnlyCheck.IsChecked == true)
                    {
                    case true:
                    {
                        query = query.Replace(") ", $" AND Aar = '{InvoiceSearchYearValue.Value.ToString()}') ");
                        break;
                    }
                    }
                    break;
                }

                default:
                {
                    switch (PaySearch.SelectedIndex != 0 && PaySearch.SelectedIndex != -1)
                    {
                    case true:
                    {
                        query += $"WHERE Betaling = '{PaySearch.SelectedItem.ToString()}'";
                        break;
                    }

                    default:
                    {
                        switch (UnpayedOnlyCheck.IsChecked == true)
                        {
                        case true:
                        {
                            query += $"WHERE Betaling = '' ";

                            switch (ThisYearOnlyCheck.IsChecked == true)
                            {
                            case true:
                            {
                                query += $"AND Aar = '{InvoiceSearchYearValue.Value.ToString()}' ";
                                break;
                            }
                            }
                            break;
                        }

                        default:
                        {
                            switch (ThisYearOnlyCheck.IsChecked == true)
                            {
                            case true:
                            {
                                try
                                {
                                    query += $"WHERE Aar = '{InvoiceSearchYearValue.Value.ToString()}' ";
                                }
                                catch (NullReferenceException)
                                {
                                    //Do Nothing
                                }
                                break;
                            }
                            }
                            break;
                        }
                        }
                        break;
                    }
                    }
                    break;
                }
                }

                data = await AsyncMySqlHelper.GetSetFromDatabase(query, "ConnString");

                try
                {
                    ServiceGrid.ItemsSource = data.Tables[0].DefaultView;
                    ProductGrid.ItemsSource = null;
                    Log.Information("Successfully filled ServiceGrid ItemSource");
                }
                catch (NullReferenceException)
                {
                    //Do Nothing
                }
            }
            catch (Exception ex)
            {
                Log.Warning(ex, "Something went wrong setting the data for the ServiceGrid");
            }
        }
Ejemplo n.º 11
0
        /// <summary>  Verifies the license to check if the license has expired or don't exist.</summary>
        private void CheckLicense()
        {
            try
            {
                Log.Information("Checking License");

                const string getList  = "SELECT * FROM licenses";
                var          licenses = AsyncMySqlHelper.ReturnStringList(getList, "LicenseConnString").Result.ToList();

#if DEBUG
                var localLicense = PropertiesExtension.Get <string>("License");
#else
                var localLicense = RegHelper.Readvalue(@"Software\", "GiroZilla", "License");
#endif

                switch (!string.IsNullOrWhiteSpace(localLicense))
                {
                case true:
                {
                    Log.Information("Local license found");

                    var count = 1;

                    foreach (var s in licenses)
                    {
                        switch (!IsLicenseVerified)
                        {
                        case true:
                        {
                            _isCorrect = Hashing.Confirm(s, localLicense);

                            switch (_isCorrect)
                            {
                            case true:
                            {
                                var searchLicenseId = $"SELECT `License_VALUE` FROM `licenses` WHERE `License_ID`='{count}'";

                                var license    = AsyncMySqlHelper.GetString(searchLicenseId, "LicenseConnString").Result;
                                var query      = $"SELECT * FROM `licenses` WHERE `License_VALUE`='{license}' AND `License_USED` > 0";
                                var canConnect = AsyncMySqlHelper.CheckDataFromDatabase(query, "LicenseConnString").Result;

                                switch (canConnect)
                                {
                                case true:
                                {
                                    _connectionStatus = 1;
                                    break;
                                }

                                case false:
                                {
                                    _connectionStatus = 0;
                                    break;
                                }
                                }

                                switch (_connectionStatus)
                                {
                                case 1:
                                {
                                    LicenseDialog.IsOpen = false;
                                    IsLicenseVerified    = true;
                                    Log.Information(@"GiroZilla v" + FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion + " loaded");
                                    break;
                                }

                                case 0:
                                {
                                    LicenseDialog.IsOpen = true;
                                    IsLicenseVerified    = false;

                                    switch (!string.IsNullOrWhiteSpace(localLicense))
                                    {
                                    case true:
                                    {
                                        Log.Warning("This license is invalid and wil be reset");

                                        ErrorText.Text = "Din nuværende licens er ugyldig & vil blive nulstillet";

#if DEBUG
                                        PropertiesExtension.Set("License", "");
#else
                                        RegHelper.SetRegValue(@"Software\GiroZilla", "License", "", RegistryValueKind.String);
#endif
                                        break;
                                    }
                                    }

                                    break;
                                }

                                default:
                                {
                                    LicenseDialog.IsOpen = true;
                                    IsLicenseVerified    = false;

                                    switch (!string.IsNullOrWhiteSpace(localLicense))
                                    {
                                    case true:
                                    {
                                        Log.Warning("Something went wrong validating this license");

                                        ErrorText.Text = "Kunne ikke validere din licens prøv igen senere";
                                        break;
                                    }

                                    default:
                                    {
                                        Log.Warning("Something went wrong validating this license (String empty or null)");

                                        ErrorText.Text = "Kunne ikke validere din licens";
                                        break;
                                    }
                                    }
                                    break;
                                }
                                }
                                break;
                            }

                            case false:
                            {
                                count++;
                                break;
                            }
                            }
                            break;
                        }
                        }
                    }
                    break;
                }

                default:
                {
                    LicenseDialog.IsOpen = true;
                    IsLicenseVerified    = false;

                    Log.Warning("The license was not found");

                    ErrorText.Text = "Licensen blev ikke fundet";
                    break;
                }
                }
            }
            catch (Exception ex)
            {
                _connectionStatus = 2;

                Log.Error(ex, "Unexpected Error");
            }
        }