Пример #1
0
        public EditUI()
        {
            string msg = "";

            AddSection()
            .IsFramed()
            .WithTitle("Edit TransactionType")
            .WithColumns(new List <Column>
            {
                new Column(
                    new List <IField> {
                    Map(x => x.Name)
                    .AsSectionField <TextBox>()
                    .WithLength(50).LabelTextIs("Name")
                    .Required().TextFormatIs("")
                    .TextFormatIs(TextFormat.name),
                    Map(x => x.Code)
                    .AsSectionField <TextBox>()
                    .TextFormatIs(TextFormat.numeric)
                    .WithLength(2).LabelTextIs("Code").Required()
                    .TextFormatIs(TextFormat.numeric),
                    Map(x => x.Description)
                    .AsSectionField <TextBox>()
                    .WithLength(60)
                    .LabelTextIs("Description")
                    .Required()
                    .TextFormatIs("^[ a-zA-Z0-9]+$"),

                    Map(x => x.ID).AsSectionField <TextLabel>().ApplyMod <VisibilityMod>(m => m.Hide <TransactionType>(h => { return(true); })),
                }),
            })
            .WithFields(new List <IField> {
                AddSectionButton()
                .SubmitTo(x =>
                {
                    try
                    {
                        TransactionTypeDAO ttypeDAO = new TransactionTypeDAO();
                        TransactionType ttype       = ttypeDAO.GetById(x.ID);

                        //check for uniqueness
                        if (!ttypeDAO.isUniqueName(ttype.Name, x.Name))
                        {
                            msg += "Name must be unique";
                            return(false);
                        }
                        if (!ttypeDAO.isUniqueCode(ttype.Code, x.Code))
                        {
                            msg += "Code must be unique";
                            return(false);
                        }

                        ttype.Name         = x.Name;
                        ttype.Code         = x.Code;
                        ttype.Description  = x.Description;
                        ttype.DateModified = DateTime.Now;

                        ttypeDAO.Update(ttype);
                        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 Transaction type {0} ", s.Name)).WithText("Update")
                .OnSuccessDisplay(s => String.Format("Transaction type \"{0}\" has been successfuly editted ", s.Name))
                .OnFailureDisplay(s => String.Format("Error editting!\n   {0} ", msg))
            });
        }
 public TransactionTypeManager(TransactionTypeDAO db)
 {
     db = _db;
 }
 public TransactionTypeManager()
 {
     _db = new TransactionTypeDAO();
 }
Пример #4
0
        public AddUI()
        {
            WithTitle("Add a new Transaction Type");

            Map(x => x.Name).As <TextBox>()
            .WithLength(35)
            .LabelTextIs("Transcton Type Name")
            .Required()
            .TextFormatIs(TextFormat.name);

            Map(x => x.Code).As <TextBox>()
            .WithLength(2)
            .LabelTextIs("Code")
            .Required()
            .TextFormatIs(TextFormat.numeric);

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

            string errorMsg = "";

            AddButton()
            .WithText("Add Transaction type")
            .SubmitTo(x =>
            {
                bool flag = false;

                try
                {
                    TransactionTypeDAO tTypeDAO = new TransactionTypeDAO();
                    if (tTypeDAO.isUniqueName(x.Name) && tTypeDAO.isUniqueCode(x.Code))
                    {
                        TransactionType transactionType = new TransactionType {
                            DateCreated = DateTime.Now, DateModified = DateTime.Now, Name = x.Name, Code = x.Code, Description = x.Description
                        };
                        tTypeDAO.Insert(transactionType);
                        flag = true;
                    }
                    else
                    {
                        errorMsg += " Transaction type's name and code must be unique";
                        flag      = false;
                    }
                }
                catch (Exception ex)
                {
                    errorMsg     += "An error occured";
                    string logMsg = "Message= " + ex.Message + " Inner Exception= " + ex.InnerException;
                    MessageLogger.LogError(logMsg);
                }
                return(flag);
            })
            .OnSuccessDisplay(x =>
            {
                return("Transaction type Added Successfully");
            })
            .OnFailureDisplay(x => { return("Unable to add Transaction type.\n  " + errorMsg); });;
        }