[K/3Cloud] 创建一个业务单据表单插件

来源:互联网 发布:php 冒泡排序算法 编辑:程序博客网 时间:2024/04/27 15:10

概念

创建一个业务单据插件,处理单据的相关控制逻辑。

示例

新建一个类,继承自单据插件基类Kingdee.BOS.Core.Bill.PlugIn.AbstractBillPlugIn。
using Kingdee.BOS.Core.Bill.PlugIn;using Kingdee.BOS.Core.DynamicForm.PlugIn;using Kingdee.BOS.Core.Metadata;using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Kingdee.K3.Example.Business.PlugIn{    /// <summary>    /// 销售订单 单据维护插件    /// </summary>    public class SaleOrderEdit : Kingdee.BOS.Core.Bill.PlugIn.AbstractBillPlugIn    {        }}

K3Cloud案

基础资料中客户单据的表单插件
using System;using System.Collections.Generic;using System.Linq;using System.Text;using Kingdee.BOS.Core.Bill.PlugIn;using Kingdee.BOS.Core.Metadata.EntityElement;using Kingdee.BOS.Orm.DataEntity;using System.Text.RegularExpressions;using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;using Kingdee.BOS.Core.Bill.PlugIn.Args;using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;using Kingdee.BOS.Core.Metadata;using System.Data;using Kingdee.BOS.Util;using Kingdee.BOS.Core.DynamicForm;using Kingdee.BOS;using Kingdee.BOS.ServiceHelper;using Kingdee.BOS.JSON;using Kingdee.K3.BD.ServiceHelper;using Kingdee.BOS.Core.Bill;using Kingdee.K3.BD;using Kingdee.BOS.Core.Metadata.ControlElement;using Kingdee.BOS.Cache;namespace Kingdee.K3.BD.Common.Business.PlugIn{    /// <summary>    /// 客户单据插件    /// </summary>    public class CustomerEdit : AbstractBillPlugIn    {        #region 变量        /// <summary>        /// 是否启用预留        /// </summary>        private bool para_IsEnableReserve = false;        /// <summary>        /// 启用客户门户参数        /// </summary>        private bool para_EnableCustomerPortal = false;        #endregion        #region 重写方法        public override void AfterBindData(EventArgs e)        {            object oFax = this.View.Model.GetValue("FFAX") as object;            string sFax = "";            if (oFax != null)            {                sFax = Convert.ToString(oFax);            }            this.View.Model.SetValue("FFAX", sFax.Trim());            //TODO 非多组织隐藏字段(目前设计器未提供Context.IsMultiOrg变量,无法在设计器配置。以后考虑支持)            this.View.GetControl<FieldEditor>("FCorrespondOrgId").Visible = this.Context.IsMultiOrg;            this.View.GetBarItem("FT_BD_CUSTORDERORG", "tbAddLine_OOrg").Enabled = this.Context.IsMultiOrg;            this.View.GetBarItem("FT_BD_CUSTORDERORG", "tbDelLine_OOrg").Enabled = this.Context.IsMultiOrg;            this.View.GetBarItem("FT_BD_CUSTORDERORG", "tbInsertLine_OOrg").Enabled = this.Context.IsMultiOrg;            //不启用预留,隐藏客户优先级            this.View.GetControl("FPriority").Visible = para_IsEnableReserve;            //订货平台信息页签,根据是否启用客户门户,隐藏,显示            string parentKey = this.View.GetControl("FT_BD_CUSTORDERORG").ControlAppearance.Container;            if (!string.IsNullOrWhiteSpace(parentKey))            {                Control tabPage = this.View.GetControl(parentKey);                tabPage.Visible = (para_EnableCustomerPortal && tabPage.ControlAppearance is TabPageAppearance);            }            //已审核(或重新审核)&未禁用的客户&还未创建客户门户管理员时,创建管理员按钮才可用。            SetCreateCPAdminButtonStatus();            // 根据计划管理参数的参数【启用预留】显示/隐藏客户“客户优先级”字段            this.SetPriorityVisible();        }        public override void AfterUpdateViewState(EventArgs e)        {            //已审核(或重新审核)&未禁用的客户&还未创建客户门户管理员时,创建管理员按钮才可用。            SetCreateCPAdminButtonStatus();        }        public override void AfterCreateNewData(EventArgs e)        {            SetDefault();//设置结算币别默认值            //单体组织设置订单组织默认为创建组织            if (!this.Context.IsMultiOrg)            {                this.View.Model.SetValue("FOrderOrgId", this.View.Model.GetValue("FCreateOrgId"), 0);            }            if ((this.View.OpenParameter.Status == OperationStatus.ADDNEW))//复制或新增操作都 清空联系人页签 。。复制相当于新增。所以用这个标志            {                this.View.Model.DeleteEntryData("FT_BD_CUSTLOCATION");                             }                   }        public override void BeforeUpdateValue(BeforeUpdateValueEventArgs e)        {            switch (e.Key.ToUpperInvariant())            {                case "FISCREDITCHECK":                    bool isCreditCheck = Convert.ToBoolean(e.Value);                    if (isCreditCheck == false)                    {                        long mastId = Convert.ToInt64(this.View.Model.DataObject["msterID"]);                        string sql = string.Format(@"select  1 fexists from t_cre_custarchives a                                          inner join t_cre_custarchivesentry b on a.fid=b.fid                                        where a.fobjecttype='BD_Customer' and b.fobjectid={0}", mastId);                        using (IDataReader dr = DBServiceHelper.ExecuteReader(this.Context, sql))                        {                            while (dr.Read())                            {                                e.Cancel = true;                                this.View.ShowWarnningMessage(Kingdee.BOS.Resource.ResManager.LoadKDString("该客户已经被信用档案引用,不能反启用信用管理", "005023000000575", Kingdee.BOS.Resource.SubSystemType.BASE));                                break;                            }                        }                    }                    break;                default:                    break;            }        }        public override void DataChanged(DataChangedEventArgs e)        {            switch (e.Field.Key.ToUpperInvariant())            {                case "FTAXTYPE":                    DynamicObject taxType = this.View.Model.GetValue("FTaxType") as DynamicObject;                    string taxTypeId = taxType==null?"":Convert.ToString(taxType["Id"]);                    if (taxTypeId.EqualsIgnoreCase(K3.Core.BD.PreInsertDataConst.SFL01_SYS))                    {                        this.View.Model.SetValue("FTaxRate", 261);                    }                    else if (taxTypeId.EqualsIgnoreCase(K3.Core.BD.PreInsertDataConst.SFL02_SYS)                         || taxType.IsNullOrEmptyOrWhiteSpace())                    {                        this.View.Model.SetValue("FTaxRate", 233);                    }                    break;                case "FSELLER":                    //根据销售员携带默认销售组等信息。                    DynamicObject objSeller = null;                    objSeller = this.View.Model.GetValue("FSELLER") as DynamicObject;//获取销售员                    long objSellerId = objSeller == null ? 0 : Convert.ToInt64(objSeller["Id"]);                    if (objSellerId > 0)                    {                        DynamicObjectCollection objGroups = objSeller["BD_SALESMANENTRY"] as DynamicObjectCollection;//销售员单据体的实体名                        //默认收货方                        DynamicObject dyloc = (from p in objGroups                                               where p["ISDEFAULT"].ToString().Equals("true", StringComparison.CurrentCultureIgnoreCase)                                               select p).FirstOrDefault();//默认销售组                        this.View.Model.SetValue("FSALGROUPID", dyloc == null ? 0 : ((DynamicObject)dyloc)["OPERATORGROUPID"], e.Row);                    }                    break;                case "FCREATEORGID":                    SetDefault();                    break;                case "FISDEFAULTORDERORG":                    if (Convert.ToBoolean(e.NewValue))                    {                        bool isSelect = false;                        this.View.Model.BeginIniti();                        //切换默认订货组织选项,清空旧的选择项                        for (int i = 0; i < this.View.Model.GetEntryRowCount(e.Field.Entity.Key); i++)                        {                            if (i != e.Row)                            {                                isSelect = Convert.ToBoolean(this.View.Model.GetValue("FIsDefaultOrderOrg", i));                                if (isSelect)                                {                                    this.View.Model.SetValue("FIsDefaultOrderOrg", 0, i);                                }                            }                        }                        this.View.Model.EndIniti();                    }                    else                    {                        this.View.Model.BeginIniti();                        //取消选项,默认把第一行作为默认选项                        this.View.Model.SetValue("FIsDefaultOrderOrg", 1, 0);                        this.View.Model.EndIniti();                    }                    this.View.UpdateView("FT_BD_CUSTORDERORG");                    break;                default:                    break;            }        }        public override void AfterCreateModelData(EventArgs e)        {            SetFirstLineDefaultOrderOrg();        }        public override void AfterLoadData(EventArgs e)        {            SetFirstLineDefaultOrderOrg();        }        public override void BeforeF7Select(BOS.Core.DynamicForm.PlugIn.Args.BeforeF7SelectEventArgs e)        {            string filter;            switch (e.FieldKey.ToUpperInvariant())            {                case "FPRICELISTID":                case "FDISCOUNTLISTID":                case "FSELLER":                case "FSALGROUPID":                case "FTCONTACT":                    if (GetFieldFilter(e.FieldKey, out filter))                    {                        if (string.IsNullOrEmpty(e.ListFilterParameter.Filter))                        {                            e.ListFilterParameter.Filter = filter;                        }                        else                        {                            e.ListFilterParameter.Filter += " AND " + filter;                        }                    }                    break;            }        }        public override void BeforeSetItemValueByNumber(BOS.Core.DynamicForm.PlugIn.Args.BeforeSetItemValueByNumberArgs e)        {            string filter;            switch (e.BaseDataFieldKey.ToUpper())            {                case "FPRICELISTID":                case "FDISCOUNTLISTID":                case "FSELLER":                case "FSALGROUPID":                case "FTCONTACT":                    if (GetFieldFilter(e.BaseDataFieldKey, out filter))                    {                        if (string.IsNullOrEmpty(e.Filter))                        {                            e.Filter += filter;                        }                        else                        {                            e.Filter += " AND " + filter;                        }                    }                    break;            }        }        public override void ButtonClick(ButtonClickEventArgs e)        {            switch (e.Key.ToUpperInvariant())            {                case "FBTNCREATECPADMIN":                   // CreateCustPortalUser();                    break;                default:                    break;            }        }          public override void OnBillInitialize(BillInitializeEventArgs e)        {            //启用预留            object objEnalbeReserve = BOS.ServiceHelper.SystemParameterServiceHelper.GetParamter(this.Context                , 0, 0, K3.Core.MFG.MFGFormIdConst.SubSys_PLN.PLNSysParam, "IsEnableReserve");            para_IsEnableReserve = objEnalbeReserve == null ? false : Convert.ToBoolean(objEnalbeReserve);            //取启用客户门户参数            GetParameterEnableCustomerPortal();        }        public override void EntryBarItemClick(BarItemClickEventArgs e)        {            switch (e.BarItemKey.ToUpperInvariant())            {                case "TBNEWCONTACT":      // 联系人页签新增联系人                    BillShowParameter BillParam = new BillShowParameter();                    BillParam.FormId = Kingdee.K3.Core.SCM.SCMFormIdConst.BD_CommonContact;                    BillParam.ParentPageId = this.View.PageId;                    BillParam.CustomParams.Add("CompanyType", "BD_Customer");                    BillParam.CustomParams.Add("CustomerId", Convert.ToString(this.View.Model.GetPKValue()));                    this.View.ShowForm(BillParam, NewFillContactData);                    break;                case "TBEDITCONTACT":     // 联系人页签修改联系人                    int iRowIndex = this.View.Model.GetEntryCurrentRowIndex("FT_BD_CUSTLOCATION");                    if (iRowIndex < 0)                    {                        this.View.ShowErrMessage(Kingdee.BOS.Resource.ResManager.LoadKDString("请选择一个分录数据!", "005023000000576", Kingdee.BOS.Resource.SubSystemType.BASE));                    }                    else                    {                        BillShowParameter BillEditParam = new BillShowParameter();                        BillEditParam.FormId = Kingdee.K3.Core.SCM.SCMFormIdConst.BD_CommonContact;                        BillEditParam.Status = OperationStatus.EDIT;                        BillEditParam.PKey = Convert.ToString(this.View.Model.GetValue("FContactId", iRowIndex));                        BillEditParam.ParentPageId = this.View.PageId;                        BillEditParam.CustomParams.Add("CompanyType", "BD_Customer");                        BillEditParam.CustomParams.Add("IsModify", "true");                        this.View.ShowForm(BillEditParam, new Action<FormResult>((result) =>                        {                            if (result.ReturnData != null)                            {                                List<long> listContractIds = result.ReturnData as List<long>;                                long lContactId = 0;                                if (listContractIds != null & listContractIds.Count > 0)                                {                                    lContactId = listContractIds[0];                                }                                if (lContactId > 0)                                {                                    DynamicObjectCollection docContacts = ServiceHelper.SupplierCustomerServiceHelper.GetContactsByCompanyType(                                        this.Context, "BD_Customer", new long[]{lContactId});                                    this.View.Model.SetValue("FCONTACT", docContacts[0]["FNAME"], iRowIndex);                                    this.View.Model.SetValue("FJob", docContacts[0]["FPOST"], iRowIndex);                                    this.View.Model.SetValue("FBIZLOCATION", docContacts[0]["FBIZLOCATION"], iRowIndex);                                    this.View.Model.SetValue("FOFFICEPHONE", docContacts[0]["FTEL"], iRowIndex);                                    this.View.Model.SetValue("FMOBILEPHONE", docContacts[0]["FMOBILE"], iRowIndex);                                    this.View.Model.SetValue("FFAX1", docContacts[0]["FFAX"], iRowIndex);                                    this.View.Model.SetValue("FContactEmail", docContacts[0]["FEMAIL"], iRowIndex);                                    this.View.Model.SetValue("FContactId", docContacts[0]["FCONTACTID"], iRowIndex);                                    this.View.UpdateView("FT_BD_CUSTLOCATION");                                }                            }                        }));                    }                    break;                case "TBDELETECONTACT":   // 联系人页签删除联系人                    this.DeleteCustomerContact();                    break;                case "TBDELLINE_OORG":   // 订货组织页签删除默认订货组织时                    string sCode = Convert.ToString(this.View.Model.GetValue("FCPAdminCode"));                    int iRow = this.View.Model.GetEntryCurrentRowIndex("FT_BD_CUSTORDERORG");                    bool isDefault = Convert.ToBoolean(this.View.Model.GetValue("FIsDefaultOrderOrg", iRow));                    if (!sCode.IsNullOrEmptyOrWhiteSpace() && isDefault)                    {                        this.View.ShowMessage(Kingdee.BOS.Resource.ResManager.LoadKDString("当前客户已创建了客户平台管理员,不允许删除默认订货组织!", "005023000000577", Kingdee.BOS.Resource.SubSystemType.BASE));                        e.Cancel = true;                    }                    break;                case "TBADDLINE_OORG":                    SetFirstLineDefaultOrderOrg();                    break;                default:                    break;            }            base.EntryBarItemClick(e);        }        public override void AfterSave(AfterSaveEventArgs e)        {            // 成功保存后,联系人表体数据和当前客户相关联            if (e.OperationResult.IsSuccess)            {                // 当前客户的Id                long lCustomerId = Convert.ToInt64(this.View.Model.GetPKValue());                // 当前联系人表体的联系人Id                EntryEntity entryEntity = this.View.BusinessInfo.GetEntryEntity("FT_BD_CUSTLOCATION");                DynamicObjectCollection docCustomerContactIds = this.View.Model.GetEntityDataObject(entryEntity);                string sContactIds = "";                for (int i = 0; i < docCustomerContactIds.Count(); i++)                {                    long lContactId = Convert.ToInt64(docCustomerContactIds[i]["ContactId"]);                    if (lContactId != 0)                    {                        sContactIds = sContactIds + Convert.ToString(lContactId) + ",";                    }                }                if (sContactIds.Length > 0)                {                    sContactIds = sContactIds.Substring(0, sContactIds.Length - 1);                }                // 联系人表体不为空                if (docCustomerContactIds.Count() > 0)                {                    // 更新当前客户联系人的所属公司                    ServiceHelper.SupplierCustomerServiceHelper.UpdateContactId(this.Context, sContactIds, lCustomerId);                }                UpdateCpUserOrg();            }         }        /// <summary>        /// 如果创建了客户门户用户,那么要更新客户门户的信息        /// </summary>        private void UpdateCpUserOrg()        {            var cpAdminCode = this.Model.GetValue("FCPAdminCode") as string;                                   if (!string.IsNullOrWhiteSpace(cpAdminCode))            {                DynamicObject UserInfo = null;                long userId = 0;                {                    long msterID = Convert.ToInt64(this.Model.DataObject["msterID"]);                    string sfilter1 = string.Format("FCUSTOMERMASTERID = {0} ", msterID);                    OQLFilter filter1 = OQLFilter.CreateHeadEntityFilter(sfilter1);                    UserInfo = BusinessDataServiceHelper.Load(this.Context, K3.Core.SCM.SCMFormIdConst.CP_UserInfo, null, filter1).FirstOrDefault();                    userId = Convert.ToInt64(UserInfo["FUserId_Id"]);                }                DynamicObject User = null;                {                    string sfilter = string.Format("FUserID = {0} ", userId);                    OQLFilter filter = OQLFilter.CreateHeadEntityFilter(sfilter);                    User = BusinessDataServiceHelper.Load(this.Context, BOS.Core.FormIdConst.SEC_User, null, filter).FirstOrDefault();                }                var userOrg = User["Userorg"] as DynamicObjectCollection;                userOrg.Clear();                var custorderOrg = this.Model.DataObject["BD_CUSTORDERORG"] as DynamicObjectCollection;                long defaultOrgId = 0;                foreach (var item in custorderOrg)                {                    var orgId = Convert.ToInt64(item["OrderOrgId_Id"]);                    if (orgId != 0)                    {                        DynamicObject userOrgItem = new DynamicObject(userOrg.DynamicCollectionItemPropertyType);                        userOrgItem["FOrgID_Id"] = orgId;                        var entityRole = userOrgItem["EntityRole"] as DynamicObjectCollection;                        entityRole.Clear();                        var entityRoleItem = new DynamicObject(entityRole.DynamicCollectionItemPropertyType);                        entityRoleItem["FRoleId_Id"] = 10278;                        entityRole.Add(entityRoleItem);                        userOrg.Add(userOrgItem);                    }                    bool isDefault = Convert.ToBoolean(item["ISDEFAULT"]);                    if (isDefault)                    {                        defaultOrgId = orgId;                    }                }                UserInfo["FDEFAULTORGID_Id"] = defaultOrgId;                BusinessDataServiceHelper.Save(this.Context, User);                BusinessDataServiceHelper.Save(this.Context, UserInfo);                //清除用户缓存                string key = K3.Core.SCM.SCMConst.GetCpUserCacheKey(userId.ToString());                CacheUtil.ClearCache(this.Context.DBId, K3.Core.SCM.SCMConst.CP_Cache_CustomerPortalRegion, key);            }        }        public override void BeforeClosed(BeforeClosedEventArgs e)        {            // 客户页面关闭后,清楚所属公司为0的垃圾数据            ServiceHelper.SupplierCustomerServiceHelper.DeleteGarbageData(this.Context);        }        #endregion        #region 私有方法        #region 客户门户        private void SetFirstLineDefaultOrderOrg()        {            int iCount = this.View.Model.GetEntryRowCount("FT_BD_CUSTORDERORG");            if (iCount <= 1)            {                this.View.Model.SetValue("FIsDefaultOrderOrg", 1, 0);            }        }        ///// <summary>        ///// 创建客户用户        ///// </summary>        //private void CreateCustPortalUser()        //{        //    if (!para_EnableCustomerPortal)        //    {        //        this.View.ShowMessage(Kingdee.BOS.Resource.ResManager.LoadKDString("订货平台没有启用,无法创建订货平台管理员账号。", "005023000000578", Kingdee.BOS.Resource.SubSystemType.BASE), MessageBoxType.Notice);        //        return;        //    }        //    string userNumber = Convert.ToString(this.Model.GetValue("FNumber"));        //    string userName = Convert.ToString(this.Model.GetValue("FName"));        //    long orgId_Id = GetDefaultOrderOrgId();        //    if (orgId_Id == 0)        //    {        //        this.View.ShowMessage(Kingdee.BOS.Resource.ResManager.LoadKDString("客户没有默认订货组织,无法创建订货平台管理员。", "005023000000579", Kingdee.BOS.Resource.SubSystemType.BASE), MessageBoxType.Notice);        //        return;        //    }        //    var description = string.Format(Kingdee.BOS.Resource.ResManager.LoadKDString("客户【{0}】的订货平台管理员", "005023000000580", Kingdee.BOS.Resource.SubSystemType.BASE), userName);        //    var newUser = new UserHelper(this.Context);        //    newUser.CreateBosUser(userNumber, orgId_Id, description, true);        //    var r = newUser.Save(this.Context);        //    if (r.IsSuccess)        //    {        //        newUser.UserProfile.IsAdmin = true;        //        newUser.UserProfile.CustomerNumber = userNumber;        //        newUser.UserProfile.CustomerMasterID = Convert.ToInt64(this.View.Model.DataObject["MsterID"]);        //        newUser.UserProfile.DefaultOrgId = newUser.OrgId_Id;        //        newUser.UserProfile.BosUserId = newUser.Id;        //        newUser.UserProfile.CustomerId = Convert.ToInt64(this.View.Model.GetPKValue());        //        BusinessDataServiceHelper.Save(this.Context, newUser.UserProfile.MetaData.BusinessInfo, newUser.UserProfile.CPUserInfo);        //        this.View.Model.SetValue("FCPAdminCode", userNumber);        //        this.View.Model.DataChanged = false;        //        CPServiceHelpercs.SetCPAdminCodeByCustId(this.Context, userNumber, Convert.ToInt64(this.View.Model.GetPKValue()));        //        this.View.ShowMessage(string.Format(Kingdee.BOS.Resource.ResManager.LoadKDString("创建订货平台管理员成功!帐号为客户编码:{0},密码默认为888888!", "005023000000581", Kingdee.BOS.Resource.SubSystemType.BASE), userNumber), MessageBoxType.Notice);        //    }        //    else        //    {        //        string err = Kingdee.BOS.Resource.ResManager.LoadKDString("创建订货平台管理员失败:", "005023000000582", Kingdee.BOS.Resource.SubSystemType.BASE) + System.Environment.NewLine;        //        foreach (var item in r.GetFatalErrorResults())        //        {        //            err += item.Message + System.Environment.NewLine;        //        }        //        this.View.ShowMessage(err, MessageBoxType.Error);        //    }        //}        /// <summary>        /// 是否启用了客户门户        /// </summary>        /// <returns></returns>        private void GetParameterEnableCustomerPortal()        {            var objEnableCustomerPortal = SystemParameterServiceHelper.GetParamter(this.Context, 0, 0, "CP_SYSTEMPARAMETER", "EnableCustomerPortal");            para_EnableCustomerPortal = Convert.ToBoolean(objEnableCustomerPortal);        }        private long GetDefaultOrderOrgId()        {            Entity entity = this.Model.BusinessInfo.GetEntity("FT_BD_CUSTORDERORG");            var ety = this.Model.GetEntityDataObject(entity);            var orderDObj = ety.Where(p => Convert.ToBoolean(p["ISDEFAULT"]) == true).FirstOrDefault();            //ety[0]            //"BD_CUSTORDERORG"            //[0]: {[Id, 0]}            //[1]: {[OrderOrgId_Id, 0]}            //[2]: {[OrderOrgId, ]}            //[3]: {[ISDEFAULT, False]}            return orderDObj == null ? 0 : Convert.ToInt64(orderDObj["OrderOrgId_Id"]);        }        #endregion        /// <summary>        /// 携带核算体系下的本位币信息        /// </summary>        public void SetDefault()        {            DynamicObject saleOrg = this.View.Model.GetValue("FUseOrgId") as DynamicObject;            if (saleOrg != null)            {                long saleOrgId = Convert.ToInt64(saleOrg["Id"]);                if (saleOrgId > 0)                {                    JSONObject currInfo = FINServiceHelperForCommon.GetDefCurrencyAndExchangeTypeByBizOrgID(this.Context, saleOrgId);                    if (currInfo != null)                    {                        this.View.Model.SetValue("FTRADINGCURRID", Convert.ToInt64(currInfo["FCyForID"]));  //商务页签取本位币信息                    }                }            }        }        /// <summary>        /// 获取字段过滤条件        /// </summary>        /// <param name="filter"></param>        /// <returns></returns>        private bool GetFieldFilter(string fieldKey, out string filter)        {            filter = "";            if (string.IsNullOrWhiteSpace(fieldKey))            {                return false;            }            switch (fieldKey.ToUpper())            {                case "FSELLER":                    DynamicObject dept = this.View.Model.GetValue("FSALDEPTID") as DynamicObject;                    DynamicObject salegroup = this.View.Model.GetValue("FSALGROUPID") as DynamicObject;                    filter += " FIsUse='1' ";                    if (dept != null && Convert.ToInt64(dept["Id"]) > 0)//录入了部门                    {                        filter += string.Format(" And FDeptId={0} ", Convert.ToInt64(dept["Id"]));                    }                    if (salegroup != null && Convert.ToInt64(salegroup["Id"]) > 0)//录入了销售组                    {                        filter += string.Format(" And FOperatorGroupId={0} ", Convert.ToInt64(salegroup["Id"]));                    }                    break;                case "FSALGROUPID":                    DynamicObject seller = null;                    seller = this.View.Model.GetValue("FSELLER") as DynamicObject;                    filter += " FIsUse='1' ";                    if (seller != null && Convert.ToInt64(seller["Id"]) > 0)//录入了销售员                    {                        filter += string.Format(" And Exists (Select 1 From V_BD_SALESMANENTRY SE Where SE.FOperatorGroupID=FENTRYID AND SE.FId={0}) ", Convert.ToInt64(seller["Id"]));                    }                    break;                case "FTCONTACT":                    DynamicObject doCustomer = this.View.Model.DataObject;                    long lCustomerId = Convert.ToInt64(doCustomer["Id"]);                    filter += string.Format(" FCOMPANY = {0}", lCustomerId);                    break;            }            return !string.IsNullOrWhiteSpace(filter);        }        private void SetTaxRegisterCode(string sTaxRegisterCode, int iRow)        {            //string sTaxRegisterCode = this.View.Model.GetValue("FTTAXREGISTERCODE", iRow) as string;            this.View.Model.SetValue("FTAXREGISTERCODE", sTaxRegisterCode);        }        /// <summary>        /// 查询数据库客户联系人填充联系人表体        /// </summary>        private void NewFillContactData(FormResult result)        {            //if (this.View.Model.GetEntryRowCount("FT_BD_CUSTLOCATION") > 0)            //{            //    this.View.Model.DeleteEntryData("FT_BD_CUSTLOCATION");            //    this.View.UpdateView("FT_BD_CUSTLOCATION");            //}            //DynamicObject doCustomer = this.Model.DataObject;            //long lCustomerId = Convert.ToInt64(doCustomer["Id"]);            if (result.ReturnData != null)            {                List<long> lContactIds = result.ReturnData as List<long>;                if (lContactIds == null || lContactIds.Count < 1)                {                    return;                }                                DynamicObjectCollection docContacts = ServiceHelper.SupplierCustomerServiceHelper.GetContactsByCompanyType(                    this.Context, "BD_Customer", lContactIds.ToArray());                                    foreach(DynamicObject contract in docContacts)                {                    // 联系人表体创建一行                    this.View.Model.CreateNewEntryRow("FT_BD_CUSTLOCATION");                    // 获取联系人表体总行数                    int iRowSum = this.View.Model.GetEntryRowCount("FT_BD_CUSTLOCATION");                    this.View.Model.SetValue("FCONTACT", contract["FNAME"], iRowSum - 1);                    this.View.Model.SetValue("FJob", contract["FPOST"], iRowSum - 1);                    this.View.Model.SetValue("FBIZLOCATION", contract["FBIZLOCATION"], iRowSum - 1);                    this.View.Model.SetValue("FOFFICEPHONE", contract["FTEL"], iRowSum - 1);                    this.View.Model.SetValue("FMOBILEPHONE", contract["FMOBILE"], iRowSum - 1);                    this.View.Model.SetValue("FFAX1", contract["FFAX"], iRowSum - 1);                    this.View.Model.SetValue("FContactEmail", contract["FEMAIL"], iRowSum - 1);                    this.View.Model.SetValue("FContactId", contract["FCONTACTID"], iRowSum - 1);                }                this.View.UpdateView("FT_BD_CUSTLOCATION");                            }        }        /// <summary>        /// 删除客户联系人        /// </summary>        private void DeleteCustomerContact()        {            // 获取当前选中的行数组            int[] iRowIndexs = this.View.GetControl<EntryGrid>("FT_BD_CUSTLOCATION").GetSelectedRows();            // 待删除行的客户联系人Id            List<long> listContactId = new List<long>();            if (iRowIndexs.Count() <= 0 || iRowIndexs[0] == -1)            {                this.View.ShowErrMessage(Kingdee.BOS.Resource.ResManager.LoadKDString("请至少选择一个分录数据!", "005023000000583", Kingdee.BOS.Resource.SubSystemType.BASE));            }            else            {this.View.ShowMessage(Kingdee.BOS.Resource.ResManager.LoadKDString("请确认是否删除选定的记录?","005023000000584",Kingdee.BOS.Resource.SubSystemType.BASE),    MessageBoxOptions.YesNo,                                      new Action<MessageBoxResult>((result) =>                                      {                                          if (result == MessageBoxResult.Yes)                                          {                                              foreach (int rowIndex in iRowIndexs)                                              {                                                  long lCustomerContactId = Convert.ToInt64(this.View.Model.GetValue("FContactId", rowIndex));                                                  if (!listContactId.Contains(lCustomerContactId))                                                  {                                                      listContactId.Add(lCustomerContactId);                                                  }                                                  // 页面上删除联系人                                                  this.View.Model.DeleteEntryRow("FT_BD_CUSTLOCATION", rowIndex);                                              }                                              // 数据库中删除联系人                                              bool bIsSuccessful = ServiceHelper.SupplierCustomerServiceHelper.DeleteContactById(this.Context, string.Join(",", listContactId.ToArray()));                                              if (bIsSuccessful)                                              {                                                  this.View.ShowMessage(Kingdee.BOS.Resource.ResManager.LoadKDString("删除该联系人成功!", "005023000000585", Kingdee.BOS.Resource.SubSystemType.BASE));                                              }                                              else                                              {                                                  this.View.ShowMessage(Kingdee.BOS.Resource.ResManager.LoadKDString("删除该联系人失败!", "005023000000586", Kingdee.BOS.Resource.SubSystemType.BASE));                                              }                                          }                                      }));            }        }        private void SetCreateCPAdminButtonStatus()        {            //已审核(或重新审核)&未禁用的客户&还未创建客户门户管理员时,创建管理员按钮才可用。            string documentStatus = Convert.ToString(this.View.Model.GetValue("FDocumentStatus"));            string forbidStatus = Convert.ToString(this.View.Model.GetValue("FForbidStatus"));            string cpAdminCode = Convert.ToString(this.View.Model.GetValue("FCPAdminCode"));            this.View.GetControl("FBtnCreateCPAdmin").Enabled = (documentStatus.EqualsIgnoreCase("C") || documentStatus.EqualsIgnoreCase("D")) && forbidStatus.EqualsIgnoreCase("A") && string.IsNullOrWhiteSpace(cpAdminCode);        }        /// <summary>        /// 根据计划管理参数的参数【启用预留】显示/隐藏客户“客户优先级”字段        /// </summary>        private void SetPriorityVisible()        {            // 获取计划管理参数【启用预留】            bool bIsEnableReserve = Convert.ToBoolean(ServiceHelper.BDCommonServiceHelper.GetSystemProfile(this.Context,this.Context.CurrentOrganizationInfo.ID,"MFG_PLNParam","IsEnableReserve",false));            // 启用预留,显示            if (bIsEnableReserve)            {                this.View.GetControl<FieldEditor>("FPriority").Visible = bIsEnableReserve;            }            else            {                this.View.GetControl<FieldEditor>("FPriority").Visible = bIsEnableReserve;            }        }        #endregion    }}


原创粉丝点击