Exemplo n.º 1
0
        public string Logout(string loginIdentifer)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2.Add("Result", false);
            obj2.Add("Message", "");
            try
            {
                LoginUser loginUser = GlobalAppModule.GetLoginUser(loginIdentifer);
                if (loginUser != null)
                {
                    GlobalAppModule.RemoveLoginUser(loginIdentifer);
                }
                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  = "";
                    SysLogModule.Add(log);
                }
                catch { }
                obj2["Result"] = true;
            }
            catch (Exception exception)
            {
                obj2["Message"] = exception.Message;
            }
            return(JavaScriptConvert.SerializeObject(obj2));
        }
        public string DeleteRole(string loginIdentifer, string roleId)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2.Add("Result", false);
            obj2.Add("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;
            try
            {
                string str = "删除失败";
                if (SysUserModule.GetUserListByRole(long.Parse(roleId)).Count > 0)
                {
                    str = "无法删除有用户数量的角色";
                }
                else
                {
                    if (RoleModule.DeleteRole(long.Parse(roleId)))
                    {
                        str = "删除成功";
                        MenuModule.DeleteRoleMenuByRoleId(long.Parse(roleId));
                        obj2["Result"] = true;
                    }
                }
                obj2["Message"] = str;
            }
            catch (Exception exception)
            {
                obj2["Message"] = exception.Message;
            }

            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  = obj2["Message"].ToString() + "|" + roleId;
                SysLogModule.Add(log);
            }
            catch { }
            return(JavaScriptConvert.SerializeObject(obj2));
        }
Exemplo n.º 3
0
        public string DeleteUnitQuota(string loginIdentifer, string unitQuotaId)
        {
            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();
            try
            {
                string msg = CropModule.DeleteCropInfo(long.Parse(unitQuotaId));
                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 + "|" + unitQuotaId;
                    SysLogModule.Add(log);
                }
                catch { }
            }
            catch (Exception exception)
            {
                obj2["Message"] = exception.Message;
            }
            return(JavaScriptConvert.SerializeObject(obj2));
        }
Exemplo n.º 4
0
        public string DeleteUser(string loginIdentifer, string id)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2.Add("Result", false);
            obj2.Add("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;
            try
            {
                string str = SysUserModule.DeleteUser(long.Parse(id));
                if (str.Contains("删除成功"))
                {
                    obj2["Result"] = true;
                }
                obj2["Message"] = str;
            }
            catch (Exception exception)
            {
                obj2["Message"] = exception.Message;
            }

            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  = obj2["Message"].ToString() + "|" + id;
                SysLogModule.Add(log);
            }
            catch { }
            return(JavaScriptConvert.SerializeObject(obj2));
        }
        public string DeletePriceInfo(string loginIdentifer, string priceId)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2.Add("Result", false);
            obj2.Add("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();
            ResMsg msg = PriceModule.DeletePriceInfoById(priceId);

            obj2["Result"]  = msg.Result;
            obj2["Message"] = msg.Message;
            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 + "|" + priceId;
                SysLogModule.Add(log);
            }
            catch { }
            return(JavaScriptConvert.SerializeObject(obj2));
        }
Exemplo n.º 6
0
        public string LoginEx(string LoginName, string LoginPwd, string ValidateCode)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2.Add("Result", false);
            obj2.Add("Message", "");
            obj2.Add("Guid", "");

            /*
             * string cookieName = CommonUtil.GetCookieName(this.context.Request, "VCode");
             * if ((base.Session[cookieName] == null) || (base.Session[cookieName].ToString() == ""))
             * {
             *  obj2["Message"] = "请刷新验证码";
             *  return JavaScriptConvert.SerializeObject(obj2);
             * }
             * if (base.Session[cookieName].ToString() != ValidateCode)
             * {
             *  obj2["Message"] = "验证码不正确,请重新输入";
             *  return JavaScriptConvert.SerializeObject(obj2);
             * }
             * */
            /*
             * if (SysInfo.IsReg && !SysInfo.IsRegSuccess)
             * {
             *  obj2["Message"] = "系统未注册";
             *  return JavaScriptConvert.SerializeObject(obj2);
             * }
             */

            if (SysInfo.IsReg)
            {
                string path = context.Server.MapPath("~/");

                SysInfo.SetFilePath(path);

                SysInfo.IsRegSuccess = false;
                string regStr = "";
                if (FileHelper.IsExists(SysInfo.fileName))
                {
                    regStr = FileHelper.ReadFile(SysInfo.fileName);
                }
                else
                {
                    regStr = "00000000000000000000000000000000";
                    FileHelper.writeFile(SysInfo.fileName, regStr);
                }

                if (regStr != SysInfo.GetRegStr2())
                {
                    myLogger.Info("注册码不对!序列号为:" + SysInfo.GetRegStr1());
                    obj2["Message"] = "系统未注册";
                    return(JavaScriptConvert.SerializeObject(obj2));
                }
                else
                {
                    SysInfo.IsRegSuccess = true;
                }
            }

            try
            {
                long   userID = 0;
                string str3   = SysUserModule.Login(LoginName, LoginPwd, ToolsWeb.GetIP(context.Request), "", ref userID);
                if (str3 == "登陆成功")
                {
                    SysUserModule.OperatorLogin(userID, ToolsWeb.GetIP(context.Request), "");
                    LoginUser loginUser = new LoginUser
                    {
                        UserId         = userID,
                        LoginName      = LoginName,
                        LoginIdentifer = Guid.NewGuid().ToString()
                    };
                    GlobalAppModule.AddLoginUser(loginUser);

                    obj2["Result"] = true;
                    obj2["Guid"]   = loginUser.LoginIdentifer;
                }
                obj2["Message"] = str3;
            }
            catch (Exception exception)
            {
                obj2["Message"] = exception.Message;
            }

            try
            {
                SysLog log = new SysLog();
                log.LogUserId   = 0;
                log.LogUserName = LoginName;
                log.LogAddress  = ToolsWeb.GetIP(context.Request);
                log.LogTime     = DateTime.Now;
                log.LogType     = "登录";
                log.LogContent  = obj2["Message"].ToString();
                SysLogModule.Add(log);
            }
            catch { }
            return(JavaScriptConvert.SerializeObject(obj2));
        }
        public string SetRoleMenu(string loginIdentifer, string roleId, string menuIds)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2.Add("Result", false);
            obj2.Add("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;

            try
            {
                string str = "修改失败";

                try
                {
                    Role role = RoleModule.GetRole(long.Parse(roleId));

                    if (MenuModule.DeleteRoleMenuByRoleId(role.Id))
                    {
                        List <long> list = new List <long>();
                        string[]    strs = menuIds.Trim().Trim(',').Split(',');
                        foreach (string s in strs)
                        {
                            long id = long.Parse(s);
                            Menu m  = MenuModule.GetMenu(id);
                            if (m != null)
                            {
                                list.Add(id);

                                if (!list.Contains(m.ParentId))
                                {
                                    list.Add(m.ParentId);
                                }
                            }
                        }
                        if (strs.Length > 0)
                        {
                            if (MenuModule.AddRoleMenu(role.Id, list.ToArray()))
                            {
                                str            = "修改成功";
                                obj2["Result"] = true;
                            }
                        }
                    }
                    obj2["Message"] = str;
                }
                catch (Exception exception)
                {
                    obj2["Message"] = exception.Message;
                }

                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  = obj2["Message"].ToString() + "|" + roleId + "|" + menuIds;
                    SysLogModule.Add(log);
                }
                catch { }
            }
            catch (Exception exception2)
            {
                obj2["Message"] = exception2.Message;
            }
            return(JavaScriptConvert.SerializeObject(obj2));
        }
        public string DeleteMangeNode(string loginIdentifer, string managerId)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2.Add("Result", false);
            obj2.Add("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();
            District district = DistrictModule.ReturnDistrictInfo(long.Parse(managerId));

            if (district == null)
            {
                obj2["Message"] = "传入的区域ID不存在";
                return(JavaScriptConvert.SerializeObject(obj2));
            }
            if (district.ParentId == 0)
            {
                obj2["Message"] = "根节点不允许删除";
                return(JavaScriptConvert.SerializeObject(obj2));
            }
            //有设备的节点不能删除
            if (DeviceModule.GetDevicesForManageID(district.Id).Count > 0)
            {
                obj2["Message"] = "此区域下有设备,无法删除";
                return(JavaScriptConvert.SerializeObject(obj2));
            }
            string msg = DistrictModule.DeleteDistrictNode(long.Parse(managerId));

            //ResMsg msg = DevicesManager.DeleteManageNode(managerId);
            if (msg == "删除成功")//msg.Result
            {
                GlobalAppModule.IsInitMainLib = true;
                DistrictModule.UpdateDistrictInfo();
                GlobalAppModule.IsInitMainLib = false;

                Thread parameterThread = new Thread(new ParameterizedThreadStart(TcpRunThread.ParameterRun));
                parameterThread.Start(ProtocolConst.WebToGateUpdateCache + ProtocolConst.UpdateCache_District + "01" + "0".PadLeft(16, '0'));

                obj2["Result"]  = true;
                obj2["Message"] = "成功";
            }
            else
            {
                //obj2["Message"] = msg.Message;
                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 <District> .ToString(district);

                SysLogModule.Add(log);
            }
            catch { }
            return(JavaScriptConvert.SerializeObject(obj2));
        }
        public string AddWaterUser(string loginIdentifer, string waterUserJson)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2.Add("Result", false);
            obj2.Add("Message", "");
            try
            {
                ResMsg msg = CommonUtil.CheckLoginState(loginIdentifer, true);
                if (!msg.Result)
                {
                    obj2["Message"] = msg.Message;
                    return(JavaScriptConvert.SerializeObject(obj2));
                }
                LoginUser        loginUser = GlobalAppModule.GetLoginUser(loginIdentifer);
                string           message   = msg.Message;
                JavaScriptObject obj3      = (JavaScriptObject)JavaScriptConvert.DeserializeObject(waterUserJson);
                if (obj3 == null)
                {
                    obj2["Message"] = "参数waterUserJson格式不正确";
                    return(JavaScriptConvert.SerializeObject(obj2));
                }
                WaterUser wui = new WaterUser();
                wui.UserName       = obj3["名称"].ToString();
                wui.Password       = "";
                wui.TrueName       = "";
                wui.DistrictId     = long.Parse(obj3["管理ID"].ToString());
                wui.IdentityNumber = obj3["身份证号"].ToString();
                wui.Telephone      = obj3["电话"].ToString();
                wui.Address        = obj3["地址"].ToString();
                wui.State          = "正常";
                wui.WaterQuota     = decimal.Parse(obj3["用水定额"].ToString());
                wui.ElectricQuota  = decimal.Parse(obj3["用电定额"].ToString());
                wui.水价ID           = int.Parse(obj3["水价ID"].ToString());
                wui.电价ID           = int.Parse(obj3["电价ID"].ToString());

                if (WaterUserModule.ExistsUserName(wui.DistrictId, wui.UserName))
                {
                    obj2["Message"] = "存在相同户名";
                    return(JavaScriptConvert.SerializeObject(obj2));
                }
                if (WaterUserModule.ExistsIdentityNumber(wui.IdentityNumber))
                {
                    obj2["Message"] = "存在相同身份证号";
                    return(JavaScriptConvert.SerializeObject(obj2));
                }
                if (WaterUserModule.ExistsTelephone(wui.Telephone))
                {
                    obj2["Message"] = "存在相同身份证号";
                    return(JavaScriptConvert.SerializeObject(obj2));
                }

                msg = WaterUserModule.AddWaterUser(wui);
                if (msg.Result)
                {
                    obj2["Result"] = true;
                }
                else
                {
                    obj2["Message"] = msg.Message;
                }
                try
                {
                    //添加日志
                    WaterUserLog log = new WaterUserLog();
                    log.WaterUserId    = wui.id;
                    log.LogUserId      = loginUser.UserId;
                    log.LogUserName    = loginUser.LoginName;
                    log.LogAddress     = ToolsWeb.GetIP(context.Request);
                    log.LogTime        = loginUser.LastOperateTime;
                    log.LogType        = "添加";
                    log.LogContent     = msg.Message;
                    log.UserName       = wui.UserName;
                    log.Password       = wui.Password;
                    log.DistrictId     = wui.DistrictId;
                    log.TrueName       = wui.TrueName;
                    log.IdentityNumber = wui.IdentityNumber;
                    log.Telephone      = wui.Telephone;
                    log.Address        = wui.Address;
                    log.WaterQuota     = wui.WaterQuota;
                    log.ElectricQuota  = wui.ElectricQuota;
                    log.Remark         = wui.Remark;
                    log.水价ID           = wui.水价ID;
                    log.电价ID           = wui.电价ID;
                    log.State          = wui.State;
                    WaterUserLogModule.Add(log);
                }
                catch
                {
                }
            }
            catch (Exception exception)
            {
                obj2["Message"] = exception.Message;
            }
            return(JavaScriptConvert.SerializeObject(obj2));
        }
Exemplo n.º 10
0
        public string GetFileListDevice(string loginIdentifer, string LoginAddress, string RemoteStation)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2.Add("Result", false);
            obj2.Add("Message", "");

            JavaScriptArray objList = new JavaScriptArray();

            obj2.Add("List", objList);

            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;

            try
            {
                string        rootpath  = "UploadImg/" + RemoteStation + "/";
                string        path      = Server.MapPath("~/" + rootpath);
                DirectoryInfo TheFolder = new DirectoryInfo(path);
                if (TheFolder.Exists)
                {
                    foreach (FileInfo fi in TheFolder.GetFiles())
                    {
                        JavaScriptObject obj7 = new JavaScriptObject();
                        obj7.Add("fn", fi.Name);
                        obj7.Add("fp", rootpath + fi.Name);
                        obj7.Add("fd", fi.LastWriteTime.ToString("yyyyMMddHHmmssfff"));
                        obj7.Add("fz", fi.Length);
                        //obj7.Add("fm", Encode.GetMD5HashFromFile(fi.FullName));
                        obj7.Add("fm", "");
                        objList.Add(obj7);
                    }

                    obj2["Result"]  = true;
                    obj2["Message"] = "";
                }
                else
                {
                    obj2["Result"]  = true;
                    obj2["Message"] = "";
                }
            }
            catch (Exception exception)
            {
                obj2["Message"] = exception.Message;
            }

            try
            {
                SysLog log = new SysLog();
                log.LogUserId   = loginUser.UserId;
                log.LogUserName = loginUser.LoginName;
                log.LogAddress  = ToolsWeb.GetIP(context.Request) + " | " + LoginAddress;
                log.LogTime     = DateTime.Now;
                log.LogType     = "获取水文设备可下载文件列表";
                log.LogContent  = obj2["Message"].ToString();
                SysLogModule.Add(log);
            }
            catch { }
            return(JavaScriptConvert.SerializeObject(obj2));
        }
Exemplo n.º 11
0
        public string Login(string LoginName, string LoginPwd, string LoginAddress)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2.Add("Result", false);
            obj2.Add("Message", "");
            obj2.Add("Guid", "");

            if (SysInfo.IsReg)
            {
                string path = context.Server.MapPath("~/");

                SysInfo.SetFilePath(path);

                SysInfo.IsRegSuccess = false;
                string regStr = "";
                if (FileHelper.IsExists(SysInfo.fileName))
                {
                    regStr = FileHelper.ReadFile(SysInfo.fileName);
                }
                else
                {
                    regStr = "00000000000000000000000000000000";
                    FileHelper.writeFile(SysInfo.fileName, regStr);
                }

                if (regStr != SysInfo.GetRegStr2())
                {
                    myLogger.Info("注册码不对!序列号为:" + SysInfo.GetRegStr1());
                    obj2["Message"] = "系统未注册";
                    return(JavaScriptConvert.SerializeObject(obj2));
                }
                else
                {
                    SysInfo.IsRegSuccess = true;
                }
            }

            long userID = 0;

            try
            {
                string str3 = SysUserModule.Login(LoginName, LoginPwd, ToolsWeb.GetIP(context.Request), LoginAddress, ref userID);
                if (str3 == "登陆成功")
                {
                    SysUserModule.OperatorLogin(userID, ToolsWeb.GetIP(context.Request), "");
                    LoginUser loginUser = new LoginUser
                    {
                        UserId         = userID,
                        LoginName      = LoginName,
                        LoginIdentifer = Guid.NewGuid().ToString()
                    };
                    GlobalAppModule.AddLoginUser(loginUser);

                    obj2["Result"] = true;
                    obj2["Guid"]   = loginUser.LoginIdentifer;
                }
                obj2["Message"] = str3;
            }
            catch (Exception exception)
            {
                obj2["Message"] = exception.Message;
            }

            try
            {
                SysLog log = new SysLog();
                log.LogUserId   = userID;
                log.LogUserName = LoginName;
                log.LogAddress  = ToolsWeb.GetIP(context.Request) + " | " + LoginAddress;
                log.LogTime     = DateTime.Now;
                log.LogType     = "android登录";
                log.LogContent  = obj2["Message"].ToString();
                SysLogModule.Add(log);
            }
            catch { }
            return(JavaScriptConvert.SerializeObject(obj2));
        }
Exemplo n.º 12
0
        public string UploadFile(string loginIdentifer, string LoginAddress, string filename, string sum, string curr)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2.Add("Result", false);
            obj2.Add("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;

            try
            {
                string fileStr = context.Request["fileStr"];

                //myLogger.Info("sum:" + sum + ",curr:" + curr + ",filename:" + filename + ",length:" + HexStringUtility.HexStringToByteArray(fileStr).Length);
                string appName = loginUser.LoginName + "_fileStrs";

                string[] fileStrs;
                if (int.Parse(curr) == 1)
                {
                    try
                    {
                        SysLog log = new SysLog();
                        log.LogUserId   = loginUser.UserId;
                        log.LogUserName = loginUser.LoginName;
                        log.LogAddress  = ToolsWeb.GetIP(context.Request) + " | " + LoginAddress;
                        log.LogTime     = DateTime.Now;
                        log.LogType     = "android上传文件";
                        log.LogContent  = "sum:" + sum + ",curr:" + curr + ",filename:" + filename;
                        SysLogModule.Add(log);
                    }
                    catch { }

                    if (Application[appName] != null)
                    {
                        //myLogger.Info("上传文件移除已存在的记录fileStrs");
                        Application.Remove(appName);
                    }
                }

                if (Application[appName] != null)
                {
                    fileStrs = (string[])Application[appName];
                }
                else
                {
                    //myLogger.Info("初始化fileStrs,长度:" + int.Parse(sum));
                    fileStrs = new string[int.Parse(sum)];
                    Application.Add(appName, fileStrs);
                }

                fileStrs[int.Parse(curr) - 1] = fileStr;

                obj2["Result"] = true;
                if (sum == curr)
                {
                    obj2["Message"] = "1";//接收完成
                    SaveFile(fileStrs, loginUser.LoginName, filename);
                    if (Application[appName] != null)
                    {
                        //myLogger.Info("接收完成移除已存在的记录fileStrs");
                        Application.Remove(appName);
                    }
                }
                else
                {
                    obj2["Message"] = "0";//继续上传
                }
            }
            catch (Exception ex)
            {
                myLogger.Error(ex.Message);
                obj2["Message"] = "上传文件出错!";
            }

            return(JavaScriptConvert.SerializeObject(obj2));
        }
        public string Recharge(string loginIdentifer, string userid1, string userid2, string n)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2.Add("Result", false);
            obj2.Add("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();

            string msg = "交易失败!";
            long   nl  = 0;

            try
            {
                nl = long.Parse(n);
            }
            catch
            {
            }
            if (nl <= 0)
            {
                msg = "交易失败!水量非法!";
            }
            else
            {
                try
                {
                    WaterUser wu1 = WaterUserModule.GetWaterUserById(long.Parse(userid1));
                    if (wu1.WaterQuota - nl > 0)
                    {
                        WaterUser wu2 = WaterUserModule.GetWaterUserById(long.Parse(userid2));

                        wu2.WaterQuota = wu2.WaterQuota + nl;
                        ResMsg r2 = WaterUserModule.ModifyWaterUser(wu2);
                        if (r2.Result)
                        {
                            wu1.WaterQuota = wu1.WaterQuota - nl;
                            ResMsg r1 = WaterUserModule.ModifyWaterUser(wu1);
                            if (r1.Result)
                            {
                                obj2["Result"] = true;
                                msg            = "交易成功!";
                            }
                            else
                            {
                                wu2            = WaterUserModule.GetWaterUserById(long.Parse(userid2));
                                wu2.WaterQuota = wu2.WaterQuota - nl;
                                WaterUserModule.ModifyWaterUser(wu2);
                                msg = "交易失败!出卖方异常!";
                            }
                        }
                        else
                        {
                            msg = "交易失败!买受方异常!";
                        }
                    }
                    else
                    {
                        msg = "交易失败!水量不足!";
                    }
                }
                catch (Exception ex)
                {
                    msg = "交易失败!" + ex.Message;
                }
            }

            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 + "|" + userid1 + "|" + userid2 + "|" + nl;
                SysLogModule.Add(log);
            }
            catch { }

            return(JavaScriptConvert.SerializeObject(obj2));
        }
        public string AddRole(string loginIdentifer, string roleJSONString)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2.Add("Result", false);
            obj2.Add("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;

            try
            {
                JavaScriptObject obj3 = (JavaScriptObject)JavaScriptConvert.DeserializeObject(roleJSONString);
                if (obj3 == null)
                {
                    obj2["Message"] = "参数格式错误";
                    return(JavaScriptConvert.SerializeObject(obj2));
                }
                if (RoleModule.GetRoleId(obj3["角色名"].ToString()) > 0)
                {
                    obj2["Message"] = "此角色已经存在!";
                    return(JavaScriptConvert.SerializeObject(obj2));
                }
                try
                {
                    Role role = new Role();
                    role.RoleName = obj3["角色名"].ToString();
                    role.IsAllow  = 1;
                    role.Weight   = 1;

                    string str = "添加失败";
                    if (RoleModule.AddRole(role) > 0)
                    {
                        str            = "添加成功";
                        obj2["Result"] = true;
                    }
                    obj2["Message"] = str;
                }
                catch (Exception exception)
                {
                    obj2["Message"] = exception.Message;
                }
            }
            catch (Exception exception2)
            {
                obj2["Message"] = exception2.Message;
            }
            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  = obj2["Message"].ToString() + "|" + roleJSONString;
                SysLogModule.Add(log);
            }
            catch { }
            return(JavaScriptConvert.SerializeObject(obj2));
        }
Exemplo n.º 15
0
        public string AddUser(string loginIdentifer, string userJSONString)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2.Add("Result", false);
            obj2.Add("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;
            try
            {
                JavaScriptObject obj3 = (JavaScriptObject)JavaScriptConvert.DeserializeObject(userJSONString);
                if (obj3 == null)
                {
                    obj2["Message"] = "参数格式错误";
                    return(JavaScriptConvert.SerializeObject(obj2));
                }
                if (SysUserModule.GetUserId(obj3["用户名"].ToString()) > 0)
                {
                    obj2["Message"] = "此用户已经存在!";
                    return(JavaScriptConvert.SerializeObject(obj2));
                }
                try
                {
                    SysUser user = new SysUser();
                    user.UserName   = obj3["用户名"].ToString();
                    user.Password   = "******";
                    user.RegDate    = DateTime.Now;
                    user.LogonDate  = DateTime.Parse("2000-1-1");
                    user.IsAllow    = 1;
                    user.RoleId     = long.Parse(obj3["角色ID"].ToString());
                    user.DistrictId = long.Parse(obj3["管理ID"].ToString());
                    user.TrueName   = obj3["用户名"].ToString();
                    user.Sex        = "";
                    user.Mobile     = "";
                    user.Address    = "";
                    user.Remark     = "";

                    string str = SysUserModule.AddUser(user);
                    if (str.Contains("添加成功"))
                    {
                        obj2["Result"] = true;
                    }
                    obj2["Message"] = str;

                    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  = str + "|" + ModelHandler <SysUser> .ToString(user);

                        SysLogModule.Add(log);
                    }
                    catch { }
                }
                catch (Exception exception)
                {
                    obj2["Message"] = exception.Message;
                }
            }
            catch (Exception exception2)
            {
                obj2["Message"] = exception2.Message;
            }
            return(JavaScriptConvert.SerializeObject(obj2));
        }
Exemplo n.º 16
0
        public string ModifyPassWord(string loginIdentifer, string id, string oldPwd, string newPwd)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2.Add("Result", false);
            obj2.Add("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;
            try
            {
                string message = "";

                if ((id == null) || (id.Trim() == ""))
                {
                    if (SysUserModule.GetUser(long.Parse(message)) == null)
                    {
                        obj2["Message"] = "要修改密码的用户不存在";
                        return(JavaScriptConvert.SerializeObject(obj2));
                    }
                    id = message;
                }
                try
                {
                    string str2 = SysUserModule.ModifyPassWord(long.Parse(id), oldPwd, newPwd);
                    if (str2.Contains("修改成功"))
                    {
                        obj2["Result"] = true;
                    }
                    obj2["Message"] = str2;
                }
                catch (Exception exception)
                {
                    obj2["Message"] = exception.Message;
                }
            }
            catch (Exception exception2)
            {
                obj2["Message"] = exception2.Message;
            }
            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  = obj2["Message"].ToString() + "|" + id + "【" + oldPwd + "】【" + newPwd + "】";
                SysLogModule.Add(log);
            }
            catch { }
            return(JavaScriptConvert.SerializeObject(obj2));
        }
        public string ModifyPriceInfo(string loginIdentifer, string priceJson)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2.Add("Result", false);
            obj2.Add("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 jso = (JavaScriptObject)JavaScriptConvert.DeserializeObject(priceJson);

            if (jso == null)
            {
                obj2["Message"] = "参数priceJson格式不正确";
                return(JavaScriptConvert.SerializeObject(obj2));
            }
            if ((!jso.ContainsKey("ID") || (jso["ID"] == null)) || (jso["ID"].ToString().Trim() == ""))
            {
                obj2["Message"] = "价格ID不能为空";
                return(JavaScriptConvert.SerializeObject(obj2));
            }
            PriceInfo pi = null;

            try
            {
                pi = this.JsonToPriceInfo(jso);
            }
            catch (Exception exception)
            {
                obj2["Message"] = exception.Message;
                return(JavaScriptConvert.SerializeObject(obj2));
            }
            ResMsg msg = PriceModule.ModifyPriceInfo(pi);

            string[]    strArray  = new string[] { "一阶名称", "二阶名称", "三阶名称", "四阶名称" };
            string[]    strArray2 = new string[4];
            string[]    strArray3 = new string[4];
            XmlDocument document  = new XmlDocument();
            string      filename  = AppDomain.CurrentDomain.BaseDirectory.ToString() + @"App_Config\Price.config";

            document.Load(filename);
            XmlNode node  = document.GetElementsByTagName("水价").Item(0);
            XmlNode node2 = document.GetElementsByTagName("电价").Item(0);
            int     num   = int.Parse(document.SelectSingleNode("价格设置/水价/阶梯数量").InnerText);
            int     num2  = int.Parse(document.SelectSingleNode("价格设置/电价/阶梯数量").InnerText);

            for (int i = 0; (i < num) && (i < strArray.Length); i++)
            {
                XmlNode node5 = node.SelectSingleNode(strArray[i]);
                strArray2[i] = node5.InnerText;
            }
            for (int j = 0; (j < num2) && (j < strArray.Length); j++)
            {
                XmlNode node6 = node2.SelectSingleNode(strArray[j]);
                strArray3[j] = node6.InnerText;
            }
            obj2["Result"]  = msg.Result;
            obj2["Message"] = msg.Message;
            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 <PriceInfo> .ToString(pi);

                SysLogModule.Add(log);
            }
            catch { }
            return(JavaScriptConvert.SerializeObject(obj2));
        }
        public string WriteOffWaterUserByUserSerialNumber(string loginIdentifer, string userSerialNumber)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2.Add("Result", false);
            obj2.Add("Message", "");
            try
            {
                ResMsg msg = CommonUtil.CheckLoginState(loginIdentifer, true);
                if (!msg.Result)
                {
                    obj2["Message"] = msg.Message;
                    return(JavaScriptConvert.SerializeObject(obj2));
                }
                LoginUser loginUser = GlobalAppModule.GetLoginUser(loginIdentifer);
                if ((userSerialNumber == null) || (userSerialNumber.Trim() == ""))
                {
                    obj2["Message"] = "用户卡号不能为空";
                    return(JavaScriptConvert.SerializeObject(obj2));
                }

                CardUser cu = CardUserModule.GetCardUserBySerialNumber(userSerialNumber);
                if (cu == null)
                {
                    obj2["Message"] = "卡号为" + userSerialNumber + "的用户卡不存在";
                    return(JavaScriptConvert.SerializeObject(obj2));
                }
                WaterUser wui = WaterUserModule.GetWaterUserById(cu.WaterUserId);
                if (wui == null)
                {
                    obj2["Message"] = "卡号为" + userSerialNumber + "的用水户不存在";
                    return(JavaScriptConvert.SerializeObject(obj2));
                }
                ResMsg msg1 = WaterUserModule.WriteOffWaterUserById(cu.WaterUserId);
                if (msg1.Result)//msg.Result
                {
                    obj2["Result"] = true;
                }
                else
                {
                    obj2["Message"] = msg.Message;
                }
                try
                {
                    //添加日志
                    WaterUserLog log = new WaterUserLog();
                    log.WaterUserId    = wui.id;
                    log.LogUserId      = loginUser.UserId;
                    log.LogUserName    = loginUser.LoginName;
                    log.LogAddress     = ToolsWeb.GetIP(context.Request);
                    log.LogTime        = loginUser.LastOperateTime;
                    log.LogType        = "注销";
                    log.LogContent     = msg.Message;
                    log.UserName       = wui.UserName;
                    log.Password       = wui.Password;
                    log.DistrictId     = wui.DistrictId;
                    log.TrueName       = wui.TrueName;
                    log.IdentityNumber = wui.IdentityNumber;
                    log.Telephone      = wui.Telephone;
                    log.Address        = wui.Address;
                    log.WaterQuota     = wui.WaterQuota;
                    log.ElectricQuota  = wui.ElectricQuota;
                    log.Remark         = wui.Remark;
                    log.水价ID           = wui.水价ID;
                    log.电价ID           = wui.电价ID;
                    log.State          = wui.State;
                    WaterUserLogModule.Add(log);
                }
                catch
                {
                }
            }
            catch (Exception exception)
            {
                obj2["Message"] = exception.Message;
            }
            return(JavaScriptConvert.SerializeObject(obj2));
        }
        public string AddDevice(string loginIdentifer, string deviceJSONString)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2.Add("Result", false);
            obj2.Add("Message", "");
            LoginUser loginUser = GlobalAppModule.GetLoginUser(loginIdentifer);

            if (loginUser == null)
            {
                obj2["Message"] = "未登录";
                return(JavaScriptConvert.SerializeObject(obj2));
            }
            if (loginUser.LoginTimeout)
            {
                obj2["Message"] = "登录超时";
                return(JavaScriptConvert.SerializeObject(obj2));
            }
            JavaScriptObject obj3 = (JavaScriptObject)JavaScriptConvert.DeserializeObject(deviceJSONString);

            if (obj3 == null)
            {
                obj2["Message"] = "参数deviceJSONString格式不正确";
                return(JavaScriptConvert.SerializeObject(obj2));
            }
            loginUser.LastOperateTime = DateTime.Now;
            CommonUtil.WaitMainLibInit();

            Device device = new Device();

            device.SimNo       = obj3["手机卡号"].ToString();
            device.DeviceName  = obj3["名称"].ToString();
            device.Description = "";
            try
            {
                device.SetupDate = DateTime.Parse(obj3["安装时间"].ToString() + ":00");
            }
            catch
            {
                obj2["Message"] = "安装时间格式错误";
                return(JavaScriptConvert.SerializeObject(obj2));
            }
            device.SetupAddress = obj3["安装位置"].ToString();
            try
            {
                string[] arrMap = obj3["经纬度"].ToString().Trim().Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                device.LON = (long)(double.Parse(arrMap[0]) * 1000000);
                device.LAT = (long)(double.Parse(arrMap[1]) * 1000000);
            }
            catch { device.LON = 0; device.LAT = 0; }
            device.IsValid    = 1;
            device.LastUpdate = DateTime.Parse("2000-1-1");
            try
            {
                device.DistrictId = long.Parse(obj3["管理ID"].ToString());
            }
            catch
            {
                obj2["Message"] = "请选择区域";
                return(JavaScriptConvert.SerializeObject(obj2));
            }
            device.DeviceNo = obj3["编码"].ToString();
            try
            {
                if (device.DeviceNo.Length > 3)
                {
                    obj2["Message"] = "设备序号必须为整数,范围1-255";
                    return(JavaScriptConvert.SerializeObject(obj2));
                }
                int i = Convert.ToInt16(device.DeviceNo);
                if (i < 1 || i > 255)
                {
                    obj2["Message"] = "设备序号必须为整数,范围1-255";
                    return(JavaScriptConvert.SerializeObject(obj2));
                }
            }
            catch
            {
                obj2["Message"] = "设备序号必须为整数,范围1-255";
                return(JavaScriptConvert.SerializeObject(obj2));
            }

            device.Online     = 0;
            device.OnlineTime = DateTime.Parse("2000-1-1");
            try
            {
                device.YearExploitation = decimal.Parse(obj3["年可开采水量"].ToString());
            }
            catch { device.YearExploitation = 0; }
            try
            {
                device.AlertAvailableWater = int.Parse(obj3["可用水量提醒"].ToString());
            }
            catch { device.AlertAvailableWater = 0; }
            try
            {
                device.AlertAvailableElectric = int.Parse(obj3["可用电量提醒"].ToString());
            }
            catch { device.AlertAvailableElectric = 0; }
            try
            {
                device.DeviceTypeCodeId = int.Parse(obj3["流量计类型"].ToString());
            }
            catch { device.DeviceTypeCodeId = 0; }
            try
            {
                device.MeterPulse = int.Parse(obj3["电表脉冲数"].ToString());
            }
            catch { device.MeterPulse = 0; }
            try
            {
                device.AlertWaterLevel = decimal.Parse(obj3["水位报警值"].ToString());
            }
            catch { device.AlertWaterLevel = 0; }
            device.TerminalState = "正常";
            device.Remark        = "";
            try
            {
                //device.CropId = long.Parse(obj3["作物"].ToString());
                device.CropId = 0;
            }
            catch
            {
                device.CropId = 0;
                //obj2["Message"] = "请选择作物";
                //return JavaScriptConvert.SerializeObject(obj2);
            }
            try
            {
                device.Area = decimal.Parse(obj3["面积"].ToString());
            }
            catch
            {
                device.Area = 0;
            }
            try
            {
                device.StationType = int.Parse(obj3["站类型"].ToString());
            }
            catch
            {
                device.StationType = 0;
            }
            try
            {
                device.StationCode = int.Parse(obj3["地址码"].ToString());
                //device.StationCode = 0;
            }
            catch
            {
                device.StationCode = 0;
            }
            if (device.StationCode < 0 || device.StationCode > 65535)
            {
                //obj2["Message"] = "地址码必须为整数,范围0-65535";
                //return JavaScriptConvert.SerializeObject(obj2);
            }
            try
            {
                //device.Frequency = int.Parse(obj3["通信频率"].ToString());
                device.Frequency = 0;
            }
            catch
            {
                device.Frequency = 0;
            }
            try
            {
                string MainDevNo = obj3["主站编码"].ToString().PadLeft(3, '0');
                Device MainD     = DeviceModule.GetDeviceByDistrictId(device.DistrictId, MainDevNo);
                if (MainD != null)
                {
                    device.MainId = MainD.Id;
                }
            }
            catch
            {
                device.MainId = 0;
            }
            device.DeviceType    = obj3["设备类型"].ToString();
            device.RemoteStation = obj3["水位仪编码"].ToString().Trim();

            if (DeviceModule.ExistsSimNo(device.SimNo))
            {
                obj2["Message"] = "已存在手机号码";
                return(JavaScriptConvert.SerializeObject(obj2));
            }
            if (DeviceModule.ExistsDeviceName(device.DeviceName, device.DistrictId))
            {
                obj2["Message"] = "已存在设备名称";
                return(JavaScriptConvert.SerializeObject(obj2));
            }
            if (DeviceModule.ExistsDeviceNo(device.DeviceNo, device.DistrictId))
            {
                obj2["Message"] = "已存在设备编码";
                return(JavaScriptConvert.SerializeObject(obj2));
            }
            /*********update by kqz 2017-3-6***************/

            /*if (device.RemoteStation != null && device.RemoteStation.Length > 0)
             * {
             *  if (DeviceModule.ExistsRemoteStation(device.RemoteStation, device.Id))
             *  {
             *      obj2["Message"] = "已存在水位仪编码";
             *      return JavaScriptConvert.SerializeObject(obj2);
             *  }
             * }*/
            /*********update by kqz 2017-3-6***************/
            ResMsg msg = DeviceModule.AddDevice(device);

            if (msg.Result)
            {
                GlobalAppModule.IsInitMainLib = true;
                try
                {
                    //更新网关设备缓存
                    Thread parameterThread = new Thread(new ParameterizedThreadStart(TcpRunThread.ParameterRun));
                    parameterThread.Start(ProtocolConst.WebToGateUpdateCache + ProtocolConst.UpdateCache_Device + "01" + DeviceModule.GetFullDeviceNoByID(device.Id).PadLeft(16, '0'));
                }
                catch (Exception exception)
                {
                    //new Guard().Logger(exception, "GetOperateDevice");
                    myLogger.Error(exception.Message);
                }
                GlobalAppModule.IsInitMainLib = false;
                obj2["Result"]  = true;
                obj2["Message"] = "成功";
            }
            else
            {
                obj2["Message"] = msg.Message;
            }
            try
            {
                //添加日志
                DeviceLog log = new DeviceLog();
                log.DeviceId               = device.Id;
                log.LogUserId              = loginUser.UserId;
                log.LogUserName            = loginUser.LoginName;
                log.LogAddress             = ToolsWeb.GetIP(context.Request);
                log.LogTime                = loginUser.LastOperateTime;
                log.LogType                = "添加";
                log.LogContent             = msg.Message + " | " + JavaScriptConvert.SerializeObject(device);
                log.SimNo                  = device.SimNo;
                log.DeviceName             = device.DeviceName;
                log.Description            = device.Description;
                log.SetupDate              = device.SetupDate;
                log.SetupAddress           = device.SetupAddress;
                log.LON                    = device.LON;
                log.LAT                    = device.LAT;
                log.IsValid                = device.IsValid;
                log.LastUpdate             = device.LastUpdate;
                log.DistrictId             = device.DistrictId;
                log.DeviceNo               = device.DeviceNo;
                log.Online                 = device.Online;
                log.OnlineTime             = device.OnlineTime;
                log.YearExploitation       = device.YearExploitation;
                log.AlertAvailableWater    = device.AlertAvailableWater;
                log.AlertAvailableElectric = device.AlertAvailableElectric;
                log.DeviceTypeCodeId       = device.DeviceTypeCodeId;
                log.MeterPulse             = device.MeterPulse;
                log.AlertWaterLevel        = device.AlertWaterLevel;
                log.TerminalState          = device.TerminalState;
                log.Remark                 = device.Remark;
                log.CropId                 = device.CropId;
                log.Area                   = device.Area;
                log.StationType            = device.StationType;
                log.StationCode            = device.StationCode;
                log.Frequency              = device.Frequency;
                log.MainId                 = device.MainId;
                log.DeviceType             = device.DeviceType;
                DeviceLogModule.Add(log);
            }
            catch
            {
            }
            return(JavaScriptConvert.SerializeObject(obj2));
        }
Exemplo n.º 20
0
        public string AddUnitQuota(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 = new Crop();
                crop.CropName   = obj3["名称"].ToString();
                crop.WaterPerMu = decimal.Parse(obj3["单位定额"].ToString());
                crop.Remark     = "";

                if (CropModule.ExistsCropName(crop.CropName))
                {
                    obj2["Result"]  = false;
                    obj2["Message"] = "作物名称重复!";
                    return(JavaScriptConvert.SerializeObject(obj2));
                }

                string msg = CropModule.AddCropInfo(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));
        }
        public string DeleteDevice(string loginIdentifer, string devID)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2.Add("Result", false);
            obj2.Add("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();

            Device device = DeviceModule.GetDeviceByID(long.Parse(devID));

            if (device == null)
            {
                obj2["Result"]  = true;
                obj2["Message"] = "noDevice";
                return(JavaScriptConvert.SerializeObject(obj2));
            }

            string FullDeviceNo = DeviceModule.GetFullDeviceNoByID(device.Id);

            ResMsg msg = DeviceModule.DeleteDevice(long.Parse(devID));

            if (msg.Result)
            {
                GlobalAppModule.IsInitMainLib = true;
                try
                {
                    //更新网关设备缓存
                    Thread parameterThread = new Thread(new ParameterizedThreadStart(TcpRunThread.ParameterRun));
                    parameterThread.Start(ProtocolConst.WebToGateUpdateCache + ProtocolConst.UpdateCache_Device + "02" + FullDeviceNo.PadLeft(16, '0'));
                }
                catch (Exception exception)
                {
                    //new Guard().Logger(exception, "GetOperateDevice");
                    myLogger.Error(exception.Message);
                }
                GlobalAppModule.IsInitMainLib = false;
                obj2["Result"]  = true;
                obj2["Message"] = "成功";
            }
            else
            {
                obj2["Message"] = msg.Message;
            }
            try
            {
                //添加日志
                DeviceLog log = new DeviceLog();
                log.DeviceId               = device.Id;
                log.LogUserId              = loginUser.UserId;
                log.LogUserName            = loginUser.LoginName;
                log.LogAddress             = ToolsWeb.GetIP(context.Request);
                log.LogTime                = loginUser.LastOperateTime;
                log.LogType                = "删除";
                log.LogContent             = msg.Message + " | " + JavaScriptConvert.SerializeObject(device);
                log.SimNo                  = device.SimNo;
                log.DeviceName             = device.DeviceName;
                log.Description            = device.Description;
                log.SetupDate              = device.SetupDate;
                log.SetupAddress           = device.SetupAddress;
                log.LON                    = device.LON;
                log.LAT                    = device.LAT;
                log.IsValid                = device.IsValid;
                log.LastUpdate             = device.LastUpdate;
                log.DistrictId             = device.DistrictId;
                log.DeviceNo               = device.DeviceNo;
                log.Online                 = device.Online;
                log.OnlineTime             = device.OnlineTime;
                log.YearExploitation       = device.YearExploitation;
                log.AlertAvailableWater    = device.AlertAvailableWater;
                log.AlertAvailableElectric = device.AlertAvailableElectric;
                log.DeviceTypeCodeId       = device.DeviceTypeCodeId;
                log.MeterPulse             = device.MeterPulse;
                log.AlertWaterLevel        = device.AlertWaterLevel;
                log.TerminalState          = device.TerminalState;
                log.Remark                 = device.Remark;
                log.CropId                 = device.CropId;
                log.Area                   = device.Area;
                log.StationType            = device.StationType;
                log.StationCode            = device.StationCode;
                log.Frequency              = device.Frequency;
                log.MainId                 = device.MainId;
                log.DeviceType             = device.DeviceType;
                DeviceLogModule.Add(log);
            }
            catch
            {
            }
            return(JavaScriptConvert.SerializeObject(obj2));
        }
        public string AddMangeNode(string loginIdentifer, string manageJSONString)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2.Add("Result", false);
            obj2.Add("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(manageJSONString);

            if (obj3 == null)
            {
                obj2["Message"] = "参数格式错误";
                return(JavaScriptConvert.SerializeObject(obj2));
            }

            District district = new District();

            district.LON          = 0;
            district.LAT          = 0;
            district.ParentId     = long.Parse(obj3["上级ID"].ToString());
            district.DistrictName = obj3["名称"].ToString();
            district.DistrictType = int.Parse(obj3["级别ID"].ToString());
            district.DistrictCode = obj3["编码"].ToString();

            if (DistrictModule.ExistsDistrictName(district.ParentId, district.DistrictName))
            {
                obj2["Result"]  = false;
                obj2["Message"] = "同一级别名称重复!";
                return(JavaScriptConvert.SerializeObject(obj2));
            }

            if (DistrictModule.ExistsDistrictCode(district.ParentId, district.DistrictCode))
            {
                obj2["Result"]  = false;
                obj2["Message"] = "同一级别编码重复!";
                return(JavaScriptConvert.SerializeObject(obj2));
            }

            string msg = DistrictModule.AddDistrictInfo(district);

            //ResMsg msg = DevicesManager.AddManageNode(node);
            if (msg == "添加成功")//msg.Result
            {
                GlobalAppModule.IsInitMainLib = true;
                DistrictModule.UpdateDistrictInfo();
                GlobalAppModule.IsInitMainLib = false;

                Thread parameterThread = new Thread(new ParameterizedThreadStart(TcpRunThread.ParameterRun));
                parameterThread.Start(ProtocolConst.WebToGateUpdateCache + ProtocolConst.UpdateCache_District + "01" + "0".PadLeft(16, '0'));

                obj2["Result"]  = true;
                obj2["Message"] = "成功";
            }
            else
            {
                //obj2["Message"] = msg.Message;
                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 <District> .ToString(district);

                SysLogModule.Add(log);
            }
            catch { }

            return(JavaScriptConvert.SerializeObject(obj2));
        }
Exemplo n.º 23
0
        public string ModifyUser(string loginIdentifer, string userJSONString)
        {
            JavaScriptObject obj2 = new JavaScriptObject();

            obj2.Add("Result", false);
            obj2.Add("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;
            try
            {
                JavaScriptObject obj3 = (JavaScriptObject)JavaScriptConvert.DeserializeObject(userJSONString);
                if (obj3 == null)
                {
                    obj2["Message"] = "参数格式错误";
                    return(JavaScriptConvert.SerializeObject(obj2));
                }

                try
                {
                    SysUser user = SysUserModule.GetUser(long.Parse(obj3["ID"].ToString()));
                    user.UserName   = obj3["用户名"].ToString();
                    user.RoleId     = long.Parse(obj3["角色ID"].ToString());
                    user.DistrictId = long.Parse(obj3["管理ID"].ToString());
                    user.TrueName   = obj3["用户名"].ToString();

                    long existsId = SysUserModule.GetUserId(user.UserName);
                    if (existsId > 0 && existsId != user.ID)
                    {
                        obj2["Message"] = "此用户已经存在!";
                        return(JavaScriptConvert.SerializeObject(obj2));
                    }

                    string str = SysUserModule.ModifyUser(user);
                    if (str.Contains("修改成功"))
                    {
                        obj2["Result"] = true;
                    }
                    obj2["Message"] = str;
                }
                catch (Exception exception)
                {
                    obj2["Message"] = exception.Message;
                }
            }
            catch (Exception exception2)
            {
                obj2["Message"] = exception2.Message;
            }

            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  = obj2["Message"].ToString() + "|" + userJSONString;
                SysLogModule.Add(log);
            }
            catch { }
            return(JavaScriptConvert.SerializeObject(obj2));
        }