public bool suaCTP_MuonSach(DTO_CHITIETMUONSACH dtoctms)
        {
            try
            {
                _conn.Open();

                string sql = string.Format("UPDATE CHITIETMUONSACH  SET UPDATED_AT = '{0}' WHERE ID IN " +
                                           "(SELECT CT.ID FROM MUONSACH MS, (SELECT * FROM CHITIETMUONSACH) CT " +
                                           "WHERE MS.ID = CT.ID_MUONSACH AND CT.CREATED_AT = CT.UPDATED_AT AND MS.ID_USER = {1} AND CT.ID_SACH = {2})",
                                           dtoctms.UPDATED_AT.ToString("yyyy-MM-dd hh:mm:ss"), dtoctms.ID_MUONSACH, dtoctms.ID_SACH);

                MySqlCommand cmd = new MySqlCommand(sql, _conn);

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

            return(false);
        }
        public bool themCTP_MuonSach(DTO_CHITIETMUONSACH dtoctms)
        {
            try
            {
                _conn.Open();

                string sql = string.Format("INSERT INTO CHITTIETMUONSACH (ID_MUONSACH, ID_SACH, CREATED_AT, UPDATED_AT) VALUES ( {0}, {1}, {2}, {3} )",
                                           dtoctms.ID_MUONSACH, dtoctms.ID_SACH, dtoctms.CREATED_AT.ToString("yyyy-MM-dd hh:mm:ss"), dtoctms.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);
        }
Exemple #3
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);
            }
        }
Exemple #4
0
        public DTO_CHITIETMUONSACH lay_CTMuonSach_ChuaTra(int iddocgia, int idsach)
        {
            try
            {
                _conn.Open();

                string sql = string.Format("SELECT CT.CREATED_AT FROM MUONSACH MS, CHITIETMUONSACH CT " +
                                           "WHERE MS.ID = CT.ID_MUONSACH AND CT.UPDATED_AT IS NULL AND MS.ID_USER = {0} AND CT.ID_SACH = {1}", iddocgia, idsach);

                MySqlDataAdapter    sda     = new MySqlDataAdapter(sql, _conn);
                DataTable           dtctms  = new DataTable();
                DTO_CHITIETMUONSACH dtoctms = new DTO_CHITIETMUONSACH();

                sda.Fill(dtctms);

                if (dtctms.Rows.Count > 0)
                {
                    dtoctms.CREATED_AT = Convert.ToDateTime(dtctms.Rows[0]["CREATED_AT"].ToString());

                    return(dtoctms);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                _conn.Close();
            }

            return(null);
        }
Exemple #5
0
        public bool suaCTP_MuonSach(int iddocgia, int idsach)
        {
            DTO_CHITIETMUONSACH dtoctms = new DTO_CHITIETMUONSACH()
            {
                ID_SACH = idsach, UPDATED_AT = DateTime.Now
            };

            return(dalphieums.suaCTP_MuonSach(iddocgia, dtoctms));
        }
Exemple #6
0
        public bool themCTP_MuonSach(int idmuonsach, int idsach)
        {
            DTO_CHITIETMUONSACH dtoctms = new DTO_CHITIETMUONSACH()
            {
                ID_MUONSACH = idmuonsach, ID_SACH = idsach, CREATED_AT = DateTime.Now
            };

            return(dalphieums.themCTP_MuonSach(dtoctms));
        }
        private void dtgvSachMuon_SelectionChanged(object sender, EventArgs e)
        {
            if (dtgvSachMuon.SelectedRows.Count < 1)
            {
                return;
            }

            DataGridViewRow     sltHang = null;
            DTO_CHITIETMUONSACH dtoctms = null;
            DateTime            datemuonsach;

            try
            {
                sltHang = dtgvSachMuon.SelectedRows[0];

                dtoctms = bllphieums.layCTMuonSach_ChuaTra(
                    Int32.Parse(ttbMaDocGia.Text), Int32.Parse(sltHang.Cells[0].Value.ToString()));

                if (dtoctms != null)
                {
                    datemuonsach = dtoctms.CREATED_AT;

                    ttbNgayMuon.Clear();
                    ttbNgayMuon.Refresh();
                    ttbNgayMuon.Text = datemuonsach.Date.ToString("dd/MM/yyyy");

                    ttbSoNgayTT.Clear();
                    ttbSoNgayTT.Refresh();
                    ttbSoNgayTT.Text = DateTime.Now.Subtract(datemuonsach).Days.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }