public Boolean addNewUser(user User)
 {
     UserDataAccess uda1 = new UserDataAccess();
     int result = uda1.insertUser(User);
     if (result.Equals(1))
         return true;
     else
         return false;
 }
 public Boolean authenticateUser(user User)
 {
     UserDataAccess uda1 = new UserDataAccess();
     user tmpAuthenticatedUser = uda1.getAuthenticatedUser(User.UserName, User.Password);
     if (User.UserName == tmpAuthenticatedUser.UserName && User.Password == tmpAuthenticatedUser.Password)
     {
         wrapperDataBuffer.WrapperObject.User1 = tmpAuthenticatedUser;
         return true;
     }
     else
     {
         return false;
     }
 }
Esempio n. 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            String userName = ((txtUsrname.Text).Clone().ToString()).Replace(" ", string.Empty);
            String password = (txtPwrd.Text).Clone().ToString();

            if (userName == "" && password == "")
            {
                usernameVerifyMessage.Show();
                passwordVerifyMessage.Show();
                hideLabels();
            }
            else if (userName == "")
            {
                usernameVerifyMessage.Show();
                hideLabels();
            }
            else if (password == "")
            {
                passwordVerifyMessage.Show();
                hideLabels();
            }
            else
            {
                user User = new user(userName, -1, password, null, null, null, null, null);
                userDataManipulations userDataManipulations = new userDataManipulations();
                Boolean userValidity = userDataManipulations.authenticateUser(User);

                if (userValidity)
                {
                    wrapperDataBuffer.WrapperObject.Flag = 0;
                    MainMenuAdmin newMainMenuAdmin = new MainMenuAdmin();
                    newMainMenuAdmin.Show();
                    this.Hide();
                }
                else
                {
                    loginVerifyMessage.Show();
                    hideLabels();
                }
            }
        }
        public user getUsrByUsrname(String username)
        {
            user tempUser = new user();
            try
            {
                using (SqlConnection con = new SqlConnection(conString))
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand("SearchUser", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@username", username);

                    using (SqlDataReader rdr = cmd.ExecuteReader())
                    {

                        while (rdr.Read())
                        {
                            if (!rdr[0].ToString().Equals("0"))
                            {
                                tempUser.UserName = (String)rdr["username"];
                                tempUser.FName = (String)rdr["f_Name"];
                                tempUser.LName = (String)rdr["l_Name"];
                                tempUser.Address = (String)rdr["address"];
                                tempUser.Telephone = (String)rdr["tel"];
                                tempUser.Nic = (String)rdr["nic"];
                                tempUser.Role = (int)rdr["role"];
                                tempUser.Password = (String)rdr["password"];
                            }
                        }
                    }
                    con.Close();
                }
            }
            catch (Exception e)
            {
            }
            return tempUser;
        }
        //get User by Username and Password
        public user getAuthenticatedUser(String username, String password)
        {
            user tempUser = new user();
            try
            {
                using (SqlConnection con = new SqlConnection(conString))
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand("GetUser", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@username", username);
                    cmd.Parameters.AddWithValue("@password", password);

                    using (SqlDataReader rdr = cmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            tempUser.UserName = (String)rdr["username"];
                            tempUser.FName = (String)rdr["f_Name"];
                            tempUser.LName = (String)rdr["l_Name"];
                            tempUser.Address = (String)rdr["address"];
                            tempUser.Telephone = (String)rdr["tel"];
                            tempUser.Nic = (String)rdr["nic"];
                            tempUser.Role = (int)rdr["role"];
                            tempUser.Password = (String)rdr["password"];
                        }
                    }
                    con.Close();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error Message" + e.Message);
            }
            return tempUser;
        }
Esempio n. 6
0
        private void btnAddService_Click(object sender, EventArgs e)
        {
            String fName = ((txtFname.Text).Replace(" ", string.Empty)).Clone().ToString();
            String lName = ((txtLname.Text).Replace(" ", string.Empty)).Clone().ToString();
            String nic = ((txtNIC.Text).Replace(" ", string.Empty)).Clone().ToString();
            String role = ((txtRole.Text).Replace(" ", string.Empty)).Clone().ToString();
            String usName = ((userName.Text).Replace(" ", string.Empty)).Clone().ToString();

            if (fName == "")
            {
                fnameVerify.Show();
                hideLabelsTimer();
            }
            else if (lName == "")
            {
                lnameVerify.Show();
                hideLabelsTimer();
            }
            else if (usName == "")
            {
                userNameVerify.Show();
                hideLabelsTimer();
            }
            else if (nic == "")
            {
                nicVerify.Show();
                hideLabelsTimer();
            }
            else if (role == "")
            {
                roleVerify.Show();
                hideLabelsTimer();
            }
            else if (password.Text == "")
            {
                passwordVerify.Show();
                hideLabelsTimer();
            }
            else
            {
                String uName = (userName.Text).Clone().ToString();
                int urole = ((KeyValuePair<int, string>)txtRole.SelectedItem).Key;
                String uPword = (password.Text).Clone().ToString();
                String uFName = (txtFname.Text).Clone().ToString();
                String uLName = (txtLname.Text).Clone().ToString();
                String uAddress = (txtAddress.Text).Clone().ToString();
                String uTel = (txtTel.Text).Clone().ToString();
                String uLNic = (txtNIC.Text).Clone().ToString();
                userDataManipulations userDataManipulations = new userDataManipulations();
                if (!(userDataManipulations.validateUserName(uName)))
                {
                    user newUser = new user(uName, urole, uPword, uFName, uLName, uAddress, uTel, uLNic);
                    Boolean userInsertionFlag = userDataManipulations.addNewUser(newUser);
                    if (userInsertionFlag)
                    {
                        userInsertionSuccessMsg.Show();
                        hideLabelsTimer();
                    }
                    else
                    {
                        userInsertFailureMsg.Show();
                        hideLabelsTimer();
                    }
                }
                else
                {
                    userNameVerify.Show();
                }

            }
        }
 public int insertUser(user tempUser)
 {
     int result = 1;
     try
     {
         using (SqlConnection con = new SqlConnection(conString))
         {
             con.Open();
             SqlCommand cmd = new SqlCommand("InsertUsers", con);
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.AddWithValue("@username", tempUser.UserName);
             cmd.Parameters.AddWithValue("@f_Name", tempUser.FName);
             cmd.Parameters.AddWithValue("@l_Name", tempUser.LName);
             cmd.Parameters.AddWithValue("@address", tempUser.Address);
             cmd.Parameters.AddWithValue("@tel", tempUser.Telephone);
             cmd.Parameters.AddWithValue("@nic", tempUser.Nic);
             cmd.Parameters.AddWithValue("@role", tempUser.Role);
             cmd.Parameters.AddWithValue("@password", tempUser.Password);
             result = (Int32)cmd.ExecuteScalar();
             con.Close();
         }
     }
     catch (Exception e)
     {
         result = 0;
     }
     return result;
 }