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
查看全文
相关阅读:
人机界面设计
可用性
* 产品设计
界面设计
原型设计工具——Axure
原型系统
交互设计
原型设计
Microsoft-PetSop4.0(宠物商店)-数据库设计-Sql
第1章 游戏之乐——NIM(2)“拈”游戏分析
原文地址:https://www.cnblogs.com/flashicp/p/697063.html
最新文章
golang学习笔记---函数、方法和接口
golang 学习笔记 ---数组/字符串/切片
Docker在Windows下的安装以及Hello World
Docker 的技术组件
Docker学习笔记 ---存储与管理
Docker 学习笔记 ---Docker组件
docker学习笔记 --- centos install
golang ---JSON
golang ---struct
chkconfig 检查、设置系统的各种服务
热门文章
解决:mysql5.7 timestamp默认值0000-00-00 00:00:00 报错
解决python pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query')
mysql创建用户
Tomcat启动报Error listenerStart错误
nginx linux 安装
nginx监听相同端口,根据域名请求不同的server
Linux命令--mysqld_safe和mysqld区别
mysql导入导出sql文件
linux后台启动命令-的原因
软件人机界面设计
Copyright © 2011-2022 走看看