private void SetPressuressSchedule() { BinaryFormatter formatter = new BinaryFormatter(); string pubPath = Environment.CurrentDirectory; string dataPath = pubPath + "\\..\\..\\data\\indications\\" + activeDate.Substring(0, 4) + "\\" + activeDate + "\\pressure"; DirectoryInfo dir = new DirectoryInfo(@dataPath); progressBar1.Visible = true; progressBar1.Minimum = 1; progressBar1.Maximum = dir.GetFiles().Length; progressBar1.Value = 1; progressBar1.Step = 10; foreach (var item in dir.GetFiles()) { progressBar1.PerformStep(); Schedule shed = new Schedule(); shed.id = Convert.ToInt32(item.Name.Substring(0, item.Name.Length - 4).Substring(4)); shed.name = "noname!"; Form1._form._newRoot.pases.ForEach(iv => { if (iv.id == shed.id) { shed.name = iv.name; } }); using (FileStream fs = new FileStream(dataPath + "\\" + item.Name, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { foreach (int id in userJconfig.formSchedulePressures.checkedPases) { if (id == Convert.ToInt32(item.Name.Substring(0, item.Name.Length - 4).Substring(4))) { using (BinaryReader reader = new BinaryReader(fs)) { // пока не достигнут конец файла // считываем каждое значение из файла while (reader.PeekChar() > -1) { Indication ind = new Indication(); DateTime dt = DateTime.Parse(reader.ReadString()); ind.datetime = dt; ind.value = Convert.ToSingle(reader.ReadString()); shed.indications.Add(ind); } } } } fs.Close(); } PressuresSchedule.Add(shed); } progressBar1.Visible = false; }
private void SetPressuressSchedulePeriod() { DateTime startDate = dateTimePicker1.Value; DateTime stopDate = dateTimePicker2.Value; string pubPath = Environment.CurrentDirectory; string dataPath = ""; progressBar1.Visible = true; while (startDate < stopDate) { dataPath = pubPath + "\\..\\..\\data\\indications\\" + startDate.Year.ToString() + "\\" + startDate.Year.ToString() + "-" + startDate.Month.ToString() + "-" + startDate.Day.ToString() + "\\pressure"; //определить существование дирректории if (Directory.Exists(dataPath)) { DirectoryInfo dir = new DirectoryInfo(@dataPath); progressBar1.Minimum = 1; progressBar1.Value = 1; progressBar1.Step = 10; progressBar1.Maximum = dir.GetFiles().Length; foreach (var item in dir.GetFiles()) { progressBar1.PerformStep(); Schedule shed = new Schedule(); PressuresSchedule.ForEach(sciv => { if (sciv.id == Convert.ToInt32(item.Name.Substring(0, item.Name.Length - 4).Substring(4))) { shed = sciv; return; } }); if (shed.name == null) { shed.id = Convert.ToInt32(item.Name.Substring(0, item.Name.Length - 4).Substring(4)); shed.name = "noname!"; Form1._form._newRoot.pases.ForEach(iv => { if (iv.id == shed.id) { shed.name = iv.name; } }); PressuresSchedule.Add(shed); } using (FileStream fs = new FileStream(dataPath + "\\" + item.Name, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { foreach (int id in userJconfig.formSchedulePressures.checkedPases) { if (id == Convert.ToInt32(item.Name.Substring(0, item.Name.Length - 4).Substring(4))) { using (BinaryReader reader = new BinaryReader(fs)) { // пока не достигнут конец файла // считываем каждое значение из файла while (reader.PeekChar() > -1) { Indication ind = new Indication(); DateTime dt = DateTime.Parse(reader.ReadString()); ind.datetime = dt; ind.value = Convert.ToSingle(reader.ReadString()); shed.indications.Add(ind); } } } } fs.Close(); } } } startDate = startDate.AddDays(1); } progressBar1.Visible = false; }