private void Button_Click(object sender, RoutedEventArgs e) { string tag = (sender as System.Windows.Controls.Button).Tag.ToString().ToLower(); if (tag == "scan") { string filePathName = ""; //定义图像文件的位置(包括路径及文件名) System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog(); //添加打开对话框 ofd.Filter = "Excel文件|*.xls;*.xlsx"; //设置过滤器 if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) //如果确定打开图片,则保存文件的路径及文件名到字符串变量filePathName中 { filePathName = ofd.FileName; //包括路径和文件名 // filepath = this.filename.Text = ofd.FileName; filepath = ofd.FileName; } } else if (tag == "confirm") { ExcelProject project = (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Project; if (Operation == WindowOperation.Add) { if (QualityCheck()) { project.Author = (App.Current.Resources["Locator"] as ViewModelLocator).Main.User.UserID; bool rs = ImportExcel(project.ProjectNO, project.ProjectName, filepath); if (SQliteDbContext.GetAllExcelProject().Exists(x => x.ProjectNO == project.ProjectNO)) { MessageBox.Show("工程编号已经存在!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); this.projectNO.Focus(); return; } if (rs) { int r = SQliteDbContext.AddExcelProject(project); if (r > 0 && rs) { MessageBox.Show("添加成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } } } else if (Operation == WindowOperation.Update) { QualityCheck(); int r = SQliteDbContext.UpdateExcelProject(project); if (r > 0) { MessageBox.Show("更新成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } else if (Operation == WindowOperation.Delete) { QualityCheck(); int r = SQliteDbContext.DeleteExcelProject(project); if (r > 0) { MessageBox.Show("删除成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } (App.Current.Resources["Locator"] as ViewModelLocator).Main.ExProjects = new System.Collections.ObjectModel.ObservableCollection <ExcelProject>(SQliteDbContext.GetAllExcelProject()); } else if (tag == "cancel") { this.Close(); } }