)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » Framework (Ia.Ftn.Cl.Models.Ui.Administration)

Public general use code classes and xml files that we've compiled and used over the years:

Network Design Document support class for Fixed Telecommunications Network (FTN) UI model.

    1: using Microsoft.AspNetCore.Identity;
    2: using System.Collections.Generic;
    3: using System.Data;
    4: using System.Linq;
    5: using System.Runtime.Serialization;
    6:  
    7: namespace Ia.Ftn.Cl.Models.Ui.Administration
    8: {
    9:     ////////////////////////////////////////////////////////////////////////////
   10:  
   11:     /// <summary publish="true">
   12:     /// Network Design Document support class for Fixed Telecommunications Network (FTN) UI model.
   13:     /// </summary>
   14:     /// 
   15:     /// <remarks> 
   16:     /// Copyright © 2006-2021 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   17:     ///
   18:     /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
   19:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   20:     ///
   21:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   22:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   23:     /// 
   24:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   25:     /// 
   26:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   27:     /// </remarks> 
   28:     public class Framework
   29:     {
   30:         private static Ia.Ftn.Cl.Models.StaffIdentityUser headStaff;
   31:         private static List<Ia.Ftn.Cl.Models.StaffIdentityUser> staffList;
   32:  
   33:         ////////////////////////////////////////////////////////////////////////////
   34:  
   35:         /// <summary>
   36:         ///
   37:         /// </summary>
   38:         public Framework() { }
   39:  
   40:         ////////////////////////////////////////////////////////////////////////////    
   41:  
   42:         /// <summary>
   43:         /// 
   44:         /// </summary>
   45:         public static string FrameworkStructureDataTable()
   46:         {
   47:             string htmlTable;
   48:             List<Ia.Ftn.Cl.Models.Business.Administration.Framework> frameworkList;
   49:  
   50:             frameworkList = (from f in Ia.Ftn.Cl.Models.Data.Administration.FrameworkList
   51:                              where f.Type == "ministry" || f.Type == "supplier"
   52:                              select f).ToList();
   53:  
   54:             htmlTable = @"<div id=""framework-structure"">";
   55:  
   56:             foreach (Ia.Ftn.Cl.Models.Business.Administration.Framework framework in frameworkList)
   57:             {
   58:                 htmlTable += FrameworkStructureDataTableIteration(framework);
   59:             }
   60:  
   61:             htmlTable += "</div>";
   62:  
   63:             return htmlTable;
   64:         }
   65:  
   66:         ////////////////////////////////////////////////////////////////////////////    
   67:  
   68:         /// <summary>
   69:         /// 
   70:         /// </summary>
   71:         private static string FrameworkStructureDataTableIteration(Ia.Ftn.Cl.Models.Business.Administration.Framework framework)
   72:         {
   73:             string htmlTable;
   74:             Ia.Ftn.Cl.Models.StaffIdentityUser headStaff;
   75:             List<Ia.Ftn.Cl.Models.StaffIdentityUser> staffList;
   76:  
   77:             htmlTable = null;
   78:  
   79:             if (framework != null)
   80:             {
   81:                 headStaff = (from s in Ia.Ftn.Cl.Models.Data.StaffIdentityUser.List() where s.Framework != null && s.Framework.Id == framework.Id && s.IsHead select s).SingleOrDefault();
   82:  
   83:                 htmlTable = "<table>";
   84:  
   85:                 if (framework.Children.Count > 0)
   86:                 {
   87:                     htmlTable += "<tr>";
   88:  
   89:                     htmlTable += @"<td class=""" + framework.Type + @""" colspan=""" + framework.Children.Count + @""">" + framework.ArabicName;
   90:                     if (headStaff != null) htmlTable += @"<span class=""head"">" + headStaff.FirstAndMiddleName + "</span>";
   91:                     htmlTable += @"</td>";
   92:  
   93:                     htmlTable += "</tr>";
   94:  
   95:                     htmlTable += "<tr>";
   96:  
   97:                     foreach (Ia.Ftn.Cl.Models.Business.Administration.Framework f in framework.Children)
   98:                     {
   99:                         htmlTable += @"<td class=""" + f.Type + @""">" + FrameworkStructureDataTableIteration(f) + "</td>";
  100:                     }
  101:  
  102:                     htmlTable += "</tr>";
  103:                 }
  104:                 else
  105:                 {
  106:                     staffList = (from s in Ia.Ftn.Cl.Models.Data.StaffIdentityUser.List()
  107:                                  where s.Framework != null && s.Framework.Id == framework.Id && !s.IsHead
  108:                                  select s).ToList();
  109:  
  110:                     htmlTable += "<tr>";
  111:  
  112:                     htmlTable += @"<td class=""" + framework.Type + @""">" + framework.ArabicName;
  113:                     if (headStaff != null) htmlTable += @"<span class=""head"">" + headStaff.FirstAndMiddleName + "</span>";
  114:  
  115:                     foreach (Ia.Ftn.Cl.Models.StaffIdentityUser staff in staffList)
  116:                     {
  117:                         htmlTable += @"<span class=""staff"">" + staff.FirstAndMiddleName + "</span>";
  118:                     }
  119:  
  120:                     htmlTable += @"</td>";
  121:  
  122:                     htmlTable += "</tr>";
  123:                 }
  124:  
  125:                 htmlTable += "</table>";
  126:             }
  127:  
  128:             return htmlTable;
  129:         }
  130:  
  131:         ////////////////////////////////////////////////////////////////////////////
  132:         ////////////////////////////////////////////////////////////////////////////    
  133:  
  134:         /// <summary>
  135:         /// 
  136:         /// </summary>
  137:         public static string StructureDataTable()
  138:         {
  139:             int companyCount, sectorCount, departmentCount, divisionCount, sectionCount;
  140:             int companySectionCount, sectorSectionCount, departmentSectionCount, divisionSectionCount, sectionSectionCount;
  141:             string htmlTable;
  142:  
  143:             companyCount = sectorCount = departmentCount = divisionCount = sectionCount = 0;
  144:             companySectionCount = sectorSectionCount = departmentSectionCount = divisionSectionCount = sectionSectionCount = 0;
  145:  
  146:             staffList = Ia.Ftn.Cl.Models.Data.StaffIdentityUser.List();
  147:  
  148:             htmlTable = @"<div id=""framework-structure"">";
  149:  
  150:             htmlTable += "<table>";
  151:  
  152:             companyCount = 1;
  153:  
  154:             var companyList = Ia.Ftn.Cl.Models.Data.Administration.FrameworkList.Where(u => u.Type == "ministry" || u.Type == "supplier").ToList();
  155:  
  156:             foreach (var company in companyList)
  157:             {
  158:                 companySectionCount = (from d in company.Descendants where d.Type == "section" select d).Count();
  159:  
  160:                 var sectorList = (from d in company.Children where d.Type == "sector" select d).ToList();
  161:  
  162:                 if (sectorList.Count > 0)
  163:                 {
  164:                     sectorCount = 1;
  165:  
  166:                     foreach (var sector in sectorList)
  167:                     {
  168:                         sectorSectionCount = (from d in sector.Descendants where d.Type == "section" select d).Count();
  169:  
  170:                         var departmentList = (from d in sector.Children where d.Type == "department" select d).ToList();
  171:  
  172:                         if (departmentList.Count > 0)
  173:                         {
  174:                             departmentCount = 1;
  175:  
  176:                             foreach (var department in departmentList)
  177:                             {
  178:                                 departmentSectionCount = (from d in department.Descendants where d.Type == "section" select d).Count();
  179:  
  180:                                 var divisionList = (from d in department.Children where d.Type == "division" select d).ToList();
  181:  
  182:                                 if (divisionList.Count > 0)
  183:                                 {
  184:                                     divisionCount = 1;
  185:  
  186:                                     foreach (var division in divisionList)
  187:                                     {
  188:                                         divisionSectionCount = (from d in division.Descendants where d.Type == "section" select d).Count();
  189:  
  190:                                         var sectionList = (from d in division.Children where d.Type == "section" select d).ToList();
  191:  
  192:                                         if (sectionList.Count > 0)
  193:                                         {
  194:                                             sectionCount = 1;
  195:  
  196:                                             foreach (var section in sectionList)
  197:                                             {
  198:                                                 sectionSectionCount = sectionList.Count;
  199:  
  200:                                                 htmlTable += @"<tr class=""company" + companyCount + @""">";
  201:  
  202:                                                 if (sectorCount == 1 && departmentCount == 1 && divisionCount == 1 && sectionCount == 1)
  203:                                                 {
  204:                                                     htmlTable += @"<td class=""company"" rowspan=""" + companySectionCount + @""">" + CompanyStructureDataTable(company) + "</td>";
  205:                                                     //htmlTable += "<td class=pstn rowspan=" + companySectionCount + ">" + PstnStructureDataTable(company.Pstns) + "</td>";
  206:                                                 }
  207:  
  208:                                                 if (departmentCount == 1 && divisionCount == 1 && sectionCount == 1) htmlTable += @"<td class=""sector"" rowspan=""" + sectorSectionCount + @""">" + SectorStructureDataTable(sector) + "</td>";
  209:  
  210:                                                 if (divisionCount == 1 && sectionCount == 1) htmlTable += @"<td class=""department"" rowspan=""" + departmentSectionCount + @""">" + DepartmentStructureDataTable(department) + "</td>";
  211:  
  212:                                                 if (sectionCount == 1) htmlTable += @"<td class=""division"" rowspan=""" + divisionSectionCount + @""">" + DivisionStructureDataTable(division) + "</td>";
  213:  
  214:                                                 // field type color
  215:                                                 //if (olt.FieldType == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.FieldType.Green)
  216:                                                 htmlTable += @"<td class=""section"">" + SectionStructureDataTable(section) + "</td>";
  217:                                                 //else /*if (olt.FieldType == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.FieldType.Brown)*/
  218:                                                 //    htmlTable += @"<td style=""background-color:brown""> </td><td class=olt>" + OltStructureDataTable(olt) + "</td>";
  219:  
  220:                                                 htmlTable += @"</tr>";
  221:  
  222:                                                 sectionCount++;
  223:                                             }
  224:                                         }
  225:                                         else divisionCount--;
  226:  
  227:                                         divisionCount++;
  228:                                     }
  229:                                 }
  230:                                 else departmentCount--;
  231:  
  232:                                 departmentCount++;
  233:                             }
  234:                         }
  235:                         else sectorCount--;
  236:  
  237:                         sectorCount++;
  238:                     }
  239:                 }
  240:                 else companyCount--;
  241:  
  242:                 companyCount++;
  243:             }
  244:  
  245:             htmlTable += "</table>";
  246:  
  247:             htmlTable += "</div>";
  248:  
  249:             return htmlTable;
  250:         }
  251:  
  252:         ////////////////////////////////////////////////////////////////////////////    
  253:  
  254:         /// <summary>
  255:         /// 
  256:         /// </summary>
  257:         private static string CompanyStructureDataTable(Ia.Ftn.Cl.Models.Business.Administration.Framework company)
  258:         {
  259:             string content; //, kuwaitFtnAreas;
  260:  
  261:             //kuwaitFtnAreas = string.Empty;
  262:  
  263:             //foreach (Ia.Ftn.Cl.Model.Business.Service.KuwaitFtnArea ka in company.KuwaitFtnAreas) kuwaitFtnAreas += ka.NameArabicName + "<br />";
  264:  
  265:             //kuwaitFtnAreas = kuwaitFtnAreas.Trim(',');
  266:  
  267:             content = company.ArabicName;
  268:  
  269:             headStaff = (from s in staffList
  270:                          where s.Framework != null && s.Framework.Id == company.Id && s.IsHead
  271:                          select s).SingleOrDefault();
  272:  
  273:             if (headStaff != null) content += @"<br />" + headStaff.FullName;
  274:  
  275:             //string.Join(", ", company.AreaSymbolList);
  276:             //content += @"<br />" + kuwaitFtnAreas;
  277:  
  278:             return content;
  279:         }
  280:  
  281:         ////////////////////////////////////////////////////////////////////////////    
  282:  
  283:         /// <summary>
  284:         /// 
  285:         /// </summary>
  286:         private static string PstnStructureDataTable(ICollection<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pstn> pstnList)
  287:         {
  288:             string content;
  289:  
  290:             var list = pstnList.ToList();
  291:  
  292:             content = string.Empty;
  293:  
  294:             foreach (var pstn in list)
  295:             {
  296:                 content += pstn.Name + " (نحاس) (" + pstn.PstnExchangeType + ")";
  297:                 content += @"<br />";
  298:                 content += string.Join(", ", pstn.DomainList);
  299:                 content += "<br />";
  300:                 content += @" Uses NP/LNP/SPS Server?: " + Ia.Cl.Models.Default.YesNo(pstn.UsesNpServer) + " ";
  301:  
  302:                 content += @"<br />";
  303:                 content += @"<br />";
  304:             }
  305:  
  306:             return content;
  307:         }
  308:  
  309:         ////////////////////////////////////////////////////////////////////////////    
  310:  
  311:         /// <summary>
  312:         /// 
  313:         /// </summary>
  314:         private static string SectorStructureDataTable(Ia.Ftn.Cl.Models.Business.Administration.Framework sector)
  315:         {
  316:             string content;//, domainList;
  317:  
  318:             //domainList = string.Empty;
  319:  
  320:             //foreach (int i in sector.DomainList) domainList += i + ", ";
  321:  
  322:             //domainList = domainList.Trim();
  323:             //domainList = domainList.Trim(',');
  324:  
  325:             content = sector.ArabicName; //.Vendor.Name;
  326:  
  327:             headStaff = (from s in staffList
  328:                          where s.Framework != null && s.Framework.Id == sector.Id && s.IsHead
  329:                          select s).SingleOrDefault();
  330:  
  331:             if (headStaff != null) content += @"<br />" + headStaff.FullName;
  332:  
  333:             //content += @"<br />" + domainList;
  334:  
  335:             return content;
  336:         }
  337:  
  338:         ////////////////////////////////////////////////////////////////////////////    
  339:  
  340:         /// <summary>
  341:         /// 
  342:         /// </summary>
  343:         private static string DepartmentStructureDataTable(Ia.Ftn.Cl.Models.Business.Administration.Framework department)
  344:         {
  345:             string content;
  346:  
  347:             content = department.ArabicName; //.Name + @"<br />" + department.Vendor.Name;
  348:  
  349:             headStaff = (from s in staffList where s.Framework != null && s.Framework.Id == department.Id && s.IsHead select s).SingleOrDefault();
  350:             if (headStaff != null) content += @"<br />" + headStaff.FullName;
  351:  
  352:             return content;
  353:         }
  354:  
  355:         ////////////////////////////////////////////////////////////////////////////    
  356:  
  357:         /// <summary>
  358:         /// 
  359:         /// </summary>
  360:         private static string DivisionStructureDataTable(Ia.Ftn.Cl.Models.Business.Administration.Framework division)
  361:         {
  362:             string content;
  363:  
  364:             content = division.ArabicName; //.Name + @"<br />" + department.Vendor.Name;
  365:  
  366:             headStaff = (from s in staffList where s.Framework != null && s.Framework.Id == division.Id && s.IsHead select s).SingleOrDefault();
  367:             if (headStaff != null) content += @"<br />" + headStaff.FullName;
  368:  
  369:             return content;
  370:         }
  371:  
  372:         ////////////////////////////////////////////////////////////////////////////    
  373:  
  374:         /// <summary>
  375:         /// 
  376:         /// </summary>
  377:         private static string SectionStructureDataTable(Ia.Ftn.Cl.Models.Business.Administration.Framework section)
  378:         {
  379:             string content;
  380:             List<int> ponlist, proposedPonList;
  381:             Dictionary<string, List<int>> dic;
  382:  
  383:             proposedPonList = new List<int>();
  384:             dic = new Dictionary<string, List<int>>();
  385:  
  386:             content = section.ArabicName; //.Symbol;
  387:  
  388:             headStaff = (from s in staffList where s.Framework != null && s.Framework.Id == section.Id && s.IsHead select s).SingleOrDefault();
  389:             if (headStaff != null) content += @"<br />" + headStaff.FullName;
  390:  
  391:             var sectionStaffList = (from s in staffList where s.Framework != null && s.Framework.Id == section.Id && !s.IsHead select s).ToList();
  392:             if (sectionStaffList.Count > 0) content += @"<br /><br />" + string.Join("<br />", sectionStaffList.Select(u => u.FullName));
  393:  
  394:             /*
  395:             content += @" (" + section.AmsName + ") ";
  396: 
  397:             content += "<br />";
  398:             content += @" SIP?: " + Ia.Cl.Models.Default.YesNo(section.IsSip) + " ";
  399: 
  400:             foreach (var ponGroup in section.PonGroupList)
  401:             {
  402:                 ponlist = new List<int>();
  403: 
  404:                 foreach (int i in ponGroup.UsedPonInPonGroupList) if (i != 0) ponlist.Add(i);
  405: 
  406:                 if (!dic.ContainsKey(ponGroup.Symbol))
  407:                 {
  408:                     dic[ponGroup.Symbol] = ponlist;
  409:                 }
  410:                 else dic[ponGroup.Symbol].AddRange(ponlist);
  411: 
  412:                 /*
  413:                 if (ponGroup.HasNewProposedPonList) foreach (int i in ponGroup.UsedProposedPonInPonGroupList) if (i != 0) proposedPonList.Add(i);
  414: 
  415:                 if (proposedPonList.Count > 0)
  416:                 {
  417:                     content += @"(Proposed): " + Ia.Cl.Models.Default.ConvertNumberListToHyphenAndCommaSeperatedNumberString(proposedPonList) + "</b>";
  418:                 }
  419:                 * /
  420:             }
  421: 
  422:             foreach (var kvp in dic)
  423:             {
  424:                 content += "<br />";
  425:                 content += kvp.Key + @": " + Ia.Cl.Models.Default.ConvertNumberListToHyphenAndCommaSeperatedNumberString(kvp.Value) + " ";
  426:             }
  427:             */
  428:  
  429:             //content += @" (" + olt.PonListString + ") ";
  430:  
  431:             return content;
  432:         }
  433:  
  434:         ////////////////////////////////////////////////////////////////////////////
  435:         ////////////////////////////////////////////////////////////////////////////
  436:  
  437:         /// <summary>
  438:         /// 
  439:         /// </summary>
  440:         public static string StructureToSimpleTextString()
  441:         {
  442:             int siteCount, routerCount, odfCount, oltCount;
  443:             int siteOltCount, routerOltCount, odfOltCount, oltOltCount;
  444:             string content, domainList;
  445:             string kuwaitFtnAreas;
  446:             string text;
  447:  
  448:             siteCount = routerCount = odfCount = oltCount = 0;
  449:             siteOltCount = routerOltCount = odfOltCount = oltOltCount = 0;
  450:  
  451:             text = "\n";
  452:  
  453:             siteCount = 1;
  454:  
  455:             foreach (Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site site in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SiteList)
  456:             {
  457:                 siteOltCount = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
  458:                                 where o.Odf != null && o.Odf.Router != null && o.Odf.Router.Site == site
  459:                                 select o).Count();
  460:  
  461:                 if (site.Routers.Count > 0)
  462:                 {
  463:                     routerCount = 1;
  464:  
  465:                     foreach (Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Router router in site.Routers)
  466:                     {
  467:                         routerOltCount = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
  468:                                           where o.Odf != null && o.Odf.Router == router
  469:                                           select o).Count();
  470:  
  471:                         if (router.Odfs.Count > 0)
  472:                         {
  473:                             odfCount = 1;
  474:  
  475:                             foreach (Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Odf odf in router.Odfs)
  476:                             {
  477:                                 odfOltCount = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
  478:                                                where o.Odf == odf
  479:                                                select o).Count();
  480:  
  481:                                 oltCount = 1;
  482:  
  483:                                 foreach (Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt olt in odf.Olts)
  484:                                 {
  485:                                     oltOltCount = odf.Olts.Count;
  486:  
  487:                                     if (routerCount == 1 && odfCount == 1 && oltCount == 1)
  488:                                     {
  489:                                         text += "\n";
  490:  
  491:                                         //text += "\n";
  492:                                         //text += "\n";
  493:                                         text += @"===========================";
  494:  
  495:                                         text += "\n";
  496:  
  497:                                         kuwaitFtnAreas = string.Empty;
  498:  
  499:                                         foreach (Ia.Ftn.Cl.Models.Business.Service.KuwaitFtnArea ka in site.KuwaitFtnAreas) kuwaitFtnAreas += ka.NameArabicName + "\n";
  500:  
  501:                                         kuwaitFtnAreas = kuwaitFtnAreas.Trim();
  502:  
  503:                                         content = site.NameArabicName;
  504:                                         content += "\n";
  505:                                         content += "\n" + string.Join(", ", site.AreaSymbolList);
  506:                                         content += "\n";
  507:                                         content += "\n" + kuwaitFtnAreas;
  508:  
  509:                                         text += content.Trim();
  510:                                     }
  511:  
  512:                                     if (odfCount == 1 && oltCount == 1)
  513:                                     {
  514:                                         //text += "\n";
  515:                                         text += "\n";
  516:  
  517:                                         //text += "| --------------------------";
  518:                                         text += "\n";
  519:  
  520:                                         domainList = string.Empty;
  521:  
  522:                                         foreach (int i in router.DomainList) domainList += i + ", ";
  523:  
  524:                                         domainList = domainList.Trim();
  525:                                         domainList = domainList.Trim(',');
  526:  
  527:                                         content = router.Vendor.Name + @" " + domainList;
  528:  
  529:                                         text += "| " + content;
  530:  
  531:                                         text += "\n";
  532:                                     }
  533:  
  534:                                     if (oltCount == 1)
  535:                                     {
  536:                                         text += "\n";
  537:  
  538:                                         //text += "\t\t\t\t\t\t--------------------------";
  539:                                         text += "| | " + odf.Name + @" (" + odf.Vendor.Name + ")";
  540:                                     }
  541:  
  542:                                     /*
  543: // field type color
  544: if (olt.FieldType == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.FieldType.Green)
  545:     htmlTable += @"<td style=""background-color:green""> </td><td class=olt>" + OltStructureDataTable(olt) + "</td>";
  546: else /*if (olt.FieldType == Ia.Ftn.Cl.Model.Business.NetworkDesignDocument.FieldType.Brown)* /
  547:     htmlTable += @"<td style=""background-color:brown""> </td><td class=olt>" + OltStructureDataTable(olt) + "</td>";
  548:     */
  549:  
  550:                                     //text += @"====================================";
  551:  
  552:                                     oltCount++;
  553:                                 }
  554:  
  555:                                 odfCount++;
  556:                             }
  557:                         }
  558:                         else routerCount--;
  559:  
  560:                         routerCount++;
  561:                     }
  562:                 }
  563:  
  564:                 siteCount++;
  565:             }
  566:  
  567:             text += "\n";
  568:  
  569:             return text.Trim();
  570:         }
  571:  
  572:         ////////////////////////////////////////////////////////////////////////////
  573:         ////////////////////////////////////////////////////////////////////////////    
  574:     }
  575: }