Example #1
0
 private void Rp_newSale_Click(object sender, EventArgs e)
 {
     if (Priviladge.Contains("Admin"))
     {
         //You are in this page
     }
     else
     {
         //navigatin code
         NewSale newSale = new NewSale();
         newSale.Show();
         this.Width = 2;
     }
 }
        /// <summary>
        /// This function is to
        /// Check weather the username and the passwords match and
        /// if they match, login to the application
        /// if not show the message to the user.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_login_Click(object sender, EventArgs e)
        {
            //first check weather the input fields are not empoty
            if (TB_UserName.Text != null && TB_UserName.Text != null)
            {
                try
                {
                    //The sql quary for the validation
                    String LoginCheck = "SELECT * FROM Employee WHERE userName = '******' AND password='******' ";
                    //Initialice the adaptor
                    SqlDataAdapter LoginAdaptor = new SqlDataAdapter(LoginCheck, connection);
                    //the virtul table for store the data
                    DataTable userTb = new DataTable();
                    //fill the tabe with fetched data.
                    //for a valid login thismust be only 1rows.
                    LoginAdaptor.Fill(userTb);

                    if (userTb.Rows.Count == 1)
                    {
                        //Login Successfull
                        username  = userTb.Rows[0][0].ToString();
                        userpriv  = userTb.Rows[0][6].ToString();
                        CashiName = userTb.Rows[0][2].ToString().Replace(" ", "") + " " + userTb.Rows[0][3].ToString().Replace(" ", "");
                        Properties.Settings.Default.User        = username;
                        Properties.Settings.Default.PrivLevel   = userpriv;
                        Properties.Settings.Default.CashierName = CashiName;


                        NewSale newSale = new NewSale();
                        newSale.Show();
                        this.Hide();
                    }
                    else
                    {
                        //not a successfull login
                        MessageBox.Show("Incorrect UserName Or Password.\nIf you're not a registered user, Please use Gest Login or contact Administrator");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Login Error!\nContact Your IT Administrator\n Details : " + ex.Message, "Error");
                }
            }
        }