Beispiel #1
0
 public Hoadon LayHoaDon(string mahd)
 {
     using (SqlConnection connection = new SqlConnection(connectionString))
     {
         string     sql = @"SELECT * FROM HOADON WHERE maHD = @mahd";
         SqlCommand cmd = new SqlCommand(sql, connection);
         cmd.Parameters.AddWithValue("@mahd", mahd);
         connection.Open();
         SqlDataReader reader = cmd.ExecuteReader();
         if (reader.Read())
         {
             Hoadon hd = new Hoadon
             {
                 MaHD         = (string)reader["maHD"],
                 MaNV         = (string)reader["maNV"],
                 MaPhong      = reader["maPhong"].ToString(),
                 MaCongToDien = (string)reader["maCongToDien"],
                 MaCongToNuoc = (string)reader["maCongToNuoc"],
                 TongTien     = (long)reader["tongTien"],
                 NgayGhi      = reader["ngayGhi"].ToString(),
             };
             return(hd);
         }
     }
     return(null);
 }
Beispiel #2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            Hoadon ph = LayDuLieuTuForm();

            HoaDonDAO phDAO = new HoaDonDAO();

            bool exist = phDAO.KTMaHD(ph.MaHD);

            if (exist)
            {
                lblThongBao.Text = "Mã mã hóa đơn đã tồn tại";
            }
            else
            {
                bool result = phDAO.Them(ph);
                if (result)
                {
                    lblThongBao.Text = "Thêm hóa đơn thành công";
                    LayDuLieu();
                }
                else
                {
                    lblThongBao.Text = "Có lỗi, vui lòng thử lại!";
                }
            }
        }
Beispiel #3
0
        private Hoadon LayDuLieuTuForm()
        {
            string mahd     = txtMaHĐ.Text;
            string manv     = txtMaNV.Text;
            string maphong  = txtMaPhong.Text;
            string mctn     = txtMaCTN.Text;
            string mctd     = txtMaCTD.Text;
            string ngay     = txtNgayGhi.Text;
            long   tongtien = long.Parse(TextBox1.Text);



            Hoadon ph = new Hoadon
            {
                MaHD         = mahd,
                MaNV         = manv,
                MaPhong      = maphong,
                MaCongToDien = mctd,
                MaCongToNuoc = mctn,
                NgayGhi      = ngay,
                TongTien     = tongtien
            };

            return(ph);
        }
Beispiel #4
0
 public void DoDuLieuVaoCacTruong(Hoadon nv)
 {
     txtMaHĐ.Text    = nv.MaHD;
     txtMaNV.Text    = nv.MaNV;
     txtMaPhong.Text = nv.MaPhong;
     txtMaCTD.Text   = nv.MaCongToDien;
     txtMaCTN.Text   = nv.MaCongToNuoc;
     txtNgayGhi.Text = nv.NgayGhi;
     TextBox1.Text   = nv.TongTien.ToString();
 }
Beispiel #5
0
        protected void gvHoaDon_SelectedIndexChanged(object sender, EventArgs e)
        {
            string    manv  = gvHoaDon.SelectedRow.Cells[0].Text;
            HoaDonDAO nvDAO = new HoaDonDAO();
            Hoadon    nv    = nvDAO.LayHoaDon(manv);

            if (nv != null)
            {
                DoDuLieuVaoCacTruong(nv);
            }
        }
Beispiel #6
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            Hoadon    hd     = LayDuLieuTuForm();
            HoaDonDAO nvDAO  = new HoaDonDAO();
            bool      result = nvDAO.ChinhSua(hd);

            if (result)
            {
                lblThongBao.Text = "Cập nhật thành công cho nhân viên: " + hd.MaHD;
                LayDuLieu();
            }
            else
            {
                lblThongBao.Text = "Cập nhật không thành công, vui lòng kiểm tra lại";
            }
        }
Beispiel #7
0
        public bool Them(Hoadon hd)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = @"INSERT INTO HOADON(maHD,maNV,maPhong,maCongToDien,maCongToNuoc,tongTien,ngayGhi)
                            VALUES(@mahd, @manv, @maphong, @mctd, @mctn, @tongtien, @ngayghi)";
                {
                    SqlCommand command = new SqlCommand(sql, connection);
                    command.Parameters.AddWithValue("@mahd", hd.MaHD);
                    command.Parameters.AddWithValue("@manv", hd.MaNV);
                    command.Parameters.AddWithValue("@maphong", hd.MaPhong);
                    command.Parameters.AddWithValue("@mctd", hd.MaCongToDien);
                    command.Parameters.AddWithValue("@mctn", hd.MaCongToNuoc);
                    command.Parameters.AddWithValue("@tongtien", hd.TongTien);
                    command.Parameters.AddWithValue("@ngayghi", Convert.ToDateTime(hd.NgayGhi));
                    connection.Open();
                    int result = command.ExecuteNonQuery();

                    return(result >= 1);
                }
            }
        }
Beispiel #8
0
 public bool ChinhSua(Hoadon nv)
 {
     using (SqlConnection connection = new SqlConnection(connectionString))
     {
         string     sql     = @"UPDATE HOADON SET maHD=@mahd,maNV=@manv,maPhong=@maphong,maCongToDien=@mctd,maCongToNuoc=@mctn,tongTien=@tongtien,ngayGhi=@ngayghi WHERE maHD = @mahd";
         SqlCommand command = new SqlCommand(sql, connection);
         command.Parameters.AddWithValue("@mahd", nv.MaHD);
         command.Parameters.AddWithValue("@manv", nv.MaNV);
         command.Parameters.AddWithValue("@maphong", nv.MaPhong);
         command.Parameters.AddWithValue("@mctd", nv.MaCongToDien);
         command.Parameters.AddWithValue("@mctn", nv.MaCongToNuoc);
         command.Parameters.AddWithValue("@tongtien", nv.TongTien);
         command.Parameters.AddWithValue("@ngayghi", Convert.ToDateTime(nv.NgayGhi));
         connection.Open();
         int result = command.ExecuteNonQuery();
         if (result >= 1)
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #9
0
 internal bool Them(Hoadon ph)
 {
     throw new NotImplementedException();
 }