private void buttonLoad_Click(object sender, EventArgs e) { if (MessageBox.Show("Внимание!\nДанное действие загрузит список магазинов сопротивления расположенный в файле Rbtxt.txt с заменой текущего списка магазинов сопротивления.\nДля загрузки нажмите Ок, для выхода Отмена", "Чтение из файла", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK) { R.ClearList(); try { using (StreamReader file = new StreamReader(@"Rbtxt.txt", false)) { while (!file.EndOfStream) { if (file.ReadLine().Trim() == "[1]") { ResistanceBox f = new ResistanceBox(); R.AddRb(f.Read(file)); } else { ResistanceBox2 f2 = new ResistanceBox2(); R.AddRb(f2.Read(file)); } } listBox1.Items.Clear(); R.ShowModel(listBox1); } listBox1.SelectedIndex = 0; } catch { MessageBox.Show("При загрузке данных из файла произошла ошибка", "Ошибка чтения", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public override ResistanceBox Read(StreamReader sr) { ResistanceBox2 Rb = new ResistanceBox2(); FirstPartRead(Rb, sr); double NullResistance2; double.TryParse(sr.ReadLine().Trim(), out NullResistance2); Rb.NullResistance2 = NullResistance2; double VariationNullResistance2; double.TryParse(sr.ReadLine().Trim(), out VariationNullResistance2); Rb.VariationNullResistance2 = VariationNullResistance2; SecondPartRead(Rb, sr); return(Rb); }
private void buttonAdd_Click(object sender, EventArgs e) { ResistanceBox Rb; Formuls Formula = new Formuls(); if (comboBoxTypeDevice.SelectedIndex == 0) { Rb = new ResistanceBox(); } else { Rb = new ResistanceBox2(); } if (textBoxDevice.Text == "") { toolTip1.Show("Введите модель магазина сопротивлений", textBoxDevice, 3000); return; } else { Rb.Model = textBoxDevice.Text; } if (textBoxAccuracy.Text == "") { toolTip1.Show("Введите класс точности прибора", textBoxAccuracy, 3000); return; } else { Rb.Accuracy = textBoxAccuracy.Text; } Rb.NumberDecade = (int)nUDNumberDecade.Value; Rb.MinResistance = (double)numericUpDownRmin.Value; Rb.MaxResistance = (double)numericUpDownRmax.Value; if (comboBoxTypeDevice.SelectedIndex == 0) { Rb.NullResistance = (double)numericUDRo1.Value; Rb.VariationNullResistance = (double)numericUDVarRo1.Value; } else { Rb.NullResistance = (double)numericUDRo1.Value; Rb.VariationNullResistance = (double)numericUDVarRo1.Value; (Rb as ResistanceBox2).NullResistance2 = (double)numericUDRo2.Value; (Rb as ResistanceBox2).VariationNullResistance2 = (double)numericUDVarRo2.Value; } double[] constants = new double[3]; if (radioButtonType1.Checked) { constants = new double[3]; constants = SelectedFormulsType134(constants); Rb.RelativeError = new Func <double, double[], double>(Formula.Formula1); } if (radioButtonType2.Checked) { constants = new double[2]; constants[0] = (double)numericUpDownA.Value; constants[1] = (double)numericUpDownB.Value; Rb.RelativeError = new Func <double, double[], double>(Formula.Formula2); } if (radioButtonType3.Checked) { constants = new double[3]; constants = SelectedFormulsType134(constants); Rb.RelativeError = new Func <double, double[], double>(Formula.Formula3); } if (radioButtonType4.Checked) { constants = new double[3]; constants = SelectedFormulsType134(constants); Rb.RelativeError = new Func <double, double[], double>(Formula.Formula4); } if (radioButtonType5.Checked) { constants = new double[1]; constants[0] = (double)numericUpDownA.Value; Rb.RelativeError = new Func <double, double[], double>(Formula.Formula5); } Rb.ConstantABC = constants; Rb.Temperature = maskedTextBoxTemperature.Text; Rb.Humidity = maskedTextBoxHumidity.Text; Rb.Pressure = maskedTextBoxPressure.Text; Form1 f = Owner as Form1; if (f != null) { if (this.Text == "Редактирование прибора") { f.R.Replace(f.indexOfList, Rb); f.listBox1.Items.Clear(); f.R.ShowModel(f.listBox1); f.listBox1.SelectedIndex = f.indexOfList; } else { f.listBox1.Items.Clear(); f.R.AddRb(Rb); f.R.ShowModel(f.listBox1); f.listBox1.SelectedIndex = 0; } } Close(); }
/// <summary> /// Список магазинов сопротивления по умолчанию /// </summary> public void DefaultDevice() { Formuls Formula = new Formuls(); ResistanceBox2 P4834 = new ResistanceBox2("P4834", "0,02/2,5*10^(-7)", 8, "20±2°С", "25-80%", "84-106,7кПа"); P4834.MinResistance = 0.01; P4834.MaxResistance = 111111.1; P4834.NullResistance = 0.012; P4834.NullResistance2 = 0.024; P4834.VariationNullResistance = 0.0012; P4834.VariationNullResistance2 = 0.0024; P4834.RelativeError = new Func <double, double[], double>(Formula.Formula1); P4834.ConstantABC = new double[] { 0.02, 0.00000025, 1000000 }; ListOfResistanceBoxes.Add(P4834); ResistanceBox2 P4831 = new ResistanceBox2("P4831", "0,02/2,0*10^(-6)", 7, "20±2°С", "25-80%", "84-106,7кПа"); P4831.MinResistance = 0.01; P4831.MaxResistance = 111111.10; P4831.NullResistance = 0.021; P4831.NullResistance2 = 0.021; P4831.VariationNullResistance = 0.0021; P4831.VariationNullResistance2 = 0.0021; P4831.RelativeError = new Func <double, double[], double>(Formula.Formula1); P4831.ConstantABC = new double[] { 0.02, 0.000002, P4831.MaxResistance }; ListOfResistanceBoxes.Add(P4831); ResistanceBox P327 = new ResistanceBox("P327", "0,01/1,5*10^(-6)", 6, "20±1°С", "25-80%", "84-106,7кПа"); P327.MinResistance = 0.1; P327.MaxResistance = 111111.0; P327.NullResistance = 0.012; P327.VariationNullResistance = 0.001; P327.RelativeError = new Func <double, double[], double>(Formula.Formula1); P327.ConstantABC = new double[] { 0.01, 0.0000015, P327.MaxResistance }; ListOfResistanceBoxes.Add(P327); ResistanceBox MCP_60M = new ResistanceBox("MCP-60M", "0,02", 6, "20±2°С", "25-80%", "84-106,7кПа"); MCP_60M.MinResistance = 0.01; MCP_60M.MaxResistance = 11111.1; MCP_60M.NullResistance = 0.018; MCP_60M.VariationNullResistance = 0.002; MCP_60M.RelativeError = new Func <double, double[], double>(Formula.Formula3); MCP_60M.ConstantABC = new double[] { 0.02, 0.02, MCP_60M.NumberDecade }; ListOfResistanceBoxes.Add(MCP_60M); ResistanceBox MCP_60 = new ResistanceBox("MCP-60", "0,02", 6, "20±2°С", "25-80%", "84-106,7кПа"); MCP_60.MinResistance = 0.01; MCP_60.MaxResistance = 11111.1; MCP_60.NullResistance = 0.011; MCP_60.VariationNullResistance = 0.0025; MCP_60.RelativeError = new Func <double, double[], double>(Formula.Formula3); MCP_60.ConstantABC = new double[] { 0.02, 0.1, 1 }; ListOfResistanceBoxes.Add(MCP_60); ResistanceBox P33 = new ResistanceBox("P33", "0,2/6*10^(-6)", 6, "20±2°С", "25-80%", "84-106,7кПа"); P33.MinResistance = 0.1; P33.MaxResistance = 99999.9; P33.NullResistance = 0.06; P33.VariationNullResistance = 0.006; P33.RelativeError = new Func <double, double[], double>(Formula.Formula1); P33.ConstantABC = new double[] { 0.2, 0.000006, P33.MaxResistance }; ListOfResistanceBoxes.Add(P33); ResistanceBox2 P4830_1 = new ResistanceBox2("P4830/1", "0,05/2,5*10^(-5)", 6, "20±2°С", "25-80%", "84-106,7кПа"); P4830_1.MinResistance = 0.01; P4830_1.MaxResistance = 12222.21; P4830_1.NullResistance = 0.03; P4830_1.NullResistance2 = 0.02; P4830_1.VariationNullResistance = 0.003; P4830_1.VariationNullResistance2 = 0.002; P4830_1.RelativeError = new Func <double, double[], double>(Formula.Formula1); P4830_1.ConstantABC = new double[] { 0.05, 0.000025, P4830_1.MaxResistance }; ListOfResistanceBoxes.Add(P4830_1); ResistanceBox2 P4830_2 = new ResistanceBox2("P4830/2", "0,05/2,5*10^(-6)", 6, "20±2°С", "25-80%", "84-106,7кПа"); P4830_2.MinResistance = 0.1; P4830_2.MaxResistance = 122222.1; P4830_2.NullResistance = 0.03; P4830_2.NullResistance2 = 0.015; P4830_2.VariationNullResistance = 0.003; P4830_2.VariationNullResistance2 = 0.0015; P4830_2.RelativeError = new Func <double, double[], double>(Formula.Formula1); P4830_2.ConstantABC = new double[] { 0.05, 0.0000025, P4830_2.MaxResistance }; ListOfResistanceBoxes.Add(P4830_2); ResistanceBox MCP_63 = new ResistanceBox("MCP-63", "0,05/4*10^(-6)", 7, "20±2°С", "25-80%", "84-106,7кПа"); MCP_63.MinResistance = 0.01; MCP_63.MaxResistance = 111111.1; MCP_63.NullResistance = 0.035; MCP_63.VariationNullResistance = 0.0035; MCP_63.RelativeError = new Func <double, double[], double>(Formula.Formula4); MCP_63.ConstantABC = new double[] { 0.05, 0.000004, MCP_63.MaxResistance }; ListOfResistanceBoxes.Add(MCP_63); //ResistanceBox P40103 = new ResistanceBox("Р40103", "0,1", 1, "20±2°С", "25-80%", "84-106,7кПа"); //P40103.MinResistance = 0.01; //P40103.MaxResistance = 111111.1; //P40103.NullResistance = 0.035; //P40103.VariationNullResistance = 0.0035; //P40103.RelativeError = new Func<double, double[], double>(Formula.Formula5); //P40103.ConstantABC = new double[] { 0.1 }; //ListOfResistanceBoxes.Add(P40103); }