📄 studentin.aspx.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Personal_StudentIn : System.Web.UI.Page
{
static int formID = 0;
static int st_Class = 0;
static string st_IntroduceBy;
static Decimal st_Fee = 0;
static Decimal st_RealPay = 0;
static Decimal st_Rate = 1;
static string st_JoinDate = "";
LoginInfo My;
protected void Page_Load(object sender, EventArgs e)
{
My = new LoginInfo(Session["LoginID"]);
if (My.LoginID == 0) Response.Redirect("~/Signin.aspx");
My = new LoginInfo(Convert.ToInt32(Session["LoginID"]));
formID = Convert.ToInt32(Request.QueryString["ID"]);
st_Class = Convert.ToInt32(Request.QueryString["ClassID"]);
// st_JoinDate = DateTime.Now;
PersonInput.PersonID = formID;
ErrMsg.Text = "";
if (!My.IsAdmin() ) ddlIntroduceBy.Enabled = false;
if (!IsPostBack)
{
String sql = "SELECT * FROM J_Student WHERE st_ID=" + formID + " AND 1<=" + My.PowerOnStudent(formID);
DataTable dt = DBExec.ExecDataTable(sql);
txtlRate.Attributes.Add("onchange", "calcRealPay('" + txtFee.ClientID + "','" + txtlRate.ClientID + "','" + txtRealPay.ClientID + "');");
txtFee.Attributes.Add("onchange", "calcRealPay('" + txtFee.ClientID + "','" + txtlRate.ClientID + "','" + txtRealPay.ClientID + "');");
if (dt.Rows.Count != 0)
{
DataRow sdr = dt.Rows[0];
ddlBanJi.SelectedValue = sdr["st_Class"].ToString();
if (sdr["st_JoinDate"] != DBNull.Value)
txtJoinDate.Text = (Convert.ToDateTime(sdr["st_JoinDate"])).ToShortDateString();
lblMessageResult.Text = formID + "号同学的记录:";
txtRealPay.Text = Convert.ToDecimal(sdr["st_RealPay"]).ToString("#0.00");
txtlRate.Text = sdr["st_Rate"].ToString();
txtFee.Text = Convert.ToDecimal(sdr["st_Fee"]).ToString("#0.00");
if (sdr["st_IntroduceBy"] != DBNull.Value)
{
ddlIntroduceBy.SelectedValue = sdr["st_IntroduceBy"].ToString().Trim();
}
else
{
ddlIntroduceBy.SelectedIndex = 0;
}
}
else
{
lblMessageResult.Text = "请在下面输入新学生记录";
ddlIntroduceBy.SelectedValue = My.LoginID.ToString();
txtFee.Text = st_Fee.ToString();
txtlRate.Text = st_Rate.ToString();
txtRealPay.Text = st_RealPay.ToString();
ddlBanJi.DataSourceID = "SqlDataSource3";
ddlBanJi.DataBind();
if (st_Class != 0)
ddlBanJi.Text = st_Class.ToString();
txtJoinDate.Text = DateTime.Now.ToShortDateString();
}
//为双向选择列表赋值
DualList.DepartmentID = formID;
}
}
//修改该学生所对应的(班级-课程)号
private void ModifyDepartmentStudent()
{
String selectedCourse = DualList.AllValues.Trim();
String unSelectedCourse = DualList.AllUnSelect.Trim();
if (unSelectedCourse == "") unSelectedCourse = "0";
// ErrMsg.Text +="<BR />ALLVALUES=" + selectedCourse+"AllUNSELECT="+unSelectedCourse + "<br />";
// Response.Write("DUALLIST="+selectedDeCourse);
//清除以前的选课,前提是该课程从未上过 sc_State字段表示该生该课目前上过的次数
String sql = "DELETE FROM J_StCourse WHERE sc_Student=" + formID + " AND sc_ID NOT IN (SELECT at_StCourse FROM J_Attend)";
try
{
DBExec.ExecNonQuery(sql);
}
catch (SqlException e)
{
ErrMsg.Text += e.Message;
}
if (selectedCourse != "")
{
String[] selDeCourse = selectedCourse.Split(',');
for (int i = 0; i < selDeCourse.Length; i++)
{
//判断是否选修过相同的课程
sql = "SELECT COUNT(J_StCourse.sc_ID) FROM J_StCourse INNER JOIN J_DeCourse ON dc_ID=sc_DeCourse WHERE " + formID + "=sc_Student AND dc_Course="
+ "(SELECT dc_Course FROM J_DeCourse WHERE dc_ID=" + selDeCourse[i] + ")";
int n = DBExec.ExecGetInt(sql);
if (n == 0)
{
sql = "INSERT INTO J_StCourse (sc_Student,sc_DeCourse) VALUES (" + formID + ", " + selDeCourse[i] + ")";
DBExec.ExecNonQuery(sql);
ErrMsg.Text += "一门课程已添加.<BR />";
}
else
{
ErrMsg.Text += "课程无法添加, 因为已选修过相同课程.<BR />";
}
}
}
}
protected void btnOK_Click(object sender, EventArgs e)
{
string sql;
if (!IsValid) return;
ErrMsg.Text = "";
st_Class = CommOp.ToInt(ddlBanJi.SelectedValue);
st_JoinDate = txtJoinDate.Text;
st_IntroduceBy = ddlIntroduceBy.Text;
try
{
if (txtFee.Text.Trim() != "")
st_Fee = Convert.ToDecimal(txtFee.Text);
if (txtRealPay.Text.Trim() != "")
st_RealPay = Convert.ToDecimal(txtRealPay.Text);
}
catch (Exception ex)
{
ErrMsg.Text += ex.Message + "<br />";
}
if (formID > 0 && My.PowerOnStudent(formID) < 2 && !My.IsAdmin())
{
ErrMsg.Text += "您无权限进行该学生的修改操作.<br />";
}
if (st_Class == 0)
{
ErrMsg.Text += "您没有为该学生选择班级.<br />也许管理员还没有跟您分配班级,请与管理员联系。<br />";
}
if (My.PowerOnClass(st_Class) < 1)
{
ErrMsg.Text += "您无权限对此班级进行学生的调动。<br />";
}
st_Rate = Convert.ToDecimal(txtlRate.Text);
if (ErrMsg.Text != "") return;
PersonInput.AddorModify();
formID = PersonInput.PersonID;
List<SqlParameter> sp = new List<SqlParameter>();
sp.Add(new SqlParameter("@st_ID", formID));
sp.Add(new SqlParameter("@st_Class", st_Class));
sp.Add(new SqlParameter("@st_Fee", st_Fee));
sp.Add(new SqlParameter("@st_Rate", st_Rate));
sp.Add(new SqlParameter("@st_RealPay", st_RealPay));
if (st_JoinDate == "")
sp.Add(new SqlParameter("@st_JoinDate", DBNull.Value));
else
sp.Add(new SqlParameter("@st_JoinDate", st_JoinDate));
if (st_IntroduceBy == "")
sp.Add(new SqlParameter("@st_IntroduceBy", DBNull.Value));
else
sp.Add(new SqlParameter("@st_IntroduceBy", st_IntroduceBy));
if (PersonInput.Operation == uctl_PersonInput.Modified)
{
sql = "UPDATE J_Student SET st_Class=@st_Class,st_JoinDate=@st_JoinDate,st_IntroduceBy=@st_IntroduceBy," +
"st_Fee= @st_Fee ,st_Rate= @st_Rate ,st_RealPay= @st_RealPay WHERE st_ID=@st_ID";
DBExec.ExecParamQuery(sql, sp);
ModifyDepartmentStudent();
ErrMsg.Text = "成功修改了学生信息";
}
else
{
sql = "INSERT INTO J_Student (st_ID,st_Class,st_JoinDate,st_IntroduceBy,st_Fee,st_Rate,st_RealPay) VALUES " +
" (@st_ID, @st_Class, @st_JoinDate, @st_IntroduceBy, @st_Fee , @st_Rate , @st_RealPay )";
DBExec.ExecParamQuery(sql, sp);
/*
//在增加一个新同学时为该同学分配该班所有的必修课
sql = "SELECT dc_ID FROM J_DeCourse WHERE dc_Department=" + st_Class;
DataTable dt = DBExec.ExecDataTable(sql);
foreach (DataRow row in dt.Rows)
{
sql = "INSERT INTO J_StCourse (sc_Student,sc_DeCourse) VALUES (" + formID + ", " + row[0].ToString() + ")";
DBExec.ExecNonQuery(sql);
}
*/
ErrMsg.Text = "成功新增了学生信息";
Response.Redirect(Request.Path.ToString() + "?ID=" + formID, true);
}
lblMessageResult.Text += formID + "号:" + PersonInput.PersonName;
DualList.DepartmentID = formID;
PersonInput.PersonID = formID;
}
protected void btnAddNew_Click(object sender, EventArgs e)
{
Response.Redirect(Request.Path + "?ClassID=" + st_Class, true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -