private TargetSalesViewModel GetTargetSalesViewModel(SalesTarget item, List <RHHeader> rhHeaders) { TargetSalesViewModel model = new TargetSalesViewModel() { RayonCode = item.RayonCode, AchiGroup = item.AchiGroup, Material = item.Material, Division = item.Division, Target = item.Target.Value.ToString("N0"), SLM_NIK = item.SLM.Value, SLM_Name = rhHeaders.FirstOrDefault(x => x.RayonCode.Equals(item.RayonCode)).SLMObj1.FullName, FSS_NIK = item.FSS.Value, FSS_Name = rhHeaders.FirstOrDefault(x => x.RayonCode.Equals(item.RayonCode)).FSSObj1.FullName, Bulan = item.Bulan.Value, Tahun = item.Tahun.Value }; return(model); }
private List <TargetSalesViewModel> GetListTargetSalesViewModel(HttpPostedFileBase postedFile) { IWorkbook workbook = GetWorkbook(postedFile); if (workbook == null) { return(null); } ISheet sheet = workbook.GetSheetAt(0); List <TargetSalesViewModel> result = new List <TargetSalesViewModel>(); TargetSalesViewModel model = null; object obj = null; int tempInt = 0; List <string> listRemarks = null; for (int i = 1; i <= sheet.LastRowNum; i++) { tempInt = 0; listRemarks = new List <string>(); try { IRow row = sheet.GetRow(i); if (row == null) { continue; } model = new TargetSalesViewModel(); obj = GetObjFromCell(row.GetCell(0)); model.FSS_NIK = obj == null ? 0 : Convert.ToInt32(obj.ToString().Trim()); obj = GetObjFromCell(row.GetCell(1)); model.FSS_Name = obj == null ? null : obj.ToString().Trim(); obj = GetObjFromCell(row.GetCell(2)); model.SLM_NIK = obj == null ? 0 : Convert.ToInt32(obj.ToString().Trim()); obj = GetObjFromCell(row.GetCell(3)); model.SLM_Name = obj == null ? null : obj.ToString().Trim(); obj = GetObjFromCell(row.GetCell(4)); model.RayonCode = obj == null ? null : obj.ToString().Trim(); obj = GetObjFromCell(row.GetCell(5)); model.AchiGroup = obj == null ? null : obj.ToString().Trim(); obj = GetObjFromCell(row.GetCell(6)); model.Division = obj == null ? null : obj.ToString().Trim(); obj = GetObjFromCell(row.GetCell(7)); model.Material = obj == null ? null : obj.ToString().Trim(); obj = GetObjFromCell(row.GetCell(8)); model.Bulan = obj == null ? 0 : Convert.ToInt32(obj.ToString().Trim()); obj = GetObjFromCell(row.GetCell(9)); model.Tahun = obj == null ? 0 : Convert.ToInt32(obj.ToString().Trim()); obj = GetObjFromCell(row.GetCell(10)); model.Target = obj == null ? "0" : double.Parse(obj.ToString().Trim()).ToString("N0"); } catch (Exception ex) { //model.Remarks = StaticMessage.ERR_INVALID_ROW_XLS; } finally { if (!string.IsNullOrEmpty(model.RayonCode)) { result.Add(model); } } } return(result); }