示例#1
0
        public JsonResult SaveUserPrice(string MainID, string Data)
        {
            var list     = JsonHelper.ToList(Data);
            var costInfo = this.GetEntityByID(MainID);

            if (costInfo == null)
            {
                throw new Formula.Exceptions.BusinessException("未能找到指定的内容,无法添加个人单价");
            }
            foreach (var item in list)
            {
                var userID = item.GetValue("UserID");
                var entity = costInfo.S_W_UserUnitPrice.FirstOrDefault(d => d.UserID == userID);
                if (entity == null)
                {
                    entity          = new S_W_UserUnitPrice();
                    entity.ID       = FormulaHelper.CreateGuid();
                    entity.UserID   = item.GetValue("UserID");
                    entity.UserName = item.GetValue("UserName");
                    costInfo.S_W_UserUnitPrice.Add(entity);
                }
                entity.UnitPrice = String.IsNullOrEmpty(item.GetValue("UnitPrice")) ? 0m : Convert.ToDecimal(item.GetValue("UnitPrice"));
                entity.UserLevel = item.GetValue("UserLevel");
            }
            costInfo.ModifyDate   = DateTime.Now;
            costInfo.ModifyUser   = this.CurrentUserInfo.UserName;
            costInfo.ModifyUserID = this.CurrentUserInfo.UserID;
            this.entities.SaveChanges();
            return(Json(""));
        }
示例#2
0
        public JsonResult SaveExcel()
        {
            var    reader      = new System.IO.StreamReader(HttpContext.Request.InputStream);
            string data        = reader.ReadToEnd();
            var    tempdata    = JsonConvert.DeserializeObject <Dictionary <string, string> >(data);
            var    list        = JsonConvert.DeserializeObject <List <S_W_UserUnitPrice> >(tempdata["data"]);
            var    currentUser = FormulaHelper.GetUserInfo();
            string costInfoID  = this.GetQueryString("CostInfoID");
            var    costInfo    = this.GetEntityByID(costInfoID);

            if (costInfo == null)
            {
                throw new Formula.Exceptions.BusinessException("未能找到指定的内容,无法添加个人单价");
            }
            foreach (var item in list)
            {
                var employee = this.entities.Set <T_Employee>().FirstOrDefault(d => d.Name == item.UserName);
                if (employee == null)
                {
                    continue;
                }
                var userID = employee.UserID;
                var entity = costInfo.S_W_UserUnitPrice.FirstOrDefault(d => d.UserID == userID);
                if (entity == null)
                {
                    entity          = new S_W_UserUnitPrice();
                    entity.ID       = FormulaHelper.CreateGuid();
                    entity.UserID   = employee.UserID;
                    entity.UserName = employee.Name;
                    costInfo.S_W_UserUnitPrice.Add(entity);
                }
                entity.UnitPrice = item.UnitPrice;
                entity.UserLevel = item.UserLevel;
                this.entities.SaveChanges();
            }
            costInfo.ModifyDate   = DateTime.Now;
            costInfo.ModifyUser   = currentUser.UserName;
            costInfo.ModifyUserID = currentUser.UserID;
            return(Json("Success"));
        }
示例#3
0
        public JsonResult PushToUserPrice(string ResourceList, string formData)
        {
            var list = JsonHelper.ToList(ResourceList);
            var data = JsonHelper.ToObject(formData);

            if (String.IsNullOrEmpty(data.GetValue("StartDate")))
            {
                throw new Formula.Exceptions.BusinessValidationException("没有设置生效日期,无法批量设置单价");
            }
            if (String.IsNullOrEmpty(data.GetValue("BelongYear")))
            {
                throw new Formula.Exceptions.BusinessValidationException("没有设置生效年份,无法批量设置单价");
            }
            if (String.IsNullOrEmpty(data.GetValue("BelongMonth")))
            {
                throw new Formula.Exceptions.BusinessValidationException("没有设置生效月份,无法批量设置单价");
            }
            var startDate     = Convert.ToDateTime(data.GetValue("StartDate"));
            var belongYear    = Convert.ToInt32(data.GetValue("BelongYear"));
            var belongMonth   = Convert.ToInt32(data.GetValue("BelongMonth"));
            var isRemoveLater = data.GetValue("RemoveLater") == true.ToString().ToLower() ? true : false;

            foreach (var item in list)
            {
                var resCode = item.GetValue("ResourceCode");
                if (String.IsNullOrEmpty(resCode))
                {
                    continue;
                }
                var resourceList = this.entities.Set <S_W_ResourcePrice>().Where(c => c.ResourceCode == resCode &&
                                                                                 c.StartDate >= startDate).ToList();
                //此处需要判定起始日期是否有单价记录,如果没有单价记录,则需要去之前一个有单价记录的数据来作为起始日期的单价
                var startResInfo = resourceList.FirstOrDefault(c => c.StartDate == startDate);
                if (startResInfo == null)
                {
                    startResInfo = this.entities.Set <S_W_ResourcePrice>().Where(c => c.ResourceCode == resCode && c.StartDate <= startDate).OrderByDescending(c => c.StartDate).FirstOrDefault();
                    if (startResInfo != null)
                    {
                        var resInfo = startResInfo.Clone <S_W_ResourcePrice>();
                        resInfo.StartDate   = new DateTime(belongYear, belongMonth, 1);
                        resInfo.BelongYear  = belongYear;
                        resInfo.BelongMonth = belongMonth;
                        resourceList.Add(resInfo);
                    }
                }
                var userPriceList = this.entities.Set <S_W_UserUnitPrice>().Where(c => c.ResourceCode == resCode).ToList();
                var userInfoList  = userPriceList.Select(c => new { UserName = c.UserName, UserID = c.UserID, HRUserID = c.HRUserID }).Distinct().ToList();

                foreach (var userInfo in userInfoList)
                {
                    foreach (var resPriceInfo in resourceList.OrderBy(c => c.StartDate).ToList())
                    {
                        var priceInfo = userPriceList.FirstOrDefault(c => c.UserID == userInfo.UserID && c.StartDate == resPriceInfo.StartDate);
                        if (priceInfo == null)
                        {
                            priceInfo              = new S_W_UserUnitPrice();
                            priceInfo.ID           = FormulaHelper.CreateGuid();
                            priceInfo.UserName     = userInfo.UserName;
                            priceInfo.UserID       = userInfo.UserID;
                            priceInfo.HRUserID     = userInfo.HRUserID;
                            priceInfo.ResourceCode = resPriceInfo.ResourceCode;
                            priceInfo.UnitPrice    = resPriceInfo.UnitPrice;
                            priceInfo.StartDate    = resPriceInfo.StartDate;
                            priceInfo.ModifyDate   = DateTime.Now;
                            priceInfo.ModifyUser   = this.CurrentUserInfo.UserName;
                            priceInfo.ModifyUserID = this.CurrentUserInfo.UserID;
                            priceInfo.CreateDate   = DateTime.Now;
                            priceInfo.BelongYear   = resPriceInfo.BelongYear;
                            priceInfo.BelongMonth  = resPriceInfo.BelongMonth;
                            this.entities.Set <S_W_UserUnitPrice>().Add(priceInfo);
                        }
                        else if (priceInfo.ResourceCode == resPriceInfo.ResourceCode)
                        {
                            priceInfo.UnitPrice    = resPriceInfo.UnitPrice;
                            priceInfo.ModifyDate   = DateTime.Now;
                            priceInfo.ModifyUser   = this.CurrentUserInfo.UserName;
                            priceInfo.ModifyUserID = this.CurrentUserInfo.UserID;
                        }
                    }
                }
                this.entities.SaveChanges();
            }
            return(Json(""));
        }