码迷,mamicode.com
首页 > Windows程序 > 详细

4、CRM2011编程实战——将窗体中指定控件的值做处理后更新到另一个字段中

时间:2014-07-29 17:54:52      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   java   os   strong   io   

需求:将接报时间加上到期提醒时间后得到的值,更新到字段“到期截止时间”

bubuko.com,布布扣

Js调用:

//设置到期截止时间
    function setDeadLine(){
    var recordId = Xrm.Page.data.entity.getId();
    var entityName = Xrm.Page.data.entity.getEntityName();
    var reportedTime = Xrm.Page.getControl("hxcs_fdatetimeofrequesthelp").getAttribute().getValue().toLocaleString();
    var remindTime =Xrm.Page.getControl("hxcs_fremindtime").getAttribute().getText();
    $.post("/isv/Handlers/SetRemindHandler.ashx", { "recordId":recordId,"entityName":entityName,"reportedTime": reportedTime,"remindTime":remindTime}, function(data){});
}

一般处理程序SetRemindHandler.ashx,代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using System.Net;
using System.ServiceModel.Description;
using System.Configuration;

namespace IsWaterWeb
{
    /// <summary>
    /// SetRemindHandler 的摘要说明
    /// </summary>
    public class SetRemindHandler : IHttpHandler
    {
        IOrganizationService _service = null;
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string recordId=context.Request["recordId"];
            string entityName=context.Request["entityName"];
            string reportedTime = context.Request["reportedTime"]; //接报时间
            string remindTime = context.Request["remindTime"]; //到期提醒时间(h)

            if(!string.IsNullOrEmpty(reportedTime)&&!string.IsNullOrEmpty(remindTime))
            {
                DateTime rTime = Convert.ToDateTime(reportedTime);
                double hourCounts = Convert.ToDouble(remindTime);
                DateTime deadline = rTime.AddHours(hourCounts);

                _service = GetOrganization();
                Entity entity = new Entity();
                entity.Id=Guid.Parse(recordId);
                entity.LogicalName=entityName;
                entity.Attributes["hxcs_fdeadline"] = deadline;
                _service.Update(entity);
            }
        }

        public IOrganizationService GetOrganization()
        {
            String UserName = ConfigurationManager.AppSettings["LoginName"];
            String Password = ConfigurationManager.AppSettings["LoginPwd"];
            string url=ConfigurationManager.AppSettings["organizationServiceUrl"];
            Uri uri = new Uri(url);

            var cred = new ClientCredentials();
            //cred.Windows.ClientCredential = new NetworkCredential("Xiaozhou", "Zhou123.");
            cred.Windows.ClientCredential = new NetworkCredential(UserName, Password);

            OrganizationServiceProxy _proxy = new OrganizationServiceProxy(uri, null, cred, null);
            IOrganizationService _service = (IOrganizationService)_proxy;
            return _service;
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

注意:记得将一般处理程序SetRemindHandler.ashx放到服务器目录:C:\Program Files\Microsoft Dynamics CRM\CRMWeb\ISV\Handlers,如果没有Handlers目录,可以新建。


4、CRM2011编程实战——将窗体中指定控件的值做处理后更新到另一个字段中,布布扣,bubuko.com

4、CRM2011编程实战——将窗体中指定控件的值做处理后更新到另一个字段中

标签:des   style   blog   http   java   os   strong   io   

原文地址:http://blog.csdn.net/zouyujie1127/article/details/38272383

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!