예제 #1
0
        private void PayFineButton_Click(object sender, RoutedEventArgs e)
        {
            var  bookIssues = new BookIssues();
            Fine fine       = new Fine();

            bookIssues.MemberCardNo = int.Parse(MembercardnoComboBox.Text);
            bookIssues.BookID       = BookIDTextBox.Text;

            bookIssues.BookName   = BookNameTextBox.Text;
            bookIssues.MemberName = MembernameTextBox.Text;

            bookIssues.DateIssues = BookissuesDatePicker.Text;
            bookIssues.DateExpiry = BookexpiryDatePicker.Text;

            fine.today  = DateTime.Today.ToString();
            fine.amount = FineAmountTextBox.Text;


            int totalbooks = Counttotalbooks() + 1;

            //string ConnectionString = @"Server=.\SQLEXPRESS;Database=Library;Integrated Security=True";

            //string query = string.Format("update book set b_noofbooks ='" + totalbooks + "' where b_id ='" + BookIDComboBox.Text + "'");

            string query = string.Format("update book set b_noofbooks ='" + totalbooks + "' where b_id ='" + BookIDTextBox.Text + "'");

            string query1 = string.Format("delete  from returnbook where r_mcardno='" + MembercardnoComboBox.SelectedItem + "'");

            string query2 = string.Format("insert into finebook values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')",
                                          bookIssues.MemberCardNo, bookIssues.MemberName, bookIssues.BookID, bookIssues.BookName, bookIssues.DateIssues,
                                          bookIssues.DateExpiry, fine.today, fine.amount);


            SqlConnection connection = new SqlConnection(ConnectionString);

            try
            {
                connection.Open();
                SqlCommand cmd  = new SqlCommand(query, connection);
                SqlCommand cmd1 = new SqlCommand(query1, connection);
                SqlCommand cmd2 = new SqlCommand(query2, connection);
                cmd.ExecuteNonQuery();
                cmd1.ExecuteNonQuery();
                cmd2.ExecuteNonQuery();

                MessageBox.Show(" thank you!!! You paid the accumulate fine.\n Book is updated and cleared from returning!!");
                connection.Close();

                MembernameTextBox.Text = "";
                BookIDTextBox.Text     = "";
                BookNameTextBox.Text   = "";
                FineAmountTextBox.Text = "";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void IssueButton_Click(object sender, RoutedEventArgs e)
        {
            var bookIssues = new BookIssues();

            bookIssues.MemberCardNo = int.Parse(MembercardnoComboBox.Text);
            bookIssues.BookID       = BookIDComboBox.Text;

            bookIssues.BookName   = BookNameTextBox.Text;
            bookIssues.MemberName = MembernameTextBox.Text;

            bookIssues.DateIssues = BookissuesDatePicker.Text;
            bookIssues.DateExpiry = BookexpiryDatePicker.Text;

            int totalbooks = Counttotalbooks() - 1;

            if (CheckMemberCardno() != bookIssues.MemberCardNo)
            {
                if (totalbooks <= 0)
                {
                    MessageBox.Show("Sorry,U can't have this book because it is confiend copy.");
                    Clear();
                }
                else
                {
                    //string ConnectionString = @"Server=.\SQLEXPRESS;Database=Library;Integrated Security=True";

                    string query = string.Format("insert into issuesbook values('{0}','{1}','{2}','{3}','{4}','{5}')",
                                                 bookIssues.MemberCardNo, bookIssues.MemberName, bookIssues.BookID, bookIssues.BookName, bookIssues.DateIssues,
                                                 bookIssues.DateExpiry);

                    string query1 =
                        string.Format("update book set b_noofbooks='" + totalbooks + "' where b_id='" +
                                      BookIDComboBox.Text + "'");

                    string query2 = string.Format("insert into returnbook values('{0}','{1}','{2}','{3}','{4}','{5}')",
                                                  bookIssues.MemberCardNo, bookIssues.MemberName, bookIssues.BookID, bookIssues.BookName, bookIssues.DateIssues,
                                                  bookIssues.DateExpiry);

                    SqlConnection connection = new SqlConnection(ConnectionString);

                    try
                    {
                        connection.Open();
                        SqlCommand cmd  = new SqlCommand(query, connection);
                        SqlCommand cmd1 = new SqlCommand(query1, connection);
                        SqlCommand cmd2 = new SqlCommand(query2, connection);
                        cmd.ExecuteNonQuery();
                        cmd1.ExecuteNonQuery();
                        cmd2.ExecuteNonQuery();
                        MessageBox.Show("Thank you!!!! for issuing book \n Data is inserted Successfully and Book is updated!!");
                        connection.Close();
                        Clear();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }

            else
            {
                MessageBox.Show("First, return your last borrowed book !!");
                Clear();
            }
        }