Inheritance: BaseScript
Esempio n. 1
0
File: Enter.cs Progetto: DQST/Chat
 private void Enter_Load(object sender, EventArgs e)
 {
     main = new Main(this);
     main.Show();
     main.Hide();
     LoadSettings();
 }
Esempio n. 2
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();
                }
            }
        }
Esempio n. 3
0
 private void button1_Click_1(object sender, EventArgs e)
 {
     Main formMain = new Main();
     formMain.Show();
 }
Esempio n. 4
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();
        }