Exemple #1
0
        /// <summary>
        /// Save命令的Executed事件处理函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommandBindingSave_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            // 新建项目的操作
            if (isNew == true)
            {
                // 保存项目设置
                projectSetting.Name     = this.ProjectNameTextBox.Text;
                projectSetting.Province = this.ProjectProvinceTextBox.Text;
                projectSetting.City     = this.ProjectCityTextBox.Text;

                // 检查项目名是否为空
                if (string.IsNullOrEmpty(projectSetting.Name) || string.IsNullOrWhiteSpace(projectSetting.Name))
                {
                    return;
                }

                // 检测是否有同名项目
                List <string> projectList = ProjectDataBase.ReadProjectList();
                if (projectList != null && projectList.Contains(projectSetting.Name))
                {
                    MessageBox.Show("项目数据库中已存在名为\"" + projectSetting.Name + "\"的项目,无法新建项目。", "请检查项目名称", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                // 创建项目数据库
                ProjectDataBase.Create(projectSetting.Name);

                // 存储项目基本数据和公司数据
                ProjectDataBase.EditProjectBasicInfo(projectSetting.Name, projectSetting.Name, projectSetting.Province, projectSetting.City);
                ProjectDataBase.EditProjectCompany(projectSetting.Name, projectSetting.CompanyName, projectSetting.CompanyCode, projectSetting.Drawer, projectSetting.Writer, projectSetting.Checker, projectSetting.Inspector, projectSetting.Approver, projectSetting.FinalApprover);

                // 删除旧分层数据,存储新分层数据
                if (ProjectDataBase.ReadLayerNumberList(projectSetting.Name).Count > 0)
                {
                    ProjectDataBase.DeleteAllLayer(projectSetting.Name);
                }
                if (projectSetting.LayerList != null)
                {
                    for (int i = 0; i < projectSetting.LayerList.Count; i++)
                    {
                        string number      = projectSetting.LayerList[i].Number;
                        string name        = projectSetting.LayerList[i].Name;
                        string geo         = projectSetting.LayerList[i].Geo;
                        string description = projectSetting.LayerList[i].Description;
                        ProjectDataBase.AddLayer(projectSetting.Name, number, name, geo, description);
                    }
                }
            }
            // 非新建项目的操作
            else
            {
                // 保存项目设置
                string oldProjectName = projectSetting.Name;
                projectSetting.Name     = this.ProjectNameTextBox.Text;
                projectSetting.Province = this.ProjectProvinceTextBox.Text;
                projectSetting.City     = this.ProjectCityTextBox.Text;

                // 存储项目基本数据和公司数据
                ProjectDataBase.EditProjectBasicInfo(oldProjectName, projectSetting.Name, projectSetting.Province, projectSetting.City);
                ProjectDataBase.EditProjectCompany(oldProjectName, projectSetting.CompanyName, projectSetting.CompanyCode, projectSetting.Drawer, projectSetting.Writer, projectSetting.Checker, projectSetting.Inspector, projectSetting.Approver, projectSetting.FinalApprover);

                // 删除旧分层数据,存储新分层数据
                if (ProjectDataBase.ReadLayerNumberList(oldProjectName).Count > 0)
                {
                    ProjectDataBase.DeleteAllLayer(oldProjectName);
                }
                if (projectSetting.LayerList != null)
                {
                    for (int i = 0; i < projectSetting.LayerList.Count; i++)
                    {
                        string number      = projectSetting.LayerList[i].Number;
                        string name        = projectSetting.LayerList[i].Name;
                        string geo         = projectSetting.LayerList[i].Geo;
                        string description = projectSetting.LayerList[i].Description;
                        ProjectDataBase.AddLayer(oldProjectName, number, name, geo, description);
                    }
                }

                // 更改数据库文件名称,传递给主窗口更改数据文件名
                oldFile = Program.ReadProgramPath() + "\\" + oldProjectName + ".gsygeo";
                newFile = Program.ReadProgramPath() + "\\" + projectSetting.Name + ".gsygeo";
            }

            // 关闭窗口
            this.DialogResult      = true;
            Program.currentProject = projectSetting.Name;
            this.Close();
        }