Ejemplo n.º 1
0
        internal DataSourceSystem AddDataSourceSystem(DataSourceSystem dataSourceSystem)
        {
            DataSourceSystem item = null;

            if (dataSourceSystem != null && dataSourceSystem.Name == null)
            {
                return(item);
            }
            using (ImsDbContext context = new ImsDbContext())
            {
                //先用ID查重
                if (dataSourceSystem.ID != null)
                {
                    item = context.DataSourceSystems.Find(dataSourceSystem.ID);
                }
                //或用Name查重
                else
                {
                    if (dataSourceSystem.Name != null)
                    {
                        item = context.DataSourceSystems.Where(d => d.Name == dataSourceSystem.Name).FirstOrDefault();
                    }
                }
                if (item == null)
                {
                    //如果为null,说明数据库不存在该项,添加
                    item = dataSourceSystem;
                    context.DataSourceSystems.Add(item);
                    context.SaveChanges();
                }
            }
            return(item);
        }
Ejemplo n.º 2
0
        public DepartmentCategory AddDepartmentCategory(DepartmentCategory departmentCategory)
        {
            //查重,如果数据库中已存在,返回该项
            DepartmentCategory item = null;

            if (departmentCategory != null && departmentCategory.Name == null)
            {
                return(item);
            }
            using (ImsDbContext context = new ImsDbContext())
            {
                //先用ID查重
                if (departmentCategory.DepartmentCategoryID != null)
                {
                    item = context.DepartmentCategories.Find(departmentCategory.DepartmentCategoryID);
                }
                //或用Name查重
                else
                {
                    if (departmentCategory.Name != null)
                    {
                        item = context.DepartmentCategories.Where(d => d.Name == departmentCategory.Name).FirstOrDefault();
                    }
                }
                if (item == null)
                {
                    //如果为null,说明数据库不存在该项,添加
                    item = departmentCategory;

                    context.DepartmentCategories.Add(item);
                    context.SaveChanges();
                }
            }
            return(item);
        }
Ejemplo n.º 3
0
        public Department AddDepartment(Department department)
        {
            Department item = null;

            if (department == null || department.DepartmentName == null)
            {
                return(item);
            }
            using (ImsDbContext context = new ImsDbContext())
            {
                //先用ID查重

                if (department.DepartmentID != null)
                {
                    item = context.Departments.Find(department.DepartmentID);
                }
                //或用Name查重
                else
                {
                    if (department.DepartmentName != null)
                    {
                        item = context.Departments.Where(d => d.DepartmentName == department.DepartmentName).FirstOrDefault();
                    }
                }
                if (item == null)
                {
                    //如果为null,说明数据库不存在该项,添加
                    item = department;
                    //item.DepartmentID = System.Guid.NewGuid();
                    context.Departments.Add(item);
                    context.SaveChanges();
                }
            }
            return(item);
        }
Ejemplo n.º 4
0
        public IndicatorAlgorithm AddIndicatorAlgorithm(IndicatorAlgorithm indicatorAlgorithm)
        {
            IndicatorAlgorithm item = null;

            if (indicatorAlgorithm == null)
            {
                return(item);
            }
            using (ImsDbContext context = new ImsDbContext())
            {
                //先用ID查重
                if (indicatorAlgorithm.ID != null)
                {
                    item = context.IndicatorAlgorithms.Find(indicatorAlgorithm.ID);
                }
                //再用ResultOperation查找,如果能找到,则也不加入
                if (item == null && indicatorAlgorithm.ResultOperationID != null)
                {
                    item = context.IndicatorAlgorithms.Where(i => i.ResultOperationID == indicatorAlgorithm.ResultOperationID).FirstOrDefault();
                }
                if (item == null)
                {
                    //如果仍然没有,则可以添加到数据库
                    item = indicatorAlgorithm;
                    context.IndicatorAlgorithms.Add(item);
                    context.SaveChanges();
                }
            }
            return(item);
        }
Ejemplo n.º 5
0
        // id 参数名应该与控件上设置的 DataKeyNames 值匹配
        public void lvIndicator_UpdateItem(Guid IndicatorID)
        {
            TextBox txtEditName = new TextBox();

            txtEditName = (TextBox)lvIndicator.EditItem.FindControl("txtEditName");
            var     name          = txtEditName?.Text;
            TextBox txtEditRemark = new TextBox();

            txtEditRemark = (TextBox)lvIndicator.EditItem.FindControl("txtEditRemark");
            var remark = txtEditRemark?.Text;

            if (String.IsNullOrEmpty(name))
            {
                return;
            }
            using (ImsDbContext context = new ImsDbContext())
            {
                IMS.Models.Indicator item = null;
                // 在此加载该项,例如 item = MyDataLayer.Find(id);
                item = context.Indicators.Find(IndicatorID);

                if (item == null)
                {
                    // 未找到该项
                    ModelState.AddModelError("", String.Format("未找到 id 为 {0} 的项", IndicatorID));
                    return;
                }
                TryUpdateModel(item);
                if (ModelState.IsValid)
                {
                    // 在此保存更改,例如 MyDataLayer.SaveChanges();
                    //不重名,更改项目名称
                    var query = context.Indicators.Where(n => n.Name == name && n.IndicatorID != item.IndicatorID).FirstOrDefault();
                    if (query != null)
                    {
                        ModelState.AddModelError("", String.Format("项目 {0} 已存在!", name));
                        return;
                    }
                    item.Name    = name;
                    item.Remarks = remark;
                    //database win
                    bool saveFailed;
                    do
                    {
                        saveFailed = false;
                        try
                        {
                            context.SaveChanges();
                        }
                        catch (DbUpdateConcurrencyException ex)
                        {
                            saveFailed = true;
                            // Update the values of the entity that failed to save from the store
                            ex.Entries.Single().Reload();
                        }
                    } while (saveFailed);
                }
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Adds the indicator.
 /// </summary>
 /// <param name="indicatorItem">代码中的对应映射类.</param>
 public void AddIndicator(IndicatorItem indicatorItem)
 {
     if (indicatorItem == null)
     {
         return;
     }
     using (ImsDbContext context = new ImsDbContext())
     {
         //先通过Id查重,如果存在,不添加
         Indicator item  = new Indicator();
         var       query = context.Indicators.Where(i => i.IndicatorID == indicatorItem.GuidId).FirstOrDefault();
         if (query != null)
         {
             //已存在,返回
             return;
         }
         //根据IsAuto从不同表中查找ID
         if (indicatorItem.IsAuto == "是")
         {
             item.IsAutoGetData = true;
             var dataSystem = context.DataSourceSystems.Where(d => d.Name == indicatorItem.DataSystem).FirstOrDefault();
             if (dataSystem == null)
             {
                 //若不存在,直接返回,
                 return;
             }
             //需获取DataSystem的ID值
             item.DataSourceSystemID = dataSystem.ID;
             //item.DepartmentID = null;
         }
         else
         {
             item.IsAutoGetData = false;
             var department = context.Departments.Where(d => d.DepartmentName == indicatorItem.Department).FirstOrDefault();
             if (department == null)
             {
                 //如果科室不存在,说明有问题,不能再继续下一步操作
                 return;
             }
             //获取department的ID
             item.DepartmentID = department.DepartmentID;
             //item.DataSourceSystemID = null;
         }
         //继续赋其他值
         item.Name           = indicatorItem.Name;
         item.Unit           = indicatorItem.Unit;
         item.DutyDepartment = indicatorItem?.DutyDepartment;
         item.Remarks        = indicatorItem?.Remarks;
         //添加到数据库
         item.IndicatorID = indicatorItem.GuidId;
         context.Indicators.Add(item);
         context.SaveChanges();
     }
 }
Ejemplo n.º 7
0
        public void lvDepartment_InsertItem()
        {
            var     item    = new IMS.Models.Department();
            TextBox txtName = new TextBox();

            txtName = (TextBox)lvDepartment.InsertItem.FindControl("txtInsertName");
            var     name      = txtName?.Text;
            TextBox txtRemark = new TextBox();

            txtRemark = (TextBox)lvDepartment.InsertItem.FindControl("txtInsertRemark");
            var remark = txtRemark?.Text;

            TextBox txtInsertCategory = new TextBox();

            txtInsertCategory = (TextBox)lvDepartment.InsertItem.FindControl("txtInsertCategory");
            var categoryName = txtInsertCategory?.Text;

            if (String.IsNullOrEmpty(name) || String.IsNullOrEmpty(categoryName))
            {
                ModelState.AddModelError("", "请输入科室名称和科室类别!");
                return;
            }
            TryUpdateModel(item);
            if (ModelState.IsValid)
            {
                // Save changes here
                using (ImsDbContext context = new ImsDbContext())
                {
                    //需检查是否有重名情况
                    var query = context.Departments.Where(n => n.DepartmentName == name).FirstOrDefault();
                    if (query != null)
                    {
                        ModelState.AddModelError("", String.Format("科室 {0} 已存在!", name));
                        return;
                    }
                    var categoryQuery = context.DepartmentCategories.Where(d => d.Name == categoryName).FirstOrDefault();
                    if (categoryQuery == null)
                    {
                        //输入的科室类别不存在,不能修改
                        ModelState.AddModelError("", String.Format("科室类别 {0} 不存在!", categoryQuery));

                        return;
                    }
                    item.DepartmentID         = new Guid();
                    item.DepartmentName       = name;
                    item.DepartmentCategoryID = categoryQuery.DepartmentCategoryID;
                    item.Remarks = remark;
                    context.Departments.Add(item);
                    context.SaveChanges();
                }
            }
        }
Ejemplo n.º 8
0
        // id 参数名应该与控件上设置的 DataKeyNames 值匹配
        public void lvIndicatorValue_UpdateItem(Guid id)
        {
            TextBox txtValue = new TextBox();

            txtValue = (TextBox)lvIndicatorValue.EditItem.FindControl("txtValue");
            using (ImsDbContext context = new ImsDbContext())
            {
                IMS.Models.DepartmentIndicatorValue item = null;
                // 在此加载该项,例如 item = MyDataLayer.Find(id);
                item = context.DepartmentIndicatorValues.Find(id);
                if (item == null)
                {
                    // 未找到该项
                    ModelState.AddModelError("", String.Format("未找到 id 为 {0} 的项", id));
                    return;
                }
                TryUpdateModel(item);
                if (ModelState.IsValid)
                {
                    decimal value;
                    // 在此保存更改,例如 MyDataLayer.SaveChanges();
                    if (Decimal.TryParse(txtValue.Text, out value))
                    {
                        item.Value = value;
                    }
                    else
                    {
                        item.Value = null;
                    }

                    //database win
                    bool saveFailed;
                    do
                    {
                        saveFailed = false;
                        try
                        {
                            context.SaveChanges();
                        }
                        catch (DbUpdateConcurrencyException ex)
                        {
                            saveFailed = true;
                            // Update the values of the entity that failed to save from the store
                            ex.Entries.Single().Reload();
                        }
                    } while (saveFailed);
                }
            }
        }
Ejemplo n.º 9
0
        // id 参数名应该与控件上设置的 DataKeyNames 值匹配
        public void lvDepartment_DeleteItem(Guid DepartmentID)
        {
            using (ImsDbContext context = new ImsDbContext())
            {
                IMS.Models.Department item = null;
                item = context.Departments.Find(DepartmentID);
                if (item == null)
                {
                    // 未找到该项
                    ModelState.AddModelError("", String.Format("未找到 id 为 {0} 的项", DepartmentID));
                    return;
                }
                //检查在DepartmentMonitors中是否存在该信息

                var queryDepartmentMonitor = context.DepartmentIndicatorStandardValues.Where(d => d.DepartmentID == DepartmentID).FirstOrDefault();
                if (queryDepartmentMonitor != null)
                {
                    //DepartmentMonitors 中存在该信息,不能删除
                    ModelState.AddModelError("", String.Format("在科室项目值表中存在 {0} 的项,禁止删除", item.DepartmentName));
                    return;
                }
                TryUpdateModel(item);
                if (ModelState.IsValid)
                {
                    // 在此保存更改,例如 MyDataLayer.SaveChanges();
                    context.Departments.Remove(item);
                    //database win
                    bool saveFailed;
                    do
                    {
                        saveFailed = false;
                        try
                        {
                            context.SaveChanges();
                        }
                        catch (DbUpdateConcurrencyException ex)
                        {
                            saveFailed = true;
                            // Update the values of the entity that failed to save from the store
                            ex.Entries.Single().Reload();
                        }
                    } while (saveFailed);
                }
            }
        }
Ejemplo n.º 10
0
        public void lvDepartmentCategory_InsertItem()
        {
            var     item    = new IMS.Models.DepartmentCategory();
            TextBox txtName = new TextBox();

            txtName = (TextBox)lvDepartmentCategory.InsertItem.FindControl("txtInsertName");
            var     name      = txtName?.Text;
            TextBox txtRemark = new TextBox();

            txtRemark = (TextBox)lvDepartmentCategory.InsertItem.FindControl("txtInsertRemark");
            var remark = txtRemark?.Text;

            if (String.IsNullOrEmpty(name))
            {
                ModelState.AddModelError("", "请输入名称!");
                return;
            }
            TryUpdateModel(item);
            if (ModelState.IsValid)
            {
                // Save changes here
                using (ImsDbContext context = new ImsDbContext())
                {
                    //需检查是否有重名情况
                    var query = context.DepartmentCategories.Where(n => n.Name == name).FirstOrDefault();
                    if (query != null)
                    {
                        ModelState.AddModelError("", String.Format("项目 {0} 已存在!", name));
                        return;
                    }
                    item.DepartmentCategoryID = new Guid();
                    item.Name    = name;
                    item.Remarks = remark;
                    context.DepartmentCategories.Add(item);
                    context.SaveChanges();
                }
            }
        }
Ejemplo n.º 11
0
        public void AddDepartmentCategoryIndicatorMap(DepartmentCategoryIndicatorMap item)
        {
            if (item.IndicatorID == null || item.DepartmentCategoryID == null)
            {
                return;
            }
            //根据DepartmentCategoryID与IndicatorID查重
            using (ImsDbContext context = new ImsDbContext())
            {
                var query = context.DepartmentCategoryIndicatorMaps.Where(d => d.DepartmentCategoryID == item.DepartmentCategoryID &&
                                                                          d.IndicatorID == item.IndicatorID).FirstOrDefault();

                if (query == null)
                {
                    //加入数据库
                    DepartmentCategoryIndicatorMap newItem = new DepartmentCategoryIndicatorMap();
                    newItem    = item;
                    newItem.ID = System.Guid.NewGuid();
                    context.DepartmentCategoryIndicatorMaps.Add(newItem);
                    context.SaveChanges();
                }
            }
        }
Ejemplo n.º 12
0
        // id 参数名应该与控件上设置的 DataKeyNames 值匹配
        public void lvDepartment_UpdateItem(Guid DepartmentID)
        {
            TextBox txtEditName = new TextBox();

            txtEditName = (TextBox)lvDepartment.EditItem.FindControl("txtEditName");
            var     name          = txtEditName?.Text;
            TextBox txtEditRemark = new TextBox();

            txtEditRemark = (TextBox)lvDepartment.EditItem.FindControl("txtEditRemark");
            var remark = txtEditRemark?.Text;

            TextBox txtEditCategory = new TextBox();

            txtEditCategory = (TextBox)lvDepartment.EditItem.FindControl("txtEditCategory");
            var categoryName = txtEditCategory?.Text;

            if (String.IsNullOrEmpty(name) || String.IsNullOrEmpty(categoryName))
            {
                return;
            }
            using (ImsDbContext context = new ImsDbContext())
            {
                IMS.Models.Department item = null;
                // 在此加载该项,例如 item = MyDataLayer.Find(id);
                item = context.Departments.Find(DepartmentID);
                if (item == null)
                {
                    // 未找到该项
                    ModelState.AddModelError("", String.Format("未找到 id 为 {0} 的项", DepartmentID));
                    return;
                }
                TryUpdateModel(item);
                if (ModelState.IsValid)
                {
                    // 在此保存更改,例如 MyDataLayer.SaveChanges();
                    //不重名,更改科室名称
                    var query = context.Departments.Where(n => n.DepartmentName == name && n.DepartmentID != item.DepartmentID).FirstOrDefault();
                    if (query != null)
                    {
                        ModelState.AddModelError("", String.Format("科室 {0} 已存在!", name));
                        return;
                    }
                    var categoryQuery = context.DepartmentCategories.Where(d => d.Name == categoryName).FirstOrDefault();
                    if (categoryQuery == null)
                    {
                        //输入的科室类别不存在,不能修改
                        ModelState.AddModelError("", String.Format("科室类别 {0} 不存在!", categoryQuery));

                        return;
                    }
                    item.DepartmentName       = name;
                    item.Remarks              = remark;
                    item.DepartmentCategoryID = categoryQuery.DepartmentCategoryID;
                    //database win
                    bool saveFailed;
                    do
                    {
                        saveFailed = false;
                        try
                        {
                            context.SaveChanges();
                        }
                        catch (DbUpdateConcurrencyException ex)
                        {
                            saveFailed = true;
                            // Update the values of the entity that failed to save from the store
                            ex.Entries.Single().Reload();
                        }
                    } while (saveFailed);
                }
            }
        }
Ejemplo n.º 13
0
        private void AddDepartmentIndicatorValueByCalculation(Guid dlSourceSystemId, DateTime addTime)
        {
            using (ImsDbContext context = new ImsDbContext())
            {
                //1 由项目来源部门找出管属项目

                var indicatorItems = context.Indicators.Where(i => i.DataSourceSystemID != null && i.DataSourceSystemID == dlSourceSystemId).OrderBy(i => i.Name).ToList();
                foreach (var indicator in indicatorItems)
                {
                    //2 管属项目找到对应的科室类别项目映射表,找到对应科室类别
                    var departmentCategoryIndicators = indicator.DepartmentCategoryIndicatorMaps.ToList();
                    //列举出对应的科室类别,再由此找到每个科室
                    foreach (var categoryIndicator in departmentCategoryIndicators)
                    {
                        //3 通过科室类别找到管辖的科室,逐一与项目组合,添加到科室项目值表
                        var departmentCategory = categoryIndicator.DepartmentCategory;
                        if (departmentCategory == null)
                        {
                            continue;
                        }
                        //var departments = departmentCategory.Departments;
                        //列出该科室负责的填报项目,再逐步添加到值表中。

                        foreach (var department in departmentCategory.Departments)
                        {
                            //需先查重,如果已经该项目已存在于数据库,不添加
                            //检查下一项
                            var query = context.DepartmentIndicatorValues.Where(d => d.DepartmentID == department.DepartmentID && d.IndicatorID == indicator.IndicatorID &&
                                                                                d.Time.Year == addTime.Year && d.Time.Month == addTime.Month).FirstOrDefault();
                            if (query != null)
                            {
                                //需计算出该结果值
                                //相当于一个Update
                                IndicatorValue indicatorValue = new IndicatorValue();
                                var            valueReturned  = indicatorValue.GetDepartmentIndicatorValueByCalculate(query.DepartmentID, query.IndicatorID, addTime);
                                //根据项目值单位,如果是“百分比”,需乘以100
                                if (indicator.Unit == "百分比")
                                {
                                    valueReturned *= 100;
                                }
                                query.Value = valueReturned;

                                #region Client win context.SaveChanges();
                                bool saveFailed;
                                do
                                {
                                    saveFailed = false;
                                    try
                                    {
                                        context.SaveChanges();
                                    }
                                    catch (DbUpdateConcurrencyException ex)
                                    {
                                        saveFailed = true;

                                        // Update original values from the database
                                        var entry = ex.Entries.Single();
                                        entry.OriginalValues.SetValues(entry.GetDatabaseValues());
                                    }
                                } while (saveFailed);
                                #endregion
                            }
                            else
                            {
                                //不存在该项目,需添加到数据库
                                IMS.Models.DepartmentIndicatorValue item = new IMS.Models.DepartmentIndicatorValue();
                                item.DepartmentID = department.DepartmentID;
                                item.IndicatorID  = indicator.IndicatorID;
                                item.Time         = addTime;
                                item.ID           = System.Guid.NewGuid();
                                //从计算获取该值
                                IndicatorValue indicatorValue = new IndicatorValue();
                                var            valueReturned  = indicatorValue.GetDepartmentIndicatorValueByCalculate(item.DepartmentID, item.IndicatorID, addTime);
                                //根据项目值单位,如果是“百分比”,需乘以100
                                if (indicator.Unit == "百分比")
                                {
                                    valueReturned *= 100;
                                }
                                item.Value = valueReturned;
                                context.DepartmentIndicatorValues.Add(item);
                                context.SaveChanges();
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 14
0
        private void AddDepartmentIndicatorValueByMRMS(Guid dlSourceSystemId, DateTime addTime)
        {
            using (ImsDbContext context = new ImsDbContext())
            {
                //1 由项目来源部门找出管属项目

                var indicatorItems = context.Indicators.Where(i => i.DataSourceSystemID != null && i.DataSourceSystemID == dlSourceSystemId).OrderBy(i => i.Name).ToList();
                foreach (var indicator in indicatorItems)
                {
                    //2 管属项目找到对应的科室类别项目映射表,找到对应科室类别
                    var departmentCategoryIndicators = indicator.DepartmentCategoryIndicatorMaps.ToList();
                    //列举出对应的科室类别,再由此找到每个科室
                    foreach (var categoryIndicator in departmentCategoryIndicators)
                    {
                        //3 通过科室类别找到管辖的科室,逐一与项目组合,添加到科室项目值表
                        var departmentCategory = categoryIndicator.DepartmentCategory;
                        if (departmentCategory == null)
                        {
                            continue;
                        }
                        //var departments = departmentCategory.Departments;
                        //列出该科室负责的填报项目,再逐步添加到值表中。

                        foreach (var department in departmentCategory.Departments)
                        {
                            //从病案管理系统中获取项目值
                            decimal valueReturned = Decimal.Zero;
                            try
                            {
                                var bagl = new ImsAutoLib.Bagl.Bagl("BaglConnection");
                                valueReturned = bagl.GetIndicatorValue(department.DepartmentID, indicator.IndicatorID, addTime);
                            }
                            catch (Exception ex)
                            {
                                ModelState.AddModelError("", String.Format("无法连接病案室管理系统。<br/>详情:{0}", ex.Message));
                                valueReturned = Decimal.Zero;
                            }
                            //需先查重,如果已经该项目已存在于数据库,不添加
                            //检查下一项
                            var query = context.DepartmentIndicatorValues.Where(d => d.DepartmentID == department.DepartmentID && d.IndicatorID == indicator.IndicatorID &&
                                                                                d.Time.Year == addTime.Year && d.Time.Month == addTime.Month).FirstOrDefault();
                            if (query != null)
                            {
                                //更改项目的计算值。
                                //从病案管理系统中获取值

                                query.Value = valueReturned;
                                #region  Client win context.SaveChanges();
                                bool saveFailed;
                                do
                                {
                                    saveFailed = false;
                                    try
                                    {
                                        context.SaveChanges();
                                    }
                                    catch (DbUpdateConcurrencyException ex)
                                    {
                                        saveFailed = true;

                                        // Update original values from the database
                                        var entry = ex.Entries.Single();
                                        entry.OriginalValues.SetValues(entry.GetDatabaseValues());
                                    }
                                } while (saveFailed);
                                #endregion
                            }
                            else
                            {
                                //不存在该项目,需添加到数据库
                                IMS.Models.DepartmentIndicatorValue item = new IMS.Models.DepartmentIndicatorValue();
                                item.DepartmentID = department.DepartmentID;
                                item.IndicatorID  = indicator.IndicatorID;
                                item.Time         = addTime;
                                item.ID           = System.Guid.NewGuid();
                                item.Value        = valueReturned;
                                context.DepartmentIndicatorValues.Add(item);
                                context.SaveChanges();
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 15
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            //添加时需对该用户进行权限检测,如果不属于该科室成员,不能够新增项目数据

            //将找到该项目的来源部门。
            if (dlDepartment == null || txtDate == null || String.IsNullOrEmpty(txtDate.Text))
            {
                return;
            }
            try
            {
                var departmentID = Guid.Parse(dlDepartment.SelectedValue);
                var addTime      = DateTime.Parse(txtDate.Text);
                using (ImsDbContext context = new ImsDbContext())
                {
                    //1 由项目来源部门找出管属项目

                    var indicatorItems = context.Indicators.Where(i => i.DepartmentID != null && i.DepartmentID == departmentID).OrderBy(i => i.Name).ToList();
                    foreach (var indicator in indicatorItems)
                    {
                        //2 管属项目找到对应的科室类别项目映射表,找到对应科室类别
                        var departmentCategoryIndicators = indicator.DepartmentCategoryIndicatorMaps.ToList();
                        //列举出对应的科室类别,再由此找到每个科室
                        foreach (var categoryIndicator in departmentCategoryIndicators)
                        {
                            //3 通过科室类别找到管辖的科室,逐一与项目组合,添加到科室项目值表
                            var departmentCategory = categoryIndicator.DepartmentCategory;
                            if (departmentCategory == null)
                            {
                                continue;
                            }
                            var departments = departmentCategory.Departments;
                            //列出该科室负责的填报项目,再逐步添加到值表中。

                            foreach (var department in departments)
                            {
                                //需先查重,如果已经该项目已存在于数据库,不添加
                                //检查下一项
                                var query = context.DepartmentIndicatorValues.Where(d => d.DepartmentID == department.DepartmentID && d.IndicatorID == indicator.IndicatorID &&
                                                                                    d.Time.Year == addTime.Year && d.Time.Month == addTime.Month).FirstOrDefault();
                                if (query != null)
                                {
                                    continue;
                                }
                                else
                                {
                                    //不存在该项目,需添加到数据库
                                    IMS.Models.DepartmentIndicatorValue item = new IMS.Models.DepartmentIndicatorValue();
                                    item.DepartmentID = department.DepartmentID;
                                    item.IndicatorID  = indicator.IndicatorID;
                                    item.Time         = addTime;
                                    item.ID           = System.Guid.NewGuid();
                                    context.DepartmentIndicatorValues.Add(item);
                                    context.SaveChanges();
                                }
                            }
                        }
                    }
                }
                //需更新该页面 通过改变Message的值,会调用lvIndicatorValue_GetData
                //添加时间过长时,通过UpdateProcessing显示模态提示框,并能够显示进度条,添加成功后,关闭模态框
                Message.Text = "添加项目成功!";
            }
            catch (Exception ex)
            {
                Message.Text = ex.Message;
            }
        }