public void Execute(object parameter) { this.execute(parameter); try { Image image = (Image)parameter; OpenFileDialog OPF = new OpenFileDialog(); if (OPF.ShowDialog() == DialogResult.OK) { image.Source = BitmapFrame.Create(new Uri(OPF.FileName)); byte[] imageData = null; FileInfo fInfo = new FileInfo(OPF.FileName); long numBytes = fInfo.Length; FileStream fStream = new FileStream(OPF.FileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fStream); imageData = br.ReadBytes((int)numBytes); string iImageExtension = (Path.GetExtension(OPF.FileName)).Replace(".", "").ToLower(); ViewModelService.Resolve <WorkBrandWindowViewModel>().Logotype = imageData; ViewModelService.Resolve <WorkBrandWindowViewModel>().ImageType = iImageExtension; parameter = image; } } catch (Exception exp) { MessageBox.Show("Вы загрузили не изображение.\nДобавьте изображение ещё раз"); } }
public void Execute(object parameter) { this.execute(parameter); ViewModelService.Register <WorkBrandWindowViewModel>(); ViewService.Register <WorkBrandWindow>(); ViewService.Resolve <WorkBrandWindow>(ViewModelService.Resolve <WorkBrandWindowViewModel>()).Show(); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); var currentDomain = AppDomain.CurrentDomain; var basePath = currentDomain.BaseDirectory.Substring(0, currentDomain.BaseDirectory.Length - 11); currentDomain.SetData("DataDirectory", basePath); ViewModelService.Register <MainWindowViewModel>(); ViewService.Register <MainWindow>(); ViewService.Resolve <MainWindow>(ViewModelService.Resolve <MainWindowViewModel>()).Show(); }
private static void UpdateCar(object parameter) { try { using (Cars_DB db = new Cars_DB()) { Cars car = (Cars)parameter; car.Car_Name = ViewModelService.Resolve <WorkCarWindowViewModel>().Car_Name; db.Entry(car).State = EntityState.Modified; db.SaveChanges(); MessageBox.Show("Автомобиль успешно изменён"); } } catch (Exception exp) { MessageBox.Show(exp.Message); } }
private static void CreateBrand(object parameter) { try { using (Cars_DB db = new Cars_DB()) { BrandCar brand = (BrandCar)parameter; brand.Logotype = ViewModelService.Resolve <WorkBrandWindowViewModel>().Logotype; brand.Type_Image = ViewModelService.Resolve <WorkBrandWindowViewModel>().ImageType; db.BrandCar.Add(brand); db.SaveChanges(); MessageBox.Show("Брэнд успешно добавлен"); } } catch (Exception exp) { MessageBox.Show(exp.Message); } }
private static void UpdateBrand(object parameter) { try { using (Cars_DB db = new Cars_DB()) { BrandCar brand = (BrandCar)parameter; if (brand.Brand_Name != ViewModelService.Resolve <WorkBrandWindowViewModel>().Brand_Name_For_Update) { db.BrandCar.Add(brand); foreach (var p in db.Cars.ToList()) { if (ViewModelService.Resolve <WorkBrandWindowViewModel>().Brand_Name_For_Update == p.Brand_Name) { p.Brand_Name = ViewModelService.Resolve <WorkBrandWindowViewModel>().Brand_Name; db.Entry(p).State = EntityState.Modified; } } db.BrandCar.Remove(db.BrandCar.Find(ViewModelService.Resolve <WorkBrandWindowViewModel>().Brand_Name_For_Update)); db.SaveChanges(); return; } brand.Brand_Name = ViewModelService.Resolve <WorkBrandWindowViewModel>().Brand_Name; brand.Logotype = ViewModelService.Resolve <WorkBrandWindowViewModel>().Logotype; brand.Type_Image = ViewModelService.Resolve <WorkBrandWindowViewModel>().ImageType; db.Entry(brand).State = EntityState.Modified; db.SaveChanges(); MessageBox.Show("Брэнд успешно изменён"); } } catch (Exception exp) { MessageBox.Show(exp.Message); } }