コード例 #1
0
        /// <summary>
        /// 提交 需要判断新增还是编辑,通过父窗口传过来的提交测试路线信息还是修改测试路线信息
        /// 调用对应的command命令
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <param name="OperationFlag">操作类型</param>
        private void Submit(object sender, RoutedEventArgs e)
        {
            //先校验数据格式是否正确
            if (Verify() == false)
            {
                MessageBox.Show("请检查数据格式!");
                return;
            }

            //确认提交
            OKWindow okWindow = new OKWindow("提交数据", "确实要提交这条数据吗?");

            okWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            okWindow.ShowDialog();
            if (okWindow.Ret == false)
            {
                return;
            }

            //再执行相关操作
            if (OperationFlag == "Insert")
            {
                TestRouteBase trb = new TestRouteBase
                {
                    Index       = 0,
                    LineMileage = this.trbLineMileage.Text,
                    Material    = this.trbMaterial.Text,
                    Picture     = this.trbPicture.Source as BitmapImage,
                    TestRoutes  = this.trbTestRoutes.Text,
                    Time        = this.trbTime.Text
                };

                //如果是Insert必须保证路面类型必须有一条
                TestRoute tr = new TestRoute {
                    TestRouteBase = trb, PavementTypeInfo = ptInfo
                };

                var MyVM = this.testRouteViewModelSelf;
                if (MyVM != null && MyVM.InsertCommand.CanExecute(tr))
                {
                    MyVM.InsertCommand.Execute(tr);
                }
            }
            else if (OperationFlag == "Update")
            {
                TestRouteBase trb = new TestRouteBase
                {
                    Index       = this.trSelf.TestRouteBase.Index,
                    LineMileage = this.trbLineMileage.Text,
                    Material    = this.trbMaterial.Text,
                    Picture     = this.trbPicture.Source as BitmapImage,
                    TestRoutes  = this.trbTestRoutes.Text,
                    Time        = this.trbTime.Text
                };

                TestRoute tr = new TestRoute {
                    TestRouteBase = trb, PavementTypeInfo = ptInfo
                };

                var MyVM = this.testRouteViewModelSelf;
                if (MyVM != null && MyVM.UpdateCommand.CanExecute(tr))
                {
                    MyVM.UpdateCommand.Execute(tr);
                }
            }

            this.Close();
        }