Example #1
0
        private void SetInfo(Foresight.DataAccess.Company data)
        {
            string erromsg = string.Empty;

            Foresight.DataAccess.Company defaultCompany = WebUtil.GetCompany(this.Context);
            if (defaultCompany != null)
            {
                this.tdRealName.Value     = data.CompanyName;
                this.tdPhoneNumber.Value  = data.PhoneNumber;
                this.tdAddress.Value      = data.Address;
                this.tdDesc.Value         = data.CompanyDesc;
                this.tdChargeMan.Value    = data.ChargePerson;
                this.tdIsActive.Value     = defaultCompany.IsPay ? "1" : "0";
                this.tdDistributor.Value  = defaultCompany.Distributor;
                this.tdUserCount.Value    = defaultCompany.UserCount == int.MinValue ? "0" : defaultCompany.UserCount.ToString();
                this.tdStartTime.Value    = defaultCompany.ServerStartTime == DateTime.MinValue ? "" : defaultCompany.ServerStartTime.ToString("yyyy-MM-dd HH:mm:ss");
                this.tdEndTime.Value      = defaultCompany.ServerEndTime == DateTime.MinValue ? "" : defaultCompany.ServerEndTime.ToString("yyyy-MM-dd HH:mm:ss");
                this.tdProjectCount.Value = defaultCompany.ProjectCount == int.MaxValue ? "" : defaultCompany.ProjectCount.ToString();
            }
            else
            {
                this.tdRealName.Value    = data.CompanyName;
                this.tdPhoneNumber.Value = data.PhoneNumber;
                this.tdAddress.Value     = data.Address;
                this.tdDesc.Value        = data.CompanyDesc;
                this.tdChargeMan.Value   = data.ChargePerson;
            }
        }
Example #2
0
        private void getcompanyinfo(HttpContext context)
        {
            Foresight.DataAccess.Company company = null;
            if (!checkvalidcompany(context, out company))
            {
                var items = new { status = false, errormsg = "公司未登记" };
                WebUtil.WriteJson(context, items);
                return;
            }
            if (!string.IsNullOrEmpty(company.Login_LogImg))
            {
                company.Login_LogImg = WebUtil.GetContextPath() + company.Login_LogImg;
            }
            if (!string.IsNullOrEmpty(company.Login_BodyImg))
            {
                company.Login_BodyImg = WebUtil.GetContextPath() + company.Login_BodyImg;
            }
            if (!string.IsNullOrEmpty(company.Home_LogoImg))
            {
                company.Home_LogoImg = WebUtil.GetContextPath() + company.Home_LogoImg;
            }
            bool     ExpiringShow  = company.ExpiringShow;
            DateTime ServerEndTime = company.ServerEndTime;
            int      ExpiringDay   = company.ExpiringDay > 0 ? company.ExpiringDay : 0;

            if (ExpiringShow && ServerEndTime > DateTime.MinValue)
            {
                if (ServerEndTime > DateTime.Now.AddDays(ExpiringDay))
                {
                    ExpiringShow = false;
                }
            }
            string ExpiringMsg = company.ExpiringMsg;

            if (string.IsNullOrEmpty(ExpiringMsg))
            {
                ExpiringMsg = "产品售后服务将于{到期日期}到期,到期后不影响产品正常使用。继续享受售后服务与技术支持,请您联系相关人员购买服务有效期";
            }
            ExpiringMsg = ExpiringMsg.Replace("{到期日期}", company.ServerEndTime.ToString("yyyy年MM月dd日"));
            var data_company = new { CompanyID = company.CompanyID, CompanyName = company.CompanyName, PhoneNumber = company.PhoneNumber, IsActive = company.IsActive, BaseURL = company.BaseURL, UserCount = company.UserCount, ServerStartTime = company.ServerStartTime, ServerEndTime = ServerEndTime, IsPay = company.IsPay, IsAdmin = company.IsAdmin, IsCustomer = company.IsCustomer, LocalURL = company.LocalURL, Login_LogImg = company.Login_LogImg, Login_BodyImg = company.Login_BodyImg, Home_LogoImg = company.Home_LogoImg, VersionCode = company.VersionCode, ProjectCount = company.ProjectCount >= 0 ? company.ProjectCount : int.MaxValue, IsHideLogin_LogImg = company.IsHideLogin_LogImg, IsHideLogin_BodyImg = company.IsHideLogin_BodyImg, IsHideHome_LogoImg = company.IsHideHome_LogoImg, CopyRightText = company.CopyRightText, IsHideCopyRightText = company.IsHideCopyRightText, ExpiringMsg = ExpiringMsg, ExpiringDay = ExpiringDay, ExpiringShow = ExpiringShow, SystemNo = company.SystemNumber };

            if (company.IsAdmin)
            {
                var items = new { status = true, errormsg = "OK", company = data_company };
                WebUtil.WriteJson(context, items);
                return;
            }
            if (!company.IsPay)
            {
                var items = new { status = false, errormsg = "公司已欠费", company = data_company };
                WebUtil.WriteJson(context, items);
                return;
            }
            var item = new { status = true, errormsg = "OK", company = data_company };

            WebUtil.WriteJson(context, item);
            return;
        }
Example #3
0
        private void getsysmenulist(HttpContext context)
        {
            Foresight.DataAccess.Company company = null;
            if (!checkvalidcompany(context, out company))
            {
                var items = new { status = false, errormsg = "公司未登记" };
                WebUtil.WriteJson(context, items);
                return;
            }
            var list = SysMenu.GetSysModulesByCompany(company.CompanyID);
            var item = new { status = true, errormsg = "OK", list = list };

            WebUtil.WriteJson(context, item);
        }
Example #4
0
        private void saveappuser(HttpContext context)
        {
            Foresight.DataAccess.Company company = null;
            if (!checkvalidcompany(context, out company))
            {
                var items = new { status = false, errormsg = "公司未登记" };
                WebUtil.WriteJson(context, items);
                return;
            }
            string LoginName = context.Request["LoginName"];
            string Password  = context.Request["Password"];
            string UserType  = context.Request["UserType"];

            UserType = string.IsNullOrEmpty(UserType) ? UserTypeDefine.APPUser.ToString() : UserType;
            int FromUserID = WebUtil.GetIntValue(context, "FromUserID");
            var user       = Foresight.DataAccess.User.GetAPPUser(FromUserID, company.CompanyID);
            var exist_user = Foresight.DataAccess.User.GetUserByLoginName(LoginName, Foresight.DataAccess.UserTypeDefine.APPUser.ToString());

            if (exist_user != null)
            {
                if (user == null)
                {
                    WebUtil.WriteJson(context, new { status = false, errormsg = "用户名已存在" });
                    return;
                }
                if (user != null && exist_user.UserID != user.UserID)
                {
                    WebUtil.WriteJson(context, new { status = false, errormsg = "用户名已存在" });
                    return;
                }
            }
            if (user == null)
            {
                user = new Foresight.DataAccess.User();
                user.FromCompanyID = company.CompanyID;
                user.FromUserID    = FromUserID;
                user.CreateTime    = DateTime.Now;
                user.Type          = UserType;
            }
            user.LoginName = LoginName;
            user.Password  = Password;
            user.Save();
            var item = new { status = true, errormsg = "OK" };

            WebUtil.WriteJson(context, item);
        }
Example #5
0
        private bool checkvalidcompany(HttpContext context, out Foresight.DataAccess.Company company)
        {
            string baseurl   = EncryptHelper.GetURL(context);
            string signature = context.Request["signature"];
            string token     = context.Request["token"];

            company = null;
            if (string.IsNullOrEmpty(baseurl) && string.IsNullOrEmpty(signature) && string.IsNullOrEmpty(token))
            {
                return(false);
            }
            company = Foresight.DataAccess.Company.GetCompanyByURL(baseurl, signature: signature, token: token);
            if (company == null)
            {
                return(false);
            }
            return(true);
        }
Example #6
0
        private void savecompanyinfo(HttpContext context)
        {
            Foresight.DataAccess.Company company = null;
            if (!checkvalidcompany(context, out company))
            {
                var items = new { status = false, errormsg = "公司未登记" };
                WebUtil.WriteJson(context, items);
                return;
            }
            company.CompanyName  = context.Request.Params["CompanyName"];
            company.PhoneNumber  = context.Request.Params["PhoneNumber"];
            company.Address      = context.Request.Params["Address"];
            company.CompanyDesc  = context.Request.Params["CompanyDesc"];
            company.ChargePerson = context.Request.Params["ChargePerson"];
            company.Save();
            var item = new { status = true, errormsg = "OK" };

            WebUtil.WriteJson(context, item);
        }
Example #7
0
        private void getusercount(HttpContext context)
        {
            Foresight.DataAccess.Company company = null;
            if (!checkvalidcompany(context, out company))
            {
                var items = new { status = false, errormsg = "公司未登记" };
                WebUtil.WriteJson(context, items);
                return;
            }
            string total = company.UserCount <= 0 ? "0" : company.UserCount.ToString();

            if (company.IsAdmin)
            {
                total = int.MaxValue.ToString();
            }
            var item = new { status = true, errormsg = total };

            WebUtil.WriteJson(context, item);
            return;
        }
Example #8
0
        public static bool RemoveAPPUser(Foresight.DataAccess.Company company, List <int> UserIDList, out string errormsg)
        {
            errormsg = string.Empty;
            if (IsLocalSystem())
            {
                errormsg = "局域网单机系统无法删除APP用户";
                return(false);
            }
            if (IsInternalSys(out errormsg, false))
            {
                errormsg = "内部系统,无须审核";
                return(true);
            }
            ResponseData response = null;
            int          i        = 0;

            do
            {
                try
                {
                    i++;
                    string key    = EncriptName(company.BaseURL);
                    string result = Foresight.Web.HttpRequest.Post(null, new Dictionary <string, string>()
                    {
                        { "visit", "removeappuser" }, { "key", key }, { "signature", SysConfig.GetSignature() }, { "token", SysConfig.GetToken() }, { "UserIDList", JsonConvert.SerializeObject(UserIDList) }
                    });
                    response = JsonConvert.DeserializeObject <ResponseData>(result);
                }
                catch (Exception ex)
                {
                    Utility.LogHelper.WriteError("EncryptHelper", "RemoveAPPUser", ex);
                }
            } while (response == null && i <= 3);
            if (response != null)
            {
                errormsg = response.errormsg;
                return(response.status);
            }
            errormsg = "操作超时,请稍候重试";
            return(false);
        }
Example #9
0
        private void removeappuser(HttpContext context)
        {
            Foresight.DataAccess.Company company = null;
            if (!checkvalidcompany(context, out company))
            {
                var items = new { status = false, errormsg = "公司未登记" };
                WebUtil.WriteJson(context, items);
                return;
            }
            string     UserIDs    = context.Request["UserIDList"];
            List <int> UserIDList = new List <int>();

            if (!string.IsNullOrEmpty(UserIDs))
            {
                UserIDList = JsonConvert.DeserializeObject <List <int> >(UserIDs);
            }
            if (UserIDList.Count == 0)
            {
                WebUtil.WriteJson(context, new { status = true, errormsg = "OK" });
                return;
            }
            using (SqlHelper helper = new SqlHelper())
            {
                try
                {
                    helper.BeginTransaction();
                    string cmdtext = "delete from [User] where [FromCompanyID]=@FromCompanyID and [FromUserID] in (" + string.Join(",", UserIDList.ToArray()) + ");";
                    List <SqlParameter> parameters = new List <SqlParameter>();
                    parameters.Add(new SqlParameter("@FromCompanyID", company.CompanyID));
                    helper.Execute(cmdtext, CommandType.Text, parameters);
                    helper.Commit();
                }
                catch (Exception ex)
                {
                    WebUtil.WriteJson(context, new { status = false, errormsg = "系统异常:" + ex.Message });
                    helper.Rollback();
                    return;
                }
            }
            WebUtil.WriteJson(context, new { status = true, errormsg = "OK" });
        }
Example #10
0
        public static bool SaveCompany(Foresight.DataAccess.Company company, out string errormsg)
        {
            errormsg = string.Empty;
            if (IsLocalSystem())
            {
                return(Web.APPCode.SqlLiteHelper.SaveCompany(company, out errormsg));
            }
            if (IsInternalSys(out errormsg, false))
            {
                errormsg = "内部系统,无须审核";
                return(true);
            }
            ResponseData response = null;
            int          i        = 0;

            do
            {
                try
                {
                    i++;
                    string key    = EncriptName(company.BaseURL);
                    string result = Foresight.Web.HttpRequest.Post(null, new Dictionary <string, string>()
                    {
                        { "visit", "savecompanyinfo" }, { "key", key }, { "signature", SysConfig.GetSignature() }, { "token", SysConfig.GetToken() }, { "CompanyName", company.CompanyName }, { "Address", company.Address }, { "PhoneNumber", company.PhoneNumber }, { "CompanyDesc", company.CompanyDesc }, { "ChargePerson", company.ChargePerson }
                    });
                    response = JsonConvert.DeserializeObject <ResponseData>(result);
                }
                catch (Exception ex)
                {
                    Utility.LogHelper.WriteError("EncryptHelper", "SaveCompany", ex);
                }
            } while (response == null && i <= 3);
            if (response != null)
            {
                errormsg = response.errormsg;
                return(response.status);
            }
            errormsg = "操作超时,请稍候重试";
            return(false);
        }
Example #11
0
        private void checkcompany(HttpContext context)
        {
            Foresight.DataAccess.Company company = null;
            if (!checkvalidcompany(context, out company))
            {
                var items = new { status = false, errormsg = "公司未登记" };
                WebUtil.WriteJson(context, items);
                return;
            }
            if (company.IsAdmin)
            {
                var items = new { status = true, errormsg = "OK" };
                WebUtil.WriteJson(context, items);
                return;
            }
            if (!company.IsPay)
            {
                var items = new { status = false, errormsg = "当前公司未付费,禁止登陆" };
                WebUtil.WriteJson(context, items);
                return;
            }
            if (!company.IsActive)
            {
                var items = new { status = false, errormsg = "当前公司已禁用,禁止登陆" };
                WebUtil.WriteJson(context, items);
                return;
            }
            if (DateTime.Now < company.ServerStartTime || DateTime.Now > company.ServerEndTime)
            {
                var items = new { status = true, errormsg = "当前公司已超过使用期限,禁止登陆" };
                WebUtil.WriteJson(context, items);
                return;
            }
            var item = new { status = true, errormsg = "OK" };

            WebUtil.WriteJson(context, item);
            return;
        }
Example #12
0
        private void getcompanyinfo(HttpContext context)
        {
            string BaseURL  = WebUtil.GetContextPath();
            string errormsg = string.Empty;

            Foresight.DataAccess.Company company = WebUtil.GetCompany(context, readCache: false);
            string Login_LogoImg = company != null ? company.Login_LogImg : string.Empty;
            string Login_BodyImg = company != null ? company.Login_BodyImg : string.Empty;
            string Home_LogoImg  = company != null ? company.Home_LogoImg : string.Empty;
            string CompanyName   = company != null ? company.CompanyName : string.Empty;
            string CopyRightText = company != null ? company.CopyRightText : string.Empty;
            string ExpiringMsg   = company != null ? company.ExpiringMsg : string.Empty;

            bool     IsHideLogin_LogImg  = company != null ? company.IsHideLogin_LogImg : false;
            bool     IsHideLogin_BodyImg = company != null ? company.IsHideLogin_BodyImg : false;
            bool     IsHideHome_LogoImg  = company != null ? company.IsHideHome_LogoImg : false;
            bool     IsHideCopyRightText = company != null ? company.IsHideCopyRightText : false;
            bool     ExpiringShow        = company != null ? company.ExpiringShow : false;
            DateTime EndTime             = company != null ? company.ServerEndTime : DateTime.MinValue;
            int      ExpiringDay         = company != null ? company.ExpiringDay : 0;

            WebUtil.WriteJson(context, new { status = true, Login_LogoImg = Login_LogoImg, Login_BodyImg = Login_BodyImg, errormsg = errormsg, Home_LogoImg = Home_LogoImg, CompanyName = CompanyName, IsHideLogin_LogImg = IsHideLogin_LogImg, IsHideLogin_BodyImg = IsHideLogin_BodyImg, IsHideHome_LogoImg = IsHideHome_LogoImg, CopyRightText = CopyRightText, IsHideCopyRightText = IsHideCopyRightText, ExpiringShow = ExpiringShow, ExpiringDay = ExpiringDay, ExpiringMsg = ExpiringMsg });
        }
Example #13
0
 private void SetInfo(Foresight.DataAccess.Company data)
 {
     this.tdRealName.Value             = data.CompanyName;
     this.tdPhoneNumber.Value          = data.PhoneNumber;
     this.tdAddress.Value              = data.Address;
     this.tdIsActive.Value             = data.IsActive ? "1" : "0";
     this.tdIsPay.Value                = data.IsPay ? "1" : "0";
     this.tdDesc.Value                 = data.CompanyDesc;
     this.tdChargeMan.Value            = data.ChargePerson;
     this.tdDistributor.Value          = data.Distributor;
     this.tdUserCount.Value            = data.UserCount == int.MinValue ? "0" : data.UserCount.ToString();
     this.tdStartTime.Value            = data.ServerStartTime == DateTime.MinValue ? "" : data.ServerStartTime.ToString("yyyy-MM-dd HH:mm:ss");
     this.tdEndTime.Value              = data.ServerEndTime == DateTime.MinValue ? "" : data.ServerEndTime.ToString("yyyy-MM-dd HH:mm:ss");
     this.LogoPath                     = data.Login_LogImg;
     this.LogoBodyPath                 = data.Login_BodyImg;
     this.HomeLogoPath                 = data.Home_LogoImg;
     this.tdProjectCount.Value         = data.ProjectCount >= 0 ? data.ProjectCount.ToString() : "";
     this.btnShowLogin_LogImg.Checked  = !data.IsHideLogin_LogImg;
     this.btnShowLogin_BodyImg.Checked = !data.IsHideLogin_BodyImg;
     this.btnShowHome_LogoImg.Checked  = !data.IsHideHome_LogoImg;
     this.tdCopyRightText.Value        = data.CopyRightText;
     this.btnShowCopyRightText.Checked = !data.IsHideCopyRightText;
     this.tdAlowRemoteUpdate.Value     = data.AlowRemoteUpdate ? "1" : "0";
     this.tdIsWechatOn.Value           = data.IsWechatOn ? "1" : "0";
     this.tdVersionCode.Value          = data.VersionCode > 0 ? data.VersionCode.ToString() : "";
     this.tdExpiringDay.Value          = data.ExpiringDay > 0 ? data.ExpiringDay.ToString() : "0";
     this.btnExpiringShow.Checked      = data.ExpiringShow;
     this.tdExpiringMsg.Value          = data.ExpiringMsg;
     if (string.IsNullOrEmpty(data.Signature) || string.IsNullOrEmpty(data.Token))
     {
         data.Signature = Utility.Tools.GetRandomString(32, true, false, true);
         data.Token     = Utility.Tools.GetByteString(4);
         data.Save();
     }
     this.tdSignature.InnerHtml = data.Signature;
     this.tdToken.InnerHtml     = data.Token;
 }
Example #14
0
        public static bool DoUpgradeSite(Foresight.DataAccess.Company company, List <Utility.SiteVersionModel> list, int VersionCode, out string errormsg)
        {
            errormsg = string.Empty;
            if (IsLocalSystem())
            {
                errormsg = "局域网单机系统无法升级";
                return(false);
            }
            string       apiurl   = company.BaseURL + "/upgrade/api/api.ashx";
            ResponseData response = null;
            int          i        = 0;

            do
            {
                try
                {
                    i++;
                    string key    = EncriptName(company.BaseURL);
                    string result = Foresight.Web.HttpRequest.Post(null, new Dictionary <string, string>()
                    {
                        { "action", "doupgrade" }, { "VersionCode", VersionCode.ToString() }, { "versions", JsonConvert.SerializeObject(list) }
                    }, apiurl: apiurl);
                    response = JsonConvert.DeserializeObject <ResponseData>(result);
                }
                catch (Exception ex)
                {
                    Utility.LogHelper.WriteError("EncryptHelper", "DoUpgradeSite", ex);
                }
            } while (response == null && i <= 3);
            if (response != null)
            {
                errormsg = response.errormsg;
                return(response.status);
            }
            errormsg = "操作超时,请稍候重试";
            return(false);
        }
Example #15
0
        private void SaveUserInfo(HttpContext context)
        {
            bool   new_user_add = false;
            string UserType     = context.Request["UserType"];

            UserType = string.IsNullOrEmpty(UserType) ? UserTypeDefine.SystemUser.ToString() : UserType;
            int UserID    = GetIntValue(context, "UserID");
            int CompanyID = GetIntValue(context, "CompanyID");

            CompanyID = CompanyID <= 0 ? WebUtil.GetCompanyID(context) : CompanyID;
            Foresight.DataAccess.User    user    = null;
            Foresight.DataAccess.Company company = null;
            int  isLocked        = GetIntValue(context, "IsLocked");
            bool IsAllowSysLogin = WebUtil.GetIntValue(context, "IsAllowSysLogin") == 1;

            int user_type = WebUtil.GetIntValue(context, "user_type");

            if (UserID > 0)
            {
                user = User.GetUser(UserID);
            }
            if (user == null || isLocked == 0)
            {
                if (UserType.Equals(UserTypeDefine.SystemUser.ToString()) || IsAllowSysLogin)
                {
                    company = WebUtil.GetCompany(context, false);
                    int userCount  = company.UserCount;
                    int TotalCount = Foresight.DataAccess.User.GetSysUserCount();
                    if (user == null || (user != null && user.IsLocked))
                    {
                        TotalCount = TotalCount + 1;
                    }
                    if (TotalCount > userCount)
                    {
                        WebUtil.WriteJson(context, new { status = true, addfailed = true });
                        return;
                    }
                }
            }
            if (user == null)
            {
                new_user_add    = true;
                user            = new User();
                user.CreateTime = DateTime.Now;
            }
            string LoginName = context.Request.Params["LoginName"];

            if (UserType.Equals(UserTypeDefine.SystemUser.ToString()))
            {
                var sameuser = Foresight.DataAccess.User.GetUserByLoginName(LoginName);
                if (sameuser != null && sameuser.UserID != user.UserID)
                {
                    WebUtil.WriteJson(context, new { status = false, error = "登录名已存在" });
                    return;
                }
            }
            else
            {
                var sameuser = Foresight.DataAccess.User.GetAPPUserByLoginName(LoginName);
                if (sameuser != null && sameuser.UserID != user.UserID)
                {
                    if (UserType.Equals(Foresight.DataAccess.UserTypeDefine.APPUser.ToString()) && sameuser.Type.Equals(UserTypeDefine.APPCustomer.ToString()))
                    {
                        user = sameuser;
                    }
                    else
                    {
                        WebUtil.WriteJson(context, new { status = false, error = "登录名已存在" });
                        return;
                    }
                }
            }
            if (user_type <= 0 || new_user_add)
            {
                user.Type = UserType;
            }
            user.NickName    = context.Request.Params["NickName"];
            user.RealName    = context.Request.Params["RealName"];
            user.PhoneNumber = context.Request.Params["PhoneNumber"];
            user.Gender      = context.Request.Params["Gender"];
            user.IsLocked    = isLocked == 0 ? false : true;
            if (user.IsLocked)
            {
                user.LockTime = DateTime.Now;
            }
            if (!user.IsLocked)
            {
                user.ActiveTime = DateTime.Now;
            }
            string Pwd = context.Request.Params["Password"];

            user.LoginName = LoginName;
            if (!string.IsNullOrEmpty(Pwd))
            {
                user.Password = User.EncryptPassword(Pwd);
            }
            user.IsAllowSysLogin     = IsAllowSysLogin;
            user.IsAllowAPPUserLogin = WebUtil.GetIntValue(context, "IsAllowAPPUserLogin") == 1;
            user.HotPhoneLine        = context.Request.Params["HotPhoneLine"];
            user.BelongServiceName   = context.Request.Params["BelongServiceName"];
            user.QQNumber            = context.Request.Params["QQNumber"];
            user.OpenID               = context.Request.Params["OpenID"];
            user.PositionName         = context.Request["PositionName"];
            user.Education            = context.Request["Education"];
            user.DepartmentID         = WebUtil.GetIntValue(context, "DepartmentID");
            user.FixedPoint           = WebUtil.GetIntValue(context, "FixedPoint");
            user.FixedPointUpdateDate = WebUtil.GetDateValue(context, "FixedPointUpdateDate");
            user.IsAllowPhrase        = WebUtil.GetIntValue(context, "IsAllowPhrase") == 1;
            string DepartmentIDs = context.Request["DepartmentIDList"];

            int[] DepartmentIDList = new int[] { };
            if (!string.IsNullOrEmpty(DepartmentIDs))
            {
                DepartmentIDList = Utility.JsonConvert.DeserializeObject <int[]>(DepartmentIDs);
            }
            UserDepartment[] userDepartmentList = new UserDepartment[] { };
            if (user.UserID > 0)
            {
                userDepartmentList = UserDepartment.GetUserDepartmentListByMinMaxUserID(user.UserID, user.UserID);
            }
            using (SqlHelper helper = new SqlHelper())
            {
                try
                {
                    helper.BeginTransaction();
                    user.Save(helper);
                    foreach (var item in userDepartmentList)
                    {
                        item.Delete(helper);
                    }
                    foreach (var DepartmentID in DepartmentIDList)
                    {
                        var data = new UserDepartment();
                        data.UserID       = user.UserID;
                        data.DepartmentID = DepartmentID;
                        data.Save(helper);
                    }
                    var usercompany = Foresight.DataAccess.UserCompany.GetUserCompanyByUserID(user.UserID, helper);
                    if (usercompany == null)
                    {
                        usercompany           = new UserCompany();
                        usercompany.CompanyID = CompanyID;
                    }
                    usercompany.UserID = user.UserID;
                    usercompany.Save(helper);
                    helper.Commit();
                }
                catch (Exception)
                {
                    helper.Rollback();
                    WebUtil.WriteJson(context, new { status = false });
                }
            }
            //if (UserType.Equals(UserTypeDefine.APPUser.ToString()))
            //{
            //    company = Foresight.DataAccess.Company.GetCompanies().FirstOrDefault();
            //    string errormsg = string.Empty;
            //    if (!EncryptHelper.SaveAPPUser(company, user.LoginName, user.Password, user.UserID, user.Type, out errormsg))
            //    {
            //        user.Delete();
            //        WebUtil.WriteJson(context, new { status = false, error = errormsg });
            //        return;
            //    }
            //}
            if (new_user_add)
            {
                #region 新增账号日志
                APPCode.CommHelper.SaveOperationLog("新增账号" + user.LoginName, Utility.EnumModel.OperationModule.AddUser.ToString(), "新增账号", user.UserID.ToString(), "User");
                #endregion
            }
            WebUtil.WriteJson(context, new { status = true });
        }
Example #16
0
        private void registercompany(HttpContext context)
        {
            Foresight.DataAccess.Company fromcompany = null;
            if (!checkvalidcompany(context, out fromcompany))
            {
                var items = new { status = false, errormsg = "公司未登记" };
                WebUtil.WriteJson(context, items);
                return;
            }
            if (fromcompany.CompanyID == 93)
            {
                var items = new { status = false, errormsg = "你已被禁止使用该功能" };
                WebUtil.WriteJson(context, items);
                return;
            }
            string CompanyName = context.Request.Params["CompanyName"];
            var    company     = Foresight.DataAccess.Company.GetCompanyByCompanyName(CompanyName);

            if (company != null)
            {
                var item = new { status = false, errormsg = "该公司已注册,请联系公司管理员分配帐号" };
                WebUtil.WriteJson(context, item);
                return;
            }
            string LoginName = context.Request.Params["LoginName"];
            var    user      = Foresight.DataAccess.User.GetUserByLoginName(LoginName);

            if (user != null)
            {
                var item = new { status = false, errormsg = "登录名已存在,请更换" };
                WebUtil.WriteJson(context, item);
                return;
            }

            string PhoneNumber = context.Request.Params["PhoneNumber"];

            company             = new Company();
            company.CompanyName = CompanyName;
            company.AddTime     = DateTime.Now;
            company.IsActive    = false;
            company.Distributor = fromcompany.CompanyName;
            company.PhoneNumber = PhoneNumber;
            company.IsCustomer  = true;
            company.IsPay       = false;

            user            = new Foresight.DataAccess.User();
            user.LoginName  = LoginName;
            user.Password   = Foresight.DataAccess.User.EncryptPassword(context.Request.Params["Password"]);
            user.Type       = Foresight.DataAccess.UserTypeDefine.SystemUser.ToString();
            user.CreateTime = DateTime.Now;
            user.IsLocked   = false;

            var usercompany = new Foresight.DataAccess.UserCompany();

            using (SqlHelper helper = new SqlHelper())
            {
                try
                {
                    helper.BeginTransaction();
                    company.Save(helper);
                    user.Save(helper);
                    usercompany.UserID    = user.UserID;
                    usercompany.CompanyID = company.CompanyID;
                    usercompany.Save(helper);
                    helper.Commit();
                    var items = new { status = true, errormsg = "注册成功,管理员审核中,请耐心等待" };
                    WebUtil.WriteJson(context, items);
                }
                catch (Exception ex)
                {
                    LogHelper.WriteError("EncryptHandler", "visit: registercompany", ex);
                    helper.Rollback();
                    var items = new { status = false, errormsg = "服务器内部异常,请稍候重试" };
                    WebUtil.WriteJson(context, items);
                    return;
                }
            }
        }
Example #17
0
        public static bool GetCompanyInfo(string BaseURL, int FromCompanyID, out string errormsg, out Foresight.DataAccess.Company company, bool includedemo = true)
        {
            company  = null;
            errormsg = string.Empty;
            if (IsInternalSys(out errormsg, out company, includedemo))
            {
                return(true);
            }
            if (IsLocalSystem())
            {
                return(Web.APPCode.SqlLiteHelper.GetCompanyInfo(BaseURL, FromCompanyID, out errormsg, out company, includedemo: includedemo));
            }
            ResponseCompany response = null;
            int             i        = 0;

            do
            {
                try
                {
                    i++;
                    string key    = EncriptName(BaseURL);
                    string result = Foresight.Web.HttpRequest.Get(new Dictionary <string, string>()
                    {
                        { "visit", "getcompanyinfo" }, { "key", key }, { "signature", SysConfig.GetSignature() }, { "token", SysConfig.GetToken() }
                    });
                    response = JsonConvert.DeserializeObject <ResponseCompany>(result);
                }
                catch (Exception ex)
                {
                    Utility.LogHelper.WriteError("EncryptHelper", "GetCompanyInfo", ex);
                }
            } while (response == null && i <= 3);
            if (response != null)
            {
                company  = response.company;
                errormsg = response.errormsg;
                return(response.status);
            }
            errormsg = "操作超时,请稍候重试";
            return(false);
        }
Example #18
0
        private void SaveCompanyInfo(HttpContext context)
        {
            int CompanyID = GetIntValue(context, "CompanyID");

            Foresight.DataAccess.Company company = null;
            if (CompanyID > 0)
            {
                company = Company.GetCompany(CompanyID);
            }
            if (company == null)
            {
                company         = new Company();
                company.AddTime = DateTime.Now;
            }
            company.CompanyName         = context.Request.Params["CompanyName"];
            company.PhoneNumber         = context.Request.Params["PhoneNumber"];
            company.CompanyDesc         = context.Request.Params["Description"];
            company.IsActive            = GetIntValue(context, "IsActive") == 0 ? false : true;
            company.IsPay               = GetIntValue(context, "IsPay") == 0 ? false : true;
            company.Address             = context.Request.Params["Address"];
            company.ChargePerson        = context.Request.Params["ChargeMan"];
            company.Distributor         = context.Request.Params["Distributor"];
            company.UserCount           = GetIntValue(context, "UserCount");
            company.ServerStartTime     = GetDateTimeValue(context, "StartTime");
            company.ServerEndTime       = GetDateTimeValue(context, "EndtTime");
            company.IsHideLogin_LogImg  = WebUtil.GetIntValue(context, "IsHideLogin_LogImg") == 1;
            company.IsHideLogin_BodyImg = WebUtil.GetIntValue(context, "IsHideLogin_BodyImg") == 1;
            company.IsHideHome_LogoImg  = WebUtil.GetIntValue(context, "IsHideHome_LogoImg") == 1;
            company.IsHideCopyRightText = WebUtil.GetIntValue(context, "IsHideCopyRightText") == 1;
            company.CopyRightText       = context.Request["CopyRightText"];
            company.AlowRemoteUpdate    = WebUtil.GetIntValue(context, "AlowRemoteUpdate") == 1;
            company.IsWechatOn          = WebUtil.GetIntValue(context, "IsWechatOn") == 1;
            company.VersionCode         = GetIntValue(context, "VersionCode");
            company.ExpiringDay         = WebUtil.GetIntValue(context, "ExpiringDay");
            company.ExpiringShow        = WebUtil.GetIntValue(context, "ExpiringShow") == 1;
            company.ExpiringMsg         = context.Request["ExpiringMsg"];
            if (!string.IsNullOrEmpty(context.Request["ProjectCount"]))
            {
                int ProjectCount = WebUtil.GetIntValue(context, "ProjectCount");
                company.ProjectCount = ProjectCount;
            }
            else
            {
                company.ProjectCount = int.MinValue;
            }
            HttpFileCollection uploadFiles = context.Request.Files;

            if (uploadFiles.Count > 0)
            {
                for (int i = 0; i < uploadFiles.Count; i++)
                {
                    HttpPostedFile postedFile  = uploadFiles[i];
                    string         fileOriName = postedFile.FileName;
                    if (fileOriName != "" && fileOriName != null)
                    {
                        string extension = System.IO.Path.GetExtension(fileOriName).ToLower();
                        string fileName  = DateTime.Now.ToFileTime().ToString() + extension;
                        string filepath  = "/upload/Project/";
                        string rootPath  = HttpContext.Current.Server.MapPath("~" + filepath);
                        if (!System.IO.Directory.Exists(rootPath))
                        {
                            System.IO.Directory.CreateDirectory(rootPath);
                        }
                        string Path = rootPath + fileName;
                        postedFile.SaveAs(Path);
                        if (i == 0)
                        {
                            company.Login_LogImg = filepath + fileName;
                        }
                        else if (i == 1)
                        {
                            company.Login_BodyImg = filepath + fileName;
                        }
                        else
                        {
                            company.Home_LogoImg = filepath + fileName;
                        }
                    }
                }
            }
            company.Save();
            string errormsg = string.Empty;

            EncryptHelper.SaveCompany(company, out errormsg);
            context.Response.Write("{\"status\":true}");
        }