在Dynamics CRM中使用Bootstrap
我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面的微软最有价值专家(Microsoft MVP),欢迎关注我的微信公众号 MSFTDynamics365erLuoYong ,回复165或者20151023可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!
var service = GetOrganizationService();
var entity = new Entity("webresource");
entity["name"] = "new_/common/fonts/glyphicons-halflings-regular.eot";
entity["displayname"] = "glyphicons-halflings-regular.eot";
using (FileStream fs = File.OpenRead(@"C:\Users\luoyong\Downloads\bootstrap-3.3.5-dist\bootstrap-3.3.5-dist\fonts\glyphicons-halflings-regular.eot"))
{
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, , bytes.Length);
entity["content"] = Convert.ToBase64String(bytes);
}
entity["webresourcetype"] = new OptionSetValue();//XML
service.Create(entity);
static void Main(string[] args)
{
var service = GetOrganizationService();
const string bootstrapBaseDir = @"C:\Users\luoyong\Downloads\bootstrap-3.3.5-dist\bootstrap-3.3.5-dist\";
const string solutionPrefix = "new_";
Dictionary<string, string> files = new Dictionary<string, string>();//bootstrap依赖的Web资源
files.Add("glyphicons-halflings-regular.eot", "fonts");
files.Add("glyphicons-halflings-regular.svg", "fonts");
files.Add("glyphicons-halflings-regular.ttf", "fonts");
files.Add("glyphicons-halflings-regular.woff", "fonts");
files.Add("glyphicons-halflings-regular.woff2", "fonts");
files.Add("bootstrap.min.js", "js");
files.Add("jquery-1.11.3.min.js", "js");
files.Add("bootstrap.min.css", "css");
files.Add("bootstrap-theme.min.css", "css");
//处理css文件,记得要替换fonts文件夹中的内容
foreach (var item in (from item in files where item.Value == "css" select item).ToDictionary(item => item.Key, item => item.Value))
{
var fontEntity = new Entity("webresource");
fontEntity["displayname"] = item.Key;
string text = File.ReadAllText(@bootstrapBaseDir + item.Value + "\\" + item.Key);
foreach (var fontitem in (from fontitem in files where fontitem.Value == "fonts" select fontitem).ToDictionary(fontitem => fontitem.Key, fontitem => fontitem.Value))
{
text = text.Replace(fontitem.Key, fontitem.Key.Replace("-", "_"));
}
File.WriteAllText(@bootstrapBaseDir + item.Value + "\\" + item.Key, text);
using (FileStream fs = File.OpenRead(@bootstrapBaseDir + item.Value + "\\" + item.Key))
{
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, , bytes.Length);
fontEntity["content"] = Convert.ToBase64String(bytes);
}
fontEntity["webresourcetype"] = new OptionSetValue();//CSS
fontEntity["name"] = solutionPrefix + @"/common/css/" + item.Key.Replace("-", "_");
service.Create(fontEntity);
}
//处理fonts文件夹
foreach (var item in (from item in files where item.Value == "fonts" select item).ToDictionary(item => item.Key, item => item.Value))
{
var fontEntity = new Entity("webresource");
fontEntity["displayname"] = item.Key;
using (FileStream fs = File.OpenRead(@bootstrapBaseDir + item.Value + "\\" + item.Key))
{
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, , bytes.Length);
fontEntity["content"] = Convert.ToBase64String(bytes);
}
fontEntity["webresourcetype"] = new OptionSetValue();//XML
fontEntity["name"] = solutionPrefix + @"/common/fonts/" + item.Key.Replace("-", "_");
service.Create(fontEntity);
}
//处理js文件夹
foreach (var item in (from item in files where item.Value == "js" select item).ToDictionary(item => item.Key, item => item.Value))
{
var fontEntity = new Entity("webresource");
fontEntity["displayname"] = item.Key;
using (FileStream fs = File.OpenRead(@bootstrapBaseDir + item.Value + "\\" + item.Key))
{
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, , bytes.Length);
fontEntity["content"] = Convert.ToBase64String(bytes);
}
fontEntity["webresourcetype"] = new OptionSetValue();//javascript
var pattern = @"jquery.*min\.js";//用正则表达式替换juery版本号
Regex rgx = new Regex(pattern);
fontEntity["name"] = solutionPrefix + @"/common/js/" + rgx.Replace(item.Key.Replace("-", "_"),"jquery.min.js");
service.Create(fontEntity);
}
Console.WriteLine("程序运行完成!");
Console.ReadKey();
}
<!DOCTYPE html>
<html>
<head>
<title>微软MVP罗勇测试注释</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../common/css/bootstrap.min.css">
</head>
<body>
<div class="container-fluid">
<table id="notestable" class="table table-striped table-bordered table-hover table-condensed">
<thead>
<tr>
<th class="text-nowrap">序号</th>
<th>注释标题</th>
<th>注释内容</th>
<th>创建人</th>
<th>创建时间</th>
<th>修改人</th>
<th>修改时间</th>
<th>附件名称</th>
<th class="text-nowrap">附件大小(KB)</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<blockquote class="pull-right">这是微软MVP罗勇学习Bootstrap后的第一次练习!<small>Powered by Bootstrap</small></blockquote>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">附件 <small>罗勇使用Bootstrap做的效果</small></h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="../../ClientGlobalContext.js.aspx"></script>
<script type="text/javascript" src="../common/js/jquery.min.js"></script>
<script type="text/javascript" src="../common/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../common/XrmServiceToolkit.min.js"></script>
<script type="text/javascript">
Date.prototype.format = function (fmt) {
var o = {
"M+": this.getMonth() + 1,//月份
"d+": this.getDate(),//日
"h+": this.getHours(),//小时
"m+": this.getMinutes(),//分
"s+": this.getSeconds()//秒
};
if (/(y+)/.test(fmt))
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt))
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ?
(o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
} function ShowAttachmentByNoteId(NoteId, MimeType) {
if (MimeType.indexOf("image") > -1) { $(".modal-body").children().remove();
var loadingBtn = $("<button type='button' class='btn btn-info btn-block'>正在加载...</button>");
loadingBtn.appendTo($(".modal-body"));
XrmServiceToolkit.Rest.Retrieve(
NoteId,
"AnnotationSet",
"DocumentBody",
null,
function (result) {
$(".modal-body").children().remove();
var DocumentBody = result.DocumentBody;
var img = $("<img />");
img.attr("alt", "Embedded Image");
img.addClass("img-thumbnail");
img.attr("src", "data:" + MimeType + ";base64," + DocumentBody);
img.appendTo($(".modal-body"));
},
function (error) {
alert(error.message);
},
true
);
}
else if (MimeType.indexOf("officedocument.presentationml.presentation") > -1 || MimeType.indexOf("officedocument.spreadsheetml.sheet") > -1 || MimeType.indexOf("officedocument.wordprocessingml.document") > -1) {//office文档
var warningBtn = $("<button type='button' class='btn btn-info btn-block'>请在新窗口中查看!</button>");
$(".modal-body").children().remove();
warningBtn.appendTo($(".modal-body"));
window.open("https://view.officeapps.live.com/op/view.aspx?src=" + encodeURIComponent("http://mvpluoyong.azurewebsites.net/GetAnnotationDocument.ashx?AnnotationId=" + NoteId));
}
else if (MimeType.indexOf("pdf") > -1) {
var warningBtn = $("<button type='button' class='btn btn-info btn-block'>请在新窗口中查看!</button>");
$(".modal-body").children().remove();
warningBtn.appendTo($(".modal-body"));
window.open("http://mvpluoyong.azurewebsites.net/GetAnnotationDocument.ashx?AnnotationId=" + encodeURIComponent(NoteId));
}
else {
var warningBtn = $("<button type='button' class='btn btn-block btn-warning'>暂时不支持这种文件类型附件的查看!</button>");
$(".modal-body").children().remove();
warningBtn.appendTo($(".modal-body"));
}
} $(function () {
var clientUrl = GetGlobalContext().getClientUrl();
//var id = window.parent.Xrm.Page.data.entity.getId(); //这种方法可以获取表单中的很多信息,包括id
var match = RegExp('[?&]id=([^&]*)').exec(window.location.search);//这里是外接通过url传递id的值过来
var id = match && decodeURIComponent(match[1].replace(/\+/g, ' '));
match = RegExp('[?&]typename=([^&]*)').exec(window.location.search);
var typename = match && decodeURIComponent(match[1].replace(/\+/g, ' '));
XrmServiceToolkit.Rest.RetrieveMultiple(
"AnnotationSet",
"?$select=AnnotationId,Subject,NoteText,MimeType,FileName,FileSize,IsDocument,CreatedOn,CreatedBy,ModifiedOn,ModifiedBy&$filter=ObjectTypeCode eq '" + typename + "' and ObjectId/Id eq guid'" + id + "'&$orderby=CreatedOn asc",
function (results) {
for (var i = 0; i < results.length; i++) {
var tr = $("<tr></tr>");
tr.appendTo($("#notestable tbody"));
var td = $("<td class='text-center'>" + (i + 1) + "</td>");
td.appendTo(tr);
td = $("<td>" + (results[i].Subject == null ? "" : results[i].Subject) + "</td>");
td.appendTo(tr);
td = $("<td><a data-toggle='tooltip' title='点击我在新窗口中查看或者编辑本注释全部内容!' href='" + clientUrl + "/main.aspx?etn=annotation&pagetype=entityrecord&id=%7B" + results[i].AnnotationId + "%7D' target='_blank'>" + results[i].NoteText + (results[i].IsDocument ? " <span class='glyphicon glyphicon-paperclip'></span>" : "") + "</a></td>");
td.appendTo(tr);
td = $("<td>" + results[i].CreatedBy.Name + "</td>");
td.appendTo(tr);
td = $("<td>" + results[i].CreatedOn.format('yyyy-MM-ddThh:mm:ssZ') + "</td>");
td.appendTo(tr);
td = $("<td>" + results[i].ModifiedBy.Name + "</td>");
td.appendTo(tr);
td = $("<td>" + results[i].ModifiedOn.format('yyyy-MM-ddThh:mm:ssZ') + "</td>");
td.appendTo(tr);
td = $("<td>" + (results[i].FileName == null ? "" : ("<a href='#' data-toggle='modal' data-target='#myModal' data-annotationid='" + results[i].AnnotationId + "' data-mimetype='" + results[i].MimeType + "'>" + results[i].FileName + "</a>") + "</td>"));
td.find("a").click(function () {
ShowAttachmentByNoteId($(this).attr("data-annotationid"), $(this).attr("data-mimetype"));
});
td.appendTo(tr);
td = $("<td>" + (results[i].FileSize == null ? "" : Math.round((results[i].FileSize) / 1024)) + "</td>");
td.appendTo(tr);
}
},
function (error) {
alert(error.message);
},
function () {
},
true
);
});
</script>
</body>
</html>
7. 引用效果,引用靠右对齐。
在Dynamics CRM中使用Bootstrap的更多相关文章
- Dyanmics CRM您无法登陆系统。原因可能是您的用户记录或所属的业务部门在Microoft Dynamics CRM中已被禁用
当在操作CRM时,做不论什么的写操作包含创建数据.更新数据.都会提示以下截图中的错误:"您无法登陆系统.原因可能是您的用户记录或所属的业务部门在Microoft Dynamics CRM中已 ...
- Dynamics CRM中一个查找字段引发的【血案】
摘要: 本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复267或者20180311可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyon ...
- Dynamics CRM中的地址知多D?
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复169或者20151105可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! CRM中的地址以前不是很了解,定 ...
- 在Dynamics CRM中自定义一个通用的查看编辑注释页面
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复162或者20151016可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! 注释在CRM中的显示是比较特别, ...
- Dynamics CRM中的注释(Note)及RollupRequest消息初探
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复161或者20151015可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! 注释,这个实体的架构名称是Ann ...
- Dynamics CRM中的操作(action)是否是一个事务(transaction)?
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复168或者20151104可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! 以前的博文 微软Dynamics ...
- Dynamics CRM 中Web API中的深度创建(Deep Insert)
我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...
- 您无法登陆系统。原因可能是您的用户记录或所属的业务部门在Microoft Dynamics CRM中已被禁用
问题发生在CRM 4.0 上 1 用户所在办事处及办事处上级被禁用. 2 如果已经重新启用了,还是报这个错误. 可以把停用的办事处及相关下级再重新--停用--启用一次试试. 3 如果还是报错,查看是否 ...
- 在Dynamics CRM 2015中通过3CX插件(以及3CX windows phone)拨出电话
背景 在On-premises部署的Dynamics CRM中实现通过网页拨通客户电话的功能 要点 3CX 提供了开箱即用的Dynamics CRM Solution,只需要在Microsoft Dy ...
随机推荐
- SpringBoot整合freemarker模板
一.目录展示 二.导入依赖 三.application.properties配置文件 四.在src/main/resource/templates文件夹中创建HelloFreeMarker.ftl文件 ...
- 机器学习-Python 01
机器学习中最常用最流行的语言工具现阶段应该是Python, 这篇文章主要介绍一些常用的Python语法知识.本篇博文适合那些有其他语言基础的程序员们,如果一点基础都没有,我建议先跳过.博主以前是做移动 ...
- 信鸽推送Push API
目录 信鸽推送 push API 0. 基本 push 1. 根据 token list,推送到android和ios 2. 推送到android和ios 所有用户 信鸽推送 push API 参考: ...
- Java修炼——四种方式解析XML_SAX
四种方式解析XML:DOM JDOM DOM4J SAX 先写一个XML栗子: <?xml version="1.0" encoding="U ...
- linux运维中经常使用的目录和文件讲解
第9章 linux中目录结构 9.1 linux中的常见目录和解释说明 ID 目录 说明 1 bin 命令文件保存的地方 2 sbin 只有root用户才可以使用的命令 3 Boot(了解即可) Li ...
- Ceph 架构以及原理分析
一.架构 Ceph在一个统一的系统中独特地提供对象,块和文件存储. Ceph高度可靠,易于管理且免费. Ceph的强大功能可以改变您公司的IT基础架构以及管理大量数据的能力. Ceph提供了非凡的可扩 ...
- 正则去掉html标签之间的空格、换行符、tab符,但是保留html标签内部的属性空格
今天遇到一个比较少见的去空格: 正则去掉html标签之间的空格.换行符.tab符,但是保留html标签内部的属性空格 JS 举例: "<a href='baidu.com' name= ...
- 《项目实战》从Spring开始说起
引导 从今天开始,我们正式进入项目实战系列,我们会从项目架构的搭建,以及如何解决三高问题(高并发.高可用.高性能),源码会同步进行更新,欢迎大家持续关注 https://gitee.com/liupa ...
- 详谈springboot启动类的@SpringBootApplication注解
前几天我们学会了如何创建springboot项目今天我们说一下他是怎么运行的为什么不需要我们再去编写繁重的配置文件的 @SpringBootApplication 首先我们看一下这个注解,他是用来标注 ...
- 【Vuejs】350- 学习 Vue 源码的必要知识储备
前言 我最近在写 Vue 进阶的内容.在这个过程中,有些人问我看 Vue 源码需要有哪些准备吗?所以也就有了这篇计划之外的文章. 当你想学习 Vue 源码的时候,需要有扎实的 JavaScript 基 ...