private void Add() { FixtureBase fixture = (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Fixture; switch (Operation) { case WindowOperation.Add: if (QualityCheck()) { try { Bitmap bitmap = new Bitmap(filepath); if (folderExist(System.Environment.CurrentDirectory + "\\Image\\" + "ExcelProject")) { filepath = System.Environment.CurrentDirectory + "\\Image\\" + "ExcelProject" + "\\" + System.IO.Path.GetFileName(filepath); } else { folderCreate(System.Environment.CurrentDirectory + "\\Image\\" + "ExcelProject"); filepath = System.Environment.CurrentDirectory + "\\Image\\" + "ExcelProject" + "\\" + System.IO.Path.GetFileName(filepath); } bitmap.Save(filepath); bitmap.Dispose(); } catch (Exception ex) { System.Windows.MessageBox.Show("工程中已经存在同名的图片,请将图片重命名后再导入", "警告", MessageBoxButton.OK, MessageBoxImage.Warning); return; } int row = SQliteDbContext.AddFixtureBaseInfo(fixture); if (row > 0) { System.Windows.MessageBox.Show("添加成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } break; case WindowOperation.Update: if (QualityCheck()) { int rs = SQliteDbContext.UpdateFixtureBaseInfo(fixture); if (rs > 0) { System.Windows.MessageBox.Show("更新成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } break; case WindowOperation.Delete: int rd = SQliteDbContext.DeleteFixtureBaseInfo(fixture); if (rd > 0) { System.Windows.MessageBox.Show("删除成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } break; default: break; } (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Fixtures = new System.Collections.ObjectModel.ObservableCollection <FixtureBase>(SQliteDbContext.GetAllFixtureBaseInfos()); }