金蝶云星空插件开发常用代码

全局参数相关
this.Context.UserId//获取当前用户ID
this.Context.UserName//获取当前用户名
this.Context.LoginName//获取当前用户登陆账户
this.Context.CurrentOrganizationInfo.ID//获取当前组织
this.Context.ClientType//获取当前登陆类型:客户端(WPF)或网页端()
this.Context.IsMultiOrg;//获取是否是第一次加载
this.View.Model.GetPKValue();获取当前单据ID

控件基础操作
设置菜单显示的文本
this.View.GetBarItem(“Toolbar1”, “tbCK_ShowFolder”).Text = IsShowFolder.Equals(“1”) ? “隐藏文件夹” : “显示文件夹”;
设置控件标题
this.View.GetControl(“FCombox”).SetCustomPropertyValue(“title”, “控件标题”);
设置控件的显示隐藏
this.View.GetControl(“FPriority”).Visible = true;
this.ListView.GetBarItem(“FList”, “tbNew”).Visible = false;
设置单据体为不可编辑状态
this.View.StyleManager.SetEnabled(“FEntity”, null, false);
设置控件锁定
this.View.LockField(“FBase1”, false);
this.View.StyleManager.SetEnabled(“FCustomer”, null, false);
this.View.GetControl(“FCustomer”).SetCustomPropertyValue(“disabled”,false);
设置控件选中的焦点
this.View.GetControl(“FTextSearch”).SetFocus();
设置字段必录
(this.View.GetControl(“FMilestone”) as FieldEditor).SetCustomPropertyValue(KeyConst.MUSTINPUT, true);
修改页签标题
This.View.GetControl(“FTab_p0”).SetCustomPropertyValue(“title”,”XXXX页签名称”)
修改控件颜色
this.View.GetControl(“1111”).ControlAppearance.TextColor = “@FF0000”;
获取窗体ID
this.View.UserParameterKey
获取父级页面
this.View.ParentFormView
分隔容器
this.View.GetControl(“FSpliteContainer”).HideFirstPanel(false);//隐藏上部分
this.View.GetControl(“FSpliteContainer”).HideSecondPanel(false);//隐藏下部分
面板
this.View.GetControl(“FPanel”).SetBackGroundColor(“#FFFF0000”);//添加背景色
修改按钮字体大小
this.View.GetControl(“FBtnQuery”).SetCustomPropertyValue(“fontSize”, 20);
修改按钮样式
this.View.GetControl

this.View.GetControlthis.View.GetControl

修改按钮显示图片
this.View.GetControl
修改按钮样式为图片与文字共存,并允许显示小文字
this.View.GetControl(“FSHOPCAR”).SetStyleKey(“TextIconWithMsgButtonStyle”)
this.View.GetControl(“FSHOPCAR”).SetViceText(“300”)
this.View.GetControl(“FSHOPCAR”).SetTextIcon(“images/biz/default/Common/ShopcarBig.png”)

赋值
基础资料取值
DynamicObject obj = this.Model.DataObject;
DynamicObjectCollection rows = obj[“PPBomEntry”] as DynamicObjectCollection;//子项明细实体
var wl = rows[i][“MaterialID”] as DynamicObject;//取物料
string zxwl = wl[“F_DZLSX”].ToString();//取基础物料属性值
//获取基础物料编码
this.View.Model.GetValue(“F_CPLH”) == null ? “0” : (this.View.Model.GetValue(“F_CPLH”) as DynamicObject)[“Number”].ToString();
//普通赋值
this.View.Model.SetValue(“FStartDate”, DateTime.Now.ToString(“yyyy-MM-dd”));
//基础资料赋值
this.Model.SetItemValueByID(“FSurfaceTreatment”, “1”, 0);
this.Model.SetItemValueByNumber(“FSurfaceTreatment”, “1”, 0);
//多选基础资料赋值
string[] notifyList = new String[] { this.Context.UserId.ToString() };
this.Model.SetValue(“FNotify”, notifyList);
//单据体赋值
DataTable tableQuery = new DataTable();
this.View.Model.ClearNoDataRow();
this.View.Model.DeleteEntryData(“FEntity”);
foreach (DataRow row in tableQuery.Rows)
{
this.Model.CreateNewEntryRow(“FEntity”);
int RowCout = this.Model.GetEntryRowCount(“FEntity”);
this.Model.SetValue(“FID”, row[“FID”], RowCout – 1);
this.Model.SetValue(“FNUMBER”, row[“FNUMBER”], RowCout – 1);
this.Model.SetItemValueByNumber(“FSurfaceTreatment”, “1”, RowCout – 1);
}
this.View.UpdateView(“FEntity”);

单据体相关
//单据体赋值
DataTable tableQuery = new DataTable();
this.View.Model.ClearNoDataRow();
this.View.Model.DeleteEntryData(“FEntity”);
foreach (DataRow row in tableQuery.Rows)
{
this.Model.CreateNewEntryRow(“FEntity”);
int RowCout = this.Model.GetEntryRowCount(“FEntity”);
this.Model.SetValue(“FID”, row[“FID”], RowCout – 1);
this.Model.SetValue(“FNUMBER”, row[“FNUMBER”], RowCout – 1);
this.Model.SetItemValueByNumber(“FSurfaceTreatment”, “1”, RowCout – 1);
}
this.View.UpdateView(“FEntity”);
//获取单据体的值
int iRowIndex = this.View.Model.GetEntryCurrentRowIndex(“FEntity”);
EntryEntity entryEntity = this.View.BusinessInfo.GetEntryEntity(“FEntity”);
DynamicObjectCollection docCustomer = this.View.Model.GetEntityDataObject(entryEntity);
string fid = docCustomer[iRowIndex][“FID”].ToString();
//获取单据体当前选中的列
this.View.GetControl(“FTreeEntity”).GetFocusField();
设置选择的值高亮显示
this.View.GetControl(“FList”).SetFireRowChangeEvent(true);
//冻结列
this.View.GetControl(“FEntity”).SetFrozen(“FPartName”, “”);
//设置某行某列锁定
this.View.GetFieldEditor(“FNetWeightChange”, e.Row).SetEnabled(“”, True);
//循环单据体所有列
foreach (Field fld in _currInfo.GetEntity(“FEntity”).Fields)
初始化表格的导航属性为纵向导航(即按回车是往下移动焦点)
this.View.GetControl(Key).SetEnterMoveNextColumnCell(true);
创建行
this.View.Model.CreateNewEntryRow(“FEntity”);//新增
删除行
this.View.Model.DeleteEntryRow(“FEntity”, (int)rownum);//删除
设置字段默认排序
this.View.GetControl(“FEntity”).SetSort(“FEStep”, EntryGridFieldSortOrder.Ascending);
锁定列头
this.View.GetControl(“FEntity”).SimplizationAllColumns();
设置样式
DataTable tableStyle = new DataTable();
tableStyle.Columns.AddRange(new DataColumn[] { new DataColumn(“FFileName”), new DataColumn(“FColor”), new DataColumn(“FRowIndex”) });
tableStyle.Rows.Add(“FFileName”, UtilHelper.未开始颜色, RowCout – 1);
EntryGrid grid = this.View.GetControl(“FEntity”);
foreach (DataRow row in tableStyle.Rows)
{
grid.SetBackcolor(row[“FFileName”].ToString(), row[“FColor”].ToString(), Convert.ToInt32(row[“FRowIndex”]));
}
设置过滤条件
EntryGrid grid = this.View.GetControl(“FEntity”);
grid.SetFilterString(” FC_IsAllocated = ‘true’ “);
设置选中行
this.View.GetControl(“FEntityD”).SetFocusRowIndex(iRowIndex);
根据条件锁定单据体单元格
DynamicObjectCollection part = this.View.Model.GetEntityDataObject(this.View.BusinessInfo.GetEntryEntity(“FEntity”));
for (int i = 0; i < part.Count; i++)
{
if (!(part[i][“FEState”] == null ? “未开始” : part[i][“FEState”].ToString()).Equals(“未开始”))
{
this.View.GetFieldEditor(“FESurfaceCode”, i).SetEnabled(“”, false);
}
}

列表插件
隐藏菜单
this.ListView.GetMainBarItem(“tbNew”).Visible = false;
设置列表行高
this.View.GetControl(“FLIST”).SetRowHeight(25);
获取选中行
ListSelectedRow selectRows = this.ListView.CurrentSelectedRowInfo;
if (selectRows == null)
{
this.View.ShowErrMessage(“未选中行记录!”);
return;
}
string fid = selectRows.PrimaryKeyValue.ToString();
获取选中的行
Kingdee.BOS.Core.List.ListSelectedRowCollection selectedRowsInfo = this.ListView.SelectedRowsInfo;
string objectID = this.ListView.BillBusinessInfo.GetForm().Id;
获取当前列表查询的所有主键数据
this.ListView.GetPKData();
刷新列表
this.ListView.Refresh();
根据过滤条件,重新取数,刷新列表
this.ListView.RefreshByFilter();
动态设置列表值显示
public override void FormatCellValue(FormatCellValueArgs args)
{
string filedName = args.Header.FieldName;//字段名
if (filedName.EqualsIgnoreCase(“FNowDisposeUser”))//获取当前处理人员
{
args.FormateValue = “显示的值”;
}
}
//设置默认查询条件 设置值能查看自己有权限的仓库
public override void PrepareFilterParameter(FilterArgs e)
{
if (string.IsNullOrWhiteSpace(e.FilterString) == false)
{
e.FilterString += ” and “;
}
e.FilterString += string.Format(@” FSTOCKID IN (SELECT FID FROM dbo.LT_CBS_t_StockAdmin a WHERE c.FUSERID = {0}) “, this.Context.UserId.ToString());
}

界面相关
//设置单据标题
LocaleValue formTitle = new LocaleValue();
formTitle.Add(new KeyValuePair<int, string=””>(this.Context.UserLocale.LCID, “文件管理-修订”));
this.View.SetFormTitle(formTitle);
//打开窗体
DynamicFormShowParameter param = new DynamicFormShowParameter();
param.FormId = “SAL_DISCOUNTDETAIL”;
param.CustomParams.Add(“IncludedTax”, “true”);//传入参数
this.View.ShowForm(param);
//获取页面中的所有控件
public List GetAllKeyList()
{
IMetaDataService metaService = ServiceHelper.GetService();
FormMetadata meta = metaService.Load(this.Context, “”) as FormMetadata;
return meta == null ? new List() : meta.BusinessInfo.Elements.Select(field => field.Key).ToList();
List xx = meta.BusinessInfo.GetFieldList();
}
//【1】打开F7界面
int iClassTypeID = 1012506;
int iLookupType = (int)BOSEnum.Enu_LookUpType.Enu_LookUpType_NewBase;
m_BillInterface.ShowF7Select(send, new OnShowF7SelectEventArgs(iLookupType, iClassTypeID, strFilter));
//【2】打开自定义aspx页面
Guid rndGuid = Guid.NewGuid();
string strUrl = “CRM/BumpBill.aspx?FClassTypeID=1012024&FRndNum=” + rndGuid.ToString()
+ “??dialogWidth:800px; dialogHeight:600px;resizable:no;status: no; unadorned : no; help : no;Minimize=no;Maximize=no;”;
m_ListInterface.AddAction(new BOSAction(iBillID.ToString(), “ShowBill”, strUrl));
//【3】打开EBOS单据
Dictionary dctData = new Dictionary();
dctData[“FID”] = iBillID.ToString();
m_ListInterface.ShowBill(1012025, BOSEnum.Enu_BillStatus.Enu_BillStatus_New, dctData);
//【4】打开序时簿
StringBuilder sBuilder = new StringBuilder();
sBuilder.AppendFormat(“EXTBOS/Filter/BOSListManager.aspx?FClassTypeID=1012701&FDirect=1&FQuick=1&FLic=0&FType=-1”);
sBuilder.AppendFormat(“??dialogWidth:750px; dialogHeight:565px;”);
sBuilder.AppendFormat(“resizable:no;scroll: no; status: no; unadorned : no; help : no;Minimize=no;Maximize=no;”);
m_BillInterface.ShowCustomePage(e.BarName, sBuilder.ToString());
//页签控件的使用
this.View.GetControl(“F_LT_Tab”).SelectedIndex = 0;
this.View.GetControl(“F_LT_Tab”).SetFireSelChanged(true);//设置该页签触发页签切换事件
this.View.GetControl(“F_LT_Tab”).SelectedTabItemKey = “F_LT_TAB2_P0”;//调用无效
//页签切换事件
public override void TabItemSelectedChange(TabItemSelectedChangeEventArgs e)
{
string sendID = e.Key.ToUpper();
if (sendID.Equals(“FTABUSING”))
{
}
}
//面板嵌入网页
this.View.GetControl(“FPanelWebBrowse”).SetCustomPropertyValue(“Source”, “www.189622.com”);
需要表单构造插件!!!!
public class LT_PLM_FindReport2 : AbstractDynamicWebFormBuilderPlugIn
{
public override void CreateControl(CreateControlEventArgs e)
{
if (e.ControlAppearance.Key.EqualsIgnoreCase(“F_LT_Panel”))
{
e.Control[“xtype”] = “kdwebbrowser”;
}
}
}
//等待界面
var processForm = this.View.ShowProcessForm(new Action(t => { }), true, “正在执行,请稍候…”);
Kingdee.BOS.KDThread.MainWorker.QuequeTask(() =>
{
try
{
//分成5次停留,模拟引入数据的时间消耗
//每次停留2s,刷新一下实际进度值
System.Threading.Thread.Sleep(2000);
//更新进度
this.View.Session[“ProcessRateValue”] = 20;
System.Threading.Thread.Sleep(2000);
//更新进度
this.View.Session[“ProcessRateValue”] = 40;
System.Threading.Thread.Sleep(2000);
//更新进度
this.View.Session[“ProcessRateValue”] = 60;
System.Threading.Thread.Sleep(2000);
//更新进度
this.View.Session[“ProcessRateValue”] = 80;
System.Threading.Thread.Sleep(2000);
//更新进度:更新到100时,会自动关闭进度界面,结束进度
this.View.Session[“ProcessRateValue”] = 100;
}
finally
{
// 确保标记进度已经到达100%
this.View.Session[“ProcessRateValue”] = 100;
// 引入完毕,关闭进度显示页面
var processView = this.View.GetView(processForm.PageId);
if (processView != null)
{
processView.Close();
this.View.SendDynamicFormAction(processView);
}
}
}, (t) => { });

基础资料相关
//基础资料取值
this.View.Model.GetValue(“FCustomer”) == null ? “0” : (this.View.Model.GetValue(“FCustomer”) as DynamicObject)[“Id”].ToString()
//普通赋值
this.View.Model.SetValue(“FStartDate”, DateTime.Now.ToString(“yyyy-MM-dd”));
//基础资料赋值
this.Model.SetItemValueByID(“FSurfaceTreatment”, “1”, 0);
this.Model.SetItemValueByNumber(“FSurfaceTreatment”, “1”, 0);
//多选基础资料赋值
string[] notifyList = new String[] { this.Context.UserId.ToString() };
this.Model.SetValue(“FNotify”, notifyList);
//获取基础资料ID
IDBService DBService = Kingdee.BOS.Contracts.ServiceFactory.GetService(this.Context);
IEnumerable fEntryIDS = DBService.GetSequenceInt64(this.Context, “LT_IT_ITAssetsBudgetDetail”, addNum);

下拉列表相关
对下拉列表进行赋值
//定义List用于存储下拉列表枚举值;
List list = new List();
//通过this.View.BusinessInfo.GetFieldList()方法获取所有字段;
foreach (Kingdee.BOS.Core.Metadata.FieldElement.Field field in this.View.BusinessInfo.GetFieldList())
{
EnumItem item = new EnumItem();
item.Caption = field.Name;
item.EnumId = field.Key;
item.Value = field.Key;
list.Add(item);
}
//通过this.View.GetControl方法获取界面上的下拉列表控件;
//SetComboItems绑定值;
this.View.GetControl(“FCombo”).SetComboItems(list);

提示信息
this.View.ShowErrMessage(Kingdee.BOS.Resource.ResManager.LoadKDString(“请选择一个分录数据!”, “005023000000576”, Kingdee.BOS.Resource.SubSystemType.BASE));
this.View.ShowWarnningMessage(Kingdee.BOS.Resource.ResManager.LoadKDString(“该客户已经被信用档案引用,不能反启用信用管理”, “005023000000575”,
Kingdee.BOS.Resource.SubSystemType.BASE));
var description = string.Format(Kingdee.BOS.Resource.ResManager.LoadKDString(“客户【{0}】的订货平台管理员”, “005023000000580”,
Kingdee.BOS.Resource.SubSystemType.BASE), “1111”);
this.View.ShowMessage(string.Format(Kingdee.BOS.Resource.ResManager.LoadKDString(“创建订货平台管理员成功!帐号为客户编码:{0},密码默认为888888!”, “005023000000581”,
Kingdee.BOS.Resource.SubSystemType.BASE), “1111”), MessageBoxType.Notice);
this.View.ShowMessage(Kingdee.BOS.Resource.ResManager.LoadKDString(“请确认是否删除选定的记录?”, “005023000000584”,
Kingdee.BOS.Resource.SubSystemType.BASE), MessageBoxOptions.YesNo,
new Action((result) =>
{
if (result == MessageBoxResult.Yes)
{
}
}));
//列表弹出自定义提示内容
IOperationResult opResult = new OperationResult();
opResult.OperateResult.Add(new OperateResult()
{
Message = “”,
MessageType = MessageType.Normal,
SuccessStatus = true
});
this.View.ShowOperateResult(opResult.OperateResult);
DynamicFormShowParameter param = new DynamicFormShowParameter {
FormId = “BOS_ImportErrMsg”
};
this.View.Session[“importDataResult”] = result;
this.View.Session[“businessInfo”] = this._meta.BusinessInfo;
param.CustomParams.Add(“result”, “importDataResult”);
param.CustomParams.Add(“exporttype”, exportType.ToString());
param.CustomParams.Add(“businessInfo”, “businessInfo”);
param.OpenStyle.ShowType = ShowType.Modal;
this.View.ShowForm(param);

自定义事件
string _isQueryPanelVisible = “FALSE”;//是否显示查询面板
public override void CustomEvents(CustomEventsArgs e)
{
if (e.EventName.Equals(“IsExpandedChanged”))
{
if (e.Key.ToUpper().Equals(“F_LT_FRAME”))
{
//获取框架控件的伸缩状态
_isQueryPanelVisible = e.EventArgs;
}
}
if (e.EventName.Equals(“EnterKeyPressed”))
{
if (e.Key.ToUpper().Equals(“FTEXTSEARCH”))
{
焦点在文本框上按回车执行事件
}
}
if (e.EventName.ToUpper() == “FILECHANGED”)
{
if (e.Key.ToUpper() == “FileUpdate”.ToUpper())
{
文件上传事件
}
}
}

public override void OnFormatRowConditions(Core.Report.PlugIn.Args.ReportFormatConditionArgs args)
{
FormatCondition fc = new FormatCondition();
fc.ApplayRow = true;
if (args.DataRow.ColumnContains(“FUserName”)&&args.DataRow[“FUserName”].ToString() ==
“Dev”)// 用户等于Dev
{
fc.BackColor = ColorTranslator.ToHtml(System.Drawing.Color.Blue);// 背景色蓝色;
}
args.FormatConditions.Add(fc);
}
设置列表、帐表数据行背景色
grid.SetForecolor(“FNUMBER”, “#ff0000”, 0);
grid.SetForecolor(“FNUMBER”, “#FF0000”, 0);//注意:这里是字段标识Key
this.View.ShowMessage(“121212”);
grid.SetBackcolor(“FNUMBER”, “#FF2525”, 1);
grid.SetRowBackcolor(“#FF2525”,0);
EntryGrid grid = this.View.GetControl(“FEntity”);
grid.Enabled = false;
grid.SetRowBackcolor(“#FFFF00”, 0);
//通用设置方法
DataTable tableStyle = new DataTable();
tableStyle.Columns.AddRange(new DataColumn[] { new DataColumn(“FFileName”),new DataColumn(“FColor”), new DataColumn(“FRowIndex”)});
tableStyle.Rows.Add(“FNName”, UtilHelper.已超期颜色, RowCout – 1);//如果为关键节点则显示红色
TreeEntryGrid grid = this.View.GetControl(“FTreeEntity”);
foreach (DataRow row in tableStyle.Rows)
{
grid.SetForecolor(row[“FFileName”].ToString(), row[“FColor”].ToString(), Convert.ToInt32(row[“FRowIndex”]));
}

————————————————————打开一个窗口,在此窗口直接打开URL地址
private void ShowKDWebBrowseForm()
{
Kingdee.BOS.JSON.JSONObject webobj = new Kingdee.BOS.JSON.JSONObject();
webobj[“source”] = @”http://www.189622.com”;
webobj[“height”] = 545;
webobj[“width”] = 810;
webobj[“isweb”] = true; //是否新弹出一个浏览器窗口(or选项卡)打开网页地址
webobj[“title”] = “金蝶官网”;
//要求前端,调用ShowKDWebbrowseForm方法,显示指定的网页
this.View.AddAction(“ShowKDWebbrowseForm”, webobj);
this.View.SendDynamicFormAction(this.View);
}
————————————————————调用单据保存
DynamicObject[] doCustomer = new DynamicObject[1];
doCustomer[0] = this.Model.DataObject;
this.View.InvokeFormOperation(FormOperationEnum.Save);
AppServiceContext.SaveService.Save(this.Context, this.View.OpenParameter.FormMetaData.BusinessInfo, doCustomer);
————————————————————DynamicObject
DynamicObject的结构非常简单明了,就是一个字典,类似于一个Dictionary<string, object=””>,其中的object可能是一个简单值(普通字段)
可能是一个复杂值(如基础资料字段),更可能是一个集合(如单据体);
如果值是一个集合,则这个集合的成员,又会是一个DynamicObject对象。
实际上,我们并不推荐伙伴直接操作DynamicObject,所以也不会提供此方面的介绍。
我们是希望开发者通过如下方式读取字段数据:
1. 在界面插件中,通过如下方式取数:
this.Model.GetValue(key, rowIndex);
2. 在其他缺少Model的地方,则采用如下方式取数:
普通字段:
var field = businessInfo.GetField(key);
string value = field.DynamicProperty.GetValue(dynamicObject);
基础资料字段:
var baseField = businessInfo.GetField(key) as BaseDataField;
long id = Convert.ToInt64(baseField.RefIdDynamicProperty.GetValue(dynamicObject));
DynamicObject bdInfo = baseField.DynamicProperty.GetValue(dynamicObject) as DynamicObject;
单据体:
var entity = businessInfo.GetEntity(key);
DynamicObjectCollection rows = entity.DynamicProperty.GetValue(dynamicObject) as DynamicObjectCollection;
多选辅助资料:
MulAssistantField targetFld = businessInfo.GetField(key) as MulAssistantField;
DynamicObjectCollection mulAssiRows = targetFld.RefEntityDynamicProperty.GetValue(headObj) as DynamicObjectCollection;
foreach(var row in mulAssiRows)
{
string id = Convert.ToString(targetFld.RefIDDynamicProperty.GetValue(row));
DynamicObject bdInfo = targetFld.DynamicProperty.GetValue(row) as DynamicObject;
}
多选基础资料,类似于多选辅助资料,不赘述;
上述方式,都是通过字段、实体上的DynamicProperty属性到DynamicObject中取数,此属性也提供了SetValue方法赋值;
3. 既没有Model,也没有字段元数据时,才根据DynamicObject本身的结构,逐层往下取数(高级):
语句1:取简单值
string strValue = Convert.ToString(dynamicObject[key]);
语句2:取复杂值
DynamicObject bdInfo = dynamicObject[key] as DynamicObject;
语句3:取集合,及集合中字段值
DynamicObjectCollection mulAssiRows = dynamicObject[entityKey] as DynamicObjectCollection;
foreach(var row in mulAssiRows)
{
string id = Convert.ToString(row[key]);
DynamicObject bdInfo = row[key] as DynamicObject;
}

服务插件
1、事件:AfterExecuteOperationTransaction,发生在审核完成后。执行失败不会影响审核
2、事件:EndOperationTransaction,发生在审核完成后。执行失败会影响审核
–保存验证插件
public class LT_PLM2_SampleApplySave : AbstractOperationServicePlugIn
{
public override void OnPreparePropertys(PreparePropertysEventArgs e)
{
base.OnPreparePropertys(e);
//添加字段,这样在底下Validate才能取到值,奇怪..
e.FieldKeys.Add(“FItemNumber”);
}
public override void OnAddValidators(AddValidatorsEventArgs e)
{
base.OnAddValidators(e);
var validator = new LT_PLM2_SampleApplySaveValidator();
validator.EntityKey = “FBillHead”;
e.Validators.Add(validator);
}
}
public class LT_PLM2_SampleApplySaveValidator : AbstractValidator
{
public override void Validate(ExtendedDataEntity[] dataEntities, ValidateContext validateContext, Context ctx)
{
foreach (ExtendedDataEntity entity in dataEntities)
{
string sql = string.Empty;
string Id = entity.DataEntity[“Id”].ToString();
string FBillStatus = entity.DataEntity[“FBillStatus”].ToString();//单据状态
string FItemNumber = entity.DataEntity[“FItemNumber”] == null ? string.Empty : entity.DataEntity[“FItemNumber”].ToString();//物料代码
DynamicObjectCollection docCustomer = entity.DataEntity[“LT_PLM2_SampleApplyEntry”] as DynamicObjectCollection;//获取单据体信息
if (FProjectID.Equals(string.Empty))
{
validateContext.AddError(entity, new ValidationErrorInfo(validateContext.BusinessInfo.GetBillNoField().Id, Id, entity.DataEntityIndex, 0, Id,
“保存失败,请关联项目!”, “错误!”, ErrorLevel.FatalError));
return;
}
}
}
}
————————————————————插件事务
//必须引用System.Transactions.dll
using(KDTransactionScope trans = new KDTransactionScope(System.Transactions.TransactionScopeOption.Required))
{
// TODO
Kingdee.BOS.App.Data.DBUtils.Execute(this.Context, “truncate TABLE t1”);
trans.Complete();
}
——————————————————————-模拟手动创建单据
///
/// 创建新增单据视图
///
/// 上下文对象
/// 表单标识
///
public static IBillView CreateAddNewView(Context ctx, string formId)
{
FormMetadata meta = MetaDataServiceHelper.Load(ctx, formId) as FormMetadata;
BusinessInfo info = meta.BusinessInfo;
IResourceServiceProvider formServiceProvider = info.GetForm().GetFormServiceProvider(true);
IBillViewService billViewService = formServiceProvider.GetService(typeof(IDynamicFormView)) as IBillViewService;
Form form = info.GetForm();
BillOpenParameter billOpenParameter = new BillOpenParameter(form.Id, meta.GetLayoutInfo().Id);
billOpenParameter = new BillOpenParameter(form.Id, string.Empty);
billOpenParameter.Context = ctx;
billOpenParameter.ServiceName = form.FormServiceName;
billOpenParameter.PageId = Guid.NewGuid().ToString();
billOpenParameter.FormMetaData = meta;
billOpenParameter.LayoutId = meta.GetLayoutInfo().Id;
billOpenParameter.Status = OperationStatus.ADDNEW;
billOpenParameter.PkValue = null;
billOpenParameter.CreateFrom = CreateFrom.Default;
billOpenParameter.ParentId = 0;
billOpenParameter.GroupId = “”;
billOpenParameter.DefaultBillTypeId = null;
billOpenParameter.DefaultBusinessFlowId = null;
billOpenParameter.SetCustomParameter(“ShowConfirmDialogWhenChangeOrg”, false);//设置参数,主业务组织修改时,不提示,直接创建新单
List value = form.CreateFormPlugIns();
billOpenParameter.SetCustomParameter(FormConst.PlugIns, value);
((IDynamicFormViewService)billViewService).Initialize(billOpenParameter, formServiceProvider);//初始化视图
IBillView bill_view = (IBillView)billViewService;//表单视图
bill_view.CreateNewModelData();//创建新的模型数据
DynamicFormViewPlugInProxy proxy = bill_view.GetService();//主动触发插件的OnLoad事件
proxy.FireOnLoad();
return bill_view;
}
IBil1View bil1_view = toEditView(“BD_MATERIAL”, FMaterialld); IDynamicFormViewService
dynamicFormView = bill_view as IDynamicFormViewService;
//结算单整个的表单
dymamicFormView. SetItemValueByTD(“E_QLRB pp”,dynamioObject[‘P_QLFB_PFEAY”] != mull ? dymamioCbjectl[ “_LRB_PPMY”].ToString() : “”0);
bi11_view. Mode1.Save() ;
——————————————————————————
判断文本、基础资料、数量、日期等常见字段是否为空的表达式
  • 文本为空
  • F_TPQJ_Text  = null  OR  F_TPQJ_Text  = “”  OR  F_TPQJ_Text  = ” “
  • 基础资料为空
  • F_TPQJ_Base  = null  OR  F_TPQJ_Base = “”  OR  F_TPQJ_Base = ” “
  • 多选基础资料为空
  • len( F_TPQJ_MulBase ) > 0
  • 数量为空(整数、小数、数量因为默认值是0,都可以用0来判断)
  • F_TPQJ_Qty =0
  • 日期为空
  • F_TPQJ_Date is null
  • 复选框,不勾选
  •  F_TPQJ_CheckBox  = false
  • 下拉列表判断为空
  •  F_TPQJ_Combo  = “”
  • ——————————————————————————

暂无评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

本站提供金蝶、钉钉等开发实施相关技术文章的发布和转载。如有侵权,联系立删(info@zjgkd.cn) 。
苏公网安备32058202011935 · 苏ICP备13058196号-11
Powered by WordPress