using SqlSugar; using System.ComponentModel; using System.Reflection; using WCS.Protocol.HJ.DataStructure; using WMS.Info.Models.WCSDeviceMonitor; namespace WMS.BZWeb.Extensions { public static class WCSDBAttributeExtensions { public static DBDetail GetAttributesDBDetail(this SRMData obj) { DBDetail dBDetail = new DBDetail() { DBName = new List(), DBDatas = new Dictionary>() }; List list = new List(); if (obj.D521 != null) { var WCS_SRM521IntefaceType = obj.D521?.GetType().GetInterfaces()[0]; var WCS_SRM521IntefaceProperties = WCS_SRM521IntefaceType.GetProperties(); foreach (PropertyInfo pi in obj.D521?.GetType()?.GetProperties()) { string describle = string.Empty; foreach (PropertyInfo intefacePropertyInfo in WCS_SRM521IntefaceProperties) { if (pi.Name == intefacePropertyInfo.Name) { var descriptionAttribute = intefacePropertyInfo.GetCustomAttribute(); if (descriptionAttribute != null) { describle = descriptionAttribute.Description; } break; } } string proname = "DB521_" + pi.Name; var abc = pi.GetValue(obj.D521, null); if (abc == null) continue; list.Add(new DBData { Name = proname, Desc = describle, Value = abc.ToString() }); } dBDetail.DBName.Add("DB521"); dBDetail.DBDatas.Add("DB521", list); } if (obj.D520 != null) { var WCS_SRM520IntefaceType = obj.D520?.GetType().GetInterfaces()[0]; var WCS_SRM520IntefaceProperties = WCS_SRM520IntefaceType.GetProperties(); list = new List(); foreach (PropertyInfo pi in obj.D520?.GetType()?.GetProperties()) { string describle = string.Empty; foreach (PropertyInfo intefacePropertyInfo in WCS_SRM520IntefaceProperties) { if (pi.Name == intefacePropertyInfo.Name) { var descriptionAttribute = intefacePropertyInfo.GetCustomAttribute(); if (descriptionAttribute != null) { describle = descriptionAttribute.Description; } break; } } string proname = "DB520_" + pi.Name; var abc = pi.GetValue(obj.D520, null); if (abc == null) continue; list.Add(new DBData { Name = proname, Desc = describle, Value = abc.ToString() }); } dBDetail.DBName.Add("DB520"); dBDetail.DBDatas.Add("DB520", list); } if (obj.D537 != null) { list = new List(); var WCS_SRM537IntefaceType = obj.D537?.GetType().GetInterfaces()[0]; var WCS_SRM537IntefaceProperties = WCS_SRM537IntefaceType.GetProperties(); foreach (PropertyInfo pi in obj.D537?.GetType()?.GetProperties()) { string describle = string.Empty; foreach (PropertyInfo intefacePropertyInfo in WCS_SRM537IntefaceProperties) { if (pi.Name == intefacePropertyInfo.Name) { var descriptionAttribute = intefacePropertyInfo.GetCustomAttribute(); if (descriptionAttribute != null) { describle = descriptionAttribute.Description; } break; } } string proname = "DB537_" + pi.Name; var abc = pi.GetValue(obj.D537, null); if (abc == null) continue; list.Add(new DBData { Name = proname, Desc = describle, Value = abc.ToString() }); } dBDetail.DBName.Add("DB537"); dBDetail.DBDatas.Add("DB537", list); } return dBDetail; } public static DBDetail GetAttributesDBDetail(this StationData obj) { DBDetail dBDetail = new DBDetail() { DBName = new List(), DBDatas = new Dictionary>() }; List list = new List(); if (obj.D521 != null) { var WCS_Station521IntefaceType = obj.D521?.GetType().GetInterfaces()[0]; var WCS_Station521IntefaceProperties = WCS_Station521IntefaceType.GetProperties(); foreach (PropertyInfo pi in obj.D521?.GetType()?.GetProperties()) { string describle = string.Empty; foreach (PropertyInfo intefacePropertyInfo in WCS_Station521IntefaceProperties) { if (pi.Name == intefacePropertyInfo.Name) { var descriptionAttribute = intefacePropertyInfo.GetCustomAttribute(); if (descriptionAttribute != null) { describle = descriptionAttribute.Description; } break; } } string proname = "DB521_" + pi.Name; var abc = pi.GetValue(obj.D521, null); if (abc == null) continue; list.Add(new DBData { Name = proname, Desc = describle, Value = abc.ToString() }); } dBDetail.DBName.Add("DB521"); dBDetail.DBDatas.Add("DB521", list); } if (obj.D520 != null) { list = new List(); var WCS_Station520IntefaceType = obj.D520?.GetType().GetInterfaces()[0]; var WCS_Station520IntefaceProperties = WCS_Station520IntefaceType.GetProperties(); foreach (PropertyInfo pi in obj.D520?.GetType()?.GetProperties()) { string describle = string.Empty; foreach (PropertyInfo intefacePropertyInfo in WCS_Station520IntefaceProperties) { if (pi.Name == intefacePropertyInfo.Name) { var descriptionAttribute = intefacePropertyInfo.GetCustomAttribute(); if (descriptionAttribute != null) { describle = descriptionAttribute.Description; } break; } } string proname = "DB520_" + pi.Name; var abc = pi.GetValue(obj.D520, null); if (abc == null) continue; list.Add(new DBData { Name = proname, Desc = describle, Value = abc.ToString() }); } dBDetail.DBName.Add("DB520"); dBDetail.DBDatas.Add("DB520", list); } if (obj.D523 != null) { list = new List(); var WCS_Station523IntefaceType = obj.D523?.GetType().GetInterfaces()[0]; var WCS_Station523IntefaceProperties = WCS_Station523IntefaceType.GetProperties(); foreach (PropertyInfo pi in obj.D523?.GetType()?.GetProperties()) { string describle = string.Empty; foreach (PropertyInfo intefacePropertyInfo in WCS_Station523IntefaceProperties) { if (pi.Name == intefacePropertyInfo.Name) { var descriptionAttribute = intefacePropertyInfo.GetCustomAttribute(); if (descriptionAttribute != null) { describle = descriptionAttribute.Description; } break; } } string proname = "DB523_" + pi.Name; var abc = pi.GetValue(obj.D523, null); if (abc == null) continue; list.Add(new DBData { Name = proname, Desc = describle, Value = abc.ToString() }); } dBDetail.DBName.Add("DB523"); dBDetail.DBDatas.Add("DB523", list); } if (obj.D80 != null) { var WCS_Station80IntefaceType = obj.D80?.GetType().GetInterfaces()[0]; var WCS_Station80IntefaceProperties = WCS_Station80IntefaceType.GetProperties(); list = new List(); foreach (PropertyInfo pi in obj.D80?.GetType()?.GetProperties()) { string describle = string.Empty; foreach (PropertyInfo intefacePropertyInfo in WCS_Station80IntefaceProperties) { if (pi.Name == intefacePropertyInfo.Name) { var descriptionAttribute = intefacePropertyInfo.GetCustomAttribute(); if (descriptionAttribute != null) { describle = descriptionAttribute.Description; } break; } } string proname = "DB80_" + pi.Name; var abc = pi.GetValue(obj.D80, null); //if (abc == null) continue; list.Add(new DBData { Name = proname, Desc = describle, Value = abc?.ToString() }); } dBDetail.DBName.Add("DB80"); dBDetail.DBDatas.Add("DB80", list); } if (obj.D81 != null) { var WCS_Station81IntefaceType = obj.D81?.GetType().GetInterfaces()[0]; var WCS_Station81IntefaceProperties = WCS_Station81IntefaceType.GetProperties(); list = new List(); foreach (PropertyInfo pi in obj.D81?.GetType()?.GetProperties()) { string describle = string.Empty; foreach (PropertyInfo intefacePropertyInfo in WCS_Station81IntefaceProperties) { if (pi.Name == intefacePropertyInfo.Name) { var descriptionAttribute = intefacePropertyInfo.GetCustomAttribute(); if (descriptionAttribute != null) { describle = descriptionAttribute.Description; } break; } } string proname = "DB81_" + pi.Name; var abc = pi.GetValue(obj.D81, null); //if (abc == null) continue; list.Add(new DBData { Name = proname, Desc = describle, Value = abc?.ToString() }); } dBDetail.DBName.Add("DB81"); dBDetail.DBDatas.Add("DB81", list); } if (obj.D91 != null) { var WCS_Station91IntefaceType = obj.D91?.GetType().GetInterfaces()[0]; var WCS_Station91IntefaceProperties = WCS_Station91IntefaceType.GetProperties(); list = new List(); foreach (PropertyInfo pi in obj.D91?.GetType()?.GetProperties()) { string describle = string.Empty; foreach (PropertyInfo intefacePropertyInfo in WCS_Station91IntefaceProperties) { if (pi.Name == intefacePropertyInfo.Name) { var descriptionAttribute = intefacePropertyInfo.GetCustomAttribute(); if (descriptionAttribute != null) { describle = descriptionAttribute.Description; } break; } } string proname = "DB91_" + pi.Name; var abc = pi.GetValue(obj.D91, null); if (abc == null) continue; list.Add(new DBData { Name = proname, Desc = describle, Value = abc.ToString() }); } dBDetail.DBName.Add("DB91"); dBDetail.DBDatas.Add("DB91", list); } return dBDetail; } //public static DBDetail GetAttributesDBDetail(this RGVData obj) //{ // DBDetail dBDetail = new DBDetail() { DBName = new List(), DBDatas = new Dictionary>() }; // List list = new List(); // foreach (PropertyInfo pi in obj.D521?.GetType()?.GetProperties()) // { // AttributeCollection attributes = TypeDescriptor.GetProperties(obj.D521.GetType())[pi.Name].Attributes; // DescriptionAttribute myAttribute = (DescriptionAttribute)attributes[typeof(DescriptionAttribute)]; // string describle = myAttribute.Description; // string proname = "DB521_" + pi.Name; // var abc = pi.GetValue(obj.D521, null); // if (abc == null) continue; // // list.Add(new DBData { Name = proname, Desc = describle, Value = abc.ToString() }); // } // dBDetail.DBName.Add("DB521"); // dBDetail.DBDatas.Add("DB521", list); // list = new List(); // foreach (PropertyInfo pi in obj.D520?.GetType()?.GetProperties()) // { // AttributeCollection attributes = TypeDescriptor.GetProperties(obj.D520.GetType())[pi.Name].Attributes; // DescriptionAttribute myAttribute = (DescriptionAttribute)attributes[typeof(DescriptionAttribute)]; // string describle = myAttribute.Description; // string proname = "DB520_" + pi.Name; // var abc = pi.GetValue(obj.D520, null); // if (abc == null) continue; // list.Add(new DBData { Name = proname, Desc = describle, Value = abc.ToString() }); // } // dBDetail.DBName.Add("DB520"); // dBDetail.DBDatas.Add("DB520", list); // list = new List(); // foreach (PropertyInfo pi in obj.D523?.GetType()?.GetProperties()) // { // AttributeCollection attributes = TypeDescriptor.GetProperties(obj.D523.GetType())[pi.Name].Attributes; // DescriptionAttribute myAttribute = (DescriptionAttribute)attributes[typeof(DescriptionAttribute)]; // string describle = myAttribute.Description; // string proname = "DB523_" + pi.Name; // var abc = pi.GetValue(obj.D523, null); // if (abc == null) continue; // list.Add(new DBData { Name = proname, Desc = describle, Value = abc.ToString() }); // } // dBDetail.DBName.Add("DB523"); // dBDetail.DBDatas.Add("DB523", list); // return dBDetail; //} } }