private async Task <bool> CheckValidTemplate() { bool temp = false; FileInfo file; var sheetName = ""; foreach (var item in fileList) { try { if (!CommonEngine.CheckExistsUnicodeChar(item.FileName)) { item.IsValid = false; item.Note = LanguageEngine.GetMessageCaption("000021", ConfigEngine.Language); } file = new FileInfo(item.FilePath); CommonEngine.SetWaitFormInfo("Đang kiểm tra tập tin " + file.Name, "Checking file " + file.Name, 1); if (file.Exists) { temp = await ReportEngine.CheckValidImportTemplate(CommonEngine.userInfo.UserID, ConfigEngine.Language, strStoreProcedure, file.Name, strModuleID, strFunctionID, file.FullName); if (!temp) { item.IsValid = false; item.Note = ConfigEngine.Language.Equals("vi") ? "Mẫu không hợp lệ!" : "Invalid template!"; } else { item.IsValid = true; item.Note = ConfigEngine.Language.Equals("vi") ? "Mẫu hợp lệ!" : "Valid template!"; item.SheetName = sheetName; string tmp = item.FileName; tmp = tmp.Substring(0, tmp.LastIndexOf('.')); tmp = Regex.Replace(tmp, @"[^a-zA-Z0-9\s-().\[\]]", ""); item.TableName = tmp; } } else { item.IsValid = false; item.Note = ConfigEngine.Language.Equals("vi") ? "Tập tin không tồn tại!" : "File not exists!"; } } catch (Exception ex) { CommonEngine.ShowExceptionMessage(ex); } } grvSeletedFiles.RefreshData(); return(true); }
private async Task GetDataToImport() { try { total_file = fileList.Count; correct_file = (from item in fileList where item.IsValid == true select item).ToList().Count; invalid_file = total_file - correct_file; fileList = (from item in fileList where item.IsValid select item).ToList(); grvSeletedFiles.RefreshData(); gluSeletedFiles.DataBindings.Clear(); gluSeletedFiles.Properties.DataSource = fileList; gluSeletedFiles.Properties.ValueMember = "TableName"; gluSeletedFiles.Properties.DisplayMember = "FileName"; if (fileList.Count > 0) { gluSeletedFiles.EditValue = fileList[0].TableName; } DataSet temp = new DataSet(); string column_array = ""; foreach (var file in fileList) { CommonEngine.SetWaitFormInfo("Đang tải tập tin " + file.FileName, "Loading file data " + file.FileName, 1); column_array = ""; ReportEngine.GetDataExcel(ref dsMainData, strFunctionID, file.FilePath, file.TableName, file.SheetName, ref column_array); file.CollumArray = column_array.Substring(0, column_array.Length - 1); } if (dsMainData.Tables.Count > 0) { isGetFileData = true; ShowDataTable(dsMainData.Tables[gluSeletedFiles.EditValue + ""]); await ShowRequireColumn(); } } catch (Exception ex) { CommonEngine.ShowExceptionMessage(ex); } }