Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
0
        public string PayPalTransactionProcessLongRunningAction(string id, int PaypalApi, string RangeDate)
        {
            using (ImsDbContext dbContext = new ImsDbContext())
            {
                dbContext.Configuration.AutoDetectChangesEnabled = false;
                PaypalApi paypalApi = dbContext.PaypalApis.Find(PaypalApi);
                dbContext.Configuration.AutoDetectChangesEnabled = true;
                this.ImsService.PayPalHelper(paypalApi);
                string   dataRange = RangeDate;
                string[] date      = dataRange.Split(new char[] { '-' });

                DateTime startDate = DateTime.Parse(date[0].Trim());
                DateTime endDate   = DateTime.Parse(date[1].Trim());

                IEnumerable <PaymentTransactionSearchResultType> PaypalTransactionSearch = this.ImsService.ApiTransactionSearch(startDate, endDate);
                int total = PaypalTransactionSearch.Count <PaymentTransactionSearchResultType>();


                if (PaypalTransactionSearch.Count() > 0)
                {
                    var lastsearch = PaypalTransactionSearch.Last();
                    var lastdetail = this.ImsService.ApiTransactionDetail(lastsearch);
                    ProcessLastDate = lastdetail.PaymentTransactionDetails.PaymentInfo.PaymentDate;
                }
                else
                {
                    ProcessLastDate = startDate.ToCnDataString();
                }
                int i = 0;
                // List<PayPalTransaction> pptlist = new List<PayPalTransaction>();
                PaypalTransactionSearch.ToList().ForEach(a =>
                {
                    GetTransactionDetailsResponseType PaypalTransactionDetails = this.ImsService.ApiTransactionDetail(a);
                    if (PaypalTransactionDetails.Ack.Equals(AckCodeType.SUCCESS))
                    {
                        i++;
                        int d = Precentage(i, total);

                        lock (syncRoot)
                        {
                            ProcessStatus[id] = d;
                            ProcessTotal      = total;
                            ProcessNumber     = i + 1;
                        }
                        dbContext.Configuration.AutoDetectChangesEnabled = false;
                        bool flag = dbContext.PayPalTransactions.AsNoTracking().Count(j => j.TransactionId == a.TransactionID) == 0;
                        dbContext.Configuration.AutoDetectChangesEnabled = true;
                        if (flag)
                        {
                            var detail = this.ImsService.PayPayTransaction(PaypalTransactionDetails);
                            // pptlist.Add(detail);
                            dbContext.Insert <PayPalTransaction>(detail);
                        }
                    }
                });
                // dbContext.PayPalTransactions.AddRange(pptlist);
                // dbContext.SaveChanges();
            }
            return(id);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 获取“结果指标”的值。(通过“时段的开始时间”和“时段的结束时间”)。
 /// </summary>
 /// <param name="departmentId">科室ID。</param>
 /// <param name="indicatorId">指标ID。</param>
 /// <param name="start">时段的开始时间。</param>
 /// <param name="end">时段的结束时间。</param>
 /// <returns>指定时段的指定科室的指定指标的值。</returns>
 /// <remarks>时间点不做修正,请在调用的代码中自行修正。内部调用默认Ims上下文。</remarks>
 /// <example>
 /// <code>
 /// decimal value = GetDepartmentIndicatorValueValueByCalculate(departmentId, indicatorId, new DateTime(2016, 1, 1), new DateTime(2016, 1, 31));
 /// </code>
 /// </example>
 public static decimal GetDepartmentIndicatorValueValueByCalculate(Guid departmentId, Guid indicatorId, DateTime start, DateTime end)
 {
     using (var imsDbContext = new ImsDbContext())
     {
         return(GetDepartmentIndicatorValueValue(imsDbContext, departmentId, indicatorId, start, end));
     }
 }
Ejemplo n.º 6
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.º 7
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);
                }
            }
        }
        // 返回类型可以更改为 IEnumerable,但是为了支持
        // 分页和排序,必须添加以下参数:
        //     int maximumRows
        //     int startRowIndex
        //     out int totalRowCount
        //     string sortByExpression
        public IQueryable <IMS.Models.DepartmentCategoryIndicatorMap> gvCategoryIndicator_GetData()
        {
            IQueryable <IMS.Models.DepartmentCategoryIndicatorMap> query = null;
            ImsDbContext context = new ImsDbContext();

            query = context.DepartmentCategoryIndicatorMaps.Include(i => i.DepartmentCategory).Include(i => i.Indicator).OrderBy(o => o.DepartmentCategory.Name);
            return(query);
        }
Ejemplo n.º 9
0
        // 返回类型可以更改为 IEnumerable,但是为了支持
        // 分页和排序,必须添加以下参数:
        //     int maximumRows
        //     int startRowIndex
        //     out int totalRowCount
        //     string sortByExpression
        public IQueryable <IMS.Models.Indicator> lvIndicator_GetData()
        {
            IQueryable <IMS.Models.Indicator> query = null;
            ImsDbContext context = new ImsDbContext();

            query = context.Indicators.OrderBy(o => o.Name);
            return(query);
        }
Ejemplo n.º 10
0
        // 返回类型可以更改为 IEnumerable,但是为了支持
        // 分页和排序,必须添加以下参数:
        //     int maximumRows
        //     int startRowIndex
        //     out int totalRowCount
        //     string sortByExpression
        public IQueryable <IMS.Models.DepartmentCategory> lvDepartmentCategory_GetData()
        {
            IQueryable <IMS.Models.DepartmentCategory> query = null;
            ImsDbContext context = new ImsDbContext();

            query = context.DepartmentCategories.OrderBy(o => o.Name);
            return(query);
        }
Ejemplo n.º 11
0
        // 返回类型可以更改为 IEnumerable,但是为了支持
        // 分页和排序,必须添加以下参数:
        //     int maximumRows
        //     int startRowIndex
        //     out int totalRowCount
        //     string sortByExpression
        public IQueryable <IMS.Models.Department> ListView1_GetData()
        {
            IQueryable <IMS.Models.Department> query = null;
            ImsDbContext context = new ImsDbContext();

            query = context.Departments;
            return(query);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 获取“指标”的值。(通过“时间点”和“波及的月份时长”)。
        /// </summary>
        /// <param name="imsDbContext">IMS上下文。</param>
        /// <param name="departmentId">科室ID。</param>
        /// <param name="indicatorId">指标ID。</param>
        /// <param name="time">时间点。</param>
        /// <param name="duarationMonth">波及的月份时长。</param>
        /// <returns>指定时段的指定科室的指定指标的值。当算法操作符为空时,返回0。当除数为0时,直接返回0。</returns>
        /// <exception cref="ArgumentOutOfRangeException">波及的月份时长必须为正整数。</exception>
        /// <remarks>时间点自动修正为波及时段的起始和终末日期。</remarks>
        /// <example>
        /// <code>
        /// decimal value = GetDepartmentIndicatorValueValue(new ImsDbContext(), departmentId, indicatorId, new DateTime(2016, 1, 15), 2);
        /// //将获取2016年1月1日至2016年2月29日的数据。
        /// </code>
        /// </example>
        public static decimal GetDepartmentIndicatorValueValue(ImsDbContext imsDbContext, Guid departmentId, Guid indicatorId, DateTime time, int duarationMonth)
        {
            if (duarationMonth <= 0)
            {
                throw new ArgumentOutOfRangeException("波及的月份时长必须为正整数。");
            }

            return(GetDepartmentIndicatorValueValue(imsDbContext, departmentId, indicatorId, new DateTime(time.Year, time.Month, 1), new DateTime(time.Year, time.Month, 1).AddMonths(duarationMonth).AddDays(-1)));
        }
Ejemplo n.º 13
0
        // 返回类型可以更改为 IEnumerable,但是为了支持
        // 分页和排序,必须添加以下参数:
        //     int maximumRows
        //     int startRowIndex
        //     out int totalRowCount
        //     string sortByExpression
        public IQueryable <IMS.Models.DepartmentIndicatorValue> lvDepartmentIndicatorValue_GetData()
        {
            IQueryable <IMS.Models.DepartmentIndicatorValue> query = null;
            ImsDbContext context = new ImsDbContext();

            //query = context.DepartmentIndicatorValues.Include(i => i.Department).Include(i => i.Indicator).OrderBy(i => i.Department.DepartmentName);

            return(query);
        }
Ejemplo n.º 14
0
        public string PaymentTransactionProcessLongRunningAction(string id, int PaypalApi, string RangeDate)
        {
            PaypalApi paypalApi = this.ImsService.GetPaypalApi(PaypalApi);

            this.ImsService.PayPalHelper(paypalApi);

            string dataRange = RangeDate;

            string[] date = dataRange.Split(new char[] { '-' });

            DateTime startDate = DateTime.Parse(date[0].Trim());
            DateTime endDate   = DateTime.Parse(date[1].Trim());

            IEnumerable <PaymentTransactionSearchResultType> PaypalTransactionSearch = this.ImsService.ApiTransactionSearch(startDate, endDate);
            var total = PaypalTransactionSearch.Count <PaymentTransactionSearchResultType>();


            int i = 0;

            foreach (var item in PaypalTransactionSearch)
            {
                GetTransactionDetailsResponseType PaypalTransactionDetails = this.ImsService.ApiTransactionDetail(item);
                if (PaypalTransactionDetails.Ack.Equals(AckCodeType.SUCCESS))
                {
                    i++;
                    int d = Precentage(i, total);

                    lock (syncRoot)
                    {
                        ProcessStatus[id] = d;
                    }


                    /*TransactionDetailRequest request = new TransactionDetailRequest
                     * {
                     *  TransactionID = item.TransactionID
                     * };*/

                    PaymentTransactionRequest request = new PaymentTransactionRequest
                    {
                        TransactionID = item.TransactionID
                    };
                    if (this.ImsService.GetPaymentTransactionList(request).Count() == 0)
                    {
                        var detail = this.ImsService.PaymentTransaction(PaypalTransactionDetails);

                        using (var dbContext = new ImsDbContext())
                        {
                            dbContext.Insert <Evisou.Ims.Contract.Model.PayPal.PaymentTransactionType>(detail);
                        }
                    }
                }
            }

            return(id);
        }
Ejemplo n.º 15
0
        // 返回类型可以更改为 IEnumerable,但是为了支持
        // 分页和排序,必须添加以下参数:
        //     int maximumRows
        //     int startRowIndex
        //     out int totalRowCount
        //     string sortByExpression
        public IQueryable <IMS.Models.Department> lvDepartment_GetData()
        {
            IQueryable <IMS.Models.Department> query = null;
            ImsDbContext context = new ImsDbContext();

            query = context.Departments.OrderBy(o => o.DepartmentName).Include(i => i.DepartmentCategory)
                    .OrderBy(d => d.DepartmentName).AsQueryable();

            return(query);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 获取“指标”的值。(通过“时段的开始时间”和“时段的结束时间”)。
        /// </summary>
        /// <param name="imsDbContext">IMS上下文。</param>
        /// <param name="departmentId">科室ID。</param>
        /// <param name="indicatorId">指标ID。</param>
        /// <param name="start">时段的开始时间。</param>
        /// <param name="end">时段的结束时间。</param>
        /// <returns>指定时段的指定科室的指定指标的值。当算法操作符为空时,返回0。当除数为0时,直接返回0。</returns>
        /// <remarks>时间点不做修正,请在调用的代码中自行修正。</remarks>
        /// <example>
        /// <code>
        /// decimal value = GetDepartmentIndicatorValueValue(new ImsDbContext(), departmentId, indicatorId, new DateTime(2016, 1, 1), new DateTime(2016, 1, 31));
        /// </code>
        /// </example>
        public static decimal GetDepartmentIndicatorValueValue(ImsDbContext imsDbContext, Guid departmentId, Guid indicatorId, DateTime start, DateTime end)
        {
            //检测“算法表”中是否有对应“IndicatorId”的项目

            var indicatorAlgorithm = imsDbContext.IndicatorAlgorithms.Where(i => i.ResultOperationID == indicatorId).FirstOrDefault();

            if (indicatorAlgorithm != null)//在“算法表”中找到。
            {
                //当算法操作符为空时,返回0。
                if (indicatorAlgorithm.Operation == null)
                {
                    return(decimal.Zero);
                }

                //获取两个操作数

                decimal FirstOperand  = GetDepartmentIndicatorValueValue(imsDbContext, departmentId, indicatorAlgorithm.FirstOperationID.Value, start, end);
                decimal SecondOperand = GetDepartmentIndicatorValueValue(imsDbContext, departmentId, indicatorAlgorithm.SecondOperationID.Value, start, end);

                //执行操作符所代表的计算过程。

                switch (indicatorAlgorithm.Operation)
                {
                case ("addition"):
                    return(FirstOperand + SecondOperand);

                case ("subtraction"):
                    return(FirstOperand - SecondOperand);

                case ("multiplication"):
                    return(FirstOperand * SecondOperand);

                case ("division"):
                    return((SecondOperand == decimal.Zero) ? decimal.Zero : FirstOperand / SecondOperand);    //除数为0时,返回0。

                default:
                    return(decimal.Zero);
                }
            }
            else //最终尝试在“值表”中找。
            {
                //在“值表”中不应该查找出“结果指标”,更不可能对其进行整合,因为“结果指标”不可以直接整合,而必须由“算法表”中通过获取其计算方法并执行相应计算而得出。逻辑上不会出现在“值表”中查找“结果指标”的可能性,因为在维护“算法表”的时候,已设置所有“结果指标”的“指标ID”,所以当尝试在“算法表”中寻找“结果指标”时,必然命中。

                var queryDepartmentIndicatorValue = imsDbContext.DepartmentIndicatorValues.Where(i => i.IndicatorID == indicatorId && i.DepartmentID == departmentId && i.Time <= end && i.Time >= start);
                if (queryDepartmentIndicatorValue.Any())
                {
                    decimal?returnedValue = queryDepartmentIndicatorValue.Sum(i => i.Value);
                    return(returnedValue.HasValue ? returnedValue.Value : decimal.Zero);
                }
                else
                {
                    return(decimal.Zero);
                }
            }
        }
Ejemplo n.º 17
0
        public Decimal GetDepartmentIndicatorValueByCalculate(Guid departmentId, Guid indicatorId, DateTime time)
        {
            decimal value = Decimal.Zero;

            using (ImsDbContext context = new ImsDbContext())
            {
                //根据inidicatorId从IndicatorAlgorithm中找到ResultOperation
                value = GetDepartmentIndicatorValue(context, departmentId, indicatorId, time);
            }
            return(value);
        }
Ejemplo n.º 18
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.º 19
0
        // 返回类型可以更改为 IEnumerable,但是为了支持
        // 分页和排序,必须添加以下参数:
        //     int maximumRows
        //     int startRowIndex
        //     out int totalRowCount
        //     string sortByExpression
        public IQueryable <IMS.Models.Indicator> GridView3_GetData([Control] Guid?lblID)
        {
            IQueryable <IMS.Models.Indicator> query = null;

            if (lblID != null)
            {
                ImsDbContext context = new ImsDbContext();
                query = context.Indicators.Where(i => i.DepartmentID == lblID).OrderBy(i => i.Name);
            }
            return(query);
        }
Ejemplo n.º 20
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.º 21
0
        public DepartmentCategory FindDepartmentCategoryByName(string name)
        {
            DepartmentCategory item = null;

            if (name != null)
            {
                using (ImsDbContext context = new ImsDbContext())
                {
                    item = context.DepartmentCategories.Where(d => d.Name == name).FirstOrDefault();
                }
            }
            return(item);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Finds the name of the indicator by.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns>IMS.Models.Indicator.</returns>
        public Indicator FindIndicatorByName(string name)
        {
            Indicator item = null;

            if (name != null)
            {
                using (ImsDbContext context = new ImsDbContext())
                {
                    item = context.Indicators.Where(i => i.Name == name).FirstOrDefault();
                }
            }
            return(item);
        }
Ejemplo n.º 23
0
        public Dictionary <Guid, string> GetDataSourceSystemDic()
        {
            Dictionary <Guid, string> listData = new Dictionary <Guid, string>();

            using (ImsDbContext context = new ImsDbContext())
            {
                //listData.Add(" ", "-全选-");
                foreach (var query in context.DataSourceSystems)
                {
                    listData.Add(query.ID, query.Name);
                }
            }
            return(listData);
        }
Ejemplo n.º 24
0
        public Dictionary <Guid, string> GetDepartmentCategoryDic()
        {
            Dictionary <Guid, string> listData = new Dictionary <Guid, string>();

            using (ImsDbContext context = new ImsDbContext())
            {
                //listData.Add(" ", "-全选-");
                foreach (var query in context.DepartmentCategories)
                {
                    listData.Add(query.DepartmentCategoryID, query.Name);
                }
            }
            return(listData);
        }
Ejemplo n.º 25
0
        // 返回类型可以更改为 IEnumerable,但是为了支持
        // 分页和排序,必须添加以下参数:
        //     int maximumRows
        //     int startRowIndex
        //     out int totalRowCount
        //     string sortByExpression
        public IQueryable <IMS.Models.Indicator> lvIndicatorItem_GetData([Control] Guid?dlSourceSystem, [Control] DateTime?txtDate)
        {
            IQueryable <IMS.Models.Indicator> query = null;

            if (dlSourceSystem != null)
            {
                ImsDbContext context = new ImsDbContext();

                //需找到该Department
                //var department = context.Departments.Find(dlSourceSystem);
                query = context.Indicators.Where(i => i.DataSourceSystemID != null && i.DataSourceSystemID == dlSourceSystem).OrderBy(i => i.Name);
            }
            return(query);
        }
Ejemplo n.º 26
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.º 27
0
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            //将ddlDepartmentCategory的ID与时间传入到列表中,获取DataTable,先绑定到GridView查看一下内容,之后再导出到Excel表中
            //保存到一个ReportFileTemp再下载
            DateTime startTime            = DateTime.Parse(txtTimeFrom.Text);
            DateTime endTime              = DateTime.Parse(txtTimeTo.Text);
            Guid     departmentCategoryID = Guid.Parse(ddlDepartmentCategory.SelectedValue);

            if (DateTime.Compare(endTime, startTime) < 0)
            {
                Message.Text = "截止时间不能小于开始时间!";
            }
            using (ImsDbContext context = new ImsDbContext())
            {
                var dt = Logic.Reports.GetGenericReport(context, departmentCategoryID, startTime, endTime);
                //先分析表结构
                //添加固定的headerTitle
                List <string> headTitleList = new List <string>();
                //将列名写到headColumnNameList中
                List <string> headColumnList = new List <string>();
                foreach (DataColumn columnName in dt.Columns)
                {
                    headColumnList.Add(columnName.ColumnName);
                }

                List <List <string> > itemValueListList = new List <List <string> >();
                foreach (DataRow row in dt.Rows)
                {
                    List <string> itemValueList = new List <string>();

                    foreach (DataColumn column in dt.Columns)
                    {
                        itemValueList.Add(row[column].ToString());
                    }
                    itemValueListList.Add(itemValueList);
                }
                //写入到Excel表中

                string titleName = ddlDepartmentCategory.SelectedItem.Text + txtTimeFrom.Text + "至" + txtTimeTo.Text + "汇总报表";
                headTitleList.Add(titleName);
                string fileName = "/ReportFileTemp/" + ddlDepartmentCategory.SelectedItem.Text + DateTime.UtcNow.ToBinary().ToString() + ".xlsx";
                string filePath = Server.MapPath(fileName);
                new WriteToExcel().WriteItemValueToExcel(filePath, headTitleList, headColumnList, itemValueListList);
                //将页面转至文件名处,提供下载
                Response.Redirect(fileName);
            }
        }
Ejemplo n.º 28
0
        // 返回类型可以更改为 IEnumerable,但是为了支持
        // 分页和排序,必须添加以下参数:
        //     int maximumRows
        //     int startRowIndex
        //     out int totalRowCount
        //     string sortByExpression
        public IQueryable <IMS.Models.DepartmentIndicatorValue> lvIndicatorValue_GetData([Control] Guid?dlDepartment, [Control] DateTime?txtDate, [Control] string Message)
        {
            IQueryable <IMS.Models.DepartmentIndicatorValue> query = null;

            if (dlDepartment == null || txtDate == null)
            {
                return(query);
            }

            ImsDbContext context = new ImsDbContext();

            //找到该项目管辖的项目
            query = context.DepartmentIndicatorValues.Include(i => i.Indicator).Include(i => i.Department)
                    .Where(d => d.Indicator.DepartmentID == dlDepartment && d.Time == txtDate).OrderBy(i => i.Department.DepartmentName).ThenBy(t => t.Indicator.Name);

            return(query);
        }
Ejemplo n.º 29
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.º 30
0
 // id 参数名应该与控件上设置的 DataKeyNames 值匹配
 public void lvDepartmentIndicatorValue_UpdateItem(Guid id)
 {
     //管理员管理此项目,可不设删除限制
     using (ImsDbContext context = new ImsDbContext())
     {
         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();
         }
     }
 }