Guest User

Untitled

a guest
Oct 3rd, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.79 KB | None | 0 0
  1. <%@ WebHandler Language="C#" Class="schedulerConnector" %>
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Services;
  8. using dhtmlxConnectors;
  9. using System.Configuration;
  10. using Bluesoft;
  11. using CMS.Helpers;
  12. using CMS.UIControls;
  13. using CMS.DataEngine;
  14. using CMS.Membership;
  15.  
  16. /// <summary>
  17. /// Connector body
  18. /// </summary>
  19. [WebService(Namespace = "http://tempuri.org/")]
  20. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  21. public class schedulerConnector : dhtmlxRequestHandler
  22. {
  23.     public override IdhtmlxConnector CreateConnector(HttpContext context)
  24.     {
  25.         var connector = new dhtmlxSchedulerConnector(
  26.               "BluesoftCRM_CalendarEvent"
  27.             , "CalendarEventID"
  28.             , dhtmlxDatabaseAdapterType.SqlServer2005
  29.             , ConfigurationManager.ConnectionStrings["CMSConnectionString"].ConnectionString
  30.             , "CalendarEventStartDate"
  31.             , "CalendarEventEndDate"
  32.             , "CalendarEventText as text, CalendarEventDetails as details, CalendarEventRecType as rec_type, CalendarEventEventPid as event_pid, CalendarEventEventLength as event_length, CalendarEventUserID"
  33.         );
  34.  
  35.         // attach handlers
  36.         connector.BeforeProcessing += new EventHandler<DataActionProcessingEventArgs>(onBeforeProcessing);
  37.         connector.AfterProcessing += new EventHandler<DataActionProcessingEventArgs>(onAfterProcessing);
  38.  
  39.         return connector;
  40.     }
  41.  
  42.     // is called delete_related in PHP example
  43.     protected void onBeforeProcessing(object sender, DataActionProcessingEventArgs e)
  44.     {
  45.         string type = e.DataAction.Data[Connector.DecodeField("rec_type")].ToString();
  46.  
  47.         if ((e.DataAction.ActionType == ActionType.Deleted || e.DataAction.ActionType == ActionType.Updated) && !string.IsNullOrEmpty(type))
  48.         {
  49.             Connector.Request.Adapter.ExecuteScalar("DELETE FROM BluesoftCRM_CalendarEvent WHERE CalendarEventEventPid='" + e.DataAction.PrimaryKeyValue.ToString() + "'");
  50.         }
  51.         if (e.DataAction.ActionType == ActionType.Deleted && e.DataAction.Data[Connector.DecodeField("event_pid")].ToString() != "0")
  52.         {
  53.             Connector.Request.Adapter.ExecuteScalar("UPDATE BluesoftCRM_CalendarEvent SET CalendarEventRecType='none' WHERE CalendarEventID='" + e.DataAction.PrimaryKeyValue.ToString() + "'");
  54.             e.DataAction.SetCompleted();
  55.         }
  56.     }
  57.  
  58.     // is called insert_related in PHP example
  59.     protected void onAfterProcessing(object sender, DataActionProcessingEventArgs e)
  60.     {
  61.         if (e.DataAction.ActionType == ActionType.Inserted && e.DataAction.Data[Connector.DecodeField("rec_type")].ToString() == "none")
  62.         {
  63.             e.DataAction.ChangeActionType(ActionType.Deleted);
  64.         }
  65.     }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment