20150624_Andriod _web_service_匹配

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Data.SqlClient;
using System.Text.RegularExpressions;
using System.Collections;
using System.Collections.Generic;

namespace bpm_test
{
    //public class DBOperation:IDisposable
    public class DBOperation
    {
        /// <summary> 
        /// 一个操作数据库的类,所有对SQLServer的操作都写在这个类中,使用的时候实例化一个然后直接调用就可以 
        /// </summary>

public static SqlConnection sqlCon;  //用于连接数据库 
 
        //将下面的引号之间的内容换成上面记录下的属性中的连接字符串 
        //connectionString="sever=服务器名;database=数据库名;User ID=用户;Password=密码"
        //con.ConnectionString = "server=505-03;database=ttt;user=sa;pwd=123";
        // string connectionStringTest3 = @"server=BL48VQ68YDRNQMN\SQLEXPRESS;database=PrimarySchool;user id=admin;password=123456";
        //string connectionStringTest4 = @"Data Source = BL48VQ68YDRNQMN\SQLEXPRESS; Initial Catalog = tempdb; User Id = admin; Password = 123456;";

//private String ConServerStr = @"Data Source=BOTTLE-PC;Initial Catalog=StockManage;Integrated Security=True"; 
        private String ConServerStr = @"Data Source=ITpc;Initial Catalog=Test_hr;User Id = sa; Password = 26";
         
        //默认构造函数 
        public DBOperation() 
        { 
            if (sqlCon == null) 
            { 
                sqlCon = new SqlConnection(); 
                sqlCon.ConnectionString = ConServerStr; 
                sqlCon.Open(); 
            } 
        } 
          
        //关闭/销毁函数,相当于Close() 
        public void Dispose() 
        { 
            if (sqlCon != null) 
            { 
                sqlCon.Close(); 
                sqlCon = null; 
            } 
        } 
         
        /// <summary> 
        /// 获取所有货物的信息 
        /// </summary> 
        /// <returns>所有货物信息</returns> 
        public List<string> selectAllCargoInfor() 
        { 
            List<string> list = new List<string>(); 
 
            try 
            {
                string sql = "select * from Test_1"; 
                SqlCommand cmd = new SqlCommand(sql,sqlCon); 
                SqlDataReader reader = cmd.ExecuteReader(); 
 
                while (reader.Read()) 
                { 
                    //将结果集信息添加到返回向量中 
                    list.Add(reader[0].ToString()); 
                    list.Add(reader[1].ToString()); 
                    list.Add(reader[2].ToString());
                    list.Add(reader[3].ToString());
                } 
 
                reader.Close(); 
                cmd.Dispose(); 
 
            } 
            catch(Exception) 
            { 
 
            } 
            return list; 
        } 
 
        /// <summary> 
        /// 增加一条货物信息 
        /// </summary> 
        /// <param name="Cname">货物名称</param> 
        /// <param name="Cnum">货物数量</param> 
        public bool insertCargoInfo(string Ts_01, string Ts_02, string Ts_03, string Ts_06) 
        { 
            try 
            {
                string sql = "insert into Test_1 (Ts_01,Ts_02,Ts_03,Ts_06) values ('" + Ts_01 + "', '" + Ts_02 + "', '" + Ts_03 + "', '" + Ts_06 + "' )"; 
                SqlCommand cmd = new SqlCommand(sql, sqlCon); 
                cmd.ExecuteNonQuery(); 
                cmd.Dispose(); 
 
                return true; 
            } 
            catch (Exception) 
            { 
                return false; 
            } 
        } 
 
        /// <summary> 
        /// 删除一条货物信息 
        /// </summary> 
        /// <param name="Cno">货物编号</param> 
        public bool deleteCargoInfo(string Ts_01) 
        { 
            try 
            {
                string sql = "delete from Test_1 where Ts_01 = '" + Ts_01 + "' ";
                SqlCommand cmd = new SqlCommand(sql, sqlCon); 
                cmd.ExecuteNonQuery(); 
                cmd.Dispose(); 
 
                return true; 
            } 
            catch (Exception) 
            { 
                return false; 
            } 
        }

}
}

***************************************************************

***************************************************************

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace bpm_test
{
    /// <summary>
    /// Service1 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]

// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {

DBOperation dbOperation = new DBOperation();

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

/// <summary>
        /// ///Ht////   http://192.168.1.91:8028/
        /// </summary>
        /// <returns></returns>
        [WebMethod(Description = "获取所有的信息")]
        public string[] selectAllCargoInfor()
        {
            return dbOperation.selectAllCargoInfor().ToArray();
        }

[WebMethod(Description = "增加一条信息")]
        public bool insertCargoInfo(string Ts_01, string Ts_02, string Ts_03, string Ts_06)
        {
            return dbOperation.insertCargoInfo(Ts_01,Ts_02,Ts_03,Ts_06);
        }

[WebMethod(Description = "删除一条信息")]
        public bool deleteCargoInfo(string Ts_01)
        {
            return dbOperation.deleteCargoInfo(Ts_01);
        }

////////////////////////
    }
}

***************************************************************

上一篇:ThreadLocal实现方式&使用介绍—无锁化线程封闭


下一篇:[LeetCode]题解(python):052-N-Queens II