public override void ChangeAction(BaseDataModel model) { _model = (OrderDataModel)model; InitOrderReceiveElement(); }
public virtual void ChangeAction(BaseDataModel model) { }
protected static void SetBaseInfo(BaseModel dataItem, BaseDataModel baseItem) { dataItem.ApplicationId = baseItem.ApplicationId; }
public override void ChangeAction(BaseDataModel model) { _model = (MaterialStorageModel)model; InitMaterialElement(); }
public async Task GetObjectData(string moduleName, string objectName, string objectId) { BaseDataModel response = await _dm.LookupObject(moduleName, objectName, objectId); await _dm.PushToStore($"{moduleName}-{objectName}-{objectId}", response.Data); }
/// <summary> /// Translates model into a set of classes that are used to drive CRUD operations, this takes into account the passed expressions /// </summary> /// <param name="modelType">The Type of the model object to process</param> /// <param name="target">Model instance we're working on</param> /// <param name="parent">Model instance's parent object, optional</param> /// <param name="expressions">Data load expressions, optional</param> /// <returns>Entity model class describing this model instance</returns> internal static EntityInfo GetClassInfo <TModel>(Type modelType, BaseDataModel <TModel> target, IDataModelParent parent = null, params Expression <Func <TModel, object> >[] expressions) { // Get static information about the fields to work with and how to handle CRUD operations var staticClassInfo = Instance.GetStaticClassInfo(modelType); // Copy static info in dynamic model to allow instance specific updates EntityInfo entityInfo = new EntityInfo(staticClassInfo); // if the user specified an expression then update our class info to reflect that if (expressions != null && expressions.Any()) { var nonExpandableGraphCollections = entityInfo.GraphNonExpandableCollections; bool nonExpandableGraphCollectionSkipped = false; List <string> graphFieldsToLoad = new List <string>(); List <string> sharePointFieldsToLoad = new List <string>(); foreach (Expression <Func <TModel, object> > expression in expressions) { string fieldToLoad = GetFieldToLoad(entityInfo, expression); if (fieldToLoad != null) { // Non expandable collections do not count as regular field as they're loaded via an additional query if (nonExpandableGraphCollections.Any()) { if (nonExpandableGraphCollections.FirstOrDefault(p => p.Name.Equals(fieldToLoad, StringComparison.InvariantCultureIgnoreCase)) == null) { graphFieldsToLoad.Add(fieldToLoad); } else { // We're not loading this collection as we're using a separate query, but in case // this collection was the only requested one (e.g. web.GetAsync(p=>p.Lists)) we still need // process our field load settings later on nonExpandableGraphCollectionSkipped = true; } } else { graphFieldsToLoad.Add(fieldToLoad); } sharePointFieldsToLoad.Add(fieldToLoad); } } if (graphFieldsToLoad.Count > 0 || nonExpandableGraphCollectionSkipped) { // Indicate that this entity information used an expression, will be used when building get queries entityInfo.GraphFieldsLoadedViaExpression = true; foreach (var field in entityInfo.Fields) { if (!sharePointFieldsToLoad.Contains(field.Name)) { field.Load = false; } } } if (sharePointFieldsToLoad.Count > 0) { entityInfo.SharePointFieldsLoadedViaExpression = true; } } // If fields are marked as key field we always include them in the load foreach (var field in entityInfo.Fields.Where(p => p.IsGraphKey || p.IsSharePointKey)) { field.Load = true; } if (target != null && parent == null) { // In case a model can be used from different contexts (e.g. ContentType can be used from Web, but also from List) // it's required to let the entity know this context so that it can provide the correct information when requested parent = (target as IDataModelParent).Parent; if (parent is IManageableCollection) { // Parent is a collection, so jump one level up parent = (target as IDataModelParent).Parent.Parent; } } else if (target == null && parent != null) { // Otherwise fallback to the provided parent, if any if (parent is IManageableCollection) { // Parent is a collection, so jump one level up parent = parent.Parent; } } if (parent != null) { entityInfo.Target = parent.GetType(); } return(entityInfo); }
private static async Task <ApiCallRequest> BuildGetAPICallGraphAsync <TModel>(BaseDataModel <TModel> model, EntityInfo entity, ODataQuery <TModel> oDataQuery, ApiCall apiOverride, bool useLinqGet, bool loadPages) { string getApi = useLinqGet ? entity.GraphLinqGet : entity.GraphGet; ApiType apiType = ApiType.Graph; if (entity.GraphBeta) { if (CanUseGraphBeta(model, entity)) { apiType = ApiType.GraphBeta; } else { // we can't make this request var cancelledApiCallRequest = new ApiCallRequest(default);
/// <summary> /// /// </summary> private void Excate(SourceTaskItem sourceTask) { string sqlStr = @" SELECT ISNULL(TransToType.longitude,'0') AS longitude, ISNULL(TransToType.latitude,'0') AS latitude, C.* FROM ( SELECT * FROM ( SELECT ROW_NUMBER() OVER(PARTITION BY deviceAddress ORDER BY dataTime DESC) AS RowNumber, *FROM ( SELECT * FROM baseData WHERE deviceAddress IN(SELECT deviceAddress FROM TransToType WHERE transTo1 = '9') ) AS A ) AS B WHERE RowNumber = 1 -- AND deviceAddress ='11004' '11018' '11036' ) AS C LEFT JOIN TransToType ON C.deviceAddress = TransToType.deviceAddress "; //_log.InfoFormat(DateTime.Now + Environment.NewLine + "DustMonitoringTask sqlStr:{0}", sqlStr); DataTable dt = new SQLHelper(sourceTask.ConnectionString).ExecuteQuery(sqlStr, CommandType.Text); DateTime now = DateTime.Now; _log.InfoFormat(DateTime.Now + Environment.NewLine + "DustMonitoringTask sqlStr:{0}", dt.Rows.Count); List <BaseDataModel> dataList = new List <BaseDataModel>(); foreach (DataRow item in dt.Rows) { BaseDataModel baseDataModel = new BaseDataModel(); baseDataModel.ID = ConvertObject.ToInt32(item["ID"]); baseDataModel.deviceAddress = ConvertObject.ToString(item["deviceAddress"]);; baseDataModel.sensorCount = ConvertObject.ToString(item["sensorCount"], ""); baseDataModel.PM25 = ConvertObject.ToString(item["PM25"], ""); baseDataModel.PM10 = ConvertObject.ToString(item["PM10"], ""); baseDataModel.noise = ConvertObject.ToString(item["noise"], ""); baseDataModel.temperature = ConvertObject.ToString(item["temperature"], ""); baseDataModel.humidity = ConvertObject.ToString(item["humidity"], ""); baseDataModel.windSpeed = ConvertObject.ToString(item["windSpeed"], ""); baseDataModel.windPower = ConvertObject.ToString(item["windPower"], ""); baseDataModel.windDirection = ConvertObject.ToString(item["windDirection"], ""); baseDataModel.dataTime = ConvertObject.ToDateTime(item["dataTime"]); baseDataModel.transTo = ConvertObject.ToString(item["transTo"], ""); baseDataModel.transCode = ConvertObject.ToString(item["transCode"], ""); baseDataModel.longitude = ConvertObject.ToString(item["longitude"], ""); baseDataModel.latitude = ConvertObject.ToString(item["latitude"], ""); //十分钟之内的数据才会统计 if (baseDataModel.dataTime >= now.AddMinutes(-10)) { dataList.Add(baseDataModel); } } foreach (BaseDataModel item in dataList) { TBJDataUploadService _TBJDataUploadService = new TBJDataUploadService(); _TBJDataUploadService.UploadData(item); //sqlStr = string.Format("UPDATE baseData SET ISAsync='1' WHERE ID = '{0}'", baseDataModel.ID); //int result = new SQLHelper(sourceTask.ConnectionString).ExecuteNonQuery(sqlStr, CommandType.Text); //_log.InfoFormat("{0}{1}记录更新结果为:{2},{3}", DateTime.Now, Environment.NewLine, sqlStr, result); //Thread.Sleep(1000); } }
public override void ChangeAction(BaseDataModel model) { _model = (AssembleTypePresetModel)model; SetUpElement(); }
internal static Task <ApiCallRequest> BuildGetAPICallAsync <TModel>(BaseDataModel <TModel> model, EntityInfo entity, ApiCall apiOverride, bool forceSPORest = false, bool useLinqGet = false, bool loadPages = false) { return(BuildGetAPICallAsync(model, entity, new ODataQuery <TModel>(), apiOverride, forceSPORest, useLinqGet, loadPages)); }
public override void ChangeAction(BaseDataModel model) { _model = (FormulaDataModel)model; InitElement(); }
public override void ChangeAction(BaseDataModel model) { _model = (SaveDataGroupModel)model; InitSaveElement(); }
public override void ChangeAction(BaseDataModel model) { _model = (BuildPanelModel)model; InitBuildElement(); }
public override void ChangeAction(BaseDataModel model) { _model = (LeaderDataModel)model; SetUpItem(State.Select_Dialog, _model.Info); }
private static async Task <ApiCallRequest> BuildGetAPICallRestAsync <TModel>(BaseDataModel <TModel> model, EntityInfo entity, ODataQuery <TModel> oDataQuery, ApiCall apiOverride, bool useLinqGet, bool loadPages) { string getApi = useLinqGet ? entity.SharePointLinqGet : entity.SharePointGet; IEnumerable <EntityFieldInfo> fields = entity.Fields.Where(p => p.Load); Dictionary <string, string> urlParameters = new Dictionary <string, string>(); StringBuilder sb = new StringBuilder(); // Only add select statement whenever there was a filter specified if (entity.SharePointFieldsLoadedViaExpression) { // $select foreach (var field in fields) { // If there was a selection on which fields to include in an expand (via the QueryProperties() option) then add those fields if (field.SharePointExpandable && field.ExpandFieldInfo != null) { AddExpandableSelectRest(sb, field, null, ""); } else { sb.Append($"{JsonMappingHelper.GetRestField(field)},"); } } urlParameters.Add("$select", sb.ToString().TrimEnd(new char[] { ',' })); sb.Clear(); } // $expand foreach (var field in fields.Where(p => p.SharePointExpandable)) { if (entity.SharePointFieldsLoadedViaExpression) { sb.Append($"{JsonMappingHelper.GetRestField(field)},"); // If there was a selection on which fields to include in an expand (via the Include() option) and the included field was expandable itself then add it if (field.ExpandFieldInfo != null) { string path = ""; AddExpandableExpandRest(sb, field, null, path); } } else { if (field.ExpandableByDefault) { sb.Append($"{JsonMappingHelper.GetRestField(field)},"); } } } urlParameters.Add("$expand", sb.ToString().TrimEnd(new char[] { ',' })); oDataQuery.AddODataToUrlParameters(urlParameters, ODataTargetPlatform.SPORest); // REST apis do not apply a default top // In order to not receive all items in one request, we apply a default top // We don't change the original ODataQuery to avoid side effects if (useLinqGet && !urlParameters.ContainsKey(ODataQuery <TModel> .TopKey)) { urlParameters.Add(ODataQuery <TModel> .TopKey, model.PnPContext.GlobalOptions.HttpSharePointRestDefaultPageSize.ToString()); } sb.Clear(); // Build the API call string baseApiCall = ""; if (apiOverride.Equals(default(ApiCall))) { baseApiCall = $"{model.PnPContext.Uri.AbsoluteUri.TrimEnd(new char[] { '/' })}/{getApi}"; } else { baseApiCall = $"{model.PnPContext.Uri.AbsoluteUri.TrimEnd(new char[] { '/' })}/{apiOverride.Request}"; } // Parse tokens in the base api call baseApiCall = await ApiHelper.ParseApiCallAsync(model, baseApiCall).ConfigureAwait(false); sb.Append(baseApiCall); // Build the querystring parameters NameValueCollection queryString = HttpUtility.ParseQueryString(string.Empty); foreach (var urlParameter in urlParameters.Where(i => !string.IsNullOrEmpty(i.Value))) { // Add key and value, which will be automatically URL-encoded, if needed queryString.Add(urlParameter.Key, urlParameter.Value); } // Build the whole URL if (queryString.AllKeys.Length > 0) { // In .NET Framework to ToString() of a NameValueCollection will use HttpUtility.UrlEncodeUnicode under // the covers resulting in issues. So we decode and encode again as a workaround. This code produces the // same result when used under .NET5/Core versus .NET Framework sb.Append($"?{queryString.ToEncodedString()}"); } // Create ApiCall instance and call the override option if needed var call = new ApiCallRequest(new ApiCall(sb.ToString(), ApiType.SPORest, loadPages: loadPages)); if (model.GetApiCallOverrideHandler != null) { call = await model.GetApiCallOverrideHandler.Invoke(call).ConfigureAwait(false); } return(call); }
public override void ExecuteProgramJob(SourceTaskItem sourceTask, LogTaskItem logTask) { string sqlStr = @" SELECT * FROM ( SELECT ROW_NUMBER() OVER(PARTITION BY deviceAddress ORDER BY dataTime DESC) AS RowNumber, *FROM ( SELECT * FROM baseData WHERE deviceAddress IN(SELECT deviceAddress FROM TransToType WHERE transTo = '12') ) AS A ) AS B WHERE RowNumber = 1 AND deviceAddress ='11056'"; //_log.InfoFormat(DateTime.Now + Environment.NewLine + "DustMonitoringTask sqlStr:{0}", sqlStr); DataTable dt = new SQLHelper(sourceTask.ConnectionString).ExecuteQuery(sqlStr, CommandType.Text); DateTime now = DateTime.Now; _log.InfoFormat(DateTime.Now + Environment.NewLine + "DustMonitoringTask sqlStr:{0}", dt.Rows.Count); List <BaseDataModel> dataList = new List <BaseDataModel>(); foreach (DataRow item in dt.Rows) { BaseDataModel baseDataModel = new BaseDataModel(); baseDataModel.ID = ConvertObject.ToInt32(item["ID"]); baseDataModel.deviceAddress = ConvertObject.ToString(item["deviceAddress"]);; baseDataModel.sensorCount = ConvertObject.ToString(item["sensorCount"], "0"); baseDataModel.PM25 = ConvertObject.ToString(item["PM25"], "0"); baseDataModel.PM10 = ConvertObject.ToString(item["PM10"], "0"); baseDataModel.noise = ConvertObject.ToString(item["noise"], "0"); baseDataModel.temperature = ConvertObject.ToString(item["temperature"], "0"); baseDataModel.humidity = ConvertObject.ToString(item["humidity"], "0"); baseDataModel.windSpeed = ConvertObject.ToString(item["windSpeed"], "0"); baseDataModel.windPower = ConvertObject.ToString(item["windPower"], "0"); baseDataModel.windDirection = ConvertObject.ToString(item["windDirection"], "0"); baseDataModel.dataTime = ConvertObject.ToDateTime(item["dataTime"]); baseDataModel.transTo = ConvertObject.ToString(item["transTo"], "0"); baseDataModel.transCode = ConvertObject.ToString(item["transCode"], "0"); //十分钟之内的数据才会统计 if (baseDataModel.dataTime >= now.AddMinutes(-10)) { dataList.Add(baseDataModel); } } foreach (BaseDataModel item in dataList) { DustMonitoringService dustMonitoringService = new DustMonitoringService(); dustMonitoringService.Regester(item); while (true) { if (dustMonitoringService._client.State == Cowboy.Sockets.TcpSocketConnectionState.Closed) { break; } Thread.Sleep(1000); } //sqlStr = string.Format("UPDATE baseData SET ISAsync='1' WHERE ID = '{0}'", baseDataModel.ID); //int result = new SQLHelper(sourceTask.ConnectionString).ExecuteNonQuery(sqlStr, CommandType.Text); //_log.InfoFormat("{0}{1}记录更新结果为:{2},{3}", DateTime.Now, Environment.NewLine, sqlStr, result); //Thread.Sleep(1000); } }
public static T Mapping <T>(this BaseDataModel obj) { return(Mapper.Map <BaseDataModel, T>(obj)); }
/// <summary> /// When using REST batch requests the URL needs to be correctly cased, so we're loading the web url while doing an interactive request. /// Also loading the default needed properties to save additional loads for missing key properties /// </summary> /// <param name="context">PnPContext being initialized</param> /// <param name="options">Options for the initialization of this context</param> /// <returns></returns> internal static async Task InitializeContextAsync(PnPContext context, PnPContextOptions options) { // Set environment if not yet set if (!context.Environment.HasValue) { context.Environment = CloudManager.GetEnvironmentFromUri(context.Uri); // Ensure the Microsoft Graph URL is set depending on the used cloud environment context.GraphClient.UpdateBaseAddress(CloudManager.GetMicrosoftGraphAuthority(context.Environment.Value)); } // Store the provided options, needed for context cloning context.LocalContextOptions = options; // IMPORTANT: this first call is an interactive call by design as that allows us set the // web URL using the correct casing. Correct casing is required in REST batching // IMPORTANT: if you change this logic by adding more initialization data you also need // to update the CopyContextInitialization method! // Combine the default properties to load with optional additional properties var(siteProps, webProps) = GetDefaultPropertiesToLoad(options); // Use the query client to build the correct initialization query for the given Web properties BaseDataModel <IWeb> concreteEntity = EntityManager.GetEntityConcreteInstance(typeof(IWeb), context.Web, context) as BaseDataModel <IWeb>; var entityInfo = EntityManager.GetClassInfo(concreteEntity.GetType(), concreteEntity, null, webProps.ToArray()); var apiCallRequest = await QueryClient.BuildGetAPICallAsync(concreteEntity, entityInfo, new ApiCall($"_api/Web", ApiType.SPORest), true).ConfigureAwait(false); // Load required web properties var api = new ApiCall(apiCallRequest.ApiCall.Request, ApiType.SPORest) { Interactive = true }; await(context.Web as Web).RequestAsync(api, HttpMethod.Get, "Get").ConfigureAwait(false); // Replace the context URI with the value using the correct casing context.Uri = context.Web.Url; // Request the site properties await context.Site.LoadAsync(siteProps.ToArray()).ConfigureAwait(false); // Ensure the Graph ID is set once and only once if (context.Web is IMetadataExtensible me) { if (!me.Metadata.ContainsKey(PnPConstants.MetaDataGraphId)) { me.Metadata.Add(PnPConstants.MetaDataGraphId, $"{context.Uri.DnsSafeHost},{context.Site.Id},{context.Web.Id}"); } } // If the GroupId is available ensure it's also correctly set on the Group metadata so that calls via that // model can work if (context.Site.IsPropertyAvailable(p => p.GroupId) && context.Site.GroupId != Guid.Empty) { if (context.Group is IMetadataExtensible groupMetaData) { if (!groupMetaData.Metadata.ContainsKey(PnPConstants.MetaDataGraphId)) { groupMetaData.Metadata.Add(PnPConstants.MetaDataGraphId, context.Site.GroupId.ToString()); } } } }
private static DataTable MakerData(DataTable dt, BaseDataModel model) { var valueList = new StringBuilder(); if (dt != null) { if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { switch (model.Unit) { case ChartUnit.unit_hour: valueList.AppendFormat(",{0}", dt.Rows[i]["Value24"].ToString()); break; case ChartUnit.unit_month: valueList.AppendFormat(",{0}", dt.Rows[i]["Value30"].ToString()); break; case ChartUnit.unit_day: valueList.AppendFormat(",{0}", dt.Rows[i]["Value365"].ToString()); break; default: valueList.AppendFormat(",{0}", dt.Rows[i]["Value30"].ToString()); break; } } var listV = valueList.ToString().Length > 0 ? valueList.ToString().Substring(1).Split(',') : null; if (listV == null) { return(null); } DataTable dataTable = TableViews.BaseTable.CreateBigBaseDataTable(); Dictionary <string, decimal> YearsDir = new Dictionary <string, decimal>(); var year = model.Endtime.Year - model.Starttime.Year + 1; for (int y = model.Starttime.Year; y < model.Endtime.Year + 1; y++) { YearsDir.Add(y.ToString(), 0); } decimal[] YearData = new decimal[year]; if (model.Unit == ChartUnit.unit_year) { var count = 0; foreach (var yd in YearsDir) { foreach (var l in listV) { if (l != "") { if (Convert.ToDateTime(l.Split('_')[0]).Year == int.Parse(yd.Key)) { YearData[count] = YearData[count] + decimal.Parse(l.Split('_')[1]); } } } count++; } for (int i = 0; i < YearsDir.Count; i++) { DataRow dr = dataTable.NewRow(); dr["CountID"] = model.ObjectId; dr["Starttime"] = model.Starttime.AddYears(i).ToString("yyyy-1-1"); dr["Endtime"] = model.Starttime.AddYears(i + 1).ToString("yyyy-1-1"); dr["CountValue"] = YearData[i]; dataTable.Rows.Add(dr); } } else { foreach (string t in listV) { if (t != "") { //model switch (model.Unit) { case ChartUnit.unit_day: if (Convert.ToDateTime(t.Split('_')[0]).Subtract(model.Starttime).Days >= 0 && Convert.ToDateTime(t.Split('_')[0]).Subtract(model.Endtime).Days <= 0) { DataRow dr = dataTable.NewRow(); dr["CountID"] = dt.Rows[0]["CountID"].ToString(); dr["Starttime"] = t.Split('_')[0]; dr["Endtime"] = Convert.ToDateTime(t.Split('_')[0]).AddDays(1); dr["CountValue"] = t.Split('_')[1]; dataTable.Rows.Add(dr); } break; case ChartUnit.unit_hour: if (Convert.ToDateTime(t.Split('_')[0]).Subtract(model.Starttime).Hours >= 0 && Convert.ToDateTime(t.Split('_')[0]).Subtract(model.Endtime).Hours <= 0) { DataRow dr = dataTable.NewRow(); dr["CountID"] = dt.Rows[0]["CountID"].ToString(); dr["Starttime"] = t.Split('_')[0]; dr["Endtime"] = Convert.ToDateTime(t.Split('_')[0]).AddHours(1); dr["CountValue"] = t.Split('_')[1]; dataTable.Rows.Add(dr); } break; case ChartUnit.unit_month: if (Convert.ToDateTime(t.Split('_')[0]).Subtract(model.Starttime).Days >= 0 && Convert.ToDateTime(t.Split('_')[0]).Subtract(model.Endtime).Days <= 0) { DataRow dr = dataTable.NewRow(); dr["CountID"] = dt.Rows[0]["CountID"].ToString(); dr["Starttime"] = t.Split('_')[0]; dr["Endtime"] = Convert.ToDateTime(t.Split('_')[0]).AddMonths(1); dr["CountValue"] = t.Split('_')[1]; dataTable.Rows.Add(dr); } break; //case ChartUnit.unit_year: // if (Convert.ToDateTime(t.Split('_')[0]).Subtract(model.Starttime).Days >= 0 && // Convert.ToDateTime(t.Split('_')[0]).Subtract(model.Endtime).Days <= 0) // { // DataRow dr = dataTable.NewRow(); // dr["CountID"] = dt.Rows[0]["CountID"].ToString(); // dr["Starttime"] = t.Split('_')[0]; // dr["Endtime"] = Convert.ToDateTime(t.Split('_')[0]).AddMonths(1); // dr["CountValue"] = t.Split('_')[1]; // dataTable.Rows.Add(dr); // } // break; } } } } return(dataTable); } } return(dt); }
public void ToCRC16() { //string inputStr = @"QN=20160801085857223;ST=32;CN=1062;PW=100000;MN=010000A8900016F000169DC0;Flag=5;CP=&&RtdInterval=30&&"; //int length = inputStr.Length; //string result = CRC.ToCRC16(inputStr, Encoding.ASCII, false); //Console.WriteLine(result); BaseDataModel _baseDataModel = new BaseDataModel() { dataTime = DateTime.Now, deviceAddress = "11056", humidity = "12", ID = 12, latitude = "114.213452", longitude = "34.232157", noise = "12", PM10 = "12", PM25 = "12", sensorCount = "12", temperature = "12", transCode = "12", transTo = "12", TSP = "12", windDirection = "12", windPower = "12", windSpeed = "12" }; RequstModel requstModel = new RequstModel(); string resultStr = requstModel.ToString(new DataModel() { QN = DateTime.Now.ToString("yyyyMMddHHmmssfff"), ST = "39", CN = "2011", PW = "123456", MN = "11004", Flag = "5", CP = string.Format("&&DataTime={0};" + "a01001-Rtd={1},a01001-Flag=N;" + "a01002-Rtd={2},a01002-Flag=N;" + "a01006-Rtd={3},a01006-Flag=N;" + "a01007-Rtd={4},a01007-Flag=N;" + "a01008-Rtd={5},a01008-Flag=N;" + "a34001-Rtd={6},a34001-Flag=N;" + "a34002-Rtd={7},a34002-Flag=N;" + "a34004-Rtd={8},a34004-Flag=N;" + "La-Rtd={9},La-Flag=N;" + "longitude={10};latitude={11};&&", DateTime.Now.ToString("yyyyMMddhhmmss"), _baseDataModel.temperature, //温度 摄氏度 _baseDataModel.humidity, //湿度 % 0, //气压 千帕 _baseDataModel.windSpeed, //风速 米/秒 _baseDataModel.windDirection, //风向 角度 _baseDataModel.TSP, //总悬浮颗粒物 TSP _baseDataModel.PM10, //可吸入颗粒物 PM10 _baseDataModel.PM25, //细微颗粒物 PM2.5 _baseDataModel.noise, //噪声 分贝 _baseDataModel.longitude, _baseDataModel.latitude ), }); Console.WriteLine(resultStr); }
/// <summary> /// 根据查询的起始时间获取需要取的表的表名集合 /// </summary> /// <param name="model">查询条件实体类</param> /// <param name="tcount">返回的表的集合</param> /// <returns></returns> private static List <string> GetTcountNames(BaseDataModel model, List <string> tcount) { if (model.Unit == ChartUnit.unit_hour) { if (model.IsDevice == 0) { tcount.Add("TS_DataCenter_Area_Hour_" + model.Starttime.Year.ToString(CultureInfo.InvariantCulture)); } else { tcount.Add("TS_DataCenter_Device_Hour_" + model.Starttime.Year.ToString(CultureInfo.InvariantCulture)); } } else if (model.Unit == ChartUnit.unit_day) { if (model.Starttime.Year.Equals(model.Endtime.Year)) { // 同年 if (model.IsDevice == 0) { tcount.Add("TS_DataCenter_Area_Day_" + model.Starttime.Year.ToString(CultureInfo.InvariantCulture)); } else { tcount.Add("TS_DataCenter_Device_Day_" + model.Starttime.Year.ToString(CultureInfo.InvariantCulture)); } } else { DateTime temp = model.Starttime; while (temp.Year <= model.Endtime.Year) // while (Convert.ToDateTime(temp.ToString("yyyy-MM-")+model.endtime.Day.ToString()) <= model.endtime) { if (model.IsDevice == 0) { tcount.Add("TS_DataCenter_Area_Day_" + temp.Year.ToString(CultureInfo.InvariantCulture)); } else { tcount.Add("TS_DataCenter_Device_Day_" + temp.Year.ToString(CultureInfo.InvariantCulture)); } temp = temp.AddYears(1); } } } else { if (model.Starttime.Year.Equals(model.Endtime.Year)) { // 同年 if (model.IsDevice == 0) { tcount.Add("TS_DataCenter_Area_Month_" + model.Starttime.Year.ToString(CultureInfo.InvariantCulture)); } else { tcount.Add("TS_DataCenter_Device_Month_" + model.Starttime.Year.ToString(CultureInfo.InvariantCulture)); } } else { DateTime temp = model.Starttime; while (temp.Year <= model.Endtime.Year) { if (model.IsDevice == 0) { tcount.Add("TS_DataCenter_Area_Month_" + temp.Year.ToString(CultureInfo.InvariantCulture)); } else { tcount.Add("TS_DataCenter_Device_Month_" + temp.Year.ToString(CultureInfo.InvariantCulture)); } temp = temp.AddYears(1); } } } return(tcount); }
public static string ToSQLParameter(BaseDataModel data, string dataColumnName) { var returnValue = "NULL"; switch (dataColumnName) { case BaseDataModel.BaseDataColumns.ApplicationId: if (data.ApplicationId != null) { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NUMBER, BaseDataModel.BaseDataColumns.ApplicationId, data.ApplicationId); } else { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, BaseDataModel.BaseDataColumns.ApplicationId); } break; case BaseDataModel.BaseDataColumns.CreatedDate: if (data.CreatedDate != null) { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_STRING_OR_DATE, BaseDataModel.BaseDataColumns.CreatedDate, data.CreatedDate); } else { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, BaseDataModel.BaseDataColumns.CreatedDate); } break; case BaseDataModel.BaseDataColumns.ModifiedDate: if (data.ModifiedDate != null) { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_STRING_OR_DATE, BaseDataModel.BaseDataColumns.ModifiedDate, data.ModifiedDate); } else { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, BaseDataModel.BaseDataColumns.ModifiedDate); } break; case BaseDataModel.BaseDataColumns.CreatedByAuditId: if (data.CreatedByAuditId != null) { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NUMBER, BaseDataModel.BaseDataColumns.CreatedByAuditId, data.CreatedByAuditId); } else { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, BaseDataModel.BaseDataColumns.CreatedByAuditId); } break; case BaseDataModel.BaseDataColumns.ModifiedByAuditId: if (data.ModifiedByAuditId != null) { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NUMBER, BaseDataModel.BaseDataColumns.ModifiedByAuditId, data.ModifiedByAuditId); } else { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, BaseDataModel.BaseDataColumns.ModifiedByAuditId); } break; } return(returnValue); }
/// <summary> /// 能耗集合 /// </summary> /// <param name="model">查询的对象封装</param> /// <returns></returns> public static BaseResult GetBaseEneryDataListNew(BaseQueryModel model) { BaseResult Res = new BaseResult(); Res.BaseLayerObjectResults = new Dictionary <string, BaseData>(); //Res.DeviceResults = new Dictionary<Model.Device, BaseData>(); bool IsDevice = model.IsDevice == 0 ? false : true; var datas = new DataTable(); if (model != null && model.ObjectList.Count > 0) { foreach (var objects in model.ObjectList) { double tempCount = 0; BaseDataModel bmodel = new BaseDataModel(); bmodel.Starttime = model.Starttime; if (model.Unit == ChartUnit.unit_hour) { bmodel.Endtime = (model.Starttime == model.Endtime) ? model.Starttime.AddDays(1).AddHours(-1) : model.Endtime; } else { bmodel.Endtime = model.Endtime; } bmodel.IsDevice = model.IsDevice; bmodel.ItemCode = model.ItemCode; bmodel.ObjectId = objects; bmodel.Unit = model.Unit; datas = GetBaseData(bmodel); BaseData bsDatas = new BaseData(); bsDatas.itemCode = new Model.Itemcode(); var ItemCodeList = new DAL.Itemcode().GetItemcodeList(string.Format(" and ItemCodeNumber='{0}'", model.ItemCode), string.Format(" order by ItemcodeID")); bsDatas.itemCode = ItemCodeList.Count > 0 ? ItemCodeList[0] : null; Model.BaseLayerObject ObjectInfo = new Model.BaseLayerObject(); Model.Device DeviceObjectInfo = new Model.Device(); if (!IsDevice) { List <Model.BaseLayerObject> infoList = new List <Model.BaseLayerObject>(); if (model.areaType == WEB.DataContact.AreaType.Area) { infoList = new DAL.BaseLayerObject().GetBaseLayerObjectList(string.Format(" and LayerObjectID={0}", objects), string.Format(" order by LayerObjectID")); } else { infoList = new DAL.BaseLayerObject().GetBaseFuncLayerObjectList(string.Format(" and LayerObjectID={0}", objects), string.Format(" order by LayerObjectID")); } ObjectInfo = infoList.Count > 0 ? infoList[0] : null; bsDatas.Datas = new List <DataItems>(); foreach (DataRow item in datas.Rows) { tempCount += double.Parse(item["CountValue"].ToString()); bsDatas.Datas.Add(new DataItems() { DatePick = item["Starttime"].ToString(), DataValue = decimal.Parse(item["CountValue"].ToString()), CoalDataValue = Convert.ToDecimal(double.Parse(item["CountValue"].ToString()) * bsDatas.itemCode.ItemCoal), Co2DataValue = Convert.ToDecimal(double.Parse(item["CountValue"].ToString()) * bsDatas.itemCode.ItemCO2), MoneyDataValue = Convert.ToDecimal(double.Parse(item["CountValue"].ToString()) * bsDatas.itemCode.ItemMoney), DataValueAndDept = item["CountValue"].ToString() + bsDatas.itemCode.Unit }); } bsDatas.baseLayerObject = ObjectInfo; } else { var infoList = new DAL.Device().GetDeviceList(string.Format(" and deviceid={0}", objects), string.Format(" order by DeviceID")); DeviceObjectInfo = infoList.Count > 0 ? infoList[0] : null; bsDatas.Datas = new List <DataItems>(); foreach (DataRow item in datas.Rows) { tempCount += double.Parse(item["CountValue"].ToString()); bsDatas.Datas.Add(new DataItems() { DatePick = item["Starttime"].ToString(), DataValue = Convert.ToDecimal(item["CountValue"].ToString()), CoalDataValue = Convert.ToDecimal(double.Parse(item["CountValue"].ToString()) * bsDatas.itemCode.ItemCoal), Co2DataValue = Convert.ToDecimal(double.Parse(item["CountValue"].ToString()) * bsDatas.itemCode.ItemCO2), MoneyDataValue = Convert.ToDecimal(double.Parse(item["CountValue"].ToString()) * bsDatas.itemCode.ItemMoney), DataValueAndDept = item["CountValue"].ToString() + bsDatas.itemCode.Unit }); } bsDatas.device = DeviceObjectInfo; } bsDatas.Total = Convert.ToDecimal(tempCount); bsDatas.ConvertDataValueList = new System.Collections.Hashtable(); bsDatas.ConvertDataValueList.Add("ITEMCOAL", Math.Round((tempCount * bsDatas.itemCode.ItemCoal), 4).ToString()); bsDatas.ConvertDataValueList.Add("ITEMCO2", Math.Round((tempCount * bsDatas.itemCode.ItemCO2), 4).ToString()); bsDatas.ConvertDataValueList.Add("ITEMMONEY", Math.Round((tempCount * bsDatas.itemCode.ItemCO2), 4).ToString()); Res.BaseLayerObjectResults.Add( !IsDevice ? ObjectInfo.LayerObjectID.ToString() : DeviceObjectInfo.DeviceID.ToString(), bsDatas); } return(Res); } return(null); }
public override void ChangeAction(BaseDataModel model) { _model = (AssembleShipModel)model; SetUpCart(); }
private static DataTable MakerData(DataTable dt, BaseDataModel model) { var valueList = new StringBuilder(); if (dt != null) { if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { switch (model.Unit) { case ChartUnit.unit_hour: valueList.AppendFormat(",{0}", dt.Rows[i]["Value24"].ToString()); break; case ChartUnit.unit_month: valueList.AppendFormat(",{0}", dt.Rows[i]["Value30"].ToString()); break; case ChartUnit.unit_day: valueList.AppendFormat(",{0}", dt.Rows[i]["Value365"].ToString()); break; default: valueList.AppendFormat(",{0}", dt.Rows[i]["Value30"].ToString()); break; } } string strValue = valueList.ToString().Replace(",,", ","); var listV = strValue.Length > 0 ? strValue.Substring(1).Split(',') : null; //listV = from m in listV where m != "" OrderBy(m=>m).ToArray(); listV = listV.Where(m => m != "").OrderBy(m => m).ToArray(); // listV OrderBy(m=>m).ToArray(); if (listV == null) { return(null); } DataTable dataTable = TableViews.BaseTable.CreateBigBaseDataTable(); Dictionary <string, decimal> YearsDir = new Dictionary <string, decimal>(); var year = model.Endtime.Year - model.Starttime.Year + 1; for (int y = model.Starttime.Year; y < model.Endtime.Year + 1; y++) { YearsDir.Add(y.ToString(), 0); } decimal[] YearData = new decimal[year]; if (model.Unit == ChartUnit.unit_year) { var count = 0; foreach (var yd in YearsDir) { foreach (var l in listV) { if (l != "") { if (Convert.ToDateTime(l.Split('_')[0]).Year == int.Parse(yd.Key)) { YearData[count] = YearData[count] + decimal.Parse(l.Split('_')[1]); } } } count++; } for (int i = 0; i < YearsDir.Count; i++) { DataRow dr = dataTable.NewRow(); dr["CountID"] = model.ObjectId; dr["Starttime"] = model.Starttime.AddYears(i).ToString("yyyy-1-1"); dr["Endtime"] = model.Starttime.AddYears(i + 1).ToString("yyyy-1-1"); dr["CountValue"] = YearData[i]; dataTable.Rows.Add(dr); } } else { int hourCount = 0; foreach (string t in listV) { if (t != "") { #region 组合数据 switch (model.Unit) { case ChartUnit.unit_day: if (Convert.ToDateTime(t.Split('_')[0]).Subtract(model.Starttime).Days >= 0 && Convert.ToDateTime(t.Split('_')[0]).Subtract(model.Endtime).Days <= 0) { int Count = 0; if ((Convert.ToDateTime(t.Split('_')[0]).Subtract(model.Starttime).Days != 0) && (hourCount > 0)) { TimeSpan ts = Convert.ToDateTime(listV[hourCount].Split('_')[0]) - Convert.ToDateTime(listV[hourCount - 1].Split('_')[0]); Count = ts.Days; } for (int row = 1; row < Count; row++) { DataRow drAdd = dataTable.NewRow(); drAdd["CountID"] = dt.Rows[0]["CountID"].ToString(); drAdd["Starttime"] = Convert.ToDateTime(t.Split('_')[0]).AddDays(row - 1); drAdd["Endtime"] = Convert.ToDateTime(t.Split('_')[0]).AddDays(row); drAdd["CountValue"] = 0; dataTable.Rows.Add(drAdd); } DataRow dr = dataTable.NewRow(); dr["CountID"] = dt.Rows[0]["CountID"].ToString(); dr["Starttime"] = t.Split('_')[0]; dr["Endtime"] = Convert.ToDateTime(t.Split('_')[0]).AddDays(1); dr["CountValue"] = t.Split('_')[1]; dataTable.Rows.Add(dr); } break; case ChartUnit.unit_hour: if (Convert.ToDateTime(t.Split('_')[0]).Subtract(model.Starttime).Hours >= 0 && Convert.ToDateTime(t.Split('_')[0]).Subtract(model.Endtime).Hours <= 0) { int Count = 0; if (hourCount > 0) { Count = Convert.ToDateTime(listV[hourCount].Split('_')[0]).Hour - Convert.ToDateTime(listV[hourCount - 1].Split('_')[0]).Hour; } for (int row = 1; row < Count; row++) { DataRow drAdd = dataTable.NewRow(); drAdd["CountID"] = dt.Rows[0]["CountID"].ToString(); drAdd["Starttime"] = Convert.ToDateTime(t.Split('_')[0]).AddHours(row - 1); drAdd["Endtime"] = Convert.ToDateTime(t.Split('_')[0]).AddHours(row); drAdd["CountValue"] = 0; dataTable.Rows.Add(drAdd); } DataRow dr = dataTable.NewRow(); dr["CountID"] = dt.Rows[0]["CountID"].ToString(); dr["Starttime"] = t.Split('_')[0]; dr["Endtime"] = Convert.ToDateTime(t.Split('_')[0]).AddHours(1); dr["CountValue"] = t.Split('_')[1]; dataTable.Rows.Add(dr); } break; case ChartUnit.unit_month: if (Convert.ToDateTime(t.Split('_')[0]).Subtract(DateTime.Parse(model.Starttime.ToString("yyyy-MM-01"))).Days >= 0 && Convert.ToDateTime(t.Split('_')[0]).Subtract(model.Endtime).Days <= 0) { int Count = 0; if (hourCount > 0) { int yearCha = Convert.ToDateTime(listV[hourCount].Split('_')[0]).Year - Convert.ToDateTime(listV[hourCount - 1].Split('_')[0]).Year; int monthCha = Convert.ToDateTime(listV[hourCount].Split('_')[0]).Month - Convert.ToDateTime(listV[hourCount - 1].Split('_')[0]).Month; Count = yearCha * 12 + monthCha; } for (int row = 1; row < Count; row++) { DataRow drAdd = dataTable.NewRow(); drAdd["CountID"] = dt.Rows[0]["CountID"].ToString(); drAdd["Starttime"] = Convert.ToDateTime(t.Split('_')[0]).AddMonths(row - 1); drAdd["Endtime"] = Convert.ToDateTime(t.Split('_')[0]).AddMonths(row); drAdd["CountValue"] = 0; dataTable.Rows.Add(drAdd); } DataRow dr = dataTable.NewRow(); dr["CountID"] = dt.Rows[0]["CountID"].ToString(); dr["Starttime"] = t.Split('_')[0]; dr["Endtime"] = Convert.ToDateTime(t.Split('_')[0]).AddMonths(1); dr["CountValue"] = t.Split('_')[1]; dataTable.Rows.Add(dr); } break; //case ChartUnit.unit_year: // if (Convert.ToDateTime(t.Split('_')[0]).Subtract(model.Starttime).Days >= 0 && // Convert.ToDateTime(t.Split('_')[0]).Subtract(model.Endtime).Days <= 0) // { // DataRow dr = dataTable.NewRow(); // dr["CountID"] = dt.Rows[0]["CountID"].ToString(); // dr["Starttime"] = t.Split('_')[0]; // dr["Endtime"] = Convert.ToDateTime(t.Split('_')[0]).AddMonths(1); // dr["CountValue"] = t.Split('_')[1]; // dataTable.Rows.Add(dr); // } // break; } #endregion } hourCount++; } } return(dataTable); } } return(dt); }
/// <summary> /// 噪音数据上报 /// //string.Format("&&DataTime={0};" + // "a01001-Rtd={1},a01001-Flag=N;" + // "a01002-Rtd={2},a01002-Flag=N;" + // "a01006-Rtd={3},a01006-Flag=N;" + // "a01007-Rtd={4},a01007-Flag=N;" + // "a01008-Rtd={5},a01008-Flag=N;" + // "a34001-Rtd={6},a34001-Flag=N;" + // "a34002-Rtd={7},a34002-Flag=N;" + // "a34004-Rtd={8},a34004-Flag=N;" + // "La-Rtd={9},La-Flag=N;" + // "longitude={10};latitude={11};&&", // DateTime.Now.ToString("yyyyMMddhhmmss"), // _baseDataModel.temperature, //温度 摄氏度 // _baseDataModel.humidity, //湿度 % // 0, //气压 千帕 // _baseDataModel.windSpeed, //风速 米/秒 // _baseDataModel.windDirection, //风向 角度 // _baseDataModel.TSP, //总悬浮颗粒物 TSP // _baseDataModel.PM10, //可吸入颗粒物 PM10 // _baseDataModel.PM25, //细微颗粒物 PM2.5 // _baseDataModel.noise, //噪声 分贝 // _baseDataModel.longitude, // _baseDataModel.latitude // ) /// </summary> public void UploadData(BaseDataModel _baseDataModel) { RequstModel requstModel = new RequstModel(); StringBuilder cpsb = new StringBuilder(); cpsb.Append("&&").AppendFormat("DataTime={0};", DateTime.Now.ToString("yyyyMMddhhmmss")); if (!string.IsNullOrEmpty(_baseDataModel.temperature))//温度 摄氏度 { cpsb.AppendFormat("a01001-Rtd={0},a01001-Flag=N;", _baseDataModel.temperature); } if (!string.IsNullOrEmpty(_baseDataModel.humidity))//湿度 % { cpsb.AppendFormat("a01002-Rtd={0},a01002-Flag=N;", _baseDataModel.humidity); } if (!string.IsNullOrEmpty(_baseDataModel.windSpeed))//风速 米/秒 { cpsb.AppendFormat("a01007-Rtd={0},a01007-Flag=N;", _baseDataModel.windSpeed); } if (!string.IsNullOrEmpty(_baseDataModel.windDirection))//风向 角度 { cpsb.AppendFormat("a01008-Rtd={0},a01008-Flag=N;", _baseDataModel.windDirection); } if (!string.IsNullOrEmpty(_baseDataModel.TSP))//总悬浮颗粒物 TSP { cpsb.AppendFormat("a34001-Rtd={0},a34001-Flag=N;", _baseDataModel.TSP); } if (!string.IsNullOrEmpty(_baseDataModel.PM10))//可吸入颗粒物 PM10 { cpsb.AppendFormat("a34002-Rtd={0},a34002-Flag=N;", _baseDataModel.PM10); } if (!string.IsNullOrEmpty(_baseDataModel.PM25))//细微颗粒物 PM2.5 { cpsb.AppendFormat("a34004-Rtd={0},a34004-Flag=N;", _baseDataModel.PM25); } if (!string.IsNullOrEmpty(_baseDataModel.noise))//噪声 分贝 { cpsb.AppendFormat("La-Rtd={0},La-Flag=N;", _baseDataModel.noise); } if (!string.IsNullOrEmpty(_baseDataModel.longitude))//经度 { cpsb.AppendFormat("longitude={0};", _baseDataModel.longitude); } if (!string.IsNullOrEmpty(_baseDataModel.latitude))//纬度 { cpsb.AppendFormat("latitude={0};", _baseDataModel.latitude); } cpsb.Append("&&"); string resultStr = requstModel.ToString(new DataModel() { QN = DateTime.Now.ToString("yyyyMMddHHmmssfff"), ST = "39", CN = "2011", PW = "123456", MN = _baseDataModel.deviceAddress, Flag = "5", CP = cpsb.ToString(), }); byte[] sendData = Encoding.ASCII.GetBytes(resultStr); tcpSend(sendData); //do //{ // Thread.Sleep(1000); // if (isEnd) // { // break; // } //} while (true); _log.InfoFormat("{0}{1} MonitoringPollutantsTask 数据上传完成 设备号:{2}", DateTime.Now, Environment.NewLine, _baseDataModel.deviceAddress); _client.Close(); _client.Dispose(); }
public override void ChangeAction(BaseDataModel model) { _model = (CampBaseModel)model; SetUpElement(); SetSelect(); }