/// <summary> /// Кнопка добавить /// </summary> private void Button_Click_OK(Object sender, RoutedEventArgs e) { ProgressiveCavityPump newPump = new ProgressiveCavityPump(); newPump.RateCoefficients = new List <RateCoefficient>(); newPump.PowerCoefficients = new List <PowerCoefficient>(); newPump.TorqueCoefficients = new List <TorqueCoefficient>(); try { for (int i = 1; i < RateCoefficients.Children.Count; i++) { TextBox box = (TextBox)(RateCoefficients.Children[i] as StackPanel).Children[1]; int order = i - 1; newPump.RateCoefficients.Add(new RateCoefficient(order, double.Parse(box.Text))); } for (int i = 1; i < PowerCoefficients.Children.Count; i++) { TextBox box = (TextBox)(PowerCoefficients.Children[i] as StackPanel).Children[1]; int order = i - 1; newPump.PowerCoefficients.Add(new PowerCoefficient(order, double.Parse(box.Text))); } for (int i = 1; i < TorqueCoefficients.Children.Count; i++) { TextBox box = (TextBox)(TorqueCoefficients.Children[i] as StackPanel).Children[1]; int order = i - 1; newPump.TorqueCoefficients.Add(new TorqueCoefficient(order, double.Parse(box.Text))); } newPump.Name = ((TextBox)NamePCP.Children[1]).Text; newPump.Diameter = Convert.ToDouble(((TextBox)Diameter.Children[1]).Text); newPump.NominalRate = Convert.ToDouble(((TextBox)NominalRate.Children[1]).Text); newPump.BaseSpeed = Convert.ToDouble(((TextBox)NominalSpeed.Children[1]).Text); } catch { MessageBox.Show("Ошибка Неправильно задано одно из полей."); return; } this.Hide(); //MainWindow.Button_Click_UpdateGrafESN(null, null); using (PersistanceContext db = new PersistanceContext()) { db.PcpPumps.Add(newPump); db.SaveChanges(); //Обновляем каталог MainWindow.CatalogPcp = db.PcpPumps.Include("PowerCoefficients").Include("RateCoefficients").Include("TorqueCoefficients").ToList(); //Отображаем таблицу каталога ЭЦН MainWindow.ShowPCPDataBase(); } MainWindow.Button_Click_UpdateGrafPCP(null, null); }
/// <summary> /// Кнопка добавить /// </summary> private void Button_Click_OK(Object sender, RoutedEventArgs e) { ElectricSubmersiblePump pump = new ElectricSubmersiblePump(); pump.HeadCoefficients = new List <HeadCoefficient>(); pump.PowerCoefficients = new List <PowerCoefficient>(); pump.EfficiencyCoefficients = new List <EfficiencyCoefficient>(); TextBox[] HeadTextBoxes = { TB_HeadX0, TB_HeadX1, TB_HeadX2, TB_HeadX3, TB_HeadX4, TB_HeadX5, TB_HeadX6, TB_HeadX7, TB_HeadX8, TB_HeadX9 }; TextBox[] PowerTextBoxes = { TB_Power0, TB_Power1, TB_Power2, TB_Power3, TB_Power4, TB_Power5, TB_Power6, TB_Power7, TB_Power8, TB_Power9 }; TextBox[] EfficiencyTextBoxes = { TB_Efficiency0, TB_Efficiency1, TB_Efficiency2, TB_Efficiency3, TB_Efficiency4, TB_Efficiency5, TB_Efficiency6, TB_Efficiency7, TB_Efficiency8, TB_Efficiency9 }; try { for (int i = 0; i < HeadTextBoxes.Count(); i++) { TextBox box = HeadTextBoxes[i]; pump.HeadCoefficients.Add(new HeadCoefficient(i, double.Parse(box.Text))); } for (int i = 0; i < PowerTextBoxes.Count(); i++) { TextBox box = PowerTextBoxes[i]; pump.PowerCoefficients.Add(new PowerCoefficient(i, double.Parse(box.Text))); } for (int i = 0; i < EfficiencyTextBoxes.Count(); i++) { TextBox box = EfficiencyTextBoxes[i]; pump.EfficiencyCoefficients.Add(new EfficiencyCoefficient(i, double.Parse(box.Text))); } pump.Name = NameTB.Text; pump.BaseFrequency = Convert.ToDouble(TB_BaseFrequency.Text); pump.ConditionalDimension = ConditionalDimensionComboBox.Text; pump.NominalRate = Convert.ToDouble(TB_NominalRate.Text); pump.MinAvailableRate = Convert.ToDouble(TB_MinAvailableRate.Text); pump.MaxAvailableRate = Convert.ToDouble(TB_MaxAvailableRate.Text); pump.MinRecomendedRate = Convert.ToDouble(TB_MinRecomendedRate.Text); pump.MaxRecomendedRate = Convert.ToDouble(TB_MaxRecomendedRate.Text); } catch (Exception ex) { MessageBox.Show("Ошибка Неправильно задано одно из полей."); return; } this.Hide(); MainWindow.Button_Click_UpdateGrafESN(null, null); using (PersistanceContext db = new PersistanceContext()) { db.EspPumps.Add(pump); db.SaveChanges(); //Обновляем каталог MainWindow.CatalogEsp = db.EspPumps.Include("PowerCoefficients") .Include("EfficiencyCoefficients").Include("HeadCoefficients").ToList(); //Отображаем таблицу каталога ЭЦН MainWindow.ShowESPDataBase(); } }
/// <summary> /// Кнопка добавить /// </summary> private void Button_Click_OK(Object sender, RoutedEventArgs e) { TextBox[] HeadTextBoxes = { TB_HeadX0, TB_HeadX1, TB_HeadX2, TB_HeadX3, TB_HeadX4, TB_HeadX5, TB_HeadX6, TB_HeadX7, TB_HeadX8, TB_HeadX9 }; TextBox[] PowerTextBoxes = { TB_Power0, TB_Power1, TB_Power2, TB_Power3, TB_Power4, TB_Power5, TB_Power6, TB_Power7, TB_Power8, TB_Power9 }; TextBox[] EfficiencyTextBoxes = { TB_Efficiency0, TB_Efficiency1, TB_Efficiency2, TB_Efficiency3, TB_Efficiency4, TB_Efficiency5, TB_Efficiency6, TB_Efficiency7, TB_Efficiency8, TB_Efficiency9 }; ChosenPump.HeadCoefficients.Clear(); ChosenPump.PowerCoefficients.Clear(); ChosenPump.EfficiencyCoefficients.Clear(); for (int i = 0; i < HeadTextBoxes.Count(); i++) { TextBox box = HeadTextBoxes[i]; ChosenPump.HeadCoefficients.Add(new HeadCoefficient(i, double.Parse(box.Text))); } for (int i = 0; i < PowerTextBoxes.Count(); i++) { TextBox box = PowerTextBoxes[i]; ChosenPump.PowerCoefficients.Add(new PowerCoefficient(i, double.Parse(box.Text))); } for (int i = 0; i < EfficiencyTextBoxes.Count(); i++) { TextBox box = EfficiencyTextBoxes[i]; ChosenPump.EfficiencyCoefficients.Add(new EfficiencyCoefficient(i, double.Parse(box.Text))); } ChosenPump.Name = NameTB.Text; ChosenPump.BaseFrequency = Convert.ToDouble(TB_BaseFrequency.Text); ChosenPump.ConditionalDimension = ConditionalDimensionComboBox.Text; ChosenPump.NominalRate = Convert.ToDouble(TB_NominalDischarge.Text); ChosenPump.MinAvailableRate = Convert.ToDouble(TB_MinAvailableDischarge.Text); ChosenPump.MaxAvailableRate = Convert.ToDouble(TB_MaxAvailableDischarge.Text); ChosenPump.MinRecomendedRate = Convert.ToDouble(TB_MinRecomendedDischarge.Text); ChosenPump.MaxRecomendedRate = Convert.ToDouble(TB_MaxRecomendedDischarge.Text); this.Hide(); using (PersistanceContext db = new PersistanceContext()) { ElectricSubmersiblePump espForChange = db.EspPumps.Include("PowerCoefficients") .Include("EfficiencyCoefficients").Include("HeadCoefficients").Where(esp => esp.Id == ChosenPump.Id).ToList()[0]; db.EspPumps.Remove(espForChange); espForChange = ChosenPump; db.EspPumps.Add(espForChange); db.SaveChanges(); List <ElectricSubmersiblePump> espList = db.EspPumps.Include("PowerCoefficients") .Include("EfficiencyCoefficients").Include("HeadCoefficients").ToList(); //Обновляем каталог MainWindow.CatalogEsp = espList; //Отображаем таблицу каталога ЭЦН MainWindow.ShowESPDataBase(); } MainWindow.Button_Click_UpdateGrafESN(null, null); }