public override void Execute() { base.Execute(); if (ValidateModule()) { string exportFileName; exportFileName = (string)this["E02"]; var gridView = PrintGrid.DefaultView as GridView; if (gridView != null) { lnkFile.Visible = false; foreach (var control in CommonControlByID.Values) { control.Enabled = false; } var columns = new List <string>(); var fields = new List <ModuleFieldInfo>(); var headers = new List <string>(); foreach (GridColumn column in gridView.Columns) { var flagAddColumn = true; if (column.Visible && column.VisibleIndex >= 0) { //TUDQ them if (modExport == 1 & columnRemove != null) { for (var j = 0; j < columnRemove.Rows.Count; j++) { if (columnRemove.Rows[j]["Value"].ToString() == column.FieldName) { flagAddColumn = false; } } } if (flagAddColumn) { var field = (ModuleFieldInfo)column.Tag; if (field != null) { fields.Add(field); columns.Add(column.FieldName); headers.Add(column.ToolTip); } } } //if (column.Visible && column.VisibleIndex >= 0) //{ // var field = (ModuleFieldInfo)column.Tag; // if (field != null) // { // fields.Add(field); // columns.Add(column.FieldName); // headers.Add(column.Caption); // } //} } if ((string)this["E01"] == CODES.EXPORT.EXPORTTYPE.XML || (string)this["E01"] == CODES.EXPORT.EXPORTTYPE.TXT) { CurrentThread = new WorkerThread( delegate(WorkerThread thread) { LockUserAction(); ExportSuccess = false; try { using (var ctrlSA = new SAController()) { DataContainer container; DataSet ds = new DataSet("main"); DataTable tempTable; ctrlSA.FetchAllSearchResult(out container, ModuleInfo.ModuleID, ModuleInfo.SubModule, LastSearchResultKey, LastSearchTime, 0); tempTable = container.GetTable( FieldUtils.GetModuleFields( ModuleInfo.ModuleID, CODES.DEFMODFLD.FLDGROUP.SEARCH_COLUMN )); tempTable.TableName = "DATA_RECORD"; ds.Tables.Add(tempTable); //ds.Tables.Add(table); if ((string)this["E01"] == CODES.EXPORT.EXPORTTYPE.XML) { ds.WriteXml((string)this["E02"]); } else { WriteFileText(ds.Tables[0], (string)this["E02"]); } CurrentThread.JobName = string.Format(Language.SaveToFileStatus, exportFileName); thread.ExecuteUpdateGUI(true); } thread.JobName = Language.CompletedStatus; thread.PercentComplete = 100; ExportSuccess = true; } catch (Exception ex) { ShowError(ex); } finally { UnLockUserAction(); } thread.ExecuteUpdateGUI(true); }, this); btnExport.Enabled = false; CurrentThread.ProcessComplete += thread_ProcessComplete; CurrentThread.DoUpdateGUI += thread_DoUpdateGUI; CurrentThread.Start(); } else { var exporter = new DataTableExporter(columns.ToArray(), headers.ToArray(), ModuleInfo, fields.ToArray()); CurrentThread = new WorkerThread( delegate(WorkerThread thread) { LockUserAction(); ExportSuccess = false; FileFormatType exportType; int maxRowCount; switch ((string)this["E01"]) { case CODES.EXPORT.EXPORTTYPE.EXCEL_XLSX: exportType = FileFormatType.Excel2007Xlsx; maxRowCount = CONSTANTS.MAX_ROWS_IN_EXPORT_XLSX; break; default: exportType = FileFormatType.Excel2003; maxRowCount = CONSTANTS.MAX_ROWS_IN_EXPORT_XLS; break; } try { using (var ctrlSA = new SAController()) { DataContainer container; DataTable tempTable; var book = exporter.CreateWorkBook(); var fromRow = 0; var rowCount = 0; ResultTable = null; do { ctrlSA.FetchAllSearchResult(out container, ModuleInfo.ModuleID, ModuleInfo.SubModule, LastSearchResultKey, LastSearchTime, fromRow); tempTable = container.GetTable( FieldUtils.GetModuleFields( ModuleInfo.ModuleID, CODES.DEFMODFLD.FLDGROUP.SEARCH_COLUMN )); if (tempTable.Rows.Count > 0) { fromRow = fromRow + tempTable.Rows.Count; rowCount = rowCount + tempTable.Rows.Count; if (ResultTable == null) { ResultTable = tempTable; } else { foreach (DataRow row in tempTable.Rows) { ResultTable.ImportRow(row); } // TODO: CHANGE NAME OF THREAD thread.JobName = string.Format("{0} rows buffered", rowCount); thread.ExecuteUpdateGUI(); } } if (ResultTable != null && ResultTable.Rows.Count > maxRowCount) { ExportDataTable(exporter, book, thread); ClearExportedRows(); } }while (tempTable.Rows.Count > 0); if (ResultTable != null && ResultTable.Rows.Count > 0) { ExportDataTable(exporter, book, thread); } else { book.Worksheets.Add("No result"); } CurrentThread.JobName = string.Format(Language.SaveToFileStatus, exportFileName); thread.ExecuteUpdateGUI(true); book.Save(exportFileName, exportType); } thread.JobName = Language.CompletedStatus; thread.PercentComplete = 100; ExportSuccess = true; } catch (Exception ex) { thread.PercentComplete = 100; thread.JobName = Language.ErrorStatus; ShowError(ex); } finally { UnLockUserAction(); } thread.ExecuteUpdateGUI(true); }, this); btnExport.Enabled = false; CurrentThread.ProcessComplete += thread_ProcessComplete; CurrentThread.DoUpdateGUI += thread_DoUpdateGUI; CurrentThread.Start(); } } } }