示例#1
0
        public EditUI()
        {
            string msg = "";

            AddSection()
            .IsFramed()
            .WithTitle("Edit Route")
            .WithColumns(new List <Column>
            {
                new Column(
                    new List <IField> {
                    Map(x => x.Name)
                    .AsSectionField <TextBox>()
                    .WithLength(50).LabelTextIs("Name")
                    .Required().TextFormatIs("")
                    .TextFormatIs("^[ a-zA-Z0-9]+$"),
                    Map(x => x.BIN)
                    .AsSectionField <TextBox>()
                    .TextFormatIs(TextFormat.numeric)
                    .WithLength(6, 20).LabelTextIs("BIN").Required()
                    .TextFormatIs(TextFormat.numeric),
                    Map(x => x.Description)
                    .AsSectionField <TextBox>()
                    .WithLength(60)
                    .LabelTextIs("Description")
                    .Required()
                    .TextFormatIs("^[ a-zA-Z0-9]+$"),
                    Map(x => x.SinkNode).AsSectionField <DropDownList>()
                    .Of(() => { return(new SinkNodeDAO().Get().ToList()); })
                    .ListOf(x => x.Name, x => x.ID).WithEditableText()
                    .Required()
                    .LabelTextIs("Sink Node"),

                    Map(x => x.ID).AsSectionField <TextLabel>().ApplyMod <VisibilityMod>(m => m.Hide <Route>(h => { return(true); })),
                }),
            })
            .WithFields(new List <IField> {
                AddSectionButton()
                .SubmitTo(x =>
                {
                    try
                    {
                        RouteDAO routeDao = new RouteDAO();
                        Route route       = routeDao.GetById(x.ID);

                        //check for uniqueness
                        if (!routeDao.isUniqueName(route.Name, x.Name))
                        {
                            msg += "Route name must be unique";
                            return(false);
                        }
                        else if (!routeDao.isUniqueBIN(route.BIN, x.BIN))
                        {
                            msg += "PAN must be unique";
                            return(false);
                        }

                        route.Name         = x.Name;
                        route.BIN          = x.BIN;
                        route.Description  = x.Description;
                        route.SinkNode     = x.SinkNode;
                        route.DateModified = DateTime.Now;

                        routeDao.Update(route);
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        msg          += "An error occured";
                        string logMsg = "Message= " + ex.Message + " Inner Exception= " + ex.InnerException;
                        MessageLogger.LogError(logMsg);
                        return(false);
                    }
                })
                .ConfirmWith(s => String.Format("Update Route type {0} ", s.Name)).WithText("Update")
                .OnSuccessDisplay(s => String.Format("Route \"{0}\" has been successfuly editted ", s.Name))
                .OnFailureDisplay(s => String.Format("Error editting!\n   {0} ", msg))
            });
        }
示例#2
0
        public AddUI()
        {
            string msg = "";

            WithTitle("Add new Route");

            Map(x => x.Name).As <TextBox>()
            .WithLength(35)
            .LabelTextIs("Route Name")
            .Required()
            .TextFormatIs("^[ a-zA-Z0-9]+$");

            Map(x => x.BIN).As <TextBox>()
            .WithLength(6, 20)
            .LabelTextIs("BIN")
            .Required()
            .TextFormatIs(TextFormat.numeric);

            Map(x => x.Description).As <TextBox>()
            .WithLength(50)
            .LabelTextIs("Description")
            .Required()
            .TextFormatIs("^[ a-zA-Z0-9]+$");

            Map(x => x.SinkNode).As <DropDownList>()
            .Of(() => { return(new SinkNodeDAO().Get().ToList()); })
            .ListOf(x => x.Name, x => x.ID).WithEditableText()
            .Required()
            .LabelTextIs("Sink Node");



            AddButton()
            .ApplyMod <IconMod>(x => x.WithIcon(Ext.Net.Icon.Disk))
            .WithText("Submit")
            .SubmitTo(x =>
            {
                try
                {
                    Route route       = new Route();
                    RouteDAO routeDao = new RouteDAO();
                    if (!routeDao.isUniqueName(x.Name))
                    {
                        msg += "Route name must be unique";
                        return(false);
                    }
                    else if (!routeDao.isUniqueBIN(x.BIN))
                    {
                        msg += "PAN must be unique";
                        return(false);
                    }
                    else
                    {
                        route.Name         = x.Name;
                        route.BIN          = x.BIN;
                        route.SinkNode     = x.SinkNode;
                        route.Description  = x.Description;
                        route.DateCreated  = DateTime.Now;
                        route.DateModified = DateTime.Now;

                        routeDao.Insert(route);
                        return(true);    //Success
                    }
                }
                catch (Exception ex)
                {
                    msg          += "An error occured";
                    string logMsg = "Message= " + ex.Message + " Inner Exception= " + ex.InnerException;
                    MessageLogger.LogError(logMsg);
                    return(false);
                }
            })
            .OnSuccessDisplay(x =>
            {
                return("Route" + "" + x.Name + " saved successfully.");
            })
            .OnFailureDisplay(s => String.Format("Error: {0} ", msg))
            .CssClassIs("btn btn-default");
        }