标题:把C源代码编译成vb-->multiple1902转移
取消只看楼主
neptuneking
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-8-31
 问题点数:0 回复次数:1 
把C源代码编译成vb-->multiple1902转移

请高手帮忙把下面的代码用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();
}
}
}

搜索更多相关主题的帖子: 源代码 编译 
2007-08-31 14:40
neptuneking
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-8-31
得分:0 
以下是引用multiple1902在2007-8-31 15:05:55的发言:
你走错地方了

这是VS7或VS8的代码。

还在关注问题的话跟帖说明一声,谢谢合作。

紧着用的啊,麻烦版主帮忙啊!!
Thank you !!!

2007-08-31 23:41



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-166787-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.051997 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved