示例#1
0
        private void addTransaction()
        {
            BookTransaction bt = new BookTransaction();

            bt.DateIssue       = DateTime.Today.Date;
            bt.OriginalDateDue = DateTime.Today.AddDays(21).Date;
            bt.MemberID        = memberID;
            context.BookTransactions.Add(bt);
            context.SaveChanges();
            B.transactionNo = bt.TransactionID;
        }
示例#2
0
        private void ExtendButton_Click(object sender, EventArgs e)
        {
            DateTime datedue = Convert.ToDateTime(dataGridView1.CurrentRow.Cells[3].Value.ToString());
            int      TrID    = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value.ToString());
            int      BID     = Convert.ToInt32(dataGridView1.CurrentRow.Cells[1].Value.ToString());

            context = new LibrarySevenAEntities();
            var             QBT = context.BookTransactions.Where(x => x.TransactionID == TrID);
            BookTransaction bk  = QBT.First();

            if (bk.OriginalDateDue == datedue)
            {
                var             QBTD = context.BookTransDetails.Where(x => x.TransactionID == TrID && x.BookID == BID);
                BookTransDetail btd  = QBTD.First();
                btd.DateDue = datedue.AddDays(21);
                context.SaveChanges();
                //refresh
                context = new LibrarySevenAEntities();
                List <BookTransaction> lbt = new List <BookTransaction>();
                lbt = context.BookTransactions.Where(x => x.MemberID == memberID).ToList();
                if (lbt.Count > 0)
                {
                    List <object> lbtd = new List <object>();

                    for (int i = 0; i < lbt.Count; i++)
                    {
                        int temp = Convert.ToInt32(lbt[i].TransactionID.ToString());
                        var q    = from x in context.BookTransDetails
                                   where x.TransactionID == temp && x.RentalStatus == false
                                   select new { x.TransactionID, x.BookID, x.book.BookTitle, x.DateDue };
                        if (q.ToList().Count > 0)
                        {
                            object bktd = q.ToList().First();
                            lbtd.Add(bktd);
                        }
                    }
                    dataGridView1.DataSource = lbtd;
                    this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                }
            }
            else
            {
                MessageBox.Show("Unable to extend, this book has previously been extended");
            }
        }
 private void SearchButton_Click(object sender, EventArgs e)
 {
     try
     {
         context = new LibrarySevenAEntities();
         if (TransactionIDTextBox.Text != "")
         {
             int j = Convert.ToInt32(TransactionIDTextBox.Text);
             var q = context.BookTransactions.Where(x => x.TransactionID == j);
             dataGridView1.DataSource               = q.ToList();
             dataGridView1.Columns[4].Visible       = false;
             dataGridView1.Columns[5].Visible       = false;
             this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
         }
         else
         {
             if (BookIDTextBox.Text == "")
             {
                 if (MemberIDTextBox.Text == "")
                 {
                     var q = context.BookTransactions;
                     dataGridView1.DataSource               = q.ToList();
                     dataGridView1.Columns[4].Visible       = false;
                     dataGridView1.Columns[5].Visible       = false;
                     this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                 }
                 else if (MemberIDTextBox.Text != "")
                 {
                     short j = Convert.ToInt16(MemberIDTextBox.Text);
                     var   q = context.BookTransactions.Where(x => x.MemberID == j);
                     dataGridView1.DataSource               = q.ToList();
                     dataGridView1.Columns[4].Visible       = false;
                     dataGridView1.Columns[5].Visible       = false;
                     this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                 }
             }
             else
             {
                 List <BookTransDetail> LBTD = new List <BookTransDetail>();
                 int w = Convert.ToInt32(BookIDTextBox.Text);
                 LBTD = context.BookTransDetails.Where(x => x.BookID == w).ToList();
                 if (LBTD.Count > 0)
                 {
                     List <BookTransaction> LBKT = new List <BookTransaction>();
                     if (MemberIDTextBox.Text == "")
                     {
                         for (int i = 0; i < LBTD.Count; i++)
                         {
                             int             temp = Convert.ToInt32(LBTD[i].TransactionID.ToString());
                             var             q    = context.BookTransactions.Where(x => x.TransactionID == temp);
                             BookTransaction bkt  = q.ToList().First();
                             LBKT.Add(bkt);
                         }
                     }
                     else
                     {
                         for (int i = 0; i < LBTD.Count; i++)
                         {
                             int temp = Convert.ToInt32(LBTD[i].TransactionID.ToString());
                             int j    = Convert.ToInt16(MemberIDTextBox.Text);
                             var q    = context.BookTransactions.Where(x => x.TransactionID == temp &&
                                                                       x.MemberID == j);
                             if (q.ToList().Count > 0)
                             {
                                 BookTransaction bkt = q.ToList().First();
                                 LBKT.Add(bkt);
                             }
                         }
                     }
                     dataGridView1.DataSource               = LBKT;
                     dataGridView1.Columns[4].Visible       = false;
                     dataGridView1.Columns[5].Visible       = false;
                     this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         if (ex is FormatException || ex is InvalidOperationException)
         {
             lblInputError.Text = "Incorrect Input, please check your search values";
             return;
         }
     }
 }