public IEnumerable <DataItem> GetDataItem(string organizationId, params string[] variableIds) { IList <DataItem> results = new List <DataItem>(); //string connStr = ConnectionStringFactory.NXJCConnectionString; //_dataFactory = new SqlServerDataFactory(connStr); //EnergyContrastHelper contrastHelper = new EnergyContrastHelper(_type); //foreach (var item in contrastHelper.GetRealtimeDatas(organizationId, variableIds)) //{ // results.Add(item); //} Dictionary <string, string> dataDic = RealtimeTagValueService.GetAnlogTagValue(organizationId, variableIds); foreach (string key in dataDic.Keys) { results.Add(new DataItem { ID = organizationId + ">" + key + ">" + _type, Value = dataDic[key]//table.Rows[0][item] is DBNull ? "0" : Convert.ToDecimal(table.Rows[0][item]).ToString("#").Trim() }); } //foreach (var item in GetRealtimeDatas(organizationId)) //{ // results.Add(item); //} return(results); }
public static Dictionary <string, string> GetDcsTime(string factoryId, string relatedTags) { Dictionary <string, string> dcsTime; string sumStr_new; relatedTags = relatedTags.Trim(';'); string[] relatedTagArray = relatedTags.Split('>'); if (relatedTagArray.Length > 2) { string[] sb = relatedTagArray[1].Split('_'); StringBuilder sumStr = new StringBuilder(); //string[] tagsArray = relatedTags.Split(',',';'); if (relatedTagArray[0] == "zc_nxjc_qtx_efc") { sumStr.Append("Db_02_01"); sumStr.Append("_"); sumStr.Append(sb[0]); } else { sumStr.Append(relatedTagArray[0]); sumStr.Append("_"); sumStr.Append(sb[0]); } sumStr_new = sumStr.ToString(); dcsTime = RealtimeTagValueService.GetDcsTime(factoryId, sumStr_new); } else { string[] sb = relatedTagArray[0].Split('_'); StringBuilder sumStr = new StringBuilder(); if (factoryId == "zc_nxjc_qtx_efc") { sumStr.Append("Db_02_01"); sumStr.Append("_"); sumStr.Append(sb[0]); sumStr_new = sumStr.ToString(); } else { sumStr.Append(factoryId); sumStr.Append("_"); sumStr.Append(sb[0]); sumStr_new = sumStr.ToString(); } dcsTime = RealtimeTagValueService.GetDcsTime(factoryId, sumStr_new); } return(dcsTime); }
public Dictionary <string, string> GetRunningTime(string ids) { string organizationIdDcs = ""; string organization = ""; Dictionary <string, string> EnergyTime = new Dictionary <string, string>(); string[] iditems = ids.Split(','); for (int i = 0; i < iditems.Length - 1; i++) { string[] itemArry = iditems[i].Split('>'); organization = itemArry[0]; string[] organizationArry = organization.Split('_'); if (organizationArry.Length < 5) { continue; } else { break; } } string connectionString = ConnectionStringFactory.NXJCConnectionString; ISqlServerDataFactory dataFactory = new SqlServerDataFactory(connectionString); string mySql = @"select A.[MeterDatabase],A.[DCSProcessDatabase] from system_Database AS A, system_Organization AS B where A.[DatabaseID]=B.[DatabaseID] and B.organizationid=@IdInformation "; SqlParameter myParameter = new SqlParameter("@IdInformation", organization); DataTable table = dataFactory.Query(mySql, myParameter); string organizationId = table.Rows[0][0].ToString(); organizationIdDcs = table.Rows[0][0].ToString(); if (organizationIdDcs == "Db_02_01") { organizationIdDcs = "zc_nxjc_qtx_efc"; } string dataBaseName = table.Rows[0][1].ToString(); EnergyTime = RealtimeTagValueService.GetDcsTime(organizationIdDcs, dataBaseName); string mySqlNew = @"select [vDate] from {0}.[dbo].[RealtimeAmmeter]"; DataTable tableAmmater = dataFactory.Query(string.Format(mySqlNew, organizationId)); EnergyTime.Add("Ammatertime", tableAmmater.Rows[0][0].ToString()); return(EnergyTime); }
/// <summary> /// 运行状态信息 /// </summary> /// <param name="factoryId"></param> /// <param name="relatedTags"></param> /// <returns></returns> public static Dictionary <string, string> GetRelatedTags(string factoryId, string relatedTags) { //DebugHelper.TestStart(); //ISqlServerDataFactory dataFactory = new SqlServerDataFactory(ConnectionStringFactory.NXJCConnectionString); //string ammeterDBName = ConnectionStringFactory.GetAmmeterDatabaseName(factoryId); Dictionary <string, RunningStatus> result_dic = new Dictionary <string, RunningStatus>(); Dictionary <string, string> resultStatus_dic = new Dictionary <string, string>(); relatedTags = relatedTags.Trim(';'); string[] relatedTagArray = relatedTags.Split(';'); //string[] tagsArray = relatedTags.Split(',',';'); //所有的标签集合 List <string> tagsList = new List <string>(); //标签字典,键为标签ID,值为存储相关标签的list IDictionary <string, IList <string> > tagDic = new Dictionary <string, IList <string> >(); foreach (string tagGroup in relatedTagArray) { string[] t_array = tagGroup.Split(','); if (t_array.Length != 0) { if (t_array[0].Trim() != "") { IList <string> t_list = t_array.ToList(); if (t_list.Remove(t_array[0])) { tagDic.Add(t_array[0], t_list); tagsList.AddRange(t_list); } } } } if (tagsList.Count() == 0) { //return result_dic; return(resultStatus_dic); } #region // // string mySql = @"select // TagName,DBName,TableName,FieldName // from // [{0}].[dbo].View_DCSContrast as A // where // "; // StringBuilder sqlBuilder = new StringBuilder(mySql); // List<SqlParameter> parameterList = new List<SqlParameter>(); // List<string> tempList = new List<string>(); // foreach (string item in tagsList) // { // string t_item = item.Trim(); // if ("" == t_item) //如果为空跳过 // { // continue; // } // else // { // if (!tempList.Contains(t_item)) // { // tempList.Add(t_item); // //sqlBuilder.Append("A.DCSName+'_'+A.FieldName=@" + t_item + " or ");//根据新视图可能需要改为:sqlBuilder.Append("A.DCSName+'_'+A.FieldName+'_'+A.TableName=@" + t_item + " or "); // sqlBuilder.Append("A.TagName=@" + t_item + " or "); // parameterList.Add(new SqlParameter(t_item, t_item)); // } // } // } // sqlBuilder=sqlBuilder.Remove(sqlBuilder.Length - 4, 4); // //DebugHelper.TestStart(); // DataTable baseTable = dataFactory.Query(string.Format(sqlBuilder.ToString(),ammeterDBName), parameterList.ToArray()); // //DebugHelper.TestStop("执行数字量视图sql时间(ms):"); // if (baseTable.Rows.Count == 0) // { // //return result_dic; // return resultStatus_dic; // } // string dataSql = @"select {0} // from {1}"; // StringBuilder itemBuilder = new StringBuilder(); // StringBuilder tableBuilder = new StringBuilder(); // List<string> itemList = new List<string>(); // List<string> tableList = new List<string>(); // foreach (DataRow dr in baseTable.Rows) // { // if (itemList.Contains(dr["TagName"].ToString().Trim())) // { // continue; // } // else // { // itemList.Add(dr["TagName"].ToString().Trim()); // itemBuilder.Append("["+dr["FieldName"].ToString().Trim()+"] as ["+dr["TagName"].ToString().Trim()+"]"); // itemBuilder.Append(","); // } // if (!tableList.Contains(dr["DBName"].ToString().Trim() + ".[dbo].Realtime_" + dr["TableName"].ToString().Trim())) // { // tableList.Add(dr["DBName"].ToString().Trim() + ".[dbo].Realtime_" + dr["TableName"].ToString().Trim()); // tableBuilder.Append(dr["DBName"].ToString().Trim() + ".[dbo].Realtime_" + dr["TableName"].ToString().Trim()); // tableBuilder.Append(","); // } // } // itemBuilder.Remove(itemBuilder.Length - 1, 1); // tableBuilder.Remove(tableBuilder.Length - 1, 1); // //DebugHelper.TestStart(); // DataTable dataTable = dataFactory.Query(string.Format(dataSql,itemBuilder.ToString(),tableBuilder)); // //DebugHelper.TestStop("执行数字量数据sql查询时间(ms):"); // //DebugHelper.TestStart(); // Dictionary<string, bool> dataDictionary = new Dictionary<string, bool>();//标签字典 // foreach(DataColumn dc in dataTable.Columns) // { // string columnName = dc.ColumnName; // if (!dataDictionary.Keys.Contains(columnName)) // { // bool flag=dataTable.Rows[0][columnName] is DBNull?false:Convert.ToBoolean(dataTable.Rows[0][columnName]); // dataDictionary.Add(columnName, flag); // } // } #endregion #region //foreach (string tagGroup in relatedTagArray) //{ // string[] tags_arr = tagGroup.Split(','); // for (int i = 0; i < tags_arr.Length; i++) // { // tags_arr[i] = tags_arr[i].Trim(); // } // if (tags_arr.Count() !=7 ) // { // continue; // } // else // { // if (!result_dic.Keys.Contains(factoryId + ">" + tags_arr[0]+ ">BoolSignal") ) // { // RunningStatus runningStatusObj = new RunningStatus(); // runningStatusObj.KeepReady = tags_arr[0] == "" || !dataDictionary.Keys.Contains(tags_arr[0]) ? false : dataDictionary[tags_arr[0]]; // runningStatusObj.Foreward = tags_arr[1] == "" || !dataDictionary.Keys.Contains(tags_arr[1]) ? false : dataDictionary[tags_arr[1]]; // runningStatusObj.Reversal = tags_arr[2] == "" || !dataDictionary.Keys.Contains(tags_arr[2]) ? false : dataDictionary[tags_arr[2]]; // runningStatusObj.LocaleForeward = tags_arr[3] == "" || !dataDictionary.Keys.Contains(tags_arr[3]) ? false : dataDictionary[tags_arr[3]]; // runningStatusObj.LocaleReversal = tags_arr[4] == "" || !dataDictionary.Keys.Contains(tags_arr[4]) ? false : dataDictionary[tags_arr[4]]; // runningStatusObj.Breakdown = tags_arr[5] == "" || !dataDictionary.Keys.Contains(tags_arr[5]) ? false : dataDictionary[tags_arr[5]]; // runningStatusObj.Stop = tags_arr[6] == "" || !dataDictionary.Keys.Contains(tags_arr[6]) ? false : dataDictionary[tags_arr[6]]; // result_dic.Add(factoryId + ">" + tags_arr[0] + ">BoolSignal", runningStatusObj); // } // } //} #endregion Dictionary <string, bool> dataDictionary = RealtimeTagValueService.GetBoolTagValue(factoryId, tagsList.ToArray()); string status = ""; foreach (string tagId in tagDic.Keys) { status = "";//每次循环都复位一下 string[] tags_arr = tagDic[tagId].ToArray(); for (int i = 0; i < tags_arr.Length; i++) { tags_arr[i] = tags_arr[i].Trim(); } if (tags_arr.Count() == 0) { continue; } else { if (!result_dic.Keys.Contains(tagId)) { #region //RunningStatus runningStatusObj = new RunningStatus(); //runningStatusObj.KeepReady = tags_arr[0] == "" || !dataDictionary.Keys.Contains(tags_arr[0]) ? false : dataDictionary[tags_arr[0]]; //runningStatusObj.Foreward = tags_arr[1] == "" || !dataDictionary.Keys.Contains(tags_arr[1]) ? false : dataDictionary[tags_arr[1]]; //runningStatusObj.Reversal = tags_arr[2] == "" || !dataDictionary.Keys.Contains(tags_arr[2]) ? false : dataDictionary[tags_arr[2]]; //runningStatusObj.LocaleForeward = tags_arr[3] == "" || !dataDictionary.Keys.Contains(tags_arr[3]) ? false : dataDictionary[tags_arr[3]]; //runningStatusObj.LocaleReversal = tags_arr[4] == "" || !dataDictionary.Keys.Contains(tags_arr[4]) ? false : dataDictionary[tags_arr[4]]; //runningStatusObj.Breakdown = tags_arr[5] == "" || !dataDictionary.Keys.Contains(tags_arr[5]) ? false : dataDictionary[tags_arr[5]]; //runningStatusObj.Stop = tags_arr[6] == "" || !dataDictionary.Keys.Contains(tags_arr[6]) ? false : dataDictionary[tags_arr[6]]; //result_dic.Add( tagId , runningStatusObj); #endregion resultStatus_dic.Add(tagId, GetStatus(dataDictionary, tags_arr)); } } } //DebugHelper.TestStop("数字量键值对生成(ms):"); //DebugHelper.TestStop("数字量查询总时间(ms):"); //return result_dic; return(resultStatus_dic); }