📄 com_forumtopics.asmx.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_ForumTopics 的摘要说明。
/// </summary>
public class COM_ForumTopics : 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_ForumForum COM_ForumForum = new WhiteForumServer.forum.COM_ForumForum();
protected SqlConnection SqlConn;
public COM_ForumTopics()
{
//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
[WebMethod]
public DataSet DsMainListForAll(string[] strFieldValue)
{
DataSet ds;
string[] FieldName = {"forum_id","t_status","t_level"};
string[] FieldType = {"string","string","string"};
string[] SearchType = {"=","=","="};
string strWhere = string.Empty;
string strSql = string.Empty;
if(strFieldValue.Length>2)
{
string[] FieldValue = {strFieldValue[2],strFieldValue[3],strFieldValue[4]};
strWhere = this.COM_BASE.CreateSqlString(FieldValue,FieldName,SearchType,FieldType);
}
strSql = this.COMInterface.CreateSqlFromInterface(strFieldValue[0],strFieldValue[1]);
if (strWhere.Trim() != string.Empty && strWhere != null )
{
strSql = string.Format(" {0} where {1} order by topic_id DESC",strSql,strWhere);
}
else if (strWhere.Trim() == string.Empty)
{
strSql = string.Format(" {0} order by topic_id DESC",strSql);
}
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 = {"topic_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(topic_id) as topic_id from forum_topics where topic_id<'"+str_FieldValue[0]+"'");//取上一条数据
string str_Sql2 = string.Format("select min(topic_id) as topic_id from forum_topics where topic_id>'"+str_FieldValue[0]+"'");//取下一条数据
switch (SearchType)
{
case "0":
str_Sql = string.Format(" {0} where {1} order by topic_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["topic_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["topic_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_topics";
string str_topic_id = string.Empty;
DataTable dt = ds.Tables[0];
string strDate = string.Empty;
string t_author = string.Empty;
string forum_id = string.Empty;
int nErr=0;
foreach(DataRow row in ds.Tables[0].Rows)
{
if(row["topic_id"].ToString()=="自动增长")
{
//row[0]=this.COMSoft.GetMaxnum(str_TableName,ref mySqlCommand,ref SqlConn,ref myTrans);
ds.Tables[0].Columns.Remove("topic_id");
}
strDate = this.Gfunction.DataTimeValue(0,2);
row["t_date"] = strDate;
t_author = row["t_author"].ToString();
forum_id = row["forum_id"].ToString();
}
if(str_topic_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_topic_id=="NumError")
{
sReturn+="(序号生成失败)";
}
else
{
sReturn+="(数据表插入失败)";
}
}
else
{
myTrans.Commit();
this.SqlConn.Close();
if(t_author.Trim() != string.Empty)
{
string strsql = string.Format("select * from system_account where acc_name = '{0}'",t_author);
DataSet dsAcc = this.COMInterface.CreateDataSetFromSql(strsql);
foreach(DataRow dr in dsAcc.Tables[0].Rows)
{
dr["t_last_post"] = strDate;
if(dr["t_topic_count"].ToString().Trim() == string.Empty || dr["t_topic_count"].ToString().Trim() == null)
{
dr["t_topic_count"] = 1;
}
else if (dr["t_topic_count"].ToString().Trim() != string.Empty && dr["t_topic_count"].ToString().Trim() != null)
{
int topiccount = int.Parse(dr["t_topic_count"].ToString().Trim());
dr["t_topic_count"] = topiccount +1;
}
}
this.COM_SystemAccoun.EditData(dsAcc,"0",ref sReturn);
}
if(forum_id.Trim() != string.Empty)
{
string[] FieldValue = {"79","dbGridMain1",forum_id};
DataSet dsForum = this.COM_ForumForum.DsSelectSingleData(FieldValue,"0",ref sReturn);
foreach(DataRow dr in dsForum.Tables[0].Rows)
{
dr["f_last_post"] = strDate;
dr["f_last_author"] = t_author;
if(dr["f_topic_count"].ToString().Trim() == string.Empty || dr["f_topic_count"].ToString().Trim() == null)
{
dr["f_topic_count"] = 1;
}
else if (dr["f_topic_count"].ToString().Trim() != string.Empty && dr["f_topic_count"].ToString().Trim() != null)
{
int topiccount = int.Parse(dr["f_topic_count"].ToString().Trim());
dr["f_topic_count"] = topiccount +1;
}
}
this.COM_ForumForum.EditData(dsForum,"0",ref sReturn);
}
switch (InsertType)
{
case "0":
sReturn = "增加成功";
break;
case "1":
string strSql = string.Format("select topic_id from forum_topics ");
str_topic_id = this.COM_BASE.GetID(strSql);
sReturn = str_topic_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_topics";
string s_pk = "topic_id";
DataTable dt = ds.Tables[0];
string str_topic_id = string.Empty;
int nErr;
try
{
str_topic_id = dt.Rows[0]["topic_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_topic_id;
break;
}
}
if(nErr !=1)
{
myTrans.Commit();
this.SqlConn.Close();
}
}
[WebMethod]
public void DeleteData(string TopicId,ref string sReturn)
{
SqlCommand mySqlCommand = new SqlCommand();
SqlTransaction myTrans;
string SqlString = string.Format(" topic_id = {0}",TopicId);
string SqlString1 = string.Format(" topic_id = {0}",TopicId);
this.SqlConn.Open();//启动连接
myTrans = this.SqlConn.BeginTransaction();//建立事务
mySqlCommand.Connection = this.SqlConn;//建立sql命令连接
mySqlCommand.Transaction = myTrans;//绑定事务
string str_TableNameMain = "forum_topics";
string str_TableNameDetail = "forum_reply";
int nErrMain = this.COM_BASE.DeleteTableBase(ref mySqlCommand,ref SqlConn,ref myTrans,str_TableNameMain,ref SqlString);
int nErrDetail = this.COM_BASE.DeleteTableBase(ref mySqlCommand,ref SqlConn,ref myTrans,str_TableNameDetail,ref SqlString1);
int nErr = nErrMain + nErrDetail;
if (nErr != 0)
{
sReturn = "删除失败";
}
else
{
sReturn = "删除成功";
}
if(nErr == 0)
{
myTrans.Commit();
this.SqlConn.Close();
}
}
[WebMethod]
public void EditViewCount(string topic_id,string accname)
{
string sReturn = string.Empty;
if(topic_id.Trim() != string.Empty)
{
string SqlString="select topic_id,limit_count,t_view_count,limit_viewemp from forum_topics where topic_id="+topic_id;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -