Ejemplo n.º 1
0
        public DTO_TRASACH tra_Sach(int ctrltinhieu = 0)
        {
            DTO_TRASACH dtots = new DTO_TRASACH()
            {
                ID_USER = Int32.Parse(ttbMaDocGia.Text), TIENBOITHUONG = Int32.Parse(ttbSachHong.Text)
            };

            List <int> lsidsach = lay_DanhSachMaSachTra();

            try
            {
                if (bllphieuts.themPhieuTraSach(ref dtots, lsidsach, ctrltinhieu))
                {
                    dtgvSachMuon.Refresh();

                    DTO_DOCGIA dtodocgia = blldocgia.layDocGia(Int32.Parse(ttbMaDocGia.Text));

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

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

                    return(dtots);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            return(null);
        }
Ejemplo n.º 2
0
        public bool themPhieuTraSach(DTO_TRASACH dtophieuts)
        {
            try
            {
                _conn.Open();

                string sql = string.Format("INSERT INTO TRASACH (ID_USER, NGAYTRA, SONGAYTRE," +
                                           " TIENTRE, TIENBOITHUONG, TIENTHUESACH, TONGTIEN, CREATED_AT, UPDATED_AT)" +
                                           " VALUES( {0}, '{1}', {2}, {3}, {4}, {5}, {6}, '{7}', '{8}' )", dtophieuts.ID_USER,
                                           dtophieuts.NGAYTRA, dtophieuts.SONGAYTRE, dtophieuts.TIENTRE, dtophieuts.TIENBOITHUONG,
                                           dtophieuts.TIENTHUESACH, dtophieuts.TONGTIEN, dtophieuts.CREATED_AT.ToString("yyyy-MM-dd HH:mm:ss.fff"), dtophieuts.UPDATED_AT.ToString("yyyy-MM-dd HH:mm:ss.fff"));

                MySqlCommand cmd = new MySqlCommand(sql, _conn);

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

            return(false);
        }
Ejemplo n.º 3
0
        private void btnLapPhieuThuTP_Click(object sender, EventArgs e)
        {
            if (!(kiemTra_DauVao() && kiemTra_TinhHopLe()))
            {
                return;
            }

            try
            {
                DTO_TRASACH dtots = tra_Sach(1);

                if (dtots != null)
                {
                    PL_Payment plpayment = new PL_Payment(dtots);

                    plpayment.Show();
                }
                else
                {
                    MessageBox.Show("Lap Phieu Thu Tien That Bai");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 4
0
        public bool tra_TungSach(ref DTO_TRASACH dtots, int idsach)
        {
            BLL_Sach          bllsach    = new BLL_Sach();
            BLL_QuyDinh       bllquydinh = new BLL_QuyDinh();
            BLL_PhieuMuonSach bllphieums = new BLL_PhieuMuonSach();

            DataTable dtphieums = null;
            DateTime  datemuonsach = DateTime.Now;
            int       totalngaytra = 0, maxngaytra = 0, finetratre = 0, feethuesach = 0, feeboithuong = 0;

            try
            {
                dtphieums    = bllphieums.layCTMuonSach_ChuaTra(dtots.ID_USER, idsach);
                datemuonsach = Convert.ToDateTime(dtphieums.Rows[0]["CREATED_AT"].ToString());

                totalngaytra = DateTime.Now.Subtract(datemuonsach).Days;
                maxngaytra   = bllquydinh.layQuyDinh("So_Ngay_Muon_Toi_Da");
                finetratre   = bllquydinh.layQuyDinh("Tien_Phat");
                feethuesach  = bllquydinh.layQuyDinh("Tien_Muon_Sach");

                dtots.SONGAYTRE     += ((totalngaytra - maxngaytra > 0) ? (totalngaytra - maxngaytra) : 0);
                dtots.TIENTRE       += dtots.SONGAYTRE * finetratre;
                dtots.TIENBOITHUONG += 0;
                dtots.TIENTHUESACH  += feethuesach;
                dtots.TONGTIEN      += dtots.TIENTRE + dtots.TIENBOITHUONG + dtots.TIENTHUESACH;

                return(true);
            }
            catch (Exception ex)
            {
                //mess
            }

            return(false);
        }
Ejemplo n.º 5
0
        public void tra_TungSach(ref DTO_TRASACH dtots, int idsach, int ishong)
        {
            BLL_Sach          bllsach    = new BLL_Sach();
            BLL_QuyDinh       bllquydinh = new BLL_QuyDinh();
            BLL_PhieuMuonSach bllphieums = new BLL_PhieuMuonSach();

            DTO_CHITIETMUONSACH dtoctms = null;
            DateTime            datemuonsach;
            int numngaytratre = 0, maxngaytra = 0, paymtratre = 0, feethuesach = 0, paymboithuong = 0;

            try
            {
                dtoctms      = bllphieums.layCTMuonSach_ChuaTra(dtots.ID_USER, idsach);
                datemuonsach = dtoctms.CREATED_AT;


                maxngaytra    = bllquydinh.layQuyDinh("So Ngay Muon Toi Da"); // 3
                paymtratre    = bllquydinh.layQuyDinh("Tien Phat");           // 1
                feethuesach   = bllquydinh.layQuyDinh("Tien Muon Sach");      // 2
                paymboithuong = bllquydinh.layQuyDinh("Tien Boi Thuong");     // 4

                numngaytratre = DateTime.Now.Subtract(datemuonsach).Days - maxngaytra;
                numngaytratre = (numngaytratre > 0 ? numngaytratre : 0);

                dtots.SONGAYTRE     += numngaytratre;
                dtots.TIENTRE       += numngaytratre * paymtratre;
                dtots.TIENBOITHUONG += ishong * paymboithuong;
                dtots.TIENTHUESACH  += feethuesach;
                dtots.TONGTIEN       = dtots.TIENTRE + dtots.TIENBOITHUONG + dtots.TIENTHUESACH;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 6
0
        public PL_Payment(DTO_TRASACH dtots)
        {
            InitializeComponent();

            ttbPhiThue.Text       = dtots.TIENTHUESACH.ToString();
            ttbTienPhat.Text      = dtots.TIENTRE.ToString();
            ttbTienBoiThuong.Text = dtots.TIENBOITHUONG.ToString();

            ttbTongTien.Text = dtots.TONGTIEN.ToString();
        }
Ejemplo n.º 7
0
 public void khoiTao_DoiTuongTraSach(ref DTO_TRASACH dtots)
 {
     dtots.NGAYTRA       = DateTime.Today.Date.ToString("yyyy-MM-dd");
     dtots.CREATED_AT    = DateTime.Now;
     dtots.SONGAYTRE     = 0;
     dtots.TIENTRE       = 0;
     dtots.TIENBOITHUONG = 0;
     dtots.TIENTHUESACH  = 0;
     dtots.TONGTIEN      = 0;
 }
Ejemplo n.º 8
0
        public void tra_Sach(List <int> lsidsach)
        {
            DTO_TRASACH dtotrasach = new DTO_TRASACH()
            {
                ID_USER = Int32.Parse(ttbMaDocGia.Text)
            };

            bllphieuts.themPhieuTraSach(ref dtotrasach, lsidsach);

            ttbSoNgayTT.Text = dtotrasach.SONGAYTRE.ToString();
            ttbNgayTra.Text  = DateTime.Now.Date.ToString();
        }
Ejemplo n.º 9
0
        public bool themPhieuTraSach(ref DTO_TRASACH dtots, List <int> lsmasach)
        {
            BLL_PhieuMuonSach bllphieums = new BLL_PhieuMuonSach();

            khoiTao_DoiTuongTraSach(ref dtots);

            foreach (int idsach in lsmasach)
            {
                tra_TungSach(ref dtots, idsach);
                themCTP_TraSach(idsach);
                bllphieums.suaCTP_MuonSach(dtots.ID_USER, idsach);
            }

            bllphieums.tongKet_MuonSach(dtots.ID_USER);

            return(dalphieuts.themPhieuTraSach(dtots));
        }
Ejemplo n.º 10
0
        public int themPhieuTraSach(DTO_TRASACH dtophieuts)
        {
            try
            {
                _conn.Open();

                string sqlthem = "", sqllay = "";

                sqlthem = string.Format("INSERT INTO TRASACH (ID_USER, NGAYTRA, SONGAYTRE," +
                                        " TIENTRE, TIENBOITHUONG, TIENTHUESACH, TONGTIEN, CREATED_AT)" +
                                        " VALUES( {0}, '{1}', {2}, {3}, {4}, {5}, {6}, '{7}' )", dtophieuts.ID_USER,
                                        dtophieuts.NGAYTRA, dtophieuts.SONGAYTRE, dtophieuts.TIENTRE, dtophieuts.TIENBOITHUONG,
                                        dtophieuts.TIENTHUESACH, dtophieuts.TONGTIEN, dtophieuts.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 TRASACH WHERE ID_USER = {0} AND CREATED_AT = '{1}'",
                                           dtophieuts.ID_USER, dtophieuts.CREATED_AT.ToString("yyyy-MM-dd hh:mm:ss"));

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

                    sda.Fill(dtsacht);


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

            return(-1);
        }
Ejemplo n.º 11
0
        public bool themPhieuTraSach(ref DTO_TRASACH dtots, List <int> lsmasach, int ctrltinhieu)
        {
            BLL_Sach          bllsach = new BLL_Sach();
            BLL_PhieuMuonSach bllphieums = new BLL_PhieuMuonSach();
            int idtrasach = 0, numsachhong = dtots.TIENBOITHUONG;

            khoiTao_DoiTuongTraSach(ref dtots);

            foreach (int idsach in lsmasach)
            {
                int ishong = (numsachhong-- > 0 ? 1 : 0);
                tra_TungSach(ref dtots, idsach, ishong);
            }

            if (ctrltinhieu == 1)
            {
                return(true);
            }

            idtrasach = dalphieuts.themPhieuTraSach(dtots);

            if (idtrasach > -1)
            {
                foreach (int idsach in lsmasach)
                {
                    themCTP_TraSach(idtrasach, idsach);
                    bllsach.suaTinhTrangSach(idsach, "Con Hang");
                    bllphieums.suaCTP_MuonSach(dtots.ID_USER, idsach);
                }

                bllphieums.tongKet_MuonSach(dtots.ID_USER);

                return(true);
            }

            return(false);
        }