Esempio n. 1
0
        //on selecting one of the values from the listbox, this method is called.
        //It a)populates the Tseries list b)calls the loadmodels() method c) calls the populatedatagridview() method
        private void ARCHlb_SelectedValueChanged(object sender, EventArgs e)
        {
            System.Windows.Forms.Cursor old = this.Cursor;
            this.Cursor = Cursors.AppStarting;

            Tseries.Clear();

            int position = ARCHlb.SelectedIndex;

            if (position == -1)
            {
                this.Cursor = old;
                return;
            }
            string curItem  = Tab[position];
            string df       = Flocations[position];
            string f        = ";Extended Properties=\"Excel 12.0;HDR=NO\"";
            string c        = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + df + f;
            string interim1 = Fnames[position].Replace(".xlsx", "");
            string interim2 = Tab[position].Replace("$", "");
            string interim3 = Flocations[position].Replace(fnames[position], interim1 + interim2 + ".csv");
            int    counter  = 0;
            string line1;
            string line2;
            string line3;
            double t      = 0;
            double tscale = 0;

            try
            {
                StreamReader sr = new StreamReader(interim3);
                while (counter < 1)
                {
                    line1 = sr.ReadLine();
                    line2 = sr.ReadLine();
                    line3 = sr.ReadLine();
                    bool tf      = Double.TryParse(line2, out t);
                    bool tfscale = Double.TryParse(line3, out tscale);
                    if (line1 == "Iterative")
                    {
                        this.Type           = "Iterative";
                        this.Transform      = t;
                        this.Transformscale = 0;
                    }
                    if (line1 == "Weibull")
                    {
                        this.Type           = "Weibull";
                        this.Transform      = t;
                        this.Transformscale = tscale;
                    }

                    counter++;
                }
            }
            catch
            {
            }
            DataSet          data      = new DataSet();
            OleDbConnection  con       = new OleDbConnection(c);
            DataTable        dataTable = new DataTable();
            string           query     = string.Format("SELECT * FROM [{0}]", curItem);
            OleDbDataAdapter adapter   = new OleDbDataAdapter(query, con);

            try
            {
                con.Open();
                adapter.Fill(dataTable);
                data.Tables.Add(dataTable);
                int m = 0, n = 0;
                m      = data.Tables[0].Rows.Count;
                n      = dataTable.Columns.Count;
                this.R = m;
                this.C = n;
                int q = 0, r = 0;
                try
                {
                    for (q = 0; q < m; q++)
                    {
                        for (r = 0; r < n; r++)
                        {
                            double d = (double)data.Tables[0].Rows[q].ItemArray[r];
                            Tseries.Add(d);
                        }
                    }
                }
                catch (Exception x)
                {
                    MessageBox.Show("No data in the underlying tab. Error:" + x.Message);
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show("The listbox selection did not work. Error: " + ex.Message);
            }
            finally
            {
                con.Close();
                Modellist.Clear();
                this.loadmodels(position);
                if (Modellist.Count() == 0)
                {
                    hide();
                    string            message = "No ARIMA models relating to this data set have been found.\nPlease go back to ARIMA section, run the models and save output.";
                    string            caption = "ARIMA Models";
                    MessageBoxButtons buttons = MessageBoxButtons.OK;
                    DialogResult      result;
                    result = MessageBox.Show(message, caption, buttons);
                }
                else
                {
                    populatedatagridview();
                    this.P = new Statistics(Tseries);
                }
                this.Cursor = old;
            }
        }
Esempio n. 2
0
        //this method is called once the user chooses a tab from the listbox
        //it (a) loads the time series data (b) calls the Hookup method which will produce a number of graphs and summary statistics c) saves a copy of the underlying data to a CSV file
        private void explrlb_SelectedValueChanged(object sender, EventArgs e)
        {
            System.Windows.Forms.Cursor old = this.Cursor;
            this.Cursor = Cursors.AppStarting;

            //clear any data that may already be in the Tseries object
            Tseries.Clear();

            int position = explrlb.SelectedIndex;

            //protects in the event that the user selectes a blank line
            if (position == -1)
            {
                this.Cursor = old;
                return;
            }
            //otherwise proceed as normal
            string          curItem = Tab[position];
            string          df      = Flocations[position];
            string          f       = ";Extended Properties=\"Excel 12.0;HDR=NO\"";
            string          c       = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + df + f;
            DataSet         data    = new DataSet();
            OleDbConnection con     = new OleDbConnection(c);
            //var
            DataTable        dataTable = new DataTable();
            string           query     = string.Format("SELECT * FROM [{0}]", curItem);
            OleDbDataAdapter adapter   = new OleDbDataAdapter(query, con);

            try
            {
                con.Open();
                adapter.Fill(dataTable);
                data.Tables.Add(dataTable);
                explrdgv1.AutoGenerateColumns = true;
                explrdgv1.DataSource          = data.Tables[0];
                string s = data.Tables[0].TableName;
                explrdgv1.AllowUserToAddRows = false;
                explrdgv1.MultiSelect        = false;
                explrdgv1.ReadOnly           = true;
                //now we populate Tseries
                int m = 0, n = 0;
                m      = data.Tables[0].Rows.Count;
                n      = dataTable.Columns.Count;
                this.R = m;
                this.C = n;
                int q = 0, r = 0;
                try
                {
                    for (q = 0; q < m; q++)
                    {
                        for (r = 0; r < n; r++)
                        {
                            double d = (double)data.Tables[0].Rows[q].ItemArray[r];
                            Tseries.Add(d);
                        }
                    }
                    //call the HookUpData method which will assist with the production of charts etc
                    HookUpData();
                }
                catch (Exception x)
                {
                    explrForm_hide();
                    MessageBox.Show("No data in the underlying tab. Error:" + x.Message);
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show("The listbox selection did not work. Error: " + ex.Message);
            }

            finally
            {
                con.Close();
                this.Cursor = old;
                //save down a CSV copy of the underlying data in case the user wants it
                curItem = curItem.Replace("'", "");
                curItem = curItem.Replace("$", "");
                string       p  = curItem + ".csv";
                string       q  = df.Replace(".xlsx", p);
                StreamWriter sw = new StreamWriter(q, false);
                sw.WriteLine("Data");
                foreach (double d in Tseries)
                {
                    sw.WriteLine(d);
                }
                sw.Close();
            }
        }