Ejemplo n.º 1
0
        private void setAutoComplete()
        {
            //Id Student
            txtIdBorrow.AutoCompleteMode    = txtIdBook.AutoCompleteMode = txtIdStudent.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            txtIdStudent.AutoCompleteSource = AutoCompleteSource.CustomSource;
            var txtIdStudentAutoCompleteCustomsource = new AutoCompleteStringCollection();

            txtIdStudentAutoCompleteCustomsource.AddRange(Student.getStudentId());
            txtIdStudent.AutoCompleteCustomSource = txtIdStudentAutoCompleteCustomsource;
            //Id borrow
            //txt.AutoCompleteMode = txtEmail.AutoCompleteMode = txtIdStudent.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            txtIdBorrow.AutoCompleteSource = AutoCompleteSource.CustomSource;
            var txtIdBorrowAutoCompleteCustomsource = new AutoCompleteStringCollection();

            txtIdBorrowAutoCompleteCustomsource.AddRange(Borrow.getBorrowId());
            txtIdBorrow.AutoCompleteCustomSource = txtIdBorrowAutoCompleteCustomsource;

            //id Book
            txtIdBook.AutoCompleteSource = AutoCompleteSource.CustomSource;
            var txtIdBookAutoCompleteCustomsource = new AutoCompleteStringCollection();

            txtIdBookAutoCompleteCustomsource.AddRange(Book.getBookSerial());
            txtIdBook.AutoCompleteCustomSource = txtIdBookAutoCompleteCustomsource;
        }
Ejemplo n.º 2
0
        private void btnMode_Click(object sender, EventArgs e)
        {
            switch (btnMode.Text)
            {
            case "Tìm":
                #region TÌM
                if (rbtnFindbyIdStudent.Checked)
                {
                    dtgvCart.Rows.Clear();
                    try
                    {
                        table = Borrow.findBorrowByIdStudent(txtIdStudent.Text);
                        foreach (DataRow row in table.Rows)
                        {
                            if (!txtIdBook.Text.Contains(row[2].ToString()))
                            {
                                txtIdBorrow.Text += row[0].ToString() + ", ";
                            }
                            dtgvCart.Rows.Add(row[2], Book.getBookNameBySerial(row[2].ToString()), row[3].ToString(), row[4], row[0], row[5]);
                        }
                        //txtIdStudent.Text = table.Rows[0][0].ToString();
                        xóaToolStripMenuItem.Enabled = tsbtnDelMode.Enabled = true;
                    }
                    catch (Exception ex)
                    {
                        clear();
                        MessageBox.Show("Không tìm thấy sinh viên\nLỗi : " + ex.Message, "Thất bại!");
                    }
                }
                else
                {
                    try
                    {
                        dtgvCart.Rows.Clear();
                        table             = Borrow.findBorrowById(txtIdBorrow.Text);
                        txtIdStudent.Text = table.Rows[0][0].ToString();
                        foreach (DataRow row in table.Rows)
                        {
                            dtgvCart.Rows.Add(row[2], Book.getBookNameBySerial(row[2].ToString()), row[3].ToString(), row[4], row[0], row[5]);
                        }
                        //edit here
                        xóaToolStripMenuItem.Enabled = tsbtnDelMode.Enabled = true;
                    }
                    catch (Exception ex)
                    {
                        clear();
                        MessageBox.Show("Không tìm thấy thẻ mượn sách của sinh viên\nLỗi : " + ex.Message, "Thất bại!");
                    }
                }
                #endregion TÌM
                break;

            case "Thêm":
                #region THÊM
            {
                try
                {
                    //foreach (DataGridViewRow row in dtgvCart.Rows)
                    //{
                    //    Borrow.insertBorrow(txtIdBorrow.Text, txtIdStudent.Text, txtIdBook.Text, (int)txtAmount.Value, txtborrow.Text, txtComment.Text);
                    //}
                    //txtIdBook.Text = "";
                    //txtAmount.Value = 1;
                    //txtComment.Text = "";
                    //txtborrow.Text = "1";
                    //lblQuantum.Text = "0";
                    Borrow.insertBorrow(txtIdBorrow.Text, txtIdBorrow.Text, txtIdStudent.Text, txtIdBook.Text, (int)txtAmount.Value, txtborrow.Text, txtComment.Text);
                    dtgvCart.Rows.Clear();
                    MessageBox.Show("Tạo thành công thẻ mượn sách cho sinh viên : " + txtIdStudent.Text + "\nMã thẻ mượn : " + txtIdBorrow.Text, "Thông báo");
                    //cbxBorrowtime.SelectedIndex = -1;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Không thể tạo\nLỗi : " + ex.Message, "Thông báo");
                    break;
                }
                //}

                setAutoComplete();
            }
                #endregion THÊM
                clear();
                break;

            case "Xóa":
                if (MessageBox.Show("Bạn có chắc muốn xóa thẻ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    if (Borrow.deleteBorrow_Detail(txtIdBorrow.Text))
                    {
                        MessageBox.Show("Xóa thẻ thành công", "Thành công", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Không xóa được thẻ", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                setAutoComplete();
                break;

            default:
                break;
            }
        }
Ejemplo n.º 3
0
        private void btnMode_Click(object sender, EventArgs e)
        {
            switch (btnMode.Text)
            {
            case "Tìm":
                #region TÌM
                if (rbtnFindbyIdStudent.Checked)
                {
                    dtgvCart.Rows.Clear();
                    try
                    {
                        table = Borrow.findBorrowByIdStudent(txtIdStudent.Text);
                        foreach (DataRow row in table.Rows)
                        {
                            if (!txtIdBook.Text.Contains(row[0].ToString()))
                            {
                                txtIdBorrow.Text += row[0].ToString() + ", ";
                            }
                            dtgvCart.Rows.Add(row[1], Book.getBookNameBySerial(row[1].ToString()), row[2].ToString());
                        }
                        //txtIdStudent.Text = table.Rows[0][0].ToString();
                        xóaToolStripMenuItem.Enabled = tsbtnDelMode.Enabled = true;
                    }
                    catch (Exception ex)
                    {
                        clear();
                        MessageBox.Show("Không tìm thấy sinh viên\nLỗi : " + ex.Message, "Thất bại!");
                    }
                    //MessageBox.Show("Không tìm thấy thẻ mượn sách của sinh viên", "Thất bại!");
                }
                else
                {
                    try
                    {
                        dtgvCart.Rows.Clear();
                        table             = Borrow.findBorrowById(txtIdBorrow.Text);
                        txtIdStudent.Text = table.Rows[0][0].ToString();
                        foreach (DataRow row in table.Rows)
                        {
                            dtgvCart.Rows.Add(row[1].ToString(), Book.getBookNameBySerial(row[1].ToString()), row[2].ToString());
                        }
                        //edit here
                        xóaToolStripMenuItem.Enabled = tsbtnDelMode.Enabled = true;
                    }
                    catch (Exception ex)
                    {
                        clear();
                        MessageBox.Show("Không tìm thấy thẻ mượn sách của sinh viên\nLỗi : " + ex.Message, "Thất bại!");
                    }
                }
                #endregion TÌM
                break;

            case "Thêm":
                #region THÊM
            {
                //
                if (txtAmount.Value * txtIdStudent.TextLength * dtgvCart.Rows.Count * cbxBorrowTime.Text.Length == 0)
                {
                    MessageBox.Show("Bạn chưa điền đủ thông tin!", "Thông báo");
                }
                else
                {
                    if (Borrow.numOfBorrowCard(txtIdStudent.Text) < 5)
                    {
                        if (Borrow.insertBorrow(txtIdStudent.Text) > 0)
                        {
                            try
                            {
                                txtIdBorrow.Text = (Borrow.getId()).ToString();
                                foreach (DataGridViewRow row in dtgvCart.Rows)
                                {
                                    Borrow.insertBorrow(txtIdBorrow.Text, row.Cells[0].Value.ToString(), int.Parse(row.Cells[2].Value.ToString()), DateTime.Now, cbxBorrowTime.GetItemText(cbxBorrowTime.SelectedItem)[0] - '0', txtComment.Text);
                                }
                                txtIdBook.Text  = "";
                                txtAmount.Value = 1;
                                txtComment.Text = "";
                                lblQuantum.Text = "0";
                                dtgvCart.Rows.Clear();
                                MessageBox.Show("Tạo thành công thẻ mượn sách cho sinh viên : " + txtIdStudent.Text + "\nMã thẻ mượn : " + txtIdBorrow.Text, "Thông báo");
                                cbxBorrowTime.SelectedIndex = -1;
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("Không thể tạo\nLỗi : " + ex.Message, "Thông báo");
                                break;
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Bạn đã đạt giới hạn 5 phiếu mượn sách", "Thông báo");
                    }
                }
                setAutoComplete();
            }
                #endregion THÊM
                clear();
                break;

            case "Xóa":
                if (MessageBox.Show("Bạn có chắc muốn xóa thẻ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    if (Borrow.deleteBorrow(txtIdBorrow.Text))
                    {
                        MessageBox.Show("Xóa thẻ thành công", "Thành công", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Không xóa được thẻ", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                setAutoComplete();
                break;

            default:
                break;
            }
        }