Example #1
0
File: Enter.cs Project: DQST/Chat
 private void Enter_Load(object sender, EventArgs e)
 {
     main = new Main(this);
     main.Show();
     main.Hide();
     LoadSettings();
 }
Example #2
0
        public async void LoginConsumer()
        {
            try
            {
                if (textBox_Email.Text != "" && passwordBox_Password.Password != "")
                {
                    try
                    {
                        Consumer ConsumerLog = await Session.serverConnection.consumerService.LoginConsumerAsync(textBox_Email.Text, passwordBox_Password.Password);

                        if (ConsumerLog != null)
                        {
                            Session.consumer          = ConsumerLog;
                            Session.library.IdLibrary = await Session.serverConnection.libraryService.getLibraryByIdConsumerAsync(Session.consumer.IdConsumer);

                            Main main = new Main();
                            main.Show();
                            this.Close();
                        }
                    } catch (NullReferenceException ex)
                    {
                        textBlock_Message.Text = "*Service error, please close and try again";
                        Console.WriteLine(ex + " in Login loginConsumer");
                    }
                }
                else
                {
                    textBlock_Message.Text = "*Complete all fields";
                }
            }
            catch (Exception ex)
            {
                textBlock_Message.Text = "*Email or password are wrong";
                Console.WriteLine(ex + " in Login LoginConsumer");
            }
        }
Example #3
0
        private void LoginButton_Click(object sender, EventArgs e)
        {
            String usename  = UsernameBox.Text;
            String password = PasswordBox.Text;

            try
            {
                Employee employee = ctrl.Login(usename, password);
                if (employee != null)
                {
                    Main mainForm = new Main(this, ctrl);
                    this.Hide();
                    mainForm.Show();
                }
                else
                {
                    MessageBox.Show("The username and/or password are not matching ! ");
                }
            }
            catch (ValidationException)
            {
                MessageBox.Show("The user is already logged in");
            }
        }
Example #4
0
        //登录

        public void loginBut_Click(object sender, EventArgs e)
        {
            if (idTextBox.Text.Trim() == idText || idTextBox.Text.Trim() == "")
            {
                ToolTip.Show("请输入账号在登录", idTextBox);
                //这边的强制转换我暂时不清楚会不会成功
                //idTextBox_MouseDown(sender, (MouseEventArgs)e);
                if (pswTextBox.Text.Trim() == idText || pswTextBox.Text.Trim() == "")
                {
                    ToolTip.Show("请输入账号再登录", idTextBox);
                    //idTextBox_MouseDown(sender, (MouseEventArgs)e);
                }
            }
            else if (pswTextBox.Text.Trim() == pswText || pswTextBox.Text.Trim() == "")
            {
                ToolTip.Show("请输入密码再登录", idTextBox);
                // pswTextBox_MouseDown(sender, (MouseEventArgs)e);
            }
            else
            {
                //用户如果是第一次登录---需要验证
                if (Variable.fl)
                {
                    Y y = new Y();
                    y.Show();
                    //初始化用户名
                    y.login = this;
                    y.name  = idTextBox.Text.Trim();
                    y.psw   = pswTextBox.Text.Trim();
                }
                if (Variable.fl == false)
                {
                    //this.Show();
                    userLogin.Name = idTextBox.Text.Trim();
                    userLogin.Pwd  = pswTextBox.Text.Trim();
                    //将用户的勾选自动登录、记住密码的操作更新到数据库
                    if (remeber.Checked)
                    {
                        userLogin.Remember = 1;
                    }
                    else
                    {
                        userLogin.Remember = 0;
                    }
                    if (AutoLogin.Checked)
                    {
                        userLogin.AutoLogin = 1;
                    }
                    else
                    {
                        userLogin.AutoLogin = 0;
                    }
                    //对登录的操作
                    protocolqq.mode = 0;
                    protocolqq.ope  = 0;
                    protocolqq.data = userLogin;
                    //这个线程会睡1秒
                    user.SendMsg(protocolqq);

                    //如果登录成功
                    if (Variable.IsLogin)
                    {
                        //将该用户的用户名-密码-头像-勾选记住密码、自动登录记录到本地文件
                        #region 将这个类写入文件
                        l   = new LocMess();
                        l.I = Variable.user.ID;
                        l.H = Variable.user.HeadId;
                        //用户勾选了记住密码才想文件中存入密码
                        if (userLogin.Remember == 1)
                        {
                            l.P = userLogin.Pwd;
                        }
                        else
                        {
                            l.P = "";
                        }
                        l.R = userLogin.Remember;
                        l.A = userLogin.AutoLogin;
                        //

                        FileStream      fs = new FileStream("LocalMess.bin", FileMode.Create);
                        BinaryFormatter bf = new BinaryFormatter();
                        //  选在集合中是否存在用户名
                        if (ls.ContainsKey(l.I))
                        {
                            ls.Remove(l.I);
                        }

                        ls.Add(l.I, l);
                        //要先将l类先设为可以序列化(即在类的前面加[Serializable])
                        bf.Serialize(fs, ls);
                        //user.Password = this.PassWord.Text;
                        fs.Close();
                        #endregion
                        //显示主窗口
                        Main form = new Main();
                        this.Visible = false;
                        form.Show();
                    }

                    //用户密码错误,显示可以修改密码的pannel

                    //用户密码错误,显示可以修改密码的pannel
                    else
                    {
                        headPic.Visible  = false;
                        errorPsw.Visible = true;
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// 登录事件
        /// </summary>
        private void picLogin_Click(object sender, EventArgs e)
        {
            if (this.TxtUser.Text == "请输入用户名" || this.TxtKey.Text == "请输入密码" || this.TxtUser.Text == "" || this.TxtKey.Text == "")//判断是否为空
            {
                PassValue.MessageInfor = "用户名和密码不能为空";
                Messagebox mb = new Messagebox();
                mb.ShowDialog();
                this.TxtKey.Text = "请输入密码"; this.TxtUser.Text = "";
                this.TxtUser.Focus();
            }
            else
            {
                PassValue.username = this.TxtUser.Text;//用户名
                PassValue.password = this.TxtKey.Text;//密码
                string passvalue = PassValue.username + ":" + PassValue.password;
                WebHeaderCollection headers = new WebHeaderCollection();
                headers.Add("Authorization", "Basic " + System.Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(passvalue)));
                headers.Add("Authed", "true");
                LoginID li = null;

                HttpResult httpResult = httpReq.HttpPost("auth/tokens", null, headers);
                if ((int)httpResult.StatusCode == 0)
                {
                    MessageBox.Show(string.Format("{0}{1}", httpResult.StatusDescription, httpResult.OtherDescription), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
                //else if ((int)httpResult.StatusCode == 403)
                //{
                //    if (MessageBox.Show("用户已在其他地方登陆 是否强制登陆?", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK)
                //    {
                //        headers.Add("Authed", "true");
                //        httpResult = httpReq.HttpPost("auth/tokens", null, headers);
                //    }
                //    else
                //    {
                //        return;
                //    }
                //}

                if ((int)httpResult.StatusCode >= 200 && (int)httpResult.StatusCode < 300)
                {
                    li = httpReq.ScriptDeserialize<LoginID>(httpResult.Html);
                    PassValue.token = "Token " + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(li.id));//ID加密
                    PassValue.tokenid = li.id;
                    PassValue.Code = li.principal.code;
                    if (needRemPassword)
                    {
                        Global.GetConfig().SetConfigString("system", "LoginUserName", this.TxtUser.Text.Trim());
                        Global.GetConfig().SetConfigString("system", "LoginUserPSW", this.TxtKey.Text.Trim());
                    }

                    //获取楼层信息
                    Layout floorLayout = httpReq.HttpGet<Layout>("layout");
                    if (floorLayout != null)
                    {
                        foreach (Floor floor in floorLayout.floors)
                        {
                            PassValue.tablesstatuslist.Add(floor.number);
                        }
                        PassValue.tablesstatuslist.Sort();
                    }

                    //获取桌子信息
                    PassValue.Tables = httpReq.HttpGet<List<Table>>("tables");

                    //获取交接班需要的信息
                    Shift shift = new Shift();
                    shift.cashier = new Employee();
                    if (li != null)
                    {
                        shift.cashier.id = li.principal.id;
                    }

                    httpResult = httpReq.HttpPost("shifts", shift);
                    if ((int)httpResult.StatusCode >= 200 && (int)httpResult.StatusCode < 300)
                    {
                        shift = httpReq.ScriptDeserialize<Shift>(httpResult.Html);
                        PassValue.shiftId = shift.id;
                        needHandOver = shift.isWarn;
                    }
                    else if ((int)httpResult.StatusCode == 0)
                    {
                        MessageBox.Show(string.Format("{0}{1}", httpResult.StatusDescription, httpResult.OtherDescription), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        return;
                    }

                    Main frmMain = new Main(this);
                    frmMain.Show();
                }
                else
                {
                    MessageBox.Show("请输入正确的工号和密码!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    this.TxtKey.Text = "";
                    this.TxtUser.Text = "";
                    this.TxtUser.Focus();
                }
            }
        }
Example #6
0
        public void inputY_TextChanged(object sender, EventArgs e)
        {
            if (inputY.Text.Trim().Length == 4)
            {
                if (inputY.Text.Trim() != code)
                {
                    code = YZM.CreateRandomCode(4);
                    //一个图片信息
                    picY.BackgroundImage = YZM.CreateValidateGraphic(code);
                    //输入验证码验证
                }
                else
                {
                    Variable.fl  = false;
                    this.Visible = false;
                    login.loginBut_Click(sender, e);
#if false
                    UserLogin userLogin = new UserLogin();
                    userLogin.Name  = name;
                    userLogin.Pwd   = psw.Trim();
                    protocolqq.mode = 0;
                    protocolqq.ope  = 0;
                    protocolqq.data = userLogin;
                    //这个线程会睡1秒
                    Variable.client.SendMsg(protocolqq);

                    //Thread.Sleep(1000);
                    if (Variable.IsLogin)
                    {
                        Variable.fl = false;
                        login.loginBut_Click(sender, e);
                        //将该用户的用户名-密码-头像-勾选记住密码、自动登录记录到本地文件
                        #region 将这个类写入文件
                        l.I = userLogin.Name;
                        l.H = Variable.user.HeadId;
                        //用户勾选了记住密码才想文件中存入密码
                        if (userLogin.Remember == 1)
                        {
                            l.P = userLogin.Pwd;
                        }
                        else
                        {
                            l.P = "";
                        }
                        l.R = userLogin.Remember;
                        l.A = userLogin.AutoLogin;
                        //

                        FileStream      fs = new FileStream("LocalMess.bin", FileMode.Create);
                        BinaryFormatter bf = new BinaryFormatter();
                        //  选在集合中是否存在用户名
                        if (ls.ContainsKey(l.I))
                        {
                            ls.Remove(l.I);
                        }

                        ls.Add(l.I, l);
                        //要先将l类先设为可以序列化(即在类的前面加[Serializable])
                        bf.Serialize(fs, ls);
                        //user.Password = this.PassWord.Text;
                        fs.Close();
                        #endregion
                        //显示主窗口
                        Main form = new Main();
                        this.Visible = false;
                        form.Show();
                    }

                    else
                    {
                        errorPsw.Visible = true;
                    }
#endif
                }
            }
        }
Example #7
0
 private void button1_Click_1(object sender, EventArgs e)
 {
     Main formMain = new Main();
     formMain.Show();
 }
Example #8
0
        /// <summary>
        /// 登录事件
        /// </summary>
        private void picLogin_Click(object sender, EventArgs e)
        {
            if (this.TxtUser.Text == "请输入用户名" || this.TxtKey.Text == "请输入密码" || this.TxtUser.Text == "" || this.TxtKey.Text == "")//判断是否为空
            {
                PassValue.MessageInfor = "用户名和密码不能为空";
                Messagebox mb = new Messagebox();
                mb.ShowDialog();
                this.TxtKey.Text = "请输入密码"; this.TxtUser.Text = "";
                this.TxtUser.Focus();
            }
            else
            {
                PassValue.username = this.TxtUser.Text; //用户名
                PassValue.password = this.TxtKey.Text;  //密码
                string passvalue            = PassValue.username + ":" + PassValue.password;
                WebHeaderCollection headers = new WebHeaderCollection();
                headers.Add("Authorization", "Basic " + System.Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(passvalue)));
                headers.Add("Authed", "true");
                LoginID li = null;

                HttpResult httpResult = httpReq.HttpPost("auth/tokens", null, headers);
                if ((int)httpResult.StatusCode == 0)
                {
                    MessageBox.Show(string.Format("{0}{1}", httpResult.StatusDescription, httpResult.OtherDescription), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
                //else if ((int)httpResult.StatusCode == 403)
                //{
                //    if (MessageBox.Show("用户已在其他地方登陆 是否强制登陆?", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK)
                //    {
                //        headers.Add("Authed", "true");
                //        httpResult = httpReq.HttpPost("auth/tokens", null, headers);
                //    }
                //    else
                //    {
                //        return;
                //    }
                //}

                if ((int)httpResult.StatusCode >= 200 && (int)httpResult.StatusCode < 300)
                {
                    li = httpReq.ScriptDeserialize <LoginID>(httpResult.Html);
                    PassValue.token   = "Token " + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(li.id));//ID加密
                    PassValue.tokenid = li.id;
                    PassValue.Code    = li.principal.code;
                    if (needRemPassword)
                    {
                        Global.GetConfig().SetConfigString("system", "LoginUserName", this.TxtUser.Text.Trim());
                        Global.GetConfig().SetConfigString("system", "LoginUserPSW", this.TxtKey.Text.Trim());
                    }

                    //获取楼层信息
                    Layout floorLayout = httpReq.HttpGet <Layout>("layout");
                    if (floorLayout != null)
                    {
                        foreach (Floor floor in floorLayout.floors)
                        {
                            PassValue.tablesstatuslist.Add(floor.number);
                        }
                        PassValue.tablesstatuslist.Sort();
                    }

                    //获取桌子信息
                    PassValue.Tables = httpReq.HttpGet <List <Table> >("tables");

                    //获取交接班需要的信息
                    Shift shift = new Shift();
                    shift.cashier = new Employee();
                    if (li != null)
                    {
                        shift.cashier.id = li.principal.id;
                    }

                    httpResult = httpReq.HttpPost("shifts", shift);
                    if ((int)httpResult.StatusCode >= 200 && (int)httpResult.StatusCode < 300)
                    {
                        shift             = httpReq.ScriptDeserialize <Shift>(httpResult.Html);
                        PassValue.shiftId = shift.id;
                        needHandOver      = shift.isWarn;
                    }
                    else if ((int)httpResult.StatusCode == 0)
                    {
                        MessageBox.Show(string.Format("{0}{1}", httpResult.StatusDescription, httpResult.OtherDescription), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        return;
                    }

                    Main frmMain = new Main(this);
                    frmMain.Show();
                }
                else
                {
                    MessageBox.Show("请输入正确的工号和密码!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    this.TxtKey.Text  = "";
                    this.TxtUser.Text = "";
                    this.TxtUser.Focus();
                }
            }
        }
Example #9
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (!ValidateLoginInfo())
            {
                return;
            }

            var tcpClient = new TcpClient();
            try
            {
                tcpClient.Connect(ipAddr, port);

                if (!tcpClient.Connected)
                {
                    MessageBox.Show(@"TCP 连接未能成功建立", @"错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
            }
            catch (SocketException se)
            {
                MessageBox.Show( se.Message, @"错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            NetworkStream stream = tcpClient.GetStream();
            stream.Write(Encoding.Unicode.GetBytes(UserName), 0, Encoding.Unicode.GetBytes(UserName).Length);

            byte[] buffer = new byte[512];
            stream.Read(buffer, 0, buffer.Length);
            string connResult = Encoding.Unicode.GetString(buffer).TrimEnd('\0');

            if (connResult.Equals("cmd::Failed"))
            {
                MessageBox.Show("用户名已被使用", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else if (connResult.Equals("cmd::Successful"))
            {
                MessageBox.Show("登陆成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            string serverSocket = ServerIPAddress + ":" + port;

            Main mainForm = new Main(UserName, serverSocket, stream);

            mainForm.Owner = this;
            Hide();
            mainForm.Show();
        }