---
title: "工作笔记（一）"
author: "cfeers"
date: "2012-05-15T08:37:42Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2012-05-15T09:40:17Z"
id: 1528800
url: "https://cfeers.iteye.com/blog/1528800"
---

**1. 窗体开放简单接口**

一个Form2窗体中定义3个变量，并且拥有get/set 属性，外部程序算法返回的名称直接可以给予赋值，

也就是该窗体拥有3个对外开放的接口。

Form2:

private string \_fixedTemp= "算法名";

 

public string FixedTemp

{

  get{ return \_fixedTemp;}

  set{fixedTemp= value;}

}

 

 

Form1里：

 

Form2 frm2 = new Form2();

frm2.FixedTemp="新算法名";

 

 

 **2.监控系统脱离SQL数据库 的数据对象设计**

脱离数据库：

DataModule dm =null;    //数据对象模型

DataAccess  da = null;   //数据库操作类

DataCollection =dc =null; //数据集合类

dm = da.GetSysConfig();//得到数据对象

 

**3. 模态窗口和非模态窗口**

    模式对话框(modal dialog box模态对话框)：在关闭模式对话框之前，程序不能进行其他工作（如一般的“打开文件”对话框） ----.showDialog();  
    无模式对话框(modeless dialog box 非模态对话框)：模式对话框打开后，程序仍然能够进行其他工作（如一般的“查找与替换”对话框） --show();  
    对话框的显示有两个函数，一个是.show();另一个是.showDialog();第一个函数是以非模态对话框的形式显示，调完后会执行下面的函，当然会执行frModel.Dispose();所以弹出之后自动消毁了。改为第二个就是模态对话框了。要手动关闭

 

Form2 f2 = new Form2();   
f2.ShowDialog();   
//在f2的窗体弹出以后，将在f2窗体上进行操作，Form1暂时被限制操作

Form2 f2 = new Form2();   
f2.Show();   
//在f2的窗体弹出以后，将接着弹出下面，Form1和新弹出的f2可以同时存在，并随便你操作哪个窗体，f2关闭以后也不会对Form1产生什么影响， 

 

**4.采集温度数据的线程**

开始采集按钮事件btnStart:

private Thread thread = null;

Gather gather =new Gather ();

 

if(gather.StartGather())//启动采集类中的采集事件

{

   thread = new Thread(new ThreadStart(ScanStart));//采集温度

   thread.Start();

}

 

```
采集类 Gather.cs:

private  Thread  oThread = null;

public bool StatrGather()//开始采集
{
  try{
     oThread = new Thread(new ThreadStart(ScanTrace));
     oThread.Name ="温度采集线程";
     oThread.IsBackground = true; 
     oThread.Start();
     return ture;
    }
  catch{}
 return false;
}
public bool StopGather()//停止采集
{
try{
   oThread.Abort();
   dts.StopDevice();//停止驱动
  oThread.Sleep(1000);
   dts.CloseDevice();//关闭驱动
  return ture;
}
 catch{}
  return false;
}


public voud ScanTrace()
 {
   //扫描温度代码
}
```

 

```
 main 界面程序From1.cs
void ScanStart()
{
  while(true)
  {
    for(int i = 0; i< 2 ;i++)
    {
       if(gather.GetGatherFinishFlg(i))
       {
        showChannelsTemperatureChart(i); //显示曲线
       } 
       Thread.Sleep(1000);//暂停1s
    }
  }
} 
```

 

 **5.HashTable :根据Key取得Value**

 

HashTable  \_gatherHT = null;  
public bool GetGatherFlg(int chnlKey)  
{  
  lock(this)  
  {  
    if(gatherHT.Contains(chnlKey))//是否包含特定键  
    return (bool) \_gatherHash\[chnlKey];  
  }  
  return false;  
}