一、委托定义

   1:     public class TestData
   2:      {
   3:          //定义委托
   4:          public delegate void Get_TestDataEventHandler(Get_TestDataEventArgs e);
   5:          //定义事件
   6:          public event Get_TestDataEventHandler Get_TestData;
   7:          //定义数据类型 传递和获取 Observer所感兴趣的信息
   8:          //继承EventArgs类     
   9:          public class Get_TestDataEventArgs : EventArgs
  10:          {
  11:              //传递两个参数 strWhere strIN
  12:              //获取一个数据 dataset 类型  执行查询后返回的数据集
  13:              public readonly string strWhere,strIN;
  14:              private DataSet ds;        
  15:             
  16:              /// <summary>
  17:             /// 参数类型初始化
  18:             /// </summary>
  19:             /// <param name="strWhere">数据库查询语句 WHERE </param>
  20:             /// <param name="strIN">数据库查询语句 IN </param>
  21:              public Get_TestDataEventArgs(string strWhere,string strIN)
  22:              {
  23:                  this.strWhere = strWhere;
  24:                  this.strIN = strIN;
  25:              }          
  26:              // 设置方法执行完毕后的Dataset类型的数据           
  27:              public DataSet Data
  28:              {
  29:                  set { ds = value; }
  30:                  get { return ds; }
  31:              }
  32:          }
  33:          private DataSet _testdata;
  34:   
  35:          /// <summary>
  36:          /// 返回数据 DataSet
  37:          /// </summary>
  38:          public DataSet Testdata
  39:          {
  40:              get { return _testdata; }
  41:          }
  42:   
  43:         //判断事件是否有赋值 
  44:          protected virtual void onGet_TestData(Get_TestDataEventArgs e)
  45:          {
  46:              if (Get_TestData != null)
  47:              {
  48:                  Get_TestData(e);
  49:                  _testdata = e.Data;
  50:              }
  51:          }
  52:          /// <summary>
  53:          /// 开始获取数据
  54:          /// </summary>
  55:          /// <param name="e"></param>
  56:          public void Start(Get_TestDataEventArgs e)
  57:          {
  58:              onGet_TestData(e);
  59:          }
  60:   
  61:      }

二、调用委托方法定义

        /// <summary>
/// 多芯查询 有IN条件
/// </summary>
/// <param name="e"></param>
public void Getdata_Method_Multicore(TestData.Get_TestDataEventArgs e)
{
string sql = "SELECT * ";
sql += " WHERE (Name IN ("+e.strIN+"))";
e.Data = dbs.Query(sql);
} /// <summary>
/// 双并查询 有IN条件
/// </summary>
/// <param name="e"></param>
public void Getdata_Method_TwainCore(TestData.Get_TestDataEventArgs e)
{
string sql = " SELECT * ";
sql += " WHERE "+e.strWhere+" AND (Result LIKE N'%PASS%') AND (Name IN ("+e.strIN+"))";
e.Data = dbs.Query(sql);
} /// <summary>
/// 单芯查询 无 IN条件
/// </summary>
/// <param name="e"></param>
public void GetData_Method_OneCore(TestData.Get_TestDataEventArgs e)
{
string sql = " SELECT * ";
sql += " WHERE " + e.strWhere + " AND (Result LIKE N'%PASS%') ";
e.Data = dbs.Query(sql);
}

三、应用

          TestData _TestData = new TestData(); 
_TestData.Get_TestData += _Method_User_3D.GetData_Method_OneCore;   //3D 数据查询方法设置 

          string strWhere = "Where 语句";                    //Where 语句
string strIN = "IN 语句"; //IN 语句 为空
Maticsoft.DAL.TestData.Get_TestDataEventArgs e = new DAL.TestData.Get_TestDataEventArgs(strWhere, strIN); //委托数据类型初始化
_TestData.Start(e); //开始查询
DataSet ds = _TestData.Testdata; //查询到的数据
if (ds.Tables[0].Rows.Count > 0) //如果有记录 则表示为良品
{
_result_3D = true;
}
else { _result_3D = false; }

最新文章

  1. IOS 入门开发教程
  2. oc-14-对象方法调用类方法
  3. .NET中的三种Timer的区别和用法
  4. Javascript学习笔记(一)
  5. codevs 1725 探险 (二分)
  6. java(try块语句变量,和匿名类变量生存时间
  7. css 梯形标签页
  8. 用友CDM系统“货位间商品移库单(一步)”表体增加“货位可用数量”字段,根据表头的选择的货位自动带出数值
  9. nvarchar 和varchar区别
  10. Maven工程下报错:The superclass &quot;javax.servlet.http.HttpServlet&quot; was not found on the Java Build Path
  11. 展开被 SpringBoot 玩的日子 《 五 》 spring data jpa 的使用
  12. POST Raw JSON提交
  13. java.lang.IllegalArgumentException: No enum constant org.apache.ws.commons.schema.XmlSchemaForm.
  14. pytorch visdom可视化工具学习—1—详细使用-3-Generic Plots和Others
  15. Mysql逻辑分层、存储引擎
  16. linux环境下执行RF测试脚本
  17. elasticsearch 自定义_id
  18. docker 下 mysql 集群的搭建
  19. 理解SVG的图形填充规则
  20. EC断言16种判断

热门文章

  1. python基础7 ---python函数
  2. Hive与Hbase关系整合
  3. 每天一个Linux命令(7)pwd命令
  4. 【leetcode刷题笔记】Single Number
  5. Redis高级进阶(二)
  6. hd acm2025
  7. 51nod1613
  8. 分享知识-快乐自己:Java中各种集合特点
  9. Docker与LXC、虚拟化技术的区别——虚拟化技术本质上是在模拟硬件,Docker底层是LXC,本质都是cgroups是在直接操作硬件
  10. 一个用 vue 写的树层级组件 vue-ztree