示例#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;
     }
 }
示例#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);
            }
        }
示例#3
0
        public static bool UpdateTongTien(ChiTietNhapDTO hh)
        {
            string sTruyVan = string.Format("update tblHoaDonNhap set TongTien=(select sum(SoLuong*DonGia) from tblChiTietNhap a where a.MaHDNhap={0}) where MaHDNhap={0}", hh.MaHDNhap);

            con = DataProvider.KetNoi();
            DataProvider.ThucThiTruyVan(sTruyVan, con);
            DataProvider.DongKetNoi(con);
            return(true);
        }
示例#4
0
 public static ChiTietNhap MappingChiTietNhap(this ChiTietNhapDTO chitietnhapDTO)
 {
     return(new ChiTietNhap
     {
         MaNhap = chitietnhapDTO.MaNhap,
         MaMon = chitietnhapDTO.MaMon,
         DVT = chitietnhapDTO.DVT,
         Ngay = chitietnhapDTO.Ngay,
         TongTien = chitietnhapDTO.TongTien,
         SoLuong = chitietnhapDTO.SoLuong
     });
 }
示例#5
0
        public static bool Xoa(ChiTietNhapDTO ct)
        {
            string sTruyVan = string.Format("update tblHangHoa set SoLuong=SoLuong-{0} where MaHangHoa={1}", ct.SoLuong, ct.MaHangHoa);

            con = DataProvider.KetNoi();
            DataProvider.ThucThiTruyVan(sTruyVan, con);
            string s = string.Format("delete tblChiTietNhap where MaHDNhap={0} and MaHangHoa={1}", ct.MaHDNhap, ct.MaHangHoa);

            DataProvider.ThucThiTruyVan(s, con);
            DataProvider.DongKetNoi(con);
            return(true);
        }
示例#6
0
        public static bool themmoi(ChiTietNhapDTO hh)
        {
            string s = string.Format("insert into tblHangHoa values ({0},N'{1}',{2},{3},{4},N'{5}')", hh.MaHangHoa, hh.TenHang, hh.SoLuong, hh.DonGia, hh.GiaXuat, hh.GhiChu);

            con = DataProvider.KetNoi();
            DataProvider.ThucThiTruyVan(s, con);
            string sTruyVan = string.Format("insert into tblChiTietNhap values ({0},{1},{2},{3})", hh.MaHDNhap, hh.MaHangHoa, hh.SoLuong, hh.DonGia);

            DataProvider.ThucThiTruyVan(sTruyVan, con);
            DataProvider.DongKetNoi(con);
            return(true);
        }
示例#7
0
        public static bool SuaCT(ChiTietNhapDTO hh)
        {
            string sTruyVan = string.Format("update tblChiTietNhap set SoLuong={0},DonGia={1} where MaHDNhap={2} and MaHangHoa={3}", hh.SoLuong, hh.DonGia, hh.MaHDNhap, hh.MaHangHoa);

            con = DataProvider.KetNoi();
            DataProvider.ThucThiTruyVan(sTruyVan, con);
            string s = string.Format("update tblHangHoa set GiaNhap={0},GiaXuat={1},GhiChu=N'{2}' where MaHangHoa={3}", hh.DonGia, hh.DonGia * 1.15, hh.GhiChu, hh.MaHangHoa);

            DataProvider.ThucThiTruyVan(s, con);
            string s1 = string.Format("update tblHangHoa set SoLuong=A from (select Sum(SoLuong)A from tblChiTietNhap where MaHangHoa={0})A where MaHangHoa={0}", hh.MaHangHoa);

            DataProvider.ThucThiTruyVan(s1, con);
            DataProvider.DongKetNoi(con);
            return(true);
        }
示例#8
0
        public static bool them(ChiTietNhapDTO hh)
        {
            string sTruyVan = string.Format("insert into tblChiTietNhap values ({0},{1},{2},{3})", hh.MaHDNhap, hh.MaHangHoa, hh.SoLuong, hh.DonGia);

            con = DataProvider.KetNoi();
            DataProvider.ThucThiTruyVan(sTruyVan, con);
            string s = string.Format("update tblHangHoa set GiaNhap={0},GiaXuat={1},GhiChu=N'{2}' where MaHangHoa={3}", hh.DonGia, hh.GiaXuat, hh.GhiChu, hh.MaHangHoa);

            DataProvider.ThucThiTruyVan(s, con);
            string s1 = string.Format("update tblHangHoa set SoLuong=A from (select Sum(SoLuong)A from tblChiTietNhap where MaHangHoa={0})A where MaHangHoa={0}", hh.MaHangHoa);

            DataProvider.ThucThiTruyVan(s1, con);
            DataProvider.DongKetNoi(con);
            return(true);
        }
示例#9
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);
        }
示例#10
0
 public void themChiTietNhap(ChiTietNhapDTO chitietnhapDTO)
 {
     _chitietnhapRepository.ThemChiTietNhap(chitietnhapDTO.MappingChiTietNhap());
 }
示例#11
0
 public void suaChiTietNhap(ChiTietNhapDTO chitietnhapDTO)
 {
     _chitietnhapRepository.SuaChiTietNhap(chitietnhapDTO.MappingChiTietNhap());
 }