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 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); } }
// 當 GET, 和 POST 參數同時出現時, POST 需加上 FormBody, POST的參數在集合裡, 其餘參數為 GET 的參數, 變數名稱就是URL的參數 public HttpResponseMessage DoAction([FromBody]FormDataCollection objPostData, int request1, int request2) { try { string oper = objPostData.Get("oper"); bool bSuccess = true; string strError = ""; List<Row> rowlist = new List<Row>() { }; for (var i = 0; i < 10; i++) { Row rowobj = new Row(); var stringList = new List<string>(); rowobj.id = i; stringList.Add("Data1"); stringList.Add("Data2"); rowobj.cell = stringList; rowlist.Add(rowobj); } // jqgrid action // jsonstring: {'success':'true', 'errors':'', 'new_id':'0'} var jsonToReturn = new { success = bSuccess.ToString().ToLower(), errors = strError, new_id = 0 }; /* // jqgrid load data // jsonstring: {'total':'10', 'page':'1', 'records':'100', 'rows':{}} var jsonToReturn = new { total = totalPage.ToString(), page = page.ToString(), records = totalCount.ToString(), rows = rowlist }; */ return Request.CreateResponse(HttpStatusCode.OK, jsonToReturn); } catch (Exception exc) { // 錯誤回報代碼, 此範例為 500, 為較常用的錯誤回報代碼, 尚有其它代碼, 如 NotFound(404), ServiceUnavailable (503)…等. return Request.CreateResponse(HttpStatusCode.InternalServerError, exc.Message); } }
public HttpResponseMessage GetAlertLogForMobileByPortal(string startDate, string endDate, string portalID) { 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); System.Text.StringBuilder modules = new System.Text.StringBuilder(); List<int> allModules = new List<int>(); 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("fleetSetting_CARInfo")) if (!allModules.Contains(minfo.ModuleID)) allModules.Add(minfo.ModuleID); } } } foreach (int moduleID in allModules) { modules.Append(moduleID).Append(","); } if (modules.Length > 0) modules.Remove(modules.Length - 1, 1); List<Hashtable> allAlertLog = new List<Hashtable>(); AlertLogController ctrl = new AlertLogController(); List<AlertLogInfoForMobile> lstAlertLog = ctrl.FetchAlertLogForMobileByPortal(startDate, endDate, modules.ToString()); foreach (AlertLogInfoForMobile info in lstAlertLog) { Hashtable ht = new Hashtable(); ht.Add("DeviceID", info.DeviceID); ht.Add("fleetSetting_CARInfoID", info.fleetSetting_CARInfoID); ht.Add("countMildly", info.countMildly); ht.Add("countModerately", info.countModerately); ht.Add("countSeverely", info.countSeverely); ht.Add("TotalSevere", info.TotalSevere); ht.Add("CarNo", info.CarNo); ht.Add("Plate", info.Plate); ht.Add("CompanyID", info.CompanyID); ht.Add("fleetID", info.fleetID); ht.Add("FleetName", info.FleetName); ht.Add("DriverName", info.DriverName); ht.Add("DriverNo", info.DriverNo); ht.Add("Phone", info.Phone); allAlertLog.Add(ht); } var jsonToReturn = JsonConvert.SerializeObject(allAlertLog); return Request.CreateResponse(HttpStatusCode.OK, jsonToReturn); }
public HttpResponseMessage GetAlertLogForMobileByRange(string startDate, string endDate, string deviceID) { List<Hashtable> allAlertLog = new List<Hashtable>(); AlertLogController ctrl = new AlertLogController(); List<AlertLogInfoForMobile> lstAlertLog = ctrl.GetAlertLogForMobileByRange(startDate, endDate, deviceID); foreach (AlertLogInfoForMobile info in lstAlertLog) { Hashtable ht = new Hashtable(); ht.Add("AlertDate", info.AlertDate); ht.Add("countMildly", info.countMildly); ht.Add("countModerately", info.countModerately); ht.Add("countSeverely", info.countSeverely); ht.Add("TotalSevere", info.TotalSevere); allAlertLog.Add(ht); } var jsonToReturn = JsonConvert.SerializeObject(allAlertLog); return Request.CreateResponse(HttpStatusCode.OK, jsonToReturn); }
public HttpResponseMessage GetAlertLogForMobileByDevice(string startDate, string endDate, string deviceID) { List<Hashtable> allAlertLog = new List<Hashtable>(); AlertLogController ctrl = new AlertLogController(); List<AlertLogInfoForMobile> lstAlertLog = ctrl.FetchAlertLogForMobileByDevice(startDate, endDate, deviceID); foreach (AlertLogInfoForMobile info in lstAlertLog) { Hashtable ht = new Hashtable(); ht.Add("AlarmCreateDate", Convert.ToDateTime(info.AlarmCreateDate).ToString("yyyy/MM/dd HH:mm:ss")); ht.Add("RuleName", info.RuleName); ht.Add("AlertDate", info.AlertDate); ht.Add("Severity", info.Severity); ht.Add("AlarmTypeName", info.AlarmTypeName); ht.Add("AlarmMsg", info.AlarmMsg); allAlertLog.Add(ht); } var jsonToReturn = JsonConvert.SerializeObject(allAlertLog); return Request.CreateResponse(HttpStatusCode.OK, jsonToReturn); }
public HttpResponseMessage GetDailyLog(int page, double UTCOffset, int rows, string sidx, string sord, string filters = "", string devicefilters = "", string deviceIds = "") { //condition string condition = null; string condition2 = null; //存放KEYWARD條件 ArrayList al = null; if (!string.IsNullOrEmpty(devicefilters)) { System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); jqGridUtil.Filters f = serializer.Deserialize<jqGridUtil.Filters>(devicefilters); 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()); } else if(!string.IsNullOrEmpty(deviceIds)) { condition = string.Format("DeviceID in ({0})", deviceIds); } if (!string.IsNullOrEmpty(filters)) { 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)); } } if ( al.Count>0) { //condition = string.Join(string.Format(" {0} ", f.groupOp), al.ToArray()) + " and " + condition; condition2 = string.Join(string.Format(" {0} ", f.groupOp), al.ToArray()); } } //if (!string.IsNullOrEmpty(filters)) //{ // 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()); //} try { al = new ArrayList(1); al.Add(condition); al.Add(condition2);//新增車機過濾條件 int totalCount = DataProvider.Instance().GetCount_DailyLog(al); al = new ArrayList(); al.Add(page); al.Add(rows); al.Add(sidx); al.Add(sord); al.Add(condition); al.Add(condition2); System.Data.IDataReader dr = DataProvider.Instance().FetchAll_DailyLog(al); System.Data.DataTable dt = new System.Data.DataTable(); dt.Load(dr); 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>() { }; int i = 0; foreach (System.Data.DataRow item in dt.Rows) { Row rowobj = new Row(); var stringList = new List<string>(); rowobj.id = i; stringList.Add(i.ToString()); stringList.Add(item["DeviceID"].ToString()); stringList.Add(item["AlertID"].ToString()); stringList.Add(item["CarNo"].ToString()); //將車牌改成車號 stringList.Add(item["DriverName"].ToString()); stringList.Add(item["DriverID"].ToString()); //stringList.Add(string.Format(Localization.GetString("DateTimeFormat", Localization.SharedResourceFile), Convert.ToDateTime(item["CreateDate"]))); stringList.Add(string.Format(Localization.GetString("DateTimeFormat", Localization.SharedResourceFile), Convert.ToDateTime(item["CreateDate"]).AddHours(UTCOffset))); stringList.Add(item["RuleName"].ToString()); stringList.Add(item["AlarmTypeName"].ToString()); stringList.Add(item["SeverityCode"].ToString()); stringList.Add(string.Empty); //警報訊息 stringList.Add(item["HandleStatus"].ToString()); //工作狀態 stringList.Add(item["MisInfo"].ToString()); stringList.Add(item["AlarmType"].ToString()); stringList.Add(item["WorkListAlertID"].ToString()); //stringList.Add(item["GPS_Latitude"].ToString()); //stringList.Add(item["GPS_Longitude"].ToString()); stringList.Add(item["fleetSetting_WorkListID"].ToString()); rowobj.cell = stringList; rowlist.Add(rowobj); i = i + 1; } var jsonToReturn = new { total = totalPage.ToString(), page = page.ToString(), records = totalCount.ToString(), rows = rowlist }; return Request.CreateResponse(HttpStatusCode.OK, jsonToReturn); } catch (Exception) { throw; } }
protected void SaveControl(object source, CommandEventArgs e) { string moduleName = Constants.ModuleName; string componentName = Constants.ComponentName; //Get the index of the row to save int index = gdFormSetting.EditItemIndex; FormRightInfo editItem = FormControls[index]; HiddenField hidControlID = (HiddenField)gdFormSetting.Items[index].FindControl("hidControlID"); TextBox txtControlID = (TextBox)gdFormSetting.Items[index].FindControl("txtControlID"); DropDownList ddlEnable = (DropDownList)gdFormSetting.Items[index].FindControl("ddlEnable"); DropDownList ddlRequire = (DropDownList)gdFormSetting.Items[index].FindControl("ddlRequire"); TextBox txtClientScript = (TextBox)gdFormSetting.Items[index].FindControl("txtClientScript"); //TextBox txtVote = (TextBox)gdFormSetting.Items[index].FindControl("txtVote"); TextBox txtErrorMessageResourceID = (TextBox)gdFormSetting.Items[index].FindControl("txtErrorMessageResourceID"); if (!String.IsNullOrEmpty(txtControlID.Text)) { editItem.ControlID = txtControlID.Text; editItem.Enable = Convert.ToBoolean(ddlEnable.SelectedValue); editItem.Require = Convert.ToBoolean(ddlRequire.SelectedValue); editItem.ClientScript = txtClientScript.Text; //editItem.addVote(txtVote.Text); editItem.ErrorMessageResourceID = txtErrorMessageResourceID.Text; FormRightController formRightCtrl = new FormRightController(moduleName, componentName, DataProvider.GetConnectionString()); formRightCtrl.UpdateFormRight(editItem, hidControlID.Value); } else { } if (AddMode) { FormRightController formRightCtrl = new FormRightController(moduleName, componentName, DataProvider.GetConnectionString()); List<string> proIDList = new List<string>(); for (int i = 0; i < ddlProID.Items.Count; i++) { proIDList.Add(ddlProID.Items[i].Text); } formRightCtrl.InsertFormRight(editItem, UserInfo.UserID, proIDList); //Remove the temporary added row FormControls = GetControls(InitProcessID); AddMode = false; } //Reset Edit Index gdFormSetting.EditItemIndex = -1; BindControls(); }