Beispiel #1
0
        private void dtgv_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                DataGridViewRow temp = dtgv.Rows[e.RowIndex];
                txt_soPM.Text = temp.Cells[0].Value.ToString();
                cbx_docgia.Text = temp.Cells[1].Value.ToString();
                cbx_nhanvien.Text = temp.Cells[2].Value.ToString();
                dtpk_ngaymuon.Value = DateTime.ParseExact(temp.Cells[3].Value.ToString(), "dd/MM/yyyy", null);
                dtpk_ngaytra.Value = DateTime.ParseExact(temp.Cells[4].Value.ToString(), "dd/MM/yyyy", null);
                chbox_xacnhantra.Checked = bool.Parse(temp.Cells[5].Value.ToString());
                txt_ghichu.Text = temp.Cells[6].Value.ToString();

                if (chbox_xacnhantra.Checked)
                {
                    btn_sua.Enabled = btn_xoa.Enabled = btn_luu.Enabled = false;
                    Utils.readOnly_text_box(new List<TextBox> { txt_ghichu }, true);
                    Utils.enable_combobox(new List<ComboBox> { cbx_docgia, cbx_nhanvien }, false);
                    chbox_xacnhantra.Enabled = false;
                    dtgv_sachmuon.Enabled = false;
                    dtpk_ngaytra.Enabled = false;
                    dtpk_ngaymuon.Enabled = false;
                }
                else
                {
                   btn_sua.Enabled = btn_xoa.Enabled = btn_luu.Enabled = true;
                }

                chitietphieu_ctrl chitiet_ctrl = new chitietphieu_ctrl();
                var list_sach = chitiet_ctrl.select_all_chitietphieu_by_sopm(int.Parse(txt_soPM.Text));
                var data_sach = list_sach.data;
                if (data_sach != null)
                {
                    dtgv_sachmuon.RowCount = data_sach.Count() + 1;
                    for (int i = 0; i < data_sach.Count(); i++)
                    {
                        dtgv_sachmuon.Rows[i].Cells[0].Value = data_sach[i].masach;
                        dtgv_sachmuon.Rows[i].Cells[1].Value = data_sach[i].trangthaisach;
                    }
                }
                else
                {
                    dtgv_sachmuon.Rows.Clear();
                }

            }
        }
Beispiel #2
0
        private void btn_luu_Click(object sender, EventArgs e)
        {
            switch (option)
            {
                case Option.Nodata:

                    break;

                case Option.Insert:
                    get_ds_sach();
                    var check_docgia = Utils.err_null_data_cbx(cbx_docgia);
                    if (check_docgia != null)
                    {
                        MessageBox.Show(check_docgia);
                        break;
                    }
                    var check_nhanvien = Utils.err_null_data_cbx(cbx_nhanvien);
                    if (check_nhanvien != null)
                    {
                        MessageBox.Show(check_nhanvien);
                        break;
                    }
                    get_info();
                    //check if existing data
                    var check = true;
                    var data = dtgv.Rows;
                    foreach (DataGridViewRow item in data)
                    {
                        if (int.Parse(item.Cells[0].Value.ToString()) == phieumuontra_ett.sophieumuon)
                        {
                            check = false;
                        }
                    }
                    if (!check)
                    {
                        Utils.err_duplicate_data();
                        break;
                    }
                    List<string> lst_masach = new List<string>();
                    var sach_dataRows = dtgv_sachmuon.Rows;
                    foreach (DataGridViewRow item in sach_dataRows)
                    {
                        if (item.Cells[0].Value != null)
                        {
                            lst_masach.Add(item.Cells[0].Value.ToString());
                        }
                    }
                    var temp = phieumuontra_ctrl.insert_phieumuontra(phieumuontra_ett, lst_masach);
                    switch (temp.errcode)
                    {
                        case ErrorCode.NaN:
                            break;
                        case ErrorCode.sucess:
                            MessageBox.Show(Constants.success_insert);
                            load_data();
                            Utils.erase_text_box(new List<TextBox> { txt_soPM, txt_ghichu });
                            Utils.erase_combobox(new List<ComboBox>() { cbx_docgia, cbx_nhanvien });
                            chbox_xacnhantra.Checked = false;
                            dtgv_sachmuon.Rows.Clear();
                            // insert chitietphieu
                            var sopm = temp.data.sophieumuon;
                            chitietphieu_ctrl chitiet_ctrl = new chitietphieu_ctrl();
                            get_ds_sach();
                            phieumuontra_ett.sophieumuon = sopm;
                            foreach (chitietphieu_ett item in chitietphieu)
                            {
                                item.sophieumuon = sopm;
                                chitiet_ctrl.insert_chitietphieu(item);
                            }

                            break;
                        case ErrorCode.fail:
                            break;
                        default:
                            break;
                    }
                    break;

                case Option.Edit:
                    get_info();
                    //check if existing data
                    var check1 = true;
                    var data1 = dtgv.Rows;
                    foreach (DataGridViewRow item in data1)
                    {
                        if (int.Parse(item.Cells[0].Value.ToString()) == phieumuontra_ett.sophieumuon)
                        {
                            check1 = false;
                        }
                    }
                    if (check1)
                    {
                        Utils.err_no_duplicate_data();
                        break;
                    }
                    List<string> lst_masach1 = new List<string>();
                    var sach_dataRows1 = dtgv_sachmuon.Rows;
                    foreach (DataGridViewRow item in sach_dataRows1)
                    {
                        if (item.Cells[0].Value != null)
                        {
                            lst_masach1.Add(item.Cells[0].Value.ToString());
                        }
                    }
                    var temp1 = phieumuontra_ctrl.edit_phieumuontra(phieumuontra_ett, lst_masach1);
                    var sopm1 = phieumuontra_ett.sophieumuon;

                    chitietphieu_ctrl chitiet_ctrl1 = new chitietphieu_ctrl();
                    var list_sach = chitiet_ctrl1.select_all_chitietphieu_by_sopm(phieumuontra_ett.sophieumuon);
                    if (list_sach.data != null)
                    {
                        foreach (chitietphieu_ett item in list_sach.data)
                        {
                            chitiet_ctrl1.delete_chitietphieu(item.sophieumuon, item.masach);
                        }
                    }

                    switch (temp1.errcode)
                    {
                        case ErrorCode.NaN:
                            break;
                        case ErrorCode.sucess:
                            MessageBox.Show(Constants.success_edit);
                            load_data();
                            get_ds_sach();
                            foreach (chitietphieu_ett item in chitietphieu)
                            {
                                item.sophieumuon = sopm1;
                                chitiet_ctrl1.insert_chitietphieu(item);
                            }
                            Utils.erase_text_box(new List<TextBox> { txt_soPM, txt_ghichu});
                            Utils.readOnly_text_box(new List<TextBox> {txt_ghichu}, true);
                            Utils.erase_combobox(new List<ComboBox>() { cbx_nhanvien, cbx_docgia });
                            Utils.enable_combobox(new List<ComboBox>() { cbx_nhanvien, cbx_docgia }, false);
                            dtpk_ngaymuon.Enabled = false;
                            dtgv_sachmuon.Enabled = false;
                            dtgv_sachmuon.Rows.Clear();
                            dtpk_ngaytra.Enabled = false;
                            chbox_xacnhantra.Enabled = false;
                            chbox_xacnhantra.Checked = false;
                            break;
                        case ErrorCode.fail:
                            if (Utils.switch_false())
                            {
                                MessageBox.Show(temp1.errInfor);
                            }
                            break;
                        default:
                            break;
                    }
                    break;

                default:
                    break;
            }
        }