Пример #1
0
        private void btnReturn_Click(object sender, EventArgs e)
        {
            Int32 selectedRowCount = dataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected);

            if (selectedRowCount > 0)
            {
                foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                {
                    int         bookID = Convert.ToInt32(row.Cells[1].Value);
                    BooksDetail bd     = ctx.BooksDetails.Where(x => x.BookID == bookID).First();
                    bd.NumberLoaned = Convert.ToInt16(bd.NumberLoaned - 1);

                    int             transactionID = Convert.ToInt32(row.Cells[0].Value);
                    LoanTransDetail loanTran      = ctx.LoanTransDetails.Where(x => x.BookID == bookID && x.TransactionID == transactionID).First();
                    loanTran.LoanStatus       = "In";
                    loanTran.DateActualReturn = DateTime.Now;
                    ctx.SaveChanges();
                    dataGridView1.Rows.RemoveAt(row.Index);
                }
            }

            toolStripStatusLabel1.Text = "Successfully Updated.";
        }
Пример #2
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            using (TransactionScope ts = new TransactionScope())
            {
                LoanRecord rec = new LoanRecord();
                rec.MemberID   = Convert.ToInt32(txtMemberID.Text);
                this.memberID  = rec.MemberID;
                rec.DateIssue  = dtpDateIssue.Value;
                this.dateIssue = dtpDateIssue.Value;
                rec.DateDue    = dtpDueDate.Value;
                this.dateDue   = dtpDueDate.Value;
                rec.Remarks    = txtRemarks.Text;
                ctx.LoanRecords.Add(rec);
                int transactionID = ctx.SaveChanges();
                for (int i = 0; i < dgvBorrowInfo.Rows.Count; i++)

                {
                    LoanTransDetail detail = new LoanTransDetail();
                    detail.TransactionID = rec.TransactionID;
                    this.transactionID   = detail.TransactionID;
                    int bookID = Convert.ToInt32(dgvBorrowInfo.Rows[i].Cells[1].Value);
                    bookList.Add(bookID);
                    detail.BookID     = bookID;
                    detail.LoanStatus = "Out";
                    ctx.LoanTransDetails.Add(detail);
                    ctx.BooksDetails.Where(b => b.BookID == bookID).First().NumberLoaned++;
                }
                ctx.SaveChanges();
                ts.Complete();
            }

            txtMemberID.Text   = "";
            txtMemberName.Text = "";
            txtBookID.Text     = "";
            txtRemarks.Text    = "";
            dt.Rows.Clear();
        }