/// <summary> /// Writes the geometry information to the specified <see cref="XmlWriter" />. /// </summary> /// <param name="writer">The writer.</param> /// <exception cref="System.ArgumentNullException">writer</exception> public override void Serialize(XmlWriter writer) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } writer.WriteStartElement("CoordinateSystem"); CoordinateSystem.Serialize(writer); writer.WriteEndElement(); if (ReferenceProfile != null) { writer.WriteStartElement("ReferenceProfile"); ReferenceProfile.Serialize(writer); writer.WriteEndElement(); } if (MeasureProfile != null) { writer.WriteStartElement("MeasureProfile"); MeasureProfile.Serialize(writer); writer.WriteEndElement(); } writer.WriteStartElement("Flush"); writer.WriteAttributeString("ConnectionType", FlushConnectionType.ToString()); writer.WriteString(XmlConvert.ToString(FlushValue)); writer.WriteEndElement(); writer.WriteStartElement("Gap"); writer.WriteAttributeString("ConnectionType", GapConnectionType.ToString()); writer.WriteString(XmlConvert.ToString(GapValue)); writer.WriteEndElement(); }
/// <inheritdoc /> internal override void Serialize(XmlWriter writer) { base.Serialize(writer); if (ReferenceProfile != null) { writer.WriteStartElement("ReferenceProfile"); ReferenceProfile.Serialize(writer); writer.WriteEndElement(); } if (MeasureProfile != null) { writer.WriteStartElement("MeasureProfile"); MeasureProfile.Serialize(writer); writer.WriteEndElement(); } writer.WriteStartElement("Flush"); writer.WriteAttributeString("ConnectionType", FlushConnectionType.ToString()); writer.WriteString(XmlConvert.ToString(FlushValue)); writer.WriteEndElement(); writer.WriteStartElement("Gap"); writer.WriteAttributeString("ConnectionType", GapConnectionType.ToString()); writer.WriteString(XmlConvert.ToString(GapValue)); writer.WriteEndElement(); }
private void fillProfiles(int selectedPID) { List <MeasureProfile> list = Program.DataProvider.getMeasureProfiles(); combos = new List <DataGridViewComboBoxCell>(); MeasureProfile selected = null; comboBoxProfiles.Text = ""; comboBoxProfiles.Items.Clear(); foreach (MeasureProfile prof in list) { comboBoxProfiles.Items.Add(prof); if (prof.ID == selectedPID) { selected = prof; } } if (selected != null) { comboBoxProfiles.SelectedValue = comboBoxProfiles.SelectedItem = selected; } }
public bool insertMeasureProfile(MeasureProfile profile) { IDbTransaction trans = connection.BeginTransaction(); try { string query = "INSERT INTO MeasureProfile (Name, MaskID, TimeValue) VALUES (" + qouted(profile.Name); query += ", " + (profile.MaskID > 0 ? profile.MaskID.ToString() : "NULL") + ", " + (profile.Time > 0 ? profile.Time.ToString() : "NULL") + ")"; executeNonQuery(query); int id = (int)executeScalar("SELECT MAX(ID) FROM MeasureProfile"); foreach (int pos in profile.Settings.Keys) { query = "INSERT INTO MeasureProfileData (SensorID, MeasureProfileID, Position) VALUES ("; query += "" + getIDbySID(profile.Settings[pos].SID) + ", " + id + ", " + pos + ")"; executeNonQuery(query); } } catch { trans.Rollback(); return(false); } trans.Commit(); measureProfiles = getMeasureProfiles(); return(true); }
/// <summary> /// Проведение измерения /// </summary> /// <param name="length">продолжительность измерения</param> /// <param name="name">наименование измерения</param> /// <param name="prof">профиль измерения</param> /// <param name="init">инициализирующие значения</param> /// <param name="mask">маска по умолчанию</param> public FormMeasure(double length, string name, MeasureProfile prof, double[] init, Mask mask) { this.prof = prof; this.length = length; this.init = init; this.mask = mask; InitializeComponent(); this.Text = "Измерение: " + (this.name = name); }
private void buttonSaveNew_Click(object sender, EventArgs e) { string name = FormStringRequest.GetString("Введите название профиля"); if (name != null) { MeasureProfile prof = collectProfile(name); Program.DataProvider.insertMeasureProfile(prof); fillProfiles(-1); comboBoxProfiles.SelectedIndex = comboBoxProfiles.Items.Count - 1; } }
public static bool Save(MeasureProfile current, MeasureProfile newprof) { FormSaveProfileType inst = FormSaveProfileType.Instance; if (current != null) { inst.labelNowProfile.Text = "\'" + current.ToString() + "\'"; } if (inst.ShowDialog() == DialogResult.OK) { bool newp = inst.radioButtonNew.Checked; string name = inst.textBoxName.Text; if (!newp) { if (current == null || current.ID < 0) { MessageBox.Show("Профиль не заменён: не выбран основной."); return(false); } else { newprof.Name = current.Name; Program.DataProvider.delete("MeasureProfile", "ID=" + current.ID); Program.DataProvider.insertMeasureProfile(newprof); } } else { if (name.Trim() == "") { MessageBox.Show("Профиль не сохранён: вы не ввели название."); return(false); } else { newprof.Name = name; Program.DataProvider.insertMeasureProfile(newprof); } } return(true); } else { return(false); } }
private MeasureProfile collectProfile(string name) { MeasureProfile prof = new MeasureProfile(); prof.Name = name; if (numericUpDownTime.Value > 0) { prof.Time = (int)numericUpDownTime.Value; } if (comboBoxMasks.SelectedItem != null) { prof.MaskID = (comboBoxMasks.SelectedItem as Mask).ID; } Sensor[] list = Program.DataProvider.SensorList.ToArray(); Dictionary <int, Sensor> sens = new Dictionary <int, Sensor>(); for (int i = 0; i < combos.Count; i++) { /*if (combos[i].SelectedItem != null && checks[i].Checked) * {*/ //if (!sens.ContainsValue(combos[i].Value as Sensor)) for (int j = 0; j < list.Length; j++) { //MessageBox.Show(Convert.ToString(combos[i].Value)+"\n"+ list[j].Name + " " + list[j].SID); if (Convert.ToString(combos[i].Value) == list[j].Name + " " + list[j].SID) { //MessageBox.Show(Convert.ToString(combos[i].Value)); sens.Add(Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value) - 1, list[j]); break; } } } //else //return null; /*} * else checks[i].Checked = false;*/ if (sens.Count == 0) { return(null); } prof.Settings = sens; return(prof); }
public MeasureProfile getMeasureProfileByID(int id) { MeasureProfile res = null; measureProfiles = getMeasureProfiles(); foreach (MeasureProfile mp in MeasureProfiles) { if (mp.ID == id) { res = mp; } } return(res); }
private void fillCombos(MeasureProfile prof) { foreach (ComboBox combo in combos) { combo.Items.Clear(); combo.Items.AddRange(Program.DataProvider.SensorList.ToArray()); combo.Text = ""; combo.SelectedItem = null; } foreach (CheckBox check in checks) { check.Checked = false; } if (prof != null) { foreach (int pos in prof.Settings.Keys) { checks[pos].Checked = true; combos[pos].SelectedItem = prof.Settings[pos]; } if (prof.MaskID > 0) { foreach (object o in comboBoxMasks.Items) { if ((o as Mask).ID == prof.MaskID) { comboBoxMasks.SelectedItem = o; } } } if (prof.Time > 0) { numericUpDownTime.Value = prof.Time; } } }
/// <summary> /// Разложить графики сенсоров в соответствии с профилем /// </summary> /// <param name="profile1">профиль</param> public void stackPlotters(MeasureProfile profile1) { MeasureProfile profile = profile1 == null ? null : Program.DataProvider.getMeasureProfileByID(profile1.ID); try { Dictionary <int, Sensor> coll = new Dictionary <int, Sensor>(); Dictionary <object, UserControl> newplotters = new Dictionary <object, UserControl>(); if (profile != null) { foreach (int key in profile.Settings.Keys) { string sid = profile.Settings[key].SID; coll.Add(key, Program.DataProvider.getSensorBySID(sid)); } profile.Settings = coll; foreach (int pos in profile.Settings.Keys) { Plotter plt = new Plotter(); plt.CornerLabel = (pos + 1).ToString(); plt.Label = profile.Settings[pos].ToString(); plt.Adjusting = true; plt.PenWidth = 2; plt.DrawExtremum = true; plt.BorderStyle = BorderStyle.FixedSingle; plt.DrawVerticalBold = false; plt.DrawBaseLine = true; plt.Font = new Font("Courier New", 10); plt.ReactOnScroll = false; plt.BaseValue = profile.Settings[pos].PassportFrequency; newplotters.Add(profile.Settings[pos], plt); } } multiGraph.initWGraph(newplotters, 450, 200, 2, 2); } catch (Exception ex) { Error.Log(ex); MessageBox.Show("Ошибка:\r\n" + ex.Message); } }
private void button3_Click(object sender, EventArgs e) { MeasureProfile prf = collectProfile(""); if (prf == null) { MessageBox.Show("Профиль собран некорректно. Вы не можете его сохранить!"); return; } if (FormSaveProfileType.Save(comboBoxProfiles.SelectedItem as MeasureProfile, prf)) { int c = Program.DataProvider.getMeasureProfiles().Count; if (c > 0) { MeasureProfile mp = Program.DataProvider.MeasureProfiles[c - 1]; Program.Presets.MainWin.refreshComboProfiles(); Program.Presets.MainWin.stackPlotters(mp); fillProfiles(mp.ID); } } }
private MeasureProfile collectProfile(string name) { MeasureProfile prof = new MeasureProfile(); prof.Name = name; if (numericUpDownTime.Value > 0) { prof.Time = (int)numericUpDownTime.Value; } if (comboBoxMasks.SelectedItem != null) { prof.MaskID = (comboBoxMasks.SelectedItem as Mask).ID; } Dictionary <int, Sensor> sens = new Dictionary <int, Sensor>(); for (int i = 0; i < combos.Length; i++) { if (combos[i].SelectedItem != null && checks[i].Checked) { if (!sens.ContainsValue(combos[i].SelectedItem as Sensor)) { sens.Add(i, combos[i].SelectedItem as Sensor); } else { return(null); } } else { checks[i].Checked = false; } } prof.Settings = sens; return(prof); }
private void fillGridProfile(MeasureProfile prof) { if (dataGridView1.Columns.Count == 0) { fillGrid(); if (!flag) { flag = true; } else { return; } } dataGridView1.Rows.Clear(); combos.Clear(); if (prof != null) { foreach (int pos in prof.Settings.Keys) { DataGridViewComboBoxCell dol = new DataGridViewComboBoxCell(); dataGridView1.Rows.Add(Convert.ToString(pos + 1), dol); } try { int count = 0; foreach (int pos in prof.Settings.Keys) { DataGridViewComboBoxCell cell = dataGridView1.Rows[count].Cells[1] as DataGridViewComboBoxCell; if (cell != null) { string compare = prof.Settings[pos].Name + " " + prof.Settings[pos].SID; for (int i = 0; i < cell.Items.Count; i++) { if ((string)cell.Items[i] == compare) { cell.Value = cell.Items[i]; break; } } } count++; } } catch (Exception ex) { MessageBox.Show(ex.Message); } if (prof.MaskID > 0) { foreach (object o in comboBoxMasks.Items) { if ((o as Mask).ID == prof.MaskID) { comboBoxMasks.SelectedItem = o; } } } if (prof.Time > 0) { numericUpDownTime.Value = prof.Time; } } updateBoxes(); }
private void fillGridProfile2(MeasureProfile prof) { }
private void button1_Click(object sender, EventArgs e) { if ( textBoxName.Text != "Новое измерение" || MessageBox.Show("Вы не ввели название измерения. Начать измерение с названием 'Новое измерение'?", "Название", MessageBoxButtons.YesNo) == DialogResult.Yes ) { MeasureProfile prof = collectProfile(""); MeasureProfile curr = comboBoxProfiles.SelectedItem as MeasureProfile; if (prof == null) { MessageBox.Show("Профиль собран некорректно. Вы не можете его сохранить!"); DialogResult = DialogResult.Cancel; return; } bool eq = true; for (int pos = 0; pos < combos.Count; pos++) { if (curr == null || prof.Settings.ContainsKey(pos) ^ curr.Settings.ContainsKey(pos)) { eq = false; } else if (prof.Settings.ContainsKey(pos)) { if (!prof.Settings[pos].Equals(curr.Settings[pos])) { eq = false; } } } if (!eq) { if (FormSaveProfileType.Save(comboBoxProfiles.SelectedItem as MeasureProfile, prof)) { int c = Program.DataProvider.getMeasureProfiles().Count; if (c > 0) { MeasureProfile mp = Program.DataProvider.MeasureProfiles[c - 1]; Program.Presets.MainWin.refreshComboProfiles(); Program.Presets.MainWin.stackPlotters(mp); fillProfiles(mp.ID); usedProfile = mp; } else { usedProfile = Program.Presets.CurrentProfile; } } else { usedProfile = prof; } #region какой-то код /* * if (MessageBox.Show("Установки были изменены. Сохранить изменения?", "изменённые настройки", MessageBoxButtons.YesNo) == DialogResult.Yes) * { * string name = FormStringRequest.GetString("Введите название профиля"); * if (name != null) * { * prof.Name = name; * Program.dataProvider.insertMeasureProfile(prof); * usedProfile = Program.dataProvider.MeasureProfiles[Program.dataProvider.MeasureProfiles.Count - 1]; * } * else * usedProfile = collectProfile("неизвестный"); * * } * else * usedProfile = collectProfile("неизвестный"); */ #endregion } else { usedProfile = curr; } longitude = Convert.ToInt32(textBox6.Text); latitude = Convert.ToInt32(textBox7.Text); Program.Presets.CurrentProfile = curr; DialogResult = DialogResult.OK; Close(); } }
public static double[] getInitValues(Dictionary <DateTime, double[]> win, MeasureProfile applied) { double[] init = new double[Program.nose.SensorCount]; int count = win.Count; DateTime[] times = new DateTime[count]; win.Keys.CopyTo(times, 0); DateTime last = times[times.Length - 1]; for (int i = 0; i < init.Length; i++) { init[i] = 0d; } int c = 0; ///!!!!! ТОНКО ТУТ ЕСЛИ НЕПРАВИЛЬНО - ФИКСИТЬ!!!! for (int i = times.Length - 1; i >= 0 && (0d + last.Ticks - times[i].Ticks) / 1e7d < Program.Presets.stableTime; c++, i--) { for (int j = 0; j < Program.nose.SensorCount; j++) { init[j] += win[times[i]][j]; } } if (c > 0) { for (int i = 0; i < init.Length; i++) { init[i] /= c; } } double[] theinit = new double[applied.Settings.Count]; int ii = 0; foreach (int pos in applied.Settings.Keys) { theinit[ii++] = (int)init[pos]; } return(theinit); }
/// <summary> /// Преобразование данных из объекта газоанализатора в данные, привязанные к сенсорам по профилю /// </summary> /// <param name="win">окно данных</param> /// <param name="profile">профиль проверки</param> /// <param name="min">минимальное значение времени</param> /// <param name="max">максимальное значение времени</param> /// <returns>данные, пригодные для проверки на стабильность</returns> public static Dictionary <Sensor, List <PointD> > WinToData(Dictionary <DateTime, double[]> win, MeasureProfile profile, out DateTime min, out DateTime max) { max = min = DateTime.Now; Dictionary <Sensor, List <PointD> > result = new Dictionary <Sensor, List <PointD> >(); if (win.Keys.Count < 1) { return(result); } Dictionary <DateTime, double[]> .KeyCollection.Enumerator en = win.Keys.GetEnumerator(); if (en.MoveNext()) { min = en.Current; } foreach (int pos in profile.Settings.Keys) { result.Add(profile.Settings[pos], new List <PointD>()); } foreach (DateTime dt in win.Keys) { max = dt; double val = (dt.Ticks - min.Ticks) / 10e6d; foreach (int pos in profile.Settings.Keys) { result[profile.Settings[pos]].Add(new PointD(val, win[dt][pos])); } } return(result); }
private void новоеИзмерениеToolStripMenuItem_Click(object sender, EventArgs e) { comboBoxProfiles.Enabled = false; FormMeasureProfileSelect form = FormMeasureProfileSelect.getInstance(Program.Presets.CurrentProfile == null ? -1 : Program.Presets.CurrentProfile.ID); form.AdjustForTask(true); MeasureProfile applied; bool start = false; MeasureProfile p = Program.Presets.CurrentProfile; bool ok = true; if (form.ShowDialog() == DialogResult.OK) { start = true; } if (start) { ok = true; try { if (p != null) { DateTime min, max; Dictionary <Sensor, List <PointD> > toCheck = Program.Service.WinToData(Program.nose.getWindow(), Program.Presets.CurrentProfile, out min, out max); foreach (Sensor key in toCheck.Keys) { ok &= Program.Service.checkOk(key, toCheck[key].ToArray()) == Program.Service.CHECK_STABLE; } } } catch (Exception ex) { Error.Log(ex); } if (ok || MessageBox.Show("Не все сенсоры стабильны. Вы всё равно хотите начать измерение?", "Нестабильность", MessageBoxButtons.YesNo) == DialogResult.Yes) { Dictionary <DateTime, double[]> win = null; if (Program.nose != null) { win = Program.nose.getWindow(); } if (win == null || win.Count == 0) { MessageBox.Show("Неизвестная ошибка: всё пропало"); comboBoxProfiles.Enabled = true; return; } applied = form.usedProfile; #region init values /* * double[] init = new double[Program.nose.SensorCount]; * int count = win.Count; * DateTime[] times = new DateTime[count]; * win.Keys.CopyTo(times, 0); * DateTime last = times[times.Length - 1]; * * for (int i = 0; i < init.Length; i++) init[i] = 0d; * * int c = 0; * ///!!!!! ТОНКО ТУТ ЕСЛИ НЕПРАВИЛЬНО - ФИКСИТЬ!!!! * for (int i = times.Length - 1; i >= 0 && (0d + last.Ticks - times[i].Ticks) / 1e7d < Program.Presets.stableTime; c++, i--) * for (int j = 0; j < Program.nose.SensorCount; j++) * init[j] += win[times[i]][j]; * * if (c > 0) * for (int i = 0; i < init.Length; i++) init[i] /= c; * * double[] theinit = new double[applied.Settings.Count]; * * int ii = 0; * foreach (int pos in applied.Settings.Keys) * theinit[ii++] = (int)init[pos]; */ #endregion double[] theinit = Program.Service.getInitValues(win, applied); double len = (int)form.numericUpDownTime.Value; string txt = form.textBoxName.Text; FormMeasure meas = new FormMeasure(len, txt, applied, theinit, form.comboBoxMasks.SelectedItem as Mask, form.lng, form.ltt); meas.ShowDialog(); measureTree.ShowMeasures = measureTree.ShowMeasures; } } refreshComboProfiles(); comboBoxProfiles.Enabled = true; }