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);
        }

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

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

20150624_Andriod _web_service_匹配的更多相关文章

  1. javascript匹配各种括号书写是否正确

    今天在codewars上做了一道题,如下 看上去就是验证三种括号各种嵌套是否正确书写,本来一头雾水,一种括号很容易判断, 但是三种怎么判断! 本人只是个前端菜鸟,,不会什么高深的正则之类的. 于是,在 ...

  2. scanf类型不匹配造成死循环

        int i = 0; while (flag) { printf("please input a number >>> "); scanf("% ...

  3. 使用注解匹配Spring Aop切点表达式

    Spring中的类基本都会标注解,所以使用注解匹配切点可以满足绝大部分需求 主要使用@within()/@target @annotaton() @args()等... 匹配@Service类中的所有 ...

  4. .net使用正则表达式校验、匹配字符工具类

    开发程序离不开数据的校验,这里整理了一些数据的校验.匹配的方法: /// <summary> /// 字符(串)验证.匹配工具类 /// </summary> public c ...

  5. webpack配置别名alias出现的错误匹配

    @(webpack) webpack是一款功能强大的前端构建工具,不仅仅是针对js,它也可通过各种loader来构建相关的less,html,image等各种资源,将webpack配合流程制定工具gu ...

  6. perl 如何匹配ASCII码以及ASCII码转换

    匹配ASCII码:   /[:ascii:]/ ASCII码转换为数字: ord() 数字转换为ASCII码: chr()

  7. SQL连接操作符介绍(循环嵌套, 哈希匹配和合并连接)

    今天我将介绍在SQLServer 中的三种连接操作符类型,分别是:循环嵌套.哈希匹配和合并连接.主要对这三种连接的不同.复杂度用范例的形式一一介绍. 本文中使用了示例数据库AdventureWorks ...

  8. [LeetCode] Wildcard Matching 外卡匹配

    Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ...

  9. [LeetCode] Regular Expression Matching 正则表达式匹配

    Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...

随机推荐

  1. system(linux) power on note

    读詹荣开文档摘 BIOS 在完成硬件检测和资源分配后,将硬盘 MBR 中的 Boot Loader 读到系统的 RAM 中,然后将控制权交给 OS Boot Loader Boot Loader执行全 ...

  2. Java基础之一组有用的类——使用正则表达式查找和替换(SearchAndReplace)

    控制台程序. 使用正则表达式执行查找和替换操作,只需要调用Matcher对象的find()方法,就可以调用appendReplacement()方法来替换匹配的子序列.在提供给方法的新StringBu ...

  3. 接口是否可继承接口? 抽像类是否可实现(implements)接口? 抽像类是否可继承实体类(concrete class)?

    接口是否可继承接口? 抽像类是否可实现(implements)接口? 抽像类是否可继承实体类(concrete class)? 1. 接口可以继承接口. 2. 抽像类可以实现(implements)接 ...

  4. 开源日志技术log4j

    老师的总结: 日志:除了能记录异常信息,还可以记录程序正常运行时的关键信息. 使用log4j来进行日志文件记录经典步骤: 001.在项目中创建一个lib文件夹,然后将下载好的jar包copy到该文件夹 ...

  5. C makefile

    Makefile编写 hello.out:max.o main.c gcc max.o main.c -o hello.out max.o:max.c gcc -c max.c -o max.o

  6. 移动端下拉刷新,iScroll.js用法(转载)

    本文转载自: iScroll.js 用法参考 (share)

  7. 关于设置oracle中系统编号SYSID自动编号的问题;

    http://liye9801.blog.163.com/blog/static/601970320086210039591/ 如何在oracle里设置自动编号列 2008-07-21 12:00:3 ...

  8. paper 92:Lena与图像处理

    如果你是个数字图像处理技术的研究人员,或这方面的工程师, 想必对这位戴有羽状帽饰的美女不会感觉陌生.我第一次在国际知名的学术性刊物上见到这位美女时,不禁叹为天人,毕竟在这样严肃的学术期刊上,还从未出现 ...

  9. C# 实现 单例模式

    http://blog.sina.com.cn/s/blog_75247c770100yxpb.html

  10. Spring容器中的Bean

    一,配置合作者的Bean Bean设置的属性值是容器中的另一个Bean实力,使用<ref.../>元素,可制定一个bean属性,该属性用于指定容器中其他Bean实例的id属性 <be ...