//删除 public static int DeleteCarType(CarProject carType) { using (IDbConnection cnn = new SQLiteConnection(LoadConnectString())) { cnn.Open(); string sql = $"PRAGMA foreign_keys = true;Delete from ExcelCarProject Where CarNO=@CarNO"; return(cnn.Execute(sql, carType)); } }
//修改 public static int UpdateCarType(CarProject carType) { using (IDbConnection cnn = new SQLiteConnection(LoadConnectString())) { cnn.Open(); string sql = $"PRAGMA foreign_keys = true;Update ExcelCarProject set CarName=@CarName, ModifyDate=@ModifyDate where CarNO=@CarNO"; return(cnn.Execute(sql, carType)); } }
//添加 public static int AddCarType(CarProject carType) { using (IDbConnection cnn = new SQLiteConnection(LoadConnectString())) { cnn.Open(); string sql = $"Insert into ExcelCarProject(CarName,CarNO,ModifyDate,Author)Values(@CarName,@CarNO,@ModifyDate,@Author)"; return(cnn.Execute(sql, carType)); } }
private void Button_Click(object sender, RoutedEventArgs e) { string tag = (sender as Button).Tag.ToString(); if (tag == "confirm") { CarProject car = (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Car; if (Operation == WindowOperation.Add) { if (QualityCheck()) { car.Author = (App.Current.Resources["Locator"] as ViewModelLocator).Main.User.UserID; int r = SQliteDbContext.AddCarType(car); if (r > 0) { MessageBox.Show("添加成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); (App.Current.Resources["Locator"] as ViewModelLocator).Main.CarTypes = new System.Collections.ObjectModel.ObservableCollection <CarProject>(SQliteDbContext.GetAllCarTypes()); } } } else if (Operation == WindowOperation.Update) { QualityCheck(); int r = SQliteDbContext.UpdateCarType(car); if (r > 0) { MessageBox.Show("更新成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); (App.Current.Resources["Locator"] as ViewModelLocator).Main.CarTypes = new System.Collections.ObjectModel.ObservableCollection <CarProject>(SQliteDbContext.GetAllCarTypes()); this.Close(); } } else if (Operation == WindowOperation.Delete) { QualityCheck(); int r = SQliteDbContext.DeleteCarType(car); if (r > 0) { MessageBox.Show("删除成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); (App.Current.Resources["Locator"] as ViewModelLocator).Main.CarTypes = new System.Collections.ObjectModel.ObservableCollection <CarProject>(SQliteDbContext.GetAllCarTypes()); this.Close(); } } } else if (tag == "cancel") { this.Close(); } }
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(); } }