Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private bool ReadTableFromFile()
- {
- System.Data.DataTable curr_table = dgv.DataSource as System.Data.DataTable;
- System.IO.StreamReader strr = null;
- DateTime now = DateTime.Now;
- gDict.Clear();
- if (!System.IO.File.Exists(filePath + @"\" + fileName)) return false;
- try
- {
- strr = new System.IO.StreamReader(filePath + @"\" + fileName);
- if (strr.ReadLine().Equals("__FILE_BEGIN__"))//file is correct
- {
- do
- {
- string buffer = strr.ReadLine();
- if (buffer.Equals("__EOF__"))
- {
- strr.Close();
- fileOpenWasSuccessful = true;
- dgv.Sort(dgv.Columns[0], System.ComponentModel.ListSortDirection.Ascending);
- return true;
- }
- if (buffer.Equals("__LINE_BEGIN__"))//file is correct
- {
- System.Data.DataRow theRow = curr_table.NewRow();
- string[] preparedString;
- do
- {
- preparedString = strr.ReadLine().Split('=');
- if (preparedString[0].Equals("Date"))
- {
- DateTime dt = new DateTime();//15.03.2013 3:01:13 //dd.MM.yyyy hh:mm:ss
- dt = DateTime.ParseExact(preparedString[1], "dd.MM.yyyy hh:mm:ss", System.Globalization.CultureInfo.CurrentCulture);
- TimeSpan timediff = (now - dt);
- theRow[preparedString[0]] = timediff;
- preparedString = strr.ReadLine().Split('=');
- if (preparedString[0].Equals("IP"))
- {
- theRow[preparedString[0]] = preparedString[1];
- gDict.Add(preparedString[1], dt);
- curr_table.Rows.Add(theRow);
- if (strr.ReadLine().Equals("__EOL__"))
- break;
- else throw new fileDataIncorrectException();
- }
- else throw new fileDataIncorrectException();
- }
- else throw new fileDataIncorrectException();
- } while (true);
- }
- else throw new fileDataIncorrectException();
- }
- while (strr.Peek() != -1);
- return true;
- }
- else throw new fileDataIncorrectException();
- }
- catch (fileDataIncorrectException ex) { System.Windows.Forms.MessageBox.Show("Bad settings file\n" + ex.Message); return false; }
- catch (Exception ex) { System.Windows.Forms.MessageBox.Show("THERE WERE UNHANDLED ERROR DURING READING FILE!\n" + ex.Message); return false; }
- finally { if (strr != null) strr.Close(); }
- //return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement