zoukankan
html css js c++ java
一个关于委托的代码
这是一个关于委托的代码,先感谢我的朋友赵*,
微软提供了
Invoke
的方法,其作用就是让子线程告诉窗体线程来完成相应的控件操作。
private
Thread opThread
=
null
;
private
delegate
void
MyInvoker(
string
str);
private
MyInvoker myInv
=
null
;
private
MyInvoker barInv
=
null
;
private
delegate
bool
IncreaseHandle(
int
nValue );
//
查询 、插入的 循环次数
private
int
OPER_CIRCLE_TIMES
=
7
;
/***查找插入***/
#region
/***查找插入***/
/**/
///
<summary>
///
从三个表中提取数据,暂存到DataSet中,后加载到listview显示,并查找A及B,
///
然后,将所有数据插入到最终表中。
///
</summary>
///
<param name="operInt"></param>
///
<returns></returns>
private
int
InsertNull(
int
operInt)
{
try
{
//
查找记录
GetData dataInfo
=
new
GetData();
dataInfo.ConnString
=
this
.p_operTablePath;
DataSet myDs
=
dataInfo.GetTreeDataSet(operInt);
//
绑定到listview
DataBind(myDs);
//
向StatckInfo表,插入数据
if
(
this
.p_Result
==
1
)
{
InsertDataFromDataSet2(dataInfo,myDs);
}
}
catch
(Exception err)
{
MessageBox.Show(
this
,err.Message,
""
,MessageBoxButtons.OK,MessageBoxIcon.Error);
}
return
this
.p_Result;
}
#endregion
/***逐行插入***/
#region
/***逐行插入***/
/**/
///
<summary>
///
listview 循环插入
///
this.lv_Data.Items[i].Tag;
///
</summary>
///
<param name="dataInfo">
GetData dataInfo
</param>
///
<param name="ds">
DataSet ds
</param>
private
void
InsertDataFromDataSet2(GetData dataInfo,DataSet ds)
{
if
(ds
==
null
)
{
return
;
}
try
{
//
总行数
int
total
=
ds.Tables[
0
].Rows.Count;
//
进度条初始化
//
this.prgBar.Maximum=total;
//
prgBar.Value=0;
Bar(total.ToString());
for
(
int
i
=
0
;i
<
total;i
++
)
{
StatckInfo editstatckInfo
=
(StatckInfo)
this
.lv_Data.Items[i].Tag;
editstatckInfo.ConnString
=
this
.p_operTablePath;
bool
flag
=
editstatckInfo.OperateLocalDInfomation(editstatckInfo,
0
);
//
Label操作过程提示
//
this.labInfo.Text="正在插入的证券号是:"+editstatckInfo.IdReceipt.ToString();
//
this.labInfo.Refresh();
WriteInfo(
"
正在插入的**号是:
"
+
editstatckInfo.IdReceipt.ToString());
//
进度条滚动
//
this.prgBar.Value=prgBar.Value+1;
Bar(
"
1
"
);
}
}
catch
(Exception err)
{
MessageBox.Show(
this
,err.Message,
""
,MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
#endregion
/***DataBind***/
#region
/***DataBind***/
/**/
///
<summary>
///
从DataTable中放数据到ListView中
///
</summary>
///
<param name="ds">
DataSet ds
</param>
public
void
DataBind(DataSet ds)
{
if
(ds
==
null
)
{
this
.lv_Data.Items.Clear();
return
;
}
try
{
DataTable Dtab
=
ds.Tables[
0
];
ArrayList itemArray
=
new
ArrayList();
//
进度条初始化
//
this.prgBar.Maximum=Dtab.Rows.Count;
//
prgBar.Value=0;
//
进度条初始化
int
total
=
Dtab.Rows.Count;
Bar(total.ToString());
foreach
(DataRow Row
in
Dtab.Rows)
{
object
IDQuestion
=
Row[
0
];
object
IDType
=
Row[
1
];
object
CustomerName
=
Row[
2
];
object
CustomerID
=
Row[
3
];
object
RMoney
=
Row[
4
];
object
receiptID
=
Row[
5
];
object
noShanZheng
=
Row[
6
];
object
snChanQuan
=
Row[
7
];
object
address
=
Row[
8
];
object
Phone
=
Row[
9
];
int
sn
=
System.Convert.ToInt32(IDQuestion);
int
typeid
=
System.Convert.ToInt32(IDType);
//
构造S**&^&Info类
StatckInfo tempStack
=
new
StatckInfo(sn,typeid,CustomerName.ToString(),
CustomerID.ToString(),RMoney.ToString(),receiptID.ToString(),noShanZheng.ToString(),
snChanQuan.ToString(),address.ToString(),Phone.ToString());
//
查找AA等
GetData dataInfo
=
new
GetData();
dataInfo.ConnString
=
this
.p_operTablePath;
dataInfo.CombinStatckFileds(tempStack);
ListViewItem lvi
=
this
.GenLvItem(tempStack);
itemArray.Add(lvi);
//
Label操作过程提示
//
this.labInfo.Text="查询" +typeid.ToString()+ "表的**号是:"+receiptID.ToString();
//
this.labInfo.Refresh();
WriteInfo(
"
查询
"
+
typeid.ToString()
+
"
表的**号是:
"
+
receiptID.ToString());
//
进度条滚动
//
this.prgBar.Value=prgBar.Value+1;
Bar(
"
1
"
);
}
this
.FillListView(itemArray,
this
.lv_Data);
Result
=
1
;
}
catch
(Exception err)
{
Result
=-
1
;
MessageBox.Show(
this
,err.Message,
""
,MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
#endregion
/***多线程处理*/
#region
/***多线程处理*/
//
子线程入口函数:
/**/
///
<summary>
///
Thread function interface
///
</summary>
private
void
ThreadFun()
{
try
{
ParameteTrans();
for
(
int
i
=
1
; i
<
OPER_CIRCLE_TIMES; i
++
)
{
Thread.Sleep(
20
);
InsertNull(i);
}
}
catch
(Exception err)
{
MessageBox.Show(
this
,err.Message,
""
,MessageBoxButtons.OK,MessageBoxIcon.Error);
}
MessageBox.Show(
this
,
"
数据插入完毕!
"
,
"
插入数据
"
,MessageBoxButtons.OK,MessageBoxIcon.Information);
this
.prgBar.Visible
=
false
;
this
.labInfo.Visible
=
false
;
this
.cmdDeletSame.Enabled
=
true
;
}
/**/
///
<summary>
///
改变数值
///
</summary>
private
void
ParameteTrans()
{
//
Init increase event
myInv
=
new
MyInvoker(DisplayInfo);
barInv
=
new
MyInvoker(changebar);
}
private
void
WriteInfo(
string
str)
{
this
.Invoke(
this
.myInv,
new
object
[]
{ str }
);
}
private
void
Bar(
string
i)
{
this
.Invoke(
this
.barInv,
new
object
[]
{ i }
);
}
private
void
DisplayInfo(
string
str)
{
labInfo.Text
=
str;
}
private
void
changebar(
string
i)
{
try
{
int
myint
=
int
.Parse(i);
if
(myint
>
1
)
{
prgBar.Maximum
=
myint;
prgBar.Value
=
0
;
}
else
prgBar.Value
+=
myint;
}
catch
(Exception err)
{
MessageBox.Show(
this
,err.Message,
""
,MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
/**/
///
<summary>
///
创建子线程
///
</summary>
public
void
InitThis()
{
try
{
opThread
=
new
Thread(
new
ThreadStart(ThreadFun));
opThread.IsBackground
=
true
;
opThread.Start();
}
catch
(Exception err)
{
MessageBox.Show(
this
,err.Message,
""
,MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
#endregion
查看全文
相关阅读:
【RAC】 RAC For W2K8R2 安装--RDBMS软件的安装(五)
【RAC】 RAC For W2K8R2 安装--grid的安装(四)
【RAC】 RAC For W2K8R2 安装--共享磁盘的配置(三)
【RAC】 RAC For W2K8R2 安装--操作系统环境配置 (二)
【RAC】 RAC For W2K8R2 安装--总体规划 (一)
【OGG】 RAC环境下管理OGG的高可用 (五)
【OGG】RAC环境下配置OGG单向同步 (四)
【OGG】OGG简单配置双向复制(三)
【OGG】OGG的单向复制配置-支持DDL(二)
【OGG】OGG的单向DML复制配置(一)
原文地址:https://www.cnblogs.com/flashicp/p/697063.html
最新文章
【大数据】HBase启动
修复日志,阻止给日志多次添加handlers时候重复打印的问题
关于隐私数据获取统一说明
python 使用模板模式和工厂模式的混合设计开发各种邮件客户端发送邮件
python tornado异步性能测试
python使用dbutils的PooledDB连接池,操作数据库
python qq邮箱发送邮件
python对日志处理的封装
java的this static public protected private abstract interface 在python的对应,java python一些区别
java okhttp包的类特点
热门文章
java 实现类似于python requests包的Session类,自动管理cookie。
安卓webview子线程网络请求,怎么获得结果?
java okhttp发送post请求
java okhhtp下载学信网学籍信息
python模块和类的通用转换规则(2),三步转oo
设置联通登录页面
设计模式-行为型模式,模板模式(16)
设计模式-行为型模式,策略模式(15)
设计模式-行为型模式,状态模式(14)
【RAC】 RAC For W2K8R2 安装--创建ASM磁盘组(六)
Copyright © 2011-2022 走看看