示例#1
0
        private void OkButton_Click(object sender, EventArgs e)
        {
            ResultFunction = SetFunction ? Main.CompileFunction(FunctionBox.Text, Dims) : Main.CompileConstraint(FunctionBox.Text, Dims);

            if (ResultFunction == null)
            {
                return;
            }

            Close();
        }
示例#2
0
        internal void CompileProblem()
        {
            int objCount = Config.FunctionEqs.Count;

            Max        = new bool[objCount];
            Objectives = new MethodResults[objCount];

            for (int i = 0; i < objCount; i++)
            {
                Max[i]        = Config.FunctionEqs[i].StartsWith("Maximize:");
                Objectives[i] = CompileFunction(Config.FunctionEqs[i].Substring(10), Config.Dimensions);
            }

            Constraints = CompileConstraints(Config.ConstraintEqs, Config.Dimensions);
        }
示例#3
0
        public async Task <MethodResults> CreateNewBusiness(BusinessPullModel pullModel, BPMainContext context, string IPAddress, string instigator, CoreLoggerProvider logger)
        {
            var methodResults = new MethodResults {
                Success = false, Message = "Something went wrong.  Please try again, or contact your system administrator."
            };

            // the pull model should have been validated at the controller
            // first, create the account
            var account = new BPAccount()
            {
                BusinessAttribute = new BusinessAttribute(),
                EntityAttribute   = new EntityAttribute()
            };

            account.BusinessAttribute.BusinessName = pullModel.BusinessName;
            var subject = "Business Account Creation";
            var system  = "Business Service";

            account.EntityAttribute.AccountType = await context.AccountTypes.FirstOrDefaultAsync(x => x.Index == 2);

            account.BusinessAttribute.BusinessType = await context.BusinessTypes.FirstOrDefaultAsync(x => x.Index == pullModel.BusinessTypeId);

            var accountDateType = await context.AccountDateTypes.FirstOrDefaultAsync(x => x.Index == 1);

            var accountDate = new AccountDate {
                AccountDateType = accountDateType,
                DateLine        = DateTimeOffset.Now
            };

            account.EntityAttribute.AccountDates.Add(accountDate);

            context.Accounts.Add(account);

            methodResults = await context.SaveChangesAsync(context);

            if (methodResults.Success)
            {
                await logger.CreateNewLog($"Successfully create {pullModel.BusinessName} as {pullModel.BusinessTypes.FirstOrDefault(x => x.Value == pullModel.BusinessTypeId.ToString())} by {instigator} on {IPAddress}", subject, instigator, system);
            }
            else
            {
                await logger.CreateNewLog($"Failed to create new business {pullModel.BusinessName} by {instigator} on {IPAddress}", subject, instigator, system);
            }
            return(methodResults);
        }
示例#4
0
        public MethodResults SaveChanges(BPAuthContext context)
        {
            var methodResults = new MethodResults();

            try
            {
                context.SaveChanges();
                methodResults.Success = true;
                methodResults.Message = "Changes were saved successfully!";
            }
            catch (DbUpdateException ex)
            {
                StringBuilder sb = new StringBuilder();
                foreach (var entry in ex.Entries)
                {
                    sb.AppendLine(entry.GetType().ToString());
                }
                methodResults.Message = StaticClasses.SystemDebug ? $"The list of problems with the update are: {sb.ToString()}" :
                                        "The changes could not be made.  Please report this problem to your system administrator.";
            }
            return(methodResults);
        }
示例#5
0
        private void SetButton_Click(object sender, EventArgs e)
        {
            SetButton.Text    = "Working";
            SetButton.Enabled = false;

            if (Main.Play)
            {
                Main.PlayButton_Click(null, null);
                Thread.Sleep(500);
            }

            int dimensions = (int)DimensionBox.Value;

            try
            {
                if (dimensions < 1)
                {
                    MessageBox.Show("There must be at least one dimension");
                    return;
                }

                float[] testInput = new float[dimensions];

                foreach (string item in FunctionList.Items)
                {
                    string function = item.Substring(10);

                    MethodResults func   = Main.CompileFunction(function, dimensions);
                    float         result = (float)func.Invoke(testInput, 0f);
                }

                foreach (string constraint in ConstraintsList.Items)
                {
                    MethodResults consts = Main.CompileConstraint(constraint, dimensions);
                    bool          good   = (bool)consts.Invoke(testInput, 0f);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                //MessageBox.Show("Function or Constraint has more variabls than allowed by the specified # of dimensions");
                SetButton.Text    = "Set";
                SetButton.Enabled = true;
                return;
            }


            if (dimensions != Main.Config.Dimensions ||
                Main.BestGlobalValue.Length != FunctionList.Items.Count)
            {
                Main.Config.Dimensions = dimensions;

                Main.ResetDimensions(FunctionList.Items.Count);
            }

            Main.Config.FunctionEqs.Clear();
            foreach (string function in FunctionList.Items)
            {
                Main.Config.FunctionEqs.Add(function);
            }

            Main.Config.ConstraintEqs.Clear();
            foreach (string constraint in ConstraintsList.Items)
            {
                Main.Config.ConstraintEqs.Add(constraint);
            }

            Main.CompileProblem();



            float.TryParse(TimeBox.Text, out Main.Config.TimeInc);
            Main.Config.TimeUsed = TimeCheckBox.Checked;

            Main.RefreshAxisCombos();
            Main.RefreshEvent.Set();

            Main.Window.ResetView();

            SetButton.Text    = "Set";
            SetButton.Enabled = true;
        }
示例#6
0
        public async Task <MethodResults> AddUserToAccount(string userId, string emailAddress, string userName, CoreLoggerProvider logger, string IPAddress, string instigator, BPMainContext context, int accountId, int loginTypeId, int presidenceTypeId)
        {
            var methodResults = new MethodResults {
                Success = false, Message = "Something went wrong.  Nothing was changed.  Please try again or contact your network or system administrator."
            };
            // we're adding a user to either an existing account, or to a new account
            var account = new BPAccount();

            if (accountId == 0)
            {
                var dateType = await context.AccountDateTypes.FirstOrDefaultAsync(x => x.Index == 1);

                var accountType = await context.AccountTypes.FirstOrDefaultAsync(x => x.Index == 1);

                var accountDates = new List <AccountDate> {
                    new AccountDate {
                        DateLine = DateTimeOffset.Now, AccountDateType = dateType
                    }
                };

                account.EntityAttribute = new EntityAttribute
                {
                    AccountDates = accountDates,
                    AccountType  = accountType
                };
                account.UserAttribute = new UserAttribute();
            }
            else
            {
                account = await context.Accounts.FindAsync(accountId);
            }
            var loginType = await context.LoginIdTypes.FirstOrDefaultAsync(x => x.Index == loginTypeId);

            var presidenceType = await context.PresidenceTypes.FirstOrDefaultAsync(x => x.Index == presidenceTypeId);

            var loginIds = new List <LoginId> {
                new LoginId {
                    UserId         = userId,
                    EmailAddress   = emailAddress,
                    PresidenceType = presidenceType,
                    LoginIdType    = loginType
                }
            };
            var loginAttribute = new LoginAttribute
            {
                LoginIds = loginIds
            };

            if (accountId > 0)
            {
                var entry = context.Entry(account);
                entry.Entity.LoginAttribute = loginAttribute;
                entry.State = EntityState.Modified;
            }
            else
            {
                account.LoginAttribute = loginAttribute;
                context.Accounts.Add(account);
            }
            methodResults = await context.SaveChangesAsync(context);

            var subject = "Add user to account";
            var system  = "User Service";

            if (methodResults.Success)
            {
                await logger.CreateNewLog($"Successfully added user {emailAddress} to account {account.ID} on {IPAddress} by {instigator}.", subject, instigator, system);
            }
            else
            {
                await logger.CreateNewLog($"Unable to add user {emailAddress} to an account on {IPAddress} by {instigator}.", subject, instigator, system);
            }
            return(methodResults);
        }