08年9月入学,12年7月毕业,结束了我在软件学院愉快丰富的大学生活。此系列是对四年专业课程学习的回顾,索引参见:http://blog.csdn.net/xiaowei_cqu/article/details/7747205
///<summary> ///modify ///使用事务,输入一组必须作为一个单元操作的语句,执行成功返回true,失败则滚回返回false ///</summary> public static bool modifyTrans(string[] sqls) { bool flag = false; SqlConnection sqlConnection = null; SqlTransaction sqlTransaction = null; try { sqlConnection = new SqlConnection(strCon); sqlConnection.Open(); sqlTransaction = sqlConnection.BeginTransaction(); for (int i = 0; i < sqls.Length; i++) { SqlCommand sqlCommand = sqlConnection.CreateCommand(); sqlCommand.CommandText = sqls[i]; sqlCommand.Transaction = sqlTransaction; sqlCommand.ExecuteNonQuery(); } sqlTransaction.Commit(); flag = true; } catch (System.Data.SqlClient.SqlException ex) { sqlTransaction.Rollback(); flag = false; Console.Write("Transaction rolled back\n" + ex.Message); } catch (System.Exception ex) { flag = false; Console.Write("System Error\n" + ex.Message); } finally { if (sqlConnection != null) { if (sqlConnection.State == ConnectionState.Open) sqlConnection.Close(); } } return flag; }
public string getRole(string logName, string logPwd) { string role = "no"; try { if (logName.IndexOf("@") > 0) { string[] sqls1 = new string[] { "select * from Zhuce where LogName=", "select * from Register where rLogName=", "select * from PreRegister where preLogName=", "select * from Consultant where conLoginName=" }; string[] sqls2 = new string[] { " and Pwd=", " and rPwd=", " and prePwd=", " and conPwd=" }; string[] roles = new string[] { "Zhuce", "Register", "PreRegister", "Consultant" }; string[] keys = new string[] { "LogName", "rLogName", "preLogName", "conLoginName" }; int i = 0; while (i < 4)// 分别查询是否是注册者,咨询者,报名者,预报名者 { string table = roles[i]; DataSet ds = new DataSet(); sql = sqls1[i] + "\'" + logName + "\'" + sqls2[i] + "\'" + logPwd + "\'"; ds = DBAccess.searchData(sql, table); string key = keys[i]; ds.Tables[table].PrimaryKey = new DataColumn[] { ds.Tables[table].Columns[key] }; if (ds.Tables[table].Rows.Find(logName) != null) { role = table; return role; } else i = i + 1; } } else { string[] sqls1 = new string[] { "select * from Admin where adminID=", "select * from Teacher where teacherID=", "select * from Student where stuNbr=" }; string[] sqls2 = new string[] { " and adminPwd=", " and teaPwd=", " and stuPwd=" }; string[] roles = new string[] { "Admin", "Teacher", "Student" }; string[] keys = new string[] { "adminID", "teacherID", "stuNbr" }; int i = 0; while (i < 3)// 分别查询是否是管理员,老师,学生 { string table = roles[i]; DataSet ds = new DataSet(); sql = sqls1[i] + "\'" + logName + "\'" + sqls2[i] + "\'" + logPwd + "\'"; ds = DBAccess.searchData(sql, table); string key = keys[i]; ds.Tables[table].PrimaryKey = new DataColumn[] { ds.Tables[table].Columns[key] }; if (ds.Tables[table].Rows.Find(logName) != null) { role = table; return role; } else i = i + 1; } } } catch (Exception ex) { Console.Write(ex.Message); } return role; } public Object getObject(string role, string logName) { RoleManage rm = new RoleManage(); switch (role) { case "Zhuce": Zhuce zc = rm.getZhuce(logName); return zc; case "Consultant": Consultant consultant = rm.getConsultant(role); return consultant; case "PreRegister": PreRegister pregegister = rm.getPreRegister(role); return pregegister; case "Register": Register register = rm.getRegister(role); return register; case "Student": StuManager sm = new StuManager(); Student student = sm.getBaseInfo(logName); return student; case "Teacher": break; case "Admin": break; } return rm; }
protected void imbLogin_Click(object sender, ImageClickEventArgs e) { LogIn log = new LogIn(); string logName = Request.Form["logName"].ToString(); string pwd = Request.Form["logPwd"].ToString(); string role = log.getRole(logName, pwd); if (role != "no") { switch (role) { case "Zhuce": Zhuce zhuce = (Zhuce)log.getObject(role, logName); Session["role"] = role; Session["Zhuce"] = zhuce; Response.Redirect("Member/RegisterPage.aspx"); break; case "Register": Register register = (Register)log.getObject(role, logName); Session["role"] = role; Session["Register"] = register; Response.Redirect("Member/RegisterPage.aspx"); break; case "PreRegister": PreRegister preregister = (PreRegister)log.getObject(role, logName); Session["role"] = role; Session["PreRegister"] = preregister; Response.Redirect("Member/RegisterPage.aspx"); break; case "Consultant": Consultant consultant = (Consultant)log.getObject(role, logName); Session["role"] = role; Session["Consultant"] = consultant; Response.Redirect("Member/RegisterPage.aspx"); break; case "Admin": Adminis admin = (Adminis)log.getObject(role, logName); Session["role"] = role; Session["Admin"] = admin; Response.Redirect("Admin/Adminhome.aspx"); break; case "Teacher": Teacher teacher = (Teacher)log.getObject(role, logName); Session["role"] = role; Session["Teacher"] = teacher; Response.Redirect("Teachers/Teacherhome.aspx"); break; case "Student": Student student = (Student)log.getObject(role, logName); Session["role"] = role; Session["Student"] = student; Response.Redirect("Students/Studenthome.aspx"); break; default: break; } Response.Write("<script>alert('" + role + "欢迎您!')</script>"); } else Response.Write("<script>alert('用户名或密码错误!')</script>"); }
<marquee scrollAmount=2 width=300 height=160 direction=up>欢迎来到德优:<br>请先注册<br>您可以通过邮箱咨询<p><a href="http://www.gdpxedu.com/">点这里进入德优/a></marquee>
using System.Drawing; using System.Drawing.Text; using System.Text; using System.IO; using System.Workflow.ComponentModel.Design; using System.Drawing.Imaging;增加引用集:
C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\ System.Workflow.ComponentModel.dll
private void ValidateCode(string VNum) { int gheight = VNum.Length * 12; using (System.Drawing.Bitmap Img=new System.Drawing.Bitmap(gheight,25)){ using (System.Drawing.Graphics g=System.Drawing.Graphics.FromImage(Img)){ g.Clear(Color.White); Font f = new Font("Arial Black", 10); SolidBrush s = new SolidBrush(Color.Black); g.DrawString(VNum, f, s, 3, 3); MemoryStream ms = new MemoryStream(); Img.Save(ms, ImageFormat.Jpeg); Response.ClearContent(); Response.BinaryWrite(ms.ToArray()); } } Response.End(); } private string RndNum(int VcodeNum) { string Vchar = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"; string[] VcArray = Vchar.Split(new Char[] { ',' }); string VNum = ""; int temp = -1; Random rand = new Random(); for(int i=1;i<VcodeNum+1;i++) { if(temp!=-1) { rand = new Random(i * temp * unchecked((int)DateTime.Now.Ticks)); } int t = rand.Next(35); if(temp!=-1&&temp==t) { return RndNum(VcodeNum); } temp=t; VNum += VcArray[t]; } return VNum; }