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(); }
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(); }
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(); }
public void updatePresetTable() { 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 trialPresets", 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; }
private void button4_Click(object sender, EventArgs e) { SQLfx Data = new SQLfx(); SqlConnection con = Data.openSQLConnection(); // Open SQL Connection String query = "INSERT INTO dbo.CarListSpaceLeft (CarListSpaceLeft) VALUES (@CarListSpaceLeft)"; //WIPE TABLE ---- String query = "DELETE FROM dbo.CarListSpaceDIRECTION"; string prev = textBox6.Text; SqlCommand cmd = new SqlCommand(query, con); if (radioButton4.Checked == true && textBox6.TextLength != 0) { float value = float.Parse(textBox6.Text) * (float.Parse(txtContinuousCarSpeed.Text) * float.Parse("0.277778")); textBox6.Text = value.ToString("0.00"); } cmd.Parameters.AddWithValue("@CarListSpaceLeft", textBox6.Text); textBox6.Text = prev; cmd.ExecuteNonQuery(); //Data.closeSQLConnection(con); textBox5.Text = Data.printString("CarListSpaceLeft", "CarListSpaceLeft"); // textBox6.Text = ""; }
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 = ""; }
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(); }
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; } }
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"); }
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(); } }