示例#1
0
        public void ValidatePasswordFromDatabase()
        {
            Connection cc = new Connection();

            try {
                SqlDataAdapter sda = new SqlDataAdapter("select [UserId],[Username],[Password],[EmployeeName],[EmployeePhone],[EmployeeEmail],[EmployeeDesignation],[AllowInternetLogin] from [mbo].[PSUsers] where Username='******' and password='******'", cc.con);
                DataTable      dt  = new DataTable();
                sda.Fill(dt);



                if (dt.Rows.Count == 1)
                {
                    User _user = new User()
                    {
                        Userid              = dt.Rows[0]["UserId"].ToString(),
                        Username            = dt.Rows[0]["Username"].ToString(),
                        EmployeeName        = dt.Rows[0]["EmployeeName"].ToString(),
                        EmployeeEmail       = dt.Rows[0]["EmployeeEmail"].ToString(),
                        EmployeeDesignation = dt.Rows[0]["EmployeeDesignation"].ToString(),
                        AllowInternet       = dt.Rows[0]["AllowInternetLogin"].ToString(),
                    };
                    user = _user;

                    if (InternetradioButton.Checked == true)
                    {
                        mm = new MainForm(user);

                        if (dt.Rows[0]["AllowInternetLogin"].ToString() == "1")
                        {
                            NotificationLabel.Text = "Welcome " + user.EmployeeName;


                            NotificationLabel.Show();

                            mm.WindowState = FormWindowState.Minimized;

                            mm.Show();

                            timer1.Start();
                        }
                        else
                        {
                            MessageBox.Show("You Are Not Allowed to Login via Internet", "Blocked", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        NotificationLabel.Text = "Welcome " + user.EmployeeName;


                        NotificationLabel.Show();
                        mm             = new MainForm(user);
                        mm.WindowState = FormWindowState.Minimized;

                        mm.Show();

                        timer1.Start();
                    }
                }
                else
                {
                    NotificationLabel.Text = "Login Faild";
                    NotificationLabel.Show();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }