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
查看全文
相关阅读:
[Project Euler] 来做欧拉项目练习题吧: 题目002(转)
[Project Euler] 欧拉项目练习题001(转)
Linux wc 结合cat命令统计代码行数
mysql:主键和索引的区别
一些常用的SQL语句
mysql 性能优化方案
修改mysql用户密码
Ruby on Rails,创建开发用的MYSQL数据库
mysql数据库中分区的概念
Rails 数据库操作
原文地址:https://www.cnblogs.com/flashicp/p/697063.html
最新文章
Installing LAMP (Linux, Apache, MySQL and PHP) On Linux Mint
如何学习开源项目
POJ1523 SPF 求割点 基础题
HDU2767 有向图加最少边变强连通
POJ1236 Network of Schools 缩点+强连通 学校软件网络 基础题
HDU3072 Intelligence System
HDU3394 Railway 求块 判断环
POJ2375 Cow Ski Area 加最少的边构成强连通图 基础题
HDU3594 Cactus 判断是否为仙人掌图 难度中
POJ3114 Countries in War 缩点+SPFA 中等题
热门文章
HDU1827 电话通知
HDU3560 Graph’s Cycle Component 图论基础题
杂
爱狗人士必看电影:《忠犬八公的故事》(Hachiko: A Dog's Story)
[Project Euler] 来做欧拉项目练习题吧: 题目005(转)
李娜 好样的!
《社交网络》Facebook马克~
无题~~~
无题
关于链表
Copyright © 2011-2022 走看看