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

📄 com_forumreply.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;
using System.Data.SqlClient;

namespace WhiteForumServer.forum
{
	/// <summary>
	/// COM_ForumReply 的摘要说明。
	/// </summary>
	public class COM_ForumReply : System.Web.Services.WebService
	{
		protected ERPWebService.sysbase.COM_BASE COM_BASE = new ERPWebService.sysbase.COM_BASE();
		protected ERPWebService.sysbase.COMSoft COMSoft = new ERPWebService.sysbase.COMSoft();
		protected WhiteForumServer.BdStudioSoft.COMInterface COMInterface=new WhiteForumServer.BdStudioSoft.COMInterface();
		protected WhiteForumServer.BdStudioSoft.Gfunction  Gfunction = new WhiteForumServer.BdStudioSoft.Gfunction();
		protected ERPWebService.BdStudio.COM_SystemAccount COM_SystemAccoun = new ERPWebService.BdStudio.COM_SystemAccount();
		protected WhiteForumServer.forum.COM_ForumTopics COM_ForumTopics = new WhiteForumServer.forum.COM_ForumTopics();
		protected SqlConnection SqlConn;

		public COM_ForumReply()
		{
			//CODEGEN:该调用是 ASP.NET Web 服务设计器所必需的
			InitializeComponent();
		}

		#region Component Designer generated code
		
		//Web 服务设计器所必需的
		private IContainer components = null;
				
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.SqlConn = new SqlConnection((string)Application["db_connstring"]);
		}

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

		// WEB 服务示例
		// HelloWorld() 示例服务返回字符串 Hello World
		// 若要生成,请取消注释下列行,然后保存并生成项目
		// 若要测试此 Web 服务,请按 F5 键

//		[WebMethod]
//		public string HelloWorld()
//		{
//			return "Hello World";
//		}

		[WebMethod]
		public DataSet DsMainFieldListForAll(string m_num,string interFace,string TopicID)
		{
			DataSet ds = new DataSet();
			//string strSql = string.Format(" select * from forum_reply where topic_id = {0} order by reply_id DESC",TopicId);
			string strwhere="topic_id="+TopicID;
			string strsql = string.Format("{1} where {0} order by reply_id DESC",strwhere,this.COMInterface.CreateSqlFromInterface(m_num,interFace));
			ds = this.COM_BASE.CreateDataSetFromSql(strsql);
			return ds;
		}

		[WebMethod]
		public DataSet DsSelectSingleData(string[] str_FieldValue,string SearchType,ref string sReturn)//string[] str_FieldValue,string SearchType,ref string sReturn
		{
			string[] str_FieldName = {"reply_id"};
			string[] str_FieldType = {"int"};
			string[] str_SearchType ={"="};
			DataSet ds = new DataSet();
			string str_Sql = this.COMInterface.CreateSqlFromInterface(str_FieldValue[0],str_FieldValue[1]);
			string[] FieldValue = {str_FieldValue[2]};
			string strWhere = this.COM_BASE.CreateSqlString(FieldValue,str_FieldName,str_SearchType,str_FieldType);
			string str_Sql1 = string.Format("select max(reply_id) as reply_id from forum_reply where reply_id<'"+str_FieldValue[0]+"'");//取上一条数据
			string str_Sql2 = string.Format("select min(reply_id) as reply_id from forum_reply where reply_id>'"+str_FieldValue[0]+"'");//取下一条数据
			switch (SearchType)
			{
				case "0":
					str_Sql = string.Format(" {0} where {1} order by reply_id DESC ",str_Sql,strWhere);
					ds = this.COM_BASE.CreateDataSetFromSql(str_Sql);
					sReturn = string.Empty;
					break;
				case "1":
					DataSet dsPrev = this.COM_BASE.CreateDataSetFromSql(str_Sql1);
					if(dsPrev.Tables[0].Rows.Count==0)
					{
						sReturn = "没有上一条!";
					}
					else
					{
						foreach(DataRow row in dsPrev.Tables[0].Rows)
						{
							str_FieldValue[0]=row["reply_id"].ToString();
						}
						strWhere = this.COM_BASE.CreateSqlString(str_FieldValue,str_FieldName,str_SearchType,str_FieldType);
						str_Sql = string.Format(" {0} where {1} ",str_Sql,strWhere);
						ds = this.COM_BASE.CreateDataSetFromSql(str_Sql);
						sReturn = string.Empty;
					}
					break;
				case "2":
					DataSet dsNext = this.COM_BASE.CreateDataSetFromSql(str_Sql2);
					if(dsNext.Tables[0].Rows.Count==0)
					{
						sReturn = "没有下一条!";
					}
					else
					{
						foreach(DataRow row in dsNext.Tables[0].Rows)
						{
							str_FieldValue[0]=row["reply_id"].ToString();
						}
						strWhere = this.COM_BASE.CreateSqlString(str_FieldValue,str_FieldName,str_SearchType,str_FieldType);
						str_Sql = string.Format(" {0} where {1} ",str_Sql,strWhere);
						ds = this.COM_BASE.CreateDataSetFromSql(str_Sql);
						sReturn = string.Empty;
					}
					break;
			}						
			return ds;
		}


		[WebMethod]
		public void InsertData(DataSet ds,string InsertType,ref string sReturn)
		{
			SqlCommand mySqlCommand = new SqlCommand();
			SqlTransaction myTrans;
			string SqlString = string.Empty;

			this.SqlConn.Open();//启动连接
			myTrans = this.SqlConn.BeginTransaction();//建立事务
			mySqlCommand.Connection = this.SqlConn;//建立sql命令连接
			mySqlCommand.Transaction = myTrans;//绑定事务

			string str_TableName = "forum_reply";
			string str_reply_id = string.Empty;
			DataTable dt = ds.Tables[0];
			string r_author = string.Empty;
			string strDate = string.Empty;
			string topic_id =string.Empty;

			int nErr=0;

			foreach(DataRow row in ds.Tables[0].Rows)
			{
				if(row["reply_id"].ToString()=="自动增长")
				{
//					row[0]=this.COMSoft.GetMaxnum(str_TableName,ref mySqlCommand,ref SqlConn,ref myTrans);
//					str_reply_id = row[0].ToString();
					ds.Tables[0].Columns.Remove("reply_id");
					strDate = this.Gfunction.DataTimeValue(0,2);
					row["r_date"] = strDate;
					r_author = row["r_author"].ToString();
					topic_id = row["topic_id"].ToString();
				}
			}

			if(str_reply_id=="NumError")
			{
				nErr = 1;
			}

			if(nErr!=1)
			{
				try
				{
					nErr= this.COM_BASE.InsertTableBase(ref mySqlCommand,ref SqlConn,ref myTrans,str_TableName,dt,ref SqlString);
				}
				catch (Exception e)
				{
					nErr = 1;
				}
			}
		
			if (nErr == 1)
			{
				sReturn =  "增加失败";
				if(str_reply_id=="NumError")
				{
					sReturn+="(序号生成失败)";
				}
				else
				{
					sReturn+="(数据表插入失败)";
				}
			}
			else 
			{
				myTrans.Commit();
				this.SqlConn.Close();
				if(r_author.Trim() != string.Empty)
				{
					string strsql = string.Format("select * from system_account where acc_name = '{0}'",r_author);
					DataSet dsAcc = this.COMInterface.CreateDataSetFromSql(strsql);
					foreach(DataRow dr in dsAcc.Tables[0].Rows)
					{
						if(dr["t_reply_count"].ToString().Trim() == string.Empty  || dr["t_reply_count"].ToString().Trim() == null)
						{
							dr["t_reply_count"] = 1;
						}
						else if (dr["t_reply_count"].ToString().Trim() != string.Empty  && dr["t_reply_count"].ToString().Trim() != null)
						{
							int topiccount = int.Parse(dr["t_reply_count"].ToString().Trim());
							dr["t_reply_count"] = topiccount +1;
						}
						
					}
					this.COM_SystemAccoun.EditData(dsAcc,"0",ref sReturn);
				}
				if(topic_id.Trim() != string.Empty)
				{
					string strsql = string.Format("select * from forum_topics where topic_id = {0}",topic_id);
					DataSet dsAcc = this.COMInterface.CreateDataSetFromSql(strsql);
					foreach(DataRow dr in dsAcc.Tables[0].Rows)
					{
						dr["t_last_post"] = strDate;
						dr["t_last_author"] = r_author;
						if(dr["t_reply_count"].ToString().Trim() == string.Empty  || dr["t_reply_count"].ToString().Trim() == null)
						{
							dr["t_reply_count"] = 1;
						}
						else if (dr["t_reply_count"].ToString().Trim() != string.Empty  && dr["t_reply_count"].ToString().Trim() != null)
						{
							int topiccount = int.Parse(dr["t_reply_count"].ToString().Trim());
							dr["t_reply_count"] = topiccount +1;
						}						
					}
					this.COM_ForumTopics.EditData(dsAcc,"0",ref sReturn);
				}
				switch (InsertType)
				{
					case "0":
						sReturn = "增加成功";
						break;
					case "1":
						string strSql = string.Format("select reply_id from forum_reply ");
						str_reply_id = this.COM_BASE.GetID(strSql);
						sReturn = str_reply_id;
						break;
				}
			}
		}

		[WebMethod]
		public void EditData(DataSet ds,string EditType,ref string sReturn)
		{
			SqlCommand mySqlCommand = new SqlCommand();
			SqlTransaction myTrans;
			string SqlString = string.Empty;

			this.SqlConn.Open();//启动连接
			myTrans = this.SqlConn.BeginTransaction();//建立事务
			mySqlCommand.Connection = this.SqlConn;//建立sql命令连接
			mySqlCommand.Transaction = myTrans;//绑定事务

			string str_TableName = "forum_reply";
			string s_pk = "reply_id";
			DataTable dt = ds.Tables[0];
			string str_reply_id = string.Empty;
			int nErr;
			try
			{
				str_reply_id = dt.Rows[0]["reply_id"].ToString();
				nErr = this.COM_BASE.UpdateTableBase(ref mySqlCommand,ref SqlConn,ref myTrans,str_TableName,dt,ref SqlString,ref s_pk);
				
			}
			catch (Exception e)
			{
				nErr = 1;
			}
			
			if (nErr == 1)
			{
				sReturn = "修改失败";
			}
			else 
			{
				switch (EditType)
				{
					case "0":
						sReturn = "修改成功";
						break;
					case "1":
						sReturn = str_reply_id;
						break;
				}
				
			}
			if(nErr !=1)
			{
				myTrans.Commit();
				this.SqlConn.Close();
			}
			
		}

		[WebMethod]
		public void DeleteData(string WhereString,ref string sReturn)
		{
			SqlCommand mySqlCommand = new SqlCommand();
			SqlTransaction myTrans;
			string SqlString = WhereString;

			this.SqlConn.Open();//启动连接
			myTrans = this.SqlConn.BeginTransaction();//建立事务
			mySqlCommand.Connection = this.SqlConn;//建立sql命令连接
			mySqlCommand.Transaction = myTrans;//绑定事务

			string str_TableName = "forum_reply";
			int nErr = this.COM_BASE.DeleteTableBase(ref mySqlCommand,ref SqlConn,ref myTrans,str_TableName,ref SqlString);
			if (nErr == 1)
			{
				sReturn = "删除失败";
			}
			else
			{
				sReturn = "删除成功";
			}
			if(nErr !=1)
			{
				myTrans.Commit();
				this.SqlConn.Close();
			}
		}

		[WebMethod]
		public void EditViewEmp(string topic_id,string accname)
		{
			string strsql = string.Format("select reply_id,view_emp from forum_reply where topic_id ='{0}'",topic_id);
			DataSet ds = this.COM_BASE.CreateDataSetFromSql(strsql);
			if(ds.Tables[0].Rows.Count>0)
			{
				string sViewEmp="";
				foreach(DataRow row in ds.Tables[0].Rows)
				{
					sViewEmp=row["view_emp"].ToString();
					if(sViewEmp.IndexOf("["+accname+"]")==-1)
					{
						sViewEmp+=",["+accname+"]";
						strsql="update forum_reply set view_emp='"+sViewEmp+"' where reply_id="+row["reply_id"].ToString();
						SqlCommand mySqlCommand = new SqlCommand();
						SqlTransaction myTrans;

						this.SqlConn.Open();//启动连接
						myTrans = this.SqlConn.BeginTransaction();//建立事务
						mySqlCommand.Connection = this.SqlConn;//建立sql命令连接
						mySqlCommand.Transaction = myTrans;//绑定事务

						int nErr=0;

						try
						{
							nErr= this.COM_BASE.UpdateTableBaseFromSQL(ref mySqlCommand,ref SqlConn,ref myTrans,strsql);
						}
						catch (Exception e)
						{
							nErr = 1;
						}
		
						if (nErr == 1)
						{
							//sReturn =  "修改浏览人失败";
						}
						else 
						{
							myTrans.Commit();
							this.SqlConn.Close();
							//sReturn = "增加成功";
							//break;
						}
					}
				}
				
			}
			
		}
	}
}

⌨️ 快捷键说明

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