//删除 public static int DeleteExcelProject(ExcelProject ExcelProject) { using (IDbConnection cnn = new SQLiteConnection(LoadConnectString())) { cnn.Open(); string sql = $"PRAGMA foreign_keys = true;Delete from ExcelProject Where ProjectNO=@ProjectNO"; return(cnn.Execute(sql, ExcelProject)); } }
//修改 public static int UpdateExcelProject(ExcelProject ExcelProject) { using (IDbConnection cnn = new SQLiteConnection(LoadConnectString())) { cnn.Open(); string sql = $"PRAGMA foreign_keys = true;Update ExcelProject set CarNO=@CarNO,WireNO=@WireNO, ProjectName=@ProjectName, ModifyDate=@ModifyDate where CarNO=@CarNO"; return(cnn.Execute(sql, ExcelProject)); } }
//添加 public static int AddExcelProject(ExcelProject ExcelProject) { using (IDbConnection cnn = new SQLiteConnection(LoadConnectString())) { cnn.Open(); string sql = $"Insert into ExcelProject(CarNO,WireNO,ProjectNO,ProjectName,ModifyDate,Author)Values(@CarNO,@WireNO,@ProjectNO,@ProjectName,@ModifyDate,@Author)"; return(cnn.Execute(sql, ExcelProject)); } }
private void MenuItem_Click(object sender, RoutedEventArgs e) { string name = (sender as MenuItem).Header.ToString(); WindowOperation operation = WindowOperation.Add; if (name.Contains("车型")) { CarProject car = (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Car; switch (name.Substring(0, 2)) { case "新建": cmbCType.SelectedIndex = -1; (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Car = new CarProject(); operation = WindowOperation.Add; break; case "修改": if (car == null) { MessageBox.Show("请选择一个车型!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); return; } operation = WindowOperation.Update; break; case "删除": if (car == null) { MessageBox.Show("请选择一个车型!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); return; } operation = WindowOperation.Delete; break; default: break; } CarTypeWindow carTypeWindow = new CarTypeWindow(operation); carTypeWindow.ShowDialog(); } else if (name.Contains("线束")) { WireType wire = (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Wire; switch (name.Substring(0, 2)) { case "新建": partcmb.SelectedIndex = -1; (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Wire = new WireType(); operation = WindowOperation.Add; break; case "修改": if (wire == null) { MessageBox.Show("请选择一个线束!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); return; } operation = WindowOperation.Update; break; case "删除": if (wire == null) { MessageBox.Show("请选择一个线束!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); return; } operation = WindowOperation.Delete; break; default: break; } WireWindow wireWindow = new WireWindow(operation); wireWindow.ShowDialog(); } else if (name.Contains("工程")) { ExcelProject project = (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Project; switch (name.Substring(0, 2)) { case "新建": projectcmb.SelectedIndex = -1; (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Project = new ExcelProject(); operation = WindowOperation.Add; break; case "修改": if (project == null) { MessageBox.Show("请选择一个工程!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); return; } operation = WindowOperation.Update; break; case "删除": if (project == null) { MessageBox.Show("请选择一个工程!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); return; } operation = WindowOperation.Delete; break; default: break; } ExcelProjectWindow excelProjectWindow = new ExcelProjectWindow(operation); excelProjectWindow.ShowDialog(); } else if (name.Contains("治具")) { FixtureBase fixture = (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Fixture; switch (name.Substring(0, 2)) { case "新建": cmbFixture.SelectedIndex = -1; (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Project = new ExcelProject(); operation = WindowOperation.Add; break; case "修改": if (fixture == null) { MessageBox.Show("请选择一个治具!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); return; } operation = WindowOperation.Update; break; case "删除": if (fixture == null) { MessageBox.Show("请选择一个治具!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); return; } operation = WindowOperation.Delete; break; default: break; } ExFixtureWindow fixtureWindow = new ExFixtureWindow(operation); fixtureWindow.ShowDialog(); } }
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(); } }