当前位置: 代码迷 >> C语言 >> 请把C的源代码编译成vb的源代码
  详细解决方案

请把C的源代码编译成vb的源代码

热度:283   发布时间:2007-08-31 14:43:03.0
请把C的源代码编译成vb的源代码

请高手帮忙把下面的代码用vb翻译出来!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace PaiKe
{
public partial class mainForm : Form
{
public mainForm()
{
InitializeComponent();
}

private void btnRollBack_Click(object sender, EventArgs e)
{
string strConnection = "server=.;database=PaiKe;uid=sa;pwd=0407505147";
SqlConnection objConnection = new SqlConnection(strConnection);
objConnection.Open();

string strDeleteTempPaiKe = "delete from TempPaiKe";
SqlCommand objDeleteTempPaiKe = new SqlCommand(strDeleteTempPaiKe, objConnection);
objDeleteTempPaiKe.ExecuteNonQuery();

string strDeletePaiKe = "delete from PaiKe";
SqlCommand objDeletePaiKe = new SqlCommand(strDeletePaiKe, objConnection);
objDeletePaiKe.ExecuteNonQuery();

string strUpdateCourseClass = "update CourseClass set courseClass=0 where courseClass=1";
SqlCommand objUpdateCourseClass = new SqlCommand(strUpdateCourseClass, objConnection);
objUpdateCourseClass.ExecuteNonQuery();

string strUpdateClassTime = "update ClassTime set classTime=0 where classTime=1";
SqlCommand objUpdateClassTime = new SqlCommand(strUpdateClassTime, objConnection);
objUpdateClassTime.ExecuteNonQuery();

string strUpdateTeacherTime = "update TeacherTime set teacherTime=0 where teacherTime=1";
SqlCommand objUpdateTeacherTime = new SqlCommand(strUpdateTeacherTime, objConnection);
objUpdateTeacherTime.ExecuteNonQuery();

string strUpdateRoomTime = "update RoomTime set roomTime=0 where roomTime=1";
SqlCommand objUpdateRoomTime = new SqlCommand(strUpdateRoomTime, objConnection);
objUpdateRoomTime.ExecuteNonQuery();

objConnection.Close();

testLabel.Text = "删除排课表成功";
}

private void btnTempPaiKe_Click(object sender, EventArgs e)
{
string strConnection = "server=.;database=PaiKe;uid=sa;pwd=0407505147";
SqlConnection objConnection = new SqlConnection(strConnection);
objConnection.Open();

//string strSelect = "select classID,courseID,teacherID,timeID,roomID from CourseClass,TeacherCourse,Room,Time where CourseClass.courseID=TeacherCourse.courseID";
//SqlCommand objSelect = new SqlCommand(strSelect,objConnection);
//objSelect.ExecuteReader();

//string strCommand = "insert into TempPaiKe(classID,courseID,teacherID,timeID,roomID) select classID,courseID,teacherID,timeID,roomID from CourseClass,Teacher,Time,Room";
string strCommand = "insert into TempPaiKe(classID,courseID,teacherID,timeID,roomID) select classID,courseID1,teacherID,timeID,roomID from CourseClass,TeacherCourse,Time,Room where courseID1=courseID2";
//string strCommand = "insert into TempPaiKe(classID,courseID,teacherID,timeID,roomID) values('" + classID + "','" + courseID + "','"+ teacherID + "','"+ timeID + "','"+ roomID + "')";
//string strCommand = "insert into TempPaiKe(courseID) select courseID from CourseClass,TeacherCourse where CourseClass.courseID=TeacherCourse.courseID";
SqlCommand objCommand = new SqlCommand(strCommand, objConnection);
objCommand.ExecuteNonQuery();

//SqlDataAdapter objAdapter = new SqlDataAdapter(strCommand, objConnection);
//objAdapter.Fill(objDataSet, "Course");
//DataTable objCourse = objDataSet.Tables["Course"];

objConnection.Close();
testLabel.Text = "预排课成功";
}

private void btnPaiKe_Click(object sender, EventArgs e)
{
// 不判断查找tempPaike表时是否出现空

string strConnection = "server=.;database=PaiKe;uid=sa;pwd=0407505147";
SqlConnection objConnection = new SqlConnection(strConnection);
objConnection.Open();

string strSelectClass = "select classID from Class";
SqlDataAdapter objSelectClassAdapter = new SqlDataAdapter(strSelectClass, objConnection);
objSelectClassAdapter.Fill(objDataSet, "Class");
DataTable objClass = objDataSet.Tables["Class"];

// 为获取的各个表的行数而设置的变量
int courseClassNum = 0;
int teacherNum = 0;
int classCourseNum = 0;
int courseNumAll = 0;

int classTimeNum = 0;
int teacherTimeNum = 0;
int roomTimeNum = 0;

for (int classNum = 0; classNum < objClass.Rows.Count; classNum++)
{
// 获取班级名
string classID = objClass.Rows[classNum]["classID"].ToString();

string strSelectCourse = "select courseID2 from CourseClass where classID='" + classID + "'";
SqlDataAdapter objSelectCourseAdapter = new SqlDataAdapter(strSelectCourse, objConnection);
objSelectCourseAdapter.Fill(objDataSet, "Course");
DataTable objCourse = objDataSet.Tables["Course"];
for (int courseNum = courseNumAll; courseNum < objCourse.Rows.Count; courseNum++)
{
string courseID = objCourse.Rows[classCourseNum]["courseID2"].ToString();

string strSelectCourseClass = "select courseClass from CourseClass where classID='" + classID + "' and courseID2='" + courseID + "'";
SqlDataAdapter objSelectCourseClass = new SqlDataAdapter(strSelectCourseClass, objConnection);
objSelectCourseClass.Fill(objDataSet, "CourseClass");
DataTable objCourseClass = objDataSet.Tables["CourseClass"];
string courseClass = objCourseClass.Rows[courseClassNum]["courseClass"].ToString();
if (courseClass == "1")
{
// 课程班级冲突。退出,执行下一门课程
testLabel.Text = "课程班级冲突";
classCourseNum++;
courseClassNum++;
}
else
{
// 课程班级不冲突
classCourseNum++;
courseClassNum++;
courseNumAll++;


// 如果班级,教室,教师与时间有冲突,则重新选取记录
for (int i = 0; i < 101; i++)
{

// 获取随机的教室,时间
Random room = new Random();
Random time = new Random();
int roomID = room.Next(1, 6);
int timeID = time.Next(1, 21);
//int roomID = 1;
//int timeID = 1;
// 查找满足以上参数的记录
string strSelectAll = "select teacherID,classID,courseID,roomID,timeID from TempPaiKe where classID='" + classID + "' and courseID='" + courseID + "' and roomID='" + roomID + "' and timeID='" + timeID + "'";
SqlDataAdapter objSelectAllAdapter = new SqlDataAdapter(strSelectAll, objConnection);
objSelectAllAdapter.Fill(objDataSet, "All");
DataTable objAll = objDataSet.Tables["All"];

// 获取刚才满足条件的教师,教室,时间
string teacherID = objAll.Rows[teacherNum]["teacherID"].ToString();

// 查找班级时间是否冲突
string strSelectClassTime = "select classTime from ClassTime where classID='" + classID + "' and timeID='" + timeID + "'";
SqlDataAdapter objSelectClassTime = new SqlDataAdapter(strSelectClassTime, objConnection);
objSelectClassTime.Fill(objDataSet, "ClassTime");
DataTable objClassTime = objDataSet.Tables["ClassTime"];
string classTime = objClassTime.Rows[classTimeNum]["classTime"].ToString();

if (classTime == "1")
{
// 班级时间冲突,重新返回选择另一条记录
testLabel.Text = "班级时间冲突";
teacherNum++;
classTimeNum++;

}
else
{
teacherNum++;
classTimeNum++;

string strSelectTeacherTime = "select teacherTime from TeacherTime where teacherID='" + teacherID + "' and timeID='" + timeID + "'";
SqlDataAdapter objSelectTeacherTime = new SqlDataAdapter(strSelectTeacherTime, objConnection);
objSelectTeacherTime.Fill(objDataSet, "TeacherTime");
DataTable objTeacherTime = objDataSet.Tables["TeacherTime"];
string teacherTime = objTeacherTime.Rows[teacherTimeNum]["teacherTime"].ToString();
if (teacherTime == "1")
{
testLabel.Text = "教师时间冲突";
teacherTimeNum++;
}
else
{
teacherTimeNum++;

// 判断获取的参数是否产生冲突
string strSelectRoomTime = "select roomTime from RoomTime where roomID='" + roomID + "' and timeID='" + timeID + "'";
SqlDataAdapter objSelectRoomTime = new SqlDataAdapter(strSelectRoomTime, objConnection);
objSelectRoomTime.Fill(objDataSet, "RoomTime");
DataTable objRoomTime = objDataSet.Tables["RoomTime"];
string roomTime = objRoomTime.Rows[roomTimeNum]["roomTime"].ToString();
if (roomTime == "1")
{
testLabel.Text = "教室时间冲突";

// 返回上一步,重新选择时间与教室
// roomTime的行加1
roomTimeNum++;
}
else
{
// 如果没有产生冲突,则i等于最大值,退出循环
i = 101;
// roomTime的行加1
roomTimeNum++;

// 插入符合条件的记录
string strInsertPaiKe = "insert into PaiKe values ('" + classID + "','" + courseID + "','" + teacherID + "','" + timeID + "','" + roomID + "')";
SqlCommand objInsertPaiKe = new SqlCommand(strInsertPaiKe, objConnection);
objInsertPaiKe.ExecuteNonQuery();

// 记录已被用过的时间与教室
string strUpdateRoomTime = "update RoomTime set roomTime='1' where roomID='" + roomID + "' and timeID='" + timeID + "'";
SqlCommand objUpdateRoomTime = new SqlCommand(strUpdateRoomTime, objConnection);
objUpdateRoomTime.ExecuteNonQuery();

// 记录已被用过的时间与教师
string strUpdateTeacherTime = "update TeacherTime set teacherTime='1' where teacherID='" + teacherID + "' and timeID='" + timeID + "'";
SqlCommand objUpdateTeacherTime = new SqlCommand(strUpdateTeacherTime, objConnection);
objUpdateTeacherTime.ExecuteNonQuery();

// 记录已被用过的时间与班级
string strUpdateClassTime = "update ClassTime set classTime='1' where classID='" + classID + "' and timeID='" + timeID + "'";
SqlCommand objUpdateClassTime = new SqlCommand(strUpdateClassTime, objConnection);
objUpdateClassTime.ExecuteNonQuery();

// 记录已排好的课程与班级
string strUpdateCourseClass = "update CourseClass set courseClass='1' where courseID2='" + courseID + "' and classID='" + classID + "'";
SqlCommand objUpdateCourseClass = new SqlCommand(strUpdateCourseClass, objConnection);
objUpdateCourseClass.ExecuteNonQuery();

// 插入新排课表成功
}
}
}
}
}
}
}
testLabel.Text = "插入新排课表成功";
// 垃圾回收
//System.GC.Collect();
//System.GC.WaitForPendingFinalizers();
objConnection.Close();
}
}
}


谢谢!!

搜索更多相关的解决方案: 源代码  using  System  编译  public  

----------------解决方案--------------------------------------------------------
又一个做作业的?找到C代码但要交VB代码的?




by 雨中飞燕 QQ:78803110 QQ讨论群:5305909

[url=http://bbs.bc-cn.net/viewthread.php?tid=163571]请大家不要用TC来学习C语言,点击此处查看原因[/url]
C/C++算法习题(OnlineJudge):[url]http://yzfy.org/[/url]

[此贴子已经被作者于2007-8-31 14:46:28编辑过]


----------------解决方案--------------------------------------------------------

这也不是C代码啊,估计楼主哥哥整天搞别的去了,连自己学的是什么语言都不知道了


----------------解决方案--------------------------------------------------------
那是C++



by 雨中飞燕 QQ:78803110 QQ讨论群:5305909

[url=http://bbs.bc-cn.net/viewthread.php?tid=163571]请大家不要用TC来学习C语言,点击此处查看原因[/url]
C/C++算法习题(OnlineJudge):[url]http://yzfy.org/[/url]
----------------解决方案--------------------------------------------------------

这不是C#的代码吗?求作业可不好,如果楼主待遇丰厚,可以考虑下(向老K学习)


----------------解决方案--------------------------------------------------------
  相关解决方案