private void KtraSuaCTPX()
        {
            try
            {
                ChiTietPX_DTO ctpx = new ChiTietPX_DTO();
                ctpx.MaPX         = cboMaPX.Text.Trim();
                ctpx.MaHang       = cboMaHangXuat.Text.Trim();
                ctpx.TenHangXuat  = txtTenHangXuat.Text.Trim();
                ctpx.SLXuat       = int.Parse(txtSLXuat.Text.ToString());
                ctpx.DonGiaXuat   = int.Parse(txtDonGiaXuat.Text.ToString());
                ctpx.TongTienXuat = int.Parse(lbTienXuat.Text.ToString());
                kiemtra_rong();

                if (ctpxBLL.SuaChiTietPX(ctpx))
                {
                    MessageBox.Show("Sửa thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Sửa không thành công!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                Load_ChiTietPX();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public bool SuaChiTietPX(ChiTietPX_DTO ctpn)
        {
            OpenConnection();
            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "update CHITIET_PN set  TEN_HANG_XUAT=@TenHangXuat, SL_XUAT=@SLXuat, ID=@ID, DON_GIA_XUAT=@DonGiaXuat, TONG_TIEN_XUAT=@TongTienXuat where  MA_PX=@MaPX and MA_HANG=@MaHang";
            cmd.Connection  = conn;
            cmd.Parameters.Add("@MaPX", SqlDbType.VarChar).Value         = ctpn.MaPX;
            cmd.Parameters.Add("@MaHang", SqlDbType.VarChar).Value       = ctpn.MaHang;
            cmd.Parameters.Add("@TenHangXuat", SqlDbType.NVarChar).Value = ctpn.TenHangXuat;
            cmd.Parameters.Add("@SLXuat", SqlDbType.Int).Value           = ctpn.SLXuat;
            cmd.Parameters.Add("@ID", SqlDbType.Int).Value           = ctpn.ID;
            cmd.Parameters.Add("@DonGiaXuat", SqlDbType.Int).Value   = ctpn.DonGiaXuat;
            cmd.Parameters.Add("@TongTienXuat", SqlDbType.Int).Value = ctpn.TongTienXuat;
            int kq = cmd.ExecuteNonQuery();

            if (kq > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public bool ThemChiTietPX(ChiTietPX_DTO ctpn)
        {
            OpenConnection();
            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "insert into  CHITIET_PX values(@MaPX, @MaHang, @TenHangXuat, @SLXuat, @ID, @DonGiaXuat, @TongTienXuat)";
            cmd.Connection  = conn;
            cmd.Parameters.Add("@MaPX", SqlDbType.VarChar).Value         = ctpn.MaPX;
            cmd.Parameters.Add("@MaHang", SqlDbType.VarChar).Value       = ctpn.MaHang;
            cmd.Parameters.Add("@TenHangXuat", SqlDbType.NVarChar).Value = ctpn.TenHangXuat;
            cmd.Parameters.Add("@SLXuat", SqlDbType.Int).Value           = ctpn.SLXuat;
            cmd.Parameters.Add("@ID", SqlDbType.Int).Value           = ctpn.ID;
            cmd.Parameters.Add("@DonGiaXuat", SqlDbType.Int).Value   = ctpn.DonGiaXuat;
            cmd.Parameters.Add("@TongTienXuat", SqlDbType.Int).Value = ctpn.TongTienXuat;
            int kq = cmd.ExecuteNonQuery();

            if (kq > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public List <ChiTietPX_DTO> ChiTietPX(string mapx)
        {
            List <ChiTietPX_DTO> ttctpx = new List <ChiTietPX_DTO>();

            OpenConnection();
            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "select * from CHITIET_PX where MA_PX=@MaPX;";
            cmd.Connection  = conn;
            cmd.Parameters.Add("@MaPX", SqlDbType.VarChar).Value = mapx;
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                ChiTietPX_DTO ctpx = new ChiTietPX_DTO();
                ctpx.MaPX         = reader.GetString(0);
                ctpx.MaHang       = reader.GetString(1);
                ctpx.TenHangXuat  = reader.GetString(2);
                ctpx.SLXuat       = reader.GetInt32(3);
                ctpx.ID           = reader.GetInt32(4);
                ctpx.DonGiaXuat   = reader.GetInt32(5);
                ctpx.TongTienXuat = reader.GetInt32(6);
                ttctpx.Add(ctpx);
            }
            if (reader != null)
            {
                reader.Close();
            }
            return(ttctpx);
        }
 public bool SuaChiTietPX(ChiTietPX_DTO ctpx)
 {
     return(ctpxDAL.SuaChiTietPX(ctpx));
 }
 public bool ThemChiTietPX(ChiTietPX_DTO ctpx)
 {
     return(ctpxDAL.ThemChiTietPX(ctpx));
 }