コード例 #1
0
        public HISUploadDataDTO GetHISFileUploadDataById(int hfu_id)
        {
            log.MethodStart();
            HISUploadDataDTO objModel = new HISUploadDataDTO();

            using (var trans = _db.Database.BeginTransaction())
            {
                try
                {
                    var objReturn1 = _db.TRHISFileUploads.FirstOrDefault(x => x.hfu_id == hfu_id);

                    objModel = _mapper.Map <HISUploadDataDTO>(objReturn1);

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    // TODO: Handle failure
                    trans.Rollback();
                }
                finally
                {
                    trans.Dispose();
                }
            }


            log.MethodFinish();

            return(objModel);
        }
コード例 #2
0
        public HISUploadDataDTO SaveLabFileUploadData(HISUploadDataDTO model)
        {
            log.MethodStart();

            var currentDateTime        = DateTime.Now;
            HISUploadDataDTO objReturn = new HISUploadDataDTO();

            using (var trans = _db.Database.BeginTransaction())
            {
                try
                {
                    var objModel = new TRHISFileUpload();

                    if (model.hfu_status == 'N')
                    {
                        objModel = _mapper.Map <TRHISFileUpload>(model);

                        objModel.hfu_createdate = currentDateTime;
                        //objModel.hfu_updatedate = currentDateTime;

                        _db.TRHISFileUploads.Add(objModel);
                    }
                    else
                    {
                        objModel                   = _db.TRHISFileUploads.FirstOrDefault(x => x.hfu_id == model.hfu_id);
                        objModel.hfu_status        = model.hfu_status;
                        objModel.hfu_version       = model.hfu_version;
                        objModel.hfu_delete_flag   = model.hfu_delete_flag;
                        objModel.hfu_lab           = model.hfu_lab;
                        objModel.hfu_file_name     = model.hfu_file_name;
                        objModel.hfu_file_path     = model.hfu_file_path;
                        objModel.hfu_file_type     = model.hfu_file_type;
                        objModel.hfu_total_records = model.hfu_total_records;
                        objModel.hfu_error_records = model.hfu_error_records;
                        objModel.hfu_approveduser  = model.hfu_approveduser;
                        objModel.hfu_approveddate  = model.hfu_approveddate;
                        objModel.hfu_updateuser    = model.hfu_approveduser;
                        objModel.hfu_updatedate    = currentDateTime;
                    }

                    _db.SaveChanges();

                    trans.Commit();

                    objReturn = _mapper.Map <HISUploadDataDTO>(objModel);
                }
                catch (Exception ex)
                {
                    // TODO: Handle failure
                    trans.Rollback();
                }
                finally
                {
                    trans.Dispose();
                }
            }

            return(objReturn);
        }
コード例 #3
0
        public async Task <HISUploadDataDTO> GetHISFileUploadDataByIdAsync(int hfu_Id)
        {
            HISUploadDataDTO objList = new HISUploadDataDTO();

            objList = await _apiHelper.GetDataByIdAsync <HISUploadDataDTO>("his_api/GetHISFileUploadDataById", hfu_Id.ToString());

            return(objList);
        }
コード例 #4
0
        public async Task <HISUploadDataDTO> SaveHISFileUploadDataAsync(HISUploadDataDTO model)
        {
            if (model.hfu_id == 0)
            {
                //model.lfu_id = Guid.NewGuid();
                model.hfu_status      = 'N';
                model.hfu_delete_flag = false;
            }
            var HISFile = await _apiHelper.PostDataAsync <HISUploadDataDTO>("his_api/Post_SaveSPFileUploadData", model);

            return(HISFile);
        }
コード例 #5
0
        public async Task <HISUploadDataDTO> SaveFileUploadAsync(IFileListEntry fileEntry, HISUploadDataDTO model)
        {
            HISUploadDataDTO objReturn = new HISUploadDataDTO();

            if (model.hfu_id == 0)
            {
                model.hfu_status      = 'N';
                model.hfu_delete_flag = false;
            }
            else
            {
                model.hfu_status = 'E';
            }

            //model.hfu_updatedate = DateTime.Now;
            objReturn = await _apiHelper.PostDataAsync <HISUploadDataDTO>("his_api/Post_SaveSPFileUploadData", model);

            return(objReturn);
        }
コード例 #6
0
        public HISUploadDataDTO GetHISFileUploadDataById(int hfu_id)
        {
            log.MethodStart();
            HISUploadDataDTO objModel = new HISUploadDataDTO();

            using (var trans = _db.Database.BeginTransaction())
            {
                try
                {
                    //var objReturn1 = _db.TRHISFileUploads.FirstOrDefault(x => x.hfu_id == hfu_id);

                    var objDataList = _db.HISFileUploadDataDTOs.FromSqlRaw <HISUploadDataDTO>("sp_GET_TRHISFileUploadList  {0} ,{1} ,{2} ,{3}, {4}, {5}, {6} , {7}"
                                                                                              , null, null, null, null, 0, null, null
                                                                                              , hfu_id
                                                                                              ).ToList();

                    var objData = objDataList.FirstOrDefault();
                    objModel = _mapper.Map <HISUploadDataDTO>(objData);

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    // TODO: Handle failure
                    trans.Rollback();
                }
                finally
                {
                    trans.Dispose();
                }
            }


            log.MethodFinish();

            return(objModel);
        }
コード例 #7
0
        public async Task <List <STGHISFileUploadDetailDTO> > GetHISDeatilByModelAsync(HISUploadDataDTO model)
        {
            List <STGHISFileUploadDetailDTO> objList = new List <STGHISFileUploadDetailDTO>();

            objList = await _apiHelper.GetDataListByModelAsync <STGHISFileUploadDetailDTO, HISUploadDataDTO>("his_api/GetSTGHISUploadDetail", model);

            return(objList);
        }
コード例 #8
0
        public async Task <bool> GenerateExportWithError(IJSRuntime iJSRuntime, List <HISFileUploadSummaryDTO> HISFileSummary, HISUploadDataDTO HISFileUpload)
        {
            var blnError = false;

            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;

            string strPath = "";
            List <ParameterDTO> objParamList = new List <ParameterDTO>();
            var searchModel = new ParameterDTO()
            {
                prm_code_major = "UPLOAD_PATH"
            };

            objParamList = await _apiHelper.GetDataListByModelAsync <ParameterDTO, ParameterDTO>("dropdownlist_api/GetParameterList", searchModel);

            if (objParamList.FirstOrDefault(x => x.prm_code_minor == "PATH") != null)
            {
                strPath = objParamList.FirstOrDefault(x => x.prm_code_minor == "PATH").prm_value;
            }
            else
            {
                await iJSRuntime.InvokeAsync <object>("ShowAlert", "ไม่พบ Path กรุณาติดต่อผู้ดูแลระบบ");

                blnError = true;
                return(blnError);
            }

            //Read Original File
            string strUploadDate = HISFileUpload.hfu_createdate.Value.ToString("yyyyMMdd");
            var    strFilePath   = Path.Combine(strPath, strUploadDate, HISFileUpload.hfu_hos_code);
            var    strFullPath   = Path.Combine(strFilePath, HISFileUpload.hfu_file_name);

            if (!File.Exists(strFullPath))
            {
                await iJSRuntime.InvokeAsync <object>("ShowAlert", "ไม่พบไฟล์ต้นฉบับ");

                blnError = true;
                return(blnError);
            }

            var extension = Path.GetExtension(HISFileUpload.hfu_file_name);
            var copypath  = strFullPath.Replace(extension, "_ExportWarning" + extension);

            if (File.Exists(copypath))
            {
                File.Delete(copypath);
            }

            File.Copy(strFullPath, copypath);

            if (!File.Exists(copypath))
            {
                await iJSRuntime.InvokeAsync <object>("ShowAlert", "การเรียกไฟล์ต้นฉบับไม่สมบูรณ์");

                blnError = true;
                return(blnError);
            }

            var      colorTomatoRed = Color.FromArgb(255, 99, 71);
            var      colorSalmon    = Color.FromArgb(255, 160, 122);
            var      colorDarkRed   = Color.FromArgb(192, 0, 0);
            FileInfo fileInfo       = new FileInfo(copypath);

            using (ExcelPackage package = new ExcelPackage(fileInfo))
            {
                ExcelWorksheet worksheet = package.Workbook.Worksheets.FirstOrDefault();

                int dataRows       = worksheet.Dimension.Rows;
                int dataColumns    = worksheet.Dimension.Columns;
                int colDescription = dataColumns + 1;


                if (HISFileSummary != null)
                {
                    worksheet.Cells[1, colDescription].Value = "Remarks";
                    using (ExcelRange h = worksheet.Cells[1, colDescription])
                    {
                        h.Style.Font.Bold = true;
                        h.Style.Font.Color.SetColor(colorDarkRed);
                        h.Style.VerticalAlignment   = ExcelVerticalAlignment.Center;
                        h.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                    }

                    for (int iRow = 2; iRow <= dataRows; iRow++)
                    {
                        var objFile = HISFileSummary.Where(w => w.hus_error_fieldrecord.Trim() == iRow.ToString()).ToList();
                        if (objFile.Count() > 0)
                        {
                            var drWarningRow = objFile.FirstOrDefault();
                            worksheet.Cells[iRow, colDescription].Value = drWarningRow.hus_error_fieldname + " : " + drWarningRow.hus_error_fielddescr;
                            //worksheet.Cells[iRow,1,iRow, colDescription].Style.Fill.BackgroundColor.SetColor(colorSalmon);
                        }
                        //string content = worksheet.Cells[iRow, iCol].Value.ToString();
                    }
                    package.Save();
                }
                //fileContents = package.GetAsByteArray();
            }

            var strExportFileName = Path.GetFileName(copypath);

            byte[] bytes       = File.ReadAllBytes(copypath);
            var    contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

            using (MemoryStream oMemoryStream = new MemoryStream())
            {
                using (var stream = new FileStream(copypath, FileMode.Open))
                {
                    await stream.CopyToAsync(oMemoryStream);
                }
                await iJSRuntime.InvokeVoidAsync("BlazorFileSaver.saveAsBase64", strExportFileName, oMemoryStream.ToArray(), contentType);
            }
            return(blnError);
        }
コード例 #9
0
        public void GenerateExportSummary(IJSRuntime iJSRuntime, List <HISFileUploadSummaryDTO> HISFileSummary, HISUploadDataDTO HISFileUploadData)
        {
            byte[] fileContents;

            var idxRowCurrent = 1;

            var idxColErrorRowNo  = 1;
            var idxColErrorColumn = 2;
            var idxColErrorDesc   = 3;
            var strSheetName      = string.Format("{0}_{1}"
                                                  , Path.GetFileNameWithoutExtension(HISFileUploadData.hfu_file_name)
                                                  , "Summary");
            var colorDarkOliveGreen = Color.FromArgb(189, 215, 238);

            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;

            using (var package = new ExcelPackage())
            {
                var workSheet = package.Workbook.Worksheets.Add(strSheetName);

                // Header Column
                workSheet.Cells[idxRowCurrent, idxColErrorRowNo].Value  = "Row No.";
                workSheet.Cells[idxRowCurrent, idxColErrorColumn].Value = "Field";
                workSheet.Cells[idxRowCurrent, idxColErrorDesc].Value   = "Description";

                using (ExcelRange h = workSheet.Cells[1, idxColErrorRowNo, 1, idxColErrorDesc])
                {
                    h.Style.Font.Bold        = true;
                    h.Style.Fill.PatternType = ExcelFillStyle.Solid;
                    h.Style.Fill.BackgroundColor.SetColor(colorDarkOliveGreen);
                    h.Style.VerticalAlignment   = ExcelVerticalAlignment.Center;
                    h.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                }

                foreach (var obj in HISFileSummary)
                {
                    idxRowCurrent += 1;
                    workSheet.Cells[idxRowCurrent, idxColErrorRowNo].Value  = obj.hus_error_fieldrecord;
                    workSheet.Cells[idxRowCurrent, idxColErrorColumn].Value = obj.hus_error_fieldname;
                    workSheet.Cells[idxRowCurrent, idxColErrorDesc].Value   = obj.hus_error_fielddescr;
                }

                fileContents = package.GetAsByteArray();
            }

            try
            {
                var strExportFileName = string.Format("{0}_{1}_{2}"
                                                      , DateTime.Today.ToString("yyyyMMdd")
                                                      , Path.GetFileNameWithoutExtension(HISFileUploadData.hfu_file_name)
                                                      , "Summary.xlsx");
                iJSRuntime.InvokeAsync <HISFileUploadService>(
                    "saveAsFile",
                    strExportFileName,
                    Convert.ToBase64String(fileContents)
                    );
            }
            catch (Exception ex)
            {
            }
        }
コード例 #10
0
        public HISUploadDataDTO Post_SaveSPFileUploadData([FromBody] HISUploadDataDTO model)
        {
            var objReturn = _service.SaveLabFileUploadData(model);

            return(objReturn);
        }
コード例 #11
0
        public void GenerateExportSummary(IJSRuntime iJSRuntime, List <HISFileUploadSummaryDTO> HISFileSummary, HISUploadDataDTO HISFileUploadData)
        {
            byte[] fileContents;

            var idxRowCurrent = 1;

            var idxColErrorRowNo  = 1;
            var idxColErrorColumn = 2;
            var idxColErrorDesc   = 2;
            var strSheetName      = string.Format("{0}_{1}"
                                                  , Path.GetFileNameWithoutExtension(HISFileUploadData.hfu_file_name)
                                                  , "Summary");

            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;

            using (var package = new ExcelPackage())
            {
                var workSheet = package.Workbook.Worksheets.Add(strSheetName);

                // Header Column
                workSheet.Cells[idxRowCurrent, idxColErrorRowNo].Value  = "Row No.";
                workSheet.Cells[idxRowCurrent, idxColErrorColumn].Value = "Field";
                workSheet.Cells[idxRowCurrent, idxColErrorDesc].Value   = "Description";

                foreach (var obj in HISFileSummary)
                {
                    idxRowCurrent += 1;
                    workSheet.Cells[idxRowCurrent, idxColErrorRowNo].Value  = obj.hus_error_fieldrecord;
                    workSheet.Cells[idxRowCurrent, idxColErrorColumn].Value = obj.hus_error_fieldname;
                    workSheet.Cells[idxRowCurrent, idxColErrorDesc].Value   = obj.hus_error_fielddescr;
                }

                fileContents = package.GetAsByteArray();
            }

            try
            {
                var strExportFileName = string.Format("{0}_{1}_{2}"
                                                      , DateTime.Today.ToString("yyyyMMdd")
                                                      , Path.GetFileNameWithoutExtension(HISFileUploadData.hfu_file_name)
                                                      , "Summary");
                iJSRuntime.InvokeAsync <HISFileUploadService>(
                    "saveAsFile",
                    "Summary.xlsx",
                    Convert.ToBase64String(fileContents)
                    );
            }
            catch (Exception ex)
            {
            }
        }
コード例 #12
0
        public async Task <List <HISUploadErrorMessageDTO> > ValidateSPFileAsync(IFileListEntry fileEntry, HISUploadDataDTO HISfileOwner)
        {
            List <HISUploadErrorMessageDTO> ErrorMessage = new List <HISUploadErrorMessageDTO>();

            try
            {
                string              path = "";
                const bool          FIRSTROW_IS_HEADER = true;
                List <ParameterDTO> objParamList       = new List <ParameterDTO>();
                var searchModel = new ParameterDTO()
                {
                    prm_code_major = "UPLOAD_PATH"
                };

                objParamList = await _apiHelper.GetDataListByModelAsync <ParameterDTO, ParameterDTO>("dropdownlist_api/GetParameterList", searchModel);

                if (objParamList.FirstOrDefault(x => x.prm_code_minor == "PATH") != null)
                {
                    path = objParamList.FirstOrDefault(x => x.prm_code_minor == "PATH").prm_value;
                }
                else
                {
                    ErrorMessage.Add(new HISUploadErrorMessageDTO
                    {
                        hfu_status      = 'E',
                        hfu_Err_type    = "E",
                        hfu_Err_no      = 1,
                        hfu_Err_Column  = "",
                        hfu_Err_Message = "ไม่พบ Config PATH กรุณาติดต่อผู้ดูแลระบบ "
                    });

                    return(ErrorMessage);
                }

                string str_CurrentDate = DateTime.Now.ToString("yyyyMMdd");
                path = Path.Combine(path, str_CurrentDate, HISfileOwner.hfu_hos_code);
                bool exists = System.IO.Directory.Exists(path);

                if (!exists)
                {
                    System.IO.Directory.CreateDirectory(path);
                }

                path = Path.Combine(path, fileEntry.Name);

                using (FileStream file = new FileStream(path, FileMode.Create))
                {
                    try
                    {
                        await fileEntry.Data.CopyToAsync(file);
                    }
                    catch (Exception ex)
                    {
                    }
                    finally
                    {
                        file.Flush();
                    }
                }

                //        WHONetMappingSearch searchWHONet = new WHONetMappingSearch();
                //        searchWHONet.wnm_mappingid = MappingTemplate.mp_id;
                //        searchWHONet.wnm_mst_code = MappingTemplate.mp_mst_code;

                //        List<WHONetMappingListsDTO> WHONetColumn = await _apiHelper.GetDataListByModelAsync<WHONetMappingListsDTO, WHONetMappingSearch>("mapping_api/Get_WHONetMappingListByModel", searchWHONet);
                //        var WHONetColumnMandatory = WHONetColumn.Where(x => x.wnm_mandatory == true);
                #region ReadExcel
                if (Path.GetExtension(fileEntry.Name) == ".xls" || Path.GetExtension(fileEntry.Name) == ".xlsx")
                {
                    ExcelDataSetConfiguration option = new ExcelDataSetConfiguration();
                    DataSet result = new DataSet();

                    using (var stream = File.Open(path, FileMode.Open, FileAccess.Read))
                    {
                        using (var reader = ExcelReaderFactory.CreateReader(stream))
                        {
                            if (FIRSTROW_IS_HEADER == true)
                            {
                                result = reader.AsDataSet(new ExcelDataSetConfiguration()
                                {
                                    ConfigureDataTable = (tableReader) => new ExcelDataTableConfiguration()
                                    {
                                        UseHeaderRow = true
                                    }
                                }
                                                          );
                            }
                            else
                            {
                                result = reader.AsDataSet();
                            }

                            ErrorMessage.Add(new HISUploadErrorMessageDTO
                            {
                                hfu_status      = 'I',
                                hfu_Err_type    = "I",
                                hfu_Err_no      = 1,
                                hfu_Err_Column  = "Total",
                                hfu_Err_Message = result.Tables[0].Rows.Count.ToString()
                            });
                        }
                    }
                    #endregion

                    //----------  Validate Data in File -------------
                    var       dataTable   = result.Tables[0];
                    const int colRefNo    = 0;
                    const int colHNNo     = 1;
                    const int colLabNo    = 2;
                    const int colSpecDate = 3;

                    const string COL_REF_NO = "Ref No";
                    const string COL_HN_NO  = "HN";
                    const string COL_LAB_NO = "Lab";
                    const string COL_DATE   = "Date";

                    // Check column Exist
                    Boolean columnExists = result.Tables[0].Columns.Contains(COL_REF_NO) &&
                                           result.Tables[0].Columns.Contains(COL_HN_NO) &&
                                           result.Tables[0].Columns.Contains(COL_LAB_NO) &&
                                           result.Tables[0].Columns.Contains(COL_DATE);
                    if (columnExists == false)
                    {
                        ErrorMessage.Add(new HISUploadErrorMessageDTO
                        {
                            hfu_status      = 'E',
                            hfu_Err_type    = "C",
                            hfu_Err_no      = 1,
                            hfu_Err_Column  = COL_REF_NO,
                            hfu_Err_Message = "ไม่พบ Column " + COL_REF_NO
                        });
                    }

                    for (var i = 0; i < dataTable.Rows.Count; i++)
                    {
                        for (var j = 0; j < dataTable.Columns.Count; j++)
                        {
                            //HISWithSP
                            if (HISfileOwner.hfu_file_type == "HIS" && j == 4)
                            {
                                break;
                            }

                            var data = dataTable.Rows[i][j];

                            // Check column not null
                            if (string.IsNullOrEmpty(data.ToString()))
                            {
                                string columnError = "";
                                if (j == colRefNo)
                                {
                                    columnError = "Ref No.";
                                }
                                else if (j == colHNNo)
                                {
                                    columnError = "HN No.";
                                }
                                else if (j == colLabNo)
                                {
                                    columnError = "Lab No.";
                                }
                                else if (j == colSpecDate)
                                {
                                    columnError = "Date";
                                }
                            }



                            // Check Date format incorrect
                            if (j == colSpecDate)
                            {
                                //string dateString = data.ToString();
                                //DateTime dtValue;
                                //DateTime dt;
                                //string[] formateDate = { "dd/MM/yyyy" };
                                //if (DateTime.TryParse(dateString, out dtValue))
                                //{
                                //    var dateonly = dtValue.Date;
                                //    if (!DateTime.TryParseExact(dateonly.ToString(), formateDate,
                                //                 new CultureInfo("en-US"),
                                //                 DateTimeStyles.None, out dt))
                                //    {
                                //        //your condition fail code goes here
                                //        ErrorMessage.Add(new HISUploadErrorMessageDTO
                                //        {
                                //            hfu_status = 'E',
                                //            hfu_Err_type = "E",
                                //            hfu_Err_no = 1,
                                //            hfu_Err_Column = "",
                                //            hfu_Err_Message = "Column Date ต้องอยู่ในรูปแบบ " + formateDate[0]
                                //        }); ;
                                //        return ErrorMessage;
                                //    }

                                //}
                                //else
                                //{
                                //    ErrorMessage.Add(new HISUploadErrorMessageDTO
                                //    {
                                //        hfu_status = 'E',
                                //        hfu_Err_type = "E",
                                //        hfu_Err_no = 1,
                                //        hfu_Err_Column = "",
                                //        hfu_Err_Message = "Column Date ต้องอยู่ในรูปแบบ " + formateDate[0]
                                //    }); ;
                                //    return ErrorMessage;
                                //}
                            }
                        }
                    }

                    var chkError = ErrorMessage.FirstOrDefault(x => x.hfu_status == 'E');
                    if (chkError != null)
                    {
                        File.Delete(path);
                    }
                    else
                    {
                        ErrorMessage.Add(new HISUploadErrorMessageDTO
                        {
                            hfu_status      = 'I',
                            hfu_Err_type    = "P",
                            hfu_Err_no      = 1,
                            hfu_Err_Column  = "path",
                            hfu_Err_Message = path
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                //create log
            }
            return(ErrorMessage);
        }
コード例 #13
0
        public async Task <List <HISUploadErrorMessageDTO> > ValidateAndUploadFileSPFileAsync(IFileListEntry fileEntry
                                                                                              , HISUploadDataDTO HISfileOwner
                                                                                              , HISFileTemplateDTO HISTemplateActive)
        {
            List <HISUploadErrorMessageDTO> ErrorMessage = new List <HISUploadErrorMessageDTO>();

            try
            {
                string path = "";
                List <ParameterDTO> objParamList = new List <ParameterDTO>();
                var searchModel = new ParameterDTO()
                {
                    prm_code_major = "UPLOAD_PATH"
                };

                const bool FIRSTROW_IS_HEADER = true;
                const int  colRefNo           = 0;
                const int  colHNNo            = 1;
                const int  colLabNo           = 2;
                const int  colSpecDate        = 3;
                var        formateDate        = HISTemplateActive.hft_date_format;
                var        COL_REF_NO         = HISTemplateActive.hft_field1; // "Ref No";
                var        COL_HN_NO          = HISTemplateActive.hft_field2; //"HN";
                var        COL_LAB_NO         = HISTemplateActive.hft_field3; // "Lab";
                var        COL_DATE           = HISTemplateActive.hft_field4; //"Date";

                objParamList = await _apiHelper.GetDataListByModelAsync <ParameterDTO, ParameterDTO>("dropdownlist_api/GetParameterList", searchModel);

                if (objParamList.FirstOrDefault(x => x.prm_code_minor == "PATH") != null)
                {
                    path = objParamList.FirstOrDefault(x => x.prm_code_minor == "PATH").prm_value;
                }
                else
                {
                    ErrorMessage.Add(new HISUploadErrorMessageDTO
                    {
                        hfu_status      = 'E',
                        hfu_Err_type    = "E",
                        hfu_Err_no      = 1,
                        hfu_Err_Column  = "",
                        hfu_Err_Message = "ไม่พบ Config PATH กรุณาติดต่อผู้ดูแลระบบ "
                    });

                    return(ErrorMessage);
                }

                string str_CurrentDate = DateTime.Now.ToString("yyyyMMdd");
                path = Path.Combine(path, str_CurrentDate, HISfileOwner.hfu_hos_code);
                bool exists = System.IO.Directory.Exists(path);

                if (!exists)
                {
                    System.IO.Directory.CreateDirectory(path);
                }

                path = Path.Combine(path, fileEntry.Name);

                using (FileStream file = new FileStream(path, FileMode.Create))
                {
                    try
                    {
                        await fileEntry.Data.CopyToAsync(file);
                    }
                    catch (Exception ex)
                    {
                    }
                    finally
                    {
                        file.Flush();
                    }
                }

                #region ReadExcel
                if (Path.GetExtension(fileEntry.Name) == ".xls" || Path.GetExtension(fileEntry.Name) == ".xlsx")
                {
                    ExcelDataSetConfiguration option = new ExcelDataSetConfiguration();
                    DataSet result = new DataSet();

                    using (var stream = File.Open(path, FileMode.Open, FileAccess.Read))
                    {
                        using (var reader = ExcelReaderFactory.CreateReader(stream))
                        {
                            if (FIRSTROW_IS_HEADER == true)
                            {
                                result = reader.AsDataSet(new ExcelDataSetConfiguration()
                                {
                                    ConfigureDataTable = (tableReader) => new ExcelDataTableConfiguration()
                                    {
                                        UseHeaderRow = true
                                    }
                                }
                                                          );
                            }
                            else
                            {
                                result = reader.AsDataSet();
                            }


                            while (reader.Read())
                            {
                                var strFileFormatDate = reader.GetNumberFormatString(3);
                                if (strFileFormatDate.ToLower() != formateDate.ToLower())
                                {
                                    ErrorMessage.Add(new HISUploadErrorMessageDTO
                                    {
                                        hfu_status      = 'E',
                                        hfu_Err_type    = "E",
                                        hfu_Err_no      = 1,
                                        hfu_Err_Column  = "",
                                        hfu_Err_Message = "Column Date ต้องอยู่ในรูปแบบ " + formateDate
                                    });;
                                    return(ErrorMessage);
                                }
                            }

                            ErrorMessage.Add(new HISUploadErrorMessageDTO
                            {
                                hfu_status      = 'I',
                                hfu_Err_type    = "I",
                                hfu_Err_no      = 1,
                                hfu_Err_Column  = "Total",
                                hfu_Err_Message = result.Tables[0].Rows.Count.ToString()
                            });
                        }
                    }
                    #endregion

                    //----------  Validate Data in File -------------
                    var dataTable = result.Tables[0];

                    // Check column Exist
                    Boolean columnExists = result.Tables[0].Columns.Contains(COL_REF_NO) &&
                                           result.Tables[0].Columns.Contains(COL_HN_NO) &&
                                           result.Tables[0].Columns.Contains(COL_LAB_NO) &&
                                           result.Tables[0].Columns.Contains(COL_DATE);
                    if (columnExists == false)
                    {
                        ErrorMessage.Add(new HISUploadErrorMessageDTO
                        {
                            hfu_status      = 'E',
                            hfu_Err_type    = "C",
                            hfu_Err_no      = 1,
                            hfu_Err_Column  = COL_REF_NO,
                            hfu_Err_Message = "ไม่พบ Column " + COL_REF_NO
                        });
                    }

                    for (var i = 0; i < dataTable.Rows.Count; i++)
                    {
                        for (var j = 0; j < 4; j++)
                        {
                            var data = dataTable.Rows[i][j];

                            // Check column not null
                            if (string.IsNullOrEmpty(data.ToString()))
                            {
                                string columnError = "";
                                if (j == colRefNo)
                                {
                                    columnError = COL_REF_NO;
                                }
                                else if (j == colHNNo)
                                {
                                    columnError = COL_HN_NO;
                                }
                                else if (j == colLabNo)
                                {
                                    columnError = COL_LAB_NO;
                                }
                                else if (j == colSpecDate)
                                {
                                    columnError = COL_DATE;
                                }

                                var chkErrExist = ErrorMessage.FirstOrDefault(e => e.hfu_status == 'W' && e.hfu_Err_no == i + 2);

                                if (chkErrExist == null)
                                {
                                    ErrorMessage.Add(new HISUploadErrorMessageDTO
                                    {
                                        hfu_status      = 'W',
                                        hfu_Err_type    = columnError,
                                        hfu_Err_no      = i + 2,
                                        hfu_Err_Column  = "Required",
                                        hfu_Err_Message = "Field is required"
                                    });
                                }

                                else
                                {
                                    //ErrorMessage.Where(e => e.hfu_status == 'W' && e.hfu_Err_no == i + 1).
                                    //    Select(n => { n.hfu_Err_Message = ""; return n; }).ToList();
                                    chkErrExist.hfu_Err_type += ',' + columnError;
                                }
                            }

                            // Check Date format incorrect
                            //if (j == colSpecDate)
                            //{
                            //    string dateString = data.ToString();
                            //    DateTime dt;
                            //    //string[] formateDate = { HISTemplateActive.hft_date_format }; //  dd/MM/yyyy
                            //    // en-GB , en-US
                            //    //var formateDate = HISTemplateActive.hft_date_format;
                            //    try
                            //    {
                            //        dt = DateTime.Parse(dateString,new CultureInfo("en-US"));

                            //    }
                            //    catch (Exception ex)
                            //    {
                            //        ErrorMessage.Add(new HISUploadErrorMessageDTO
                            //        {
                            //            hfu_status = 'E',
                            //            hfu_Err_type = "E",
                            //            hfu_Err_no = 1,
                            //            hfu_Err_Column = "",
                            //            hfu_Err_Message = "Column Date ต้องอยู่ในรูปแบบ " + formateDate
                            //        }); ;
                            //        return ErrorMessage;
                            //    }
                            //}
                        }
                    }

                    var chkError = ErrorMessage.FirstOrDefault(x => x.hfu_status == 'E');
                    if (chkError != null)
                    {
                        File.Delete(path);
                    }
                    else
                    {
                        ErrorMessage.Add(new HISUploadErrorMessageDTO
                        {
                            hfu_status      = 'I',
                            hfu_Err_type    = "P",
                            hfu_Err_no      = 1,
                            hfu_Err_Column  = "path",
                            hfu_Err_Message = path
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                //create log
            }
            return(ErrorMessage);
        }