public HttpResponseMessage GetPushNoticeLog(string workListAlertID)
        {
            try
            {
                AlarmRuleSetController ctrl = new AlarmRuleSetController();
                List<PushNoticeLogInfo> lstCode = ctrl.FetchPushNoticeLog(workListAlertID);
                // 產生JSON 字串的範例
                List<Row> rowlist = new List<Row>() { };
                double UTCOffset = PortalSettings.TimeZone.BaseUtcOffset.TotalHours;
                for (var i = 0; i < lstCode.Count; i++)
                {
                    Row rowobj = new Row();
                    var stringList = new List<string>();
                    rowobj.id = i;
                    stringList.Add(i.ToString());
                    if (string.IsNullOrEmpty(lstCode[i].UserId))
                        stringList.Add(lstCode[i].Dnn_Logic);
                    else
                        stringList.Add(lstCode[i].UserId);
                    stringList.Add(lstCode[i].FunctionName);
                    stringList.Add(string.Format(Localization.GetString("DateTimeFormat", Localization.SharedResourceFile), Convert.ToDateTime(lstCode[i].EventTime).AddHours(UTCOffset)));
                    rowobj.cell = stringList;
                    rowlist.Add(rowobj);
                }

                var jsonToReturn = new
                {
                    rows = rowlist
                };

                return Request.CreateResponse(HttpStatusCode.OK, jsonToReturn);
            }
            catch (Exception exc)
            {
                return Request.CreateResponse(HttpStatusCode.OK, exc.Message);
            }
        }
        public HttpResponseMessage RegisterBaiduPhone(string RegisterID, string ChannelID)
        {
            try
            {
                AlarmRuleSetController CreatePhoneRecordCtrl = new AlarmRuleSetController();
                PhoneRecordInfo Info = new PhoneRecordInfo();//宣告一個物件來接
                UserInfo UInfo = UserController.GetCurrentUserInfo();  //DNN 本身物件取得基本資料

                Info.PortalId = PortalSettings.PortalId;
                Info.DnnLogic = UInfo.Username;
                Info.RegisterID = RegisterID;
                Info.UserId = UInfo.UserID;

                //---------將資料放到物件------------------------------------------------------------------------               

                CreatePhoneRecordCtrl.InsertBaiduPhoneRegister(Info);//塞入手機紀錄資料

                var jsonToReturn = new
                {
                    InsertFillLog = "Success",
                };

                return Request.CreateResponse(HttpStatusCode.OK, jsonToReturn);
            }
            catch (Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.OK, ex.Message);
            }
        }
        public HttpResponseMessage CreatePhoneRecord(string PhoneMailLogic, string RegisterID)
        {
            try
            {
                AlarmRuleSetController CreatePhoneRecordCtrl = new AlarmRuleSetController();
                PhoneRecordInfo Info = new PhoneRecordInfo();//宣告一個物件來接
                UserInfo UInfo = UserController.GetCurrentUserInfo();

                Info.PortalId = PortalSettings.PortalId;
                Info.DnnLogic = UInfo.Username;
                Info.PhoneMailLogic = PhoneMailLogic;
                Info.RegisterID = RegisterID;
                Info.UserId = UInfo.UserID;


                //int result = CreatePhoneRecordCtrl.ChkPhoneRecord(Info);//判斷是否可新增手機紀錄資料
                //string flag = "";
                //return Request.CreateResponse(HttpStatusCode.OK, result);

                //return Request.CreateResponse(HttpStatusCode.OK, result);

                //---------將資料放到物件------------------------------------------------------------------------               

                //if (result.Equals(1))
                //{
                  //  flag = "Success";
                CreatePhoneRecordCtrl.InsertPhoneRecord(Info);//塞入手機紀錄資料
                //}
                //else
                  //  flag = "Fail";
                var jsonToReturn = new
                {
                    InsertFillLog = "Success",
                };

                return Request.CreateResponse(HttpStatusCode.OK, jsonToReturn);
            }
            catch (Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.OK, ex.Message);
            }
        }
        public HttpResponseMessage SendPhoneGCM(string DeviceID, string AlertRuleID, string EventTime, string WorkListAlertID)
        {
            try
            {
                AlarmRuleSetController CreatePhoneRecordCtrl = new AlarmRuleSetController();
                PhoneGCMInfo Info = new PhoneGCMInfo();//宣告一個物件來接
                //UserInfo UInfo = UserController.GetCurrentUserInfo();
                //string InfoHours = PortalSettings.TimeZone.BaseUtcOffset.TotalHours.ToString();
                //return Request.CreateResponse(HttpStatusCode.OK, InfoHours);
                DateTime dt = Convert.ToDateTime(EventTime);
                dt = dt.AddHours(PortalSettings.TimeZone.BaseUtcOffset.TotalHours);
                Info.DeviceID = DeviceID;
                Info.AlertRuleID = AlertRuleID;
                Info.EventTime = dt.ToString("yyyy-MM-dd HH:mm:ss");
                Info.userID = "";
                Info.RegID = "";
                Info.WorkListAlertID = WorkListAlertID;
                //Info.RegisterID = RegisterID;
                //Info.UserId = UInfo.UserID;
                 


                //int result = CreatePhoneRecordCtrl.ChkPhoneRecord(Info);//判斷是否可新增手機紀錄資料
                //string flag = "";
                //return Request.CreateResponse(HttpStatusCode.OK, result);

                //return Request.CreateResponse(HttpStatusCode.OK, result);

                //---------將資料放到物件------------------------------------------------------------------------               

                //if (result.Equals(1))
                //{
                //  flag = "Success";
                CreatePhoneRecordCtrl.ChkPhoneGCM(Info);//找出手機紀錄資料  2015/5/13 先暫停

                CreatePhoneRecordCtrl.SendPhoneAPNS(Info); //發送 IOS APNS 資料

                CreatePhoneRecordCtrl.SendPhoneBaidu(Info);  //發送 Baidue 資料

                //}
                //else
                //  flag = "Fail";
                var jsonToReturn = new
                {
                    InsertFillLog = "Success",
                };

                return Request.CreateResponse(HttpStatusCode.OK, jsonToReturn);
            }
            catch (Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.OK, ex.Message);
            }
        }
        public HttpResponseMessage GetList(int moduleID, string CreateBy, int page, int rows, string sidx, string sord, string filters = "", string portalID = "")
        {
            double UTCOffset = PortalSettings.TimeZone.BaseUtcOffset.TotalHours;
            Type objectType = Type.GetType("Keywin.DNN.Modules.Common.InternalService.Components.InternalServiceController, Keywin.DNN.Modules.Common.InternalService", true, true);
            Object objComponent = Activator.CreateInstance(objectType);
            MethodInfo mi = objectType.GetMethod("FetchSubPortalByPortalID");
            int pID = PortalSettings.PortalId;
            if (!string.IsNullOrEmpty(portalID)) pID = int.Parse(portalID);
            object[] param = { pID };
            List<int> portals = (List<int>)mi.Invoke(objComponent, param);
            portals.Add(pID);

            List<int> modules = new List<int>();
            //modules.Add(moduleID);
            ModuleController mc = new ModuleController();
            TabController tc = new TabController();

            foreach (int subPortalID in portals)
            {
                TabCollection alltc = tc.GetTabsByPortal(subPortalID);
                foreach (TabInfo tinfo in alltc.Values)
                {
                    bool canView = DotNetNuke.Security.Permissions.TabPermissionController.CanViewPage(tinfo);
                    Dictionary<int, ModuleInfo> allmcInTab = mc.GetTabModules(tinfo.TabID);
                    foreach (ModuleInfo minfo in allmcInTab.Values)
                    {
                        if (minfo.FriendlyName.Equals(Constants.ComponentName))
                            modules.Add(minfo.ModuleID);
                    }
                }

            }

            //condition
            string condition = null;
            if (!string.IsNullOrEmpty(filters))
            {
                System.Collections.ArrayList al;
                System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                jqGridUtil.Filters f = serializer.Deserialize<jqGridUtil.Filters>(filters);
                al = new System.Collections.ArrayList(f.rules.Count);
                foreach (jqGridUtil.Rule rule in f.rules)
                {
                    if (!string.IsNullOrEmpty(rule.data))
                    {
                        al.Add(jqGridUtil.GetSearchString(rule.field, rule.data, rule.op));
                    }
                }
                condition = string.Join(string.Format(" {0} ", f.groupOp), al.ToArray());
            }

            if (CreateBy != null)
            {
                if (condition == null)
                    condition = "CreateBy = " + CreateBy;
                else
                    condition = condition + " AND CreateBy = " + CreateBy;
            }

            try
            {
                AlarmRuleSetController ctrl = new AlarmRuleSetController();

                //int totalCount = ctrl.GetCount(moduleID, condition);
                //List<AlarmRuleSetInfo> lstCode = ctrl.FetchAll(moduleID, page, rows, sidx, sord, condition);
                int totalCount = ctrl.GetCountForModules(modules, condition);
                List<AlarmRuleSetInfo> lstCode = ctrl.FetchAllForModules(modules, page, rows, sidx, sord, condition);

                int totalPage = 0;
                if (totalCount > 0)
                {
                    totalPage = totalCount / rows;
                    if ((totalCount % rows) > 0) totalPage += 1;
                }
                else
                {
                    totalPage = 0;
                }
                if (page > totalPage) page = totalPage;

                // 產生JSON 字串的範例
                List<Row> rowlist = new List<Row>() { };

                for (var i = 0; i < lstCode.Count; i++)
                {
                    Row rowobj = new Row();
                    var stringList = new List<string>();
                    rowobj.id = i;

                    stringList.Add(i.ToString());
                    stringList.Add(lstCode[i].ModuleID.ToString());
                    stringList.Add(lstCode[i].AlarmRuleSetID.ToString());

                    // Start User Define Parameter For WebAPI
                    stringList.Add(lstCode[i].RuleName.ToString());
                    //stringList.Add(lstCode[i].AlarmType.ToString());
                    stringList.Add(lstCode[i].AlarmTypeName.ToString());
                    stringList.Add(lstCode[i].SeverityCode.ToString());
                    //stringList.Add(lstCode[i].Notifier.ToString());
                    if (!string.IsNullOrEmpty(lstCode[i].Notifier))
                    {
                        ListController lc = new ListController();
                        ListEntryInfo lei = null;
                        string[] ary = lstCode[i].Notifier.Split(',');
                        ArrayList al = new ArrayList(ary.Length);
                        foreach (string item in ary)
                        {
                            lei = lc.GetListEntryInfo(Convert.ToInt32(item));
                            al.Add(lei.Text);
                        }
                        stringList.Add(string.Join(",", al.ToArray()));
                    }
                    else { stringList.Add(string.Empty); }
                    stringList.Add(lstCode[i].CustomCode.ToString());
                    stringList.Add(lstCode[i].HandlerName.ToString());
                    stringList.Add(lstCode[i].State.ToString());
                    stringList.Add(lstCode[i].GenerateTask.ToString());
                    stringList.Add(lstCode[i].Rules.ToString());

                    // End User Define Parameter For WebAPI

                    stringList.Add(lstCode[i].StatusCode.ToString());
                    stringList.Add(lstCode[i].UpdateByName.ToString());
                    //stringList.Add(string.Format(Localization.GetString("DateTimeFormat", Localization.SharedResourceFile), Convert.ToDateTime(lstCode[i].UpdateStamp)));
                    stringList.Add(string.Format(Localization.GetString("DateTimeFormat", Localization.SharedResourceFile), Convert.ToDateTime(lstCode[i].UpdateStamp).AddHours(UTCOffset)));


                    rowobj.cell = stringList;
                    rowlist.Add(rowobj);
                }

                var jsonToReturn = new
                {
                    total = totalPage.ToString(),
                    page = page.ToString(),
                    records = totalCount.ToString(),
                    rows = rowlist
                };

                return Request.CreateResponse(HttpStatusCode.OK, jsonToReturn);
            }
            catch (Exception exc)
            {
                return Request.CreateResponse(HttpStatusCode.OK, exc.Message);
            }

        }