本文整理汇总了C#中CsvReader.MoveTo方法的典型用法代码示例。如果您正苦于以下问题:C# CsvReader.MoveTo方法的具体用法?C# CsvReader.MoveTo怎么用?C# CsvReader.MoveTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CsvReader
的用法示例。
在下文中一共展示了CsvReader.MoveTo方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNextComic
private static Comic GetNextComic()
{
var nextComicIndex = Random.Next(1, 400);
using (var csv = new CsvReader(new StreamReader("comics.csv"), false))
{
csv.MoveTo(nextComicIndex);
return new Comic
{
Title = csv[2],
Publisher = csv[1],
ReleaseDate = csv[0]
};
}
}
示例2: Model_Shown
private void Model_Shown(object sender, EventArgs e)
{
// Load in brand table
dataGridViewModel.ReadOnly = true;
dataGridViewMaker.ReadOnly = true;
using (CsvReader csv = new CsvReader(new StreamReader(filePathBrand), true, ';'))
{
int n = csv.FieldCount;
int i = 0;
while (csv.ReadNextRecord())
{
dataGridViewMaker.Rows.Add();
dataGridViewMaker.Rows[i].Cells[0].Value = i + 1;
for (int j = 0; j < n; j++)
{
dataGridViewMaker.Rows[i].Cells[j + 1].Value = csv[j];
}
i++;
}
}
// first id brand in table
int k = int.Parse(dataGridViewMaker.Rows[0].Cells[1].Value.ToString());
// Load in model table
using (CsvReader csv = new CsvReader(new StreamReader(filePathMoels), true, ';'))
{
int n = csv.FieldCount;
int i = 0;
if (k != 0)
{
csv.MoveTo(n - 1);
while (csv.ReadNextRecord())
{
if (int.Parse(csv[1]) == k)
{
dataGridViewModel.Rows.Add();
dataGridViewModel.Rows[i].Cells[0].Value = i + 1;
dataGridViewModel.Rows[i].Cells[2].Value = csv[2];
i++;
}
}
}
else
{
dataGridViewModel.Rows.Add();
dataGridViewModel.Rows[0].Cells[0].Value = "-";
dataGridViewModel.Rows[0].Cells[0].Value = "Нема записів";
}
}
}
示例3: ParseCSV
public void ParseCSV(DotNetNuke.Services.FileSystem.FileInfo fileInfo, int startIndex)
{
using (CsvReader reader = new CsvReader(new StreamReader(fileInfo.PhysicalPath), true))
{
int tabModuleId = DataProvider.Instance().GetTabModuleIdByFileId(fileInfo.FileId);
int lineNumber = 0;
if (startIndex == 0)
{
DataProvider.Instance().ClearTempLocations();
}
else
{
lineNumber = startIndex;
reader.MoveTo(startIndex - 1);
}
try
{
while (reader.ReadNextRecord())
{
lineNumber++;
Location location = new Location();
location.LocationId = Convert.ToInt32(GetValue(reader, "UNIQUE_KEY"), CultureInfo.InvariantCulture);
location.ExternalIdentifier = GetValue(reader, "EXTERNAL_IDENTIFIER");
location.Name = GetValue(reader, "LOCATION_NAME");
string address1 = GetValue(reader, "ADDRESS1");
string address2 = GetValue(reader, "ADDRESS2");
location.City = GetValue(reader, "CITY");
string state = GetValue(reader, "STATE");
location.PostalCode = GetValue(reader, "ZIP");
location.Phone = GetValue(reader, "PHONE_NUMBER");
location.LocationDetails = GetValue(reader, "LOCATION_DETAILS");
location.Website = GetValue(reader, "WEBSITE");
location.PortalId = this.portalId;
string locationType = GetValue(reader, "TYPE_OF_LOCATION");
if (locationType == string.Empty)
{
locationType = "Default";
}
string country = GetValue(reader, "COUNTRY");
DataTable dt = DataProvider.Instance().GetLocationTypes();
int locationTypeId = -1;
foreach (DataRow dr in dt.Rows)
{
if (Convert.ToString(dr["LocationTypeName"], CultureInfo.InvariantCulture) == locationType)
{
locationTypeId = Convert.ToInt32(dr["LocationTypeID"], CultureInfo.InvariantCulture);
location.LocationTypeId = locationTypeId;
}
}
if (locationTypeId == -1)
{
locationTypeId = DataProvider.Instance().InsertLocationType(locationType);
location.LocationTypeId = locationTypeId;
}
location.RegionId = ResolveState(state);
if (location.RegionId < 1)
{
location.RegionId = Convert.ToInt32(null, CultureInfo.InvariantCulture);
}
location.CountryId = ResolveCountry(country);
if (location.CountryId < 1)
{
ModuleController objModules = new ModuleController();
location.CountryId = Dnn.Utility.GetIntSetting(objModules.GetTabModuleSettings(tabModuleId), "DefaultCountry").Value;
}
location.CsvLineNumber = lineNumber;
location.Address = address1;
// Address2 is informational only - See Pat Renner.
location.Address2 = address2;
GeocodeResult geocodeResult = GetGeoCoordinates(tabModuleId, address1, location.City, location.RegionId, location.PostalCode, location.CountryId);
if (geocodeResult.Successful)
{
location.Latitude = geocodeResult.Latitude;
location.Longitude = geocodeResult.Longitude;
}
location.Approved = true;
try
{
location.SaveTemp(geocodeResult.Successful);
}
catch (SqlException ex)
{
Exceptions.LogException(ex);
}
}
}
catch (ArgumentException exc)
{
//.........这里部分代码省略.........
示例4: MoveToTest5
public void MoveToTest5()
{
using (CsvReader csv = new CsvReader(new StringReader(CsvReaderSampleData.SampleData1), false))
{
Assert.IsTrue(csv.MoveTo(-1));
csv.MoveTo(0);
Assert.IsFalse(csv.MoveTo(-1));
}
}
示例5: MoveToTest4
public void MoveToTest4()
{
using (CsvReader csv = new CsvReader(new StringReader(CsvReaderSampleData.SampleData1), true))
{
csv.SupportsMultiline = false;
string[] headers = csv.GetFieldHeaders();
Assert.IsTrue(csv.MoveTo(2));
Assert.AreEqual(2, csv.CurrentRecordIndex);
CsvReaderSampleData.CheckSampleData1(csv, false);
}
}
示例6: MoveToTest3
public void MoveToTest3()
{
using (CsvReader csv = new CsvReader(new StringReader(CsvReaderSampleData.SampleData1), true))
{
Assert.IsFalse(csv.MoveTo(CsvReaderSampleData.SampleData1RecordCount));
}
}
示例7: MoveToTest1
public void MoveToTest1()
{
using (CsvReader csv = new CsvReader(new StringReader(CsvReaderSampleData.SampleData1), true))
{
for (int i = 0; i < CsvReaderSampleData.SampleData1RecordCount; i++)
{
Assert.IsTrue(csv.MoveTo(i));
CsvReaderSampleData.CheckSampleData1(i, csv);
}
}
}
示例8: MoveToTest2
public void MoveToTest2()
{
using (CsvReader csv = new CsvReader(new StringReader(CsvReaderSampleData.SampleData1), true))
{
csv.MoveTo(1);
csv.MoveTo(0);
}
}
示例9: ArgumentTestMoveTo1
public void ArgumentTestMoveTo1()
{
using (CsvReader csv = new CsvReader(new StringReader(CsvReaderSampleData.SampleData1), false))
{
csv.MoveTo(-1);
}
}
示例10: comboBoxBrand_SelectedIndexChanged
private void comboBoxBrand_SelectedIndexChanged(object sender, EventArgs e)
{
groupBoxComplex.Enabled = true;
dataGridViewModels.Rows.Clear();
string brand = "";
brand = comboBoxBrand.SelectedItem.ToString();
for (int i = 0; i < Brandlist.Count; i++)
{
if (brand.CompareTo(Brandlist[i].name) == 0)
{
IdBrand = Brandlist[i].n;
break;
}
}
CsvReader csvBaseProperties = new CsvReader(new StreamReader("baseProperties.csv"), true, ';');
string model = "";
using (CsvReader csv = new CsvReader(new StreamReader("Car.csv"), true, ';'))
{
int i = 0;
int k_b = 0;
int k_m = 0;
int jj = 0;
while (csv.ReadNextRecord())
{
if (csv[1] == IdBrand && IdBrand != "")
{
csvBaseProperties.MoveTo(k_b);
IdBaseProperties = csv[6];
IdModels = csv[2];
IdType = csv[4];
IdColor = csv[5];
while (csvBaseProperties.ReadNextRecord())
{
if (csvBaseProperties[0] == IdBaseProperties && IdBaseProperties != "")
{
dataGridViewModels.Rows.Add();
dataGridViewModels.Rows[i].Cells[0].Value = i + 1;
for (int j = 0; j < csvBaseProperties.FieldCount; j++)
{
dataGridViewModels.Rows[i].Cells[j + 5].Value = csvBaseProperties[j].ToString();
}
i++;
break;
}
k_b++;
}
CsvReader csvModels = new CsvReader(new StreamReader("Models.csv"), true, ';');
while (csvModels.ReadNextRecord())
{
if (csvModels[0] == IdModels && IdModels != "")
{
model = csvModels[2];
break;
}
}
dataGridViewModels.Rows[i - 1].Cells[4].Value = model;
dataGridViewModels.Rows[i - 1].Cells[2].Value = IdType;
dataGridViewModels.Rows[i - 1].Cells[3].Value = IdColor;
dataGridViewModels.Rows[i - 1].Cells[1].Value = IdModels;
}
}
}
}