本文整理汇总了C#中CsvFileReader.Close方法的典型用法代码示例。如果您正苦于以下问题:C# CsvFileReader.Close方法的具体用法?C# CsvFileReader.Close怎么用?C# CsvFileReader.Close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CsvFileReader
的用法示例。
在下文中一共展示了CsvFileReader.Close方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: loadSNPSPToolStripMenuItem_Click
private void loadSNPSPToolStripMenuItem_Click(object sender, EventArgs e)
{
_openFileDialog.FileName = "SNPCC.csv";
_openFileDialog.Filter = "csv files (*.csv)|*.csv";
_openFileDialog.DefaultExt = "txt";
_openFileDialog.FilterIndex = 2;
_openFileDialog.AddExtension = true;
if (_openFileDialog.ShowDialog() == DialogResult.OK)
{
string fileName = _openFileDialog.FileName;
CsvFileReader csv = new CsvFileReader(fileName);
char[] _separators = new char[] { '\n', '"', ',' };
CsvRow row = new CsvRow();
bool entering = true;
while (entering == true)
{
entering = csv.ReadRow(row);
staters.Add(new Stater(row[1], row[0]));
char[] bar = row[2].ToCharArray();
string bs = Convert.ToString(bar[0]) + Convert.ToString(bar[1]) + Convert.ToString(bar[2]) + Convert.ToString(bar[3]);
staters[staters.Count - 1].Barcode = Convert.ToInt32(bs);
staters[staters.Count - 1].City = row[3];
staters[staters.Count - 1].County = row[4];
}
csv.Close();
staters.RemoveAt(staters.Count - 1);
List<Stater> testing = staters;
}
}
示例2: createStaterObjects
//Upload the stater list into the program.
private void createStaterObjects()
{
staters.Clear();
string pathstring = loadStaterList();
CsvFileReader csv = new CsvFileReader(pathstring);
char[] _separators = new char[] { '\n', '"', ',' };
CsvRow row = new CsvRow();
bool entering = true;
while (entering == true)
{
entering = csv.ReadRow(row);
if (row.Count != 5)
{
label1.Size = new Size(200, 30);
label1.Location = new Point(50, 20);
label1.Text = pathstring + " invalid format;\nCorrect Format: First Name, Last Name, Barcode";
error = true;
}
staters.Add(new Stater(row[1], row[2]));
char[] bar = row[0].ToCharArray();
string bs = Convert.ToString(bar[0]) + Convert.ToString(bar[1]) + Convert.ToString(bar[2]) + Convert.ToString(bar[3]);
staters[staters.Count - 1].Barcode = Convert.ToInt32(bs);
staters[staters.Count - 1].City = row[3];
staters[staters.Count - 1].County = row[4];
if (staters.Count() > 1 && staters[staters.Count - 1].Barcode == staters[staters.Count - 2].Barcode)
{
staters.RemoveAt(staters.Count - 1);
break;
}
}
csv.Close();
SNPhasBeenLoaded = true;
}
示例3: createSNPFromcsvToolStripMenuItem_Click
//Method to Load SNP for City Photos
private void createSNPFromcsvToolStripMenuItem_Click(object sender, EventArgs e)
{
if (checkSwitchStatus())
{
Picture.Text = "";
listBox1.Items.Clear();
listBox1.SelectionMode = SelectionMode.None;
programRunning = "City Photos";
this.Text = programRunning;
error = false;
this.Controls.Remove(b);
this.Controls.Remove(c);
this.Controls.Remove(t);
this.Controls.Remove(band);
this.Controls.Remove(chorus);
this.Controls.Remove(talent);
this.Controls.Remove(activities);
this.Size = new Size(282, 326);
Picture.Text = "";
listBox1.Items.Clear();
Picture.Focus();
staters.Clear();
string pathstring = loadStaterList();
CsvFileReader csv = new CsvFileReader(pathstring);
char[] _separators = new char[] { '\n', '"', ',' };
CsvRow row = new CsvRow();
bool entering = true;
while (entering == true)
{
entering = csv.ReadRow(row);
if (row.Count != 5)
{
label1.Size = new Size(200, 30);
label1.Location = new Point(73, 24);
label1.Text = pathstring + " invalid format;\nCorrect Format: First Name, Last Name, Barcode";
error = true;
}
staters.Add(new Stater(row[1], row[2]));
char[] bar = row[0].ToCharArray();
string bs = Convert.ToString(bar[0]) + Convert.ToString(bar[1]) + Convert.ToString(bar[2]) + Convert.ToString(bar[3]);
staters[staters.Count - 1].Barcode = Convert.ToInt32(bs);
staters[staters.Count - 1].City = row[3];
if (staters.Count() > 1 && staters[staters.Count - 1].Barcode == staters[staters.Count - 2].Barcode)
{
staters.RemoveAt(staters.Count - 1);
break;
}
}
csv.Close();
rows();
SNPhasBeenLoaded = true;
//checkStaterList();
if (error == false)
{
label1.Size = new Size(130, 30);
label1.Location = new Point(73, 24);
label1.Text = "Stater list successfully loaded.";
Picture.Enabled = true;
button1.Enabled = true;
Picture.Focus();
}
else
{
label1.Size = new Size(130, 30);
label1.Location = new Point(73, 24);
label1.Text = "The stater list contains an error";
}
}
}
示例4: LoadYesterdayLongRemains
void LoadYesterdayLongRemains()
{
try
{
const string kRemainsFolder = @"remains\";
string fileName = String.Format("{0}_remains.csv", _yesterday.ToString("yyyy_MM_dd"));
string remains_path = String.Format("{0}{1}{2}", kFolder, kRemainsFolder, fileName);
logger.Info("{0} 읽기 시도", remains_path);
CsvFileReader reader = new CsvFileReader(remains_path);
Boolean header = true;
while (true)
{
CsvRow row = new CsvRow();
if (reader.ReadRow(row))
{
if (header)
{
header = false;
continue;
}
DateTime dt = DateTime.ParseExact(row[0], "yyyy-MM-dd", null);
long count = Convert.ToInt64(TextUtil.RemoveComma(row[1]));
double rate = Math.Round(Convert.ToDouble(row[2]), 5);
int price = Convert.ToInt32(TextUtil.RemoveComma(row[3]));
long notional = Convert.ToInt64(TextUtil.RemoveComma(row[4]));
KtbSpotPosition pos = new KtbSpotPosition();
pos.TradingDate = dt;
pos.Long_2_Short_1 = 2;
pos.Count = count;
pos.Rate = rate;
pos.Price = price;
pos.Notional = notional;
this.Longs.Add(pos);
}
else
{
break;
}
}
reader.Close();
logger.Info("Yesterday Long Remain Position Load complete.");
}
catch (System.Exception ex)
{
logger.Error(ex.ToString());
}
}
示例5: button1_Click
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog _openFileDialog = new OpenFileDialog();
_openFileDialog.FileName = "SNPCC.csv";
_openFileDialog.Filter = "csv files (*.csv)|*.csv";
_openFileDialog.DefaultExt = "csv";
_openFileDialog.FilterIndex = 2;
_openFileDialog.AddExtension = true;
if (_openFileDialog.ShowDialog() == DialogResult.OK)
{
string fileName = _openFileDialog.FileName;
CsvFileReader csv = new CsvFileReader(fileName);
char[] _separators = new char[] { '\n', '"', ',' };
CsvRow row = new CsvRow();
bool entering = true;
while (entering == true)
{
entering = csv.ReadRow(row);
staters.Add(new Stater(row[1], row[2]));
char[] bar = row[0].ToCharArray();
string bs = Convert.ToString(bar[0]) + Convert.ToString(bar[1]) + Convert.ToString(bar[2]) + Convert.ToString(bar[3]);
staters[staters.Count - 1].Barcode = Convert.ToInt32(bs);
staters[staters.Count - 1].City = row[3];
staters[staters.Count - 1].County = row[4];
}
csv.Close();
}
_openFileDialog.FileName = "MasterPhotoList.csv";
_openFileDialog.Filter = "csv files (*.csv)|*.csv";
_openFileDialog.DefaultExt = "csv";
_openFileDialog.FilterIndex = 2;
_openFileDialog.AddExtension = true;
if (_openFileDialog.ShowDialog() == DialogResult.OK)
{
string fileName = _openFileDialog.FileName;
CsvFileReader csv = new CsvFileReader(fileName);
char[] _separators = new char[] { '\n', '"', ',' };
CsvRow row = new CsvRow();
bool entering = true;
while (entering == true)
{
entering = csv.ReadRow(row);
if (entering == true)
{
photoList.Add(new Stater(row[1], row[0]));
char[] bar = row[2].ToCharArray();
string bs = Convert.ToString(bar[0]) + Convert.ToString(bar[1]) + Convert.ToString(bar[2]) + Convert.ToString(bar[3]);
photoList[photoList.Count - 1].Barcode = Convert.ToInt32(bs);
}
}
csv.Close();
}
SaveFileDialog MySaveFileDialog = new SaveFileDialog();
MySaveFileDialog.DefaultExt = "csv";
if (MySaveFileDialog.ShowDialog() == DialogResult.OK)
{
using (Stream myStream = MySaveFileDialog.OpenFile())
{
if (myStream != null)
{
List<Stater> temp = new List<Stater>();
for (int i = 0; i < photoList.Count; i++)
{
temp.Add(new Stater(photoList[i].FirstName, photoList[i].LastName));
temp[temp.Count - 1].Barcode = photoList[i].Barcode;
}
for (int i = 0; i < photoList.Count; i++)
{
for (int j = 0; j < staters.Count; j++)
{
if (photoList[i].Barcode == staters[j].Barcode)
{
staters.RemoveAt(j);
}
}
}
for (int i = 0; i < photoList.Count; i++)
{
for (int j = 0; j < staters.Count; j++)
{
if (photoList[i].Barcode == staters[j].Barcode)
{
staters.RemoveAt(j);
}
}
}
using (StreamWriter myWritter = new StreamWriter(myStream, System.Text.Encoding.ASCII))
{
for (int i = 0; i < staters.Count; i++)
{
myWritter.WriteLine(staters[i].FirstName + "," + staters[i].LastName + "," + staters[i].Barcode + "," + staters[i].City + "," + staters[i].County);
//.........这里部分代码省略.........
示例6: button2_Click
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog _openFileDialog = new OpenFileDialog();
_openFileDialog.FileName = "MasterPhotoList.csv";
_openFileDialog.Filter = "csv files (*.csv)|*.csv";
_openFileDialog.DefaultExt = "csv";
_openFileDialog.FilterIndex = 2;
_openFileDialog.AddExtension = true;
if (_openFileDialog.ShowDialog() == DialogResult.OK)
{
string fileName = _openFileDialog.FileName;
CsvFileReader csv = new CsvFileReader(fileName);
char[] _separators = new char[] { '\n', '"', ',' };
CsvRow row = new CsvRow();
bool entering = true;
while (entering == true)
{
entering = csv.ReadRow(row);
if (entering == true)
{
photoList.Add(new Stater(row[1], row[0]));
char[] bar = row[2].ToCharArray();
string bs = Convert.ToString(bar[0]) + Convert.ToString(bar[1]) + Convert.ToString(bar[2]) + Convert.ToString(bar[3]);
photoList[photoList.Count - 1].Barcode = Convert.ToInt32(bs);
}
}
csv.Close();
}
_openFileDialog.FileName = "Missing Staters.csv";
_openFileDialog.Filter = "csv files (*.csv)|*.csv";
_openFileDialog.DefaultExt = "csv";
_openFileDialog.FilterIndex = 2;
_openFileDialog.AddExtension = true;
if (_openFileDialog.ShowDialog() == DialogResult.OK)
{
string fileName = _openFileDialog.FileName;
CsvFileReader csv = new CsvFileReader(fileName);
char[] _separators = new char[] { '\n', '"', ',' };
counter = 0;
CsvRow row = new CsvRow();
bool entering = true;
while (entering == true)
{
entering = csv.ReadRow(row);
if (entering == true)
{
check.Add(new Stater(row[0], row[1]));
char[] bar = row[2].ToCharArray();
string bs = Convert.ToString(bar[1]) + Convert.ToString(bar[1]) + Convert.ToString(bar[2]) + Convert.ToString(bar[3]);
check[counter].Barcode = Convert.ToInt32(bs);
check[counter].City = row[3];
check[counter].County = row[4];
}
counter++;
}
csv.Close();
}
SaveFileDialog MySaveFileDialog = new SaveFileDialog();
MySaveFileDialog.DefaultExt = "csv";
if (MySaveFileDialog.ShowDialog() == DialogResult.OK)
{
using (Stream myStream = MySaveFileDialog.OpenFile())
{
if (myStream != null)
{
for (int i = 0; i < counter-1; i++)
{
for (int j = 0; j < photoList.Count; j++)
{
bool contains = photoList.Contains(check[i]);
if (contains==true)
{
check.RemoveAt(i);
}
}
}
using (StreamWriter myWritter = new StreamWriter(myStream, System.Text.Encoding.ASCII))
{
for (int i = 0; i < check.Count; i++)
{
myWritter.WriteLine(check[i].FirstName + "," + check[i].LastName + "," + check[i].Barcode + "," + check[i].City + "," + check[i].County);
}
}
}
}
}
//.........这里部分代码省略.........
示例7: HarmonyToDB
//.........这里部分代码省略.........
}
else
TobeWritten += Descs[j] + ",";
}
TobeWritten = TobeWritten.Remove(TobeWritten.Length - 1);
if (IsHeaderWritten == false)
{
OriginalHeader = TobeWritten;
stream.WriteLine(TobeWritten);
IsHeaderWritten = true;
}
else
{
// inconsistency between the headers... skip the plate
if (TobeWritten != OriginalHeader)
{
continue;
}
}
#endregion
// now let's process the data
int IdxRow = 0;
while (!CSVReader.EndOfStream)
{
CSVReader.ReadRow(CurrentRow);
TobeWritten = PlateName+",";
for (int j = 0; j < Descs.Count; j++)
{
if ((IdxBoundingBox > -1) && (j == IdxBoundingBox))
{
// let's process the bounding box
string BB = CurrentRow[j];
BB = BB.Remove(BB.Length - 1);
BB = BB.Remove(0, 1);
string[] Splitted = BB.Split(Sep, StringSplitOptions.None);
TobeWritten += Splitted[0] + "," + Splitted[1] + "," + Splitted[2] + "," + Splitted[3] + ",";
// j += 3;
}
else if (j == IndexRow)
{
TobeWritten += ConvertPosition(int.Parse(CurrentRow[IndexCol]), int.Parse(CurrentRow[IndexRow]))+",";
}
else if ((j == IndexCol)||(j==IndexCellcount)||(j==IndexCompound)||(j==IndexConcentration))
{
// do nothing
}
else
{
if (CurrentRow[j] != "")
TobeWritten += CurrentRow[j] + ",";
else
TobeWritten += "NaN,";
}
}
TobeWritten = TobeWritten.Remove(TobeWritten.Length - 1);
stream.WriteLine(TobeWritten );
IdxRow++;
}
CSVReader.Close();
stream.Dispose();
MyProgressBar.progressBar.Value++;
MyProgressBar.progressBar.Update();
}
MyProgressBar.Close();
#endregion
#region let's build the database now
// if (CSVFeedBackWindow == null) return;
// if (CSVFeedBackWindow.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;
string DBPath = Path + "\\DB";
Directory.CreateDirectory(DBPath);
cConvertCSVtoDB CCTODB = CSVtoDB(TPath, ",", DBPath);
if (CCTODB == null)
{
return;
}
else
{
// update image accessor
cGlobalInfo.OptionsWindow.radioButtonImageAccessDefined.Checked = false;
cGlobalInfo.OptionsWindow.radioButtonImageAccessHarmony35.Checked = true;
cGlobalInfo.OptionsWindow.textBoxImageAccesImagePath.Text = Path;
cGlobalInfoToBeExported GlobalInfoToBeExported = new cGlobalInfoToBeExported();
cGlobalInfo.OptionsWindow.TmpOptionPath = GlobalInfoToBeExported.Save(DBPath+"\\Options.opt");
//cGlobalInfo.OptionsWindow.sav
}
#endregion
}
示例8: backgroundWorkerForCSVtoDB_DoWork
private void backgroundWorkerForCSVtoDB_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
CSVsr = new CsvFileReader(PathName);
CSVsr.Separator = this.Delimiter.ToCharArray()[0];
CsvRow OriginalNames = new CsvRow();
if (!CSVsr.ReadRow(OriginalNames))
{
CSVsr.Close();
return;
}
int ColPlateName = GetColIdxFor("Plate name", CSVWindow);
int ColCol = GetColIdxFor("Column", CSVWindow);
int ColRow = GetColIdxFor("Row", CSVWindow);
int ColWellPos = GetColIdxFor("Well position", CSVWindow);
int ColPhenotypeClass = GetColIdxFor("Phenotype Class", CSVWindow);
int[] ColsForDescriptors = GetColsIdxFor("Descriptor", CSVWindow);
FormForProgress ProgressWindow = new FormForProgress();
ProgressWindow.Text = "CSV -> DB : processing";
ProgressWindow.Show();
CsvRow CurrentDesc = new CsvRow();
int TotalPlateNumber = 0;
int TotalObjectNumber = 0;
int TotalWellNumber = 0;
string OriginalPlatePlateName;
string CurrentPlateName;
string ConvertedName;
this.CompleteReportString += "Source file: " + PathName + "\n";
this.CompleteReportString += OriginalNames.Count + " features selected.\n";
this.CompleteReportString += "Time stamp: " + DateTime.Now.ToString() + " \n";
if (CSVsr.ReadRow(CurrentDesc) == false) return;
do
{
if (ColPlateName == -1)
{
ConvertedName = OriginalPlatePlateName = CurrentPlateName = "Generated Plate Name";
}
else
{
OriginalPlatePlateName = CurrentDesc[ColPlateName];
CurrentPlateName = CurrentDesc[ColPlateName];
ConvertedName = "";
foreach (var c in System.IO.Path.GetInvalidFileNameChars())
ConvertedName = OriginalPlatePlateName.Replace(c, '-');
}
List<string> ListNameSignature = new List<string>();
for (int idxDesc = 0/*Mode + 1*/; idxDesc < ColsForDescriptors.Length/* + Mode + 1*/; idxDesc++)
{
string TmpSignature = OriginalNames[ColsForDescriptors[idxDesc]];
TmpSignature = TmpSignature.Replace('[', '_');
TmpSignature = TmpSignature.Replace(']', '_');
ListNameSignature.Add(TmpSignature);
}
ListNameSignature.Add("Phenotype_Class");
ListNameSignature.Add("Phenotype_Confidence");
cSQLiteDatabase SQDB = new cSQLiteDatabase(SelectedPath + "\\" + ConvertedName, ListNameSignature, true);
this.CompleteReportString += "\n" + CurrentPlateName + ":\n";
TotalPlateNumber++;
do
{
string OriginalWellPos;
int[] Pos = new int[2];
if (Mode == 1)
{
Pos = ConvertPosition(CurrentDesc[ColWellPos]);
if (Pos == null)
{
if (MessageBox.Show("Error in converting the current well position.\nGo to Edit->Options->Import-Export->Well Position Mode to fix this.\nDo you want continue ?", "Loading error !", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == System.Windows.Forms.DialogResult.No)
{
CSVsr.Close();
return;
}
//else
// goto NEXTLOOP;
}
OriginalWellPos = CurrentDesc[ColWellPos];
}
else
{
if (int.TryParse(CurrentDesc[ColCol], out Pos[0]) == false)
goto NEXTLOOP;
if (int.TryParse(CurrentDesc[ColRow], out Pos[1]) == false)
goto NEXTLOOP;
OriginalWellPos = ConvertPosition(int.Parse(CurrentDesc[ColCol]), int.Parse(CurrentDesc[ColRow]));// "("+CurrentDesc[ColCol]+","+CurrentDesc[ColRow]+")";
}
//.........这里部分代码省略.........
示例9: LoadYesterdayLongRemains
void LoadYesterdayLongRemains()
{
try
{
CsvFileReader reader = new CsvFileReader(_yesterdayLongRemainFileName_Input);
Boolean header = true;
while (true)
{
CsvRow row = new CsvRow();
if (reader.ReadRow(row))
{
if (header)
{
header = false;
continue;
}
DateTime dt = DateTime.ParseExact(row[0], "yyyy-MM-dd", null);
long count = Convert.ToInt64(row[1]) * CommonConst._100_000_000;
double rate = Math.Round(Convert.ToDouble(row[2]), 5);
int price = Convert.ToInt32(row[3]);
long notional = Convert.ToInt64(row[4]);
KtbSpotPosition pos = new KtbSpotPosition();
pos.TradingDate = dt;
pos.Long_2_Short_1 = 2;
pos.Count = count;
pos.Rate = rate;
pos.Price = price;
pos.Notional = notional;
this.Longs.Add(pos);
}
else
{
break;
}
}
reader.Close();
logger.Info("Yesterday Long Remain Position Load complete.");
}
catch (System.Exception ex)
{
logger.Error(ex.ToString());
}
}
示例10: LoadTodayShort
void LoadTodayShort()
{
try
{
CsvFileReader reader = new CsvFileReader(_todayShortFileName_Input);
Boolean header = true;
while (true)
{
CsvRow row = new CsvRow();
if (reader.ReadRow(row))
{
if (header)
{
header = false;
continue;
}
DateTime dt = this.Today;
long count = Convert.ToInt64(row[1]) * CommonConst._100_000_000;
double rate = Math.Round(Convert.ToDouble(row[2]), 5);
int price = Convert.ToInt32(TextUtil.RemoveComma(row[3]));
long notional = Convert.ToInt64(TextUtil.RemoveComma(row[4]));
KtbSpotPosition pos = new KtbSpotPosition();
pos.TradingDate = dt;
pos.Long_2_Short_1 = 1;
pos.Count = count;
pos.Rate = rate;
pos.Price = price;
pos.Notional = notional;
this.Shorts.Add(pos);
}
else
{
break;
}
}
reader.Close();
logger.Info("Today Short Position Load complete.");
}
catch (System.Exception ex)
{
logger.Error(ex.ToString());
}
}
示例11: generateDBFromCSVToolStripMenuItem_Click
private void generateDBFromCSVToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog CurrOpenFileDialog = new OpenFileDialog();
CurrOpenFileDialog.Filter = "csv files (*.csv)|*.csv";//|db files (*.db)|*.db|nc files (*.nc)|*.nc
CurrOpenFileDialog.Multiselect = false;
DialogResult Res = CurrOpenFileDialog.ShowDialog();
if (Res != DialogResult.OK) return;
FormForImportExcel CSVWindow = CellByCellFromCSV(CurrOpenFileDialog.FileNames[0]);
if (CSVWindow == null) return;
if (CSVWindow.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;
if (CompleteScreening != null) CompleteScreening.Close3DView();
FolderBrowserDialog WorkingFolderDialog = new FolderBrowserDialog();
WorkingFolderDialog.ShowNewFolderButton = true;
WorkingFolderDialog.Description = "Select the working directory";
if (WorkingFolderDialog.ShowDialog() != DialogResult.OK) return;
//if (IsFileUsed(CurrOpenFileDialog.FileNames[0]))
//{
// MessageBox.Show("File currently used by another application.\n", "Loading error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
// return;
//}
//Microsoft.Research.Science.Data.DataSet Datacsv = Microsoft.Research.Science.Data.CSV.CsvDataSet.Open(CurrOpenFileDialog.FileNames[0]);
//int NumDesc = Datacsv.Variables.Count;
//for (int IdxDesc = 0; IdxDesc < NumDesc; IdxDesc++)
//{
// var DescInfo = Datacsv.Variables[IdxDesc];
// string NameDesc = DescInfo.Name;
// var TypeData = DescInfo.TypeOfData;
// string DataName = TypeData.Name;
//}
int NumPlateName = 0;
int NumRow = 0;
int NumCol = 0;
int NumWellPos = 0;
// int NumLocusID = 0;
// int NumConcentration = 0;
// int NumName = 0;
// int NumInfo = 0;
// int NumClass = 0;
int numDescritpor = 0;
for (int i = 0; i < CSVWindow.dataGridViewForImport.Rows.Count; i++)
{
string CurrentVal = CSVWindow.dataGridViewForImport.Rows[i].Cells[2].Value.ToString();
if ((CurrentVal == "Plate name") && ((bool)CSVWindow.dataGridViewForImport.Rows[i].Cells[1].Value))
NumPlateName++;
if ((CurrentVal == "Row") && ((bool)CSVWindow.dataGridViewForImport.Rows[i].Cells[1].Value))
NumRow++;
if ((CurrentVal == "Column") && ((bool)CSVWindow.dataGridViewForImport.Rows[i].Cells[1].Value))
NumCol++;
if ((CurrentVal == "Well position") && ((bool)CSVWindow.dataGridViewForImport.Rows[i].Cells[1].Value))
NumWellPos++;
if ((CurrentVal == "Descriptor") && ((bool)CSVWindow.dataGridViewForImport.Rows[i].Cells[1].Value))
numDescritpor++;
}
if (NumPlateName != 1)
{
MessageBox.Show("One and only one \"Plate Name\" has to be selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if ((NumRow != 1) && (GlobalInfo.OptionsWindow.radioButtonWellPosModeDouble.Checked == true))
{
MessageBox.Show("One and only one \"Row\" has to be selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if ((NumCol != 1) && (GlobalInfo.OptionsWindow.radioButtonWellPosModeDouble.Checked == true))
{
MessageBox.Show("One and only one \"Column\" has to be selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if ((NumWellPos != 1) && (GlobalInfo.OptionsWindow.radioButtonWellPosModeSingle.Checked == true))
{
MessageBox.Show("One and only one \"Well position\" has to be selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if ((numDescritpor < 1) && (CSVWindow.IsImportCSV))
{
MessageBox.Show("You need to select at least one \"Descriptor\" !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
int Mode = 2;
if (GlobalInfo.OptionsWindow.radioButtonWellPosModeSingle.Checked) Mode = 1;
CsvFileReader CSVsr = new CsvFileReader(CurrOpenFileDialog.FileNames[0]);
CsvRow OriginalNames = new CsvRow();
if (!CSVsr.ReadRow(OriginalNames))
//.........这里部分代码省略.........
示例12: Init
public static void Init( string cultureStr)
{
_initialised = true;
_phrases.Clear(); // Reset the list since we are building it again
if (cultureStr != "")
{
try
{
_ci = new CultureInfo(cultureStr);
Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = _ci; // Change the culture of the current application
_localCulture = _ci.TwoLetterISOLanguageName;
_localCulture3Letter = _ci.ThreeLetterISOLanguageName;
}
catch (Exception)
{
}
}
if (_localCulture == "en")
return; // Nothing to do
string phraseFileName = Path.Combine(GlobalDefs.LocalisationPath, _localCulture + ".txt");
string fixedPhraseFileName = Path.Combine(GlobalDefs.LocalisationPath, _localCulture + "-fixed.txt"); // User override language corrections
Monitor.Enter(_phrases); // Get a lock before updating the list
// Get the manually corrected translations if they exist
if (File.Exists(fixedPhraseFileName))
{
try
{
using (CsvFileReader reader = new CsvFileReader(fixedPhraseFileName))
{
CsvRow row = new CsvRow();
while (reader.ReadRow(row))
{
if (row.Count > 1)
{
string key = row[0].ToLower().Trim();
// Take care of special characters
key = key.Replace("\\\\", "\\"); //Order matters first check for \\
key = key.Replace("\\r", "\r");
key = key.Replace("\\n", "\n");
key = key.Replace("\\\'", "\'");
if (!_phrases.ContainsKey(key)) // no duplicates
{
_phrases.Add(key, row[1]); // Create a sorted list of values with manual updates
}
}
}
reader.Close();
}
}
catch (Exception e)
{
Log.AppLog.WriteEntry("Unable to read localisation file " + fixedPhraseFileName + "\n" + e.Message, Log.LogEntryType.Error);
}
}
// Get the automatic translations
if (File.Exists(phraseFileName))
{
try
{
using (CsvFileReader reader = new CsvFileReader(phraseFileName))
{
CsvRow row = new CsvRow();
while (reader.ReadRow(row))
{
if (row.Count > 1)
{
string key = row[0].ToLower().Trim();
// Take care of special characters
key = key.Replace("\\\\", "\\"); //Order matters first check for \\
key = key.Replace("\\r", "\r");
key = key.Replace("\\n", "\n");
key = key.Replace("\\\'", "\'");
if (!_phrases.ContainsKey(key)) // Check if there is a user provided translation if so, skip it
{
_phrases.Add(key, row[1]);
}
}
}
}
}
catch (Exception e)
{
Log.AppLog.WriteEntry("Unable to read localisation file " + phraseFileName + "\n" + e.Message, Log.LogEntryType.Error);
}
}
Monitor.Exit(_phrases);
}
示例13: LoadingCSVProcedure
private void LoadingCSVProcedure(FormForImportExcel FromExcel)
{
int Mode = 2;
if (cGlobalInfo.OptionsWindow.radioButtonWellPosModeSingle.Checked) Mode = 1;
CsvFileReader CSVsr = new CsvFileReader(PathNames[0]);
if (!CSVsr.BaseStream.CanRead)
{
MessageBox.Show("Cannot read the file !", "Process finished !", MessageBoxButtons.OK, MessageBoxIcon.Information);
CSVsr.Close();
return;
}
CsvRow Names = new CsvRow();
if (!CSVsr.ReadRow(Names))
{
CSVsr.Close();
return;
}
int ColSelectedForName = GetColIdxFor("Name", FromExcel);
// int ColLocusID = GetColIdxFor("Locus ID", FromExcel);
// int ColConcentration = GetColIdxFor("Concentration", FromExcel);
// int ColInfo = GetColIdxFor("Info", FromExcel);
// int ColClass = GetColIdxFor("Class", FromExcel);
int ColPlateName = GetColIdxFor("Plate name", FromExcel);
int ColCol = GetColIdxFor("Column", FromExcel);
int ColRow = GetColIdxFor("Row", FromExcel);
int ColWellPos = GetColIdxFor("Well position", FromExcel);
int[] ColsForDescriptors = GetColsIdxFor("Descriptor", FromExcel);
while (CSVsr.EndOfStream != true)
{
NEXT: ;
CsvRow CurrentDesc = new CsvRow();
if (CSVsr.ReadRow(CurrentDesc) == false) break;
string PlateName = CurrentDesc[ColPlateName];
//return;
// check if the plate exist already
cPlate CurrentPlate = cGlobalInfo.CurrentScreening.GetPlateIfNameIsContainIn(PlateName);
if (CurrentPlate == null) goto NEXT;
int[] Pos = new int[2];
if (Mode == 1)
{
Pos = ConvertPosition(CurrentDesc[ColWellPos]);
}
else
{
if (!int.TryParse(CurrentDesc[ColCol], out Pos[0]))
{
if (MessageBox.Show("Error in converting the current well position.\nGo to Edit->Options->Import-Export->Well Position Mode to fix this.\nDo you want continue ?", "Loading error !", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == System.Windows.Forms.DialogResult.No)
{
CSVsr.Close();
return;
}
else
goto NEXTLOOP;
}
Pos[1] = Convert.ToInt16(CurrentDesc[ColRow]);
}
cWell CurrentWell = CurrentPlate.GetWell(Pos[0] - 1, Pos[1] - 1, false);
if (CurrentWell == null) goto NEXT;
if (ColSelectedForName != -1)
{
CurrentWell.SetCpdName(CurrentDesc[ColSelectedForName]);
}
else
{
CurrentWell.SetAsNoneSelected();
}
//if (ColLocusID != -1)
//{
// double CurrentValue;
// if (!double.TryParse(CurrentDesc[ColLocusID], out CurrentValue))
// goto NEXTSTEP;
// CurrentWell.LocusID = CurrentValue;
//}
//if (ColConcentration != -1)
//{
// double CurrentValue;
// if (!double.TryParse(CurrentDesc[ColConcentration], out CurrentValue))
// goto NEXTSTEP;
// CurrentWell.Concentration = CurrentValue;
//}
NEXTSTEP: ;
//if (ColInfo != -1)
// CurrentWell.Info = CurrentDesc[ColInfo];
//if (ColClass != -1)
//.........这里部分代码省略.........
示例14: CellByCellFromCSV
private FormForImportExcel CellByCellFromCSV(string FileName, char Delimiter)
{
FormForImportExcel FromExcel = new FormForImportExcel();
FromExcel.IsImportCSV = true;
int Mode = 2;
if (cGlobalInfo.OptionsWindow.radioButtonWellPosModeSingle.Checked) Mode = 1;
CsvFileReader CSVsr = new CsvFileReader(FileName);
CSVsr.Separator = Delimiter;
CsvRow Names = new CsvRow();
if (!CSVsr.ReadRow(Names))
{
CSVsr.Close();
return null;
}
int NumPreview = 4;
List<CsvRow> LCSVRow = new List<CsvRow>();
for (int Idx = 0; Idx < NumPreview; Idx++)
{
CsvRow TNames = new CsvRow();
// if (TNames.Count == 0) break;
if (!CSVsr.ReadRow(TNames))
{
CSVsr.Close();
return null;
}
LCSVRow.Add(TNames);
}
// FromExcel.dataGridViewForImport.RowsDefaultCellStyle.BackColor = Color.Bisque;
FromExcel.dataGridViewForImport.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige;
DataGridViewColumn ColName = new DataGridViewColumn();
FromExcel.dataGridViewForImport.Columns.Add("Data Name", "Data Name");
DataGridViewCheckBoxColumn columnSelection = new DataGridViewCheckBoxColumn();
columnSelection.Name = "Selection";
FromExcel.dataGridViewForImport.Columns.Add(columnSelection);
DataGridViewComboBoxColumn columnType = new DataGridViewComboBoxColumn();
if (cGlobalInfo.OptionsWindow.radioButtonWellPosModeDouble.Checked)
columnType.DataSource = new string[] { "Plate name", "Column", "Row", "Descriptor", "Phenotype Class" };
else
columnType.DataSource = new string[] { "Plate name", "Well position", "Descriptor", "Phenotype Class" };
columnType.Name = "Type";
FromExcel.dataGridViewForImport.Columns.Add(columnType);
for (int i = 0; i < LCSVRow.Count; i++)
{
DataGridViewColumn NewCol = new DataGridViewColumn();
NewCol.ReadOnly = true;
FromExcel.dataGridViewForImport.Columns.Add("Readout " + i, "Readout " + i);
}
if (LCSVRow[0].Count > Names.Count)
{
CSVsr.Close();
MessageBox.Show("Inconsistent column number. Check your CSV file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
for (int i = 0; i < Names.Count; i++)
{
int IdxRow = 0;
FromExcel.dataGridViewForImport.Rows.Add();
FromExcel.dataGridViewForImport.Rows[i].Cells[IdxRow++].Value = Names[i];
if (i == 0) FromExcel.dataGridViewForImport.Rows[i].Cells[IdxRow++].Value = true;
else if (i == 1) FromExcel.dataGridViewForImport.Rows[i].Cells[IdxRow++].Value = true;
else if ((i == 2) && (cGlobalInfo.OptionsWindow.radioButtonWellPosModeDouble.Checked)) FromExcel.dataGridViewForImport.Rows[i].Cells[IdxRow++].Value = true;
else FromExcel.dataGridViewForImport.Rows[i].Cells[IdxRow++].Value = false;
if (i == 0)
{
FromExcel.dataGridViewForImport.Rows[i].Cells[IdxRow++].Value = "Plate name";
}
else if (i == 1)
{
if (cGlobalInfo.OptionsWindow.radioButtonWellPosModeDouble.Checked)
{
FromExcel.dataGridViewForImport.Rows[i].Cells[IdxRow++].Value = "Column";
}
else
{
FromExcel.dataGridViewForImport.Rows[i].Cells[IdxRow++].Value = "Well position";
}
}
else if (i == 2)
{
if (cGlobalInfo.OptionsWindow.radioButtonWellPosModeDouble.Checked)
{
FromExcel.dataGridViewForImport.Rows[i].Cells[IdxRow++].Value = "Row";
}
else
FromExcel.dataGridViewForImport.Rows[i].Cells[IdxRow++].Value = "Descriptor";
}
else
//.........这里部分代码省略.........