Exemplo n.º 1
0
        private void dateTimePicker1_Leave(object sender, EventArgs e)
        {
            dateTimePicker2.Value = dateTimePicker1.Value.AddDays(7);

            Entities   ctx = new Entities();
            LoanRecord lr  = new LoanRecord();

            if (dateTimePicker1.Value < System.DateTime.Today)
            {
                MessageBox.Show("Issue Date should not be past!",
                                "Warning",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning,
                                MessageBoxDefaultButton.Button1,
                                MessageBoxOptions.RightAlign,
                                false);
            }

            if (dateTimePicker1.Value > System.DateTime.Now)
            {
                MessageBox.Show("Issue Date should not be future!",
                                "Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error,
                                MessageBoxDefaultButton.Button1,
                                MessageBoxOptions.RightAlign,
                                false);
                return;
            }
        }
Exemplo n.º 2
0
        private void check_in_Click(object sender, EventArgs e)
        {
            int        loanNumber = (int)dataGridView1.CurrentRow.Cells[0].Value;
            LoanRecord checkedIn  = ctx.LoanRecords.Where(x => x.LoanNumber == loanNumber).First();

            checkedIn.DateReturned = dateTimePicker1.Value;
            checkedIn.LoanStatus   = "in";
            ctx.SaveChanges();
        }
Exemplo n.º 3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (cboMemberID.Text == "--Select ID--" || cboISBN.Text == "--Select ISBN--")
            {
                MessageBox.Show("Select MemberID and ISBN!!",
                                "Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error,
                                MessageBoxDefaultButton.Button1,
                                MessageBoxOptions.RightAlign,
                                false);
                return;
            }

            Entities   ctx = new Entities();
            LoanRecord lr  = new LoanRecord();

            string memberID  = cboMemberID.Text;
            string isbn      = cboISBN.Text;
            string issueDate = dateTimePicker1.Value.ToString();
            string dueDate   = dateTimePicker2.Value.ToString();
            string qty       = txtQuantityOfBook.Text;
            string remarks   = txtRemarks.Text;

            lr.MemberID     = Convert.ToInt32(memberID);
            lr.ISBN         = isbn;
            lr.DateBorrowed = Convert.ToDateTime(issueDate);
            lr.DueDate      = Convert.ToDateTime(dueDate);
            lr.Quantity     = Convert.ToInt32(qty);
            lr.LoanStatus   = "out";
            lr.Remarks      = remarks;

            ctx.LoanRecords.Add(lr);

            Book b = ctx.Books.Where(x => x.ISBN == isbn).First();

            b.TotalOnLoan += Convert.ToInt32(qty);

            int    mID = Convert.ToInt32(cboMemberID.Text);
            Member m   = ctx.Members.Where(x => x.MemberID == mID).First();

            m.BooksBorrowed += Convert.ToInt32(qty);


            if (b.TotalQty < b.TotalOnLoan)
            {
                MessageBox.Show("There has no copy. It cannot be lent.");
                return;
            }


            if (lr.DateBorrowed > System.DateTime.Now)
            {
                MessageBox.Show("Issue Date should not be future!",
                                "Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error,
                                MessageBoxDefaultButton.Button1,
                                MessageBoxOptions.RightAlign,
                                false);
                return;
            }

            if (cboMemberID.Text == "--Select ID--" || cboISBN.Text == "--Select ISBN--")
            {
                MessageBox.Show("Select MemberID and ISBN!!",
                                "Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error,
                                MessageBoxDefaultButton.Button1,
                                MessageBoxOptions.RightAlign,
                                false);
                return;
            }

            ctx.SaveChanges();
            MessageBox.Show("Record is saved.");
        }