Exemple #1
0
        private void NotifyBTN_OnClick(object sender, RoutedEventArgs e)
        {
            using (var dbContext = new DatabaseContext())
            {
                try
                {
                    var db = dbContext.Assets.Where(x =>
                                                    x.CalibrationCertificationDate.Date >= DateTime.Today.Date &&
                                                    x.CalibrationCertificationDate.Date < DateTime.Today.Date.AddDays(10.0)).ToList();
                    ExpiredAssets.Clear();
                    foreach (var asset in db)
                    {
                        ExpiredAssets.Add(new AssetDto(asset));
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                    MessageBox.Show("Error Loading Assets ");
                }
            }

            if (ExpiredAssets.Count > 0)
            {
                var window = new ShowExpiryNotificationWindow(ExpiredAssets, 0.0);
                window.Show();
            }
            else
            {
                MessageBox.Show("There are no assets to expire this week");
            }
        }
Exemple #2
0
        private void SearchBTN_OnClick(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(QueryTXT.Text))
            {
                MessageBox.Show("There is no text to search for");
                return;
            }

            var      query    = QueryTXT.Text;
            DateTime?toDate   = DateTime.Today;
            DateTime?fromDate = DateTime.Today;

            if (FromDatePicker.SelectedDate == null)
            {
                using (var dbContext = new DatabaseContext())
                {
                    try
                    {
                        var db = dbContext.Assets.OrderBy(x => x.DateOfPurchase).First();
                        fromDate = db.DateOfPurchase;
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine(exception);
                        MessageBox.Show("Error Loading Assets for date");
                    }
                }
            }
            else
            {
                fromDate = FromDatePicker.SelectedDate;
            }


            if (ToDatePicker.SelectedDate != null)
            {
                toDate = ToDatePicker.SelectedDate;
            }
            //DateTime date2Compare = new DateTime(2017, 1, 20);
            //list.Where(x => myDateColumn >= date2Compare && x.myTextColumn.Contains('abc'));
            using (var dbContext = new DatabaseContext())
            {
                var res = new List <AssetDto>();
                try
                {
                    switch (PropertyPicker.SelectedIndex)
                    {
                    case 0:
                        res = AssetGridDataSource.Where(x =>
                                                        x.DateOfPurchase >= fromDate && x.DateOfPurchase <= toDate &&
                                                        x.AssetId.Contains(query)).ToList();
                        break;

                    case 1:
                        res = AssetGridDataSource.Where(x =>
                                                        x.DateOfPurchase >= fromDate && x.DateOfPurchase <= toDate &&
                                                        x.AssetNumber.Contains(query)).ToList();
                        break;

                    case 2:
                        res = AssetGridDataSource.Where(x =>
                                                        x.DateOfPurchase >= fromDate && x.DateOfPurchase <= toDate &&
                                                        x.AssetName.Contains(query)).ToList();
                        break;

                    case 3:
                        res = AssetGridDataSource.Where(x =>
                                                        x.DateOfPurchase >= fromDate && x.DateOfPurchase <= toDate &&
                                                        x.PMVCode.Contains(query)).ToList();
                        break;

                    case 4:
                        res = AssetGridDataSource.Where(x =>
                                                        x.DateOfPurchase >= fromDate && x.DateOfPurchase <= toDate &&
                                                        x.CurrentLocation.Contains(query)).ToList();
                        break;

                    case 5:
                        res = AssetGridDataSource.Where(x =>
                                                        x.DateOfPurchase >= fromDate && x.DateOfPurchase <= toDate &&
                                                        x.PoNumber.Contains(query)).ToList();
                        break;

                    case 6:
                        res = AssetGridDataSource.Where(x =>
                                                        x.DateOfPurchase >= fromDate && x.DateOfPurchase <= toDate &&
                                                        x.PlateSerialNumber.Contains(query)).ToList();
                        break;

                    case 7:
                        res = AssetGridDataSource.Where(x =>
                                                        x.DateOfPurchase >= fromDate && x.DateOfPurchase <= toDate &&
                                                        Math.Abs(x.PurchaseCostOfAsset - NumberHelpers.StringToDouble(query)) < 0.05).ToList();
                        break;

                    case 8:
                        res = AssetGridDataSource.Where(x =>
                                                        x.DateOfPurchase >= fromDate && x.DateOfPurchase <= toDate &&
                                                        x.AssetStatus.ToString().Contains(query)).ToList();
                        break;

                    case 9:
                        res = AssetGridDataSource.Where(x =>
                                                        x.DateOfPurchase >= fromDate && x.DateOfPurchase <= toDate &&
                                                        x.ToolType.Contains(query)).ToList();
                        break;

                    case 10:
                        res = AssetGridDataSource.Where(x =>
                                                        x.DateOfPurchase >= fromDate && x.DateOfPurchase <= toDate &&
                                                        x.CalibrationCertificationNumber.Contains(query)).ToList();
                        break;
                    }

                    if (res.Count > 0)
                    {
                        var totalPayment = CalculateTotalPaymentOfInterval(res, fromDate, toDate);
                        var window       =
                            new ShowExpiryNotificationWindow(new ObservableCollection <AssetDto>(res), totalPayment);
                        window.Show();
                    }
                    else
                    {
                        MessageBox.Show("No results were found");
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                    MessageBox.Show("Error Loading Assets for date");
                }

                QueryTXT.Text = string.Empty;
            }
        }