private void SearchBtn_Click(object sender, RoutedEventArgs e)
        {
            string UserId = UserIdTxtBx.Text;

            try
            {
                if (string.IsNullOrEmpty(UserId))
                {
                    MessageBox.Show(
                        messageBoxText: "Please enter valid Values.",
                        caption: "Error",
                        button: MessageBoxButton.OK,
                        MessageBoxImage.Error);
                    UserIdTxtBx.Focus();
                }
                else
                {
                    con.Open();
                    SqlCommand checkUser = new SqlCommand("SELECT COUNT(*) FROM Users WHERE Id= @Id", con);
                    checkUser.Parameters.AddWithValue("@Id", UserIdTxtBx.Text);
                    int BookExist = (int)checkUser.ExecuteScalar();

                    if (BookExist > 0)
                    {
                        SetValueForUserId = int.Parse(UserIdTxtBx.Text);
                        new EditMemberInformation().Show();
                        Close();
                    }
                    else
                    {
                        MessageBox.Show(
                            messageBoxText: "User Not Found!",
                            caption: "Error",
                            button: MessageBoxButton.OK,
                            MessageBoxImage.Error);
                    }
                }
            }
            catch (Exception b)
            {
                MessageBox.Show(
                    messageBoxText: "Exception occur :" + b.Message + "\t" + b.GetType(),
                    caption: "Exception",
                    button: MessageBoxButton.OK,
                    icon: MessageBoxImage.Error);
            }
        }
예제 #2
0
        private void BorrowBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string BookId = BookIdTxtBx.Text;
                string UserId = UserIdTxtBx.Text;

                if (string.IsNullOrEmpty(BookId) && string.IsNullOrEmpty(UserId) && ReturnDateDP.SelectedDate == null && DeadlineDateDp.SelectedDate == null)
                {
                    MessageBox.Show(
                        messageBoxText: "Please enter valid Values.",
                        caption: "Error",
                        button: MessageBoxButton.OK,
                        MessageBoxImage.Error);

                    BookIdTxtBx.Focus();
                    UserIdTxtBx.Focus();
                    ReturnDateDP.Focus();
                    DeadlineDateDp.Focus();
                }
                else
                {
                    con.Open();
                    cmd = new SqlCommand("INSERT INTO BorrowedBooks (BookId,UserId,ReturnDate,DeadLineDate,IssueDate) VALUES (@BookId,@UserId,@ReturnDate,@DeadLineDate,@IssueDate)", con);
                    cmd.Parameters.Add("@BookId", BookIdTxtBx.Text);
                    cmd.Parameters.Add("@UserId", UserIdTxtBx.Text);
                    cmd.Parameters.Add("@ReturnDate", ReturnDateDP.SelectedDate);
                    cmd.Parameters.Add("@DeadLineDate", DeadlineDateDp.SelectedDate);
                    cmd.Parameters.Add("@IssueDate", DateTime.Now);
                    cmd.ExecuteNonQuery();
                    MessageBox.Show(
                        messageBoxText: $"Book with Book Id : «{BookIdTxtBx.Text}» successfully Borrowed.",
                        caption: "Successful Adding",
                        button: MessageBoxButton.OK,
                        icon: MessageBoxImage.Information);
                    con.Close();
                }
            }
            catch (Exception b)
            {
                MessageBox.Show(
                    messageBoxText: "Exception occur :" + b.Message + "\t" + b.GetType(),
                    caption: "Exception",
                    button: MessageBoxButton.OK,
                    icon: MessageBoxImage.Error);
            }
        }
예제 #3
0
        private void BorrowBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string BookId = BookIdTxtBx.Text;
                string UserId = UserIdTxtBx.Text;


                if (string.IsNullOrEmpty(BookId) && string.IsNullOrEmpty(UserId))
                {
                    MessageBox.Show(
                        messageBoxText: "Please enter valid Values.",
                        caption: "Error",
                        button: MessageBoxButton.OK,
                        MessageBoxImage.Error);

                    BookIdTxtBx.Focus();
                    UserIdTxtBx.Focus();
                }
                else
                {
                    con.Open();
                    SqlCommand checkdata = new SqlCommand("SELECT COUNT(*) From BorrowedBooks WHERE BookId= @BookId and UserId=@UserId", con);
                    checkdata.Parameters.AddWithValue("@BookId", BookIdTxtBx.Text);
                    checkdata.Parameters.AddWithValue("@UserId", UserIdTxtBx.Text);
                    int BookExist = (int)checkdata.ExecuteScalar();
                    con.Close();
                    if (BookExist > 0)
                    {
                        con.Open();
                        cmd = new SqlCommand("Delete From BorrowedBooks Where BookId=@BookId and UserId=@UserId", con);

                        cmd.Parameters.AddWithValue("@BookId", BookIdTxtBx.Text);
                        cmd.Parameters.AddWithValue("@UserId", UserIdTxtBx.Text);

                        int deleted = cmd.ExecuteNonQuery();
                        MessageBox.Show(
                            messageBoxText: $"The Book successfully Borrowed Back",
                            caption: "Successful",
                            button: MessageBoxButton.OK,
                            icon: MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show(
                            messageBoxText: "the enterd record not Found.",
                            caption: "Error",
                            button: MessageBoxButton.OK,
                            MessageBoxImage.Error);
                    }
                }
            }
            catch (Exception b)
            {
                MessageBox.Show(
                    messageBoxText: "Exception occur :" + b.Message + "\t" + b.GetType(),
                    caption: "Exception",
                    button: MessageBoxButton.OK,
                    icon: MessageBoxImage.Error);
            }
        }