金蝶基础方法介绍说明
1:获取单据相关信息
(1)获取当前行号
int rowIndex = this.Model.GetEntryCurrentRowIndex("FEntity"); FEntity为单据体标识
(2)获取单据体集合
Entity entity = this.View.BillBusinessInfo.GetEntity("FSaleOrderEntry"); [size=12.6667px]FSaleOrderEntry为单据体标识
DynamicObjectCollection entrys = this.Model.GetEntityDataObject(entity);
(3)操作插件获取选中行
[size=12.6667px] // 扩展方法,需要 using Kingdee.BOS.Core.DynamicForm
var selectedRows = this.Option.GetBillOperationSelectedRows();
(4)获取选中行
int[] selectedIndexsR = this.View.GetControl<EntryGrid>("FSaleOrderEntry").GetSelectedRows();
(5)获取选中行数据
//当前选中行行号
int[] selectedIndexsR = this.View.GetControl<EntryGrid>("FSaleOrderEntry").GetSelectedRows();
//单据体数据
DynamicObjectCollection selectedRowsDy = this.Model.DataObject["SaleOrderEntry"] as DynamicObjectCollection;
//选中行数据
DynamicObject selectedRow = selectedRowsDy[selectedIndexsR[0]];
(6)获取单据内码
long billNo = Convert.ToInt64(this.View.Model.GetPKValue());//获取当前单据编号内码
(7)获取单据分录内码
int row = this.Model.GetEntryCurrentRowIndex("FSubEntity");
Entity entiry = this.View.Model.BillBusinessInfo.GetEntity("FSubEntity");
object pkValue = this.View.Model.GetEntryPKValue(entiry.Key, row);
(8)在单据列表界面,使用如下语句获取当前选择行的单据内码
this.ListView.CurrentSelectedRowInfo.PrimaryKeyValue
3:当前界面的数据保存,直接调用保存操作
Kingdee.BOS.ServiceHelper.BusinessDataServiceHelper.Save(this.Context, this.View.BusinessInfo, this.View.Model.DataObject);
4:检验字符串函数
ObjectUtils.IsNullOrEmptyOrWhiteSpace
IsNullOrWhiteSpace
5:利用代码弹出提示框
this.View.ShowMessage("详细信息", MessageBoxOptions.YesNo, ret =>
{
if (ret == MessageBoxResult.No)
{
e.Cancel = true;
return;
}
}, string.Format("物料编码为:{0}的物料存在不同的报关项号,是否继续?", string.Join(",", list)), MessageBoxType.Notice);
6:通过主键获取对象
FormMetadata formMetadata = MetaDataServiceHelper.Load(this.Context, "BD_MATERIAL") as FormMetadata;
DynamicObject dynamicObject = BusinessDataServiceHelper.LoadSingle(
this.Context,
id,
formMetadata .BusinessInfo.GetDynamicObjectType());
7:获取表单字段的值
DynamicObject FMaterial = (DynamicObject)this.View.Model.GetValue("FMaterialId");[size=12.6667px]FMaterialId为字段标识,本字段是一个基础资料字段
DynamicObject FMaterial = (DynamicObject)this.View.Model.GetValue("FMaterialId",e.Row);e.ROW为单据体行号
8:设置表单字段的值
1:给分录赋值
this.View.Model.SetValue("FEntryNote", FNOTE,rowIndex);
2:给单据头赋值
this.View.Model.SetValue("FEntryNote",FNOTE);
9:数据库执行语句
DBUtils.Execute(this.Context, updateSql);
var mas = DBUtils.ExecuteDynamicObject(this.Context, sql);
10:新增、删除单据体行
this.View.Model.DeleteEntryRow("FSONEntity", i);
this.View.Model.CreateNewEntryRow("FSONEntity");
11:刷新操作
this.View.UpdateView("FieldKey")刷新某个字段
this.View.InvokeFormOperation(Kingdee.BOS.Core.DynamicForm.FormOperationEnum.Refresh)//刷新整单
12:代码锁定单元格
this.View.GetFieldEditor("FBaseUnitId", 0).SetEnabled("", false);
this.View.GetFieldEditor("FBarCodeAmount", 0).Enabled = false;
13:常用服务端操作
计算默认值
IDynamicFormModel model = AppServiceContext.CreateDynamicFormModel(ctx, formMetadata.BusinessInfo, dataObject, null);
IDefaultValueCalculator calculator = model.GetService<IDefaultValueCalculator>();
calculator.Initialize(model);
calculator.ApplyDefaultValue(head, dataObject, 0);
calculator.ApplyDefaultValue(entity, entryObject, 1);
暂存
IDraftService service = Kingdee.BOS.Contracts.ServiceFactory.GetService<IDraftService>(ctx);
service.Draft(ctx, formMetadata.BusinessInfo, dataObjects);
保存
AppServiceContext.SaveService.Save(ctx, formMetadata.BusinessInfo, dataObjects);
提交
AppServiceContext.SubmitService.Submit(ctx, formMetadata.BusinessInfo, pkArray, "Submit");
审核
List<KeyValuePair<object, object>> pkIds = new List<KeyValuePair<object, object>>();
foreach (var o in pkArray)
{
pkIds.Add(new KeyValuePair<object, object>(o, ""));
}
List<object> paraAudit = new List<object>();
//1审核通过
paraAudit.Add("1");
//审核意见
paraAudit.Add("");
AppServiceContext.SetStatusService.SetBillStatus(ctx, formMetadata.BusinessInfo, pkIds, paraAudit, "Audit");
反审核
List<object> paraUnAudit = new List<object>();
//2反审核
paraUnAudit.Add("2");
//审核意见
paraUnAudit.Add("");
AppServiceContext.SetStatusService.SetBillStatus(ctx, formMetadata.BusinessInfo, pkIds, paraUnAudit, "UnAudit");
删除
// 删除前进行校验
AppServiceContext.DeleteService(ctx, formMetadata.BusinessInfo, pkArray);
// 不做校验直接删除
AppServiceContext.BusinessDataService.Delete(ctx, pkArray, formMetadata.BusinessInfo.GetDynamicObjectType());
单据转换
ConvertRuleElement convertRule = AppServiceContext.ConvertService.GetConvertRules(ctx, "srcFormId", "destFormId").FirstOrDefault();
PushArgs pushArgs = new PushArgs(convertRule, selectedRows)
{
TargetBillTypeId = targetBillTypeId,
TargetOrgId = orgId,
};
//执行下推操作,并获取下推结果
ConvertOperationResult convResult = AppServiceContext.ConvertService.Push(ctx, pushArgs);
DynamicObject[] destObjects = (from p in convResult.TargetDataEntities select p.DataEntity).ToArray();
14:设置焦点行、获取焦点行
//设置父窗体的焦点行
this.View.ParentFormView.SetEntityFocusRow("FEntity", selectedIndexsR[0]);
//获取当前分录焦点行FocusRow
EntryGrid entryGrid = this.View.GetControl<EntryGrid>("FEntity");
int rowIndex = entryGrid.GetFocusRowIndex();
15:获取单据体每一行的数据包
//获取父窗
体选中行
int[] selectedIndexsR = this.View.ParentFormView.GetControl<EntryGrid>("FEntity").GetSelectedRows();
Entity entity = this.View.ParentFormView.Model.BillBusinessInfo.GetEntity("FEntity");
foreach (int i in selectedIndexsR)
{
DynamicObject rowObj = this.View.ParentFormView.Model.GetEntityDataObject(entity, i) as DynamicObject;
}
16:抛出异常
throw new KDException("", "已经产生条码不能反审核");
17:仓位赋值
(1)表单插件
//获取组织
string OrGID = Convert.ToString(this.Context.CurrentOrganizationInfo.ID);
RelatedFlexGroupField stockLocFld = this.View.BillBusinessInfo.GetField("FStockLocID") as RelatedFlexGroupField;
if ("100498".Equals(OrGID))
{
FSTOCKID = "1317258";
stockLocld = 104431;
}
//仓库仓位赋值
this.View.Model.SetValue("FStockID", FSTOCKID, i);
DynamicObject[] stockLoc = BusinessDataServiceHelper.LoadFromCache(this.Context, new object[] { stockLocld }, stockLocFld.RefFormDynamicObjectType);
stockLocFld.DynamicProperty.SetValue(obj, stockLoc[0]);
stockLocFld.RefIDDynamicProperty.SetValue(obj, stockLocld);
this.View.UpdateView("FStockLocID", i);
(2)操作插件、列表插件
直接后台更新仓位ID
18:字符串、集合去重
BillNo = String.Join(";", BillNo.Split(';').Distinct());
PrimaryKeyValues.Distinct()
19:代码打开窗口状态
BillShowParameter showParam = new BillShowParameter();
showParam.FormId = "SAL_SaleOrder";
showParam.PageId = Guid.NewGuid().ToString();
showParam.OpenStyle.ShowType = ShowType.MainNewTabPage;
20:列表插件获取单据体
ListSelectedRowCollection rows = this.ListView.SelectedRowsInfo;
List<object> pkIds = new List<object>();
foreach (var row in rows)
{
pkIds.Add(row.PrimaryKeyValue);
}
FormMetadata metadata = MetaDataServiceHelper.Load(this.Context, "SAL_DELIVERYNOTICE") as FormMetadata;
DynamicObject[] dynamicObjects = BusinessDataServiceHelper.Load(this.Context, pkIds.ToArray(), metadata.BusinessInfo.GetDynamicObjectType());
21:获取当前时间,确定当前时间是周几
// 获取当前时间
DateTime dateTime=Kingdee.BOS.ServiceHelper.TimeServiceHelper.GetSystemDateTime(this.Context);
//获取单据日期时间
string times = (string)Convert.ToDateTime(this.View.Model.GetValue("FDate")).ToString("yyyy-MM-dd", DateTimeFormatInfo.InvariantInfo);
//获取当前日期是星期几
string Text = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(DateTime.Now.DayOfWeek);
DateTime time=Convert.ToDateTime((times+" 17:30 "));
if (dateTime>= time)//超过五点半
{
if ("星期六".Equals(Text))
{
this.View.Model.SetValue("FDate", Convert.ToDateTime(this.View.Model.GetValue("FDate")).AddDays(2));
}
else
{
this.View.ShowMessage("您做单的时间超过下午五点半了,保存后系统将把做单日期往后推一天");
this.View.Model.SetValue("FDate", Convert.ToDateTime(this.View.Model.GetValue("FDate")).AddDays(1));
}
}
22:获取当前用户信息
· this.Context.UserId
· 16394
· this.Context.UserName
· "Administrator"
· this.Context.UserToken
· "a9cd8152-8923-487d-bf91-77297bfd8fde"
· this.Context.LoginName
· "Administrator"
· this.Context.CustomName
· "金蝶软件"
· this.Context.ComputerName
· "SmartSoftCs"
· this.Context.ClientInfo.IpAddress
· "192.168.0.105"
· this.Context.ClientInfo.MacAddress
· "00:24:2B:59:EE:C5"
· this.Context.ClientInfo.Version
· this.Context.ClientInfo.ClientType
23:辅助属性相关表
select * from T_BD_FLEXSITEMDETAILV where fid in ('102122','100149')
select * from T_BD_FLEXAUXPROPERTY
select * from T_BD_FLEXAUXPROPERTY_L
SELECT * FROM T_BD_MaterialAuxPty
--辅助资料
select * FROM T_BAS_ASSISTANTDATA
select * from T_BAS_ASSISTANTDATAENTRY
24:操作插件新增分录
(1)获取分录集合
DynamicObjectCollection entrysHZ = (DynamicObjectCollection)Entity["FHZEntity"];
(2)分录集合增加一个行数据包
1)如果分录一行都没有
DynamicObject obj = new DynamicObject(entrysHZ.DynamicCollectionItemPropertyType);
2)如果分录存在单据行-可以用此方法也可以用上面的方法
using Kingdee.BOS.Orm;
DynamicObject cloneEntity=obj.Clone(false, true) as DynamicObject;
(3)调用单据保存方法
25:分录保存主键重复问题解决
DynamicObject obj = new DynamicObject(entrysHZ.DynamicCollectionItemPropertyType);
var MaxFEntryId = Kingdee.BOS.ServiceHelper.DBServiceHelper.GetSequenceInt64(this.Context, "Z_PRD_PICKMTRLDATAHZ", 1);
obj["id"] = Convert.ToString(MaxFEntryId.ElementAt(0)) ;
26:数据库日期转换及C#代码日期转换
C#时间转换:string times = (string)Convert.ToDateTime(dyFilter["FDateYM"]).ToString("yyyy-MM-dd", DateTimeFormatInfo.InvariantInfo);
数据库日期:
select CONVERT(datetime2,'2019-04-01', 23)
select CONVERT(varchar(100), GETDATE(), 23)
select CONVERT(date, GETDATE(), 23)
27:数据库去掉尾零及C#代码去掉尾零
数据库:cast(BARCODEMAIN.FENTITY_LENGTH as real)
c#:Convert.ToDecimal(obj["FBARVOLUMENUMBER"]).ToString("0.###")
28:修改表单只读属性
SELECT FPACKAGEID, * FROM T_META_OBJECTTYPE WHERE FID='...' ...表示该表单的标识
当FPACKAGEID=null时表示该表单不是只读
在u盘内发现的,可能是从哪位大佬那里借鉴过来的,但是找不到出处了,非本人原创整理,在此分享给大家
https://vip.kingdee.com/article/14229?productLineId=1
金蝶基础方法介绍说明
本文2024-09-16 17:13:59发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-14386.html