Beispiel #1
0
        private void SaveBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string FirstName   = FirstNameTxtBx.Text;
                string LastName    = LastNameTxtBx.Text;
                string Gender      = GenderCmBx.Text;
                string Email       = EmailTxtBx.Text;
                string Username    = UsernameTxtBx.Text;
                string PhoneNumber = PhoneNumberTxtBx.Text;
                string Password    = PasswordTxtBx.Password;
                string Education   = EducationTxtBx.Text;
                string BirthDate   = BirthDateDP.Text;

                if (string.IsNullOrEmpty(FirstName) && string.IsNullOrEmpty(LastName) && string.IsNullOrEmpty(Email) && string.IsNullOrEmpty(Username) && string.IsNullOrEmpty(PhoneNumber) && string.IsNullOrEmpty(Password) && string.IsNullOrEmpty(Education) && string.IsNullOrEmpty(BirthDate) && GenderCmBx.SelectedIndex == -1)
                {
                    MessageBox.Show(
                        messageBoxText: "Please enter valid Values.",
                        caption: "Error",
                        button: MessageBoxButton.OK,
                        MessageBoxImage.Error);

                    FirstNameTxtBx.Focus();
                    LastNameTxtBx.Focus();
                    GenderCmBx.Focus();
                    EmailTxtBx.Focus();
                    UsernameTxtBx.Focus();
                    PhoneNumberTxtBx.Focus();
                    PasswordTxtBx.Focus();
                    EducationTxtBx.Focus();
                    BirthDateDP.Focus();
                }
                else
                {
                    con.Open();
                    cmd = new SqlCommand("Update Users Set FirstName=@FirstName , LastName=@LastName , Gender=@Gender , Email=@Email , Username=@Username , PhoneNumber=@PhoneNumber , Password=@Password , Education=@Education , BirthDate=@BirthDate  where Id ='" + MemberDashboard.SetValueForUserId + "'", con);
                    cmd.Parameters.Add("@FirstName", FirstNameTxtBx.Text);
                    cmd.Parameters.Add("@LastName", LastNameTxtBx.Text);
                    cmd.Parameters.Add("@Gender", GenderCmBx.Text);
                    cmd.Parameters.Add("@Email", EmailTxtBx.Text);
                    cmd.Parameters.Add("@Username", UsernameTxtBx.Text);
                    cmd.Parameters.Add("@PhoneNumber", PhoneNumberTxtBx.Text);
                    cmd.Parameters.Add("@Education", EducationTxtBx.Text);
                    cmd.Parameters.Add("@Password", PasswordTxtBx.Password);
                    cmd.Parameters.Add("@BirthDate", BirthDateDP.SelectedDate);

                    cmd.ExecuteNonQuery();
                    MessageBox.Show(
                        messageBoxText: $"Information of User «{FirstNameTxtBx.Text + LastNameTxtBx.Text}»  Successfully Updated",
                        caption: "Successful Update",
                        button: MessageBoxButton.OK,
                        icon: MessageBoxImage.Information);
                    con.Close();
                }
            }
            catch (Exception b)
            {
                MessageBox.Show("Exception occur while Updating table:" + b.Message + "\t" + b.GetType());
            }
        }
Beispiel #2
0
        private void RemoveMemberBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string FirstName   = FirstNameTxtBx.Text;
                string LastName    = LastNameTxtBx.Text;
                string Gender      = GenderCmBx.Text;
                string Email       = EmailTxtBx.Text;
                string Username    = UsernameTxtBx.Text;
                string PhoneNumber = PhoneNumberTxtBx.Text;
                string Password    = PasswordTxtBx.Password;
                string Education   = EducationTxtBx.Text;
                string BirthDate   = BirthDateDP.Text;

                if (string.IsNullOrEmpty(FirstName) && string.IsNullOrEmpty(LastName) && string.IsNullOrEmpty(Email) && string.IsNullOrEmpty(Username) && string.IsNullOrEmpty(PhoneNumber) && string.IsNullOrEmpty(Password) && string.IsNullOrEmpty(Education) && string.IsNullOrEmpty(BirthDate) && GenderCmBx.SelectedIndex == -1)
                {
                    MessageBox.Show(
                        messageBoxText: "Please enter valid Values.",
                        caption: "Error",
                        button: MessageBoxButton.OK,
                        MessageBoxImage.Error);

                    FirstNameTxtBx.Focus();
                    LastNameTxtBx.Focus();
                    GenderCmBx.Focus();
                    EmailTxtBx.Focus();
                    UsernameTxtBx.Focus();
                    PhoneNumberTxtBx.Focus();
                    PasswordTxtBx.Focus();
                    EducationTxtBx.Focus();
                    BirthDateDP.Focus();
                }

                else
                {
                    con.Open();
                    cmd = new SqlCommand("Delete From Users Where FirstName=@FirstName and LastName=@LastName and Gender=@Gender and Email=@Email and Username=@Username and PhoneNumber=@PhoneNumber and Password=@Password and Education=@Education and BirthDate=@BirthDate", con);

                    cmd.Parameters.AddWithValue("@FirstName", FirstNameTxtBx.Text);
                    cmd.Parameters.AddWithValue("@LastName", LastNameTxtBx.Text);
                    cmd.Parameters.AddWithValue("@Gender", GenderCmBx.Text);
                    cmd.Parameters.AddWithValue("@Email", EmailTxtBx.Text);
                    cmd.Parameters.AddWithValue("@Username", UsernameTxtBx.Text);
                    cmd.Parameters.AddWithValue("@PhoneNumber", PhoneNumberTxtBx.Text);
                    cmd.Parameters.AddWithValue("@Password", PasswordTxtBx.Password);
                    cmd.Parameters.AddWithValue("@Education", EducationTxtBx.Text);
                    cmd.Parameters.AddWithValue("@BirthDate", BirthDateDP.Text);
                    int deleted = cmd.ExecuteNonQuery();
                    MessageBox.Show(
                        messageBoxText: $"User «{FirstNameTxtBx.Text + LastNameTxtBx.Text}» Successfully Removed",
                        caption: "Successful Removing",
                        button: MessageBoxButton.OK,
                        icon: MessageBoxImage.Information);
                    new SearchEditMemberInformation().Show();
                    Close();
                }
            }

            catch (Exception b)
            {
                MessageBox.Show(
                    messageBoxText: "Exception occur :" + b.Message + "\t" + b.GetType(),
                    caption: "Exception",
                    button: MessageBoxButton.OK,
                    icon: MessageBoxImage.Error);
            }
        }
Beispiel #3
0
        private void SignUpBtn_Click(object sender, RoutedEventArgs e)
        {
            string FirstName   = FirstNameTxtBx.Text;
            string LastName    = LastNameTxtBx.Text;
            string Email       = EmailTxtBx.Text;
            string Username    = UsernameTxtBx.Text;
            string PhoneNumber = PhoneNumberTxtBx.Text;
            string Password    = PasswordTxtBx.Password;
            string Education   = EducationTxtBx.Text;
            string BirthDate   = BirthDateDP.Text;

            try
            {
                if (MainWindow.Librarian == true)
                {
                    if (string.IsNullOrEmpty(FirstName) && string.IsNullOrEmpty(LastName) && string.IsNullOrEmpty(Email) && string.IsNullOrEmpty(Username) && string.IsNullOrEmpty(PhoneNumber) && string.IsNullOrEmpty(Password) && string.IsNullOrEmpty(Education) && BirthDateDP.SelectedDate == null && GenderCmBx.SelectedIndex == -1)
                    {
                        MessageBox.Show(
                            messageBoxText: "Please enter valid Values.",
                            caption: "Error",
                            button: MessageBoxButton.OK,
                            MessageBoxImage.Error);

                        FirstNameTxtBx.Focus();
                        LastNameTxtBx.Focus();
                        GenderCmBx.Focus();
                        EmailTxtBx.Focus();
                        UsernameTxtBx.Focus();
                        PhoneNumberTxtBx.Focus();
                        PasswordTxtBx.Focus();
                        EducationTxtBx.Focus();
                        BirthDateDP.Focus();
                    }
                    else
                    {
                        con.Open();
                        cmd = new SqlCommand("INSERT INTO Admins (FirstName,LastName,Gender,Email,Username,PhoneNumber,Password,BirthDate,RegisterDate,Education) VALUES (@FirstName,@LastName,@Gender,@Email,@Username,@PhoneNumber,@Password,@BirthDate,@RegisterDate,@Education)", con);
                        cmd.Parameters.Add("@FirstName", FirstNameTxtBx.Text);
                        cmd.Parameters.Add("@LastName", LastNameTxtBx.Text);
                        cmd.Parameters.Add("@Gender", GenderCmBx.Text);
                        cmd.Parameters.Add("@Email", EmailTxtBx.Text);
                        cmd.Parameters.Add("@Username", UsernameTxtBx.Text);
                        cmd.Parameters.Add("@PhoneNumber", PhoneNumberTxtBx.Text);
                        cmd.Parameters.Add("@Password", PasswordTxtBx.Password);
                        cmd.Parameters.Add("@BirthDate", BirthDateDP.SelectedDate);
                        cmd.Parameters.Add("@RegisterDate", DateTime.Now);
                        cmd.Parameters.Add("@Education", EducationTxtBx.Text);
                        cmd.ExecuteNonQuery();
                        MessageBox.Show(
                            messageBoxText: $"Librarain «{FirstNameTxtBx.Text + LastNameTxtBx.Text}» successfully Added.",
                            caption: "Successful Adding",
                            button: MessageBoxButton.OK,
                            icon: MessageBoxImage.Information);
                        con.Close();
                        new LibrarianLoginPage().Show();
                        Close();
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(FirstNameTxtBx.Text) && string.IsNullOrEmpty(LastName) && string.IsNullOrEmpty(Email) && string.IsNullOrEmpty(Username) && string.IsNullOrEmpty(PhoneNumber) && string.IsNullOrEmpty(Password) && string.IsNullOrEmpty(Education) && string.IsNullOrEmpty(BirthDate) && GenderCmBx.SelectedIndex == -1)
                    {
                        MessageBox.Show(
                            messageBoxText: "Please enter valid Values.",
                            caption: "Error",
                            button: MessageBoxButton.OK,
                            MessageBoxImage.Error);

                        FirstNameTxtBx.Focus();
                        LastNameTxtBx.Focus();
                        GenderCmBx.Focus();
                        EmailTxtBx.Focus();
                        UsernameTxtBx.Focus();
                        PhoneNumberTxtBx.Focus();
                        PasswordTxtBx.Focus();
                        EducationTxtBx.Focus();
                        BirthDateDP.Focus();
                    }
                    else
                    {
                        con.Open();
                        cmd = new SqlCommand("INSERT INTO Users (FirstName,LastName,Gender,Email,Username,PhoneNumber,Password,BirthDate,RegisterDate,Education) VALUES (@FirstName,@LastName,@Gender,@Email,@Username,@PhoneNumber,@Password,@BirthDate,@RegisterDate,@Education)", con);
                        cmd.Parameters.Add("@FirstName", FirstNameTxtBx.Text);
                        cmd.Parameters.Add("@LastName", LastNameTxtBx.Text);
                        cmd.Parameters.Add("@Gender", GenderCmBx.Text);
                        cmd.Parameters.Add("@Email", EmailTxtBx.Text);
                        cmd.Parameters.Add("@Username", UsernameTxtBx.Text);
                        cmd.Parameters.Add("@PhoneNumber", PhoneNumberTxtBx.Text);
                        cmd.Parameters.Add("@Password", PasswordTxtBx.Password);
                        cmd.Parameters.Add("@BirthDate", BirthDateDP.SelectedDate);
                        cmd.Parameters.Add("@RegisterDate", DateTime.Now);
                        cmd.Parameters.Add("@Education", EducationTxtBx.Text);
                        cmd.ExecuteNonQuery();
                        MessageBox.Show(
                            messageBoxText: $"User «{FirstNameTxtBx.Text + LastNameTxtBx.Text}» Successfully Added.",
                            caption: "Successful Adding",
                            button: MessageBoxButton.OK,
                            icon: MessageBoxImage.Information);
                        con.Close();
                        new MemberLoginPage().Show();
                        Close();
                    }
                }
            }
            catch (Exception b)
            {
                MessageBox.Show(
                    messageBoxText: "Exception occur :" + b.Message + "\t" + b.GetType(),
                    caption: "Exception",
                    button: MessageBoxButton.OK,
                    icon: MessageBoxImage.Error);
            }
        }