public async Task <IHttpActionResult> XuLyChyenSale([FromBody] KH_CHUYEN_SALES datachuyensale) { //if (!ModelState.IsValid) //{ // return BadRequest(ModelState); //} var query = db.KH_CHUYEN_SALES.Where(x => x.MA_KHACH_HANG == datachuyensale.MA_KHACH_HANG).FirstOrDefault(); if (query == null) { KH_CHUYEN_SALES chuyensale = new KH_CHUYEN_SALES(); chuyensale.MA_KHACH_HANG = datachuyensale.MA_KHACH_HANG; chuyensale.SALE_HIEN_THOI = datachuyensale.SALE_HIEN_THOI; chuyensale.KHO_PHU_TRACH = datachuyensale.KHO_PHU_TRACH; db.KH_CHUYEN_SALES.Add(chuyensale); } else { query.KHO_PHU_TRACH = datachuyensale.KHO_PHU_TRACH; query.SALE_CU_2 = query.SALE_CU; query.SALE_CU = query.SALE_HIEN_THOI; query.SALE_HIEN_THOI = datachuyensale.SALE_HIEN_THOI; } try { await db.SaveChangesAsync(); } catch (DbUpdateException) { throw; } //return this.CreatedAtRoute("GetNH_NTTK", new { id = nH_NTTK.SO_CHUNG_TU }, nH_NTTK); return(Ok(datachuyensale)); }
public IHttpActionResult GetKH_CHUYEN_SALES(int id) { KH_CHUYEN_SALES kH_CHUYEN_SALES = db.KH_CHUYEN_SALES.Find(id); if (kH_CHUYEN_SALES == null) { return(NotFound()); } return(Ok(kH_CHUYEN_SALES)); }
public IHttpActionResult PostKH_CHUYEN_SALES(KH_CHUYEN_SALES kH_CHUYEN_SALES) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.KH_CHUYEN_SALES.Add(kH_CHUYEN_SALES); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = kH_CHUYEN_SALES.ID }, kH_CHUYEN_SALES)); }
public IHttpActionResult DeleteKH_CHUYEN_SALES(int id) { KH_CHUYEN_SALES kH_CHUYEN_SALES = db.KH_CHUYEN_SALES.Find(id); if (kH_CHUYEN_SALES == null) { return(NotFound()); } db.KH_CHUYEN_SALES.Remove(kH_CHUYEN_SALES); db.SaveChanges(); return(Ok(kH_CHUYEN_SALES)); }
public IHttpActionResult PutKH_CHUYEN_SALES(string makh, KH_CHUYEN_SALES kH_CHUYEN_SALES) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (makh != kH_CHUYEN_SALES.MA_KHACH_HANG) { return(BadRequest()); } var query = db.KH_CHUYEN_SALES.Where(x => x.MA_KHACH_HANG == makh).FirstOrDefault(); if (query != null) { query.SALE_CU_2 = query.SALE_CU; query.SALE_CU = query.SALE_HIEN_THOI; query.SALE_HIEN_THOI = kH_CHUYEN_SALES.SALE_HIEN_THOI; query.KHO_PHU_TRACH = kH_CHUYEN_SALES.KHO_PHU_TRACH; } // db.Entry(kH_CHUYEN_SALES).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!KH_CHUYEN_SALESExists(id)) { return(NotFound()); } else { throw; } } return(Ok()); }
public ActionResult Import_KhachHang(HttpPostedFileBase file) { try { if (Request != null) { HttpPostedFileBase filetonkho = Request.Files["UploadedFile"]; if ((filetonkho != null) && (filetonkho.ContentLength > 0) && !string.IsNullOrEmpty(filetonkho.FileName)) { string fileName = filetonkho.FileName; string fileContentType = filetonkho.ContentType; byte[] fileBytes = new byte[filetonkho.ContentLength]; var data = filetonkho.InputStream.Read(fileBytes, 0, Convert.ToInt32(filetonkho.ContentLength)); //var usersList = new List<Users>(); using (var package = new ExcelPackage(filetonkho.InputStream)) { var currentSheet = package.Workbook.Worksheets; var workSheet = currentSheet.First(); var noOfCol = workSheet.Dimension.End.Column; var noOfRow = workSheet.Dimension.End.Row; for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++) { makhach = workSheet.Cells[rowIterator, 1].Value.ToString(); tencongty = workSheet.Cells[rowIterator, 2].Value.ToString(); if (workSheet.Cells[rowIterator, 3].Value != null) { phanloaikhach = workSheet.Cells[rowIterator, 3].Value.ToString(); } else { phanloaikhach = ""; } if (workSheet.Cells[rowIterator, 4].Value != null) { nhomnganh = workSheet.Cells[rowIterator, 4].Value.ToString(); } else { nhomnganh = ""; } if (workSheet.Cells[rowIterator, 4].Value != null) { nhomnganh = workSheet.Cells[rowIterator, 4].Value.ToString(); } else { nhomnganh = ""; } if (workSheet.Cells[rowIterator, 5].Value != null) { diachivpgiaodich = workSheet.Cells[rowIterator, 5].Value.ToString(); } else { diachivpgiaodich = ""; } if (workSheet.Cells[rowIterator, 6].Value != null) { diachixuathoadon = workSheet.Cells[rowIterator, 6].Value.ToString(); } else { diachixuathoadon = ""; } if (workSheet.Cells[rowIterator, 7].Value != null) { MST = workSheet.Cells[rowIterator, 7].Value.ToString(); } else { MST = ""; } if (workSheet.Cells[rowIterator, 8].Value != null) { somayban = workSheet.Cells[rowIterator, 8].Value.ToString(); } else { somayban = ""; } if (workSheet.Cells[rowIterator, 9].Value != null) { fax = workSheet.Cells[rowIterator, 9].Value.ToString(); } else { fax = ""; } if (workSheet.Cells[rowIterator, 10].Value != null) { email = workSheet.Cells[rowIterator, 10].Value.ToString(); } else { email = ""; } if (workSheet.Cells[rowIterator, 11].Value != null) { logo = workSheet.Cells[rowIterator, 11].Value.ToString(); } else { logo = ""; } if (workSheet.Cells[rowIterator, 12].Value != null) { website = workSheet.Cells[rowIterator, 12].Value.ToString(); } else { website = ""; } if (workSheet.Cells[rowIterator, 13].Value != null) { tinh = workSheet.Cells[rowIterator, 13].Value.ToString(); } else { tinh = ""; } if (workSheet.Cells[rowIterator, 14].Value != null) { quocgia = workSheet.Cells[rowIterator, 14].Value.ToString(); } else { quocgia = ""; } if (workSheet.Cells[rowIterator, 15].Value != null) { dieukhoanthanhtoan = workSheet.Cells[rowIterator, 15].Value.ToString(); } else { dieukhoanthanhtoan = ""; } if (workSheet.Cells[rowIterator, 16].Value != null) { songayduocno = workSheet.Cells[rowIterator, 16].Value.ToString(); } else { songayduocno = ""; } if (workSheet.Cells[rowIterator, 17].Value != null) { sonotoida = workSheet.Cells[rowIterator, 17].Value.ToString(); } else { sonotoida = ""; } if (workSheet.Cells[rowIterator, 18].Value != null) { tinhtranghoatdong = workSheet.Cells[rowIterator, 18].Value.ToString(); } else { tinhtranghoatdong = ""; } if (workSheet.Cells[rowIterator, 19].Value != null) { tructhuoc = workSheet.Cells[rowIterator, 19].Value.ToString(); } else { tructhuoc = ""; } if (workSheet.Cells[rowIterator, 20].Value != null) { ghichu = workSheet.Cells[rowIterator, 20].Value.ToString(); } else { ghichu = ""; } if (workSheet.Cells[rowIterator, 21].Value != null) { phutrachhienthoi = workSheet.Cells[rowIterator, 21].Value.ToString(); } else { phutrachhienthoi = ""; } if (workSheet.Cells[rowIterator, 22].Value != null) { nguoilienhe = workSheet.Cells[rowIterator, 22].Value.ToString(); } else { nguoilienhe = ""; } if (workSheet.Cells[rowIterator, 23].Value != null) { chucvu = workSheet.Cells[rowIterator, 23].Value.ToString(); } else { chucvu = ""; } if (workSheet.Cells[rowIterator, 24].Value != null) { phongban = workSheet.Cells[rowIterator, 24].Value.ToString(); } else { phongban = ""; } if (workSheet.Cells[rowIterator, 25].Value != null) { ngaysinh = workSheet.Cells[rowIterator, 25].Value.ToString(); } else { ngaysinh = ""; } if (workSheet.Cells[rowIterator, 26].Value != null) { gioitinh = workSheet.Cells[rowIterator, 26].Value.ToString(); } else { gioitinh = ""; } if (workSheet.Cells[rowIterator, 27].Value != null) { sdt1 = workSheet.Cells[rowIterator, 27].Value.ToString(); } else { sdt1 = ""; } if (workSheet.Cells[rowIterator, 28].Value != null) { sdt2 = workSheet.Cells[rowIterator, 28].Value.ToString(); } else { sdt2 = ""; } if (workSheet.Cells[rowIterator, 29].Value != null) { emailcanhan = workSheet.Cells[rowIterator, 29].Value.ToString(); } else { emailcanhan = ""; } if (workSheet.Cells[rowIterator, 30].Value != null) { emailcongty = workSheet.Cells[rowIterator, 30].Value.ToString(); } else { emailcongty = ""; } if (workSheet.Cells[rowIterator, 31].Value != null) { skype = workSheet.Cells[rowIterator, 31].Value.ToString(); } else { skype = ""; } if (workSheet.Cells[rowIterator, 32].Value != null) { facebook = workSheet.Cells[rowIterator, 32].Value.ToString(); } else { facebook = ""; } if (workSheet.Cells[rowIterator, 33].Value != null) { ghichulienhe = workSheet.Cells[rowIterator, 33].Value.ToString(); } else { ghichulienhe = ""; } if (workSheet.Cells[rowIterator, 34].Value != null) { salephutrach = workSheet.Cells[rowIterator, 34].Value.ToString(); } else { salephutrach = ""; } if (workSheet.Cells[rowIterator, 35].Value != null) { sotknganhang = workSheet.Cells[rowIterator, 36].Value.ToString(); } else { sotknganhang = ""; } if (workSheet.Cells[rowIterator, 36].Value != null) { tentaikhoan = workSheet.Cells[rowIterator, 36].Value.ToString(); } else { tentaikhoan = ""; } if (workSheet.Cells[rowIterator, 37].Value != null) { tennganhang = workSheet.Cells[rowIterator, 37].Value.ToString(); } else { tennganhang = ""; } if (workSheet.Cells[rowIterator, 38].Value != null) { chinhanhnganhang = workSheet.Cells[rowIterator, 38].Value.ToString(); } else { chinhanhnganhang = ""; } if (workSheet.Cells[rowIterator, 39].Value != null) { tinhnganhang = workSheet.Cells[rowIterator, 39].Value.ToString(); } else { tinhnganhang = ""; } if (workSheet.Cells[rowIterator, 40].Value != null) { loaitaikhoan = workSheet.Cells[rowIterator, 40].Value.ToString(); } else { loaitaikhoan = ""; } if (workSheet.Cells[rowIterator, 41].Value != null) { ghichu = workSheet.Cells[rowIterator, 41].Value.ToString(); } else { ghichu = ""; } //Thêm khách hàng var query = db.KHs.Where(x => x.MA_KHACH_HANG == makhach).FirstOrDefault(); if (query == null) { KH khachhang = new KH(); khachhang.MA_KHACH_HANG = makhach; khachhang.TEN_CONG_TY = tencongty; if (diachivpgiaodich != "") { khachhang.VAN_PHONG_GIAO_DICH = diachivpgiaodich; } if (diachixuathoadon != "") { khachhang.DIA_CHI_XUAT_HOA_DON = diachixuathoadon; } if (MST != "") { khachhang.MST = MST; } if (somayban != "") { khachhang.HOTLINE = somayban; } if (fax != "") { khachhang.FAX = fax; } if (email != "") { khachhang.EMAIL = email; } if (logo != "") { khachhang.LOGO = logo; } if (website != "") { khachhang.WEBSITE = website; } if (tinh != "") { khachhang.TINH = tinh; } if (quocgia != "") { khachhang.QUOC_GIA = quocgia; } if (dieukhoanthanhtoan != "") { khachhang.DIEU_KHOAN_THANH_TOAN = dieukhoanthanhtoan; } if (songayduocno != "") { khachhang.SO_NGAY_DUOC_NO = Convert.ToInt32(songayduocno); } if (sonotoida != "") { khachhang.SO_NO_TOI_DA = Convert.ToInt32(sonotoida); } if (tinhtranghoatdong != "") { khachhang.TINH_TRANG_HOAT_DONG = tinhtranghoatdong; } if (tructhuoc != "") { khachhang.TRUC_THUOC = tructhuoc; } if (ghichu != "") { khachhang.GHI_CHU = ghichu; } db.KHs.Add(khachhang); db.SaveChanges(); //thêm phụ trách hiện thời if (phutrachhienthoi != "") { KH_CHUYEN_SALES chuyensale = new KH_CHUYEN_SALES(); chuyensale.MA_KHACH_HANG = makhach; chuyensale.SALE_HIEN_THOI = phutrachhienthoi; db.KH_CHUYEN_SALES.Add(chuyensale); } //Thêm phân loại khách var DATA = db.KH_PHAN_LOAI_KHACH.Where(x => x.MA_KHACH_HANG == makhach).FirstOrDefault(); if (DATA != null && phanloaikhach != "") { KH_PHAN_LOAI_KHACH plkhach = new KH_PHAN_LOAI_KHACH(); plkhach.MA_KHACH_HANG = makhach; plkhach.MA_LOAI_KHACH = phanloaikhach; if (nhomnganh != "") { plkhach.NHOM_NGANH = nhomnganh; } db.KH_PHAN_LOAI_KHACH.Add(plkhach); db.SaveChanges(); } //thêm người liên hệ if (nguoilienhe != "") { KH_LIEN_HE lhkhach = new KH_LIEN_HE(); lhkhach.MA_KHACH_HANG = makhach; lhkhach.NGUOI_LIEN_HE = nguoilienhe; if (chucvu != "") { lhkhach.CHUC_VU = chucvu; } if (phongban != "") { lhkhach.PHONG_BAN = phongban; } if (ngaysinh != "") { lhkhach.NGAY_SINH = xulydate.Xulydatetime(ngaysinh); } if (gioitinh != "") { lhkhach.GIOI_TINH = gioitinh; } lhkhach.SDT1 = sdt1; if (sdt2 != "") { lhkhach.SDT2 = sdt2; } if (emailcanhan != "") { lhkhach.EMAIL_CA_NHAN = emailcanhan; } if (emailcongty != "") { lhkhach.EMAIL_CONG_TY = emailcongty; } if (skype != "") { lhkhach.SKYPE = skype; } if (facebook != "") { lhkhach.FACEBOOK = facebook; } if (ghichulienhe != "") { lhkhach.GHI_CHU = ghichu; } db.KH_LIEN_HE.Add(lhkhach); db.SaveChanges(); //thêm sale phụ trách var datalienhe = db.KH_LIEN_HE.Where(x => x.SDT1 == sdt1).FirstOrDefault(); if (datalienhe != null) { KH_SALES_PHU_TRACH salept = new KH_SALES_PHU_TRACH(); salept.ID_LIEN_HE = datalienhe.ID_LIEN_HE; salept.SALES_PHU_TRACH = salephutrach; salept.NGAY_BAT_DAU_PHU_TRACH = DateTime.Today.Date; salept.TRANG_THAI = true; db.KH_SALES_PHU_TRACH.Add(salept); db.SaveChanges(); } //thêm tài khoản ngân hàng if (sotknganhang != "") { KH_TK_NGAN_HANG tkkhach = new KH_TK_NGAN_HANG(); tkkhach.MA_KHACH_HANG = makhach; tkkhach.SO_TAI_KHOAN = sotknganhang; if (tentaikhoan != "") { tkkhach.TEN_TAI_KHOAN = tentaikhoan; } if (tennganhang != "") { tkkhach.TEN_NGAN_HANG = tennganhang; } if (chinhanhnganhang != "") { tkkhach.CHI_NHANH = chinhanhnganhang; } if (tinhnganhang != "") { tkkhach.TINH_TP = tinhnganhang; } if (loaitaikhoan != "") { tkkhach.LOAI_TAI_KHOAN = loaitaikhoan; } if (ghichutaikhoan != "") { tkkhach.GHI_CHU = ghichutaikhoan; } db.KH_TK_NGAN_HANG.Add(tkkhach); db.SaveChanges(); } } } //trường hợp đã có khách hàng, chỉ thêm liên hệ, ... else if (query != null) { //thêm liên hệ if (nguoilienhe != "") { KH_LIEN_HE lhkhach = new KH_LIEN_HE(); lhkhach.MA_KHACH_HANG = makhach; lhkhach.NGUOI_LIEN_HE = nguoilienhe; if (chucvu != "") { lhkhach.CHUC_VU = chucvu; } if (phongban != "") { lhkhach.PHONG_BAN = phongban; } if (ngaysinh != "") { lhkhach.NGAY_SINH = xulydate.Xulydatetime(ngaysinh); } if (gioitinh != "") { lhkhach.GIOI_TINH = gioitinh; } lhkhach.SDT1 = sdt1; if (sdt2 != "") { lhkhach.SDT2 = sdt2; } if (emailcanhan != "") { lhkhach.EMAIL_CA_NHAN = emailcanhan; } if (emailcongty != "") { lhkhach.EMAIL_CONG_TY = emailcongty; } if (skype != "") { lhkhach.SKYPE = skype; } if (facebook != "") { lhkhach.FACEBOOK = facebook; } if (ghichu != "") { lhkhach.GHI_CHU = ghichu; } db.KH_LIEN_HE.Add(lhkhach); db.SaveChanges(); //thêm sale phụ trách var datalienhe = db.KH_LIEN_HE.Where(x => x.SDT1 == sdt1).FirstOrDefault(); if (datalienhe != null) { KH_SALES_PHU_TRACH salept = new KH_SALES_PHU_TRACH(); salept.ID_LIEN_HE = datalienhe.ID_LIEN_HE; salept.SALES_PHU_TRACH = salephutrach; salept.NGAY_BAT_DAU_PHU_TRACH = DateTime.Today.Date; salept.TRANG_THAI = true; db.KH_SALES_PHU_TRACH.Add(salept); db.SaveChanges(); } //thêm tài khoản ngân hàng if (sotknganhang != "") { KH_TK_NGAN_HANG tkkhach = new KH_TK_NGAN_HANG(); tkkhach.MA_KHACH_HANG = makhach; tkkhach.SO_TAI_KHOAN = sotknganhang; if (tentaikhoan != "") { tkkhach.TEN_TAI_KHOAN = tentaikhoan; } if (tennganhang != "") { tkkhach.TEN_NGAN_HANG = tennganhang; } if (chinhanhnganhang != "") { tkkhach.CHI_NHANH = chinhanhnganhang; } if (tinhnganhang != "") { tkkhach.TINH_TP = tinhnganhang; } if (loaitaikhoan != "") { tkkhach.LOAI_TAI_KHOAN = loaitaikhoan; } if (ghichutaikhoan != "") { tkkhach.GHI_CHU = ghichutaikhoan; } db.KH_TK_NGAN_HANG.Add(tkkhach); db.SaveChanges(); } } } so_dong_thanh_cong++; dong = rowIterator; } } } } } catch (Exception Ex) { ViewBag.Error = " Đã xảy ra lỗi, Liên hệ ngay với admin. " + Environment.NewLine + " Thông tin chi tiết về lỗi:" + Environment.NewLine + Ex; ViewBag.Information = "Lỗi tại các dòng: " + dong; } finally { ViewBag.Message = "Đã import thành công " + so_dong_thanh_cong + " dòng"; } return(View()); }
public IHttpActionResult CopyNewKH(string mkh, KhachHanghl thongtinmoi) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var thongtinchung = db.KHs.Where(x => x.MA_KHACH_HANG == mkh).FirstOrDefault(); var diachixuathang = db.KH_DC_XUAT_HANG.Where(x => x.MA_KHACH_HANG == mkh).ToList(); var lienhe = db.KH_LIEN_HE.Where(x => x.MA_KHACH_HANG == mkh).ToList(); var phanloai = db.KH_PHAN_LOAI_KHACH.Where(x => x.MA_KHACH_HANG == mkh).FirstOrDefault(); var taikhoan = db.KH_TK_NGAN_HANG.Where(x => x.MA_KHACH_HANG == mkh).ToList(); var policy = db.KH_POLICY.Where(x => x.MA_KHACH_HANG == mkh).ToList(); var phanhoi = db.KH_PHAN_HOI_KHACH_HANG.Where(x => x.MA_KHACH_HANG == mkh).ToList(); var thongke = db.KH_THONG_KE_MUA_HANG.Where(x => x.MA_KHACH_HANG == mkh).ToList(); KH newkhachhang = new KH(); newkhachhang.MA_KHACH_HANG = GenerateMAKH(); newkhachhang.TEN_CONG_TY = thongtinchung.TEN_CONG_TY; newkhachhang.VAN_PHONG_GIAO_DICH = thongtinchung.VAN_PHONG_GIAO_DICH; newkhachhang.DIA_CHI_XUAT_HOA_DON = thongtinchung.DIA_CHI_XUAT_HOA_DON; newkhachhang.TINH = thongtinchung.TINH; newkhachhang.QUOC_GIA = thongtinchung.QUOC_GIA; newkhachhang.MST = thongtinchung.MST; newkhachhang.HOTLINE = thongtinchung.HOTLINE; newkhachhang.EMAIL = thongtinchung.EMAIL; newkhachhang.FAX = thongtinchung.FAX; newkhachhang.LOGO = thongtinchung.LOGO; newkhachhang.WEBSITE = thongtinchung.WEBSITE; newkhachhang.DIEU_KHOAN_THANH_TOAN = thongtinchung.DIEU_KHOAN_THANH_TOAN; newkhachhang.TINH_TRANG_HOAT_DONG = thongtinchung.TINH_TRANG_HOAT_DONG; newkhachhang.SO_NGAY_DUOC_NO = thongtinchung.SO_NGAY_DUOC_NO; newkhachhang.SO_NO_TOI_DA = thongtinchung.SO_NO_TOI_DA; newkhachhang.GHI_CHU = thongtinchung.GHI_CHU; newkhachhang.TRUC_THUOC = thongtinmoi.TRUC_THUOC; newkhachhang.SALES_TAO = thongtinmoi.SALES_PHU_TRACH; newkhachhang.KHACH_DO_MARKETING_TIM_KIEM = thongtinchung.KHACH_DO_MARKETING_TIM_KIEM; newkhachhang.KHACH_MUA_DOANH_SO_CAO = thongtinchung.KHACH_MUA_DOANH_SO_CAO; newkhachhang.KHACH_MUA_SO_LUONG_NHIEU = thongtinchung.KHACH_MUA_SO_LUONG_NHIEU; newkhachhang.KHACH_DAC_BIET = thongtinchung.KHACH_DAC_BIET; newkhachhang.THONG_TIN_DA_DAY_DU = thongtinchung.THONG_TIN_DA_DAY_DU; newkhachhang.HO_SO_THANH_TOAN = thongtinchung.HO_SO_THANH_TOAN; db.KHs.Add(newkhachhang); db.SaveChanges(); KH_CHUYEN_SALES newchuyensale = new KH_CHUYEN_SALES(); newchuyensale.MA_KHACH_HANG = newkhachhang.MA_KHACH_HANG; newchuyensale.SALE_HIEN_THOI = thongtinmoi.SALES_PHU_TRACH; db.KH_CHUYEN_SALES.Add(newchuyensale); db.SaveChanges(); foreach (var item in diachixuathang) { KH_DC_XUAT_HANG newdiachi = new KH_DC_XUAT_HANG(); newdiachi.MA_KHACH_HANG = newkhachhang.MA_KHACH_HANG; newdiachi.DIA_CHI_XUAT_HANG = item.DIA_CHI_XUAT_HANG; newdiachi.GHI_CHU = item.GHI_CHU; db.KH_DC_XUAT_HANG.Add(newdiachi); db.SaveChanges(); } foreach (var item in diachixuathang) { KH_DC_XUAT_HANG newdiachi = new KH_DC_XUAT_HANG(); newdiachi.MA_KHACH_HANG = newkhachhang.MA_KHACH_HANG; newdiachi.DIA_CHI_XUAT_HANG = item.DIA_CHI_XUAT_HANG; newdiachi.GHI_CHU = item.GHI_CHU; db.KH_DC_XUAT_HANG.Add(newdiachi); db.SaveChanges(); } foreach (var item in lienhe) { KH_LIEN_HE newlienhe = new KH_LIEN_HE(); newlienhe.MA_KHACH_HANG = newkhachhang.MA_KHACH_HANG; newlienhe.NGUOI_LIEN_HE = item.NGUOI_LIEN_HE; newlienhe.CHUC_VU = item.CHUC_VU; newlienhe.PHONG_BAN = item.PHONG_BAN; newlienhe.NGAY_SINH = item.NGAY_SINH; newlienhe.GIOI_TINH = item.GIOI_TINH; newlienhe.EMAIL_CA_NHAN = item.EMAIL_CA_NHAN; newlienhe.EMAIL_CONG_TY = item.EMAIL_CONG_TY; newlienhe.SKYPE = item.SKYPE; newlienhe.FACEBOOK = item.FACEBOOK; newlienhe.GHI_CHU = item.GHI_CHU; newlienhe.SDT1 = item.SDT1; newlienhe.SDT2 = item.SDT2; newlienhe.TINH_TRANG_LAM_VIEC = item.TINH_TRANG_LAM_VIEC; db.KH_LIEN_HE.Add(newlienhe); db.SaveChanges(); } KH_PHAN_LOAI_KHACH newphanloai = new KH_PHAN_LOAI_KHACH(); newphanloai.MA_KHACH_HANG = newkhachhang.MA_KHACH_HANG; newphanloai.MA_LOAI_KHACH = phanloai.MA_LOAI_KHACH; newphanloai.NHOM_NGANH = phanloai.NHOM_NGANH; db.KH_PHAN_LOAI_KHACH.Add(newphanloai); db.SaveChanges(); foreach (var item in taikhoan) { KH_TK_NGAN_HANG newtaikhoan = new KH_TK_NGAN_HANG(); newtaikhoan.MA_KHACH_HANG = newkhachhang.MA_KHACH_HANG; newtaikhoan.SO_TAI_KHOAN = item.SO_TAI_KHOAN; newtaikhoan.TEN_TAI_KHOAN = item.TEN_TAI_KHOAN; newtaikhoan.TEN_NGAN_HANG = item.TEN_NGAN_HANG; newtaikhoan.CHI_NHANH = item.CHI_NHANH; newtaikhoan.TINH_TP = item.TINH_TP; newtaikhoan.LOAI_TAI_KHOAN = item.LOAI_TAI_KHOAN; newtaikhoan.GHI_CHU = item.GHI_CHU; db.KH_TK_NGAN_HANG.Add(newtaikhoan); db.SaveChanges(); } foreach (var item in policy) { KH_POLICY newpolicy = new KH_POLICY(); newpolicy.MA_KHACH_HANG = newkhachhang.MA_KHACH_HANG; newpolicy.MA_NHOM_HANG = item.MA_NHOM_HANG; newpolicy.GIA_BAN = item.GIA_BAN; newpolicy.CK = item.CK; newpolicy.CK_HISTORY_1 = item.CK_HISTORY_1; newpolicy.GIA_HISTORY_1 = item.GIA_HISTORY_1; newpolicy.CK_HISTORY_2 = item.CK_HISTORY_2; newpolicy.GIA_HISTORY_2 = item.GIA_HISTORY_2; newpolicy.CK_HISTORY_3 = item.CK_HISTORY_3; newpolicy.GIA_HISTORY_3 = item.GIA_HISTORY_3; db.KH_POLICY.Add(newpolicy); db.SaveChanges(); } foreach (var item in phanhoi) { KH_PHAN_HOI_KHACH_HANG newphanhoi = new KH_PHAN_HOI_KHACH_HANG(); newphanhoi.MA_KHACH_HANG = newkhachhang.MA_KHACH_HANG; newphanhoi.NGUOI_PHAN_HOI = item.NGUOI_PHAN_HOI; newphanhoi.NGAY_PHAN_HOI = item.NGAY_PHAN_HOI; newphanhoi.THONG_TIN_PHAN_HOI = item.THONG_TIN_PHAN_HOI; db.KH_PHAN_HOI_KHACH_HANG.Add(newphanhoi); db.SaveChanges(); } foreach (var item in thongke) { KH_THONG_KE_MUA_HANG newthongke = new KH_THONG_KE_MUA_HANG(); newthongke.MA_KHACH_HANG = newkhachhang.MA_KHACH_HANG; newthongke.MA_HANG = item.MA_HANG; newthongke.SL_MUA = item.SL_MUA; newthongke.DON_GIA_MUA = item.DON_GIA_MUA; newthongke.NHAN_VIEN_BAN_HANG = item.NHAN_VIEN_BAN_HANG; db.KH_THONG_KE_MUA_HANG.Add(newthongke); db.SaveChanges(); } try { db.SaveChanges(); } catch (DbUpdateException) { throw; } return(Ok(newkhachhang.MA_KHACH_HANG)); }
public ActionResult InsertKhachHang_SaleHienThoi(HttpPostedFileBase file) { using (var db = new ERP_DATABASEEntities()) { try { if (Request != null) { HttpPostedFileBase filetonkho = Request.Files["UploadedFile"]; if ((filetonkho != null) && (filetonkho.ContentLength > 0) && !string.IsNullOrEmpty(filetonkho.FileName)) { string fileName = filetonkho.FileName; string fileContentType = filetonkho.ContentType; byte[] fileBytes = new byte[filetonkho.ContentLength]; var data = filetonkho.InputStream.Read(fileBytes, 0, Convert.ToInt32(filetonkho.ContentLength)); //var usersList = new List<Users>(); using (var package = new ExcelPackage(filetonkho.InputStream)) { var currentSheet = package.Workbook.Worksheets; var workSheet = currentSheet.First(); var noOfCol = workSheet.Dimension.End.Column; var noOfRow = workSheet.Dimension.End.Row; for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++) { var makhachhang = workSheet.Cells[rowIterator, 2].Value.ToString(); var salehienthoi = workSheet.Cells[rowIterator, 4].Value.ToString(); if (makhachhang != null && salehienthoi != null) { KH_CHUYEN_SALES chuyensale = new KH_CHUYEN_SALES(); chuyensale.MA_KHACH_HANG = makhachhang; chuyensale.SALE_HIEN_THOI = salehienthoi; db.KH_CHUYEN_SALES.Add(chuyensale); so_dong_thanh_cong++; dong = rowIterator - 1; } //else // that_bai = rowIterator - 1; db.SaveChanges(); //dong = rowIterator; } } } } } catch (Exception Ex) { ViewBag.Error = " Đã xảy ra lỗi, Liên hệ ngay với admin. " + Environment.NewLine + " Thông tin chi tiết về lỗi:" + Environment.NewLine + Ex; ViewBag.Information = "Lỗi tại dòng thứ: " + dong; } finally { ViewBag.Message = "Đã import thành công " + so_dong_thanh_cong + " dòng"; //ViewBag.Dongloi = "dòng lỗi: " + dong; } return(View("UpdateKhachHang_SaleHienThoi")); } }