示例#1
0
        public ResultObj Add(OilStation obj)
        {
            // 获取当前登录用户名
            string _currentUserName = CommonService.GetCurrentUser(HttpContext).UserName;

            ResultObj resultObj = new ResultObj();

            if (IsExistSame(obj))
            {
                resultObj.IsSuccess = false;
                resultObj.ErrMsg    = "该站名已存在。";
                return(resultObj);
            }

            obj.CreateUser     = _currentUserName;
            obj.CreateTime     = DateTime.Now;
            obj.LastUpdateUser = _currentUserName;
            obj.LastUpdateTime = DateTime.Now;

            _context.OilStation.Add(obj);
            _context.SaveChanges();

            resultObj.IsSuccess = true;
            return(resultObj);
        }
示例#2
0
        // 判断是否存在相同站名
        public bool IsExistSame(OilStation obj)
        {
            var where = _context.OilStation.Where(p => p.Name == obj.Name);
            if (obj.PK != null)
            {
                where = where.Where(p => p.PK != obj.PK);
            }
            List <OilStation> list = where.ToList();

            if (list.Count > 0)
            {
                return(true);
            }
            return(false);
        }
示例#3
0
        public ResultObj Update(OilStation newObj)
        {
            // 获取当前登录用户名
            string _currentUserName = CommonService.GetCurrentUser(HttpContext).UserName;

            ResultObj resultObj = new ResultObj();

            var obj = _context.OilStation.Find(newObj.PK);

            if (obj == null)
            {
                resultObj.IsSuccess = false;
                resultObj.ErrMsg    = "修改对象不存在。";
                return(resultObj);
            }

            if (IsExistSame(newObj))
            {
                resultObj.IsSuccess = false;
                resultObj.ErrMsg    = "该站名已存在。";
                return(resultObj);
            }
            obj.Branch          = newObj.Branch;
            obj.Name            = newObj.Name;
            obj.District        = newObj.District;
            obj.PLCIP           = newObj.PLCIP;
            obj.HMIIP           = newObj.HMIIP;
            obj.VolumnPer1cm    = newObj.VolumnPer1cm;
            obj.LevelCalcFactor = newObj.LevelCalcFactor;
            obj.LevelCalcOffset = newObj.LevelCalcOffset;
            obj.PumpRatedFlow   = newObj.PumpRatedFlow;
            obj.PumpCalcFactor  = newObj.PumpCalcFactor;
            obj.PumpCalcOffset  = newObj.PumpCalcOffset;
            obj.Latitude        = newObj.Latitude;
            obj.Longitude       = newObj.Longitude;
            obj.Remark          = newObj.Remark;

            obj.LastUpdateTime = DateTime.Now;
            obj.LastUpdateUser = _currentUserName;

            _context.OilStation.Update(obj);
            _context.SaveChanges();

            resultObj.IsSuccess = true;
            return(resultObj);
        }