예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            string pwd         = "";
            var    md5         = MD5.Create();
            var    computeHash = md5.ComputeHash(Encoding.UTF8.GetBytes(PwdTxt.ToString()));

            foreach (var b in computeHash)
            {
                pwd += b.ToString();
            }

            using (var context = new Model())
            {
                var cStaffBaseInformation = context.C_StaffBaseInformation.FirstOrDefault(s => s.Account == AccountTxt.Text);
                if (cStaffBaseInformation != null)
                {
                    if (cStaffBaseInformation.Password == pwd)
                    {
                        FrmDialog.ShowDialog(this, "登陆成功,欢迎使用!", "登陆成功");
                        // MessageBox.Show("登陆成功,欢迎使用!");
                        this.Hide();

                        string strIp = "";
                        foreach (var ipAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
                        {
                            strIp = ipAddress.ToString();
                        }
                        //在登陆过程表中插入数据
                        var cLoginInProcessing = new C_LoginInProcessing()
                        {
                            StaffCode  = cStaffBaseInformation.StaffCode,
                            StaffID    = cStaffBaseInformation.StaffID,
                            StaffName  = cStaffBaseInformation.StaffName,
                            OnlineTime = context.GetServerDate(),
                            //设备id???
                            EquipmentID   = 1,
                            EquipmentName = "车车中心",
                            IP            = strIp,
                            Remarks       = "测试数据"
                        };

                        context.C_LoginInProcessing.Add(cLoginInProcessing);
                        context.SaveChanges();

                        new MainPanel(cLoginInProcessing.StaffID, cLoginInProcessing.StaffCode, cLoginInProcessing.StaffName).Show();
                    }
                    else
                    {
                        FrmDialog.ShowDialog(this, "密码错误,请重试!", "登陆失败");
                        // MessageBox.Show("密码错误,请重试!");
                    }
                }
                else
                {
                    FrmDialog.ShowDialog(this, "该用户不存在!", "登陆失败");
                    // MessageBox.Show("该用户不存在!");
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string pwd         = "";
            var    md5         = MD5.Create();
            var    computeHash = md5.ComputeHash(Encoding.UTF8.GetBytes(PwdTxt.ToString()));

            foreach (var b in computeHash)
            {
                pwd += b.ToString();
            }

            using (var context = new Model())
            {
                // var connectionState = context.Database.Connection.State;
                // if (connectionState==ConnectionState.Closed||connectionState==ConnectionState.Broken)
                // {
                //     FrmDialog.ShowDialog(this, "服务器异常,请校正服务器状态后重试");
                //     return;
                // }
                var cStaffBaseInformation = context.C_StaffBaseInformation.FirstOrDefault(s => s.Account == AccountTxt.Text);
                if (cStaffBaseInformation != null)
                {
                    if (cStaffBaseInformation.Password == pwd)
                    {
                        FrmDialog.ShowDialog(this, "登陆成功,欢迎使用!", "登陆成功");
                        this.Hide();

                        string strIp = "";
                        foreach (var ipAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
                        {
                            strIp = ipAddress.ToString();
                        }

                        if (!cStaffBaseInformation.Account.Contains("admin"))
                        {
                            int.TryParse(_equipmentId, out var result);
                            //在登陆过程表中插入数据
                            var cLoginInProcessing = new C_LoginInProcessing()
                            {
                                StaffCode  = cStaffBaseInformation.StaffCode,
                                StaffID    = cStaffBaseInformation.StaffID,
                                StaffName  = cStaffBaseInformation.StaffName,
                                OnlineTime = context.GetServerDate(),
                                //设备id???
                                EquipmentID   = result,
                                EquipmentName = _equipmentName,
                                IP            = strIp,
                                Remarks       = "测试数据"
                            };

                            context.C_LoginInProcessing.Add(cLoginInProcessing);
                            context.SaveChanges();
                        }

                        new MainPanel(cStaffBaseInformation.StaffID, cStaffBaseInformation.StaffCode, cStaffBaseInformation.StaffName).Show();
                    }
                    else
                    {
                        FrmDialog.ShowDialog(this, "密码错误,请重试!", "登陆失败");
                    }
                }
                else
                {
                    FrmDialog.ShowDialog(this, "该用户不存在!", "登陆失败");
                }
            }
        }