委托使用
来源:互联网 发布:键盘记录软件 隐蔽手机 编辑:程序博客网 时间:2024/05/20 07:59
委托使用,也是参考百度,给自己做个笔记。
委托自己理解就是定义一个接口,把接口公布出去,自己会调用接口。但接口具体怎么实现,是在别处实现。因为实现的时候通常要使用到实现类里面的参数。
这样就实现了两个页面之间的配合,既可以获取到委托订定义类UCBarcodeGridView调用页面的状态数据,又可以获取到实际执行页面的状态数据
UCBarcodeGridView 类是个自定义控件类,定义了委托,并在自己的方法里面调用委托类。
namespace ScreamWMS.UserControls
{
'声明委托
public delegate void ViewDefineBarcode(Boolean isConfir,DataTable tab);
public partial class UCBarcodeGridView : DevExpress.XtraEditors.XtraUserControl
{
'声明委托类变量
public event ViewDefineBarcode OnbtinViewDefineBarcodeClick;
private DataTable tab;
public UCBarcodeGridView(DataTable tab)
{
InitializeComponent();
this.tab = tab;
this.gridControl1.DataSource = tab;
private void btnCancel_Click(object sender, EventArgs e)
{
OnbtinViewDefineBarcodeClick(false, tab);
}
private void btnConfirm_Click(object sender, EventArgs e)
{
OnbtinViewDefineBarcodeClick(true, tab);
}
private void btnSearch_Click(object sender, EventArgs e)
{
string newFilter = "1=1 ";
string filter = gridView1.ActiveFilterString;
if (txtProductName.Text != string.Empty)
{
newFilter = newFilter + string.Format(" And productName like '%{0}%'", txtProductName.Text.Trim());
}
if (txtSpec.Text != string.Empty)
{
newFilter = newFilter + string.Format(" And Spec like '%{0}%'", txtSpec.Text.Trim());
}
this.gridView1.ActiveFilterString = newFilter;
}
private void txtFilter_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
string newFilter = "1=1 ";
string filter = gridView1.ActiveFilterString;
if (txtBrand.Text.Trim() != string.Empty)
{
newFilter = newFilter + string.Format(" And brandcode like '%{0}%'", txtBrand.Text.Trim());
}
if (txtProductName.Text.Trim() != string.Empty)
{
newFilter = newFilter + string.Format(" And productName like '%{0}%'", txtProductName.Text.Trim());
}
if (txtSpec.Text.Trim() != string.Empty)
{
newFilter = newFilter + string.Format(" And Spec like '%{0}%'", txtSpec.Text.Trim());
}
if (txtProductCode.Text.Trim() != string.Empty)
{
newFilter = newFilter + string.Format(" And ProductCode like '%{0}%'", txtProductCode.Text.Trim());
}
this.gridView1.ActiveFilterString = newFilter;
}
}
}
}
B类实例化了委托类变量
Class B{
private void btnViewDefineBarcode_Click(object sender, EventArgs e)
{
UCBarcodeGridView barcodeListTree = new UCBarcodeGridView(tab);
this.Controls.Add(barcodeListTree);
barcodeListTree.BringToFront();
barcodeListTree.OnbtinViewDefineBarcodeClick += new ViewDefineBarcode(delegate(Boolean isChoose, DataTable gbTable)
{
if (isChoose)
{
foreach (DataRow row in gbTable.Rows)
{
int barcodeCount = Convert.ToInt32(row["Qty"]);
if (barcodeCount != 0)
{
for (int i = 0; i < barcodeCount; i++)
{
this.txtBarcode.Text = row["ProductCode"].ToString().Trim();
txtBarcode_KeyPress(txtBarcode, new KeyPressEventArgs('\r'));
}
}
}
}
this.Controls.Remove(barcodeListTree);
});
barcodeListTree.Show();
}
}
- 委托之使用委托
- 使用委托
- 使用委托
- 委托使用
- 委托使用
- C#委托-委托的使用
- c#异步委托委托的使用
- 黑马程序员--C#委托(使用委托)
- C#中使用委托
- 委托的使用情况
- 使用.NET异步委托
- delegate 委托的使用
- 委托的使用
- C# Form使用委托
- c#委托的使用
- 为什么要使用委托
- 委托的使用
- form中使用委托
- Mouse
- dropdownlistbox 对text属性赋值为空字串后, 显示不更新
- Struts2中的constant详解
- Shell脚本入门(六) - 条件控制语句: if
- ym——Android仿QQ5.0侧滑菜单ResideMenu源码分析
- 委托使用
- int类型转换成String 填充补0
- 源代码下载网站目录
- c#中new一个对象以后,是否需要手动释放?
- Java 实现奇偶排序
- struts2命名空间
- android应用
- 分享:40 岁了还在写代码,是一种幸福,还是一种悲哀?
- Precision & Recall计算机视觉中常用的评价标准