예제 #1
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");
            }
        }
예제 #2
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");
            }
        }
예제 #3
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");
            }
        }