扩展按钮功能 - 扩展一个【复制单据】按钮操作详解


本文学习内容:
1. 扩展功能按钮
2. 复制单据
操作步骤:
1. 在模块主窗体给菜单添加扩展权限,如: ButtonAuthority.EX_01。
2. 给扩展权限定义名称:如:复制单据。
3. 当调试完成,在系统管理的《菜单管理》导入菜单。
参考下面的代码:
增加扩展按钮的权限:
C# Code:
menuSalesOrder.Tag = new MenuItemTag(MenuType.DataForm, (int)CSFrameworkV5.Interfaces.ModuleID.SalesModule, AuthorityCategory.BUSINESS_ACTION_VALUE + ButtonAuthority.EX_01);
//来源:C/S框架网(www.csframework.com) QQ:23404761
menuSalesOrder.Tag = new MenuItemTag(MenuType.DataForm, (int)CSFrameworkV5.Interfaces.ModuleID.SalesModule, AuthorityCategory.BUSINESS_ACTION_VALUE + ButtonAuthority.EX_01);
//来源:C/S框架网(www.csframework.com) QQ:23404761
修改扩展按钮自定义名称:
C# Code:
(menuSalesOrder.Tag as MenuItemTag).SetActionName(ButtonAuthority.EX_01, "复制单据");
//来源:C/S框架网 | www.csframework.com | QQ:23404761
//来源:C/S框架网 | www.csframework.com | QQ:23404761
控制按钮状态:
C# Code:
//查看模式,复制单据按钮可用
protected override void SetViewMode()
{
base.SetViewMode();
this.Buttons.GetButtonByName("btnClone").Enable =_AllowDataOperate && this.ButtonAuthorized(ButtonAuthority.EX_01);
protected override void SetViewMode()
{
base.SetViewMode();
this.Buttons.GetButtonByName("btnClone").Enable =_AllowDataOperate && this.ButtonAuthorized(ButtonAuthority.EX_01);
}
//修改模式,复制单据按钮灰掉,禁用
protected override void SetEditMode()
{
base.SetEditMode();
this.Buttons.GetButtonByName("btnClone").Enable = false;
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
//修改模式,复制单据按钮灰掉,禁用
protected override void SetEditMode()
{
base.SetEditMode();
this.Buttons.GetButtonByName("btnClone").Enable = false;
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
重写InitButtons方法,初始化窗体的按钮:
C# Code:
public override void InitButtons()
{
base.InitButtons();
//复制单据
if (this.ButtonAuthorized(ButtonAuthority.EX_01))
{
IButtonInfo btnClone = this.ToolbarRegister.CreateButton("btnClone", "复制单据", ToolBarGroup.扩展功能1,
Globals.LoadBitmap("32_Copy.png"), new Size(57, 28), true, true, this.DoClone);
_buttons.AddButton(btnClone);
}
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
public override void InitButtons()
{
base.InitButtons();
//复制单据
if (this.ButtonAuthorized(ButtonAuthority.EX_01))
{
IButtonInfo btnClone = this.ToolbarRegister.CreateButton("btnClone", "复制单据", ToolBarGroup.扩展功能1,
Globals.LoadBitmap("32_Copy.png"), new Size(57, 28), true, true, this.DoClone);
_buttons.AddButton(btnClone);
}
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
DoClone按钮事件:
C# Code:
public void DoClone(IButtonInfo sender)
{
this.AssertFocusedRow();
if (Msg.AskQuestion("确定要复制单据吗?"))
{
//获取当前单据
this.DoViewContent(this.Buttons.GetButtonByName(ButtonNameList.btnView));
if (this.IsViewMode)
{
//重置主表的数据
_BLLInstance.DataBindRow.SetAdded();//改为新增状态
SetEditorBindingValue(txtSONO, "*自动生成*", true);
_BLLInstance.DataBindRow[tb_SO.CreatedBy] = Loginer.CurrentUser.Account;
_BLLInstance.DataBindRow[tb_SO.CreationDate] = DateTime.Now;
//重置明细表的数据
foreach (DataRow R in _BLLInstance.CurrentBusiness.Tables[tb_SOs.__TableName].Rows)
{
R.SetAdded();//改为新增状态
R[tb_SOs.SONO] = DBNull.Value;//清空外键
R[tb_SOs.CreatedBy] = Loginer.CurrentUser.Account;
R[tb_SOs.CreationDate] = DateTime.Now;
}
//
//以下处理多个明细表
//
_UpdateType = UpdateType.Add;
this.SetEditMode();
this.ButtonStateChanged(UpdateType.Add);
}
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
public void DoClone(IButtonInfo sender)
{
this.AssertFocusedRow();
if (Msg.AskQuestion("确定要复制单据吗?"))
{
//获取当前单据
this.DoViewContent(this.Buttons.GetButtonByName(ButtonNameList.btnView));
if (this.IsViewMode)
{
//重置主表的数据
_BLLInstance.DataBindRow.SetAdded();//改为新增状态
SetEditorBindingValue(txtSONO, "*自动生成*", true);
_BLLInstance.DataBindRow[tb_SO.CreatedBy] = Loginer.CurrentUser.Account;
_BLLInstance.DataBindRow[tb_SO.CreationDate] = DateTime.Now;
//重置明细表的数据
foreach (DataRow R in _BLLInstance.CurrentBusiness.Tables[tb_SOs.__TableName].Rows)
{
R.SetAdded();//改为新增状态
R[tb_SOs.SONO] = DBNull.Value;//清空外键
R[tb_SOs.CreatedBy] = Loginer.CurrentUser.Account;
R[tb_SOs.CreationDate] = DateTime.Now;
}
//
//以下处理多个明细表
//
_UpdateType = UpdateType.Add;
this.SetEditMode();
this.ButtonStateChanged(UpdateType.Add);
}
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
效果图:


扫一扫加作者微信


版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网