private void EditWentylatorInDB(Wentylator w)
        {
            using (var context = new DBContext())
            {
                Wentylator newWentylator = context.Wentylatory.Include(b => b.Nature).Include(c => c.Coefficients).First(wentylator => wentylator.ID == w.ID);
                newWentylator.Name       = w.Name;
                newWentylator.Power      = w.Power;
                newWentylator.Revolution = w.Revolution;
                newWentylator.NatureId   = w.NatureId;

                if (_excelExists)
                {
                    var oldCoefficients = context.Coefficients.Where(c => c.Wentylator.Name == newWentylator.Name);
                    foreach (var coef in oldCoefficients)
                    {
                        coef.IsArchived = true;
                    }
                    double[,] C = GetCoefficientsFromExcel(ref newWentylator);
                    for (int i = 0; i < C.GetLength(0); i++)
                    {
                        var coefficient = new Coefficient
                        {
                            Wentylator = newWentylator,
                            Level      = i,
                            Value      = C[i, 0]
                        };
                        context.Coefficients.Add(coefficient);
                    }
                }
                context.SaveChanges();
            }
        }
 public FrmAddFan(Wentylator w)
 {
     InitializeComponent();
     Text = "Edycja wentylatora";
     btnBrowse.Visible        = false;
     lblBrowse.Visible        = false;
     tbxExcelFilename.Visible = false;
     _wentylator = w;
 }
        private double[,] GetCoefficientsFromExcel(ref Wentylator w)
        {
            ExcellReader xlr = new ExcellReader();

            xlr.getExcelFile(tbxExcelFilename.Text);

            double[,] Y = new double[xlr.Dp.Count(), 1];
            for (int i = 0; i < xlr.Dp.Count(); i++)
            {
                Y[i, 0] = xlr.Dp[i];
            }
            w.AirMassFlowFrom = xlr.Q.First();
            w.AirMAssFlowTo   = xlr.Q.Last();
            List <double> U = Chebyshev.ConvertXToU(xlr.Q);

            double[,] T = Chebyshev.CalculatePolynomials(U, 4);
            double[,] C = Chebyshev.ComputeVectorC(T, Y);
            return(C);
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            //weryfikacja poprawności danych
            //...
            double power = 0, revolution = 0, pressure = 0;
            int    nature;

            try
            {
                power      = double.Parse(tbxPower.Text);
                revolution = double.Parse(tbxRevolution.Text);
                nature     = (cbxNature.SelectedItem as Nature).ID;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Błędne dane: \n\t" + ex.Message, "Błąd!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }



            if (_wentylator != null)
            {
                EditWentylatorInDB(_wentylator);
            }
            else
            {
                Wentylator w = new Wentylator()
                {
                    Name       = tbxName.Text,
                    Power      = power,
                    Revolution = revolution,
                    //Pressure = pressure,
                    NatureId = nature
                };
                AddWentylatorToDB(w);
            }

            Close();
        }
示例#5
0
        private void menu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            var row = dataGridView1.Rows[_selectedRow];

            switch (e.ClickedItem.Name.ToString())
            {
            case "Edytuj":
                Wentylator w = new Wentylator()
                {
                    Name  = row.Cells["Nazwa"].Value.ToString(),
                    Power = double.Parse(row.Cells["Moc"].Value.ToString()),
                    //Pressure = double.Parse(row.Cells["Ciśnienie"].Value.ToString()),
                    Revolution = double.Parse(row.Cells["Obroty"].Value.ToString()),
                    Nature     = row.Cells["Typ"].Value as Nature
                };
                FrmAddFan frm = new FrmAddFan(w);
                frm.ShowDialog();
                break;

            case "Usuń":
                using (var context = new DBContext())
                {
                    string name     = row.Cells["Nazwa"].Value.ToString();
                    var    toDelete = context.Wentylatory.Include(b => b.Coefficients).First(
                        we => we.Name.Equals(name));

                    context.Coefficients.RemoveRange(toDelete.Coefficients);
                    context.Wentylatory.Remove(toDelete);
                    context.SaveChanges();
                }
                dataGridView1.Rows.RemoveAt(_selectedRow);
                _selectedRow = -1;
                break;

            default:
                break;
            }
        }
        private void AddWentylatorToDB(Wentylator w)
        {
            using (var context = new DBContext())
            {
                context.Wentylatory.Add(w);

                if (_excelExists)
                {
                    double[,] C = GetCoefficientsFromExcel(ref w);
                    for (int i = 0; i < C.GetLength(0); i++)
                    {
                        var coefficient = new Coefficient
                        {
                            Wentylator = w,
                            Level      = i,
                            Value      = C[i, 0]
                        };
                        context.Coefficients.Add(coefficient);
                    }
                }
                context.SaveChanges();
            }
            MessageBox.Show("Pomyślnie dodano wentylator do bazy! \n", "Sukces!", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }