本文整理汇总了C#中FileHelperEngine.SetProgressHandler方法的典型用法代码示例。如果您正苦于以下问题:C# FileHelperEngine.SetProgressHandler方法的具体用法?C# FileHelperEngine.SetProgressHandler怎么用?C# FileHelperEngine.SetProgressHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileHelperEngine
的用法示例。
在下文中一共展示了FileHelperEngine.SetProgressHandler方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: cmdRun_Click
private void cmdRun_Click(object sender, EventArgs e)
{
cmdRun.Enabled = false;
FileHelperEngine engine = new FileHelperEngine(typeof (CustomersVerticalBar));
object[] records = engine.ReadFile(MainClass.GlobalTestFile);
Application.DoEvents();
engine.SetProgressHandler(new ProgressChangeHandler(ProgressChange));
engine.WriteString(records);
cmdRun.Enabled = true;
}
示例2: Import
public bool Import(string filename, BackgroundWorker bw = null)
{
try
{
if (!File.Exists(filename))
{
Log.n("Vare import: Fant ikke fil eller ble nektet tilgag. (" + filename + ")", Color.Red);
return false;
}
int importReadErrors = 0;
var engine = new FileHelperEngine(typeof(csvObsolete));
engine.ErrorManager.ErrorMode = ErrorMode.SaveAndContinue;
main.processing.SetProgressStyle = ProgressBarStyle.Marquee;
engine.SetProgressHandler(new ProgressChangeHandler(ReadProgressCSV));
var resCSV = engine.ReadFile(filename) as csvObsolete[];
if (engine.ErrorManager.HasErrors)
{
foreach (ErrorInfo err in engine.ErrorManager.Errors)
{
importReadErrors++;
Log.e("Import: Klarte ikke lese linje " + err.LineNumber + ": " + err.RecordString);
Log.d("Exception: " + err.ExceptionInfo.ToString());
if (importReadErrors > 100)
{
Log.e("Feil: CSV er ikke en obsolete eksportering eller filen er skadet. (" + filename + ")");
return false;
}
}
}
main.processing.SetProgressStyle = ProgressBarStyle.Continuous;
int count = resCSV.Length;
if (count == 0)
return false;
Log.n("Prosesserer " + count.ToString("#,##0") + " vare oppføringer.. (" + filename + ")");
DateTime dtLast = DateTime.MinValue;
DataTable tableUkurans = main.database.tableUkurans.GetDataTable();
DataTable tableInfo = main.database.tableVareinfo.GetAllProducts();
if (tableInfo == null)
throw new Exception("Intern feil i databasen. tableInfo var null!");
int countInfo = tableInfo.Rows.Count;
Log.d("Product info table has " + string.Format("{0:n0}", countInfo) + " rows before import");
for (int i = 0; i < count; i++)
{
if (bw != null)
{
if (bw.CancellationPending)
return false;
if (i % 83 == 0)
{
bw.ReportProgress(i, new StatusProgress(count, null, 0, 100));
main.processing.SetText = "Lagrer varebeholdning..: "
+ string.Format("{0:n0}", i) + " / " + string.Format("{0:n0}", count);
}
}
string varekode = resCSV[i].Varekode;
if (varekode.Length > 0)
varekode = varekode.Substring(1, varekode.Length - 1);
DataRow[] filter = tableInfo.Select(TableVareinfo.KEY_VAREKODE + " = '" + varekode + "'");
if (filter.Length == 0)
{
DataRow row = tableInfo.NewRow();
row[TableVareinfo.INDEX_VAREKODE] = varekode;
row[TableVareinfo.INDEX_TEKST] = resCSV[i].VareTekst;
row[TableVareinfo.INDEX_KAT] = (int)resCSV[i].Kat;
row[TableVareinfo.INDEX_KATNAVN] = resCSV[i].KatNavn;
row[TableVareinfo.INDEX_GRUPPE] = (int)resCSV[i].Grp;
row[TableVareinfo.INDEX_GRUPPENAVN] = resCSV[i].GrpNavn;
row[TableVareinfo.INDEX_MODGRUPPE] = (int)resCSV[i].Mod;
row[TableVareinfo.INDEX_MODGRUPPENAVN] = resCSV[i].ModNavn;
row[TableVareinfo.INDEX_MERKE] = (int)resCSV[i].Merke;
row[TableVareinfo.INDEX_MERKENAVN] = resCSV[i].MerkeNavn;
row[TableVareinfo.INDEX_DATO] = DateTime.Now;
tableInfo.Rows.Add(row);
}
if (resCSV[i].Avd == main.appConfig.Avdeling || resCSV[i].Avd == (main.appConfig.Avdeling + 1000))
{
DataRow dtRow = tableUkurans.NewRow();
dtRow[TableUkurans.INDEX_AVDELING] = Convert.ToInt32(resCSV[i].Avd);
dtRow[TableUkurans.INDEX_VAREKODE] = varekode;
dtRow[TableUkurans.INDEX_ANTALL] = Convert.ToInt32(resCSV[i].AntallLager);
dtRow[TableUkurans.INDEX_KOST] = Convert.ToDecimal(resCSV[i].KostVerdiLager);
dtRow[TableUkurans.INDEX_DATO] = resCSV[i].DatoInnLager;
dtRow[TableUkurans.INDEX_UKURANS] = Convert.ToDecimal(resCSV[i].UkuransVerdi);
var s = resCSV[i].UkuransProsent;
decimal d = 0;
if (s.Length > 0)
{
//.........这里部分代码省略.........
示例3: ReadCsv
private csvImport[] ReadCsv(string file, BackgroundWorker bw, bool unattended)
{
try
{
FileHelperEngine engine = new FileHelperEngine(typeof(csvImport));
engine.ErrorManager.ErrorMode = ErrorMode.SaveAndContinue;
engine.SetProgressHandler(new ProgressChangeHandler(ReadProgressCSV));
var resCSV = engine.ReadFile(file) as csvImport[];
if (engine.ErrorManager.HasErrors)
{
List<string> filtLines = new List<string> () {};
foreach (ErrorInfo err in engine.ErrorManager.Errors)
{
if (RemoveExtraDelimiter(err.RecordString, filtLines))
{
Log.d("Import: Gjenopprettet linje " + err.LineNumber + " med feil format.");
}
else
{
importReadErrors++;
Log.n("Import: Format feil ved linje " + err.LineNumber + ": " + err.RecordString, Color.Red);
Log.d("Import: Feilmelding: " + err.ExceptionInfo.ToString());
if (importReadErrors > 100)
{
Log.n("CSV er skadet eller inneholder ikke riktige ranking transaksjoner.", Color.Red);
if (!unattended)
{
FormError errorMsg = new FormError("CSV er skadet eller inneholder ikke riktige ranking transaksjoner.",
err.ExceptionInfo, "Transaksjoner som ikke kunne leses:\n" + filtLines.Count);
errorMsg.ShowDialog();
}
return null;
}
}
}
if (filtLines.Count > 0)
{
Log.d("Import: Forsøker å legge til " + filtLines.Count + " linjer med feil på nytt etter fix...");
Log.d("Import: resCSV length før: " + resCSV.Length);
string tmpFile = GetTempFilename(".txt");
File.WriteAllLines(tmpFile, filtLines.ToArray(), Encoding.Unicode);
var resCSVfixed = engine.ReadFile(tmpFile) as csvImport[];
int oldLength = resCSV.Length;
Array.Resize<csvImport>(ref resCSV, oldLength + resCSVfixed.Length);
Array.Copy(resCSVfixed, 0, resCSV, oldLength, resCSVfixed.Length);
Log.d("Import: resCSV length etter: " + resCSV.Length);
}
}
Log.d("Import: ReadCsv ferdig '" + file + "' - Totalt: " + resCSV.Length);
return resCSV;
}
catch (IOException ex)
{
Log.n("CSV var låst for lesing. Forleng ventetid i makro hvis overføringen ikke ble ferdig i tide.", Color.Red);
Log.d("CSV var låst.", ex);
return null;
}
catch (Exception ex)
{
throw new Exception("Kritisk feil under lesing av CSV!", ex);
}
}
示例4: Import
public bool Import(string filename, FormProcessing processing, BackgroundWorker bw = null)
{
try
{
main.processing = processing;
if (!File.Exists(filename))
{
Log.n("Service Import: Fant ikke CSV service fil eller ble nektet tilgang. (" + filename + ")", Color.Red);
return false;
}
var engine = new FileHelperEngine(typeof(csvService));
engine.ErrorManager.ErrorMode = ErrorMode.SaveAndContinue;
processing.SetProgressStyle = ProgressBarStyle.Marquee;
engine.SetProgressHandler(new ProgressChangeHandler(ReadProgressCSV));
var resCSV = engine.ReadFile(filename) as csvService[];
if (engine.ErrorManager.HasErrors)
foreach (ErrorInfo err in engine.ErrorManager.Errors)
{
importReadErrors++;
Log.n("Import: Klarte ikke lese linje " + err.LineNumber + ": " + err.RecordString, Color.Red);
Log.d("Exception: " + err.ExceptionInfo.ToString());
if (importReadErrors > 100)
{
Log.n("Feil: CSV er ikke en service eksportering eller filen er skadet. (" + filename + ")", Color.Red);
return false;
}
}
processing.SetProgressStyle = ProgressBarStyle.Continuous;
int count = resCSV.Length;
if (count > 0)
{
DateTime dtFirst = DateTime.MaxValue;
DateTime dtLast = DateTime.MinValue;
string sqlStrAvd = "";
for (int i = 0; i < count; i++)
{
if (main.appConfig.importSetting != "FullFavoritt")
if (!sqlStrAvd.Contains(resCSV[i].Avd.ToString())) // Bygg SQL streng av avdelinger som skal slettes.
sqlStrAvd = sqlStrAvd + "Avdeling = '" + resCSV[i].Avd.ToString() + "' OR ";
DateTime dtTemp = Convert.ToDateTime(resCSV[i].DatoMottatt.ToString());
if (DateTime.Compare(dtTemp, dtFirst) < 0)
dtFirst = dtTemp;
if (DateTime.Compare(dtTemp, dtLast) > 0)
dtLast = dtTemp;
}
int dager = (dtLast - dtFirst).Days;
if (dager < 60)
{
Log.n("Feil: CSV inneholder for kort periode. Velg minst 60 dager perioder.", Color.Red);
return false;
}
if (dtLast < dbServiceDatoTil)
{
Log.n("Feil: CSV inneholder bare servicer som er eldre enn eksisterende servicer.", Color.Red);
return false;
}
if (main.appConfig.importSetting == "FullFavoritt")
foreach (string avdel in FormMain.Favoritter)
sqlStrAvd = sqlStrAvd + "Avdeling = '" + avdel + "' OR ";
if (sqlStrAvd.Length > 3) // Remove the last "OR"
sqlStrAvd = sqlStrAvd.Remove(sqlStrAvd.Length - 3);
var command = new SqlCeCommand("DELETE FROM tblService WHERE (DatoMottat >= '" + dtFirst.ToString("yyy-MM-dd") + "') AND (DatoMottat <= '" + dtLast.ToString("yyy-MM-dd") + "') AND (" + sqlStrAvd + ")", main.connection);
var result = command.ExecuteNonQuery();
Log.d("Slettet " + result + " servicer.");
command = new SqlCeCommand("DELETE FROM tblServiceLogg", main.connection);
result = command.ExecuteNonQuery();
Log.d("Slettet " + result + " logg oppføringer.");
Log.n("Prosesserer " + count.ToString("#,##0") + " service oppføringer.. (" + filename + ")");
if (main.appConfig.importSetting == "FullFavoritt")
foreach (string avdel in FormMain.Favoritter)
sqlStrAvd = sqlStrAvd + "Avdeling = '" + avdel + "' OR ";
if (sqlStrAvd.Length > 3) // Remove the last "OR"
sqlStrAvd = sqlStrAvd.Remove(sqlStrAvd.Length - 3);
int ordreNr = 0;
int currentRecord = 0;
int currentLog = 0;
int id = 0;
string sql = "INSERT INTO tblService (Avdeling, Ordrenr, Navn, DatoMottat, DatoIarbeid, DatoFerdig, DatoUtlevert, Status, Selgerkode, Verksted) " +
"VALUES (@Avdeling, @Ordrenr, @Navn, @DatoMottat, @DatoIarbeid, @DatoFerdig, @DatoUtlevert, @Status, @Selgerkode, @Verksted)";
for (int i = 0; i < count; i++)
{
if (FormMain.Favoritter.Contains(resCSV[i].Avd.ToString()))
{
//.........这里部分代码省略.........