?? dataservice.cs
字號:
?using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.OleDb;
using kmdsoft.Database;
using kmdsoft.Security;
using kmdsoft.Web.Services;
using System.IO;
namespace kmdsoft.Services
{
[WebService(Namespace = "http://www.kmdsoft.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class DataService : System.Web.Services.WebService
{
//WebService身份驗證的SOAP頭的實例
public AuthenticationHeader Authentication;
public DataService()
{
String strConn = System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString");
WriteLog(strConn);
}
private void WriteLog(string strLog)
{
//實例化一個文件流--->與寫入文件相關聯
string sfile = "c:\\database.txt";
FileStream fs = new FileStream(sfile, FileMode.Create);
//實例化一個StreamWriter-->與fs相關聯
StreamWriter sw = new StreamWriter(fs);
//開始寫入
sw.Write(strLog);
//清空緩沖區
sw.Flush();
//關閉流
sw.Close();
fs.Close();
}
#region 鄧資華
#region 身份驗證處理
[WebMethod(MessageName = "AuthenticateByAuthenticationHeader")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public bool Authenticate()
{
//Context.Request.SaveAs("D:\\soapInfo.txt", true);
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
return this.AuthenticateUser(Authentication.UserName, Authentication.Password);
}
[WebMethod(Description="身份認證服務。")]
public bool AuthenticateUser(String account, String password)
{
try {
if (account == null || account.Trim().Length == 0)
throw new ArgumentNullException("Account");
if (password == null || password.Trim().Length == 0)
throw new ArgumentNullException("Password");
OleDbConnection conn = DataEngine.getConn();
if (conn==null)
throw new AuthenticationException(AuthenticationReason.Unknown);
IDbCommand command = conn.CreateCommand();
command.CommandText = "SELECT account,userpassword FROM user_quar WHERE account = '" + account + "'";
command.Connection.Open();
IDataReader reader = command.ExecuteReader();
if (!reader.Read())
throw new AuthenticationException(AuthenticationReason.InvalidAccount);
object userpassword = reader["userpassword"];
//可以加入MD5或者散列值判斷。
if (!userpassword.Equals(password))
throw new AuthenticationException(AuthenticationReason.InvalidPassword);
command.Connection.Close();
return true;
}
catch (Exception ex)
{
throw SoapUtility.WrapException(ex, Context.Request.Url);
}
}
[WebMethod(Description = "獲得認證后的用戶實體信息!")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public DataSet GetUserBean(string account) {
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
DataPopeManage dp = new DataPopeManage();
return dp.GetUserBean(account);
}
#endregion
#region 測試方法
[WebMethod(Description="SayHello,此服務需要Soap報頭認證")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public string HelloWorld(String name)
{
if (!this.Authenticate())
return null;
return "Hello World:" + name;
}
[WebMethod(Description = "測試數據連接。此服務需要Soap報頭認證")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public String testConn() {
if (!this.Authenticate())
return null;
OleDbConnection conn = DataEngine.getConn();
return "當前連接:"+conn.ConnectionString;
}
#endregion
#region 人員管理
[WebMethod(Description = "查詢“人員管理”,返回某個或全部人員信息。")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public DataSet user_quar_getinfo(string idclient)
{
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
ManManage obj = new ManManage();
return obj.user_quar_getinfo(idclient);
}
[WebMethod(Description = "查詢“人員管理”,返回滿足條件的人員信息。")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public DataSet user_quar_getlist(string strRgn, string strName)
{
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
ManManage obj = new ManManage();
return obj.user_quar_getlist(strRgn,strName);
}
[WebMethod(Description = "請求“刪除數據”。成功返回真,失敗返回假。")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public bool user_quar_delInfo(string idclient)
{
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
ManManage obj = new ManManage();
return obj.user_quar_delInfo(idclient);
}
[WebMethod(Description = "保存“人員管理”的數據。")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public bool user_quar_set(DataSet mDataSet)
{
//Context.Request.SaveAs("D:\\test\\soapInfo.txt", true);
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
ManManage obj = new ManManage();
return obj.user_quar_set(mDataSet);
}
#endregion
#endregion
#region 趙磊。
#region 行政區劃
[WebMethod(Description = "查詢“行政區劃”,返回一條行政區劃信息。")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public DataSet rgn_sys_getinfo(string rgn_code)
{
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
//生成查詢條件
string strCom;
if (rgn_code != "")
{ strCom = " SELECT * FROM rgn_sys where rgn_code = '" + rgn_code + "'"; }
else
{
strCom = "SELECT * FROM rgn_sys where rgn_code is null";
}
DataEngine de = new DataEngine();
return de.query_database(strCom, "rgn_sys");
}
[WebMethod(Description = "查詢“行政區劃”,返回一條行政區劃信息。")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public DataSet admini_area_getinfo(string usertoken, string rgncode)
{
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
string strCom;
if (rgncode != "")
{
strCom = " SELECT * FROM admini_area where code = '" + rgncode + "'";
}
else
{
strCom = " SELECT * FROM admini_area where code is null";
}
DataEngine de = new DataEngine();
return de.query_database(strCom, "admini_area");
}
[WebMethod(Description = "查詢“行政區劃”,返回滿足條件的行政區劃信息。")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public DataSet admini_area_getlist(string usertoken, string rgncode, string nLevel)
{
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
string strCom = "SELECT * FROM admini_area";
if (rgncode != "")
strCom = "SELECT * FROM admini_area where left(code," + rgncode.Length + ")='" + rgncode + "' and area_class='" + nLevel + "'";
DataEngine de = new DataEngine();
return de.query_database(strCom, "admini_area");
}
[WebMethod(Description = "請求“刪除數據”。成功返回真,失敗返回假。")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public bool admini_area_delInfo(string rgncode)
{
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
DataEngine de = new DataEngine();
rgncode="'"+rgncode+"'";
return de.del_database("code", rgncode, "admini_area");
}
[WebMethod(Description = "保存“行政區劃”的數據。")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public bool admini_area_set(string usertoken, DataSet mDataSet)
{
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
DataEngine DE = new DataEngine();
int flag = DE.save_database(mDataSet, "admini_area");
if (flag == 1)
{
return true;
}
return false;
}
[WebMethod(Description = "查詢“行政區劃”,返回滿足條件的行政區劃信息。")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public string admini_area_getliststring(string usertoken, string rgncode, string nLevel)
{
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
string strCom = "SELECT * FROM admini_area";
if (rgncode != "")
strCom = "SELECT * FROM admini_area where left(code," + rgncode.Length + ")='" + rgncode + "' and area_class=" + nLevel;
return strCom;
}
[WebMethod(Description = "在空間信息中查詢“區劃信息”,返回一條區劃空間信息。")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public DataSet rgn_getinfoFromMap(string usertoken, string id) //rgn_getinfoFromMap
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -