public TrancportInfoViewModel(Trancport trancport, IObjectSetValue window) { _window = window; if (trancport.Id > 0) { EditableTrancport = TinyMapper.Map <Trancport>(trancport); } else { EditableTrancport = new Trancport(); } _trancport = trancport; _models = TracnportInformation.Info.Models; Makes = new ObservableCollection <MakeTrancport>(TracnportInformation.Info.Makes); Categories = new ObservableCollection <TrancportCategory>(TracnportInformation.Info.Categories); TrancportTypes = new ObservableCollection <TrancportType>(TracnportInformation.Info.Types); EngineTypes = new ObservableCollection <EngineType>(TracnportInformation.Info.EngineTypes); MakeTrancport = EditableTrancport?.Make?.Name; // hack crazy }
private void Search_Click(object sender, RoutedEventArgs e) { try { SearchTrancportViewModel searchTrancportViewModel = new SearchTrancportViewModel(); SearchTrancportView searchContractorView = new SearchTrancportView(searchTrancportViewModel); if (searchContractorView.ShowDialog() == true) { Trancport = searchTrancportViewModel.CurrentTrancport; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка"); } }
private void Open_Click(object sender, RoutedEventArgs e) { try { if (Trancport == null) { Trancport = new Trancport(); } TrancportInfoViewModel viewModel = new TrancportInfoViewModel(Trancport, this); TrancportInfoView view = new TrancportInfoView(viewModel); view.ShowDialog(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Не удалось открыть информацию о ТС"); } }
public SaveEntityResult SaveTrancport(Trancport trancport) { try { _WriteLineConsole($"save trancport {trancport.Model?.Name}"); using (var helper = new TransactionInfoHelper()) { helper.SaveTrancport(trancport); return(new SaveEntityResult() { Id = trancport.Id }); } } catch (Exception ex) { _WriteLineError($"save trancport {trancport?.Model?.Name}", ex.Message); return(new SaveEntityResult() { Error = true, Message = ex.Message }); } }
public void SaveTrancport(Trancport trancport) { try { CheckAddRight(); if (trancport.Category?.Id == 0) { trancport.Category = Context.TrancportCategories.GetOrAdd(new Dictionary <string, string>() { { "Name", trancport.Category.Name } }); } if (trancport.EngineType?.Id == 0) { trancport.EngineType = Context.EngineTypes.GetOrAdd(new Dictionary <string, string>() { { "Name", trancport.EngineType.Name } }); } if (trancport.Type?.Id == 0) { trancport.Type = Context.TrancportTypes.GetOrAdd(new Dictionary <string, string>() { { "Name", trancport.Type.Name } }); } if (trancport.Make.Id == 0) { var values = new Dictionary <string, string>() { { "Name", trancport.Make.Name } }; trancport.MakeId = Context.Regions.GetOrAdd(values).Id; trancport.Make = null; } if (trancport.Model.Id == 0) { var values = new Dictionary <string, string>() { { "Name", trancport.Model.Name }, { "MakeId", trancport.MakeId.ToString() } }; trancport.ModelId = Context.Cities.GetOrAdd(values).Id; trancport.Model = null; } Trancport dbTrancport = null; if (trancport.Id != 0) { dbTrancport = Context.Trancports.Get(trancport.Id, x => x.CopyPts); } UserFileCheck.AddOrUpdate(Context, trancport, trancport.CopyPts, dbTrancport?.CopyPts); Context.Trancports.AddOrUpdate(trancport); Context.SaveChanges(); } catch (AccessDeniedException) { throw; } catch (Exception ex) { Logger.Instance.Log("SaveTrancport", ex); throw new Exception("Неудалось сохранить транспорт, обратитесь к администратору"); } }
private void Delete_Click(object sender, RoutedEventArgs e) { Trancport = null; OnPropertyChanged("TrancportSignature"); }
static Trancport NewTrancport(ТРАНСПОРТ trancport, SqlContext newDb) { var tc = new Trancport(); tc.EngineType = newDb.EngineTypes.Local.FirstOrDefault( y => y.Name == trancport.ТИПЫ_ДВИГАТЕЛЕЙ1.наименование) ?? new EngineType() { Name = trancport.ТИПЫ_ДВИГАТЕЛЕЙ1.наименование }; tc.Make = newDb.MakesTrancport.Local.FirstOrDefault( x => x.Name == trancport.МАРКИ1.наименование) ?? new MakeTrancport() { Name = trancport.МАРКИ1.наименование }; tc.Model = newDb.ModelsTrancport.Local.FirstOrDefault( x => x.Name == trancport.МОДЕЛИ1.наименование && x.Make.Name == tc.Make.Name) ?? new ModelTrancport() { Name = trancport.МОДЕЛИ1.наименование, Make = tc.Make }; tc.Category = newDb.TrancportCategories.Local.FirstOrDefault( x => x.Name == trancport.КАТЕГОРИИ_ТРАНСПОРТА1.наименование) ?? new TrancportCategory() { Name = trancport.КАТЕГОРИИ_ТРАНСПОРТА1.наименование }; tc.Type = newDb.TrancportTypes.Local.FirstOrDefault( x => x.Name == trancport.ВИДЫ_ТРАНСПОРТА1.наименование) ?? new TrancportType() { Name = trancport.ВИДЫ_ТРАНСПОРТА1.наименование }; tc.BodyNumber = trancport.кузов; tc.Maker = trancport.изготовитель; tc.Mass = trancport.масса; tc.MaxMass = trancport.макс_масса; tc.Number = trancport.гос_номер; tc.Strong = trancport.мощность; tc.ByPts = trancport.кем_птс; tc.BySts = trancport.кем_стс; tc.ChassisNumber = trancport.шасси; tc.Color = trancport.цвет; tc.DatePts = trancport.дата_птс; tc.DateSts = trancport.дата_стс; tc.NumberPts = trancport.номер_птс; tc.NumberSts = trancport.номер_стс; tc.Pa = trancport.па; tc.Volume = trancport.объем; tc.Vin = trancport.вин; tc.Year = (short)Convert.ToInt32(trancport.год); tc.SerialPts = trancport.серия_птс; tc.SerialSts = trancport.серия_стс; tc.EngineMake = trancport.марка_двиг; if (!string.IsNullOrWhiteSpace(trancport.копия_птс_наим)) { tc.CopyPts = new UserFile() { Name = trancport.копия_птс_наим, File = trancport.копия_птс }; } if (!string.IsNullOrWhiteSpace(trancport.копия_стс_наим)) { tc.CopySts = new UserFile() { Name = trancport.копия_стс_наим, File = trancport.копия_стс }; } return(newDb.Trancports.Local.FirstOrDefault(x => x.Number == tc.Number) ?? tc); }
public void SaveTrancport(Trancport trancport) { _logic.SaveTrancport(trancport); }