Esempio n. 1
0
    private void CreateActivity(int organizationID, int areaID, int projectID)
    {
        ActivityDSTableAdapters.PopulateActivitiesTableAdapter pta =
            new ActivityDSTableAdapters.PopulateActivitiesTableAdapter();
        PopulateDatabaseDSTableAdapters.QueriesTableAdapter qta =
            new PopulateDatabaseDSTableAdapters.QueriesTableAdapter();

        int numberOfActivitites = r.Next(0, Convert.ToInt32(ActivitiesDropDownList.SelectedValue));
        int?activityID          = 0;

        for (int i = 0; i < numberOfActivitites; i++)
        {
            pta.Insert(
                currentUsers[r.Next(0, currentUsers.Length)],
                organizationID,
                areaID,
                projectID,
                activities[r.Next(0, activities.Length)] + " " + i.ToString(),
                ref activityID);

            // Make between 0 and X people owners of the activity
            string[] owners = GetRandomSetOfUsers(r.Next(0, Convert.ToInt32(AllowedOwnDropDownList.SelectedValue) + 1), null);
            foreach (string myOwner in owners)
            {
                qta.InsertObjectPermissions("ACTIVITY", activityID.Value, myOwner, "OWN");
            }

            bool allowAllManKPIs = false;

            // X% of the time we will allow Everyone to manage KPIs for the person
            allowAllManKPIs = (r.Next(0, 100) < Convert.ToInt32(AllowedEveryoneManageDropDownList.SelectedValue));

            if (allowAllManKPIs)
            {
                qta.InsertObjectPublic("ACTIVITY", activityID.Value, "MAN_KPI");
            }

            // Get between 0 and X random people to give them permissons to manage some aspect of this object
            string[] others = GetRandomSetOfUsers(r.Next(0, Convert.ToInt32(AllowManageDropDownList.SelectedValue) + 1), owners);

            foreach (string myOthers in others)
            {
                StringBuilder permissions = new StringBuilder();
                // Get the permissons that we will give them.  They can be one or more
                // of MAN_KPI but
                // these cannot be added if these permissons are public as above.

                // 20% of the time give them MAN_KPI
                if (r.Next(0, 100) < 20 && !allowAllManKPIs)
                {
                    AddToStringList(permissions, "MAN_KPI", ";");
                }

                if (permissions.Length > 0)
                {
                    qta.InsertObjectPermissions("ACTIVITY", activityID.Value, myOthers, permissions.ToString());
                }
            }

            CreateKPI(organizationID, areaID, projectID, activityID.Value, 0);
        }
    }
Esempio n. 2
0
    private void CreateKPI(int organizationID, int areaID, int projectID, int activityID, int personID)
    {
        PopulateDatabaseDSTableAdapters.QueriesTableAdapter qta =
            new PopulateDatabaseDSTableAdapters.QueriesTableAdapter();

        int kpisToGenerate = r.Next(0, Convert.ToInt32(KPIDropDownList.SelectedValue));

        for (int i = 0; i < kpisToGenerate; i++)
        {
            KPITest         theTest       = kpiTests[r.Next(0, kpiTests.Count)];                                                     // Randomply select a test KPI
            bool            hasTarget     = r.Next(0, 10) < Convert.ToInt32(KPITargetsDropDownList.SelectedValue) ? true : false;    // 60% of the time the KPI has a target
            bool            hasCategories = r.Next(0, 10) < Convert.ToInt32(KPICategoriesDropDownList.SelectedValue) ? true : false; // 80% of the time the KPI doesn not have a target
            int             noCategories  = r.Next(1, Convert.ToInt32(CategoriesDropDownList.SelectedValue));
            List <Category> cat           = new List <Category>();
            decimal?        target        = null;
            if (hasCategories)
            {
                for (int j = 0; j < noCategories; j++)
                {
                    List <CategoryItem> items = new List <CategoryItem>();
                    foreach (CategoryItem catItem in categories[j].Items)
                    {
                        decimal?cattarget = null;
                        if (hasTarget)
                        {
                            cattarget = (Decimal)(r.NextDouble() * 500);
                        }
                        items.Add(new CategoryItem(catItem.ItemID, catItem.ItemName, cattarget));
                    }
                    cat.Add(new Category(categories[j].ID, categories[j].ID, items));
                }
            }

            if (hasTarget && !hasCategories)
            {
                target = (Decimal)(r.NextDouble() * 500);
            }

            DateTime startDate = DateTime.MinValue;

            if (hasTarget)
            {
                startDate = DateTime.Today.Subtract(new TimeSpan(r.Next(5, 350), 0, 0, 0, 0));
            }

            string unitID = "";
            switch (theTest.Type)
            {
            case "GENINT": unitID = "INT"; break;

            case "GENPER": unitID = "PERCENT"; break;

            case "GENTIME": unitID = "TIME"; break;

            case "GENDEC": unitID = "DECIMAL"; break;

            default:
                unitID = ""; break;
            }

            string reportUnit = reportingUnits[r.Next(0, reportingUnits.Length)];

            int currencyIndex = r.Next(0, currencies.Length);
            int kpiID         = KPIBLL.CreateKPI(organizationID,
                                                 areaID,
                                                 projectID,
                                                 activityID,
                                                 personID,
                                                 theTest.Name,
                                                 unitID,
                                                 theTest.Direction,
                                                 theTest.Strategy,
                                                 startDate,
                                                 reportUnit,
                                                 hasTarget ? r.Next(0, 350) : 0,
                                                 currencies[currencyIndex].Currency,
                                                 currencies[currencyIndex].Unit,
                                                 theTest.Type,
                                                 cat.ToArray(),
                                                 target,
                                                 currentUsers[r.Next(0, currentUsers.Length)]);

            // Make between 0 and X people owners of the KPI
            string[] owners = GetRandomSetOfUsers(r.Next(0, Convert.ToInt32(AllowedOwnDropDownList.SelectedValue) + 1), null);
            foreach (string myOwner in owners)
            {
                qta.InsertObjectPermissions("KPI", kpiID, myOwner, "OWN");
            }

            bool allowAllViewKPIs = false;

            // X% of the time we will allow Everyone to view the KPI
            allowAllViewKPIs = (r.Next(0, 100) < Convert.ToInt32(PublicKPIDropDownList.SelectedValue));

            if (allowAllViewKPIs)
            {
                qta.InsertObjectPublic("KPI", kpiID, "VIEW_KPI");
            }

            // Get between 0 and X random people to give them permissons to View or Enter Data on this object
            string[] others = GetRandomSetOfUsers(r.Next(0, Convert.ToInt32(AllowedViewKPIDropdownList.SelectedValue) + 1), owners);

            foreach (string myOthers in others)
            {
                StringBuilder permissions = new StringBuilder();
                // Get the permissons that we will give them.  They can be one of
                // of VIEW_KPI or ENTER_DATA but not both.  VIEW_KPI cannot be added
                // if these permissons are public as above.

                // 50% of the time give them VIEW_KPI
                if (r.Next(0, 100) < 10 && !allowAllViewKPIs)
                {
                    permissions.Append("VIEW_KPI");
                }
                else if ((r.Next(0, 100) < 50))
                {
                    // and if we did not give them VIEW_KPI 50% of the time we will give them ENTER_DATA
                    permissions.Append("ENTER_DATA");
                }

                if (permissions.Length > 0)
                {
                    qta.InsertObjectPermissions("KPI", kpiID, myOthers, permissions.ToString());
                }
            }

            // X% of the time, lets generate data for the KPI
            if (r.Next(0, 10) < Convert.ToInt32(MeasurementsDropDownList.SelectedValue))
            {
                List <KPIMeasurement> measurements = new List <KPIMeasurement>();

                int reportPeriods = r.Next(0, Convert.ToInt32(MeasurementsToGenerateDropDownList.SelectedValue));   // Generate MAX X reports

                for (int j = 0; j < reportPeriods; j++)
                {
                    if (hasCategories)
                    {
                        foreach (Category catX in cat)
                        {
                            foreach (CategoryItem catXItem in catX.Items)
                            {
                                measurements.Add(
                                    new KPIMeasurement(
                                        kpiID,
                                        DateTime.Today.Subtract(new TimeSpan(r.Next(0, 300), 0, 0, 0)),
                                        GenerateMeasurement(theTest.Type),
                                        catX.ID,
                                        catXItem.ItemID));
                            }
                        }
                    }
                    else
                    {
                        measurements.Add(
                            new KPIMeasurement(
                                kpiID,
                                DateTime.Today.Subtract(new TimeSpan(r.Next(0, 300), 0, 0, 0)),
                                GenerateMeasurement(theTest.Type),
                                "",
                                ""));
                    }
                }

                KPIBLL.InsertKPIMeasurements(measurements);
            }
        }
    }
Esempio n. 3
0
    private void CreateOrganizations()
    {
        OrganizationDSTableAdapters.PopulateOrganizationsTableAdapter ota =
            new OrganizationDSTableAdapters.PopulateOrganizationsTableAdapter();

        PopulateDatabaseDSTableAdapters.QueriesTableAdapter qta =
            new PopulateDatabaseDSTableAdapters.QueriesTableAdapter();

        int?organizationID = 0;

        foreach (string organizationName in organizations)
        {
            ota.Insert(currentUsers[r.Next(0, currentUsers.Length)],
                       organizationName, ref organizationID);

            // Make between 0 and X people owners of the organization
            string[] owners = GetRandomSetOfUsers(r.Next(0, Convert.ToInt32(AllowedOwnDropDownList.SelectedValue) + 1), null);
            foreach (string myOwner in owners)
            {
                qta.InsertObjectPermissions("ORGANIZATION", organizationID.Value, myOwner, "OWN");
            }

            bool allowAllManKPIs       = false;
            bool allowAllManProjects   = false;
            bool allowAllManActivities = false;
            bool allowAllManPeople     = false;

            // X% of the time we will allow Everyone to manage KPIs in the organization
            allowAllManKPIs = (r.Next(0, 100) < Convert.ToInt32(AllowedEveryoneManageDropDownList.SelectedValue));
            // X% of the time we will allow Everyone to manage Projects in the organization
            allowAllManProjects = (r.Next(0, 100) < Convert.ToInt32(AllowedEveryoneManageDropDownList.SelectedValue));
            // X% of the time we will allow Everyone to manage Activities in the organization
            allowAllManActivities = (r.Next(0, 100) < Convert.ToInt32(AllowedEveryoneManageDropDownList.SelectedValue));
            // X% of the time we will allow Everyone to manage People in the organization
            allowAllManPeople = (r.Next(0, 100) < Convert.ToInt32(AllowedEveryoneManageDropDownList.SelectedValue));

            if (allowAllManKPIs)
            {
                qta.InsertObjectPublic("ORGANIZATION", organizationID.Value, "MAN_KPI");
            }
            if (allowAllManProjects)
            {
                qta.InsertObjectPublic("ORGANIZATION", organizationID.Value, "MAN_PROJECT");
            }
            if (allowAllManActivities)
            {
                qta.InsertObjectPublic("ORGANIZATION", organizationID.Value, "MAN_ACTIVITY");
            }
            if (allowAllManPeople)
            {
                qta.InsertObjectPublic("ORGANIZATION", organizationID.Value, "MAN_PEOPLE");
            }

            // Get between 0 and X random people to give them permissons to manage some aspect of this object
            string[] others = GetRandomSetOfUsers(r.Next(0, Convert.ToInt32(AllowManageDropDownList.SelectedValue) + 1), owners);

            foreach (string myOthers in others)
            {
                StringBuilder permissions = new StringBuilder();
                // Get the permissons that we will give them.  They can be one or more
                // of MAN_ACTIVITY, MAN_KPI, MAN_PEOPLE and MAN_PROJECT but
                // these cannot be added if these permissons are public as above.

                // 10% of the time give them MAN_KPI
                if (r.Next(0, 100) < 10 && !allowAllManKPIs)
                {
                    AddToStringList(permissions, "MAN_KPI", ";");
                }

                // 10% of the time give them MAN_PROJECT
                if (r.Next(0, 100) < 10 && !allowAllManProjects)
                {
                    AddToStringList(permissions, "MAN_PROJECT", ";");
                }

                // 10% of the time give them MAN_ACTIVITY
                if (r.Next(0, 100) < 10 && !allowAllManActivities)
                {
                    AddToStringList(permissions, "MAN_ACTIVITY", ";");
                }

                // 10% of the time give them MAN_PEOPLE
                if (r.Next(0, 100) < 10 && !allowAllManPeople)
                {
                    AddToStringList(permissions, "MAN_PEOPLE", ";");
                }

                if (permissions.Length > 0)
                {
                    qta.InsertObjectPermissions("ORGANIZATION", organizationID.Value, myOthers, permissions.ToString());
                }
            }

            CreateAreas(organizationID.Value);
            CreateProject(organizationID.Value, 0);
            CreatePeople(organizationID.Value);
            CreateActivity(organizationID.Value, 0, 0);
            CreateKPI(organizationID.Value, 0, 0, 0, 0);
        }
    }