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
查看全文
相关阅读:
程序为什么加载到内存中
cortex-A cortex-R cortex-M处理器的性能比较
makefile 中的赋值方式
python(老男孩全栈观后感------文件处理)
python------lambda(匿名函数)
python------filter(过滤器)
Express深入解读
nodejs安装
一道有意思的题目
charAt获取数组,测试
原文地址:https://www.cnblogs.com/flashicp/p/697063.html
最新文章
得到栈中的最小值
栈实现队列
队列实现栈
8. 二叉树的下一个结点
7. 重建二叉树
52. 两个链表的第一个公共结点
35. 复杂链表的复制
23. 链表中环的入口结点
18.2 删除链表中重复的结点
66. 构建乘积数组
热门文章
LintCode 20. Dices Sum
剑指 Offer 48. 最长不含重复字符的子字符串
快排模板
STM32F104ZET6 系统定时器(SysTick)
STM32F104ZET6 中断系统
STM32F104ZET6 GPIO
Linux基础1
C语言如何操作内存
内存编址和寻址、内存对齐
位、字节、半字、字的概念和内存位宽
Copyright © 2011-2022 走看看