private void DataFile(int[,] m, ref int r, ref int c) { string StartUpPath = Application.StartupPath; string f = StartUpPath + @"\cheap.txt"; StreamReader read = new StreamReader(f); c = Convert.ToInt32(read.ReadLine()); r = Convert.ToInt32(read.ReadLine()); string WholeLine; for (int x = 1; x <= r; x++) { WholeLine = read.ReadLine(); lines = WholeLine.Split(' '); //Alternate Solution //where the number of data per row varies //*************************************** //int u = lines.Length; //for(int y=1;y<=u;y++) for (int y = 1; y <= c; y++) { m[x, y] = int.Parse(lines[y - 1]); } } read.Close(); }
/// <summary> /// Method that retrieves the whole transaction list parsing /// a flat file containing a transaction items values on the same row /// </summary> /// <returns>Transaction database list</returns> public List <Transaction> GetAllTransactions() { String WholeLine; String[] ParsedLine; StreamReader InputData; int mapIndex; List <Transaction> result = new List <Transaction>(); // create a new map map = new Map(); // retrieve the relative path of the flat file from the configuration data String AbsFilepath = ConfigurationManager.ConnectionStrings["BasketConnectionString"].ConnectionString; // open the stream for reading InputData = File.OpenText(AbsFilepath); // foreach line in the flat file do: while (!InputData.EndOfStream) { // create a new empty transaction Transaction trans = new Transaction(); WholeLine = InputData.ReadLine(); // split the line in chunks. each chunk is a text-formatted item value delimited by black spaces ParsedLine = WholeLine.Split(' '); foreach (String TextItem in ParsedLine) { // check whether the current chunk is the empty string or not if (TextItem != "") { // parse the actual item integer value from the chunk int item = Int32.Parse(TextItem); // try to get the map index for this item mapIndex = map.GetIndex(item); // check if the item has been already stored in the map or not if (mapIndex == -1) { // if not, add the item to the map and get its map index map.Insert(item); mapIndex = map.GetIndex(item); } // add the map index to the transaction trans.addItem(mapIndex); } } // add the transaction to result result.Add(trans); } // we are done. close the stream and return result InputData.Close(); return(result); }
private void BtnFileSort_Click(object sender, EventArgs e) { int c = 0; string [] lines = new string[2]; string s = Application.StartupPath; string f = s + @"\marks.txt"; StreamReader r = new StreamReader(f); StudentRecord[] rec = new StudentRecord[100]; string WholeLine; while ((WholeLine = r.ReadLine()) != null) { c++; lines = WholeLine.Split(','); rec[c] = new StudentRecord(); rec[c].sname = lines[0]; rec[c].mark = int.Parse(lines[1]); } r.Close(); int n = c; Sort(rec, n); Display(rec, n); }
private void BtnRead_Click(object sender, EventArgs e) { c = 0; n = 0; string s = Application.StartupPath; string f = s + @"\names.txt"; StreamReader r = new StreamReader(f); string WholeLine; while ((WholeLine = r.ReadLine()) != null) { c++; lines = WholeLine.Split(' '); //contents of WholeLine separated based //on blank space and each part stored st[c].fn = lines[0]; st[c].ln = lines[1]; st[c].age = Convert.ToInt32(lines[2]); } r.Close(); n = c; DisplayResults(); Sort(); DisplaySortedResults(); }
/// <summary>Export this pattern as XML</summary> public virtual XElement ToXml(XElement node) { node.Add ( Expr.ToXml(XmlTag.Expr, false), Active.ToXml(XmlTag.Active, false), PatnType.ToXml(XmlTag.PatnType, false), IgnoreCase.ToXml(XmlTag.IgnoreCase, false), Invert.ToXml(XmlTag.Invert, false), WholeLine.ToXml(XmlTag.WholeLine, false), SingleLine.ToXml(XmlTag.SingleLine, false) ); return(node); }
private void toolStripMenuItem2_Click(object sender, EventArgs e) { c = 0; n = 0; openFileDialog1.Reset(); openFileDialog1.InitialDirectory = Application.ExecutablePath; openFileDialog1.Filter = "Text files (*.txt)|*.txt|" + "All files|*.*"; openFileDialog1.FilterIndex = 1; if (openFileDialog1.ShowDialog() == DialogResult.OK) { //string s = Application.StartupPath; //string f = s + @"\albums.txt"; f = openFileDialog1.FileName; StreamReader r = new StreamReader(f); string WholeLine; while ((WholeLine = r.ReadLine()) != null) { c++; lines = WholeLine.Split(','); albumname[c] = lines[0]; borrower[c] = lines[1]; } r.Close(); n = c; Search.Shell(albumname, borrower, n); } else { MessageBox.Show("No File Chosen"); } }
private void FrmAlbums_Load(object sender, EventArgs e) { c = 0; n = 0; string s = Application.StartupPath; string f = s + @"\albums.txt"; StreamReader r = new StreamReader(f); string WholeLine; while ((WholeLine = r.ReadLine()) != null) { c++; lines = WholeLine.Split(','); albumname[c] = lines[0]; borrower[c] = lines[1]; } r.Close(); n = c; Search.Shell(albumname, borrower, n); }
private void OpenFile() { c = 0; n = 0; fileOK = "yes"; StreamReader r = null; try { openFileDialog1.Reset(); openFileDialog1.InitialDirectory = Application.ExecutablePath; openFileDialog1.Filter = "Text files (*.txt)|*.txt|" + "All files|*.*"; openFileDialog1.FilterIndex = 1; if (openFileDialog1.ShowDialog() == DialogResult.OK) { //string s = Application.StartupPath; //string f = s + @"\albums.txt"; f = openFileDialog1.FileName; r = new StreamReader(f); string WholeLine; while ((WholeLine = r.ReadLine()) != null) { c++; lines = WholeLine.Split(','); albumname[c] = lines[0]; borrower[c] = lines[1]; } //r.Close(); In finally statement below //n = c; //add filename to statusbar toolStripStatusLabel.Text = "File Loaded"; Search.Shell(albumname, borrower, n); } else { MessageBox.Show("No File Chosen"); } } catch (Exception exp) { MessageBox.Show("Error Occured during File IO " + exp.Message); fileOK = "no"; } finally { if (r != null) { r.Close(); } if (fileOK == "yes") { n = c; toolStripStatusLabel.Text = "File Loaded";//add filename to statusbar } else { c = 0; n = 0; toolStripStatusLabel.Text = "File Loading Error"; } } }