Esempio n. 1
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);
                }
            }
        }
 // id 参数名应该与控件上设置的 DataKeyNames 值匹配
 public void lvDepartmentIndicatorValue_UpdateItem(Guid id)
 {
     IMS.Models.DepartmentIndicatorValue item = null;
     // 在此加载该项,例如 item = MyDataLayer.Find(id);
     if (item == null)
     {
         // 未找到该项
         ModelState.AddModelError("", String.Format("未找到 id 为 {0} 的项", id));
         return;
     }
     TryUpdateModel(item);
     if (ModelState.IsValid)
     {
         // 在此保存更改,例如 MyDataLayer.SaveChanges();
     }
 }
Esempio n. 3
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();
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
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();
                            }
                        }
                    }
                }
            }
        }
Esempio n. 5
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;
            }
        }