private Asset ExtractAndValidateAsset() { var temp = new Asset(); if (!string.IsNullOrWhiteSpace(AssetIdBox.Text)) { temp.AssetId = AssetIdBox.Text.ToLower(); } else { Errors.Add("Asset Id Can't be Empty"); } if (!string.IsNullOrWhiteSpace(AssetNameBox.Text)) { temp.AssetName = AssetNameBox.Text.ToLower(); } else { Errors.Add("Asset Name Can't be Empty"); } if (!string.IsNullOrWhiteSpace(AssetNumberBox.Text)) { temp.AssetNumber = AssetNumberBox.Text.ToLower(); } else { Errors.Add("Asset Number Can't be Empty"); } temp.DateOfPurchase = DateOfPurchasePicker.SelectedDate ?? SelectedAsset.DateOfPurchase; if (!string.IsNullOrWhiteSpace(CostOfAssetBox.Text)) { temp.PurchaseCostOfAsset = NumberHelpers.StringToDouble(CostOfAssetBox.Text); } else { temp.PurchaseCostOfAsset = -55555.55555; Errors.Add("Cost Of Assets Can't be Empty"); } if (!string.IsNullOrWhiteSpace(MonthsToDepreciationBox.Text) && NumberHelpers.IsAllDigits(MonthsToDepreciationBox.Text)) { temp.MonthsToDepreciation = Convert.ToInt32(MonthsToDepreciationBox.Text); } else { Errors.Add("Months To Depreciation is Empty or Not correct"); } if (StatusPicker.SelectedItem != null) { switch (StatusPicker.SelectedIndex) { case 0: temp.AssetStatus = Status.Ready; break; case 1: temp.AssetStatus = Status.NeedService; break; case 2: temp.AssetStatus = Status.InService; break; } } else { Errors.Add("Please select the current status of the Asset"); } if (!string.IsNullOrWhiteSpace(ToolTypeBox.Text)) { temp.ToolType = ToolTypeBox.Text.ToLower(); } else { Errors.Add("Tool Type Can't be Empty"); } if (!string.IsNullOrWhiteSpace(PMVCodeBox.Text)) { temp.PMVCode = PMVCodeBox.Text.ToLower(); } if (!string.IsNullOrWhiteSpace(PoNumberBox.Text)) { temp.PoNumber = PoNumberBox.Text.ToLower(); } if (!string.IsNullOrWhiteSpace(PlateSerialNumberBox.Text)) { temp.PlateSerialNumber = PlateSerialNumberBox.Text.ToLower(); } if (!string.IsNullOrWhiteSpace(CalibrationCertificationNumberBox.Text)) { temp.CalibrationCertificationNumber = CalibrationCertificationNumberBox.Text.ToLower(); } temp.CalibrationCertificationDate = CalibrationCertificationDatePicker.SelectedDate ?? SelectedAsset.CalibrationCertificationDate; temp.AssetPictureBase64 = !string.IsNullOrWhiteSpace(AssetImageBase64) ? AssetImageBase64 : SelectedAsset.AssetPictureBase64; temp.CalibrationCertificationPictureBase64 = !string.IsNullOrWhiteSpace(CalibrationCertificateBase64) ? CalibrationCertificateBase64 : SelectedAsset.CalibrationCertificationPictureBase64; temp.AssetPictureFormat = !string.IsNullOrWhiteSpace(AssetImageFormat) ? AssetImageFormat : SelectedAsset.AssetPictureFormat; temp.CalibrationCertificationPictureFormat = !string.IsNullOrWhiteSpace(CalibrationCertificateFormat) ? CalibrationCertificateFormat : SelectedAsset.CalibrationCertificationPictureFormat; return(temp); }
private void SaveBTN_OnClick(object sender, RoutedEventArgs e) { var pendingRepair = new Repair() { AssetId = AssetId }; if (!string.IsNullOrWhiteSpace(RepairLocationBox.Text)) { pendingRepair.Location = RepairLocationBox.Text.ToLower(); } else { MessageBox.Show("Repair Location can't be empty"); return; } if (!string.IsNullOrWhiteSpace(LaborCostBox.Text)) { pendingRepair.LaborAmount = NumberHelpers.StringToDouble(LaborCostBox.Text); } else { MessageBox.Show("Labor Cost can't be empty"); return; } if (!string.IsNullOrWhiteSpace(SparePartsCostBox.Text)) { pendingRepair.SparePartsAmount = NumberHelpers.StringToDouble(SparePartsCostBox.Text); } else { MessageBox.Show("Spare Parts Cost can't be empty"); return; } if (RepairDatePicker.SelectedDate.HasValue) { pendingRepair.RepairDate = RepairDatePicker.SelectedDate.Value; } else { MessageBox.Show("Repair Dates can't be empty"); return; } using (var dbContext = new DatabaseContext()) { try { pendingRepair.AddedDate = DateTime.Now; dbContext.Add(pendingRepair); dbContext.SaveChanges(); if (pendingRepair.Id < 0) { MessageBox.Show("Error in Addition"); } else { MessageBox.Show("Repair Added"); ClearBoxes(); SetCallerWindowRefresh(); } } catch (Exception exception) { Console.WriteLine(exception); MessageBox.Show("Error in Addition"); } } }
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; } }