Example #1
0
 private void dgvchitiet_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == 1)
     {
         if (x == 1)
         {
             try { dgvchitiet.Rows.RemoveAt(e.RowIndex); }
             catch { }
             return;
         }
         ChiTietNhapDTO hh = new ChiTietNhapDTO();
         hh.TenHang  = dgvchitiet.Rows[e.RowIndex].Cells[2].Value.ToString();
         hh.MaHDNhap = int.Parse(txtMaHD.Text.ToString());
         DataTable dt = HoaDonNhapDAO.TimHangHoa(hh.TenHang);
         try
         {
             hh.SoLuong   = int.Parse(dgvchitiet.Rows[e.RowIndex].Cells[3].Value.ToString());
             hh.MaHangHoa = int.Parse(dt.Rows[0][0].ToString());
             ChiTietNhapDAO.Xoa(hh);
             LoadChiTiet(int.Parse(txtMaHD.Text.ToString()));
             HoaDonNhapDTO hd = new HoaDonNhapDTO();
             hd.MaHDNhap = int.Parse(txtMaHD.Text.ToString());
         }
         catch
         {
             try { dgvchitiet.Rows.RemoveAt(e.RowIndex); }
             catch { }
         }
     }
     else
     {
         return;
     }
 }
Example #2
0
        private void Sua()
        {
            HoaDonNhapDTO hd = new HoaDonNhapDTO();

            hd.MaHDNhap = int.Parse(txtMaHD.Text.ToString());
            hd.NgayNhap = dateNhap.Value.ToShortDateString();
            hd.MaNhaCC  = (int)cboCC.SelectedValue;
            hd.TongTien = 0;
            HoaDonNhapDAO.sua(hd);
            ChiTietNhapDTO hh = new ChiTietNhapDTO();

            hh.MaHDNhap = int.Parse(txtMaHD.Text.ToString());
            for (int i = 0; i < dgvchitiet.RowCount - 1; i++)
            {
                hh.TenHang = dgvchitiet.Rows[i].Cells[2].Value.ToString();
                hh.SoLuong = int.Parse(dgvchitiet.Rows[i].Cells[3].Value.ToString());
                hh.DonGia  = int.Parse(dgvchitiet.Rows[i].Cells[4].Value.ToString());
                hh.GiaXuat = int.Parse(dgvchitiet.Rows[i].Cells[4].Value.ToString()) * 2;
                try { hh.GhiChu = dgvchitiet.Rows[i].Cells[0].Value.ToString(); }
                catch { }
                DataTable dt = HoaDonNhapDAO.TimHangHoa(hh.TenHang);
                try
                {
                    hh.MaHangHoa = int.Parse(dt.Rows[0][0].ToString());
                    ChiTietNhapDAO.SuaCT(hh);
                }
                catch
                {
                    hh.MaHangHoa = ChiTietNhapDAO.IDMax() + 1;
                    ChiTietNhapDAO.themmoi(hh);
                }
                HoaDonNhapDAO.UpdateTongTien(hh);
            }
        }
Example #3
0
        private void Xoa()
        {
            HoaDonNhapDTO  hd = new HoaDonNhapDTO();
            ChiTietNhapDTO ct = new ChiTietNhapDTO();

            ct.MaHDNhap = int.Parse(txtMaHD.Text.ToString());
            hd.MaHDNhap = int.Parse(txtMaHD.Text.ToString());
            for (int i = 0; i < dgvchitiet.RowCount; i++)
            {
                DataTable dt = HoaDonNhapDAO.TimHangHoa(dgvchitiet.Rows[i].Cells[2].Value.ToString());
                try
                {
                    ct.SoLuong   = int.Parse(dgvchitiet.Rows[i].Cells[3].Value.ToString());
                    ct.MaHangHoa = int.Parse(dt.Rows[0][0].ToString());
                    ChiTietNhapDAO.Xoa(ct);
                }
                catch { }
            }
            HoaDonNhapDAO.Xoa(hd);
        }