UserInfo GetData(SqlCommand cmd)
 {
     cmd.Connection.Open();
     SqlDataReader reader = cmd.ExecuteReader();
     UserInfo ob = new UserInfo();
     using (reader)
     {
         while (reader.Read())
         {
             ob.Id = reader.GetInt32(0);
             ob.UserName = reader.GetString(1);
             ob.UserPassword = reader.GetString(2);
         }
         reader.Close();
     }
     cmd.Connection.Close();
     return ob;
 }
 public bool Insert(UserInfo obj)
 {
     SqlDBdataAccess da = new SqlDBdataAccess();
     SqlCommand cmd = da.GetCommand("insert into [dbo].[Lib_Users] ([User_Name],[User_Password],[Lib_Book_Issued_Id])" + "values(@Name,@Password,@Status)");
     SqlParameter p = new SqlParameter("@Name", SqlDbType.VarChar,50);
     p.Value = obj.UserName;
     SqlParameter p1 = new SqlParameter("@Password", SqlDbType.VarChar, 50);
     p1.Value = obj.UserPassword;
     SqlParameter p2 = new SqlParameter("@Status", SqlDbType.Int);
     p2.Value = obj.Status;
     cmd.Parameters.Add(p);
     cmd.Parameters.Add(p1);
     cmd.Parameters.Add(p2);
     cmd.Connection.Open();
     int val = cmd.ExecuteNonQuery();
     cmd.Connection.Close();
     return val > 0;
 }
        private void saveButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(userNameText.Text) || string.IsNullOrEmpty(changePasswordtextbox.Text) || string.IsNullOrEmpty(confirmPasswordtextbox.Text) || string.IsNullOrEmpty(newPasswordtextbox.Text))
            {
                MessageBox.Show("Provide All The Information", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);

            }
            else
            {
                UserInfo ob = new UserInfo();
                ob = sd.GetUserName(username);
                if (ob.UserName == username && ob.UserPassword == oldpassword && newpassword == newPasswordtextbox.Text && confirmpassword == confirmPasswordtextbox.Text)
                {
                    sd.ChangePassword(username, newpassword);
                    MessageBox.Show("Password Change Successfully");
                }
                else
                {
                    MessageBox.Show(" Username Or Password Does Not Match","Warning",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                }
            }
        }
        private void LoginButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(passwordTextbox.Text) || string.IsNullOrEmpty(userTextbox.Text))
            {
                MessageBox.Show("Enter Username Or Password", "Invalid operation", MessageBoxButtons.OK, MessageBoxIcon.Warning);

            }
            else
            {
                UserInfo ob = new UserInfo();
                ob = sd.GetUserName(username);
                if (ob.UserName == username && ob.UserPassword == password && ob.Status == 1)
                {
                    Action frm = new Action();
                    frm.Show();
                    this.Hide();

                }
                else if (ob.UserName == username && ob.UserPassword == password && ob.Status == 2)
                {
                    searchTeacher frm1 = new searchTeacher();
                    frm1.Show();
                    this.Hide();
                }
                else if (ob.UserName == username && ob.UserPassword == password && ob.Status == 3)
                {
                    searchStudent frm2 = new searchStudent();
                    frm2.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Invalid User Name Or Password", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }