Example #1
0
        public string GetUnitQuota(string loginIdentifer, string unitQuotaId)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2["Result"]  = false;
            obj2["Message"] = "";
            try
            {
                ResMsg unitQuotaInfoById = CommonUtil.CheckLoginState(loginIdentifer, false);
                if (!unitQuotaInfoById.Result)
                {
                    obj2["Message"] = unitQuotaInfoById.Message;
                    return(JavaScriptConvert.SerializeObject(obj2));
                }
                if ((unitQuotaId == null) || (unitQuotaId.Trim() == ""))
                {
                    obj2["Message"] = "参数'unitQuotaId'无效";
                    return(JavaScriptConvert.SerializeObject(obj2));
                }
                Crop             crop = CropModule.GetCrop(long.Parse(unitQuotaId));
                JavaScriptObject obj3 = this.UnitQuotaInfoToJson(crop);
                obj2["Result"]    = true;
                obj2["UnitQuota"] = obj3;
            }
            catch (Exception exception)
            {
                obj2["Message"] = exception.Message;
            }
            return(JavaScriptConvert.SerializeObject(obj2));
        }
Example #2
0
        public string ModifyUnitQuotas(string loginIdentifer, string unitQuotaJson)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2["Result"]  = false;
            obj2["Message"] = "";
            LoginUser loginUser = GlobalAppModule.GetLoginUser(loginIdentifer);

            if (loginUser == null)
            {
                obj2["Message"] = "未登录";
                return(JavaScriptConvert.SerializeObject(obj2));
            }
            if (loginUser.LoginTimeout)
            {
                obj2["Message"] = "登录超时";
                return(JavaScriptConvert.SerializeObject(obj2));
            }
            loginUser.LastOperateTime = DateTime.Now;
            CommonUtil.WaitMainLibInit();
            JavaScriptObject obj3 = (JavaScriptObject)JavaScriptConvert.DeserializeObject(unitQuotaJson);

            if (obj3 == null)
            {
                obj2["Message"] = "参数格式错误";
                return(JavaScriptConvert.SerializeObject(obj2));
            }
            try
            {
                Crop crop = CropModule.GetCrop(long.Parse(obj3["ID"].ToString()));
                crop.CropName   = obj3["名称"].ToString();
                crop.WaterPerMu = decimal.Parse(obj3["单位定额"].ToString());
                crop.Remark     = "";

                string msg = CropModule.ModifyCropInfo(crop);
                if (msg == "修改成功")//msg.Result
                {
                    GlobalAppModule.IsInitMainLib = true;
                    CropModule.LoadUnitQuotaInfos();
                    GlobalAppModule.IsInitMainLib = false;
                    obj2["Result"]  = true;
                    obj2["Message"] = "成功";
                }
                else
                {
                    obj2["Message"] = msg;
                }
                try
                {
                    SysLog log = new SysLog();
                    log.LogUserId   = loginUser.UserId;
                    log.LogUserName = loginUser.LoginName;
                    log.LogAddress  = ToolsWeb.GetIP(context.Request);
                    log.LogTime     = DateTime.Now;
                    log.LogType     = "修改作物";
                    log.LogContent  = msg + "|" + ModelHandler <Crop> .ToString(crop);

                    SysLogModule.Add(log);
                }
                catch { }
            }
            catch (Exception exception)
            {
                obj2["Message"] = exception.Message;
            }
            return(JavaScriptConvert.SerializeObject(obj2));
        }
        private JavaScriptObject DeviceNodeToJson(Device device)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            //obj2["ID"] = device.Id;
            obj2.Add("ID", device.Id);
            obj2["SimNo"] = device.SimNo;
            //obj2["DeviceName"] = device.DeviceName;
            obj2.Add("名称", device.DeviceName);
            obj2["Description"]  = device.Description;
            obj2["SetupDate"]    = device.SetupDate.ToString("yyyy-MM-dd HH:mm");
            obj2["SetupAddress"] = device.SetupAddress;
            obj2["LON"]          = device.LON / 1000000.0;
            obj2["LAT"]          = device.LAT / 1000000.0;
            obj2["IsValid"]      = device.IsValid;
            obj2["LastUpdate"]   = device.LastUpdate.ToString("yyyy-MM-dd HH:mm");
            //obj2["DistrictId"] = device.DistrictId;
            obj2.Add("管理ID", device.DistrictId);
            string districtName = DistrictModule.GetDistrictName(device.DistrictId);

            if (districtName != null)
            {
                obj2.Add("管理名称", districtName);
            }
            else
            {
                obj2.Add("管理名称", "未知");
            }
            obj2["DeviceNo"]               = device.DeviceNo;
            obj2["Online"]                 = device.Online;
            obj2["OnlineTime"]             = device.OnlineTime;
            obj2["YearExploitation"]       = device.YearExploitation;
            obj2["AlertAvailableWater"]    = device.AlertAvailableWater;
            obj2["AlertAvailableElectric"] = device.AlertAvailableElectric;
            obj2["DeviceTypeCodeId"]       = device.DeviceTypeCodeId;
            obj2["MeterPulse"]             = device.MeterPulse;
            obj2["AlertWaterLevel"]        = device.AlertWaterLevel;
            obj2["TerminalState"]          = device.TerminalState;
            obj2["Remark"]                 = device.Remark;
            obj2["CropId"]                 = device.CropId;
            Crop crop = CropModule.GetCrop(device.CropId);

            if (crop != null)
            {
                obj2["Crop"] = crop.CropName;
            }
            else
            {
                obj2["Crop"] = "未知";
            }
            obj2["Area"]        = device.Area;
            obj2["StationType"] = device.StationType.ToString().PadLeft(2, '0');
            obj2["StationCode"] = device.StationCode;
            //obj2["Frequency"] = device.Frequency.ToString("X").PadLeft(2, '0');

            switch (device.StationType)
            {
            case 0: obj2["StationTypeStr"] = "单站"; break;

            case 1: obj2["StationTypeStr"] = "主站"; break;

            case 2: obj2["StationTypeStr"] = "从站"; break;

            default: obj2["StationTypeStr"] = "单站"; break;
            }
            Device MainD = DeviceModule.GetDeviceByID(device.MainId);

            if (MainD != null)
            {
                obj2["MainDevNum"] = MainD.DeviceNo.PadLeft(3, '0');
            }
            else
            {
                obj2["MainDevNum"] = "";
            }
            obj2["DeviceType"]    = device.DeviceType;
            obj2["SlaveList"]     = "";
            obj2["RemoteStation"] = device.RemoteStation;
            List <Device> list = DeviceModule.GetAllDeviceSubList(device.Id);

            if (list != null && list.Count > 0)
            {
                JavaScriptArray array = new JavaScriptArray();
                foreach (Device dSub in list)
                {
                    JavaScriptObject objSub = new JavaScriptObject();
                    objSub.Add("ID", dSub.Id);
                    objSub.Add("名称", dSub.DeviceName);
                    objSub.Add("编号", dSub.DeviceNo);
                    objSub.Add("StationCode", dSub.StationCode);
                    objSub.Add("DeviceType", dSub.DeviceType);
                    array.Add(objSub);
                }
                obj2["SlaveList"] = array;
            }

            return(obj2);
        }