Пример #1
0
        private void 清除当前用户ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Dictionary <String, String> dicUserList = new Dictionary <string, string>();

            dicUserList = String.IsNullOrEmpty(SRConfig.Instance.GetAppString("ClientUser")) == true ? new Dictionary <string, string>() : Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <String, String> >(SRFun.DecodeReversible(SRConfig.Instance.GetAppString("ClientUser")));
            if (dicUserList.ContainsKey(this.cbxUsername.Text) == true)
            {
                dicUserList.Remove(this.cbxUsername.Text);
                SRConfig.Instance.SetAppString("ClientUser", SRFun.EncodeReversible(Newtonsoft.Json.JsonConvert.SerializeObject(dicUserList)));
            }
            if (dicUserList != null && dicUserList.Count > 0)
            {
                this.cbxUsername.ValueMember   = "Value";
                this.cbxUsername.DisplayMember = "Key";
                List <KeyValuePair <string, string> > list = dicUserList.ToList();
                list.Reverse();
                this.cbxUsername.DataSource    = list;
                this.checkBox2.Checked         = true;
                this.cbxUsername.SelectedIndex = 0;
            }
            else
            {
                this.cbxUsername.Text = "";
                this.cbxPwd.Text      = "";
            }
        }
Пример #2
0
        private void 清除当前服务器ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List <String> entList = new List <string>();

            entList = String.IsNullOrEmpty(SRConfig.Instance.GetAppString("ClientServer")) == true ? new List <String>() : Newtonsoft.Json.JsonConvert.DeserializeObject <List <String> >(SRFun.DecodeReversible(SRConfig.Instance.GetAppString("ClientServer")));
            if (entList.Any(m => m.Equals(this.cbxServer.Text) == true) == true)
            {
                entList.Remove(this.cbxServer.Text);
                SRConfig.Instance.SetAppString("ClientServer", SRFun.EncodeReversible(Newtonsoft.Json.JsonConvert.SerializeObject(entList)));
            }
            if (entList != null && entList.Count > 0)
            {
                foreach (var item in entList)
                {
                    this.cbxServer.Items.Add(item);
                }
                this.cbxServer.SelectedIndex = 0;
                this.chkServer.Checked       = true;
            }
            else
            {
                this.cbxServer.Text = "";
            }
        }
Пример #3
0
 private void FrmLogin_Load(object sender, EventArgs e)
 {
     //<add key="ClientChk" value="false"/>
     //<add key="Client" value=""/>
     #region 记住服务器
     List <String> entList = new List <string>();
     entList = String.IsNullOrEmpty(SRConfig.Instance.GetAppString("ClientServer")) == true ? new List <String>() : Newtonsoft.Json.JsonConvert.DeserializeObject <List <String> >(SRFun.DecodeReversible(SRConfig.Instance.GetAppString("ClientServer")));
     if (entList != null && entList.Count > 0)
     {
         foreach (var item in entList)
         {
             this.cbxServer.Items.Add(item);
         }
         this.cbxServer.SelectedIndex = 0;
         this.chkServer.Checked       = true;
     }
     #endregion
     #region 记住用户
     Dictionary <String, String> dicUserList = new Dictionary <string, string>();
     dicUserList = String.IsNullOrEmpty(SRConfig.Instance.GetAppString("ClientUser")) == true ? new Dictionary <string, string>() : Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <String, String> >(SRFun.DecodeReversible(SRConfig.Instance.GetAppString("ClientUser")));
     if (dicUserList != null && dicUserList.Count > 0)
     {
         this.cbxUsername.ValueMember   = "Value";
         this.cbxUsername.DisplayMember = "Key";
         List <KeyValuePair <string, string> > list = dicUserList.ToList();
         list.Reverse();
         this.cbxUsername.DataSource    = list;
         this.checkBox2.Checked         = true;
         this.cbxUsername.SelectedIndex = 0;
     }
     #endregion
 }
Пример #4
0
        //登陆
        private void picOk_Click(object sender, EventArgs e)
        {
            //更新helper
            SRConfig.Instance.SetAppString("ServerIp", this.cbxServer.Text);
            DataBaseHelper.Instance                   = new DataBaseHelper();
            DataBase.Instance.tSR_User                = new SR_User();
            DataBase.Instance.tSR_Wordbook            = new SR_Wordbook();
            DataBase.Instance.tSR_Systemrecord        = new SR_Systemrecord();
            DataBase.Instance.tSMDictionary           = new SMDictionary();
            DataBase.Instance.tSRRC_Biaoji            = new SRRC_Biaoji();
            DataBase.Instance.tSRRC_Resource          = new SRRC_Resource();
            DataBase.Instance.tSRRC_Resourcebiaojirel = new SRRC_Resourcebiaojirel();
            DataBase.Instance.tSR_UserSetting         = new SR_UserSetting();
            //登录按钮隐藏,避免重复点击
            this.picOk.Visible = false;

            String strServer   = this.cbxServer.Text;
            string strUsername = this.cbxUsername.Text;
            string strPwd      = this.textBox1.Text;

            #region 验证
            //if (string.IsNullOrEmpty(strServer) == true)
            //{
            //    new SRFMessageBox("请选择或输入服务器", "提示", MessageBoxButtons.OK).ShowDialog(); return;
            //}
            //else if (string.IsNullOrEmpty(strPort) == true)
            //{
            //    new SRFMessageBox("请选择或输入端口", "提示", MessageBoxButtons.OK).ShowDialog(); return;
            //}
            //else
            if (string.IsNullOrEmpty(strUsername) == true)
            {
                new SRFMessageBox("请输入用户名", "提示", MessageBoxButtons.OK).ShowDialog(); this.picOk.Visible = true; return;
            }
            else if (string.IsNullOrEmpty(strPwd) == true)
            {
                new SRFMessageBox("请输入密码", "提示", MessageBoxButtons.OK).ShowDialog(); this.picOk.Visible = true; return;
            }
            #endregion

            this.pristrServer   = strServer;
            this.pristrPwd      = strPwd;
            this.pristrUsername = strUsername;
            //this.lblLoginLog.Visible = true;
            //Thread.Sleep(1000);
            Thread t = new Thread(new ThreadStart(this.Login));
            t.IsBackground = true;
            t.Start();
            LoadingCheckBoxImageList();//等待时执行
            _event.WaitOne();
            //t = new Thread(new ThreadStart(FrmLogin.GetImageListByLeftSelectedId));
            //t.IsBackground = true;
            //t.Start();
            Thread.Sleep(1000);
            //this.Login();
            //this.lblLoginLog.Visible = false;
            SRLogin.SRLoginResultType loginResultType = this.priSRLoginResultType;
            //SRLogin.SRLoginResultType loginResultType = SRLogin.SRLoginResultType.LoginOk;
            switch (loginResultType)
            {
            case SRLogin.SRLoginResultType.LoginOk:
                #region 记住服务器
                List <String> entList = new List <string>();
                entList = String.IsNullOrEmpty(SRConfig.Instance.GetAppString("ClientServer")) == true ? new List <String>() : Newtonsoft.Json.JsonConvert.DeserializeObject <List <String> >(SRFun.DecodeReversible(SRConfig.Instance.GetAppString("ClientServer")));
                if (this.chkServer.Checked == true)
                {
                    if (entList.Any(m => m.Equals(this.pristrServer) == true) == true)
                    {
                        entList.Remove(this.pristrServer);    //如果存在,则移除
                    }
                    entList.Insert(0, this.pristrServer);     //插入首位,以便第一个显示
                    SRConfig.Instance.SetAppString("ClientServer", SRFun.EncodeReversible(Newtonsoft.Json.JsonConvert.SerializeObject(entList)));
                }
                else
                {
                    if (entList.Any(m => m.Equals(this.pristrServer) == true) == true)
                    {
                        entList.Remove(this.pristrServer);
                        SRConfig.Instance.SetAppString("ClientServer", SRFun.EncodeReversible(Newtonsoft.Json.JsonConvert.SerializeObject(entList)));
                    }
                }
                #endregion
                #region 记住用户
                Dictionary <String, String> dicUserList = new Dictionary <string, string>();
                dicUserList = String.IsNullOrEmpty(SRConfig.Instance.GetAppString("ClientUser")) == true ? new Dictionary <string, string>() : Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <String, String> >(SRFun.DecodeReversible(SRConfig.Instance.GetAppString("ClientUser")));
                if (this.checkBox2.Checked == true)
                {
                    if (dicUserList.ContainsKey(this.pristrUsername) == true)
                    {
                        dicUserList.Remove(this.pristrUsername);
                    }
                    dicUserList.Add(this.pristrUsername, this.pristrPwd);
                    SRConfig.Instance.SetAppString("ClientUser", SRFun.EncodeReversible(Newtonsoft.Json.JsonConvert.SerializeObject(dicUserList)));
                }
                else
                {
                    if (dicUserList.ContainsKey(this.pristrUsername) == true)
                    {
                        dicUserList.Remove(this.pristrUsername);
                        SRConfig.Instance.SetAppString("ClientUser", SRFun.EncodeReversible(Newtonsoft.Json.JsonConvert.SerializeObject(dicUserList)));
                    }
                }
                #endregion
                #region 写日志
                //SirdRoom.Data.SQL.SRSystemRecord.Create_SRSystemRecordInsert(
                //    new SirdRoom.Data.SQL.SRSystemRecord(0, -1, "登陆成功", String.Format("IP:{0} 用户名:{1}进入系统!", Request.UserHostAddress, strUsername), DateTime.Now, "Ok", SRSystemRecordType.Log)
                //    , SRSystemRecordMode.Local
                //    );
                DataBase.Instance.tSR_Systemrecord.Add(new SR_SystemrecordEntity()
                {
                    Adddate     = DateTime.Now,
                    Ltype       = "日志",
                    Title       = Param.Loginname,
                    Description = "用户登陆",
                    Remark      = "登陆"
                });
                #endregion
                Param.LoginState = true;
                Param.Loginname  = this.pristrUsername;
                Param.Pwd        = this.pristrPwd;
                List <DataParameter> whereParam = (new List <DataParameter> {
                    new DataParameter("Loginname", this.pristrUsername)
                });
                Param.UserEnt    = DataBase.Instance.tSR_User.Get_Entity(" Loginname=[$Loginname$] ", whereParam.ToArray());
                Param.UserId     = Param.UserEnt.Id;
                Param.GroupId    = Param.UserEnt.Groupid;
                Param.LoginState = true;
                var userSetting = DataBase.Instance.tSR_UserSetting.Get_Entity(Param.UserId);
                Param.filterkeyword = userSetting == null ? "" : userSetting.DefaultKeyword;
                this.DialogResult   = DialogResult.OK;
                this.Close();
                //if (Application.OpenForms["FrmLogin"] != null) Application.OpenForms["FrmLogin"].Close();
                break;

            case SRLogin.SRLoginResultType.UsernameError:
                new SRFMessageBox("用户名不存在", "提示", MessageBoxButtons.OK).ShowDialog(); this.picOk.Visible = true;
                #region 写日志
                //SirdRoom.Data.SQL.SRSystemRecord.Create_SRSystemRecordInsert(
                //    new SirdRoom.Data.SQL.SRSystemRecord(0, -1, "登陆失败", String.Format("IP:{0} 用户名:{1}登陆失败!", Request.UserHostAddress, strUsername), DateTime.Now, "Error", SRSystemRecordType.Log)
                //    , SRSystemRecordMode.Local
                //    );
                #endregion
                break;

            case SRLogin.SRLoginResultType.PwdError:
                new SRFMessageBox("密码错误,请重新输入", "提示", MessageBoxButtons.OK).ShowDialog(); this.picOk.Visible = true;
                #region 写日志
                //SirdRoom.Data.SQL.SRSystemRecord.Create_SRSystemRecordInsert(
                //    new SirdRoom.Data.SQL.SRSystemRecord(0, -1, "登陆失败", String.Format("IP:{0} 用户名:{1}密码错误!", Request.UserHostAddress, strUsername), DateTime.Now, "Error", SRSystemRecordType.Log)
                //    , SRSystemRecordMode.Local
                //    );
                #endregion
                break;

            case SRLogin.SRLoginResultType.AuthorizeExpired:
                new SRFMessageBox("授权过期!", "提示", MessageBoxButtons.OK).ShowDialog(); this.picOk.Visible = true;
                #region 写日志
                //SirdRoom.Data.SQL.SRSystemRecord.Create_SRSystemRecordInsert(
                //    new SirdRoom.Data.SQL.SRSystemRecord(0, -1, "登陆失败", String.Format("授权过期,不能使用系统!"), DateTime.Now, "Error", SRSystemRecordType.Log)
                //    , SRSystemRecordMode.Local
                //    );
                #endregion
                break;

            case SRLogin.SRLoginResultType.NoInstall:
                //Response.Redirect("~/Install/Install.aspx");
                new SRFMessageBox("无法连接到服务器!", "提示", MessageBoxButtons.OK).ShowDialog(); this.picOk.Visible = true;
                break;

            default:
                new SRFMessageBox("登陆失败!", "提示", MessageBoxButtons.OK).ShowDialog(); this.picOk.Visible = true;
                break;
            }
            //GU.SetControlVisible(this.lblLoginLog, false);
        }