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

📄 userservice.asmx.cs

📁 ASP.NET的一些开发实例,有论坛管理系统等
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;

namespace WorkGroupService.user
{
	public class user
	{
		private string username;
		private string password;
		private string station;
		public user()
		{
			username=string.Empty;
			password=string.Empty;
			station="0";
		}

		/// <summary>
		/// 属性:用户名
		/// </summary>
		public string uName
		{
			get
			{
				return username;
			}
			set
			{
				username=value;
			}
		}

		/// <summary>
		/// 属性:密码
		/// </summary>
		public string uPassword
		{
			get
			{
				return password;
			}
			set
			{
				password=value;
			}
		}

		/// <summary>
		/// 属性:密码
		/// </summary>
		public string uStation
		{
			get
			{
				return station;
			}
			set
			{
				station=value;
			}
		}
	}
	/// <summary>
	/// UserService 的摘要说明。
	/// </summary>
	public class UserService : System.Web.Services.WebService
	{
		public UserService()
		{
			//CODEGEN:该调用是 ASP.NET Web 服务设计器所必需的
			InitializeComponent();
		}
		WorkGroupService.BaseService bs=new WorkGroupService.BaseService();
		private System.Data.OleDb.OleDbConnection oleDbConnection1;
		private System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
		private System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
		private System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
		private System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
		private System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
		private WorkGroupService.user.DataSet1 dataSet11;

		#region Component Designer generated code
		
		//Web 服务设计器所必需的
		private IContainer components = null;
				
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
			this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
			this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
			this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
			this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
			this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
			this.dataSet11 = new WorkGroupService.user.DataSet1();
			((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
			// 
			// oleDbConnection1
			// 
			this.oleDbConnection1.ConnectionString = "Provider=MSDAORA.1;Password=acarsgroup;User ID=acarsgroup;Data Source=NOCDB";
			// 
			// oleDbDataAdapter1
			// 
			this.oleDbDataAdapter1.DeleteCommand = this.oleDbDeleteCommand1;
			this.oleDbDataAdapter1.InsertCommand = this.oleDbInsertCommand1;
			this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;
			this.oleDbDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
																										new System.Data.Common.DataTableMapping("Table", "用户表", new System.Data.Common.DataColumnMapping[] {
																																																			   new System.Data.Common.DataColumnMapping("用户名", "用户名"),
																																																			   new System.Data.Common.DataColumnMapping("密码", "密码"),
																																																			   new System.Data.Common.DataColumnMapping("身份", "身份")})});
			this.oleDbDataAdapter1.UpdateCommand = this.oleDbUpdateCommand1;
			// 
			// oleDbSelectCommand1
			// 
			this.oleDbSelectCommand1.CommandText = "SELECT 用户名, 密码, 身份 FROM 用户表";
			this.oleDbSelectCommand1.Connection = this.oleDbConnection1;
			// 
			// oleDbInsertCommand1
			// 
			this.oleDbInsertCommand1.CommandText = "INSERT INTO 用户表(用户名, 密码, 身份) VALUES (?, ?, ?)";
			this.oleDbInsertCommand1.Connection = this.oleDbConnection1;
			this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("用户名", System.Data.OleDb.OleDbType.VarChar, 20, "用户名"));
			this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("密码", System.Data.OleDb.OleDbType.VarChar, 20, "密码"));
			this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("身份", System.Data.OleDb.OleDbType.VarChar, 50, "身份"));
			// 
			// oleDbUpdateCommand1
			// 
			this.oleDbUpdateCommand1.CommandText = "UPDATE 用户表 SET 用户名 = ?, 密码 = ?, 身份 = ? WHERE (用户名 = ?)";
			this.oleDbUpdateCommand1.Connection = this.oleDbConnection1;
			this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("用户名", System.Data.OleDb.OleDbType.VarChar, 20, "用户名"));
			this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("密码", System.Data.OleDb.OleDbType.VarChar, 20, "密码"));
			this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("身份", System.Data.OleDb.OleDbType.VarChar, 50, "身份"));
			this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_用户名", System.Data.OleDb.OleDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "用户名", System.Data.DataRowVersion.Original, null));
			// 
			// oleDbDeleteCommand1
			// 
			this.oleDbDeleteCommand1.CommandText = "DELETE FROM 用户表 WHERE (用户名 = ?)";
			this.oleDbDeleteCommand1.Connection = this.oleDbConnection1;
			this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_用户名", System.Data.OleDb.OleDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "用户名", System.Data.DataRowVersion.Original, null));
			// 
			// dataSet11
			// 
			this.dataSet11.DataSetName = "DataSet1";
			this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
			this.dataSet11.Namespace = "http://www.tempuri.org/DataSet1.xsd";
			((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();

		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if(disposing && components != null)
			{
				components.Dispose();
			}
			base.Dispose(disposing);		
		}
		
		#endregion

		[WebMethod]
		public bool AddUser(WorkGroupService.user.user user)
		{
			try
			{
				this.oleDbConnection1.Open();
				this.oleDbInsertCommand1.Parameters[0].Value=user.uName;
				this.oleDbInsertCommand1.Parameters[1].Value=user.uPassword;
				this.oleDbInsertCommand1.Parameters[2].Value=user.uStation;
				this.oleDbInsertCommand1.ExecuteNonQuery();
				return true;
			}
			catch(Exception e)
			{
				bs.Write("AddUser(WorkGroupService.user.user user)");
				bs.Write(e.Message);
				return false;
			}
			finally
			{
				this.oleDbConnection1.Close();
			}

		}
		

		[WebMethod] 
		public bool DeleteUser(WorkGroupService.user.user user)
		{
			try
			{
				this.oleDbConnection1.Open();
				this.oleDbDeleteCommand1.Parameters[0].Value=user.uName;
				this.oleDbDeleteCommand1.ExecuteNonQuery();
				return true;
			}
			catch(Exception e)
			{
				bs.Write("DeleteUser(WorkGroupService.user.user user)");
				bs.Write(e.Message);
				return false;
			}
			finally
			{
				this.oleDbConnection1.Close();
			}
		}


		[WebMethod]
		public bool ModUser(WorkGroupService.user.user user)
		{
			try
			{
				this.oleDbConnection1.Open();
				this.oleDbUpdateCommand1.Parameters[0].Value=user.uName;
				this.oleDbUpdateCommand1.Parameters[1].Value=user.uPassword;
				this.oleDbUpdateCommand1.Parameters[2].Value=user.uStation;;
				this.oleDbUpdateCommand1.Parameters[3].Value=user.uName;
				this.oleDbUpdateCommand1.ExecuteNonQuery();
				return true;
			}
			catch(Exception e)
			{
				bs.Write("ModTask(WorkGroupService.task task)");
				bs.Write(e.Message);
				return false;
			}
			finally
			{
				this.oleDbConnection1.Close();
			}

		}
		
		[WebMethod]
		public WorkGroupService.user.user GetUser(string[] pks)
		{
			WorkGroupService.user.user GetUser=new WorkGroupService.user.user();
			string sqlwhere=string.Format("用户名='{0}'",pks[0].Trim());
			string sql=this.selectSql(sqlwhere);
			DataSet ds=this.bs.CreateDataSetFromSql(sql);
			if(ds.Tables[0].Rows.Count>0)
			{
				GetUser.uName=ds.Tables[0].Rows[0]["用户名"].ToString();
				GetUser.uPassword=ds.Tables[0].Rows[0]["密码"].ToString();
				GetUser.uStation=ds.Tables[0].Rows[0]["身份"].ToString();
			}
			return GetUser;
		}

		[WebMethod]
		public string selectSql(string sqlwhere)
		{
			if(sqlwhere.Trim()!=string.Empty)
				this.oleDbSelectCommand1.CommandText=string.Format("{0} where {1}",this.oleDbSelectCommand1.CommandText,sqlwhere);
			return this.oleDbSelectCommand1.CommandText;
		}

	}
}

⌨️ 快捷键说明

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