private static void WriteInFile(string path, string error, string message, string caption, MessageViewMode mode) { string s = DateTime.Now.ToString("########## dd.MM.yyyy HH:mm:ss"); StreamWriter sw = new StreamWriter(path + "errors.txt", true, Encoding.Unicode); sw.WriteLine(s + "\n " + message + "\n" + error); sw.Close(); if (caption != null) { MessageView mv = new MessageView(message, caption, mode); mv.ShowDialog(); } }
private void Read_Click(object sender, RoutedEventArgs e) { plotter.Model = null; System.Threading.Thread window = null; readingWindow = new MessageView("Считывание данных", "", MessageViewMode.Message, false); window = new System.Threading.Thread(new System.Threading.ThreadStart(ShowWindowReading)); window.Start(); selectedParam = new ObservableCollection <CheckedParam>(); works = new ObservableCollection <WorkSpark>(); int indexColor = 0; foreach (CheckedParam param in lbParams.Items) { param.Points.Clear(); if (param.IsChecked) { param.ColorLine = SparkControls.Helper.ListColor[indexColor++]; selectedParam.Add(param); } } foreach (CheckedParam param in selectedParam) { sqlCmd.CommandText = "update '" + param.Title + "|" + param.Unit + "' set value = replace(value, ',','.')"; sqlCmd.ExecuteNonQuery(); sqlCmd.CommandText = "select * from '" + param.Title + "|" + param.Unit + "';"; SQLiteDataReader dataReader = sqlCmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(dataReader); bool oldData = false; foreach (DataRow dr in dt.Rows) { try { if (oldData) { param.Points.Add(new PointDate { X = Convert.ToDateTime(dr[2]), Y = Convert.ToDouble(dr[1]) }); } else { PointDate pd = new PointDate { X = Convert.ToDateTime(dr[2]), Y = Convert.ToDouble(dr[1]), NumWork = Convert.ToInt32(dr[3]) }; param.Points.Add(pd); if (works.Count == 0) { works.Add(new WorkSpark() { id = pd.NumWork.ToString(), startwork = pd.X.ToString("yyyy-MM-dd HH:mm:ss") }); } else { bool add = true; foreach (WorkSpark ws in works) { if (ws.id == pd.NumWork.ToString()) { add = false; break; } } if (add) { works.Add(new WorkSpark() { id = pd.NumWork.ToString(), startwork = pd.X.ToString("yyyy-MM-dd HH:mm:ss") }); } } } } catch { param.Points.Add(new PointDate { X = Convert.ToDateTime(dr[2]), Y = Convert.ToDouble(dr[1]) }); oldData = true; } } } FillingParamsData(); System.Threading.Thread.Sleep(100); readingWindow.Invoke(new Action(() => readingWindow.Close())); }