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);
        }
Esempio n. 2
0
        private void bgwBrowser_DoWork(object sender, DoWorkEventArgs e)
        {
            string Name = String.Empty;

            tbxName.Invoke(new MethodInvoker(delegate { Name = tbxName.Text; }));
            string PowerFrom = String.Empty;

            tbxName.Invoke(new MethodInvoker(delegate { PowerFrom = tbxPowerFrom.Text; }));
            string PowerTo = String.Empty;

            tbxName.Invoke(new MethodInvoker(delegate { PowerTo = tbxPowerTo.Text; }));
            string PressureFrom = String.Empty;

            tbxName.Invoke(new MethodInvoker(delegate { PressureFrom = tbxPressureFrom.Text; }));
            string AirMassFlow = String.Empty;

            tbxName.Invoke(new MethodInvoker(delegate { AirMassFlow = tbxAirMassFlow.Text; }));
            string RevolutionFrom = String.Empty;

            tbxName.Invoke(new MethodInvoker(delegate { RevolutionFrom = tbxRevolutionFrom.Text; }));
            string RevolutionTo = String.Empty;

            tbxName.Invoke(new MethodInvoker(delegate { RevolutionTo = tbxRevolutionTo.Text; }));
            string Nature = String.Empty;

            tbxName.Invoke(new MethodInvoker(delegate { Nature = cbxNature.Text; }));
            List <Wentylator> wentylatory;

            using (var context = new DBContext())
            {
                wentylatory = context.Wentylatory.Include(b => b.Nature).Include(b => b.Coefficients).Select(w => w).ToList();

                if (Name != String.Empty)
                {
                    wentylatory = wentylatory.Where(w => w.Name.Equals(Name)).ToList();
                }

                if (PowerFrom != String.Empty)
                {
                    double power = double.Parse(PowerFrom);
                    wentylatory = wentylatory.Where(w => w.Power >= power).ToList();
                }
                if (PowerTo != String.Empty)
                {
                    double power = double.Parse(PowerTo);
                    wentylatory = wentylatory.Where(w => w.Power <= power).ToList();
                }

                if (PressureFrom != String.Empty && AirMassFlow != String.Empty)
                {
                    double airMassFlow = double.Parse(AirMassFlow);
                    double pressure    = double.Parse(PressureFrom);
                    wentylatory = wentylatory
                                  .Where(w =>
                                         Chebyshev.EvaluateFunctionFromCoefficients(
                                             w.Coefficients.OrderBy(c => c.Level).Select(v => v.Value).ToArray(),
                                             Chebyshev.Normalize(w.AirMassFlowFrom, w.AirMAssFlowTo, airMassFlow))
                                         / pressure > 0.8 &&
                                         Chebyshev.EvaluateFunctionFromCoefficients(
                                             w.Coefficients.OrderBy(c => c.Level).Select(v => v.Value).ToArray(),
                                             Chebyshev.Normalize(w.AirMassFlowFrom, w.AirMAssFlowTo, airMassFlow))
                                         / pressure < 1.2
                                         ).ToList();
                    //wentylatory = wentylatory.Where(w => w.Pressure >= pressure).AsQueryable();
                }


                if (RevolutionFrom != String.Empty)
                {
                    double revolution = double.Parse(RevolutionFrom);
                    wentylatory = wentylatory.Where(w => w.Revolution <= revolution).ToList();
                }
                if (RevolutionTo != String.Empty)
                {
                    double revolution = double.Parse(RevolutionTo);
                    wentylatory = wentylatory.Where(w => w.Revolution <= revolution).ToList();
                }

                if (Nature != String.Empty)
                {
                    wentylatory = wentylatory.Where(w => w.Nature.Name.Equals(Nature)).ToList();
                }

                DataTable dt = wentylatory.Select(w => new WentylatorDT
                {
                    Name  = w.Name,
                    Power = w.Power,
                    //Ciśnienie = w.Pressure,
                    Revolution = w.Revolution,
                    Nature     = w.Nature
                }).ToList().ToDataTable();

                dt.Locale = System.Globalization.CultureInfo.InvariantCulture;

                dataGridView1.Invoke(new MethodInvoker(delegate {
                    dataGridView1.DataSource = dt;
                    //dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.Fill);
                    foreach (DataGridViewColumn column in dataGridView1.Columns)
                    {
                        column.SortMode     = DataGridViewColumnSortMode.Automatic;
                        column.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                    }
                    dataGridView1.Columns[dataGridView1.Columns.Count - 1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                    for (int i = 0; i < dataGridView1.Columns.Count; i++)
                    {
                        int colw = dataGridView1.Columns[i].Width;
                        dataGridView1.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
                        dataGridView1.Columns[i].Width        = colw;
                    }
                }));
            }
        }