01.
public
void
Compile()
02.
{
03.
04.
String strSQL = @" SELECT Course_ID
05.
FROM HW
06.
where HW_Name =
" + "
'" + DropDownList1.Text + "'
";
07.
08.
SqlDataReader sdr1 = clsDB.QueryDataReader(strSQL);
09.
sdr1.Read();
10.
String Course_ID = sdr1[
"Course_ID"
].ToString();
11.
clsDB.Close();
12.
13.
DirectoryInfo myDirInfo;
14.
DirectoryInfo myDirInfo2;
15.
DirectoryInfo[] arrFolderInfo;
16.
myDirInfo =
new
DirectoryInfo(Server.MapPath(
"~/Storage_File/Teacher/"
+ User.Identity.Name +
"/"
+ Course_ID +
"/"
));
17.
arrFolderInfo = myDirInfo.GetDirectories(
"*"
);
18.
19.
20.
21.
22.
23.
foreach
(DirectoryInfo myFolderInfo
in
arrFolderInfo)
24.
{
25.
try
26.
{
27.
string
filenameCompile = DropDownList1.Text +
"_"
+ myFolderInfo.Name +
".cpp"
;
28.
string
filenameCompile_2 = DropDownList1.Text +
"_"
+ myFolderInfo.Name;
29.
string
ShowResult = DropDownList1.Text +
"_"
+ myFolderInfo.Name +
".exe"
;
30.
string
Output = DropDownList1.Text +
"_"
+ myFolderInfo.Name +
".txt"
;
31.
string
StudentID = myFolderInfo.Name;
32.
33.
34.
System.Diagnostics.ProcessStartInfo si =
new
System.Diagnostics.ProcessStartInfo(
"cmd.exe"
);
35.
si.RedirectStandardInput =
true
; si.RedirectStandardOutput =
true
; si.RedirectStandardError =
true
; si.UseShellExecute =
false
; si.CreateNoWindow =
true
;
36.
System.Diagnostics.Process console = System.Diagnostics.Process.Start(si);
37.
console.StandardInput.WriteLine(@
"C:"
);
38.
console.StandardInput.WriteLine(@
"cd "
+ (Server.MapPath(
"~/Storage_File/Teacher/"
+ User.Identity.Name +
"/"
+ Course_ID +
"/"
+ myFolderInfo.Name +
"/"
+ DropDownList1.Text +
"/"
)));
39.
console.StandardInput.WriteLine(@
"g++ "
+ filenameCompile +
" -o "
+ filenameCompile_2);
40.
System.Threading.Thread.Sleep(1000);
41.
42.
console.StandardInput.WriteLine(@
"exit"
);
43.
System.Threading.Thread.Sleep(1000);
44.
45.
46.
47.
48.
49.
50.
51.
myDirInfo2 =
new
DirectoryInfo(Server.MapPath(
"~/Storage_File/Teacher/"
+ User.Identity.Name +
"/"
+ Course_ID +
"/"
+ myFolderInfo.Name +
"/"
+ DropDownList1.Text +
"/"
));
52.
53.
FileInfo[] arrFileInfo;
54.
55.
56.
arrFileInfo = myDirInfo2.GetFiles(
"*.exe"
);
57.
58.
59.
60.
foreach
(FileInfo myFileInfo
in
arrFileInfo)
61.
{
62.
63.
64.
if
(myFileInfo.Name == ShowResult)
65.
{
66.
67.
String strSQL1 = @" INSERT INTO Check_Compile
68.
(StudentID,HW_Name,Compile)
69.
VALUES (
'" + StudentID + "'
,
'" + DropDownList1.Text + "'
,
'" + "ผ่าน" + "'
)";
70.
71.
clsDB.QueryExecuteNonQuery(strSQL1);
72.
clsDB.Close();
73.
74.
}
75.
76.
77.
}
78.
}
79.
80.
catch
(System.IO.IOException e)
81.
{
82.
83.
}
84.
85.
86.
}
87.
88.
String strSQL2 = @" INSERT INTO Check_Compile (StudentID,HW_Name,Compile)
89.
select Enroll.Student_ID ,
'" + DropDownList1.Text + "'
,
'ไม่ผ่าน'
FROM Enroll WHERE Enroll.Student_ID NOT IN(select Check_Compile.StudentID from Check_Compile where HW_Name =
" + "
'" + DropDownList1.Text + "'
" + "
)";
90.
clsDB.QueryExecuteNonQuery(strSQL2);
91.
clsDB.Close();
92.
93.
}