private void btnThem_Click(object sender, EventArgs e)
        {
            //int idSP = cboTenSP.SelectedIndex;
            int    idSP    = Int32.Parse(idsp.Text);
            string tenSP   = Convert.ToString(cboTenSP.Text);
            int    soLuong = 0;

            if (txtSoLuong.Text == "")
            {
                MessageBox.Show("Bạn phải nhập số lượng lớn hơn 0", "Thông báo");
                return;
            }
            else
            {
                soLuong = Convert.ToInt32(txtSoLuong.Text);
            }


            var query1 = new CTPhieuNhap();

            query1.TenSP   = tenSP;
            query1.MaSP    = idSP;
            query1.SoLuong = soLuong;



            List <CTPhieuNhap> danhsach = new List <CTPhieuNhap>();

            danhsach.Add(query1);

            try
            {
                bool flag = false;
                for (int i = 0; i < MySession.ChiTietPhieuNhap.Count; i++)
                {
                    if (MySession.ChiTietPhieuNhap[i].MaSP == danhsach[0].MaSP)
                    {
                        MySession.ChiTietPhieuNhap[i].SoLuong = MySession.ChiTietPhieuNhap[i].SoLuong + 1;
                        flag = true;
                    }
                }
                if (flag == false)
                {
                    foreach (var s in danhsach)
                    {
                        MySession.ChiTietPhieuNhap.Add(s);
                    }
                }
            }
            catch
            {
                MySession.ChiTietPhieuNhap = danhsach;
            }


            dvctnhaphang.DataSource          = null;
            dvctnhaphang.AutoGenerateColumns = false;
            dvctnhaphang.DataSource          = MySession.ChiTietPhieuNhap;
        }
 private void dvctnhaphang_SelectionChanged(object sender, EventArgs e)
 {
     if (dvctnhaphang.SelectedRows.Count > 0)
     {
         CTPhieuNhap sp = (CTPhieuNhap)dvctnhaphang.SelectedRows[0].DataBoundItem;
         cboloaisp.Text  = sp.MaSP.ToString();
         cboTenSP.Text   = sp.TenSP.ToString();
         txtSoLuong.Text = sp.SoLuong.ToString();
     }
 }
        private void btnXoa_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dvctnhaphang.SelectedRows)
            {
                CTPhieuNhap        ctpn = (CTPhieuNhap)row.DataBoundItem;
                int                id   = ctpn.MaSP;
                List <CTPhieuNhap> lst  = new List <CTPhieuNhap>();
                int                i    = 0;

                foreach (var s in MySession.ChiTietPhieuNhap)
                {
                    if (MySession.ChiTietPhieuNhap[i].MaSP != id)
                    {
                        lst.Add(s);
                    }
                    i++;
                }
                MySession.ChiTietPhieuNhap = lst;

                dvctnhaphang.DataSource          = null;
                dvctnhaphang.AutoGenerateColumns = false;
                dvctnhaphang.DataSource          = MySession.ChiTietPhieuNhap;
            }
        }
        private void btnThem_Click(object sender, EventArgs e)
        {
            //int idSP = cboTenSP.SelectedIndex;
            int idSP = Int32.Parse(idsp.Text);
            string tenSP = Convert.ToString(cboTenSP.Text);
            int soLuong = 0;
            if (txtSoLuong.Text == "")
            {
                MessageBox.Show("Bạn phải nhập số lượng lớn hơn 0", "Thông báo");
                return;
            }
            else
            {
                soLuong = Convert.ToInt32(txtSoLuong.Text);
            }

            var query1 = new CTPhieuNhap();
            query1.TenSP = tenSP;
            query1.MaSP = idSP;
            query1.SoLuong = soLuong;

            List<CTPhieuNhap> danhsach = new List<CTPhieuNhap>();
            danhsach.Add(query1);

            try
            {
                bool flag = false;
                for (int i = 0; i < MySession.ChiTietPhieuNhap.Count; i++)
                {
                    if (MySession.ChiTietPhieuNhap[i].MaSP == danhsach[0].MaSP)
                    {
                        MySession.ChiTietPhieuNhap[i].SoLuong = MySession.ChiTietPhieuNhap[i].SoLuong + 1;
                        flag = true;
                    }
                }
                if (flag == false)
                {
                    foreach (var s in danhsach)
                    {
                        MySession.ChiTietPhieuNhap.Add(s);
                    }
                }

            }
            catch
            {
                MySession.ChiTietPhieuNhap = danhsach;

            }

            dvctnhaphang.DataSource = null;
            dvctnhaphang.AutoGenerateColumns = false;
            dvctnhaphang.DataSource = MySession.ChiTietPhieuNhap;
        }