public string GetPlaceDisplayName(IReadOnlyDbContext db) { var passive = db.FindById <Passive>(PatchPanel); var rack = db.FindById <Rack>(passive.Place); var room = db.FindById <Room>(rack.Parent); StringBuilder sb = new StringBuilder(); sb.Append("اتاق/سالن ").Append(room.Name).Append(" ⇐ ") .Append("راک ").Append(rack.Name).Append(" ⇐ "); if (passive.Type == Passive.PassiveTypeEnum.PatchPanel) { sb.Append("پچ پنل "); } else if (passive.Type == Passive.PassiveTypeEnum.Transmissional) { sb.Append("تجهیز انتقال ") .Append(DisplayUtils.DisplayName(passive.TransmissionType)) .Append(" "); } else { throw new NotImplementedException(); } sb.Append(passive.Name); return(sb.ToString()); }
public override string ToString() { var disp = DisplayUtils.DisplayName(Type) + " " + Model; if (!string.IsNullOrWhiteSpace(Address)) { disp += " (" + Address + ")"; } return(disp); }
public Dictionary <PropertyInfo, string> CreateDataTableColumns <T>(DataTable table, bool convertDateToPersian = true, bool includeTimeInDates = true, bool addIndexColumn = false, string[] excludeColumns = null) { PropertyInfo[] props = typeof(T).GetProperties(); Dictionary <PropertyInfo, string> displayNames = new Dictionary <PropertyInfo, string>(); if (addIndexColumn && !table.Columns.Contains(INDEX_COLUMN)) { table.Columns.Add(INDEX_COLUMN, typeof(int)); } foreach (PropertyInfo p in props) { if (excludeColumns != null && excludeColumns.Contains(p.Name)) { continue; } string dispName = DisplayUtils.DisplayName(p); displayNames.Add(p, dispName); if (table.Columns.Contains(dispName)) { continue; } Type propType = p.PropertyType; if (propType.IsEquivalentTo(typeof(ObjectId)) || propType.IsEnum || p.PropertyType.GetInterfaces().Contains(typeof(IEnumerable))) { propType = typeof(string); } else if (propType == typeof(DateTime) && (!includeTimeInDates || convertDateToPersian)) { propType = typeof(string); } else { Type undelying = Nullable.GetUnderlyingType(propType); if (undelying != null) { propType = undelying; if (propType == typeof(DateTime) && (!includeTimeInDates || convertDateToPersian)) { propType = typeof(string); } } } DataColumn col = new DataColumn(dispName, propType); table.Columns.Add(col); } return(displayNames); }
public string GetPlaceDisplay(IReadOnlyDbContext db) { StringBuilder sb = new StringBuilder(); if (PlaceType == DevicePlaceType.Rack) { var rack = db.FindById <Rack>(Place); var room = db.FindById <Room>(rack.Parent); var building = db.FindById <Building>(room.Parent); var center = db.FindById <CommCenter>(building.Parent); var city = db.FindById <City>(center.City); sb.Append(city.Name).Append(" ⇐ ") .Append("مرکز ").Append(center.Name).Append(" ⇐ ") .Append("ساختمان ").Append(building.Name).Append(" ⇐ ") .Append("اتاق/سالن ").Append(room.Name).Append(" ⇐ ") .Append("راک ").Append(rack.Name).Append(" ⇐ ") .Append("دستگاه ").Append(ToString()); } else if (PlaceType == DevicePlaceType.Kafu) { var kafu = db.FindById <Kafu>(Place); var center = db.FindById <CommCenter>(kafu.CommCenter); var city = db.FindById <City>(center.City); sb.Append(city.Name).Append(" ⇐ ") .Append("مرکز ").Append(center.Name).Append(" ⇐ ") .Append("کافو ").Append(DisplayUtils.DisplayName(kafu.Type)) .Append(" \"").Append(kafu.Name).Append("\""); } else { throw new NotImplementedException(); } return(sb.ToString()); }
public override string ToString() { return(DisplayUtils.DisplayName(Type) + " " + Model); }
public override string ToString() { return(DisplayUtils.DisplayName(Type) + " " + Current.ToString()); }
public override string ToString() { return(DisplayUtils.DisplayName(Type) + " \"" + Name + "\" تعداد: " + Count); }
public static void CreateUI <T>(Table table, bool enabled = true, int columnCount = 2, Dictionary <string, int> fieldsColSpan = null, Dictionary <string, ControlType> overrideTypes = null, Dictionary <string, List <ListItem> > comboItems = null, string[] excludeFields = null) { table.Rows.Clear(); TableRow row = null; int i = 0; foreach (PropertyInfo prop in typeof(T).GetProperties().Where(p => excludeFields == null || !excludeFields.Contains(p.Name))) { Type ptype = prop.PropertyType; ControlType controlType; if (overrideTypes != null && overrideTypes.ContainsKey(prop.Name)) { controlType = overrideTypes[prop.Name]; } else { controlType = GetControlType(ptype); } if (controlType == ControlType.Unknown) { continue; } if (i % columnCount == 0) { if (i != 0) { table.Rows.Add(row); } row = new TableRow(); } if (fieldsColSpan != null && fieldsColSpan.ContainsKey(prop.Name) && i % columnCount + fieldsColSpan[prop.Name] > columnCount) { table.Rows.Add(row); row = new TableRow(); i += columnCount - (i % columnCount); } Label lbl = new Label { Text = DisplayUtils.DisplayName(prop) + ":" }; TableCell titleCell = new TableCell(); titleCell.Controls.Add(lbl); row.Cells.Add(titleCell); TableCell validationCell = new TableCell(); string controlID = "ac_" + prop.Name; RequiredAttribute reqAttr = prop.GetCustomAttribute <RequiredAttribute>(); if (reqAttr != null) { RequiredFieldValidator reqValidator = new RequiredFieldValidator { ControlToValidate = controlID, ForeColor = Color.Red, Text = "*", ErrorMessage = reqAttr.ErrorMessage }; validationCell.Controls.Add(reqValidator); } RegularExpressionAttribute regexAttr = prop.GetCustomAttribute <RegularExpressionAttribute>(); if (regexAttr != null) { RegularExpressionValidator regexValidator = new RegularExpressionValidator { ControlToValidate = controlID, ForeColor = Color.Red, Text = "*", ValidationExpression = regexAttr.Pattern, ErrorMessage = regexAttr.ErrorMessage }; validationCell.Controls.Add(regexValidator); } row.Cells.Add(validationCell); WebControl ctrl = null; switch (controlType) { case ControlType.Text: ctrl = new TextBox(); break; case ControlType.Number: ctrl = new TextBox { TextMode = TextBoxMode.Number }; break; case ControlType.Combo: ctrl = new DropDownList(); if (comboItems != null && comboItems.ContainsKey(prop.Name)) { foreach (ListItem item in comboItems[prop.Name]) { (ctrl as DropDownList).Items.Add(item); } } else { Array enumVals = ptype.GetEnumValues(); for (int j = 0; j < enumVals.Length; j++) { string name = enumVals.GetValue(j).ToString(); string dispName = DisplayUtils.DisplayName(ptype, name); (ctrl as DropDownList).Items.Add(new ListItem(dispName, name)); } } break; case ControlType.Check: ctrl = new CheckBox(); break; default: break; } if (ctrl == null) { continue; } ctrl.Enabled = enabled; ctrl.ID = controlID; TableCell ctrlCell = new TableCell(); if (fieldsColSpan != null && fieldsColSpan.ContainsKey(prop.Name)) { int span = fieldsColSpan[prop.Name]; ctrlCell.ColumnSpan = (span - 1) * 3 + 1; i += span - 1; ctrl.Style.Add("width", "99%"); } ctrlCell.Controls.Add(ctrl); row.Cells.Add(ctrlCell); i++; } table.Rows.Add(row); }
public DataTable Create <T>(DataTable table, IEnumerable <T> list, bool convertDateToPersian = true, bool includeTimeInDates = true, bool addIndexColumn = false, string[] excludeColumns = null, Dictionary <string, Dictionary <ObjectId, string> > valuesReferenceReplacement = null) { if (list == null) { return(null); } Dictionary <PropertyInfo, string> displayNames = CreateDataTableColumns <T>(table, convertDateToPersian, includeTimeInDates, addIndexColumn, excludeColumns); int i = 1; foreach (T item in list) { DataRow row = table.NewRow(); if (addIndexColumn) { row[INDEX_COLUMN] = i++; } foreach (PropertyInfo p in displayNames.Keys) { object value = p.GetValue(item); if (value is ObjectId) { if (valuesReferenceReplacement != null && valuesReferenceReplacement.ContainsKey(p.Name)) { if (valuesReferenceReplacement[p.Name].ContainsKey((ObjectId)value)) { value = valuesReferenceReplacement[p.Name][(ObjectId)value]; } else { value = null; } } else { value = value.ToString(); } } else if (p.PropertyType.IsEnum) { value = DisplayUtils.DisplayName(p.PropertyType, value.ToString()); } else if (value is DateTime && convertDateToPersian) { value = PersianDateUtils.GetPersianDateString((DateTime)value, includeTimeInDates); } else if (value is IEnumerable && !(value is string)) { StringBuilder sb = new StringBuilder(); Type itemsType = null; foreach (var v in (IEnumerable)value) { if (itemsType == null) { itemsType = v.GetType(); } sb.Append(DisplayUtils.DisplayName(itemsType, v.ToString())).Append(" ; "); } if (sb.Length > 3) { sb.Remove(sb.Length - 3, 3); } value = sb.ToString(); } row[displayNames[p]] = value == null ? DBNull.Value : value; } table.Rows.Add(row); } return(table); }
private byte[] CreateExcelFile(List <EquipmentsPM> pms) { using var memStream = new MemoryStream(); ExcelPackage.LicenseContext = LicenseContext.NonCommercial; using var package = new ExcelPackage(memStream); var citiesDic = Cities.ToDictionary(i => i.Id); var centers = db.All <CommCenterX>().ToDictionary(i => i.Id); var usersName = GetUsersName(); // diesels sheet ExcelWorksheet sheet = package.Workbook.Worksheets.Add("دیزل ها"); sheet.View.RightToLeft = true; sheet.DefaultColWidth = 20; int col = 1; sheet.SetValue(1, col++, "شهر"); sheet.SetValue(1, col++, "مرکز"); sheet.SetValue(1, col++, "کاربر ثبت کننده"); sheet.SetValue(1, col++, "تاریخ ثبت"); sheet.SetValue(1, col++, "تاریخ تغییر"); Dictionary <PropertyInfo, int> columns = new Dictionary <PropertyInfo, int>(); PropertyInfo[] props = typeof(DieselPM).GetProperties(); for (int i = 0; i < 3; i++) { foreach (PropertyInfo p in props) { if (!columns.ContainsKey(p)) { columns.Add(p, col); } string dispName = DisplayUtils.DisplayName(p); sheet.SetValue(1, col++, (i + 1) + "-" + dispName); } } sheet.Row(1).Style.Font.Bold = true; int row = 2; foreach (var pm in pms) { if (centers.ContainsKey(pm.CenterId)) { if (citiesDic.ContainsKey(centers[pm.CenterId].City)) { sheet.SetValue(row, 1, citiesDic[centers[pm.CenterId].City].Name); } sheet.SetValue(row, 2, centers[pm.CenterId].Name); } if (usersName.ContainsKey(pm.ReportingUser)) { sheet.SetValue(row, 3, usersName[pm.ReportingUser]); } sheet.SetValue(row, 4, PersianDateUtils.GetPersianDateString(pm.SubmitDate)); sheet.SetValue(row, 5, PersianDateUtils.GetPersianDateString(pm.EditDate)); for (int i = 0; i < pm.DieselsPM.Count; i++) { int colOffset = i * (props.Length + 1); foreach (PropertyInfo prop in props) { object value = prop.GetValue(pm.DieselsPM[i]); if (value != null) { sheet.SetValue(row, columns[prop] + colOffset, value.ToString()); } } } row++; } // rectifiers sheet sheet = package.Workbook.Worksheets.Add("یکسوسازها"); sheet.View.RightToLeft = true; sheet.DefaultColWidth = 20; col = 1; sheet.SetValue(1, col++, "شهر"); sheet.SetValue(1, col++, "مرکز"); sheet.SetValue(1, col++, "کاربر ثبت کننده"); sheet.SetValue(1, col++, "تاریخ ثبت"); sheet.SetValue(1, col++, "تاریخ تغییر"); columns = new Dictionary <PropertyInfo, int>(); props = typeof(RectifierPM).GetProperties(); for (int i = 0; i < 3; i++) { foreach (PropertyInfo p in props) { if (!columns.ContainsKey(p)) { columns.Add(p, col); } string dispName = DisplayUtils.DisplayName(p); sheet.SetValue(1, col++, (i + 1) + "-" + dispName); } } sheet.Row(1).Style.Font.Bold = true; row = 2; foreach (var pm in pms) { if (centers.ContainsKey(pm.CenterId)) { if (citiesDic.ContainsKey(centers[pm.CenterId].City)) { sheet.SetValue(row, 1, citiesDic[centers[pm.CenterId].City].Name); } sheet.SetValue(row, 2, centers[pm.CenterId].Name); } if (usersName.ContainsKey(pm.ReportingUser)) { sheet.SetValue(row, 3, usersName[pm.ReportingUser]); } sheet.SetValue(row, 4, PersianDateUtils.GetPersianDateString(pm.SubmitDate)); sheet.SetValue(row, 5, PersianDateUtils.GetPersianDateString(pm.EditDate)); for (int i = 0; i < pm.RectifiersPM.Count; i++) { int colOffset = i * (props.Length + 1); foreach (PropertyInfo prop in props) { object value = prop.GetValue(pm.RectifiersPM[i]); if (value != null) { sheet.SetValue(row, columns[prop] + colOffset, value.ToString()); } } } row++; } // batteries sheet sheet = package.Workbook.Worksheets.Add("باتریها"); sheet.View.RightToLeft = true; sheet.DefaultColWidth = 20; col = 1; sheet.SetValue(1, col++, "شهر"); sheet.SetValue(1, col++, "مرکز"); sheet.SetValue(1, col++, "کاربر ثبت کننده"); sheet.SetValue(1, col++, "تاریخ ثبت"); sheet.SetValue(1, col++, "تاریخ تغییر"); for (int i = 0; i < 4; i++) { sheet.SetValue(1, col++, (i + 1) + "-" + DisplayUtils.DisplayName <BatteryPM.BatterySeriesPM>(bs => bs.DistilledWaterAdded)); sheet.SetValue(1, col++, (i + 1) + "-" + DisplayUtils.DisplayName <BatteryPM.BatterySeriesPM>(bs => bs.Temperature)); sheet.SetValue(1, col++, (i + 1) + "-" + DisplayUtils.DisplayName <BatteryPM.BatterySeriesPM>(bs => bs.OutputCurrent)); sheet.SetValue(1, col++, (i + 1) + "-" + DisplayUtils.DisplayName <BatteryPM.BatterySeriesPM>(bs => bs.Description)); for (int j = 1; j <= 25; j++) { sheet.SetValue(1, col++, "سری " + (i + 1) + " -ولتاژ سلول " + j); } for (int j = 1; j <= 25; j++) { sheet.SetValue(1, col++, "سری " + (i + 1) + " -غلظت سلول " + j); } } sheet.Row(1).Style.Font.Bold = true; row = 2; foreach (var pm in pms) { if (centers.ContainsKey(pm.CenterId)) { if (citiesDic.ContainsKey(centers[pm.CenterId].City)) { sheet.SetValue(row, 1, citiesDic[centers[pm.CenterId].City].Name); } sheet.SetValue(row, 2, centers[pm.CenterId].Name); } if (usersName.ContainsKey(pm.ReportingUser)) { sheet.SetValue(row, 3, usersName[pm.ReportingUser]); } sheet.SetValue(row, 4, PersianDateUtils.GetPersianDateString(pm.SubmitDate)); sheet.SetValue(row, 5, PersianDateUtils.GetPersianDateString(pm.EditDate)); col = 6; for (int i = 0; i < pm.BatteriesPM.Count; i++) { for (int j = 0; j < pm.BatteriesPM[i].Series.Count; j++) { sheet.SetValue(row, col++, pm.BatteriesPM[i].Series[j].DistilledWaterAdded); sheet.SetValue(row, col++, pm.BatteriesPM[i].Series[j].Temperature); sheet.SetValue(row, col++, pm.BatteriesPM[i].Series[j].OutputCurrent); sheet.SetValue(row, col++, pm.BatteriesPM[i].Series[j].Description); for (int k = 0; k < pm.BatteriesPM[i].Series[j].Voltages.Length; k++) { sheet.SetValue(row, col++, pm.BatteriesPM[i].Series[j].Voltages[k]); } for (int k = 0; k < pm.BatteriesPM[i].Series[j].Densities.Length; k++) { sheet.SetValue(row, col++, pm.BatteriesPM[i].Series[j].Densities[k]); } } } row++; } package.Save(); return(memStream.ToArray()); }