コード例 #1
0
        private void SaveBtn_Click(object sender, RoutedEventArgs e)
        {
            switch ((OperationType)(((DictionaryEntry)(OperationTypeList.SelectedValue)).Key))
            {
            case OperationType.Edit:

                if (!CheckSheetIsValid(SheetDataGrid.SelectedItem as SheetInfo))
                {
                    MessageBox.Show("请检查该单必填信息是否完整。", "信息不完整", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                bool IsChanged = AlgorithmClass.CheckIsChanged <SheetInfo>(SheetDataGrid.SelectedItem as SheetInfo, sheetInfoForEdit);

                //单信息
                if (IsChanged == true)
                {
                    IsSavingEdit = true;
                    if (SheetDeal.UpdateSheetInfo(sheetInfoForEdit) == true)
                    {
                        //获得所有跟单员
                        sheetInfoForEdit.Follower = AlgorithmClass.GetFollowers(procedureInfoListForEdit);
                        int index = dataManager.AllSheetList.ToList().FindIndex(sheet => sheet.ID == sheetInfoForEdit.ID);
                        dataManager.AllSheetList.RemoveAt(index);
                        dataManager.AllSheetList.Insert(index, AlgorithmClass.DeepClone <SheetInfo>(sheetInfoForEdit));
                        SheetDataGrid.SelectedIndex = index;
                    }
                    else
                    {
                        MessageBox.Show("单保存失败,请重试!", "操作失败", MessageBoxButton.OK, MessageBoxImage.Error);
                        IsSavingEdit = false;
                        return;
                    }
                }

                //流程信息
                string procedureMap = AlgorithmClass.GetProcedureMap(procedureInfoListForEdit);
                if (procedureMap != AlgorithmClass.GetProcedureMap(CurProcedureInfoList))
                {
                    IsSavingEdit = true;
                    if (SheetDeal.UpdateProcedureMap(sheetInfoForEdit.ID, procedureMap) == false)
                    {
                        MessageBox.Show("流程信息保存失败,请重试!", "操作失败", MessageBoxButton.OK, MessageBoxImage.Error);
                        IsSavingEdit = false;
                        return;
                    }
                }

                //收支信息
                string bopMap = AlgorithmClass.GetBOPMap(bopInfoListForEdit);
                if (bopMap != AlgorithmClass.GetBOPMap(CurBOPInfoList))
                {
                    IsSavingEdit = true;
                    if (SheetDeal.UpdateSheetBOPMap(sheetInfoForEdit.ID, bopMap) == false)
                    {
                        MessageBox.Show("收支信息保存失败,请重试!");
                        IsSavingEdit = false;
                        return;
                    }
                }

                if (IsSavingEdit == true)
                {
                    MessageBox.Show("数据更新成功!");
                    IsSavingEdit = false;
                }

                break;

            case OperationType.New:

                if (!CheckSheetIsValid(sheetInfoForNew))
                {
                    MessageBox.Show("请检查该单必填信息是否完整。", "信息不完整", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                int insertID = 0;
                IsSavingEdit = true;
                //单信息
                if (SheetDeal.InsertSheetInfo(sheetInfoForNew, ref insertID) == true)
                {
                    sheetInfoForNew.ID       = insertID;
                    sheetInfoForNew.Follower = AlgorithmClass.GetFollowers(procedureInfoListForNew);
                    dataManager.AllSheetList.Add(AlgorithmClass.DeepClone <SheetInfo>(sheetInfoForNew));
                }
                else
                {
                    MessageBox.Show("新单创建失败,请重试!");
                    IsSavingEdit = false;
                    return;
                }

                IsSavingEdit = false;

                //流程信息
                if (SheetDeal.InsertProcedureMap(sheetInfoForNew.ID, AlgorithmClass.GetProcedureMap(procedureInfoListForNew)) == false)
                {
                    MessageBox.Show("流程信息创建失败,请重试!", "操作失败", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                //收支信息
                if (SheetDeal.InsertSheetBOPMap(sheetInfoForNew.ID, AlgorithmClass.GetBOPMap(bopInfoListForNew)) == false)
                {
                    MessageBox.Show("收支信息创建失败,请重试!", "操作失败", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                sheetInfoForNew             = new SheetInfo();
                SheetDetailGrid.DataContext = sheetInfoForNew;
                procedureInfoListForNew.Clear();
                bopInfoListForNew.Clear();

                MessageBox.Show("新单创建成功!");

                break;
            }
        }