Ejemplo n.º 1
0
        private void Button6_Click(object sender, EventArgs e)
        {
            string index = "-1";

            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
            {
                if (row.Cells[0].Value == null)
                {
                    return;
                }
                index = Convert.ToString(row.Cells[0].Value.ToString());
            }
            if (index == "-1")
            {
                return;
            }

            SQLfx Data = new SQLfx();

            SqlConnection con = Data.openSQLConnection(); // Open SQL Connection

            Console.WriteLine(index);
            String query = "insert into trialList(trialType,prepost, trialCond, trialBehav, speed, CarSpaceRight, CarSpaceLeft) select trialType,prepost, trialCond, trialBehav, speed, CarSpaceRight, CarSpaceLeft from trialPresets where ID=" + index + ";";

            Console.WriteLine(query);

            SqlCommand cmd = new SqlCommand(query, con);

            cmd.ExecuteNonQuery();
            frm1.updateDataTable();
            this.Close();
        }
Ejemplo n.º 2
0
        private void Button5_Click(object sender, EventArgs e)
        {
            string index = "-1";

            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
            {
                if (row.Cells[0].Value == null)
                {
                    return;
                }
                index = Convert.ToString(row.Cells[0].Value.ToString());
            }
            if (index == "-1")
            {
                return;
            }
            SQLfx Data = new SQLfx();

            SqlConnection con = Data.openSQLConnection(); // Open SQL Connection

            String query = "DELETE FROM trialPresets WHERE ID= " + index;

            Console.WriteLine(query);
            //WIPE TABLE ---- String query = "DELETE FROM dbo.CarListSpaceDIRECTION";
            SqlCommand cmd = new SqlCommand(query, con);

            cmd.ExecuteNonQuery();
            updatePresetTable();
        }
Ejemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            SQLfx Data = new SQLfx();

            SqlConnection con = Data.openSQLConnection(); // Open SQL Connection

            String query = "INSERT INTO dbo.CarListSpaceRight (CarListSpaceRight) VALUES (@CarListSpaceRight)";
            //WIPE TABLE ---- String query = "DELETE FROM dbo.CarListSpaceDIRECTION";
            string prev = textBox1.Text;

            if (radioButton4.Checked == true && textBox1.TextLength != 0)
            {
                float value = float.Parse(textBox1.Text) * (float.Parse(txtContinuousCarSpeed.Text) * float.Parse("0.277778"));
                textBox1.Text = value.ToString("0.00"); //Convert.ToString(value);
            }

            SqlCommand cmd = new SqlCommand(query, con);

            textBox1.Text = float.Parse(textBox1.Text).ToString("0.00");
            Console.WriteLine("YUYU" + float.Parse(textBox1.Text).ToString("0.00"));
            cmd.Parameters.AddWithValue("@CarListSpaceRight", textBox1.Text);
            textBox1.Text = prev;
            cmd.ExecuteNonQuery();

            textBox2.Text = Data.printString("CarListSpaceRight", "CarListSpaceRight");

            //textBox1.Text = "";
        }
Ejemplo n.º 4
0
        private void btnRemoveTrial_Click(object sender, EventArgs e)
        {
            string index = "-1";

            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
            {
                if (row.Cells[0].Value == null)
                {
                    return;
                }
                index = Convert.ToString(row.Cells[0].Value.ToString());
            }
            if (index == "-1")
            {
                return;
            }


            SQLfx Data = new SQLfx();

            SqlConnection con = Data.openSQLConnection(); // Open SQL Connection

            String     query = "DELETE FROM trialList WHERE ID= " + index;
            SqlCommand cmd   = new SqlCommand(query, con);

            cmd.ExecuteNonQuery();
            updateDataTable();
        }
Ejemplo n.º 5
0
        static void Main()
        {
            /////////Clear Databases on Start Up -- Can Remove This To Keep Data
            SQLfx         Data  = new SQLfx();
            SqlConnection con   = Data.openSQLConnection(); // Open SQL Connection
            String        query = "DELETE FROM dbo.CarListSpaceRight";
            SqlCommand    cmd   = new SqlCommand(query, con);

            cmd.ExecuteNonQuery();
            query = "DELETE FROM dbo.CarListSpaceLeft";
            cmd   = new SqlCommand(query, con);
            cmd.ExecuteNonQuery();
            query = "DELETE FROM dbo.properties";
            cmd   = new SqlCommand(query, con);
            cmd.ExecuteNonQuery();
            query = "DELETE FROM dbo.trialProperties";
            cmd   = new SqlCommand(query, con);
            cmd.ExecuteNonQuery();
            query = "DELETE FROM dbo.trialList";
            cmd   = new SqlCommand(query, con);
            cmd.ExecuteNonQuery();
            ///////

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
Ejemplo n.º 6
0
        private void Button2_Click(object sender, EventArgs e)
        {
            SQLfx         Data1  = new SQLfx();
            SqlConnection con1   = Data1.openSQLConnection(); // Open SQL Connection
            String        query1 = "DELETE FROM trialList";
            SqlCommand    cmd1   = new SqlCommand(query1, con1);

            cmd1.ExecuteNonQuery();
            updateDataTable();
        }
Ejemplo n.º 7
0
        public bool checkEmptyTable(String table)
        {
            SQLfx         Data  = new SQLfx();
            SqlConnection con   = Data.openSQLConnection(); // Open SQL Connection
            String        query = "SELECT COUNT(*) from " + table;
            SqlCommand    cmd   = new SqlCommand(query, con);
            //cmd.ExecuteNonQuery();


            int result = int.Parse(cmd.ExecuteScalar().ToString());

            return(result == 0); // if result equals zero, then the table is empty
        }
Ejemplo n.º 8
0
        private void button3_Click(object sender, EventArgs e)
        {
            SQLfx         Data = new SQLfx();
            SqlConnection con  = Data.openSQLConnection(); // Open SQL Connection

            String query = "DELETE FROM CarListSpaceLeft WHERE ID=(SELECT MAX(Id) FROM CarListSpaceLeft)";

            SqlCommand cmd = new SqlCommand(query, con);

            cmd.ExecuteNonQuery();

            textBox5.Text = Data.printString("CarListSpaceLeft", "CarListSpaceLeft");
            textBox6.Text = "";
        }
Ejemplo n.º 9
0
        public void updateDataTable()
        {
            SQLfx Data = new SQLfx();

            SqlConnection con = Data.openSQLConnection(); // Open SQL Connection
            SqlCommand    cmd = new SqlCommand();

            // cmd.Connection = con;

            SqlDataAdapter sqlDa = new SqlDataAdapter("SELECT Id, trialType,prepost, trialCond, trialBehav, speed, CarSpaceRight, CarSpaceLeft  FROM trialList", con);
            DataTable      dtbl  = new DataTable();

            sqlDa.Fill(dtbl);
            dataGridView1.DataSource            = dtbl;
            dataGridView1.Columns[0].HeaderText = "Id";
            dataGridView1.Columns[1].HeaderText = "Trial Type";
            dataGridView1.Columns[2].HeaderText = "Pre/Post";
            dataGridView1.Columns[3].HeaderText = "Trial Condition";
            dataGridView1.Columns[4].HeaderText = "Trial Behaviour";
            dataGridView1.Columns[5].HeaderText = "Car Speed";
            dataGridView1.Columns[6].HeaderText = "Right Facing Car Space";
            dataGridView1.Columns[7].HeaderText = "Left Facing Car Space";


            dataGridView1.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dataGridView1.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dataGridView1.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dataGridView1.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dataGridView1.Columns[4].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dataGridView1.Columns[5].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dataGridView1.Columns[6].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dataGridView1.Columns[7].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

            dataGridView1.Columns[0].Visible = false;

            dataGridView1.ReadOnly = true;

            int index;

            if (dataGridView1.Rows.Count > 1)
            {
                index = dataGridView1.Rows.Count - 2;
            }
            else
            {
                index = 0;
            }
            dataGridView1.Rows[index].Selected = true;
        }
Ejemplo n.º 10
0
        private void BtnRemovePreset_Click(object sender, EventArgs e)
        {
            SQLfx Data = new SQLfx();

            SqlConnection con = Data.openSQLConnection(); // Open SQL Connection

            String query = "DELETE FROM condPresets WHERE CONVERT(VARCHAR, condLabel)='" + cbPreset.Text + "'";

            Console.WriteLine(query);
            cbPreset.Items.Remove(cbPreset.Text);
            SqlCommand cmd = new SqlCommand(query, con);

            cmd.ExecuteNonQuery();
            button2.PerformClick();
        }
Ejemplo n.º 11
0
        private void button2_Click(object sender, EventArgs e)
        {
            SQLfx Data = new SQLfx();

            SqlConnection con = Data.openSQLConnection(); // Open SQL Connection

            String query = "DELETE FROM CarListSpaceRight WHERE ID=(SELECT MAX(Id) FROM CarListSpaceRight)";
            //WIPE TABLE ---- String query = "DELETE FROM dbo.CarListSpaceDIRECTION";
            SqlCommand cmd = new SqlCommand(query, con);

            //cmd.Parameters.AddWithValue("@CarListSpaceRight", textBox1.Text);
            cmd.ExecuteNonQuery();
            //Data.closeSQLConnection(con);
            textBox2.Text = Data.printString("CarListSpaceRight", "CarListSpaceRight");
        }
Ejemplo n.º 12
0
        public void btnVisualTest_Click(object sender, EventArgs e)
        {
            toGlobal fileStuff = new toGlobal();
            //`fileStuff.ee();

            SQLfx Data = new SQLfx();

            SqlConnection con = Data.openSQLConnection(); // Open SQL Connection
            SqlCommand    cmd = new SqlCommand();

            // cmd.Connection = con;

            SqlDataAdapter sqlDa = new SqlDataAdapter("SELECT * FROM trialList", con);
            DataTable      dtbl  = new DataTable();

            sqlDa.Fill(dtbl);

            dataGridView1.DataSource = dtbl;
        }
Ejemplo n.º 13
0
        public Form1()
        {
            InitializeComponent();
            updateDataTable();
            toGlobal      tG         = new toGlobal();
            StringBuilder output     = new StringBuilder();
            int           numEntries = 0;

            if (!tG.checkEmptyTable("condPresets"))
            {
                SQLfx          Data = new SQLfx();
                SqlConnection  con  = Data.openSQLConnection(); // Open SQL Connection
                SqlCommand     cmd  = new SqlCommand("SELECT condLabel FROM condPresets", con);
                SqlDataAdapter da   = new SqlDataAdapter(cmd);
                DataTable      dt   = new DataTable();
                da.Fill(dt);

                foreach (DataRow dr in dt.Rows)
                {
                    foreach (DataColumn col in dt.Columns)
                    {
                        output.AppendFormat("{0},", dr[col]);
                    }
                    numEntries++;
                    output.AppendLine();
                }
                if (numEntries == 0)
                {
                    return;
                }
            }


            foreach (string s in output.Replace("\n", "").Replace("\r", "").ToString().Split(',').Distinct())
            {
                Console.WriteLine(s);
                if (s.Length > 0)
                {
                    cbPreset.Items.Add(s);
                }
            }
        }
Ejemplo n.º 14
0
        private void Button1_Click(object sender, EventArgs e)
        {
            String label = textBox1.Text;

            if (label.Length == 0)
            {
                return;
            }


            SQLfx Data1 = new SQLfx();


            SqlConnection con1   = Data1.openSQLConnection(); // Open SQL Connection
            String        Uquery = "UPDATE trialList SET condLabel=('" + label + "')";

            Console.WriteLine(Uquery);
            SqlCommand cmd1 = new SqlCommand(Uquery, con1);

            cmd1.ExecuteNonQuery();



            SQLfx         Data  = new SQLfx();
            SqlConnection con   = Data.openSQLConnection(); // Open SQL Connection
            String        query = "insert into condPresets(condLabel, trialType,prepost, trialCond, trialBehav, speed, CarSpaceRight, CarSpaceLeft) select condLabel ,trialType,prepost, trialCond, trialBehav, speed, CarSpaceRight, CarSpaceLeft from trialList";

            SqlCommand cmd = new SqlCommand(query, con);

            cmd.ExecuteNonQuery();
            Console.WriteLine(query);
            //Form1 frm = new Form1();


            frm.cbPreset.Items.Add(label);
            //SqlCommand cmd = new SqlCommand(query, con);
            //cmd.ExecuteNonQuery();
            //frm1.updateDataTable();

            this.Close();
        }
Ejemplo n.º 15
0
        private void Button3_Click(object sender, EventArgs e)
        {
            SQLfx         Data  = new SQLfx();
            SqlConnection con   = Data.openSQLConnection(); // Open SQL Connection
            String        query = "insert into temptrialList(condLabel, trialType, prepost, trialCond, trialBehav, speed, CarSpaceRight, CarSpaceLeft) select condLabel, trialType, prepost, trialCond, trialBehav, speed, CarSpaceRight, CarSpaceLeft from trialList order by NEWID()";

            SqlCommand cmd = new SqlCommand(query, con);

            cmd.ExecuteNonQuery();

            button2.PerformClick();

            query = "insert into trialList(condLabel, trialType, prepost, trialCond, trialBehav, speed, CarSpaceRight, CarSpaceLeft) select condLabel, trialType, prepost, trialCond, trialBehav, speed, CarSpaceRight, CarSpaceLeft from temptrialList order by NEWID()";
            cmd   = new SqlCommand(query, con);
            cmd.ExecuteNonQuery();
            updateDataTable();

            query = "DELETE FROM temptrialList";
            cmd   = new SqlCommand(query, con);
            cmd.ExecuteNonQuery();
        }
Ejemplo n.º 16
0
        public void Button2_Click(object sender, EventArgs e)
        {
            String label = textBox1.Text;

            if (label.Length == 0)
            {
                return;
            }
            SQLfx         Data1 = new SQLfx();
            SqlConnection con1  = Data1.openSQLConnection(); // Open SQL Connection
            //String Uquery = "DELETE from condPresets WHERE condLabel=('" + label + "')";
            String Uquery = "DELETE FROM condPresets WHERE CONVERT(VARCHAR, condLabel)='" + frm.cbPreset.Text + "'";

            Console.WriteLine(Uquery);
            SqlCommand cmd1 = new SqlCommand(Uquery, con1);

            cmd1.ExecuteNonQuery();
            frm.cbPreset.Items.Remove(frm.cbPreset.Text);



            SQLfx         Data = new SQLfx();
            SqlConnection con  = Data.openSQLConnection(); // Open SQL Connection


            Uquery = "UPDATE trialList SET condLabel=('" + label + "')";
            Console.WriteLine(Uquery);
            cmd1 = new SqlCommand(Uquery, con1);
            cmd1.ExecuteNonQuery();


            String query = "insert into condPresets(condLabel, trialType,prepost, trialCond, trialBehav, speed, CarSpaceRight, CarSpaceLeft) select condLabel ,trialType,prepost, trialCond, trialBehav, speed, CarSpaceRight, CarSpaceLeft from trialList";

            SqlCommand cmd = new SqlCommand(query, con);

            cmd.ExecuteNonQuery();
            Console.WriteLine(query);
            frm.cbPreset.Items.Add(label);
            this.Close();
        }
Ejemplo n.º 17
0
        private void BtnSetPreset_Click(object sender, EventArgs e)
        {
            SQLfx         Data1 = new SQLfx();
            SqlConnection con1  = Data1.openSQLConnection(); // Open SQL Connection

            String     query1 = "DELETE FROM trialList";
            SqlCommand cmd1   = new SqlCommand(query1, con1);

            cmd1.ExecuteNonQuery();



            SQLfx         Data  = new SQLfx();
            SqlConnection con   = Data.openSQLConnection(); // Open SQL Connection
            String        query = "insert into trialList(trialType,prepost, trialCond, trialBehav, speed, CarSpaceRight, CarSpaceLeft) select trialType,prepost, trialCond, trialBehav, speed, CarSpaceRight, CarSpaceLeft from condPresets where CONVERT(VARCHAR, condLabel)='" + cbPreset.Text + "';";

            Console.WriteLine(query);
            SqlCommand cmd = new SqlCommand(query, con);

            cmd.ExecuteNonQuery();
            updateDataTable();
        }
Ejemplo n.º 18
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            SQLfx Data = new SQLfx();

            SqlConnection con = Data.openSQLConnection(); // Open SQL Connection
            SqlCommand    cmd = new SqlCommand();

            cmd.Connection  = con;
            cmd.CommandText = "INSERT INTO properties (DCP, NMD, RSD, RND, FCA, PCA, MPA, IST) VALUES (@DCP, @NMD, @RSD, @RND, @FCA, @PCA, @MPA, @IST);";
            cmd.Parameters.AddWithValue("@DCP", Convert.ToString(txtDataCollectionPeriod.Text));
            cmd.Parameters.AddWithValue("@NMD", txtNearMissDistance.Text);
            cmd.Parameters.AddWithValue("@RSD", txtRespawnStartDistance.Text);
            cmd.Parameters.AddWithValue("@RND", txtRespawnEndDistance.Text);
            cmd.Parameters.AddWithValue("@FCA", txtFullCheckAngle.Text);
            cmd.Parameters.AddWithValue("@PCA", txtPartialCheckAngle.Text);
            cmd.Parameters.AddWithValue("@MPA", txtMaxPitchAngle.Text);
            cmd.Parameters.AddWithValue("@IST", iST.Text);
            cmd.ExecuteNonQuery();

            toGlobal fileStuff = new toGlobal();

            if (txtID.Text.Length == 0)
            {
                txtID.Text = "ID";
            }
            fileStuff.ee(txtID.Text, txtAge.Text, Sex.Text, txtHeight.Text, txtPath.Text, textBox7.Text);
            cmd.ExecuteNonQuery();
            String query = "DELETE FROM dbo.properties";

            cmd = new SqlCommand(query, con);
            cmd.ExecuteNonQuery();

            Process.Start(@"C:\vr\vr3\main.py");

            //txtID.Text = "";
        }
Ejemplo n.º 19
0
        private void Button8_Click(object sender, EventArgs e)
        {
            SQLfx  Data           = new SQLfx();
            String farLaneSpace   = Data.printString("CarListSpaceLeft", "CarListSpaceLeft");
            String closeLaneSpace = Data.printString("CarListSpaceRight", "CarListSpaceRight");


            Int32  count = 210;
            String final = "";

            String[] strlist   = new String[210];
            String[] strlist1  = new String[210];
            char[]   spearator = { ' ' };


            // DCP is Array 27
            strlist  = farLaneSpace.Split(spearator, count, StringSplitOptions.None);
            strlist1 = closeLaneSpace.Split(spearator, count, StringSplitOptions.None);
            string prev = textBox7.Text;

            if (textBox7.Text != "None")
            {
                Console.WriteLine("HERE");

                if (radioButton4.Checked == true)
                {
                    textBox7.Text = Convert.ToString(float.Parse(textBox7.Text) * (float.Parse(txtContinuousCarSpeed.Text) * float.Parse("0.277778")));
                }
                if (Math.Abs(float.Parse(strlist[1]) - float.Parse(strlist1[1])) != float.Parse(textBox7.Text))
                {
                    strlist[1] = (float.Parse(strlist1[1]) + float.Parse(textBox7.Text)).ToString();
                }
            }
            textBox7.Text = prev;


            String prepost = "None";

            if (radioButton5.Checked == true)
            {
                prepost = "pre";
            }
            else if (radioButton9.Checked == true)
            {
                prepost = "stand";
            }
            else
            {
                prepost = "post";
            }

            String CLSR      = Data.printString("CarListSpaceRight", "CarListSpaceRight");
            String trialcond = textBox8.Text;
            String Speed     = Convert.ToString(float.Parse(txtContinuousCarSpeed.Text) * float.Parse("0.277778"));

            SqlConnection con = Data.openSQLConnection(); // Open SQL Connection

            String trialtype     = "trialType = '" + cbTrialType.Text + "',";
            String trialBehav    = "trialBehav = '" + cbCarBehaviour.Text + "',";
            String CarSpaceRight = "CarSpaceRight = '" + Data.printString("CarListSpaceRight", "CarListSpaceRight") + "',";
            String CarSpaceLeft  = "CarSpaceLeft = '" + string.Join(" ", strlist) + "',";
            String speed         = "speed = '" + Speed + "',";
            String trialCond     = "trialCond = '" + trialcond + "',";
            String pre_post      = "prepost = '" + prepost + "'";

            String query1 = "UPDATE trialList SET " + trialtype + trialBehav + CarSpaceRight + CarSpaceLeft + speed + trialCond + pre_post + " WHERE ID=" + ID.Text;

            Console.WriteLine(query1);
            SqlCommand cmd = new SqlCommand(query1, con);

            cmd.ExecuteNonQuery();


            if (radioButton7.Checked == true)
            {
                SqlConnection con2 = Data.openSQLConnection(); // Open SQL Connection
                SqlCommand    cmd2 = new SqlCommand();
                cmd2.Connection  = con;
                cmd2.CommandText = "INSERT INTO trialPresets (trialType, trialBehav,CarSpaceRight,CarSpaceLeft,speed,trialCond,prepost) VALUES (@trialType, @trialBehav,@CarSpaceRight,@CarSpaceLeft,@speed,@trialCond,@prepost);";
                cmd2.Parameters.AddWithValue("@trialType", cbTrialType.Text);
                cmd2.Parameters.AddWithValue("@trialBehav", cbCarBehaviour.Text);
                cmd2.Parameters.AddWithValue("@CarSpaceRight", Data.printString("CarListSpaceRight", "CarListSpaceRight"));
                cmd2.Parameters.AddWithValue("@CarSpaceLeft", string.Join(" ", strlist));
                cmd2.Parameters.AddWithValue("@speed", Speed);
                cmd2.Parameters.AddWithValue("@trialCond", trialcond);
                cmd2.Parameters.AddWithValue("@prepost", prepost);
                cmd2.ExecuteNonQuery();
            }



            String query = "DELETE FROM dbo.CarListSpaceRight";

            cmd = new SqlCommand(query, con);
            cmd.ExecuteNonQuery();
            query = "DELETE FROM dbo.CarListSpaceLeft";
            cmd   = new SqlCommand(query, con);
            cmd.ExecuteNonQuery();

            this.Hide();

            frm1.updateDataTable();
            this.Close();
        }
Ejemplo n.º 20
0
        private void Button7_Click(object sender, EventArgs e)
        {
            string index = "-1";

            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
            {
                if (row.Cells[0].Value == null)
                {
                    return;
                }
                index = Convert.ToString(row.Cells[0].Value.ToString());
            }
            if (index == "-1")
            {
                return;
            }


            cbTrialType.SelectedIndex = 0;
            cbCarBehaviour.Text       = "";
            textBox8.Text             = "";
            SQLfx         DataC = new SQLfx();
            SqlConnection conC  = DataC.openSQLConnection(); // Open SQL Connection

            String queryC = "DELETE FROM CarListSpaceRight; DELETE FROM CarListSpaceLeft";

            SqlCommand cmdC = new SqlCommand(queryC, conC);

            cmdC.ExecuteNonQuery();


            SQLfx Data = new SQLfx();

            SqlConnection con = Data.openSQLConnection(); // Open SQL Connection

            String query = "SELECT * FROM trialPresets WHERE ID= " + index;

            Console.WriteLine(query);
            SqlCommand     cmd = new SqlCommand(query, con);
            SqlDataAdapter da  = new SqlDataAdapter(cmd);
            DataTable      dt  = new DataTable();

            da.Fill(dt);
            StringBuilder output     = new StringBuilder();
            int           numEntries = 0;

            foreach (DataRow dr in dt.Rows)
            {
                foreach (DataColumn col in dt.Columns)
                {
                    output.AppendFormat("{0},", dr[col]);
                }
                numEntries++;
                output.AppendLine();
            }
            Console.WriteLine(output);

            String[] strlist1 = new String[200];
            Int32    count1   = 200;

            char[] spearator1 = { ',', '\0' };
            string newoutput  = output.ToString();

            Console.WriteLine(output.ToString().Split('\n')[0]);
            Console.WriteLine(output.ToString().Split('\n')[0].Split(',')[0]);
            Console.WriteLine(output.ToString().Split('\n')[0].Split(',')[1]);
            Console.WriteLine(numEntries);

            strlist1 = newoutput.Split(spearator1, count1, StringSplitOptions.None);
            String TrialType  = strlist1[1];
            String TrialBehav = strlist1[2];
            String trialSpeed = strlist1[6];
            String trialcond  = strlist1[7];
            String prepost    = strlist1[8];
            String CSR1       = strlist1[3];
            String CSL1       = strlist1[4];

            Console.WriteLine(TrialType + TrialBehav + trialSpeed + trialcond + prepost + CSR1 + CSL1);
            cbTrialType.Text    = TrialType;
            cbCarBehaviour.Text = TrialBehav;
            textBox8.Text       = trialcond;
            float temp = float.Parse(trialSpeed) / float.Parse("0.277778");

            Console.WriteLine(txtContinuousCarSpeed.Text);
            int inter = (int)Math.Round(temp);

            txtContinuousCarSpeed.Text = Convert.ToString(inter);
            if (prepost.Contains("pre"))
            {
                radioButton5.Checked = true;
            }
            else if (prepost.Contains("stand"))
            {
                radioButton9.Checked = true;
            }
            else
            {
                radioButton6.Checked = true;
            }
            textBox2.Text = CSR1;
            textBox5.Text = CSL1;


            SQLfx Data1 = new SQLfx();

            SqlConnection con1 = Data1.openSQLConnection(); // Open SQL Connection

            String[] CSR       = new String[200];
            char[]   spearator = { ' ' };
            CSR = CSR1.Split(spearator, count1, StringSplitOptions.None);

            for (int i = 1; i < CSR.Length; i++)
            {
                Console.WriteLine("WE " + CSR[i]);
                CSR[i] = "(" + CSR[i] + ")";
            }

            String yourString = String.Join(" , ", CSR);

            if (yourString.Length > 0)
            {
                yourString = yourString.Substring(1, yourString.Length - 1);
                Console.WriteLine("OKAY " + yourString.Substring(1, yourString.Length - 1));
                CSR1 = yourString.Substring(1, yourString.Length - 1);
                String query1 = "INSERT INTO dbo.CarListSpaceRight (CarListSpaceRight) VALUES " + CSR1;

                SqlCommand cmd1 = new SqlCommand(query1, con1);

                cmd1.ExecuteNonQuery();
            }
            SQLfx Data2 = new SQLfx();

            SqlConnection con2 = Data2.openSQLConnection(); // Open SQL Connection

            String[] CSL = new String[200];
            CSL = CSL1.Split(spearator, count1, StringSplitOptions.None);

            for (int i = 1; i < CSL.Length; i++)
            {
                Console.WriteLine("WE " + CSL[i]);
                CSL[i] = "(" + CSL[i] + ")";
            }

            yourString = String.Join(" , ", CSL);
            if (yourString.Length > 0)
            {
                yourString = yourString.Substring(1, yourString.Length - 1);
                CSL1       = yourString.Substring(1, yourString.Length - 1);
                String query2 = "INSERT INTO dbo.CarListSpaceLeft (CarListSpaceLeft) VALUES " + CSL1;

                SqlCommand cmd2 = new SqlCommand(query2, con2);
                cmd2.ExecuteNonQuery();
            }
            textBox2.Text = Data.printString("CarListSpaceRight", "CarListSpaceRight");
            textBox5.Text = Data.printString("CarListSpaceLeft", "CarListSpaceLeft");

            Console.WriteLine(CSR.GetLength(0));
            Console.WriteLine("RWRTWTW " + CSL.GetLength(0));
            if (CSL.Length - 1 > 0)
            {
                radioButton2.Checked = true;
            }
            else
            {
                radioButton1.Checked = true;
            }
        }
Ejemplo n.º 21
0
        private void btnCopyTrial_Click(object sender, EventArgs e)
        {
            // Needs defensive programming -- What if no entires in DataTable?? Should be working now
            SQLfx Data = new SQLfx();

            SqlConnection con = Data.openSQLConnection(); // Open SQL Connection

            string index = "-1";

            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
            {
                if (row.Cells[0].Value == null)
                {
                    return;
                }
                index = Convert.ToString(row.Cells[0].Value.ToString());
            }
            if (index == "-1")
            {
                return;
            }


            String         query = "SELECT * FROM trialList WHERE ID= " + index;
            SqlCommand     cmd   = new SqlCommand(query, con);
            SqlDataAdapter da    = new SqlDataAdapter(cmd);
            DataTable      dt    = new DataTable();

            da.Fill(dt);
            StringBuilder output  = new StringBuilder();
            int           checker = 0;

            foreach (DataRow dr in dt.Rows)
            {
                foreach (DataColumn col in dt.Columns)
                {
                    output.AppendFormat("{0},", dr[col]);
                }

                checker = 1;
            }
            if (checker == 1)
            {
                Console.WriteLine(output);
                String[] strlist   = new String[1000];
                Int32    count     = 200;
                char[]   spearator = { ',', '\0', '\n' };
                string   newoutput = output.ToString();

                strlist = newoutput.Split(spearator, count, StringSplitOptions.None);
                Console.WriteLine("COPYUNG" + newoutput + strlist[8]);
                String TrialType  = strlist[1];
                String TrialBehav = strlist[2];
                String CSR        = strlist[3];
                String CSL        = strlist[4];
                String trialspeed = strlist[6];
                String trialcond  = strlist[7];
                String prepost    = strlist[8];

                String replace = Regex.Replace(CSL, @"\t|\n|\r|,", "");
                //CSL[CSL.Length -1] = "/0";
                cmd.Connection  = con;
                cmd.CommandText = "INSERT INTO trialList (trialType, trialBehav,CarSpaceRight,CarSpaceLeft,speed,trialCond,prepost) VALUES (@trialType, @trialBehav,@CarSpaceRight,@CarSpaceLeft,@speed,@trialCond,@prepost);";
                cmd.Parameters.AddWithValue("@trialType", TrialType);
                cmd.Parameters.AddWithValue("@trialBehav", TrialBehav);
                cmd.Parameters.AddWithValue("@CarSpaceRight", CSR);
                cmd.Parameters.AddWithValue("@CarSpaceLeft", replace);
                cmd.Parameters.AddWithValue("@speed", trialspeed);
                cmd.Parameters.AddWithValue("@trialCond", trialcond);
                cmd.Parameters.AddWithValue("@prepost", prepost);
                cmd.ExecuteNonQuery();
                updateDataTable();
            }
        }
Ejemplo n.º 22
0
        public void ee(String PartID, String PartAge, String PartSex, String PartHeight, String folderPath, String fileExt)
        {
            Console.WriteLine(checkEmptyTable("trialList"));
            if (checkEmptyTable("trialList") && !checkEmptyTable("condPresets")) // Also check if preset selected
            {
                SQLfx         DataQ  = new SQLfx();
                SqlConnection conQ   = DataQ.openSQLConnection(); // Open SQL Connection
                String        queryQ = "insert into trialList(condLabel, trialType,prepost, trialCond, trialBehav, speed, CarSpaceRight, CarSpaceLeft) select condLabel ,trialType,prepost, trialCond, trialBehav, speed, CarSpaceRight, CarSpaceLeft from condPresets";

                SqlCommand cmdQ = new SqlCommand(queryQ, conQ);
                cmdQ.ExecuteNonQuery();
                Console.WriteLine(queryQ);
            }
            Form1 mainForm = new Form1();
            SQLfx Data     = new SQLfx();

            int    counter = 0;
            string line;

            string[] array = new String[100];



            ///////// -------- Begin Reading Globals File, Line By Line, Stored In Array ----------------------

            //  Read the file and display it line by line.
            System.IO.StreamReader file =
                new System.IO.StreamReader(@"C:\vr\vr3\VRTSGUI\VRTSGUI\GlobalsBackup.py");
            while ((line = file.ReadLine()) != null)
            {
                //System.Console.WriteLine(line);
                array[counter] = line;
                counter++;
            }
            System.Console.WriteLine("\n\nHERE: {0}     ", array[26]);
            file.Close();
            //System.Console.WriteLine("There were {0} lines.", counter);
            // Suspend the screen.
            //System.Console.ReadLine();

            ///////// -------- Get Values From SQL Database, Stored As Local Variables ----------------------

            String DCP = Data.printString("properties", "DCP");

            Console.WriteLine("XXXXXXXXXXXXXXX DCP " + DCP);
            String NMD = Data.printString("properties", "NMD");
            String RSD = Data.printString("properties", "RSD");
            String RND = Data.printString("properties", "RND");
            String FCA = Data.printString("properties", "FCA");
            String PCA = Data.printString("properties", "PCA");
            String MPA = Data.printString("properties", "MPA");
            String ist = Data.printString("properties", "IST");
            String CSR = Data.printCS("trialList", "CarSpaceRight");

            ///////// -------- Line By Line Parse and Modify Values From Array ----------------------

            char[] spearator = { '=' };
            Int32  count     = 2;
            String final     = "";

            String[] strlist = new String[2];
            String[] cS      = new String[2];

            //strlist = array[26].Split('  ');
            cS = CSR.Split(':');
            Console.WriteLine("CSR: " + cS.Length);


            // DCP is Array 27
            strlist   = array[26].Split(spearator, count, StringSplitOptions.None);
            array[26] = strlist[0] + " = " + DCP;

            // NMD is Array 28
            strlist   = array[27].Split(spearator, count, StringSplitOptions.None);
            array[27] = strlist[0] + " = " + NMD;

            // RSD is Array 31
            strlist   = array[31].Split(spearator, count, StringSplitOptions.None);
            array[31] = strlist[0] + " = " + ist;

            // RSD is Array 33
            strlist   = array[32].Split(spearator, count, StringSplitOptions.None);
            array[32] = strlist[0] + " = " + RSD;

            // RND is Array 34
            strlist   = array[33].Split(spearator, count, StringSplitOptions.None);
            array[33] = strlist[0] + " = " + RND;

            // folderPath is Array 35
            strlist   = array[34].Split(spearator, count, StringSplitOptions.None);
            array[34] = strlist[0] + " = '" + folderPath + "'";

            // folderPath is Array 36
            strlist   = array[35].Split(spearator, count, StringSplitOptions.None);
            array[35] = strlist[0] + " = '" + fileExt + "'";

            // ID is Array 41
            strlist   = array[40].Split(spearator, count, StringSplitOptions.None);
            array[40] = strlist[0] + " = " + "'" + PartID + "'";

            // participantVariableValues is Array 43
            array[42] = "participantVariableValues = " + "[" + "'" + PartID + "'" + "," + "'" + PartAge + "'" + "," + "'" + PartSex + "'" + "," + "'" + PartHeight + "'" + "]";


            // FCA is Array 45
            strlist   = array[44].Split(spearator, count, StringSplitOptions.None);
            array[44] = strlist[0] + " = " + FCA;

            // PCA is Array 46
            strlist   = array[45].Split(spearator, count, StringSplitOptions.None);
            array[45] = strlist[0] + " = " + PCA;

            // MPA is Array 48
            strlist   = array[47].Split(spearator, count, StringSplitOptions.None);
            array[47] = strlist[0] + " = " + MPA;


            string[] newArray = new String[array.Length + cS.Length];
            for (int i = 0; i < 53; i++)
            {
                newArray[i] = array[i];
            }
            // Needs defensive programming -- What if no entires in DataTable??


            SqlConnection  con = Data.openSQLConnection(); // Open SQL Connection
            SqlCommand     cmd = new SqlCommand("SELECT * FROM trialList", con);
            SqlDataAdapter da  = new SqlDataAdapter(cmd);
            DataTable      dt  = new DataTable();

            da.Fill(dt);
            StringBuilder output     = new StringBuilder();
            int           numEntries = 0;

            foreach (DataRow dr in dt.Rows)
            {
                foreach (DataColumn col in dt.Columns)
                {
                    output.AppendFormat("{0},", dr[col]);
                }
                numEntries++;
                output.AppendLine();
            }
            if (numEntries == 0)
            {
                return;
            }
            Console.WriteLine("KO --");
            Console.WriteLine(output);
            Console.WriteLine("--\n\n");
            String[] strlist1 = new String[200];
            Int32    count1   = 200;

            char[] spearator1 = { ',', '\0' };
            string newoutput  = output.ToString();

            Console.WriteLine(output.ToString().Split('\n')[0]);
            Console.WriteLine(output.ToString().Split('\n')[0].Split(',')[0]);
            Console.WriteLine(output.ToString().Split('\n')[0].Split(',')[1]);
            Console.WriteLine(numEntries);
            for (int i = 0; i < numEntries; i++)
            {
                newoutput = output.ToString().Split('\n')[i];
                Console.WriteLine("HERE: ", newoutput);
                strlist1 = newoutput.Split(spearator1, count1, StringSplitOptions.None);
                Console.WriteLine(newoutput);
                String TrialType  = strlist1[1];
                String TrialBehav = strlist1[2];
                //Console.WriteLine("ANALYSIS"+  strlist1 +  newoutput + "\n"+strlist1[6]);
                string trialSpeed = strlist1[6];
                string trialcond  = "'" + strlist1[7] + "'";
                String prepost    = "'" + strlist1[8] + "'";
                if (TrialBehav == "Spawn On Enter Road")
                {
                    TrialBehav = "SPAWNONROADENTER";
                }
                else
                {
                    TrialBehav = "SPAWNONSTARTTRIAL";
                }
                String   CSR1    = strlist1[3];
                String   CSL1    = strlist1[4];
                String   replace = Regex.Replace(CSL1, @"\t|\n|\r|,", "");
                string[] CSR12   = Regex.Split(CSR1, @"[^0-9\.]+");
                string[] CSL12   = Regex.Split(replace, @"[^0-9\.]+");
                Console.WriteLine("UIUIOUIOUIOUOI " + CSR1);
                //  Once all values are in array, respective to their lines, then write array element by element to file line by line
                string finalCSR = string.Join(",", CSR12, 1, CSR12.Length - 1);
                string finalCSL = string.Join(",", CSL12, 1, CSL12.Length - 1);


                Console.WriteLine("\n\n" + string.Join(",", CSR12, 1, CSR12.Length - 1));
                if (finalCSR.Length > 0)
                {
                    if (finalCSR[finalCSR.Length - 1] == ',')
                    {
                        finalCSR = finalCSR.Substring(0, finalCSR.Length - 1);
                    }
                }
                if (finalCSL.Length > 0)
                {
                    if (finalCSL[finalCSL.Length - 1] == ',')
                    {
                        finalCSL = finalCSL.Substring(0, finalCSL.Length - 1);
                    }
                }


                TrialType = TrialType.Replace("-", "_");
                TrialType = TrialType.ToUpper();
                if (TrialType == "STANDARD_CONSTANTGAP_PRE")
                {
                    TrialType = "STANDARD_ConstantGap_PRE";
                }
                if (numEntries == 1 || i == numEntries - 1)
                {
                    newArray[53 + i] = string.Format("(TrialType." + TrialType + ", " + trialcond + ", " + "CarBehaviour." + TrialBehav + ", " + "[" + finalCSR + "]" + ", " + "[" + finalCSL + "], " + trialSpeed + " , " + trialSpeed + ", 1, 1, True, 0, 0, AvatarBehaviour.NONE" + ", " + prepost + ")");
                }
                else
                {
                    newArray[53 + i] = string.Format("(TrialType." + TrialType + ", " + trialcond + ", " + "CarBehaviour." + TrialBehav + ", " + "[" + finalCSR + "]" + ", " + "[" + finalCSL + "], " + trialSpeed + " , " + trialSpeed + ", 1, 1, True, 0, 0, AvatarBehaviour.NONE" + ", " + prepost + "),");
                }
            }
            for (int i = 0; i <= 8; i++)
            {
                newArray[53 + numEntries + i] = array[54 + i];
            }
            // Write the string array to a new file named "WriteLines.txt".--- Will need to be chnaged to Globals.py
            using (StreamWriter outputFile = new StreamWriter(Path.Combine(@"C:\vr\vr3\Globals.py")))
            {
                for (int i = 0; i < counter + numEntries; i++)
                {
                    outputFile.WriteLine(newArray[i]);
                    Console.WriteLine(newArray[i]);
                }
            }


            Console.WriteLine("Printing to global completed");
        }