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

📄 webservice.cs

📁 一个采用VS2008+Sql2000开发的任务管理系统
💻 CS
📖 第 1 页 / 共 3 页
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Security.Cryptography;
using System.Text;
using System.IO;
//该源码下载自www.51aspx.com(51aspx.com)
namespace BronzeMonkey.GeneralTaskList
{
	/// <summary>
	/// Defines what task list we show when first logging in
	/// </summary>
	public enum StartupViewOptionEnum { LastTaskList = 0, SpecificTaskList = 1 }

	/// <summary>
	/// Contains information about the current user
	/// </summary>
	public class UserInformation
	{
		public string Username;
		public string PasswordHash;
		public int UserID;
		public bool IsManager;
		public bool IsAdministrator;
    public bool ShouldNotify;
    public int NotifyPeriod;

		public UserInformation()
		{
			this.UserID = 0;
			this.Username = "";
			this.PasswordHash = "";
			this.IsManager = false;
			this.IsAdministrator = false;
      this.ShouldNotify = false;
      this.NotifyPeriod = 24;
		}

		public UserInformation(int UserID, string Username, string PasswordHash)
		{
			this.UserID = UserID;
			this.Username = Username;
			this.PasswordHash = PasswordHash;
			this.IsManager = false;
			this.IsAdministrator = false;
      this.ShouldNotify = false;
      this.NotifyPeriod = 24;
		}
		
		public UserInformation(int UserID, string Username, string PasswordHash, bool IsManager, bool IsAdministrator)
		{
			this.UserID = UserID;
			this.Username = Username;
			this.PasswordHash = PasswordHash;
			this.IsManager = IsManager;
			this.IsAdministrator = IsAdministrator;
      this.ShouldNotify = false;
      this.NotifyPeriod = 24;
		}

		public override string ToString()
		{
			return this.Username;
		}
	}

	/// <summary>
	/// The definition of a task list item, including subject, body, etc..
	/// </summary>
	public class TaskListItem
	{
		public string Subject;
		public string Body;
		public string CreatedBy;
		public string StatusName;
		public int OwnerUserID;
		public int TaskListID;
		public DateTime CreatedDate;
		public DateTime ModifiedDate;
		public int ID;
		public int StatusValue;
		public int CategoryID;

		public TaskListItem()
		{
			CreatedDate = DateTime.Now;
			ModifiedDate = DateTime.Now;
			this.StatusValue = 0; // 0 = Open
		}

		public TaskListItem(int ID)
		{
			this.ID = ID;
			CreatedDate = DateTime.Now;
			ModifiedDate = DateTime.Now;
			this.StatusValue = 0; // 0 = Open
		}
	}


	/// <summary>
	/// Summary description for TaskList
	/// </summary>
	public class TaskList
	{
		private readonly string ConnectionString;

		public TaskList()
		{
			this.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnString"]; // ;
		}

		/// <summary>
		/// Returns a password hash code
		/// </summary>
		public string GetPasswordHash(string Password)
		{
			System.Security.Cryptography.MD5CryptoServiceProvider Provider = new MD5CryptoServiceProvider();

			//Convert the string into an array of bytes.
			byte[] HashBytes = System.Text.Encoding.UTF8.GetBytes(Password);

			// Hash the password
			byte[] Result = Provider.ComputeHash(HashBytes);
			
			// Convert the byte array to a hex string, so that our result matches that provided by
			// FormsAuthentication.HashPasswordForStoringInConfigFile(...);
			string ResultString = String.Empty;
			for(int i = 0; i< Result.Length; i++) 
			{
				ResultString += String.Format("{0,2:X2}", Result[i]);
			} 

			return ResultString;
		}

		/// <summary>
		/// Returns a userid or zero if not valid
		/// </summary>
		public int LogUserIn(string Username, string PasswordHash)
		{
			SqlConnection cn = new SqlConnection(this.ConnectionString);
			SqlCommand Command = new SqlCommand("TaskList_LogUserIn", cn);
			Command.CommandType = CommandType.StoredProcedure;

			Command.Connection.Open();

			Command.Parameters.Add("@Username", SqlDbType.VarChar, 20).Value = Username.ToLower();
			Command.Parameters.Add("@PasswordHash", SqlDbType.VarChar, 50).Value = PasswordHash;

			SqlDataReader dr = Command.ExecuteReader();
			try
			{
				while (dr.Read())
				{
					return Convert.ToInt32(dr[0].ToString());
				}
				return 0;
			}
			catch
			{
				return 0;
			}
		}

		public int LogUserInFromCookie(string Username)
		{
			SqlCommand Command = new SqlCommand("TaskList_LogUserInFromCookie", new SqlConnection(this.ConnectionString));
			Command.CommandType = CommandType.StoredProcedure;

			Command.Parameters.Add("@Username", SqlDbType.VarChar, 20).Value = Username.ToLower();
			Command.Connection.Open();

			SqlDataReader dr = Command.ExecuteReader();
			try
			{
				while (dr.Read())
				{
					return Convert.ToInt32(dr[0].ToString());
				}

				return 0;
			}
			catch
			{
				return 0;
			}
		}

		/// <summary>
		/// Creates a new task list
		/// </summary>
		public void CreateTaskList(UserInformation ui, string Name)
		{
			SqlConnection cn = new SqlConnection(this.ConnectionString);
			SqlCommand Command = new SqlCommand("TaskList_CreateTaskList", cn);
			Command.CommandType = CommandType.StoredProcedure;

			Command.Connection.Open();

			Command.Parameters.Add("@Username", SqlDbType.VarChar, 20).Value = ui.Username;
			Command.Parameters.Add("@PasswordHash", SqlDbType.VarChar, 50).Value = ui.PasswordHash;
			Command.Parameters.Add("@TaskListName", SqlDbType.VarChar, 255).Value = Name;

			Command.ExecuteNonQuery();

			Command.Connection.Close();
			Command.Dispose();
			cn.Dispose();
		}


		public void RenameTaskList(UserInformation CurrentUser, int TaskListID, string NewName)
		{
			SqlConnection cn = new SqlConnection(this.ConnectionString);
			SqlCommand Command = new SqlCommand("TaskList_RenameTaskList", cn); 
			Command.CommandType = CommandType.StoredProcedure;

			Command.Connection.Open();

			Command.Parameters.Add("@Username", SqlDbType.VarChar, 20).Value = CurrentUser.Username;
			Command.Parameters.Add("@PasswordHash", SqlDbType.VarChar, 50).Value = CurrentUser.PasswordHash;
			Command.Parameters.Add("@TaskListID", SqlDbType.BigInt).Value = TaskListID;
			Command.Parameters.Add("@NewName", SqlDbType.VarChar, 255).Value = NewName;

			Command.ExecuteNonQuery();

			Command.Connection.Close();
			Command.Dispose();
			cn.Dispose();
		}

		/// <summary>
		/// Removes a task list
		/// </summary>
		public void DeleteTaskList(UserInformation ui, int TaskListID)
		{
			SqlConnection cn = new SqlConnection(this.ConnectionString);
			SqlCommand Command = new SqlCommand("TaskList_DeleteTaskList", cn);
			Command.CommandType = CommandType.StoredProcedure;

			Command.Connection.Open();

			Command.Parameters.Add("@Username", SqlDbType.VarChar, 20).Value = ui.Username;
			Command.Parameters.Add("@PasswordHash", SqlDbType.VarChar, 50).Value = ui.PasswordHash;
			Command.Parameters.Add("@TaskListID", SqlDbType.BigInt).Value = TaskListID;

			Command.ExecuteNonQuery();

			Command.Connection.Close();
			Command.Dispose();
			cn.Dispose();
		}

		/// <summary>
		/// Retrieves the task lists that this user is assigned to.
		/// </summary>
		public SqlDataReader GetUserTaskLists(UserInformation ui, int UserToLookUpID)
		{
			SqlConnection cn = new SqlConnection(this.ConnectionString);
			SqlCommand Command = new SqlCommand("TaskList_GetUserTaskLists", cn);
			Command.CommandType = CommandType.StoredProcedure;

			Command.Connection.Open();

			Command.Parameters.Add("@Username", SqlDbType.VarChar, 20).Value = ui.Username;
			Command.Parameters.Add("@PasswordHash", SqlDbType.VarChar, 50).Value = ui.PasswordHash;
			Command.Parameters.Add("@UserToLookUpID", SqlDbType.BigInt).Value = UserToLookUpID;
			
			SqlDataReader dr = Command.ExecuteReader(CommandBehavior.CloseConnection);

			return dr;
		}

		/// <summary>
		/// Adds a new user to the Task List application
		/// </summary>
		public void AddUser(UserInformation CurrentUser, UserInformation NewUser)
		{
			SqlConnection cn = new SqlConnection(this.ConnectionString);
			SqlCommand Command = new SqlCommand("TaskList_AddUser", cn);
			Command.CommandType = CommandType.StoredProcedure;

			Command.Connection.Open();

			Command.Parameters.Add("@Username", SqlDbType.VarChar, 20).Value = CurrentUser.Username.ToLower();
			Command.Parameters.Add("@PasswordHash", SqlDbType.VarChar, 50).Value = CurrentUser.PasswordHash;
			Command.Parameters.Add("@NewUserName", SqlDbType.VarChar, 20).Value = NewUser.Username.ToLower();
			Command.Parameters.Add("@NewPasswordHash", SqlDbType.VarChar, 50).Value = NewUser.PasswordHash;
			Command.Parameters.Add("@IsManager", SqlDbType.Bit).Value = NewUser.IsManager;
			Command.Parameters.Add("@IsAdministrator", SqlDbType.Bit).Value = NewUser.IsAdministrator;

			Command.ExecuteNonQuery();

			Command.Connection.Close();

			Command.Dispose();
			cn.Dispose();
		}

		/// <summary>
		/// Modifies a Task List user
		/// </summary>
		public void ModifyUser(UserInformation CurrentUser, UserInformation OldUser, UserInformation NewUser)
		{
			SqlConnection cn = new SqlConnection(this.ConnectionString);
			SqlCommand Command = new SqlCommand("TaskList_ModifyUser", cn);
			Command.CommandType = CommandType.StoredProcedure;

			Command.Connection.Open();

			Command.Parameters.Add("@Username", SqlDbType.VarChar, 20).Value = CurrentUser.Username;
			Command.Parameters.Add("@PasswordHash", SqlDbType.VarChar, 50).Value = CurrentUser.PasswordHash;
			Command.Parameters.Add("@OldUserName", SqlDbType.VarChar, 20).Value = OldUser.Username;
			Command.Parameters.Add("@NewUserName", SqlDbType.VarChar, 20).Value = NewUser.Username;
			Command.Parameters.Add("@OldPasswordHash", SqlDbType.VarChar, 50).Value = OldUser.PasswordHash;
			Command.Parameters.Add("@NewPasswordHash", SqlDbType.VarChar, 50).Value = NewUser.PasswordHash;
			Command.Parameters.Add("@IsManager", SqlDbType.Bit).Value = NewUser.IsManager;
			Command.Parameters.Add("@IsAdministrator", SqlDbType.Bit).Value = NewUser.IsAdministrator;

			Command.ExecuteNonQuery();

			Command.Connection.Close();
			Command.Dispose();
			cn.Dispose();
		}

		/// <summary>
		/// Deletes a Task List user
		/// </summary>
		public void DeleteUser(UserInformation CurrentUser, UserInformation UserToDelete)
		{
			SqlConnection cn = new SqlConnection(this.ConnectionString);
			SqlCommand Command = new SqlCommand("TaskList_DeleteUser", cn);
			Command.CommandType = CommandType.StoredProcedure;

			Command.Connection.Open();

			Command.Parameters.Add("@Username", SqlDbType.VarChar, 20).Value = CurrentUser.Username;
			Command.Parameters.Add("@PasswordHash", SqlDbType.VarChar, 50).Value = CurrentUser.PasswordHash;
			Command.Parameters.Add("@UserIDToDelete", SqlDbType.BigInt).Value = UserToDelete.UserID;

⌨️ 快捷键说明

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