public void TM_API_1_DAY(Label lab, DateTime date, object StoreId, Action action)
{
lab.Text = "";
lab.Text = "正在执行...请稍后...";
if (DialogResult.OK == MessageBox.Show("是否执行:" + date.ToString("yyyy-MM-dd") + "?", "提示:", MessageBoxButtons.OKCancel))
{
action.Invoke();//执行委托...
lab.Text = "执行:" + date.ToString("yyyy-MM-dd") + "_运行结束!" + DateTime.Now;
}
else
{
lab.Text = "";
}
}
public void TM_API_N_DAY(Label lab, DateTime startDate, DateTime endDate, object StoreId, object type, Action action)
{
lab.Text = "";
TimeSpan timeSpan = new TimeSpan();
timeSpan = endDate - startDate;
int days = timeSpan.Days;
if (days >= 0)
{
lab.Text = "正在执行...请稍后...";
if (DialogResult.OK == MessageBox.Show("是否执行:" + startDate.ToString("yyyy-MM-dd") + " 至 " + endDate.ToString("yyyy-MM-dd") + "?", "提示:", MessageBoxButtons.OKCancel))
{
if (days == 0)
{
action.Invoke();//执行委托...
}
else
{
for (int i = 0; i <= days; i++)
{
try
{
lab.Text = "正在执行:" + startDate.AddDays(i).ToString("yyyy-MM-dd") + "_" + DateTime.Now + "...";
lab.Refresh();//强制刷新Lable
if (this.IsHandleCreated)
{
Invoke(action, new Object[] { startDate.AddDays(i), type, Convert.ToInt32(StoreId) });//修改委托的参数后执行...
}
}
catch (Exception ex)
{
continue;//继续搞
}
}
}
lab.Text = "执行:" + endDate.ToString("yyyy-MM-dd") + "_运行结束!" + DateTime.Now;
}
else
{
lab.Text = "";
}
}
else
{
MessageBox.Show("[开始日期]必须小于等于[截止日期]!");
}
}
//调用委托:
private void button9_Click(object sender, EventArgs e)
{
var lab = this.labBillBills;
var startDate = this.dtpBillBills1.Value;
var StoreId = this.cmbBillBills.SelectedValue;
var type = BillBills_Type.整日数据;
//var type = BillBills_Type.分段数据;
BillBillsBLL bll = new BillBillsBLL();
tianMaoApiBLL.TM_API_1_DAY(lab, startDate, StoreId,
delegate () { bll.RUN(startDate, type, Convert.ToInt32(StoreId)); });
}
private void button8_Click(object sender, EventArgs e)
{
var lab = this.labBillBills;
var startDate = this.dtpBillBills1.Value;
var endDate = this.dtpBillBills2.Value;
var StoreId = this.cmbBillBills.SelectedValue;
var type = BillBills_Type.整日数据;
BillBillsBLL bll = new BillBillsBLL();
tianMaoApiBLL.TM_API_N_DAY(lab, startDate, endDate, StoreId, type,
delegate () { bll.RUN(startDate, type, Convert.ToInt32(StoreId)); });
}
函数方法里面要包含参数 Action:
void function1 (Action action)
{
action.Invoke();//执行委托...
}
void function2 (Action action,string 参数1,int 参数2)
{
Invoke(action, new object[]{参数1,参数2});
}
调用函数:?
function1 (delegate () { 其他的函数(参数1,参数2...参数N) });
function2 (delegate () { 其他的函数(参数1,参数2...参数N) },参数1,参数2);
|