コード例 #1
0
        public AddUI()
        {
            PrePopulateFrom <AddFeeUIModel>(x =>
            {
                return(new AddFeeUIModel
                {
                    FlatAmmount = 0, PercentageOfTransaction = 0, Instruction = "Note that you cannot select both flat amount and percentage of transaction. One or both of them must be zero. When flat amount is selected, Minimum and maximum must be left as zero"
                });
            });

            WithTitle("Add new Fee");

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

            Map(x => x.FlatAmmount).As <TextBox>()
            .WithLength(15)     //not dealing with the world bank
            .LabelTextIs("Flat Ammount N")
            .Required()
            .TextFormatIs(TextFormat.money);

            Map(x => x.PercentageOfTransaction).As <TextBox>()
            //.WithLength(2)
            .LabelTextIs("Percentage of transaction")
            .Required()
            .TextFormatIs(@"^[0-9]\d?(\.\d+)?$");

            Map(x => x.Minimum).As <TextBox>()
            .WithLength(15)
            .LabelTextIs("Minimum (N)")
            .Required()
            .TextFormatIs(TextFormat.money);

            Map(x => x.Maximum).As <TextBox>()
            .WithLength(20)
            .LabelTextIs("Maximum (N)")
            .Required()
            .TextFormatIs(TextFormat.money);


            Map(x => x.Instruction)
            .As <TextLabel>();


            //Button click
            string errorMsg = "";

            AddButton()
            .WithText("Add Fee")
            .SubmitTo(x =>
            {
                bool flag     = false;
                FeeDAO feeDao = new FeeDAO();
                try
                {
                    if (x.PercentageOfTransaction != 0 && x.FlatAmmount != 0)
                    {
                        errorMsg += "You cannot select both flat and Percntage, one or both of them has to be zero";
                        flag      = false;
                    }
                    else if (!feeDao.isUniqueName(x.Name))
                    {
                        errorMsg += "Fee name must be unique";
                        flag      = false;
                    }
                    else if (x.Minimum > x.Maximum)
                    {
                        errorMsg += "Minimum fee cannot be greater than the maximum fee";
                        flag      = false;
                    }
                    else
                    {
                        Fee fee = new Fee {
                            DateCreated = DateTime.Now, DateModified = DateTime.Now, Name = x.Name, FlatAmmount = x.FlatAmmount, Maximum = x.Maximum, Minimum = x.Minimum, PercentageOfTransaction = x.PercentageOfTransaction
                        };
                        feeDao.Insert(fee);
                        flag = true;
                    }
                }
                catch (Exception ex)
                {
                    flag          = false;
                    errorMsg     += "an error occured";
                    string logMsg = "Message: " + ex.Message + "   InnerException = " + ex.InnerException;
                    MessageLogger.LogError(logMsg);
                }
                return(flag); //Success
            })
            .OnSuccessDisplay(x =>
            {
                return(x.Name + "Fee added successfully.");
            })
            .OnFailureDisplay(x => { return("Unable to add Fee.\n  " + errorMsg); });
        }
コード例 #2
0
 public FeeManager()
 {
     _db = new FeeDAO();
 }
コード例 #3
0
        public EditUI()
        {
            string msg = "";

            AddSection()
            .IsFramed()
            .WithTitle("Edit Fee")
            .WithColumns(new List <Column>
            {
                new Column(
                    new List <IField> {
                    Map(x => x.Name)
                    .AsSectionField <TextBox>()
                    .WithLength(50).LabelTextIs("Name")
                    .Required()
                    .TextFormatIs(TextFormat.name),
                    Map(x => x.FlatAmmount)
                    .AsSectionField <TextBox>()
                    .WithLength(60)
                    .LabelTextIs("Flat Amount (N)").Required()
                    .TextFormatIs(TextFormat.money),
                    Map(x => x.PercentageOfTransaction)
                    .AsSectionField <TextBox>()
                    //.WithLength(60).LabelTextIs("Percentage of Transation").Required()
                    .TextFormatIs(@"^[0-9]\d?(\.\d+)?$"),
                    Map(x => x.Minimum)
                    .AsSectionField <TextBox>()
                    .WithLength(60).LabelTextIs("Minimum (N)").Required()
                    .TextFormatIs(TextFormat.money),
                    Map(x => x.Maximum)
                    .AsSectionField <TextBox>()
                    .WithLength(60).LabelTextIs("Maximum (N)").Required()
                    .TextFormatIs(TextFormat.money),

                    Map(x => x.ID).AsSectionField <TextLabel>().ApplyMod <VisibilityMod>(m => m.Hide <Fee>(h => { return(true); })),
                }),
            })
            .WithFields(new List <IField> {
                AddSectionButton()
                .SubmitTo(x =>
                {
                    try
                    {
                        FeeDAO feeDAO = new FeeDAO();
                        Fee fee       = feeDAO.GetById(x.ID);

                        if (x.PercentageOfTransaction != 0 && x.FlatAmmount != 0)
                        {
                            msg += "You cannot select both flat and Percntage, one of them has to be zero";
                            return(false);
                        }
                        else if (x.PercentageOfTransaction == 0 && x.FlatAmmount == 0)
                        {
                            msg += "Only one of flat amount and percentage of transaction should be zero";
                            return(false);
                        }
                        else if (x.Minimum > x.Maximum)
                        {
                            msg += "Minimum fee cannot be greater than the maximum fee";
                            return(false);
                        }
                        //check for uniqueness
                        if (!feeDAO.isUniqueName(fee.Name, x.Name))
                        {
                            msg += "Name must be unique";
                            return(false);
                        }

                        fee.Name                    = x.Name;
                        fee.FlatAmmount             = x.FlatAmmount;
                        fee.PercentageOfTransaction = x.PercentageOfTransaction;
                        fee.Maximum                 = x.Maximum;
                        fee.Minimum                 = x.Minimum;
                        fee.DateModified            = DateTime.Now;

                        feeDAO.Update(fee);
                        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 Fee type {0} ", s.Name)).WithText("Update")
                .OnSuccessDisplay(s => String.Format("Fee \"{0}\" has been successfuly editted ", s.Name))
                .OnFailureDisplay(s => String.Format("Error editting!\n   {0} ", msg))
            });
        }