/// <summary> /// 添加区域添加调价计划 /// </summary> /// <param name="info"></param> /// <param name="meterList"></param> /// <param name="type"></param> /// <returns></returns> public Message AddPricingArea(IoT_Pricing 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_PricingMeter> meterList = new List <IoT_PricingMeter>(); foreach (View_UserMeter meter in meterTempList) { IoT_PricingMeter alarmMeter = new IoT_PricingMeter(); 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="info"></param> /// <param name="meter"></param> /// <returns></returns> public string SetPricingPlan(PricingPlan info, IoT_PricingMeter 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_调整价格; // //读取表信息 info.MeterNo = meter.MeterNo.Trim(); info.TaskID = task.TaskID; //写任务 mongo_task.Insert(CollectionNameDefine.TaskCollectionName, task); meter.TaskID = task.TaskID; //2.设置调价计划数据 DataItem_A010 item_A010 = null; CT ct = new CT(info.MeterType == "00" ? MeterType.气量表 : MeterType.金额表, (bool)info.IsUsedLadder, (JieSuanType)Convert.ToInt16(info.SettlementType.ToString()), ((int)info.Ladder) <= 0 ? 1 : (int)info.Ladder); item_A010 = new DataItem_A010(Convert.ToByte(new Random().Next(0, 255)), ct, DateTime.Now); item_A010.Price1 = (decimal)info.Price1; item_A010.Price2 = (decimal)info.Price2; item_A010.Price3 = (decimal)info.Price3; item_A010.Price4 = (decimal)info.Price4; item_A010.Price5 = (decimal)info.Price5; item_A010.UseGas1 = (decimal)info.Gas1; item_A010.UseGas2 = (decimal)info.Gas2; item_A010.UseGas3 = (decimal)info.Gas3; item_A010.UseGas4 = (decimal)info.Gas4; item_A010.StartDate = Convert.ToDateTime(info.UseDate); Command cmd = new Command(); cmd.TaskID = task.TaskID; cmd.Identification = ((UInt16)item_A010.IdentityCode).ToString("X2"); cmd.ControlCode = (byte)ControlCode.WriteData;//设置参数 cmd.DataLength = Convert.ToByte(item_A010.Length); cmd.DataCommand = MyDataConvert.BytesToHexStr(item_A010.GetBytes()); cmd.Order = 1; CommandDA.Insert(cmd); new PricingPlanDA().NewPricingPlan(info); //注:该函数如何进行事务处理,保证所有数据更新都成功。 } 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_Pricing Info; WCFServiceProxy <IPricingManage> proxy = null; try { switch (AjaxType) { case "QUERY": CommonSearch <IoT_Pricing> InfoSearch = new CommonSearch <IoT_Pricing>(); 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 = "IoT_Pricing", TFieldKey = "RegisterDate", TTotalCount = -1, TPageCurrent = 1, TFieldOrder = "RegisterDate DESC", TWhere = Where }; List <IoT_Pricing> list = InfoSearch.GetList(ref sCondition, context); jsonMessage = new Message() { Result = true, TxtMessage = JSon.ListToJson <IoT_Pricing>(list, sCondition.TTotalCount) }; break; case "QUERYUSER": CommonSearch <View_PricingMeter> InfoSearch_User = new CommonSearch <View_PricingMeter>(); 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["ID"] != null && context.Request.Form["ID"].ToString().Trim() != string.Empty) { Where += " AND ID=" + context.Request.Form["ID"].ToString().Trim(); } sCondition = new SearchCondition() { TBName = "View_PricingMeter", TFieldKey = "UserID", TTotalCount = -1, TPageCurrent = 1, TFieldOrder = "UserID DESC", TWhere = Where }; List <View_PricingMeter> list_User = InfoSearch_User.GetList(ref sCondition, context); jsonMessage = new Message() { Result = true, TxtMessage = JSon.ListToJson <View_PricingMeter>(list_User, sCondition.TTotalCount) }; break; case "ADD": if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "tjgl_tj")) { Info = new CommonModelFactory <IoT_Pricing>().GetModelFromContext(context); Info.CompanyID = base.loginOperator.CompanyID; Info.Oper = base.loginOperator.Name; Info.RegisterDate = DateTime.Now; proxy = new WCFServiceProxy <IPricingManage>(); if (context.Request.Form["Scope"] != null && context.Request.Form["Scope"].ToString().Trim() != string.Empty) { if (context.Request.Form["Scope"].ToString().Trim() == "所有用户") { jsonMessage = proxy.getChannel.AddPricingAll(Info); } else if (context.Request.Form["Scope"].ToString().Trim() == "选择用户") { List <IoT_PricingMeter> alarmMeter = new List <IoT_PricingMeter>(); 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_PricingMeter meter = new IoT_PricingMeter(); meter.MeterNo = arrNo[i]; alarmMeter.Add(meter); } } jsonMessage = proxy.getChannel.Add(Info, alarmMeter); } //选择区域用户 else { if (context.Request.Form["strArea"] != null && context.Request.Form["strArea"].ToString().Trim() != string.Empty) { string strNo = context.Request.Form["strArea"]; string[] arrNo = strNo.Split(','); jsonMessage = proxy.getChannel.AddPricingArea(Info, arrNo.ToList()); } } } } break; case "EDIT": if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "tjgl_tj")) { Info = new CommonModelFactory <IoT_Pricing>().GetModelFromContext(context); proxy = new WCFServiceProxy <IPricingManage>(); jsonMessage = proxy.getChannel.Edit(Info); } break; case "DELETE": if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "")) { Info = new CommonModelFactory <IoT_Pricing>().GetModelFromContext(context); proxy = new WCFServiceProxy <IPricingManage>(); jsonMessage = proxy.getChannel.Delete(Info); } break; case "UNDO": if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "tjgl_tj")) { Info = new CommonModelFactory <IoT_Pricing>().GetModelFromContext(context); proxy = new WCFServiceProxy <IPricingManage>(); jsonMessage = proxy.getChannel.UnSetParamter(Info); } 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)); }
/// <summary> /// 更新调价任务状态 /// </summary> /// <param name="taskID"></param> /// <param name="state">状态:0 申请 1 完成 2 撤销 3 失败</param> /// <returns></returns> public string UpdatePricingTaskState(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_PricingMeter dbinfo = dd.GetTable <IoT_PricingMeter>().Where(p => p.TaskID == taskID).SingleOrDefault(); dbinfo.State = Convert.ToChar(((byte)state).ToString()); dbinfo.FinishedDate = DateTime.Now; // 更新操作 dd.SubmitChanges(); IoT_Pricing uploadCycle = null; int iCount = dd.GetTable <IoT_PricingMeter>().Where(p => p.TaskID == taskID && p.State.ToString() == "0").Count(); if (iCount == 0)//表具任务都执行完成后 更新调价任务状态 { uploadCycle = dd.GetTable <IoT_Pricing>().Where(p => p.ID == dbinfo.ID).SingleOrDefault(); uploadCycle.State = Convert.ToChar(((byte)state).ToString()); } dd.SubmitChanges(); IoT_PricePar pricePar = dd.GetTable <IoT_PricePar>().Where(p => p.ID.ToString() == uploadCycle.PriceType).SingleOrDefault(); 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.Price1 = uploadCycle.Price1 == null ? 0 : uploadCycle.Price1; meterInfo.Gas1 = uploadCycle.Gas1 == null ? 0 : uploadCycle.Gas1; meterInfo.Price2 = uploadCycle.Price2 == null ? 0 : uploadCycle.Price2; meterInfo.Gas2 = uploadCycle.Gas2 == null ? 0 : uploadCycle.Gas2; meterInfo.Price3 = uploadCycle.Price3 == null ? 0 : uploadCycle.Price3; meterInfo.Gas3 = uploadCycle.Gas3 == null ? 0 : uploadCycle.Gas3; meterInfo.Price4 = uploadCycle.Price4 == null ? 0 : uploadCycle.Price4; meterInfo.Gas4 = uploadCycle.Gas4 == null ? 0 : uploadCycle.Gas4; meterInfo.Price5 = uploadCycle.Price5 == null ? 0 : uploadCycle.Price5; meterInfo.IsUsed = uploadCycle.IsUsed == null ? false : uploadCycle.IsUsed; meterInfo.Ladder = uploadCycle.Ladder == null ? 3 : uploadCycle.Ladder; meterInfo.SettlementType = uploadCycle.SettlementType; meterInfo.SettlementDay = pricePar.SettlementDay; meterInfo.SettlementMonth = pricePar.SettlementMonth; // 更新操作 dd.SubmitChanges(); } } catch (Exception e) { result = e.Message; } return(result); }