• MSCRM4 添加黑名单代码


    getcontactid.js 代码:

    //window.onload = getGuid;
    function getGuid() {
    var selectValues;
    var sGuids = "";
    if (window.dialogArguments) {
    selectValues = new Array(window.dialogArguments.length - 1);
    } else {
    alert("选择记录");
    window.close();
    }
    selectValues = window.dialogArguments;
    if (selectValues != null && selectValues != "undefined") {
    for (i = 0; i < selectValues.length; i++) {
    sGuids += selectValues[i] + ":";
    }
    document.getElementById("HiddenFieldGuid").value = sGuids;
    }
    else {
    alert("选择记录");
    window.close();
    }
    }
    function closewin() {
    this.window.close();
    }

    addBlacklistTip.aspx:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="addBlacklistTip.aspx.cs" Inherits="Frensworkz.CRM.XCMGCC.Web.ISV.tanhua.addBlacklistTip" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <base target="_self"/>
    <title>添加黑名单历史记录提示</title>
    <link href="/ISV/tanhua/style/addblacklist.css" rel="stylesheet" type="text/css" />
    <script src="/ISV/tanhua/js/getcontactid.js" type="text/javascript" language="javascript"></script>
    </head>
    <body onload="getGuid();">
    <form id="form1" runat="server">
    <div class="ContainerTip">
    <div class="topTip">
    <div class="ms-crm-dialog-header-title">Confirm Add Blacklist</div>
    <div class="ms-crm-Dialog-Header-Desc">You have selected 1 Contact for Add Bad.</div>
    </div>
    <div class="ms-crm-dialog-main">
    <div id="divWarning">The system will add this record. This action cannot be undone. To continue, click OK.</div>
    <div class="hide">
    <asp:HiddenField ID="HiddenFieldGuid" runat="server"/>
    </div>
    </div>

    <div class="ms-crm-dialog-footer">
    <div class="btnyesno">
    <asp:Button ID="btnYes" runat="server" Text="YES" onclick="btnYes_Click" CssClass="buttonok"/>
    <asp:Button ID="btnNo" runat="server" Text="NO" OnClientClick="closewin();" CssClass="buttonok"/>
    </div>
    </div>

    </div>
    </form>
    </body>
    </html>

    C#代码:

    using System;
    using System.Collections.Generic;

    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    using Microsoft.Crm.Sdk;
    using Microsoft.Crm.Sdk.Utility;
    using Microsoft.Crm.Sdk.Query;
    using Microsoft.Crm.Sdk.Metadata;
    using Microsoft.Crm.SdkTypeProxy;
    using Frensworkz.CRM.XCMGCC.Web.Common;

    namespace Frensworkz.CRM.XCMGCC.Web.ISV.tanhua
    {
    public partial class addBlacklistTip : BasePage
    {


    protected void Page_Load(object sender, EventArgs e)
    {

    }

    //是
    protected void btnYes_Click(object sender, EventArgs e)
    {
    try
    {
    string hiddenValue = string.Empty;
    if (HiddenFieldGuid.Value.ToString() == string.Empty) return;
    hiddenValue = HiddenFieldGuid.Value.ToString();
    string[] sarray = hiddenValue.Split(':');

    foreach (var i in sarray)
    {
    if (i == string.Empty) continue;
    Guid ccId = Guid.Empty;
    ccId = new Guid(i.ToString());

    //获取service
    var service = OrgService;


    //查询联系人的状态描述,main phone,telephone1
    DynamicEntity dy = Query.instance.GetEntityrAttr(service, "contact", ccId, new string[] { "statuscode", "mobilephone", "telephone1" });

    string telephone = string.Empty;
    if (dy.Properties.Contains("mobilephone"))
    {
    telephone = dy.Properties["mobilephone"].ToString();
    }
    else if (dy.Properties.Contains("telephone1"))
    {
    telephone = dy.Properties["telephone1"].ToString();
    }


    if (telephone == string.Empty)
    {
    //修改联系人的状态描述的值
    Moniker moniker2 = new Moniker();
    moniker2.Id = ccId;
    moniker2.Name = EntityName.contact.ToString();
    Query.instance.SetStateDynamicEntity(service, moniker2, ContactState.Inactive.ToString(), 2);
    }

    if (telephone != string.Empty)
    {
    BusinessEntityCollection blacklists = Query.instance.QueryByAttributee(service, "new_blacklist", new string[] { "new_phone" }, new string[] { telephone }, null, null, new string[] { "new_blacklistid" });
    //该联系人已经添加到黑名单,直接禁用
    if (blacklists.BusinessEntities.Count > 0)
    {
    //修改联系人的状态描述的值
    Moniker moniker = new Moniker();
    moniker.Id = ccId;
    moniker.Name = EntityName.contact.ToString();
    Query.instance.SetStateDynamicEntity(service, moniker, ContactState.Inactive.ToString(), 2);
    }

    //该联系人没有添加到黑名单,则添加到黑名单历史记录
    if (blacklists.BusinessEntities.Count <= 0)
    {
    //修改联系人的状态描述的值
    Moniker moniker1 = new Moniker();
    moniker1.Id = ccId;
    moniker1.Name = EntityName.contact.ToString();
    Query.instance.SetStateDynamicEntity(service, moniker1, ContactState.Inactive.ToString(), 2);

    //把联系人记录添加到黑名单中
    DynamicEntity blacklist = new DynamicEntity("new_blacklist");

    blacklist.Properties["new_phone"] = telephone;

    Guid bid = Query.instance.CreateDynamicEntity(service, blacklist);//创建记录到黑名单
    }
    }
    ExecScritp("window.close();");

    }

    }
    catch (Exception ex)
    {
    throw new Exception(ex.Message);
    }

    }
    }
    }

    css:

    body{background-color:#E3EFFF;}
    form{ margin:0; padding:0;}
    .ContainerTip{ 590px;height:211px; margin:0 auto;}
    .topTip{background-color:#6693CF;color:#ffffff;border-bottom:1px solid #6693CF;height:51px;vertical-align:top;padding:5px;}
    .ms-crm-dialog-header-title{font-weight:bold;font-size:13px;padding-left:5px;}
    .ms-crm-Dialog-Header-Desc{padding-top:4px;padding-left:5px;}
    .ms-crm-dialog-main{height:110px;vertical-align:top;padding:5px;overflow:auto;border-bottom:solid 1px #A7CDF0;}
    .ms-crm-dialog-footer{height:30px;padding:10px 0 10px 10px;background-color:#E3EFFF;border-top:1px solid #ffffff; line-height:25px;}
    .btnyesno{ 184px; height:25px;float:right;}
    .hide{ padding:0; margin:0;}
    .buttonok{font-family: Tahoma;font-size: 11px;line-height: 18px;height: 20px; 84px;text-align: center;cursor: pointer;border: 1px #3366CC solid;background-color: #CEE7FF;background-image: url('images/btn_rest.gif');background-repeat: repeat-x;border: 1px #3366CC solid;overflow: visible; padding:0 5px 0 5px;}

  • 相关阅读:
    小程序(1)
    手机端放在线条中间的标题
    不定长度导航的两端对齐
    扇形导航菜单
    个性搜索框
    javascript数组原型方法
    jquery插件开发的demo
    监听表单中的内容变化
    mui中的关闭页面的几种方法
    css之伪类选择器:before :after(::before ::after)
  • 原文地址:https://www.cnblogs.com/allenhua/p/2740069.html
Copyright © 2020-2023  润新知