コード例 #1
0
        private void TransformServiceFunction(TemplateDomain templateDomain, TemplateRow row)
        {
            var templateFunction = templateDomain.TemplateFunctions.FirstOrDefault(d => d.FunctionName == row.ServiceFunction);

            if (templateFunction == null)
            {
                var dateTimeNow = DateTime.Now;
                var function    = new TemplateFunction
                {
                    FunctionName       = row.ServiceFunction,
                    TemplateComponents = new List <TemplateComponent>(),
                    InsertedDate       = dateTimeNow,
                    InsertedBy         = _userIdentity.Name,
                    UpdatedDate        = dateTimeNow,
                    UpdatedBy          = _userIdentity.Name
                };

                templateDomain.TemplateFunctions.Add(function);
                templateFunction = function;
            }

            if (!string.IsNullOrEmpty(row.ServiceComponentLevel1))
            {
                TransformServiceComponent(templateFunction, row);
            }
        }
コード例 #2
0
        public void TransformServiceDomain(Template template, TemplateRow row)
        {
            var templateDomain = template.TemplateDomains.FirstOrDefault(d => d.DomainName == row.ServiceDomain);

            if (templateDomain == null)
            {
                var dateTimeNow = DateTime.Now;
                var domain      = new TemplateDomain
                {
                    DomainName        = row.ServiceDomain,
                    TemplateFunctions = new List <TemplateFunction>(),
                    InsertedDate      = dateTimeNow,
                    InsertedBy        = _userIdentity.Name,
                    UpdatedDate       = dateTimeNow,
                    UpdatedBy         = _userIdentity.Name
                };

                template.TemplateDomains.Add(domain);
                templateDomain = domain;
            }

            if (!string.IsNullOrEmpty(row.ServiceFunction))
            {
                TransformServiceFunction(templateDomain, row);
            }
        }
コード例 #3
0
        private void TransformServiceFunction(ServiceDomain serviceDomain, TemplateRow templateRow)
        {
            var serviceFunction = serviceDomain.ServiceFunctions.FirstOrDefault(d => d.FunctionType.FunctionName.Trim() == templateRow.ServiceFunction.Trim());

            if (serviceFunction == null)
            {
                var dateTimeNow = DateTime.Now;
                serviceFunction = new ServiceFunction
                {
                    ServiceDomain     = serviceDomain,
                    FunctionType      = _functionTypeRefDataService.InsertorUpdate(templateRow.ServiceFunction),
                    ServiceComponents = new List <ServiceComponent>(),
                    DiagramOrder      = 5,
                    InsertedBy        = _userIdentity.Name,
                    InsertedDate      = dateTimeNow,
                    UpdatedBy         = _userIdentity.Name,
                    UpdatedDate       = dateTimeNow
                };

                serviceDomain.ServiceFunctions.Add(serviceFunction);
                _serviceDomainService.Update(serviceDomain);
            }

            if (!string.IsNullOrEmpty(templateRow.ServiceComponentLevel1))
            {
                TransformComponentLevelOne(serviceFunction, templateRow);
            }
        }
コード例 #4
0
ファイル: TemplateRow.cs プロジェクト: 15831944/backsight
            internal static TemplateRow CreateTemplateRow(BacksightDataSet ds)
            {
                TemplateRow result = ds.Template.NewTemplateRow();

                result.SetDefaultValues();
                return(result);
            }
コード例 #5
0
        private void TransformServiceDomain(ServiceDesk serviceDesk, TemplateRow templateRow)
        {
            var serviceDomain = serviceDesk.ServiceDomains.FirstOrDefault(d => d.DomainType.DomainName.Trim() == templateRow.ServiceDomain.Trim());

            if (serviceDomain == null)
            {
                var dateTimeNow = DateTime.Now;
                serviceDomain = new ServiceDomain
                {
                    DomainType       = _domainTypeRefDataService.InsertorUpdate(templateRow.ServiceDomain),
                    ServiceFunctions = new List <ServiceFunction>(),
                    DiagramOrder     = 5,
                    InsertedBy       = _userIdentity.Name,
                    InsertedDate     = dateTimeNow,
                    UpdatedBy        = _userIdentity.Name,
                    UpdatedDate      = dateTimeNow
                };

                serviceDesk.ServiceDomains.Add(serviceDomain);
                _serviceDeskService.Update(serviceDesk);
            }

            if (!string.IsNullOrEmpty(templateRow.ServiceFunction))
            {
                TransformServiceFunction(serviceDomain, templateRow);
            }
        }
コード例 #6
0
        private void TransformResolver(TemplateComponent templateComponent, TemplateRow row)
        {
            if (!ServiceDeliveryOrganisationNames.Descriptions.Contains(row.ServiceDeliveryOrganisation))
            {
                throw new DataImportException($"Error reading Service Decomposition Template spreadsheet. Invalid Responsible Organisation Value - {row.ServiceDeliveryOrganisation}.");
            }

            var templateResolver =
                templateComponent.TemplateResolvers.FirstOrDefault(
                    r => r.ServiceDeliveryOrganisationName == row.ServiceDeliveryOrganisation &&
                    r.ServiceDeliveryUnitName == row.ServiceDeliveryUnit &&
                    r.ResolverGroupName == row.ResolverGroup);

            if (templateResolver == null)
            {
                var dateTimeNow = DateTime.Now;
                var resolver    = new TemplateResolver
                {
                    ServiceDeliveryOrganisationName = row.ServiceDeliveryOrganisation,
                    ServiceDeliveryUnitName         = row.ServiceDeliveryUnit,
                    ResolverGroupName = row.ResolverGroup,
                    TemplateComponent = templateComponent,
                    InsertedDate      = dateTimeNow,
                    InsertedBy        = _userIdentity.Name,
                    UpdatedDate       = dateTimeNow,
                    UpdatedBy         = _userIdentity.Name
                };

                templateComponent.TemplateResolvers.Add(resolver);
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: jsw7524/ReportMaker
        public void MakeReport2()
        {
            List <Product> Products = GetProductData().ToList();
            DataProcessor  dp       = new DataProcessor();

            dp.BeforeGroup = (x, d) =>
            {
                if (1 == d)
                {
                    var          groupColor        = x as IGrouping <string, Product>;
                    TemplateRow  tmp               = new TemplateRow();
                    TemplateCell colorTemplateCell = new TemplateCell()
                    {
                        content = "Color:", cellStyle = "B2"
                    };
                    tmp.RowContent.AddRange(new List <TemplateCell>()
                    {
                        colorTemplateCell, groupColor.Key, groupColor.AsEnumerable().Count()
                    });
                    dp.Result.Add(tmp);
                }
            };
            dp.Process(Products.GroupBy(a => a.Color));
            ReportMaker reportMaker = new ReportMaker();
            Dictionary <string, List <TemplateRow> > dict = new Dictionary <string, List <TemplateRow> >()
            {
                { "Products", dp.Result }
            };
            var image = reportMaker.FillDataInTemplate("Template1.xlsx", dict);

            File.WriteAllBytes("Test2.xlsx", image.ToArray());
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: jsw7524/ReportMaker
        public void MakeReport3()
        {
            List <Product> Products = GetProductData().ToList();
            DataProcessor  dp       = new DataProcessor();

            dp.BeforeGroup = (x, d) =>
            {
                if (1 == d)
                {
                    var         groupColor = x as IGrouping <string, Product>;
                    TemplateRow tmp        = new TemplateRow();
                    tmp.RowStyle = "styleFullBlueCover";
                    tmp.RowContent.AddRange(new List <TemplateCell>()
                    {
                        "Color:", groupColor.Key, groupColor.AsEnumerable().Count()
                    });
                    dp.Result.Add(tmp);
                }
            };

            dp.Process(Products.GroupBy(a => a.Color));
            ReportMakerHelper reportMakerHelper = new ReportMakerHelper();
            var         styleSheet  = reportMakerHelper.GetSheet("Template2.xlsx", "Styles");
            ReportMaker reportMaker = new ReportMaker(new StylesManager(styleSheet));
            Dictionary <string, List <TemplateRow> > dict = new Dictionary <string, List <TemplateRow> >()
            {
                { "Products", dp.Result }
            };
            var image = reportMaker.FillDataInTemplate("Template2.xlsx", dict);

            File.WriteAllBytes("Test3.xlsx", image.ToArray());
        }
コード例 #9
0
        private void TransformComponentLevelOne(ServiceFunction serviceFunction, TemplateRow templateRow)
        {
            var serviceComponent = serviceFunction.ServiceComponents.FirstOrDefault(d => d.ComponentName == templateRow.ServiceComponentLevel1 && d.ComponentLevel == 1);

            if (serviceComponent == null)
            {
                var dateTimeNow = DateTime.Now;
                serviceComponent = new ServiceComponent
                {
                    ServiceFunction   = serviceFunction,
                    ComponentName     = templateRow.ServiceComponentLevel1,
                    ComponentLevel    = 1,
                    ServiceActivities = string.IsNullOrEmpty(templateRow.ServiceComponentLevel2) &&
                                        !string.IsNullOrEmpty(templateRow.ServiceActivities)
                        ? templateRow.ServiceActivities
                        : string.Empty,
                    DiagramOrder = 5,
                    InsertedBy   = _userIdentity.Name,
                    InsertedDate = dateTimeNow,
                    UpdatedBy    = _userIdentity.Name,
                    UpdatedDate  = dateTimeNow
                };

                serviceFunction.ServiceComponents.Add(serviceComponent);
                _serviceFunctionService.Update(serviceFunction);
            }
            //else if (!string.IsNullOrEmpty(templateRow.ServiceActivities))
            //{
            //    if (!string.IsNullOrEmpty(serviceComponent.ServiceActivities))
            //        serviceComponent.ServiceActivities += $"\r\n{templateRow.ServiceActivities}";
            //    else
            //    {
            //        serviceComponent.ServiceActivities = templateRow.ServiceActivities;
            //    }

            //    _serviceComponentService.Update(serviceComponent);
            //}

            if (!string.IsNullOrEmpty(templateRow.ServiceComponentLevel2))
            {
                if (serviceComponent.Resolver != null)
                {
                    throw new DataImportException(
                              $"Error reading Service Decomposition Design spreadsheet. Worksheet, Resolvers and Childs Components detected on Component [{templateRow.ServiceComponentLevel1}].");
                }

                TransformComponentLevelTwo(serviceComponent, templateRow);
            }
            else if (!string.IsNullOrEmpty(templateRow.ServiceDeliveryOrganisation))
            {
                if (serviceComponent.Resolver != null)
                {
                    throw new DataImportException(
                              $"Error reading Service Decomposition Design spreadsheet. Worksheet, Multiple Resolvers per Component detected on Component [{templateRow.ServiceComponentLevel1}].");
                }

                TransformResolver(serviceComponent, templateRow);
            }
        }
コード例 #10
0
        private void TransformServiceComponent(TemplateFunction templateFunction, TemplateRow row)
        {
            var templateComponent = templateFunction.TemplateComponents.FirstOrDefault(c => c.ComponentName == row.ServiceComponentLevel1 && c.ComponentLevel == 1);

            if (templateComponent == null)
            {
                var dateTimeNow       = DateTime.Now;
                var levelOneComponent = new TemplateComponent
                {
                    ComponentName     = row.ServiceComponentLevel1,
                    ComponentLevel    = 1,
                    ServiceActivities =
                        string.IsNullOrEmpty(row.ServiceComponentLevel2) &&
                        !string.IsNullOrEmpty(row.ServiceActivities)
                            ? row.ServiceActivities
                            : string.Empty,
                    ChildTemplateComponents = new List <TemplateComponent>(),
                    TemplateResolvers       = new List <TemplateResolver>(),
                    TemplateFunction        = templateFunction,
                    InsertedDate            = dateTimeNow,
                    InsertedBy  = _userIdentity.Name,
                    UpdatedDate = dateTimeNow,
                    UpdatedBy   = _userIdentity.Name
                };

                templateFunction.TemplateComponents.Add(levelOneComponent);
                templateComponent = levelOneComponent;
            }

            if (!string.IsNullOrEmpty(row.ServiceComponentLevel2))
            {
                if (templateComponent.TemplateResolvers.Any())
                {
                    throw new DataImportException(
                              $"Error reading Service Decomposition Design spreadsheet. Worksheet, Resolvers and Childs Components detected on Component [{row.ServiceComponentLevel1}].");
                }
                TransformServiceComponentLevelTwo(templateComponent, row);
            }
            else if (!string.IsNullOrEmpty(row.ServiceDeliveryOrganisation))
            {
                if (templateComponent.TemplateResolvers.Any())
                {
                    throw new DataImportException(
                              $"Error reading Service Decomposition Template spreadsheet. Worksheet, Multiple Resolvers per Component detected on Component [{row.ServiceComponentLevel1}].");
                }
                TransformResolver(templateComponent, row);
            }
        }
コード例 #11
0
        private void UpdateLoginList()
        {
            cmbLogin.Enabled = false;

            ClearLoginList();

            ConnectionGroupInfo group    = SelectedGroup;
            InstanceInfo        instance = SelectedInstance;
            TemplateRow         template = SelectedTemplate;

            if (group != null && instance != null && template != null)
            {
                List <LoginRow> logins = this._loginManager.GetLogins(
                    template.Name,
                    group.Name,
                    instance.Name,
                    instance.DbType
                    );

                if (logins.Count > 0)
                {
                    foreach (LoginRow loginRow in logins)
                    {
                        BindingWrapper <LoginRow> loginWrapper = new BindingWrapper <LoginRow>(
                            loginRow,
                            DisplayLogin
                            );

                        cmbLogin.Items.Add(loginWrapper);
                    }

                    cmbLogin.SelectedIndex = 0;
                }
            }

            cmbLogin.Enabled = true;
        }
コード例 #12
0
        private void TransformResolver(ServiceComponent serviceComponent, TemplateRow templateRow)
        {
            if (!ServiceDeliveryOrganisationNames.Descriptions.Contains(templateRow.ServiceDeliveryOrganisation))
            {
                throw new DataImportException($"Error reading Service Decomposition Design spreadsheet. Invalid Responsible Organisation Value - {templateRow.ServiceDeliveryOrganisation}.");
            }

            var dateTimeNow = DateTime.Now;
            var resolver    = new Resolver
            {
                ServiceDesk      = serviceComponent.ServiceFunction.ServiceDomain.ServiceDesk,
                ServiceComponent = serviceComponent,
                ServiceDeliveryOrganisationType = _serviceDeliveryOrganisationTypeRefDataService.All().Single(x => x.ServiceDeliveryOrganisationTypeName == templateRow.ServiceDeliveryOrganisation),
                ServiceDeliveryUnitType         = !string.IsNullOrEmpty(templateRow.ServiceDeliveryUnit) ? _serviceDeliveryUnitTypeRefDataService.InsertorUpdate(templateRow.ServiceDeliveryUnit) : null,
                ResolverGroupType = !string.IsNullOrEmpty(templateRow.ResolverGroup) ? _resolverGroupTypeRefDataService.InsertorUpdate(templateRow.ResolverGroup) : null,
                InsertedBy        = _userIdentity.Name,
                InsertedDate      = dateTimeNow,
                UpdatedBy         = _userIdentity.Name,
                UpdatedDate       = dateTimeNow
            };

            serviceComponent.Resolver = resolver;
            _serviceComponentService.Update(serviceComponent);
        }
コード例 #13
0
        private Dictionary <string, ConnectionInfo> ReadLastConnections(List <ConnectionType> connectionTypes)
        {
            Dictionary <string, ConnectionInfo> lastConnections = new Dictionary <string, ConnectionInfo>();
            string machineName = Environment.MachineName;

            foreach (ConnectionType connectionType in connectionTypes)
            {
                string cnnType = connectionType.Id;

                LastConnectionProtocolRow row = this._storage.LastConnectionProtocolTable
                                                .GetLastConnection(machineName, cnnType);

                if (row != null)
                {
                    ConnectionGroupInfo group       = this._connectionsManager.GetGroup(row.GroupId);
                    TemplateRow         templateRow = this._storage.TemplateDirectory.GetTemplate(row.TemplateId);

                    if (group != null && templateRow != null)
                    {
                        ConnectionInfo connectionInfo = new ConnectionInfo
                        {
                            TemplateFile   = templateRow.Id,
                            TemplateDir    = templateRow.Directory,
                            TemplateId     = templateRow.Name,
                            ConnectionId   = row.Identity,
                            GroupName      = group.Name,
                            ConnectionType = cnnType
                        };

                        lastConnections.Add(cnnType, connectionInfo);
                    }
                }
            }

            return(lastConnections);
        }
コード例 #14
0
        private void TransformServiceComponentLevelTwo(TemplateComponent templateComponent, TemplateRow row)
        {
            var templateComponentLevelTwo = templateComponent.ChildTemplateComponents.FirstOrDefault(c => c.ComponentName == row.ServiceComponentLevel2 && c.ComponentLevel == 2);

            if (templateComponentLevelTwo == null)
            {
                var dateTimeNow       = DateTime.Now;
                var levelTwoComponent = new TemplateComponent
                {
                    ComponentName           = row.ServiceComponentLevel2,
                    ComponentLevel          = 2,
                    ServiceActivities       = !string.IsNullOrEmpty(row.ServiceActivities) ? row.ServiceActivities : string.Empty,
                    TemplateResolvers       = new List <TemplateResolver>(),
                    ParentTemplateComponent = templateComponent,
                    TemplateFunction        = templateComponent.TemplateFunction,
                    InsertedDate            = dateTimeNow,
                    InsertedBy  = _userIdentity.Name,
                    UpdatedDate = dateTimeNow,
                    UpdatedBy   = _userIdentity.Name
                };

                templateComponent.ChildTemplateComponents.Add(levelTwoComponent);
                templateComponentLevelTwo = levelTwoComponent;
            }

            if (!string.IsNullOrEmpty(row.ServiceDeliveryOrganisation))
            {
                if (templateComponentLevelTwo.TemplateResolvers.Any())
                {
                    throw new DataImportException(
                              $"Error reading Service Decomposition Template spreadsheet. Multiple Resolvers per Component detected on Component [{row.ServiceComponentLevel1}>{row.ServiceComponentLevel2}].");
                }
                TransformResolver(templateComponentLevelTwo, row);
            }
        }
コード例 #15
0
 public void AddTemplateRow(TemplateRow row) {
     this.Rows.Add(row);
 }
コード例 #16
0
 public void RemoveTemplateRow(TemplateRow row) {
     this.Rows.Remove(row);
 }
コード例 #17
0
 public TemplateRowChangeEvent(TemplateRow row, global::System.Data.DataRowAction action) {
     this.eventRow = row;
     this.eventAction = action;
 }
コード例 #18
0
ファイル: TemplateController.cs プロジェクト: CivilPol/Vodigi
        public ActionResult Create(Template template)
        {
            try
            {
                if (Session["UserAccountID"] == null)
                    return RedirectToAction("Validate", "Login");
                User user = (User)Session["User"];
                ViewData["LoginInfo"] = Utility.BuildUserAccountString(user.Username, Convert.ToString(Session["UserAccountName"]));
                if (user.IsAdmin)
                    ViewData["txtIsAdmin"] = "true";
                else
                    ViewData["txtIsAdmin"] = "false";

                if (ModelState.IsValid)
                {
                    // Set NULLs to Empty Strings
                    template = FillNulls(template);
                    template.AccountID = Convert.ToInt32(Session["UserAccountID"]);
                    template.TemplateGUID = Guid.NewGuid();

                    // Set the rows and columns from the drop downs
                    template.Rows = Convert.ToInt32(Request.Form["lstRow"].ToString().Trim());
                    template.Columns = Convert.ToInt32(Request.Form["lstColumn"].ToString().Trim());

                    string validation = ValidateInput(template);
                    if (!String.IsNullOrEmpty(validation))
                    {
                        ViewData["ValidationMessage"] = validation;
                        ViewData["RowList"] = new SelectList(BuildRowList(), "Value", "Text", Request.Form["lstRow"].ToString().Trim());
                        ViewData["ColumnList"] = new SelectList(BuildColumnList(), "Value", "Text", Request.Form["lstColumn"].ToString().Trim());
                        ViewData["Row1Height"] = Request.Form["txtRow1Height"].ToString().Trim();
                        ViewData["Row2Height"] = Request.Form["txtRow2Height"].ToString().Trim();
                        ViewData["Row3Height"] = Request.Form["txtRow3Height"].ToString().Trim();
                        ViewData["Row4Height"] = Request.Form["txtRow4Height"].ToString().Trim();
                        ViewData["Row5Height"] = Request.Form["txtRow5Height"].ToString().Trim();
                        ViewData["Row6Height"] = Request.Form["txtRow6Height"].ToString().Trim();
                        ViewData["Column1Width"] = Request.Form["txtColumn1Width"].ToString().Trim();
                        ViewData["Column2Width"] = Request.Form["txtColumn2Width"].ToString().Trim();
                        ViewData["Column3Width"] = Request.Form["txtColumn3Width"].ToString().Trim();
                        ViewData["Column4Width"] = Request.Form["txtColumn4Width"].ToString().Trim();
                        ViewData["Column5Width"] = Request.Form["txtColumn5Width"].ToString().Trim();
                        ViewData["Column6Width"] = Request.Form["txtColumn6Width"].ToString().Trim();

                        return View(template);
                    }
                    else
                    {
                        repository.CreateTemplate(template);

                        // Create all the rows and columns
                        ITemplateRowRepository rowrepository = new EntityTemplateRowRepository();
                        for (int r = 1; r <= template.Rows; r += 1)
                        {
                            TemplateRow trow = new TemplateRow();
                            trow.TemplateID = template.TemplateID;
                            trow.RowNumber = r;
                            if (r == 1) trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow1Height"]);
                            else if (r == 2) trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow2Height"]);
                            else if (r == 3) trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow3Height"]);
                            else if (r == 4) trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow4Height"]);
                            else if (r == 5) trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow5Height"]);
                            else if (r == 6) trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow6Height"]);
                            rowrepository.CreateTemplateRow(trow);
                        }

                        ITemplateColumnRepository colrepository = new EntityTemplateColumnRepository();
                        for (int c = 1; c <= template.Columns; c += 1)
                        {
                            TemplateColumn tcol = new TemplateColumn();
                            tcol.TemplateID = template.TemplateID;
                            tcol.ColumnNumber = c;
                            if (c == 1) tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn1Width"]);
                            else if (c == 2) tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn2Width"]);
                            else if (c == 3) tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn3Width"]);
                            else if (c == 4) tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn4Width"]);
                            else if (c == 5) tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn5Width"]);
                            else if (c == 6) tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn6Width"]);
                            colrepository.CreateTemplateColumn(tcol);
                        }

                        CommonMethods.CreateActivityLog((User)Session["User"], "Template", "Add",
                            "Added screen template '" + template.TemplateName + "' - ID: " + template.TemplateID.ToString());

                        return RedirectToAction("Index", "Template");
                    }
                }
                return View(template);
            }
            catch (Exception ex)
            {
                Helpers.SetupApplicationError("Template", "Create POST", ex.Message);
                return RedirectToAction("Index", "ApplicationError");
            }
        }
コード例 #19
0
        public ActionResult Create(Template template)
        {
            try
            {
                if (Session["UserAccountID"] == null)
                {
                    return(RedirectToAction("Validate", "Login"));
                }
                User user = (User)Session["User"];
                ViewData["LoginInfo"] = Utility.BuildUserAccountString(user.Username, Convert.ToString(Session["UserAccountName"]));
                if (user.IsAdmin)
                {
                    ViewData["txtIsAdmin"] = "true";
                }
                else
                {
                    ViewData["txtIsAdmin"] = "false";
                }

                if (ModelState.IsValid)
                {
                    // Set NULLs to Empty Strings
                    template              = FillNulls(template);
                    template.AccountID    = Convert.ToInt32(Session["UserAccountID"]);
                    template.TemplateGUID = Guid.NewGuid();

                    // Set the rows and columns from the drop downs
                    template.Rows    = Convert.ToInt32(Request.Form["lstRow"].ToString().Trim());
                    template.Columns = Convert.ToInt32(Request.Form["lstColumn"].ToString().Trim());

                    string validation = ValidateInput(template);
                    if (!String.IsNullOrEmpty(validation))
                    {
                        ViewData["ValidationMessage"] = validation;
                        ViewData["RowList"]           = new SelectList(BuildRowList(), "Value", "Text", Request.Form["lstRow"].ToString().Trim());
                        ViewData["ColumnList"]        = new SelectList(BuildColumnList(), "Value", "Text", Request.Form["lstColumn"].ToString().Trim());
                        ViewData["Row1Height"]        = Request.Form["txtRow1Height"].ToString().Trim();
                        ViewData["Row2Height"]        = Request.Form["txtRow2Height"].ToString().Trim();
                        ViewData["Row3Height"]        = Request.Form["txtRow3Height"].ToString().Trim();
                        ViewData["Row4Height"]        = Request.Form["txtRow4Height"].ToString().Trim();
                        ViewData["Row5Height"]        = Request.Form["txtRow5Height"].ToString().Trim();
                        ViewData["Row6Height"]        = Request.Form["txtRow6Height"].ToString().Trim();
                        ViewData["Column1Width"]      = Request.Form["txtColumn1Width"].ToString().Trim();
                        ViewData["Column2Width"]      = Request.Form["txtColumn2Width"].ToString().Trim();
                        ViewData["Column3Width"]      = Request.Form["txtColumn3Width"].ToString().Trim();
                        ViewData["Column4Width"]      = Request.Form["txtColumn4Width"].ToString().Trim();
                        ViewData["Column5Width"]      = Request.Form["txtColumn5Width"].ToString().Trim();
                        ViewData["Column6Width"]      = Request.Form["txtColumn6Width"].ToString().Trim();

                        return(View(template));
                    }
                    else
                    {
                        repository.CreateTemplate(template);

                        // Create all the rows and columns
                        ITemplateRowRepository rowrepository = new EntityTemplateRowRepository();
                        for (int r = 1; r <= template.Rows; r += 1)
                        {
                            TemplateRow trow = new TemplateRow();
                            trow.TemplateID = template.TemplateID;
                            trow.RowNumber  = r;
                            if (r == 1)
                            {
                                trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow1Height"]);
                            }
                            else if (r == 2)
                            {
                                trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow2Height"]);
                            }
                            else if (r == 3)
                            {
                                trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow3Height"]);
                            }
                            else if (r == 4)
                            {
                                trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow4Height"]);
                            }
                            else if (r == 5)
                            {
                                trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow5Height"]);
                            }
                            else if (r == 6)
                            {
                                trow.RowHeightPercentage = Convert.ToInt32(Request.Form["txtRow6Height"]);
                            }
                            rowrepository.CreateTemplateRow(trow);
                        }

                        ITemplateColumnRepository colrepository = new EntityTemplateColumnRepository();
                        for (int c = 1; c <= template.Columns; c += 1)
                        {
                            TemplateColumn tcol = new TemplateColumn();
                            tcol.TemplateID   = template.TemplateID;
                            tcol.ColumnNumber = c;
                            if (c == 1)
                            {
                                tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn1Width"]);
                            }
                            else if (c == 2)
                            {
                                tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn2Width"]);
                            }
                            else if (c == 3)
                            {
                                tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn3Width"]);
                            }
                            else if (c == 4)
                            {
                                tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn4Width"]);
                            }
                            else if (c == 5)
                            {
                                tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn5Width"]);
                            }
                            else if (c == 6)
                            {
                                tcol.ColumnWidthPercentage = Convert.ToInt32(Request.Form["txtColumn6Width"]);
                            }
                            colrepository.CreateTemplateColumn(tcol);
                        }

                        CommonMethods.CreateActivityLog((User)Session["User"], "Template", "Add",
                                                        "Added screen template '" + template.TemplateName + "' - ID: " + template.TemplateID.ToString());

                        return(RedirectToAction("Index", "Template"));
                    }
                }
                return(View(template));
            }
            catch (Exception ex)
            {
                Helpers.SetupApplicationError("Template", "Create POST", ex.Message);
                return(RedirectToAction("Index", "ApplicationError"));
            }
        }
コード例 #20
0
 private string getRow(string label, string value)
 {
     return(TemplateRow.Replace("@label", label).Replace("@value", value));
 }
コード例 #21
0
        public void CreateDelegate_RaisedPocoFactoryForDomainAggregateList_SharedEntitiesHaveReferenceEquality()
        {
            var definitionProvider = new DataAnnotationsDefinitionProvider();
            var databaseContext    = new Mock <IDatabaseContext>();

            databaseContext.Setup(context => context.GetValueMapper(It.IsAny <Type>(), It.IsAny <Type>())).Returns((IValueMapper)null);

            using (var target = new RaisedPocoFactory(definitionProvider))
            {
                var aggregateOptionRow =
                    new AggregateOptionRow {
                    AggregateOptionId = 3, AggregateOptionTypeId = 4, Name = "Slim Shady", Value = 324.10m
                };

                var topContainerRow = new TopContainerRow
                {
                    Name           = "All TV Evar",
                    TopContainerId = 2
                };

                var tomNJerry = new DomainIdentityRow
                {
                    DomainIdentityId = 23,
                    FirstName        = "Tom",
                    MiddleName       = "N.",
                    LastName         = "Jerry",
                    UniqueIdentifier = "*****@*****.**"
                };

                var mahCatzCategory = new CategoryAttributeRow {
                    CategoryAttributeId = 3, Name = "Mah Catz", IsActive = true, IsSystem = true
                };
                var fooBarCategory = new CategoryAttributeRow {
                    CategoryAttributeId = 4, Name = "foobar", IsActive = true, IsSystem = false
                };

                var porkyPig = new DomainIdentityRow
                {
                    DomainIdentityId = 55,
                    FirstName        = "Porky",
                    MiddleName       = "That's All Folks",
                    LastName         = "Pig",
                    UniqueIdentifier = "*****@*****.**"
                };
                var warnerBros = new SubContainerRow
                {
                    Name           = "Warner Bros",
                    SubContainerId = 234,
                    TopContainerId = 2,
                    TopContainer   = topContainerRow
                };
                var template1 = new TemplateRow {
                    Name = "Template1", TemplateId = 44
                };
                var template2 = new TemplateRow {
                    Name = "Template34", TemplateId = 45
                };
                var expected = new List <DomainAggregateRow>
                {
                    new DomainAggregateRow
                    {
                        DomainAggregateId = 2342,
                        AggregateOption   = aggregateOptionRow,
                        Name = "DomainAg1",
                        CategoryAttribute         = mahCatzCategory,
                        CategoryAttributeId       = mahCatzCategory.CategoryAttributeId,
                        CreatedBy                 = tomNJerry,
                        CreatedByDomainIdentityId = tomNJerry.DomainIdentityId,
                        CreatedTime               = DateTimeOffset.Now.AddDays(-5),
                        Description               = "My First Domain Aggregate YAY",
                        OtherAggregate            =
                            new OtherAggregateRow
                        {
                            OtherAggregateId      = 29,
                            AggregateOptionTypeId = 5,
                            Name = "OtherAggregate"
                        },
                        LastModifiedBy = porkyPig,
                        LastModifiedByDomainIdentityId = porkyPig.DomainIdentityId,
                        LastModifiedTime = DateTimeOffset.Now,
                        SubContainer     = warnerBros,
                        SubContainerId   = warnerBros.SubContainerId,
                        TemplateId       = template1.TemplateId,
                        Template         = template1
                    },
                    new DomainAggregateRow
                    {
                        DomainAggregateId = 2343,
                        AggregateOption   = aggregateOptionRow,
                        Name = "DomainAg2",
                        CategoryAttribute              = mahCatzCategory,
                        CategoryAttributeId            = mahCatzCategory.CategoryAttributeId,
                        CreatedBy                      = tomNJerry,
                        CreatedByDomainIdentityId      = tomNJerry.DomainIdentityId,
                        CreatedTime                    = DateTimeOffset.Now.AddDays(-4),
                        Description                    = "My Second Domain Aggregate YAY",
                        LastModifiedBy                 = porkyPig,
                        LastModifiedByDomainIdentityId = porkyPig.DomainIdentityId,
                        LastModifiedTime               = DateTimeOffset.Now.AddHours(-1),
                        SubContainer                   = warnerBros,
                        SubContainerId                 = warnerBros.SubContainerId,
                        TemplateId                     = template1.TemplateId,
                        Template = template1
                    },
                    new DomainAggregateRow
                    {
                        DomainAggregateId = 2345,
                        AggregateOption   = aggregateOptionRow,
                        Name = "DomainAg3",
                        CategoryAttribute              = fooBarCategory,
                        CategoryAttributeId            = fooBarCategory.CategoryAttributeId,
                        CreatedBy                      = tomNJerry,
                        CreatedByDomainIdentityId      = tomNJerry.DomainIdentityId,
                        CreatedTime                    = DateTimeOffset.Now.AddDays(-2),
                        Description                    = "My Third Domain Aggregate YAY",
                        LastModifiedBy                 = porkyPig,
                        LastModifiedByDomainIdentityId = porkyPig.DomainIdentityId,
                        LastModifiedTime               = DateTimeOffset.Now.AddSeconds(-97),
                        SubContainer                   = warnerBros,
                        SubContainerId                 = warnerBros.SubContainerId,
                        TemplateId                     = template1.TemplateId,
                        Template = template1
                    },
                    new DomainAggregateRow
                    {
                        DomainAggregateId = 2346,
                        AggregateOption   = aggregateOptionRow,
                        Name = "DomainAg4",
                        CategoryAttribute              = fooBarCategory,
                        CategoryAttributeId            = fooBarCategory.CategoryAttributeId,
                        CreatedBy                      = porkyPig,
                        CreatedByDomainIdentityId      = porkyPig.DomainIdentityId,
                        CreatedTime                    = DateTimeOffset.Now.AddDays(-1),
                        Description                    = "My Fourth Domain Aggregate YAY",
                        LastModifiedBy                 = porkyPig,
                        LastModifiedByDomainIdentityId = porkyPig.DomainIdentityId,
                        LastModifiedTime               = DateTimeOffset.Now.AddHours(-3),
                        SubContainer                   = warnerBros,
                        SubContainerId                 = warnerBros.SubContainerId,
                        TemplateId                     = template2.TemplateId,
                        Template = template2
                    },
                    new DomainAggregateRow
                    {
                        DomainAggregateId = 2347,
                        AggregateOption   = aggregateOptionRow,
                        Name = "DomainAg7",
                        CategoryAttribute              = mahCatzCategory,
                        CategoryAttributeId            = mahCatzCategory.CategoryAttributeId,
                        CreatedBy                      = porkyPig,
                        CreatedByDomainIdentityId      = porkyPig.DomainIdentityId,
                        CreatedTime                    = DateTimeOffset.Now.AddDays(-5),
                        Description                    = "My Last Domain Aggregate YAY",
                        LastModifiedBy                 = porkyPig,
                        LastModifiedByDomainIdentityId = porkyPig.DomainIdentityId,
                        LastModifiedTime               = DateTimeOffset.Now.AddMinutes(-16),
                        SubContainer                   = warnerBros,
                        SubContainerId                 = warnerBros.SubContainerId,
                        TemplateId                     = template1.TemplateId,
                        Template = template1
                    }
                };

                var watch            = Stopwatch.StartNew();
                var actual           = new List <DomainAggregateRow>();
                var entityDefinition = definitionProvider.Resolve <DomainAggregateRow>();

                using (var reader = expected.MockDataReaderForList(entityDefinition.ReturnableAttributes.ToList()).Object)
                {
                    while (reader.Read())
                    {
                        actual.Add(target.CreatePoco <DomainAggregateRow>(new PocoDataRequest(reader, entityDefinition, databaseContext.Object)));
                    }
                }

                watch.Stop();
                Trace.TraceInformation($"{watch.Elapsed}");

                Assert.AreEqual(expected.First(), actual.First(), string.Join(Environment.NewLine, expected.First().GetDifferences(actual.First())));

                CollectionAssert.AreEqual(expected, actual);

                Assert.IsTrue(actual.Select(x => x.SubContainer?.TopContainer).All(x => x != null));
                Assert.IsTrue(actual.Select(x => x.SubContainer).All(x => x != null));
                Assert.IsTrue(actual.Select(x => x.Template).All(x => x != null));
                Assert.IsTrue(actual.Select(x => x.CreatedBy).All(x => x != null));
                Assert.IsTrue(actual.Select(x => x.LastModifiedBy).All(x => x != null));
                Assert.IsTrue(actual.Select(x => x.CategoryAttribute).All(x => x != null));
                Assert.IsTrue(actual.Select(x => x.AggregateOption).All(x => x != null));

                foreach (var group in from c in actual.Select(x => x.SubContainer?.TopContainer) group c by c.TopContainerId)
                {
                    Assert.IsTrue(group.All(x => ReferenceEquals(x, group.First())));
                }

                foreach (var group in from c in actual.Select(x => x.SubContainer) group c by c.SubContainerId)
                {
                    Assert.IsTrue(group.All(x => ReferenceEquals(x, group.First())));
                }

                foreach (var group in from t in actual.Select(x => x.Template) group t by t.TemplateId)
                {
                    Assert.IsTrue(group.All(x => ReferenceEquals(x, group.First())));
                }

                foreach (var group in from o in actual.Select(x => x.AggregateOption) group o by o.AggregateOptionId)
                {
                    Assert.IsTrue(group.All(x => ReferenceEquals(x, group.First())));
                }

                foreach (var group in from i in actual.Select(x => x.LastModifiedBy) group i by i.DomainIdentityId)
                {
                    Assert.IsTrue(group.All(x => ReferenceEquals(x, group.First())));
                }

                foreach (var group in from i in actual.Select(x => x.CreatedBy) group i by i.DomainIdentityId)
                {
                    Assert.IsTrue(group.All(x => ReferenceEquals(x, group.First())));
                }

                foreach (var group in from a in actual.Select(x => x.CategoryAttribute) group a by a.CategoryAttributeId)
                {
                    Assert.IsTrue(group.All(x => ReferenceEquals(x, group.First())));
                }
            }
        }