private void btnLapPhieu_Click(object sender, EventArgs e)
        {
            if (kiemTra_DauVao())
            {
                DTO_MUONSACH dtomuonsach = new DTO_MUONSACH()
                {
                    ID_USER = Int32.Parse(ttbMaDocGia.Text)
                };
                ttbNgayMuon.Text = DateTime.Now.Date.ToString("dd/MM/yyyy");

                List <int> lsidsachmuon = lay_MaSachMuon();

                try
                {
                    if (bllphieums.themPhieuMuonSach(dtomuonsach, lsidsachmuon))
                    {
                        MessageBox.Show("Lập phiếu thành công");
                    }
                    else
                    {
                        // NOT FINISHED
                        MessageBox.Show("Lập phiếu thất bại");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                MessageBox.Show("Mã độc giả không hợp lệ");
            }
        }
Пример #2
0
        public bool themPhieuMuonSach(DTO_MUONSACH dtoms, List <int> lsmasach)
        {
            BLL_Sach    bllsach = new BLL_Sach();
            BLL_QuyDinh bllquydinh = new BLL_QuyDinh();
            int         maxsongaymuon = 0, totalphims = 0, feemuonsach = 0;

            maxsongaymuon = bllquydinh.layQuyDinh("So Ngay Muon Toi Da");
            feemuonsach   = bllquydinh.layQuyDinh("Tien Muon Sach");

            foreach (int idsach in lsmasach)
            {
                themCTP_MuonSach(dtoms.ID_USER, idsach);

                totalphims += feemuonsach;
            }

            dtoms.NGAYMUON   = DateTime.Today.Date.ToString("yyyy-MM-dd");
            dtoms.NGAYTRA    = DateTime.Today.AddDays(maxsongaymuon).Date.ToString("yyyy-MM-dd");
            dtoms.TONGTIEN   = totalphims;
            dtoms.TRANGTHAI  = 0;
            dtoms.CREATED_AT = DateTime.Now;
            dtoms.UPDATED_AT = DateTime.Now;

            return(dalphieums.themPhieuMuonSach(dtoms));

            return(false);
        }
        public bool themPhieuMuonSach(DTO_MUONSACH dtophieums)
        {
            try
            {
                _conn.Open();

                string sql = string.Format("INSERT INTO MUONSACH (ID_USER, NGAYMUON, NGAYTRA," +
                                           " TONGTIEN, TRANGTHAI, CREATED_AT, UPDATED_AT)" +
                                           " VALUES( {0}, '{1}', '{2}', {3}, '{4}', '{5}', '{6}' )", dtophieums.ID_USER, dtophieums.NGAYMUON, dtophieums.NGAYTRA,
                                           dtophieums.TONGTIEN, dtophieums.TRANGTHAI, dtophieums.CREATED_AT.ToString("yyyy-MM-dd hh:mm:ss"), dtophieums.UPDATED_AT.ToString("yyyy-MM-dd HH:mm:ss"));

                MySqlCommand cmd = new MySqlCommand(sql, _conn);

                if (cmd.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                _conn.Close();
            }

            return(false);
        }
Пример #4
0
        private void btnLapPhieu_Click(object sender, EventArgs e)
        {
            if (kiemTra_DauVao())
            {
                if (dtgvSachMuon.Rows.Count < 1)
                {
                    MessageBox.Show("Vui lòng chọn sách cần mượn");
                    return;
                }

                DTO_MUONSACH dtomuonsach = new DTO_MUONSACH()
                {
                    ID_USER = Int32.Parse(ttbMaDocGia.Text)
                };

                List <int> lsidsachmuon = lay_MaSachMuon();

                try
                {
                    if (bllphieums.themPhieuMuonSach(dtomuonsach, lsidsachmuon))
                    {
                        DTO_DOCGIA dtodocgia = blldocgia.layDocGia(Int32.Parse(ttbMaDocGia.Text));

                        if (dtodocgia != null)
                        {
                            ttbHoTen.Text = dtodocgia.HOVATEN;
                        }

                        ttbNgayMuon.Text = DateTime.Now.Date.ToString("dd/MM/yyyy");

                        MessageBox.Show("Lập phiếu thành công");
                    }
                    else
                    {
                        // NOT FINISHED
                        MessageBox.Show("Lập phiếu thất bại");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Пример #5
0
        public int themPhieuMuonSach(DTO_MUONSACH dtophieums)
        {
            try
            {
                _conn.Open();

                string sqlthem = "", sqllay = "";

                sqlthem = string.Format("INSERT INTO MUONSACH (ID_USER, NGAYMUON, NGAYTRA," +
                                        " TONGTIEN, TRANGTHAI, CREATED_AT)" +
                                        " VALUES( {0}, '{1}', '{2}', {3}, '{4}', '{5}' )", dtophieums.ID_USER, dtophieums.NGAYMUON, dtophieums.NGAYTRA,
                                        dtophieums.TONGTIEN, dtophieums.TRANGTHAI, dtophieums.CREATED_AT.ToString("yyyy-MM-dd hh:mm:ss"));

                MySqlCommand cmdthem = new MySqlCommand(sqlthem, _conn);

                if (cmdthem.ExecuteNonQuery() > 0)
                {
                    sqllay = string.Format("SELECT ID FROM MUONSACH WHERE ID_USER = {0} AND CREATED_AT = '{1}'",
                                           dtophieums.ID_USER, dtophieums.CREATED_AT.ToString("yyyy-MM-dd hh:mm:ss"));

                    MySqlDataAdapter sda     = new MySqlDataAdapter(sqllay, _conn);
                    DataTable        dtsachm = new DataTable();

                    sda.Fill(dtsachm);

                    return(Int32.Parse(dtsachm.Rows[0]["id"].ToString()));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                _conn.Close();
            }

            return(-1);
        }
Пример #6
0
        public bool themPhieuMuonSach(DTO_MUONSACH dtoms, List <int> lsmasach)
        {
            BLL_Sach    bllsach = new BLL_Sach();
            BLL_QuyDinh bllquydinh = new BLL_QuyDinh();
            int         idmuonsach = 0, maxsongaymuon = 0, totalphims = 0, feemuonsach = 0;

            maxsongaymuon = bllquydinh.layQuyDinh("So Ngay Muon Toi Da"); // 3
            feemuonsach   = bllquydinh.layQuyDinh("Tien Muon Sach");      // 2

            foreach (int idsach in lsmasach)
            {
                totalphims += feemuonsach;
            }

            dtoms.NGAYMUON   = DateTime.Today.Date.ToString("yyyy-MM-dd");
            dtoms.NGAYTRA    = DateTime.Today.AddDays(maxsongaymuon).Date.ToString("yyyy-MM-dd");
            dtoms.TONGTIEN   = totalphims;
            dtoms.TRANGTHAI  = 0;
            dtoms.CREATED_AT = DateTime.Now;

            idmuonsach = dalphieums.themPhieuMuonSach(dtoms);


            if (idmuonsach > -1)
            {
                foreach (int idsach in lsmasach)
                {
                    themCTP_MuonSach(idmuonsach, idsach);
                    bllsach.suaTinhTrangSach(idsach, "Het Hang");
                }

                return(true);
            }

            return(false);
        }