目录
1.搭建Visual Studio二次开发Epicor10的环境
首先需要新建一个类库项目,并引用开发所需要的DLL文件,
我这里使用UD01Form来二次开发,所以添加了UD01Form的窗体dll文件Ice.UI.UD01Entry,
如下图所示,是当前Demo中二次开发需要的DLL文件.
2.在Epicor中设计好UI界面
在这个Demo中,我在UD01原界面中添加了一个New按钮,
功能是新增一行数据,并自动生成Key1的值,
另外还需要实现隐藏左边的Panel的功能.
3.在Visual Studio中进行代码编写
在项目中新建一个类文件,
类中为New按钮添加了事件,并且隐藏了左边的Panel,
其中Initialize,Destroy,FormLoad三个方法将会在Epicor客制中调用,代码如下:
using Ice.Lib.Framework;
using Infragistics.Win.UltraWinToolbars;
using System;
using System.Windows.Forms;
namespace Epicor.Demo
{
public class UD01Entry
{
Ice.Lib.Customization.CustomScriptManager csm;
UltraToolbarsManager baseToolbarsManager;
Ice.UI.App.UD01Entry.Transaction oTrans;
Ice.Core.Session session;
EpiDataView edvUD01;
Ice.UI.App.UD01Entry.UD01Form TForm;
UltraToolbar standardTools;
EpiButton epiBtNew;
/// <summary>初始化数据(InitializeCustomCode中调用该方法)</summary>
/// <param name="csm1">接受从Epicor中传过来的CustomScriptManager对象</param>
public void Initialize(Ice.Lib.Customization.CustomScriptManager csm1)
{
csm = csm1;
oTrans = ((Ice.UI.App.UD01Entry.Transaction)(csm.GetGlobalInstance("oTrans")));
session = (Ice.Core.Session)(oTrans.Session);
edvUD01= ((EpiDataView)(oTrans.EpiDataViews["UD01"]));
baseToolbarsManager = ((UltraToolbarsManager)(csm.GetGlobalInstance("baseToolbarsManager")));
standardTools = baseToolbarsManager.Toolbars["Standard Tools"];
TForm = ((Ice.UI.App.UD01Entry.UD01Form)(this.csm.GetGlobalInstance("UD01Form")));
epiBtNew = GetControlByName<EpiButton>(TForm, "epiBtNew");//获取UI界面的控件
epiBtNew.Click += EpiBtNew_Click;
}
/// <summary>释放数据(DestroyCustomCode中调用该方法)</summary>
public void Destroy()
{
epiBtNew.Click -= EpiBtNew_Click;
}
/// <summary>窗体加载(UD01Form_Load中调用该方法)</summary>
public void FormLoad()
{
HiddenLeftTree();
}
/// <summary>New按钮事件</summary>
private void EpiBtNew_Click(object sender, EventArgs e)
{
oTrans.GetNew();
edvUD01.CurrentDataRow.BeginEdit();
edvUD01.CurrentDataRow["Key1"] = "K" + System.DateTime.Now.ToString("yyyyMMddHHmmssfff");
edvUD01.CurrentDataRow.EndEdit();
}
/// <summary>隐藏左边面板</summary>
public void HiddenLeftTree()
{
Infragistics.Win.UltraWinDock.WindowDockingArea windowDockingArea1 = (Infragistics.Win.UltraWinDock.WindowDockingArea)(TForm.Controls["windowDockingArea1"]);
windowDockingArea1.Visible = false;
}
/// <summary>按Name获取Epicor控件</summary>
public static T GetControlByName<T>(Control control, string name)
{
Control[] controls = control.Controls.Find(name, true);
if (controls.Length > 0) return (T)((Object)(controls[0]));
return default(T);
}
}
}
4.在Epicor调用写好的类库
首先要将前面写的代码,编译成DLL文件,并将文件复制到Epicor客户端Client目录下.
然后在客制中引用DLL文件(注意选择DLL文件时,右下角选择"All files")
在Epicor中添加代码调用类库
// **************************************************
// Custom code for UD01Form
// Created: 2019/1/28 15:10:36
// **************************************************
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Ice.BO;
using Ice.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;
using Epicor.Demo;//引用类库命名空间
public class Script
{
// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
// Begin Wizard Added Module Level Variables **
// End Wizard Added Module Level Variables **
// Add Custom Module Level Variables Here **
UD01Entry obj=new UD01Entry();//实例化类
public void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
// Begin Wizard Added Variable Initialization
obj.Initialize(csm);//调用Initialize方法,传入csm对象
// End Wizard Added Variable Initialization
// Begin Wizard Added Custom Method Calls
// End Wizard Added Custom Method Calls
}
public void DestroyCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
// Begin Wizard Added Object Disposal
obj.Destroy();
// End Wizard Added Object Disposal
// Begin Custom Code Disposal
// End Custom Code Disposal
}
private void UD01Form_Load(object sender, EventArgs args)
{
obj.FormLoad();
}
}
5.在Visual Studio中调试Epicor客制
运行Epicor程序之后,在VS中选择"调试->附加到进程",找到Epicor的进程,点"附加"按钮,
附加之后,我们就可以自由调试VS中的代码了.
当点击"New"按钮时,进入到之前设置好的调试断点处.
代码运行成功,左边的Panel隐藏了,点击"New"按钮新增了一行数据,并生成了Key1的值.
6.后记(将代码全部整合到Epicor客制中)
如果公司正式环境中不方便使用自己开发的类库,可以直接复制VS中的代码到Epicor客制中,
然后添加对应的DLL文件和命名空间,即可运行.
Epicor客制中代码如下:
// **************************************************
// Custom code for UD01Form
// Created: 2019/1/28 15:10:36
// **************************************************
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Ice.BO;
using Ice.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;
using Ice.Lib.Framework;
using Infragistics.Win.UltraWinToolbars;
using System;
using System.Windows.Forms;
public class Script
{
// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
// Begin Wizard Added Module Level Variables **
// End Wizard Added Module Level Variables **
// Add Custom Module Level Variables Here **
UD01Entry obj=new UD01Entry();
public void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
// Begin Wizard Added Variable Initialization
obj.Initialize(csm);
// End Wizard Added Variable Initialization
// Begin Wizard Added Custom Method Calls
// End Wizard Added Custom Method Calls
}
public void DestroyCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
// Begin Wizard Added Object Disposal
obj.Destroy();
// End Wizard Added Object Disposal
// Begin Custom Code Disposal
// End Custom Code Disposal
}
private void UD01Form_Load(object sender, EventArgs args)
{
obj.FormLoad();
}
public class UD01Entry
{
Ice.Lib.Customization.CustomScriptManager csm;
UltraToolbarsManager baseToolbarsManager;
Ice.UI.App.UD01Entry.Transaction oTrans;
Ice.Core.Session session;
EpiDataView edvUD01;
Ice.UI.App.UD01Entry.UD01Form TForm;
UltraToolbar standardTools;
EpiButton epiBtNew;
/// <summary>初始化数据(InitializeCustomCode中调用该方法)</summary>
/// <param name="csm1">接受从Epicor中传过来的CustomScriptManager对象</param>
public void Initialize(Ice.Lib.Customization.CustomScriptManager csm1)
{
csm = csm1;
oTrans = ((Ice.UI.App.UD01Entry.Transaction)(csm.GetGlobalInstance("oTrans")));
session = (Ice.Core.Session)(oTrans.Session);
edvUD01= ((EpiDataView)(oTrans.EpiDataViews["UD01"]));
baseToolbarsManager = ((UltraToolbarsManager)(csm.GetGlobalInstance("baseToolbarsManager")));
standardTools = baseToolbarsManager.Toolbars["Standard Tools"];
TForm = ((Ice.UI.App.UD01Entry.UD01Form)(this.csm.GetGlobalInstance("UD01Form")));
epiBtNew = GetControlByName<EpiButton>(TForm, "epiBtNew");//获取UI界面的控件
epiBtNew.Click += EpiBtNew_Click;
}
/// <summary>释放数据(DestroyCustomCode中调用该方法)</summary>
public void Destroy()
{
epiBtNew.Click -= EpiBtNew_Click;
}
/// <summary>窗体加载(UD01Form_Load中调用该方法)</summary>
public void FormLoad()
{
HiddenLeftTree();
}
/// <summary>New按钮事件</summary>
private void EpiBtNew_Click(object sender, EventArgs e)
{
oTrans.GetNew();
edvUD01.CurrentDataRow.BeginEdit();
edvUD01.CurrentDataRow["Key1"] = "K" + System.DateTime.Now.ToString("yyyyMMddHHmmssfff");
edvUD01.CurrentDataRow.EndEdit();
}
/// <summary>隐藏左边面板</summary>
public void HiddenLeftTree()
{
Infragistics.Win.UltraWinDock.WindowDockingArea windowDockingArea1 = (Infragistics.Win.UltraWinDock.WindowDockingArea)(TForm.Controls["windowDockingArea1"]);
windowDockingArea1.Visible = false;
}
/// <summary>按Name获取Epicor控件</summary>
public static T GetControlByName<T>(Control control, string name)
{
Control[] controls = control.Controls.Find(name, true);
if (controls.Length > 0) return (T)((Object)(controls[0]));
return default(T);
}
}
}