예제 #1
0
        private bool checkDuplicateReaderID(string readerID)
        {
            bool          check      = true;
            ReaderDAO     readerDAO  = new ReaderDAO();
            List <Reader> listReader = readerDAO.getAllReaders();

            foreach (Reader r in listReader)
            {
                if (r.ReaderID.Equals(readerID))
                {
                    check = false;
                }
            }
            return(check);
        }
예제 #2
0
        private void btnUpdateReader_Click(object sender, EventArgs e)
        {
            if (txtReaderID1.Text.Length == 0)
            {
                MessageBox.Show("Pls Chosse the Reader first!!");
                return;
            }
            if (txtReaderName1.Text.Length == 0 || txtAddress1.Text.Length == 0 || txtPhone1.Text.Length == 0 || txtEmail1.Text.Length == 0)
            {
                MessageBox.Show("All value must not blank");
                return;
            }
            try
            {
                int test = int.Parse(txtPhone1.Text);
            }catch (Exception ex)
            {
                MessageBox.Show("The phone must be a number!!");
                return;
            }
            Reader    reader    = new Reader(txtReaderID1.Text, txtReaderName1.Text, txtAddress1.Text, txtPhone1.Text, txtEmail1.Text);
            ReaderDAO readerDAO = new ReaderDAO();

            if (readerDAO.updateReader(reader))
            {
                DataTable table = new DataTable();
                table.Columns.Add("ID", typeof(string));
                table.Columns.Add("Name", typeof(string));
                table.Columns.Add("Address", typeof(string));
                table.Columns.Add("Phone", typeof(string));
                table.Columns.Add("Email", typeof(string));
                List <Reader> list = readerDAO.getAllReaders();
                foreach (Reader r in list)
                {
                    table.Rows.Add(r.ReaderID, r.ReaderName, r.ReaderAddress, r.ReaderPhone, r.Email);
                }
                MessageBox.Show("Update Success!!");
                dgvListReader.DataSource          = table;
                dgvListReader.AllowUserToAddRows  = false;
                dgvListReader.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            }
            else
            {
                MessageBox.Show("Update Fail...");
            }
        }
예제 #3
0
        private void btnSearchReader_Click(object sender, EventArgs e)
        {
            List <Reader> list      = null;
            string        search    = txtSearchReader.Text;
            ReaderDAO     readerDAO = new ReaderDAO();
            DataTable     table     = new DataTable();

            table.Columns.Add("ID", typeof(string));
            table.Columns.Add("Name", typeof(string));
            table.Columns.Add("Address", typeof(string));
            table.Columns.Add("Phone", typeof(string));
            table.Columns.Add("Email", typeof(string));
            if (search.Length == 0)
            {
                list = readerDAO.getAllReaders();
                foreach (Reader r in list)
                {
                    table.Rows.Add(r.ReaderID, r.ReaderName, r.ReaderAddress, r.ReaderPhone, r.Email);
                }
            }
            else
            {
                Reader rd = readerDAO.findReaderByID(search);
                if (rd == null)
                {
                    MessageBox.Show("Not Found!!");
                    return;
                }
                else
                {
                    table.Rows.Add(rd.ReaderID, rd.ReaderName, rd.ReaderAddress, rd.ReaderPhone, rd.Email);
                }
            }
            dgvListReader.DataSource          = table;
            dgvListReader.AllowUserToAddRows  = false;
            dgvListReader.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
        }
예제 #4
0
        private void btnConfirmNewReader_Click(object sender, EventArgs e)
        {
            try
            {
                int test = int.Parse(txtNewReaderPhone.Text);
            } catch (Exception ex)
            {
                MessageBox.Show("Phone must be a number");
                return;
            }
            OrderDAO      orderDAO   = new OrderDAO();
            ReaderDAO     readerDAO  = new ReaderDAO();
            List <Reader> listReader = readerDAO.getAllReaders();

            if (txtNewReaderName.Text.Length == 0 || txtNewReaderEmail.Text.Length == 0 || txtNewReaderAddress.Text.Length == 0 || txtNewReaderPhone.Text.Length == 0)
            {
                MessageBox.Show("All info must not blank!!");
                return;
            }
            int cc = 1;

            foreach (Reader r in listReader)
            {
                string[] tmp = r.ReaderID.Split('-');
                if (int.Parse(tmp[1]) == cc)
                {
                    cc++;
                }
                else
                {
                    string ID = "SE-" + cc;
                    if (checkDuplicateReaderID(ID))
                    {
                        break;
                    }
                    else
                    {
                        cc++;
                    }
                }
            }
            string   readerID      = "SE-" + cc;
            string   readerName    = txtNewReaderName.Text;
            string   readerAddress = txtNewReaderAddress.Text;
            string   readerPhone   = txtNewReaderPhone.Text;
            string   readerEmail   = txtNewReaderEmail.Text;
            DateTime borrowDate    = dtpBorrowDate.Value;
            DateTime returnDate    = dtpReturnDate.Value;

            if (returnDate.CompareTo(borrowDate) < 0)
            {
                MessageBox.Show("Return Date must not be earlier than Borrow Date!!");
                return;
            }
            DateTime dateOfCreate = DateTime.Now;
            Reader   rd           = new Reader(readerID, readerName, readerAddress, readerPhone, readerEmail);


            string      recordID = "OD-" + readerID + "-1";
            List <Book> listBook = dao.getAllBooks();
            List <Book> listcheckQuantityBook = new List <Book>();

            foreach (Cart c in listcart)
            {
                foreach (Book b in listBook)
                {
                    if (b.BookID.Equals(c.BookID))
                    {
                        b.Quantity = b.Quantity - c.Quantity;
                        listcheckQuantityBook.Add(b);
                    }
                }
            }
            foreach (Book b in listcheckQuantityBook)
            {
                if (b.Quantity < 0)
                {
                    MessageBox.Show("Quantity of the book " + b.BookName + " is not enough");
                    return;
                }
            }
            int totalQuantity = 0;

            foreach (Cart c in listcart)
            {
                totalQuantity += c.Quantity;
            }
            Order order = new Order(recordID, emp.EmployeeID, readerID, borrowDate, returnDate, dateOfCreate, totalQuantity, "Đang mượn");

            readerDAO.insertReader(rd);
            bool checkCreateOrder = orderDAO.createOrder(order);

            if (checkCreateOrder)
            {
                int count = 0;
                foreach (Cart c in listcart)
                {
                    count++;
                    string recordDetailID = recordID + "-" + count;
                    orderDAO.createOrderDetail(recordDetailID, recordID, c.BookID, c.Quantity);
                }
                orderDAO.setQuantityBook(listcheckQuantityBook);
                MessageBox.Show("New Reader has ID: " + readerID + " is added!!");
                MessageBox.Show("Order Success!!");
                listcart.Clear();
                txtCartBookID.Text       = "";
                txtCartBookName.Text     = "";
                txtCartQuantityBook.Text = "";

                txtNewReaderName.Text    = "";
                txtNewReaderAddress.Text = "";
                txtNewReaderPhone.Text   = "";
                txtNewReaderEmail.Text   = "";
                dgvListBorrow.DataSource = null;
            }
        }