示例#1
0
        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();
            }
        }