⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usermanagement.cs

📁 本论文叙述了联机考试系统的现状以及C#语言的概况。重点介绍了联机考试系统的实现过程:包括系统分析、 系统调查、 数据流程分析、功能设计、 数据库设计、 系统物理配置方案、 系统实现、 系统测试和调试。
💻 CS
字号:
using System;
using System.Data;
using System.Data.OleDb;
using System.Web;
using System.Web.Mail;

namespace SupermarketProject
{
	/// <summary>
	/// Summary description for UserManagement.
	/// </summary>
	
	public struct stEmployee
	{
		public string UsrId;
		public string Passwd;
		public int PriorityId;
		public string EmpName;
		public bool EmpStatus;
		public string EmailId;

	};

	public class UserManagement
	{
		public UserManagement()
		{}
		
	
	public DataTable FetchEmployeeDetails(string[] searchValue)
	{
		
		string str="";
	
		if(searchValue[0] != "") //Empname is not null
		{
			str="select * from Employees where EmpName like '"+searchValue[0]+ "'";
			if(searchValue[1] != "") // Usrer Id is not null
			{
				str += " and UsrId = '"+searchValue[1]+"'";
				str += " and EmpStatus = "+Convert.ToBoolean(searchValue[2]);
			}
			else
				str += " and EmpStatus = "+Convert.ToBoolean(searchValue[2]);
		}
		else
		{
			if(searchValue[1] != "")
			{
				str="select * from Employees where UsrId = '"+searchValue[1]+ "'";
				str += " and EmpStatus = "+Convert.ToBoolean(searchValue[2]);
			}
			else
			{
					str += " Select * from Employees where EmpStatus = "+Convert.ToBoolean(searchValue[2]);

			}

		}

		//Console.WriteLine(str);
	
		OleDbDataAdapter adapter=new OleDbDataAdapter(str,DataConnection.oleconn);
		DataSet dset=new DataSet("Employees");
		adapter.Fill(dset,"Employees");
		//Console.WriteLine(dset.Tables["Employees"].Rows.Count.ToString());
		return dset.Tables[0]; 
		}

		public void AddEmployee(stEmployee stEmp)
		{
			string str="Insert into Employees values('"+
				stEmp.UsrId+"','"+stEmp.Passwd+"',"+stEmp.PriorityId+",'"+stEmp.EmpName+"',"+stEmp.EmpStatus+",'"+stEmp.EmailId+"');";
			//Console.WriteLine(str);
		
			try
			{
				DataConnection.commnd.CommandText=str;
				DataConnection.commnd.ExecuteNonQuery ();
		
				this.SendMail(stEmp.EmailId,stEmp.UsrId ,stEmp.Passwd);
				Console.WriteLine("新的职工记录已添加");
			}
			catch(OleDbException myException)
			{
				Console.WriteLine(myException.Message);
			}
		}
		public void ModifyEmployee(stEmployee stEmp)
		{
			string str="Update Employees set Passwd ='"+stEmp.Passwd+"', PriorityId ="+stEmp.PriorityId+",EmpName = '"+stEmp.EmpName+"', EmpStatus= "+stEmp.EmpStatus+",EmailId = '"+stEmp.EmailId+"' where Usrid = '"+stEmp.UsrId+"';";
			//Console.WriteLine(str);
			
			try
			{
				DataConnection.commnd.CommandText=str;
				DataConnection.commnd.ExecuteNonQuery();
				
				Console.WriteLine("职工记录已更新");
			}
			catch(OleDbException myException)
			{
				Console.WriteLine(myException.Message);
			}
		}
		public void ModifyPassWord(string newPwd,string UsrId)
		{
			string str="Update Employees set Passwd ='"+newPwd+"'where Usrid ='"+UsrId+"';";
			//Console.WriteLine(str);
			
			try
			{
				DataConnection.commnd.CommandText=str;
				DataConnection.commnd.ExecuteNonQuery();
				
				Console.WriteLine("您的密码已修改");
			}
			catch(OleDbException myException)
			{
				Console.WriteLine(myException.Message);
			}
		}
		public bool Login(string usrid,string password)
		{
			string str;
			int rows = 0;
						
			str="select UsrId,Passwd from Employees where UsrId = '"+usrid+"' and Passwd = '"+password+"'";
			
			
			try
			{
				OleDbDataAdapter adapter=new OleDbDataAdapter(str,DataConnection.oleconn);

				DataSet dset=new DataSet("Employees");
				adapter.Fill(dset,"Employees");
			
				rows = dset.Tables["Employees"].Rows.Count;
			}
			catch(OleDbException myException)
			{
				Console.WriteLine(myException.Message);
			}
			if(rows > 0)
				return true;
			else
				return false;

		}

		public void SendMail(string mail, string id, string pwd)
		{
			Console.WriteLine("sdasd");
			//Replace the SMTP server address with an 
			//appropriate address.
			SmtpMail.SmtpServer ="10.1.1.23";
			MailMessage message=new MailMessage();
			
			//Replace the From address with the required
			//e-mail address
			message.From = "vijayk@aptech.ac.in";
			message.To = mail;
			message.Subject = "登录信息";
			Console.WriteLine(mail);
			
			string info="\n\n恭喜!成功加入系统。\n 以下是您的详细登陆信息:\n 用户名: " + id + "\n 密码: " + pwd;
			message.Body =info;
			
			try
			{
				SmtpMail.Send(message);
                System.Windows.Forms.MessageBox.Show("电子邮件地址");				
			}
			catch (HttpException InvAddr)
			{
				System.Windows.Forms.MessageBox.Show(InvAddr.Message);
			}

		}


	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -