public void Operation_FinanceSubjects(CE_OperatorMode mode, Business_Base_FinanceSubjects info)
        {
            DepotManagementDataContext ctx = CommentParameter.DepotDataContext;

            var varData = from a in ctx.Business_Base_FinanceSubjects
                          where a.SubjectsCode == info.SubjectsCode
                          select a;

            switch (mode)
            {
            case CE_OperatorMode.添加:

                if (varData.Count() > 0)
                {
                    throw new Exception("【代码】:" + info.SubjectsCode + "重复, 无法录入");
                }

                ctx.Business_Base_FinanceSubjects.InsertOnSubmit(info);
                break;

            case CE_OperatorMode.修改:

                if (varData.Count() != 1)
                {
                    throw new Exception("【代码】:" + info.SubjectsCode + "为空或者不唯一, 无法录入");
                }

                Business_Base_FinanceSubjects temp = varData.Single();

                temp.SubjectsName = info.SubjectsName;
                temp.ParentCode   = info.ParentCode;

                break;

            case CE_OperatorMode.除:

                var varData1 = from a in ctx.Business_Base_FinanceRelationInfo_Subjects_Purpose
                               where a.SubjectsCode == info.SubjectsCode
                               select a;

                var varData2 = from a in ctx.Business_Base_FinanceRelationInfo_Subjects_Storage
                               where a.SubjectsCode == info.SubjectsCode
                               select a;

                if (varData1.Count() > 0 || varData2.Count() > 0)
                {
                    throw new Exception("存在关联关系,无法删除");
                }

                ctx.Business_Base_FinanceSubjects.DeleteAllOnSubmit(varData);
                break;

            default:
                break;
            }

            ctx.SubmitChanges();
        }
        private void dgvSubjects_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dgvSubjects.CurrentRow == null)
            {
                return;
            }

            txtSubjects_Code.Text  = dgvSubjects.CurrentRow.Cells["科目代码"].Value.ToString();
            txtSubjects_Name.Text  = dgvSubjects.CurrentRow.Cells["科目名称"].Value.ToString();
            txtSubjects_Parent.Tag = dgvSubjects.CurrentRow.Cells["父级科目代码"].Value.ToString() == "Root" ?
                                     "" : dgvSubjects.CurrentRow.Cells["父级科目代码"].Value.ToString();

            Business_Base_FinanceSubjects temp =
                _serviceParametersSetting.GetFinanceSubjectsSingle(dgvSubjects.CurrentRow.Cells["父级科目代码"].Value.ToString());

            txtSubjects_Parent.Text = temp == null ? "核算科目" : temp.SubjectsName;
        }
        void OperationInfo(CE_OperatorMode mode, Control cl)
        {
            try
            {
                if (GlobalObject.GeneralFunction.ParentControlIsExist <TabPage>(cl, tpSubjects.Name))
                {
                    if (txtSubjects_Code.Text.Trim().Length == 0)
                    {
                        MessageDialog.ShowPromptMessage("请录入【科目代码】");
                        return;
                    }

                    if (txtSubjects_Name.Text.Trim().Length == 0)
                    {
                        MessageDialog.ShowPromptMessage("请录入【科目名称】");
                        return;
                    }

                    if (txtSubjects_Parent.Text.Trim().Length == 0)
                    {
                        MessageDialog.ShowPromptMessage("请选择【父级科目】");
                        return;
                    }

                    Business_Base_FinanceSubjects subjects = new Business_Base_FinanceSubjects();

                    subjects.SubjectsName = txtSubjects_Name.Text;
                    subjects.SubjectsCode = txtSubjects_Code.Text;
                    subjects.ParentCode   = txtSubjects_Parent.Tag == null ? "" : txtSubjects_Parent.Tag.ToString();

                    _serviceParametersSetting.Operation_FinanceSubjects(mode, subjects);
                }
                else if (GlobalObject.GeneralFunction.ParentControlIsExist <TabPage>(cl, tpPurpose.Name))
                {
                    if (txtPurpose_Code.Text.Trim().Length == 0)
                    {
                        MessageDialog.ShowPromptMessage("请输入【用途代码】");
                        return;
                    }

                    if (txtPurpose_Name.Text.Trim().Length == 0)
                    {
                        MessageDialog.ShowPromptMessage("请输入【用途名称】");
                        return;
                    }

                    if (txtPurpose_ParentName.Text.Trim().Length == 0)
                    {
                        MessageDialog.ShowPromptMessage("请选择【父级用途】");
                        return;
                    }

                    if (txtPurpose_Parent.Text.Trim().Length >= txtPurpose_Code.Text.Trim().Length ||
                        txtPurpose_Code.Text.Trim().Substring(0, txtPurpose_Parent.Text.Trim().Length) != txtPurpose_Parent.Text.ToString())
                    {
                        MessageDialog.ShowPromptMessage("【用途代码】中前面字符未包含【父级用途】代码,例如:【父级代码】:99,则【用途代码】应为:9901、 9902等等");
                        return;
                    }

                    BASE_MaterialRequisitionPurpose purpose = new BASE_MaterialRequisitionPurpose();

                    purpose.Inventory             = chb_Inventory.Checked;
                    purpose.Code                  = txtPurpose_Code.Text;
                    purpose.IsDisable             = true;
                    purpose.IsEnd                 = true;
                    purpose.Purpose               = txtPurpose_Name.Text;
                    purpose.DestructiveInspection = chb_DestructiveInspection.Checked;
                    purpose.ThreeOutSideFit       = chb_ThreeOutSideFit.Checked;
                    purpose.ThreeOutSideRepair    = chb_ThreeOutSideRepair.Checked;
                    purpose.ApplicableDepartment  = txtApplicableDepartment.Tag == null ? "" : txtApplicableDepartment.Tag.ToString();
                    purpose.RemindWord            = txtRemindWord.Text;

                    _serviceParametersSetting.Operation_MaterialRequisitionPurpose(mode, purpose, txtPurpose_Parent.Text.Trim());
                }
                else if (GlobalObject.GeneralFunction.ParentControlIsExist <TabPage>(cl, tpStorage.Name))
                {
                    if (txtStorage_Code.Text.Trim().Length == 0)
                    {
                        MessageDialog.ShowPromptMessage("请录入【库房代码】");
                        return;
                    }

                    if (txtStorage_Name.Text.Trim().Length == 0)
                    {
                        MessageDialog.ShowPromptMessage("请录入【库房名称】");
                        return;
                    }

                    if (txtStorage_Subjects.Text.Trim().Length == 0)
                    {
                        MessageDialog.ShowPromptMessage("请选择【所属科目】");
                        return;
                    }

                    BASE_Storage storage = new BASE_Storage();

                    storage.Aftermarket                   = chbAftermarket.Checked;
                    storage.AftermarketParts              = chbAftermarketParts.Checked;
                    storage.AssemblyWarehouse             = chbAssemblyWarehouse.Checked;
                    storage.FinancialAccountingFlag       = chbFinancialAccountingFlag.Checked;
                    storage.PartInPlanCalculation         = chbPartInPlanCalculation.Checked;
                    storage.SingleFinancialAccountingFlag = chbSingleFinancialAccountingFlag.Checked;
                    storage.WorkShopCurrentAccount        = chbWorkShopCurrentAccount.Checked;
                    storage.ZeroCostFlag                  = chbZeroCostFlag.Checked;

                    storage.StorageID   = txtStorage_Code.Text;
                    storage.StorageName = txtStorage_Name.Text;

                    storage.StorageLv = 1;


                    Business_Base_FinanceRelationInfo_Subjects_Storage storageSubjects =
                        new Business_Base_FinanceRelationInfo_Subjects_Storage();

                    storageSubjects.StorageID    = txtStorage_Code.Text;
                    storageSubjects.SubjectsCode = txtStorage_Subjects.Tag == null ? "" : txtStorage_Subjects.Tag.ToString();

                    _serviceParametersSetting.Operation_StorageInfo(mode, storage, storageSubjects);
                }
                else if (GlobalObject.GeneralFunction.ParentControlIsExist <TabPage>(cl, tpSubjectsPurpose.Name))
                {
                    if (txtSubjectsPurpose_Code.Text.Trim().Length == 0)
                    {
                        MessageDialog.ShowPromptMessage("请选择【领料用途】");
                        return;
                    }

                    if (txtSubjectsPurpose_Subjects.Text.Trim().Length == 0)
                    {
                        MessageDialog.ShowPromptMessage("请选择【所属科目】");
                        return;
                    }

                    Business_Base_FinanceRelationInfo_Subjects_Purpose purposeSubjects =
                        new Business_Base_FinanceRelationInfo_Subjects_Purpose();

                    purposeSubjects.PurposeCode  = txtSubjectsPurpose_Code.Text;
                    purposeSubjects.SubjectsCode = txtSubjectsPurpose_Subjects.Tag == null ?
                                                   "" : txtSubjectsPurpose_Subjects.Tag.ToString();

                    _serviceParametersSetting.Operation_SubjectsPurpose(mode, purposeSubjects);
                }
                else if (GlobalObject.GeneralFunction.ParentControlIsExist <TabPage>(cl, tpBudgetProject.Name))
                {
                    if (txtBudgetProject.Text.Trim().Length == 0)
                    {
                        MessageDialog.ShowPromptMessage("请录入【科目名称】");
                        return;
                    }

                    if (txtBudgetProject_Parent.Text.Trim().Length == 0)
                    {
                        MessageDialog.ShowPromptMessage("请选择【父级科目】");
                        return;
                    }

                    if (txtBudgetProject_Code.Text.Trim().Length == 0)
                    {
                        MessageDialog.ShowPromptMessage("请录入【科目代码】");
                        return;
                    }

                    Business_Base_Finance_Budget_ProjectItem project = new Business_Base_Finance_Budget_ProjectItem();

                    project.PerentProjectID = txtBudgetProject_Parent.Tag == null ? "" : txtBudgetProject_Parent.Tag.ToString();
                    project.ProjectName     = txtBudgetProject.Text;
                    project.ProjectID       = txtBudgetProject_Code.Text;

                    _serviceParametersSetting.Operation_BudgetProject(mode, project);
                }

                MessageDialog.ShowPromptMessage("操作成功");
                ShowInfo();
            }
            catch (Exception ex)
            {
                MessageDialog.ShowPromptMessage(ex.Message);
                return;
            }
        }