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 = ""; }
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 = ""; }
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"); }
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"); }