Esempio n. 1
0
        /// <summary>
        /// 修改楼栋信息
        /// </summary>
        /// <param name="buildingId"></param>
        /// <param name="cityId"></param>
        /// <param name="userName"></param>
        /// <param name="buildingObj"></param>
        /// <param name="message"></param>
        /// <param name="_db"></param>
        /// <returns></returns>
        public static int UpdateBuildingInfo(int buildingId, int cityId, string userName, JObject buildingObj, out string message, DataBase _db = null)
        {
            DateTime nowTime = DateTime.Now;
            DataBase db      = new DataBase(_db);

            message = "";
            //更新Building值
            DATBuilding building = DATBuildingManager.GetBuildingByBuildingId(buildingId, cityId, _db: db);

            if (building == null)
            {
                db.Close();
                message = "楼栋不存在或已被删除";
                return(0);
            }
            try
            {
                foreach (var _prop in buildingObj)
                {
                    string key      = _prop.Key;
                    var    property = building.GetType().GetProperties()
                                      .Where(pInfo => pInfo.Name.ToLower().Equals(key.ToLower())).FirstOrDefault();
                    if (property == null)
                    {
                        continue;
                    }
                    object _value = CommonUtility.valueType(property.PropertyType, _prop.Value.Value <JValue>().Value, true);
                    property.SetValue(building, _value, null);
                }
                building.SaveDateTime = nowTime;  //最后修改时间
                building.SaveUser     = userName; //修改人
                db.DB.Update(building);
            }
            catch (Exception ex)
            {
                db.Close();
                message = "系统异常";
                log.Error("修改楼栋时失败,buildingId:" + buildingId, ex);
                return(-1);
            }
            db.Close();
            return(1);
        }
Esempio n. 2
0
        /// <summary>
        /// 修改房号信息
        /// </summary>
        /// <param name="houseId"></param>
        /// <param name="cityId"></param>
        /// <param name="userName"></param>
        /// <param name="houseObj"></param>
        /// <param name="message"></param>
        /// <param name="_db"></param>
        /// <returns></returns>
        public static int UpdateHouseInfo(int houseId, int cityId, string userName, JObject houseObj, out string message, DataBase _db = null)
        {
            DateTime nowTime = DateTime.Now;
            DataBase db      = new DataBase(_db);

            message = "";
            //更新house值
            DATHouse house = DATHouseManager.GetHouseByHouseId(houseId, cityId, _db: db);

            if (house == null)
            {
                db.Close();
                message = "房号不存在或已被删除";
                return(0);
            }
            try
            {
                foreach (var _prop in houseObj)
                {
                    string key      = _prop.Key;
                    var    property = house.GetType().GetProperties()
                                      .Where(pInfo => pInfo.Name.ToLower().Equals(key.ToLower())).FirstOrDefault();
                    if (property == null)
                    {
                        continue;
                    }
                    object _value = CommonUtility.valueType(property.PropertyType, _prop.Value.Value <JValue>().Value, true);
                    property.SetValue(house, _value, null);
                }
                house.SaveDateTime = nowTime;  //最后修改时间
                house.SaveUser     = userName; //修改人

                DATBuilding building = DATBuildingManager.GetBuildingByBuildingId(house.BuildingId, cityId, db);
                if (building.TotalFloor.HasValue && house.EndFloorNo.HasValue && house.EndFloorNo > building.TotalFloor)
                {
                    db.Close();
                    message = "房号终止楼层不能大于楼栋总层数";
                    return(0);
                }
                else if (house.EndFloorNo.HasValue && house.EndFloorNo < house.FloorNo)
                {
                    db.Close();
                    message = "起始楼层不能大于终止楼层";
                    return(0);
                }
                else if (house.EndFloorNo.HasValue && (house.EndFloorNo < -5 || house.FloorNo < -5))
                {
                    db.Close();
                    message = "房号的起始楼层和终止楼层不能小于-5";
                    return(0);
                }
                else
                {
                    db.DB.Update(house);
                }
            }
            catch (Exception ex)
            {
                db.Close();
                message = "系统异常";
                log.Error("修改房号时失败,houseId:" + houseId, ex);
                return(-1);
            }
            db.Close();
            return(1);
        }