Пример #1
0
        //public void btnLogin_Click(object sender, EventArgs e)
        // {
        //     SignInn(cboUsername.SelectedItem.ToString(), txtPassword.Text);
        //     notifyIcon1.Visible = true;
        //     notifyIcon1.ShowBalloonTip(5000, "Happy Birthday", "King Bar Beque App wishes you a happy birthday", ToolTipIcon.Info);
        // }

        //LOGIN
        void SignInn(string Usernames, string Password)
        {
            try
            {
                DateTime currDate = DateTime.Now;
                DateTime addDat;

                _entities = new KBBQEntities();
                var data = _entities.Users.Where(x => x.Uname == Usernames && x.Pass == Password).FirstOrDefault();

                if (data != null)
                {
                    addDat = data.cdate.Value.AddDays(10);

                    if (currDate.Date == addDat.Date)
                    {
                        MessageBox.Show("Your system need to be upgraded as all the test is successfully done. Contact your technical administrator for more information.", "Upgradation Info - King Bar beque Restaurant Logins", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        return;
                    }
                }

                SqlConnection con = new SqlConnection(varinsert.dbPath);

                string     sql = "select Uname,Pass,privileges from Users where Uname=@Uname and Pass=@Pass";
                SqlCommand cmd = new SqlCommand(sql, con);
                con.Open();
                DataSet        ds    = new DataSet();
                SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                cmd.Parameters.AddWithValue("@Uname", Usernames.Trim());
                cmd.Parameters.AddWithValue("@Pass", Password.Trim());
                adapt.Fill(ds);
                con.Close();
                int count = ds.Tables[0].Rows.Count;

                //If count is equal to 1, meaning if found=true, then show frmMain form
                if (count == 1)
                {
                    string    privel       = getPrivilege();
                    frmParent frmdashboard = new frmParent();
                    //username,login date,login time, logout date, logout time

                    insertClass.insertToLogHistory(cboUsername.SelectedItem.ToString(), day, day, day, day);

                    int getLogID = 0;
                    int lab;
                    lab = selectClass.callMaxLogHistoryAndEmployee(cboUsername.SelectedItem.ToString(), getLogID);

                    /*
                     * Disable some button based on certain privileges the user has
                     * if user is assigned Administrator he/she  has all button enable at his/her disposal
                     * but in the case where he/she has a privilege called users certain buttons will be greyed out
                     * meaning he/she can't perform certain operation
                     */
                    if (privel.Equals("Users"))
                    {
                        //frmdashboard.btnRegEmployee.Enabled = false;
                        //frmdashboard.btnAddUsers.Enabled = false;
                        //frmdashboard.btnCuurency.Enabled = false;
                        //frmdashboard.btnAddPOSCurrency.Enabled = false;
                        //frmdashboard.btnAddMenuGroup.Enabled = false;
                        //frmdashboard.btnAddMenus.Enabled = false;
                        //frmdashboard.btnVEmployee.Enabled = false;
                        //frmdashboard.btnVUsers.Enabled = false;
                        //frmdashboard.button9.Enabled = false;
                        //frmdashboard.button11.Enabled = false;
                        //frmdashboard.btnBakup.Enabled = false;
                    }

                    frmdashboard.statGetUser.Text = cboUsername.SelectedItem.ToString();
                    frmdashboard.getLogNum        = lab;

                    this.Hide();
                    frmdashboard.ShowDialog();
                    txtPassword.Clear();
                    txtPassword.Text = "•••••••";
                    txtPassword.Select();
                    selectClass.selectUsers(cboUsername);
                    this.Show();
                }

                else
                {
                    MessageBox.Show("Invalid Username or Password", "Error - King Bar beque Restaurant Logins", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error - Throwing Exceptions");
            }
        }
Пример #2
0
        //LOGIN
        void Logins(string Usernames, string Password)
        {
            try
            {
                SqlConnection con = new SqlConnection(varinsert.dbPath);

                string     sql = "select Uname,Pass,privileges from Users where Uname=@Uname and Pass=@Pass";
                SqlCommand cmd = new SqlCommand(sql, con);
                con.Open();
                DataSet        ds    = new DataSet();
                SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                cmd.Parameters.AddWithValue("@Uname", Usernames.Trim());
                cmd.Parameters.AddWithValue("@Pass", Password.Trim());
                adapt.Fill(ds);
                con.Close();
                int count = ds.Tables[0].Rows.Count;

                //If count is equal to 1, meaning if found=true, then show frmMain form
                if (count == 1)
                {
                    string    privel = getPrivilege();
                    frmParent parent = new frmParent();
                    //username,login date,login time, logout date, logout time

                    insertClass.insertToLogHistory(cboUsername.SelectedItem.ToString(), day, day, day, day);

                    int getLogID = 0;
                    int lab;
                    lab = selectClass.callMaxLogHistoryAndEmployee(cboUsername.SelectedItem.ToString(), getLogID);

                    /*
                     * Disable some button based on certain privileges the user has
                     * if user is assigned Administrator he/she  has all button enable at his/her disposal
                     * but in the case where he/she has a privilege called users certain buttons will be greyed out
                     * meaning he/she can't perform certain operation
                     */
                    if (privel.Equals("Users"))
                    {
                        parent.btnRegEmployee.Enabled    = false;
                        parent.btnAddUsers.Enabled       = false;
                        parent.btnCuurency.Enabled       = false;
                        parent.btnAddPOSCurrency.Enabled = false;
                        parent.btnAddMenuGroup.Enabled   = false;
                        parent.btnAddMenus.Enabled       = false;
                        parent.btnVEmployee.Enabled      = false;
                        parent.btnVUsers.Enabled         = false;
                        parent.button9.Enabled           = false;
                        parent.button11.Enabled          = false;
                        parent.btnBakup.Enabled          = false;
                    }

                    parent.statGetUser.Text = cboUsername.SelectedItem.ToString();
                    parent.getLogNum        = lab;
                    this.Hide();
                    parent.ShowDialog();
                    txtPass.Clear();
                    txtPass.Text = "•••••••";
                    txtPass.Select();
                    this.Show();
                }

                else
                {
                    MessageBox.Show("Invalid Username or Password", "Error - King Bar Beque Restaurant Logins", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error - Throwing Exceptions");
            }
        }