Exemple #1
0
        public static The_DTO layTTThe(string maThe)
        {
            SqlConnection conn = SQLConn.connect();

            conn.Open();
            The_DTO the = new The_DTO();

            the.MaThe = maThe;
            SqlCommand cmd          = new SqlCommand("Select NgayCapThe from The where MaThe = '" + maThe + "'", conn);
            string     chuoiNgayCap = cmd.ExecuteScalar().ToString();
            DateTime   ngayCap      = new DateTime();

            DateTime.TryParse(chuoiNgayCap, out ngayCap);
            the.NgayCapThe = ngayCap;
            SqlCommand cmd1            = new SqlCommand("Select NgayHetHan from The where MaThe = '" + maThe + "'", conn);
            string     chuoiNgayHetHan = cmd1.ExecuteScalar().ToString();
            DateTime   ngayHetHan      = new DateTime();

            DateTime.TryParse(chuoiNgayHetHan, out ngayHetHan);
            the.NgayHetHan = ngayHetHan;
            SqlCommand cmd2 = new SqlCommand("Select SoSachDuocMuon from The where MaThe = '" + maThe + "'", conn);

            the.SoSachDuocMuon = Convert.ToInt32(cmd2.ExecuteScalar().ToString());
            SqlCommand cmd3 = new SqlCommand("Select SoSachDangMuon from The where MaThe = '" + maThe + "'", conn);

            the.SoSachDangMuon = Convert.ToInt32(cmd3.ExecuteScalar().ToString());
            conn.Close();
            return(the);
        }
Exemple #2
0
        public static void suaThe(The_DTO the)
        {
            SqlConnection conn = SQLConn.connect();
            SqlCommand    cmd  = new SqlCommand("sp_suathe", conn);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@mathe", SqlDbType.VarChar).Value      = the.MaThe;
            cmd.Parameters.Add("@madocgia", SqlDbType.VarChar).Value   = the.MaDocGia;
            cmd.Parameters.Add("@maloaithe", SqlDbType.VarChar).Value  = the.MaLoaiThe;
            cmd.Parameters.Add("@ngaycapthe", SqlDbType.Date).Value    = the.NgayCapThe;
            cmd.Parameters.Add("@ngayhethan", SqlDbType.Date).Value    = the.NgayHetHan;
            cmd.Parameters.Add("@sosachduocmuon", SqlDbType.Int).Value = the.SoSachDuocMuon;
            cmd.Parameters.Add("@sosachdangmuon", SqlDbType.Int).Value = the.SoSachDangMuon;
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
        }
 private void btnOkThem_Click(object sender, EventArgs e)
 {
     if (DateTime.Compare(dtpNgayTao.Value, dtpNgayHetHan.Value) < 0)
     {
         if ((txtMaThe.Text != "") && (txtMaDG.Text != "") && (txtSachDcMuon.Text != ""))
         {
             try
             {
                 The_DTO the = new The_DTO(txtMaThe.Text, txtMaDG.Text, (string)cboLoaiThe.SelectedValue, dtpNgayTao.Value, dtpNgayHetHan.Value, Convert.ToInt32(txtSachDcMuon.Text), Convert.ToInt32(txtSachDangMuon.Text));
                 BUS_OBJ.themThe(the);
                 HienThiDuLieu();
             }
             catch (Exception)
             {
                 MetroFramework.MetroMessageBox.Show(this, "Mã thẻ bị trùng. \nKhông thể thêm mới", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 //MessageBox.Show(ex.Message);
             }
             finally
             {
                 btnCancel_Click(sender, e);
                 //if (conn.State == ConnectionState.Open) conn.Close();
             }
         }
         else
         {
             MetroFramework.MetroMessageBox.Show(this, "Nhập thiếu dữ liệu.", "Lỗi.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             if (txtSachDcMuon.Text == "")
             {
                 txtSachDcMuon.Focus();
             }
             if (txtMaDG.Text == "")
             {
                 txtMaDG.Focus();
             }
             if (txtMaThe.Text == "")
             {
                 txtMaThe.Focus();
             }
         }
     }
     else
     {
         MetroFramework.MetroMessageBox.Show(this, "Nhập lỗi, ngày hết hạn trước ngày tạo.", "Lỗi.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
Exemple #4
0
 private void autoThemThe()
 {
     try
     {
         if (BUS_OBJ.demSoTheTheoTen(txtMaDG.Text) > 0)
         {
             MetroFramework.MetroMessageBox.Show(this, "Dữ liệu bị trùng, mã thẻ đã tồn tại.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
         {
             DateTime ngayCapThe = DateTime.Now;
             DateTime ngayHetHan = DateTime.Now;
             int      soSachDuocMuon = 0, soSachDangMuon = 0;
             if (string.Compare((string)cboLoaiDG.SelectedValue, "103") == 0)
             {
                 ngayHetHan     = DateTime.Now.AddYears(1);
                 soSachDuocMuon = 2;
             }
             else if (string.Compare((string)cboLoaiDG.SelectedValue, "102") == 0)
             {
                 ngayHetHan     = DateTime.Now.AddYears(4);
                 soSachDuocMuon = 5;
             }
             else if (string.Compare((string)cboLoaiDG.SelectedValue, "101") == 0)
             {
                 ngayHetHan     = DateTime.Now.AddYears(5);
                 soSachDuocMuon = 8;
             }
             The_DTO the = new The_DTO(txtMaDG.Text, txtMaDG.Text, (string)cboLoaiDG.SelectedValue, ngayCapThe, ngayHetHan, soSachDuocMuon, soSachDangMuon);
             BUS_OBJ.themThe(the);
         }
     }
     catch (Exception ex)
     {
         MetroFramework.MetroMessageBox.Show(this, "Mã thẻ mượn sách đã tồn tại. \nKhông thể thêm mới thẻ", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     finally
     {
         //if (conn.State == ConnectionState.Open) conn.Close();
     }
 }
Exemple #5
0
 public static void suaThe(The_DTO the)
 {
     Sach_DAO.suaThe(the);
 }
Exemple #6
0
 public static void themThe(The_DTO the)
 {
     Sach_DAO.themThe(the);
 }