📄 baseservice.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.IO;
using System.Data.OleDb;
namespace WorkGroupService
{
/// <summary>
/// BaseService 的摘要说明。
/// </summary>
public class BaseService : System.Web.Services.WebService
{
//错误信息记录的文件路径
protected string FilePath=@"c:\LogFile.txt";
private System.Data.OleDb.OleDbCommand oleDbCommand1;
protected OleDbDataAdapter OleDbAd;
public BaseService()
{
//CODEGEN:该调用是 ASP.NET Web 服务设计器所必需的
InitializeComponent();
}
private System.Data.OleDb.OleDbConnection oleDbConnection1;
#region Component Designer generated code
//Web 服务设计器所必需的
private IContainer components = null;
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
this.oleDbCommand1 = new System.Data.OleDb.OleDbCommand();
//
// oleDbConnection1
//
this.oleDbConnection1.ConnectionString = "Provider=MSDAORA.1;Password=acarsgroup;User ID=acarsgroup;Data Source=NOCDB";
//
// oleDbCommand1
//
this.oleDbCommand1.Connection = this.oleDbConnection1;
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
/// <summary>
/// 根据SQL语句填充DataSet
/// </summary>
[WebMethod]
public DataSet CreateDataSetFromSql(string sql)
{
DataSet ds = new DataSet();
try
{
this.OleDbAd = new OleDbDataAdapter(sql,this.oleDbConnection1);
this.OleDbAd.Fill(ds);
}
catch(Exception e)
{
this.Write("public DataSet CreateDataSetFromSql(string sql)");
this.Write("错误信息!");
this.Write(e.Message);
}
return ds;
}
/// <summary>
/// 往文件c:\LogFile.txt写入错误信息
/// </summary>
[WebMethod]
public void Write(string strErr)
{
string strOld;
try
{
System.IO.FileInfo file=new System.IO.FileInfo(this.FilePath);
if(!file.Exists)
System.IO.File.Create(this.FilePath).Close();
// using(System.IO.File.Create(this.FilePath))
// {}
using(StreamReader sr=File.OpenText(this.FilePath))
{
strOld=sr.ReadToEnd();
}
Stream stream=File.OpenWrite(this.FilePath);
using (StreamWriter sw=new StreamWriter(stream))
{
if(strOld==string.Empty)
{
sw.Write(System.DateTime.Now.ToString());
sw.Write("\r\n"+strErr);
}
else
{
sw.Write(strOld);
sw.Write("\r\n"+"\r\n"+System.DateTime.Now.ToString());
sw.Write("\r\n"+strErr);
}
}
}
catch(Exception ex)
{
string str=ex.Message;
}
}
[WebMethod]
public string sqlorder(string[] OrderType)
{
string sqlorder=string.Empty;
if(OrderType.Length==2)
{
if(OrderType[0].Trim()=="0")
{
sqlorder=string.Format("Order by {0}",OrderType[1].Trim());
}
else if(OrderType[1].Trim()=="1")
{
sqlorder=string.Format("Order by {0} DESC",OrderType[1].Trim());
}
}
return sqlorder;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -