/// <summary> /// 添加区域上传周期 /// </summary> /// <param name="info"></param> /// <param name="meterList"></param> /// <param name="type"></param> /// <returns></returns> public Message AddSetAlarmArea(IoT_SetUploadCycle info, List <String> communityList) { Message m; string configName = System.Configuration.ConfigurationManager.AppSettings["defaultDatabase"]; DataContext dd = new DataContext(System.Configuration.ConfigurationManager.ConnectionStrings[configName].ConnectionString); try { List <View_UserMeter> meterTempList = dd.GetTable <View_UserMeter>().Where(p => p.CompanyID == info.CompanyID && communityList.Contains(p.Community)).ToList(); List <IoT_UploadCycleMeter> meterList = new List <IoT_UploadCycleMeter>(); foreach (View_UserMeter meter in meterTempList) { IoT_UploadCycleMeter alarmMeter = new IoT_UploadCycleMeter(); alarmMeter.MeterNo = meter.MeterNo; meterList.Add(alarmMeter); } m = Add(info, meterList); } catch (Exception e) { m = new Message() { Result = false, TxtMessage = "新增设置上传周期失败!" + e.Message }; } return(m); }
/// <summary> /// 更新设置上传周期任务状态,用于上传周期设置完成,撤销,失败时调用更新。 /// </summary> /// <param name="taskID"></param> /// <param name="state">状态: 1 完成 2 撤销 3 失败</param> /// <returns></returns> public string UpdateUploadCycleState(string taskID, TaskState state) { if (state == TaskState.Waitting) { return("状态不能为申请"); } string result = ""; string configName = System.Configuration.ConfigurationManager.AppSettings["defaultDatabase"]; //Linq to SQL 上下文对象 DataContext dd = new DataContext(System.Configuration.ConfigurationManager.ConnectionStrings[configName].ConnectionString); try { IoT_UploadCycleMeter dbinfo = dd.GetTable <IoT_UploadCycleMeter>().Where(p => p.TaskID == taskID).SingleOrDefault(); dbinfo.State = Convert.ToChar(((byte)state).ToString()); dbinfo.FinishedDate = DateTime.Now; // 更新操作 dd.SubmitChanges(); IoT_SetUploadCycle uploadCycle = null; int iCount = dd.GetTable <IoT_UploadCycleMeter>().Where(p => p.TaskID == taskID && p.State.ToString() == "0").Count(); if (iCount == 0) { uploadCycle = dd.GetTable <IoT_SetUploadCycle>().Where(p => p.ID == dbinfo.ID).SingleOrDefault(); uploadCycle.State = Convert.ToChar(((byte)state).ToString()); uploadCycle.FinishedDate = DateTime.Now; } dd.SubmitChanges(); if (state == TaskState.Undo) { new M_SetParameterService().UnSetParameter(taskID); } if (state == TaskState.Finished) { IoT_Meter meterInfo = dd.GetTable <IoT_Meter>().Where(p => p.MeterNo == dbinfo.MeterNo).SingleOrDefault(); meterInfo.UploadCycle = uploadCycle.ReportType; // 更新操作 dd.SubmitChanges(); } } catch (Exception e) { result = e.Message; } return(result); }
/// <summary> /// 设置上传周期 /// </summary> /// <param name="info"></param> /// <param name="meter"></param> /// <returns></returns> public string SetUploadCycle(IoT_SetUploadCycle info, IoT_UploadCycleMeter meter) { string result = ""; try { MongoDBHelper <Task> mongo_task = new MongoDBHelper <Task>(); Task task = new Task(); task.MeterMac = meter.MeterNo.Trim(); task.TaskDate = QuShi.getDate(); task.TaskID = Guid.NewGuid().ToString(); //用于和指令进行进行关联 task.TaskState = TaskState.Waitting; task.TaskType = TaskType.TaskType_设置上传周期; // //写任务 mongo_task.Insert(CollectionNameDefine.TaskCollectionName, task); meter.TaskID = task.TaskID; /*上传周期模式: * 00:以月为周期,在每个月的XX日YY时ZZ分上传数据; * 01:以XX天为周期,在每XX天的YY时ZZ分上传数据,起点为每月的01日00时00分; * 02:以YY时为周期,在每YY小时的ZZ分上传数据,起点为每天的00时00分; * 03:以燃气表启动开始计时,以XX日YY时ZZ分上传数据 */ ReportCycleType cycleType = ReportCycleType.时周期; if (info.ReportType == "00") { cycleType = ReportCycleType.月周期; } else if (info.ReportType == "01") { cycleType = ReportCycleType.天周期; } else if (info.ReportType == "02") { cycleType = ReportCycleType.时周期; } else if (info.ReportType == "03") { cycleType = ReportCycleType.周期采集; } /*周期参数, * DD 天 范围:00-31 * HH 小时 范围:00-23 * MM 分钟 范围:00-59*/ int DD = 1; int HH = 23; int MM = 59; try { DD = Convert.ToInt32(info.Par.Substring(0, 2)); HH = Convert.ToInt32(info.Par.Substring(2, 2)); MM = Convert.ToInt32(info.Par.Substring(4, 2)); } catch { } //2.设置上传周期 DataItem_C105 item_C105 = new DataItem_C105(Convert.ToByte(new Random().Next(0, 255)), cycleType, DD, HH, MM); item_C105.type = (ReportCycleType)Convert.ToByte(info.ReportType); item_C105.XX = Convert.ToUInt16(info.Par.Substring(0, 2)); item_C105.YY = Convert.ToUInt16(info.Par.Substring(2, 2)); item_C105.ZZ = Convert.ToUInt16(info.Par.Substring(4, 2)); Command cmd = new Command(); cmd.TaskID = task.TaskID; cmd.Identification = ((UInt16)item_C105.IdentityCode).ToString("X2"); cmd.ControlCode = (byte)ControlCode.CYWriteData;//设置参数 cmd.DataLength = Convert.ToByte(item_C105.Length); cmd.DataCommand = MyDataConvert.BytesToHexStr(item_C105.GetBytes()); cmd.Order = 2; CommandDA.Insert(cmd); } catch (Exception e) { result = e.Message; } return(result); }
public override void DoLoginedHandlerWork(HttpContext context) { Message jsonMessage; jsonMessage = new Message() { Result = false, TxtMessage = "权限验证失败,可能原因:\n1、数据中心通讯失败。\n2、系统管理员未与您分配对应操作权限。" }; //获取操作类型AType:ADD,EDIT,DELETE string AjaxType = context.Request.QueryString["AType"] == null ? string.Empty : context.Request.QueryString["AType"].ToString().ToUpper(); IoT_SetUploadCycle Info; WCFServiceProxy <ISetUploadCycle> proxy = null; try { switch (AjaxType) { //查询上传周期资料 case "QUERY": CommonSearch <View_UpLoadDateView> InfoSearch = new CommonSearch <View_UpLoadDateView>(); string Where = "1=1 "; Where += "AND CompanyID='" + loginOperator.CompanyID + "' "; if (context.Request.Form["Date1"] != null && context.Request.Form["Date1"].ToString().Trim() != string.Empty) { Where += " AND convert(char(10),RegisterDate,120)='" + context.Request.Form["Date1"].ToString() + "'";; } if (context.Request.Form["TWhere"] != null && context.Request.Form["TWhere"].ToString().Trim() != string.Empty) { Where += context.Request.Form["TWhere"].ToString(); } SearchCondition sCondition = new SearchCondition() { TBName = "View_UpLoadDateView", TFieldKey = "CycleID", TTotalCount = -1, TPageCurrent = 1, TFieldOrder = "RegisterDate DESC", TWhere = Where }; List <View_UpLoadDateView> list = InfoSearch.GetList(ref sCondition, context); jsonMessage = new Message() { Result = true, TxtMessage = JSon.ListToJson <View_UpLoadDateView>(list, sCondition.TTotalCount) }; break; //查询所有设定上传周期失败的用户 case "QUERYUSERFILE": CommonSearch <View_UpLoadDate> InfoSearch_UserFILE = new CommonSearch <View_UpLoadDate>(); Where = "1=1 "; Where += "AND CompanyID='" + loginOperator.CompanyID + "' AND State='3'"; if (context.Request.Form["TWhere"] != null && context.Request.Form["TWhere"].ToString().Trim() != string.Empty) { Where += context.Request.Form["TWhere"].ToString(); } if (context.Request.Form["MeterID"] != null && context.Request.Form["MeterID"].ToString().Trim() != string.Empty) { Where += " AND MeterID=" + context.Request.Form["MeterID"].ToString().Trim(); } sCondition = new SearchCondition() { TBName = "View_UpLoadDate", TFieldKey = "MeterID", TTotalCount = -1, TPageCurrent = 1, TFieldOrder = "MeterID DESC", TWhere = Where }; List <View_UpLoadDate> list_UserFILE = InfoSearch_UserFILE.GetList(ref sCondition, context); jsonMessage = new Message() { Result = true, TxtMessage = JSon.ListToJson <View_UpLoadDate>(list_UserFILE, sCondition.TTotalCount) }; break; //根据设定上传周期的用户 case "QUERYUSER": CommonSearch <View_UpLoadDate> InfoSearch_User = new CommonSearch <View_UpLoadDate>(); Where = "1=1 "; Where += "AND CompanyID='" + loginOperator.CompanyID + "' "; if (context.Request.Form["TWhere"] != null && context.Request.Form["TWhere"].ToString().Trim() != string.Empty) { Where += context.Request.Form["TWhere"].ToString(); } if (context.Request.Form["MeterID"] != null && context.Request.Form["MeterID"].ToString().Trim() != string.Empty) { Where += " AND MeterID=" + context.Request.Form["MeterID"].ToString().Trim(); } sCondition = new SearchCondition() { TBName = "View_UpLoadDate", TFieldKey = "UserID", TTotalCount = -1, TPageCurrent = 1, TFieldOrder = "UserID DESC", TWhere = Where }; List <View_UpLoadDate> list_User = InfoSearch_User.GetList(ref sCondition, context); jsonMessage = new Message() { Result = true, TxtMessage = JSon.ListToJson <View_UpLoadDate>(list_User, sCondition.TTotalCount) }; break; //新增上传周期 case "ADD": if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "szbjcs")) { Info = new CommonModelFactory <IoT_SetUploadCycle>().GetModelFromContext(context); Info.CompanyID = base.loginOperator.CompanyID; Info.Oper = base.loginOperator.Name; Info.RegisterDate = DateTime.Now; List <IoT_UploadCycleMeter> alarmMeter = new List <IoT_UploadCycleMeter>(); string Total = string.IsNullOrEmpty(context.Request.Form["Total"]) == true ? "" : context.Request.Form["Total"].ToString(); string ReportType = string.IsNullOrEmpty(context.Request.Form["ReportType"]) == true ? "" : context.Request.Form["ReportType"].ToString(); string par = (string.IsNullOrEmpty(context.Request.Form["strDay"]) == true ? "00" : context.Request.Form["strDay"].ToString()) + (string.IsNullOrEmpty(context.Request.Form["strMinu"]) == true ? "00" : context.Request.Form["strHour"].ToString()) + (string.IsNullOrEmpty(context.Request.Form["strHour"]) == true ? "00" : context.Request.Form["strMinu"].ToString()); string Context = string.IsNullOrEmpty(context.Request.Form["Context"]) == true ? "" : context.Request.Form["Context"].ToString(); Info.Context = Context; Info.ReportType = ReportType; Info.RegisterDate = DateTime.Now; Info.Par = par; Info.State = '0'; Info.TaskID = "";//目前还不知道任务ID的取值方法 proxy = new WCFServiceProxy <ISetUploadCycle>(); if (!string.IsNullOrEmpty(context.Request.Form["hidType"]) && (context.Request.Form["hidType"].ToString() != "")) { //设定选择用户的说明 if (context.Request.Form["hidType"].ToString() == "1") { Info.Scope = "所有用户"; jsonMessage = proxy.getChannel.AddSetAlarmAll(Info); } else if (context.Request.Form["hidType"].ToString() == "2") { Info.Scope = "选择用户"; alarmMeter = new List <IoT_UploadCycleMeter>(); if (context.Request.Form["strNo"] != null && context.Request.Form["strNo"].ToString().Trim() != string.Empty) { string strNo = context.Request.Form["strNo"]; string[] arrNo = strNo.Split(','); for (int i = 0; i < arrNo.Length; i++) { IoT_UploadCycleMeter meter = new IoT_UploadCycleMeter(); meter.MeterNo = arrNo[i]; alarmMeter.Add(meter); } } jsonMessage = proxy.getChannel.Add(Info, alarmMeter); } else { string strNo = context.Request.Form["communityStr"] == null ? "" : context.Request.Form["communityStr"]; string[] arrNo = strNo.Split(','); Info.Scope = context.Request.Form["hidType"].ToString(); jsonMessage = proxy.getChannel.AddSetAlarmArea(Info, arrNo.ToList()); } } } break; //修改上传周期 //case "EDIT": // if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "szbjcs")) // { // Info = new CommonModelFactory<IoT_SetUploadCycle>().GetModelFromContext(context); // proxy = new WCFServiceProxy<ISetUploadCycle>(); // jsonMessage = proxy.getChannel.Edit(Info); // } // break; //撤销上传周期的设定 case "REVOKE": if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "SCZQREV")) { proxy = new WCFServiceProxy <ISetUploadCycle>(); string ID = string.Empty; if (context.Request["ID"] != null && context.Request["ID"].ToString().Trim() != string.Empty) { ID = context.Request["ID"].ToString() == "" ? "0" : context.Request["ID"].ToString(); } jsonMessage = proxy.getChannel.revoke(ID, loginOperator.CompanyID); } break; default: jsonMessage = new Message() { Result = false, TxtMessage = "操作未定义。" }; break; } } catch (Exception ex) { jsonMessage = new Message() { Result = false, TxtMessage = ex.Message }; } finally { if (proxy != null) { proxy.CloseChannel(); } } context.Response.Write(JSon.TToJson <Message>(jsonMessage)); }