代码如下:
using GF_Plugin.Helper;
using Microsoft.Xrm.Sdk;
/// <summary>
/// 概述:发送短信功能
/// 文件:GF_Plugin.MemberApplySendCustSMS
/// 作者:詹詹 创建时间:2016/7/28 15:19:49
/// 描述:
/// <summary>
using System;
using System.Data.OracleClient;
namespace GF_Plugin
{
public class MemberApplySendCustSMS : PluginBase, IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
//插件初始化
base.Initialize(serviceProvider);
Guid entityId;
string logicalName;
if (targer == null)
{
entityId = targerref.Id;
logicalName = targerref.LogicalName;
}
else
{
entityId = targer.Id;
logicalName = targer.LogicalName;
}
if (logicalName == "gf_member")
{
if (isCreate)//(isUpdate)是更新记录还是创建记录
{
try
{
// prettarger=(Entity)context.PreEntityImages["Image"]; //update时要
posttarger = (Entity)context.PostEntityImages["Image"];
var memberId = posttarger.Id;//获得gf_memberId
var cellNo = posttarger.Contains("gf_cellphonenumber") ? posttarger["gf_cellphonenumber"].ToString() : null;//获得手机号
var accountName = posttarger.Contains("gf_name") ? posttarger["gf_name"].ToString() : null;//获得姓名
Guid accountid = ((EntityReference)posttarger["gf_accountid"]).Id;//获得客户guid
//判断该客户是否存在会员申请记录
Entity memberapply = GetEntity("gf_memberapply", "gf_accountid", accountid.ToString());
if (null != memberapply && memberapply.Id != Guid.Empty )
{
//发送短信给客户
var currentTime = System.DateTime.Now;//插件获得当前系统时间
var currenttime = (System.DateTime.Now).ToString("yyyy-MM-dd");//插件获得当前系统时间
if (cellNo != null)
{
//var message = "尊敬的" + accountName + "您已成功注册会员";
string connString = "User ID=xxx;Password=xxx;Data Source=(DESCRIPTION = (ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xxx.xx.xx)(PORT = xxxx))) (CONNECT_DATA = (SERVICE_NAME = orcl)))";
OracleConnection conn = new OracleConnection(connString);
conn.Open();
string sql = "insert into 表名(SMContent, SendTarget, ServiceID, RequestTime, RcompleteTimeBegin, RcompleteTimeEnd, RcompleteHourBegin, RcompleteHourEnd, Roadby) values('" + message + "', '" + cellNo + "', '" + currentTime.Ticks.ToString() + "',to_date('" + currenttime + "','yyyy-mm-dd'),to_date('" + currenttime + "','yyyy-mm-dd'),to_date('" + currenttime + "','yyyy-mm-dd'),0,xxxx,1)";
OracleCommand oc = new OracleCommand(sql, conn);
int result = oc.ExecuteNonQuery();
}
}
}
catch (Exception e)
{
//throw (e);
}
}
}
}
}
}
以上为插件代码,隐去了一些信息。
1.首先创建这么个类,取名test.cs。
2.利用插件工具上传插件。这里用update。sandbox是沙盒模式,据说可以调试,但是具体如何调试我还不会。。。
所以我选的是none;第二项选择database.
3.上传完插件后,在插件那里先create a step....然后创建image属性,这样就可以了。