Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,LastName,Title,BirthDate,City")] Empl empl)
        {
            if (id != empl.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(empl);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EmplExists(empl.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(empl));
        }
        /// <summary>
        /// Process employees. Some come, some go.
        /// </summary>
        /// <param name="connection">DB Connection</param>
        private Boolean ProcessEmployees(SqlConnection connection, Random r, TextBox txtResults, String description, int amount)
        {
            txtResults.AppendText(Environment.NewLine + description);
            SqlDataReader reader = null;
            SqlCommand    cmd    = new SqlCommand();

            cmd.CommandText = "Select * from vStoresNotClosedForever";
            cmd.CommandType = CommandType.Text;
            cmd.Connection  = connection;
            int storeID;

            // Add a random employee for each store that is not closed forever
            try {
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    storeID = Convert.ToInt32(reader.GetValue(0));
                    Empl.AddRandomEmpl(storeID, r, connection);
                }
                reader.Close();
                Empl.RandomizeWorkStatusForAllEmployees(connection, r, Write);
            } catch (Exception ex) {
                Console.WriteLine("AddTransactions.ProcessEmployees(): " + ex.Message);
            } finally { try { reader.Close(); } catch (Exception ex) { Utils.Log(ex.Message); } }
            return(true);
        }
        static void Main(string[] args)
        {
            Empl e = AcceptData();

            InsertData(e);
            Console.WriteLine("Record Added Successfully");
            SelectData();
        }
Esempio n. 4
0
        public ActionResult ConfirmDelete(int id)
        {
            Empl empl = repo.Get(id);

            if (empl != null)
            {
                return(View(empl));
            }
            return(NotFound());
        }
Esempio n. 5
0
        public ActionResult Details(int id)
        {
            Empl empl = repo.Get(id);

            if (empl != null)
            {
                return(View(empl));
            }
            return(NotFound());
        }
Esempio n. 6
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Title,BirthDate,City")] Empl empl)
        {
            if (ModelState.IsValid)
            {
                _context.Add(empl);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(empl));
        }
        private static Empl AcceptData()
        {
            Console.WriteLine("Enter Empid, Empname, Gender, city and Deptid");
            Empl e = new Empl();

            e.Empid   = Convert.ToInt32(Console.ReadLine());
            e.Name    = Console.ReadLine();
            e.Gender  = Console.ReadLine();
            e.Newcity = Console.ReadLine();
            e.Deptid  = Convert.ToInt32(Console.ReadLine());
            return(e);
        }
Esempio n. 8
0
    public void Main()
    {
        Empl test = new Empl()
        {
            TestProp = "blub",
            TestInt  = 1
        };

        if (test.ValidateProperties(Validations.CheckEmptyStringsAndZeroInts))
        {
            Console.WriteLine("validation passed");
        }
        else
        {
            Console.WriteLine("validation failed");
        }
    }
Esempio n. 9
0
        private static void Demo()
        {
            SimulatorNamespace.SimGrocery sg = new SimulatorNamespace.SimGrocery();
            Config.randomNumberSeed    = 42;
            Config.random              = new Random(Config.randomNumberSeed);
            Config.verboseConsoleMode  = false;
            Config.elapsedMinutesToRun = 0;     // zero means ignore this limit
            Config.setTransactionDelay(5);      // Seconds
            Config.useCurrentDateStampForTransaction = true;
            Config.startDate               = DateTime.Now;
            Config.throughDate             = DateTime.Now.AddYears(10);
            Config.mode                    = Config.modeEnum.running;
            Config.server                  = "il-server-002.uccc.uc.edu\\mssqlserver2019";
            Config.login                   = "******";
            Config.password                = "******";
            Config.database                = "GroceryStoreSimulatorIsaiah";
            Config.useCoupons              = true;
            Config.checkForAllStoresClosed = true;
            Config.executeFailSafeOptions  = false;     // false = do not delete all the history from stores, employees, etc.
            Config.prioritizeProducts      = true;
            // This is tricky: the index of the selected item in the combo box must map to a specific enum. Be sure both are zero based:
            Config.storeCheckInterval   = Config.enum_availableCheckIntervals.OnThe10s;
            Config.emplCheckInterval    = Config.enum_availableCheckIntervals.OnThe10s;
            Config.productCheckInterval = Config.enum_availableCheckIntervals.OnThe10s;
            Config.couponCheckInterval  = Config.enum_availableCheckIntervals.OnThe10s;
            //String[] tmp = cbCouponAmountToAdd.SelectedItem.ToString().Split();
            Config.couponAmountToAdd = 100; // After couponCheckInterval
            int numOfTransactionsToAdd = 0; // 0 = infinite transactions

            if (Config.executeFailSafeOptions)
            {
                ProductPriceHist.CopyFromFromProductTableIntoProductPriceHist(Config.startDate); // Config.earliestPossibleDate);     // Fail-safe strategy
                Empl.MakeAllEmplAvailableToWork(Config.startDate);                               // Config.earliestPossibleDate);                                   // Fail-safe strategy
                Store.MakeAllStoreOpenForBusiness(Config.startDate);                             // Config.earliestPossibleDate);                                 // Fail-safe strategy
            }
            //*****************************
            // Finally, start transacting
            //*****************************
            Utils.Log("Starting Simulator...");
            sg.StartTransactionSimulation(numOfTransactionsToAdd, Config.random, null, null);
        }
 private static void InsertData(Empl e1)
 {
     db.Empls.Add(e1);
     db.SaveChanges();
 }
Esempio n. 11
0
        private void btnStartTransactionSimulator_Click(object sender, EventArgs e)
        {
            TextBox.CheckForIllegalCrossThreadCalls = false;    // We will spawn a thread that writes to a control on this thread.
            Boolean  validInput = true;
            DateTime startDate = DateTime.Now, throughDate = DateTime.Now;

            switch (Config.mode)
            {
            case Config.modeEnum.idle:
                try {
                    // Check to see if the user wants to run for a period of elapsed time or run forever
                    if (cbIgnoreElapsedTime.Checked == true)
                    {
                        Config.elapsedMinutesToRun = 0;         // zero means ignore this limit
                    }
                    else
                    {
                        int      hours = 0, minutes = 0;
                        String[] split = txtElapsedTimeToRun.Text.Trim().Split(':');
                        hours = Convert.ToInt32(split[0]);
                        if (split.Length == 2)
                        {
                            minutes = Convert.ToInt32(split[1]);
                        }
                        Config.elapsedMinutesToRun = hours * 60 + minutes;
                    }
                } catch (Exception ex) {
                    validInput = false;
                    MessageBox.Show("Input error: " + ex.Message, "Check Hours:Minutes to run.");
                }
                try {
                    Config.setTransactionDelay(Convert.ToInt32(txtTransactionDelay.Text));
                } catch (Exception ex) {
                    MessageBox.Show("Input error: " + ex.Message, "Check Transaction Delay.");
                    Utils.Log(ex.Message);
                    validInput = false;
                }
                if (validInput && !cbUseCurrentDateStampForTransaction.Checked)
                {
                    try {
                        // Don't store these values in the Config object unless both are valid.
                        startDate   = Convert.ToDateTime(txtStartDate.Text);
                        throughDate = Convert.ToDateTime(txtThroughDate.Text);
                        if ((throughDate - startDate).TotalDays < 0)
                        {
                            throw new Exception("Through Date must follow or equal Start Date.");
                        }
                        if (startDate < Config.earliestPossibleDate)
                        {
                            throw new Exception("Start date cannot be earlier than " + Config.earliestPossibleDate.ToShortDateString());
                        }
                    } catch (Exception ex) {
                        validInput = false;
                        MessageBox.Show("Input error: " + ex.Message, "Check Start Date and Through Date.");
                    }
                }
                if (validInput)
                {
                    Config.useCurrentDateStampForTransaction = cbUseCurrentDateStampForTransaction.Checked;
                    Config.startDate              = startDate;
                    Config.throughDate            = throughDate;
                    Config.mode                   = Config.modeEnum.running;
                    Config.server                 = txtServer.Text;
                    Config.login                  = txtLogin.Text;
                    Config.password               = txtPassword.Text;
                    Config.database               = txtDatabase.Text;
                    Config.useCoupons             = cbUseCoupons.Checked;
                    Config.executeFailSafeOptions = cbExecuteFailSafe.Checked;
                    // This is tricky: the index of the selected item in the combo box must map to a specific enum. Be sure both are zero based:
                    Config.storeCheckInterval   = (Config.enum_availableCheckIntervals)cbStoreCheckInterval.SelectedIndex;
                    Config.emplCheckInterval    = (Config.enum_availableCheckIntervals)cbEmplCheckInterval.SelectedIndex;
                    Config.productCheckInterval = (Config.enum_availableCheckIntervals)cbProductCheckInterval.SelectedIndex;
                    Config.couponCheckInterval  = (Config.enum_availableCheckIntervals)cbCouponCheckInterval.SelectedIndex;
                    String[] tmp = cbCouponAmountToAdd.SelectedItem.ToString().Split();
                    Config.couponAmountToAdd = Convert.ToInt32(tmp[0]);
                    int numOfTransactionsToAdd;
                    if (cbRunForever.Checked == true)
                    {
                        numOfTransactionsToAdd = 0;     // Zero means run forever
                    }
                    else
                    {
                        try {
                            numOfTransactionsToAdd = Convert.ToInt32(txtNumOfTransactionsToAdd.Text);
                        } catch (Exception ex) {
                            MessageBox.Show("Enter the number of transactions to add or select Run Forever", "Invalid Number");
                            txtNumOfTransactionsToAdd.Focus();
                            Utils.Log(ex.Message);
                            return;
                        }
                    }
                    try {
                        if (Config.executeFailSafeOptions)
                        {
                            ProductPriceHist.CopyFromFromProductTableIntoProductPriceHist(Config.startDate); // Config.earliestPossibleDate);     // Fail-safe strategy
                            Empl.MakeAllEmplAvailableToWork(Config.startDate);                               // Config.earliestPossibleDate);                                   // Fail-safe strategy
                            Store.MakeAllStoreOpenForBusiness(Config.startDate);                             // Config.earliestPossibleDate);                                 // Fail-safe strategy
                        }
                        sg.StartTransactionSimulation(numOfTransactionsToAdd, Config.random, txtResults, lblStatus);
                    } catch (Exception ex) {
                        txtResults.Text += "btnGo_Click:" + "sg.StartSimulation: " + ex.Message;
                    }
                    btnStartTransactionSimulator.Text = "Halt";
                    watch = Stopwatch.StartNew();
                    lblElapsedTime.Text = "";
                    ShowTimerControls(true);
                    timer1.Enabled    = true;
                    txtSeed.Enabled   = false;
                    lblStartTime.Text = (String.Format("{0:hh\\:mm\\:ss tt}", DateTime.Now));
                }
                break;

            case Config.modeEnum.running:
                Config.mode = Config.modeEnum.idle;
                btnStartTransactionSimulator.Text = "Go";
                sg.Halt();
                watch           = null;
                timer1.Enabled  = false;
                txtSeed.Enabled = true;
                break;
            }
        }
Esempio n. 12
0
 public ActionResult Edit(Empl empl)
 {
     repo.Update(empl);
     return(RedirectToAction("Index"));
 }
Esempio n. 13
0
 public ActionResult Create(Empl user)
 {
     repo.Create(user);
     return(RedirectToAction("Index"));
 }
        /// <summary>
        /// Compute random record IDs for the random transaction we will add
        /// </summary>
        /// <param name="tp">The set of transaction parameters upon which to operate</param>
        private void computeRandomValuesForTransaction(TransactionParameters tp, Random r)
        {
            try {
                // Date/time of transaction
                if (Config.useCurrentDateStampForTransaction)
                {
                    tp.dateOfTransaction = DateTime.Now.ToShortDateString();
                    tp.timeOftransaction = DateTime.Now.ToLongTimeString();
                }
                else
                {
                    tp.dateOfTransaction = Utils.GetRandomDate(r);
                    tp.timeOftransaction = Utils.GetRandomTime(r);
                }
                tp.emplID  = 0;
                tp.storeID = Utils.GetRandomStoreID(r, DefaultValues.storeID_count);

                //tp.storeID = 10;
                //tp.dateOfTransaction = "1/9/2017";
                //tp.timeOftransaction = "12:29:1.656";
                //if (tp.storeID == 29)
                //{
                //   int tmp = 42;
                //}
                while (true)
                {
                    int emplID;
                    // Pick a random employee that is available for work at the storeID
                    try {
                        emplID = (int)Utils.MyDLookup("EmplID", "SELECT TOP 1 EmplID FROM [fEmplWhoCanWorkOnASpecificDateAtASpecificStore](" + Utils.QuoteMeForSQL(tp.dateOfTransaction) + " ," + tp.storeID + ") ORDER BY NEWID()", "", "");
                        // SELECT top 1   * FROM [fEmplWhoCanWorkOnASpecificDateAtASpecificStore]('1/1/2016', 2) order by newID()
                    } catch (Exception ex) { emplID = 0; Utils.Log("AddTransactions.computeRandomValuesForTransaction(): " + ex.Message); }
                    // emplID = (int)Utils.MyDLookup("EmplID", "(SELECT ROW_NUMBER() OVER (ORDER BY emplID) AS RowNum, * FROM tEmpl) sub ", " RowNum = " + (r.Next(DefaultValues.emplID_count) + 1), "");
                    if (emplID > 0)
                    {
                        tp.emplID = emplID;
                        break;
                    }
                    else
                    {
                        //if (tp.storeID == 21) {
                        //    int foo = -42;
                        //}
                        Write("### It appears that no employees are available for work. Adding one... ###");
                        emplID    = Empl.AddRandomEmplAndMakeThemAvailableForWork(tp.storeID, DateTime.Parse(tp.dateOfTransaction), connection, r);
                        tp.emplID = emplID;
                        break;
                    }
                }
                if (tp.emplID == 0)         // Uh oh. No employees available for work at this store...
                // todo: something here
                //int tmp = 0;
                {
                }
                tp.loyaltyID = (int)Utils.MyDLookup("loyaltyID",
                                                    "(SELECT ROW_NUMBER() OVER (ORDER BY loyaltyID) AS RowNum, * FROM tloyalty) sub ",
                                                    " RowNum = " + (r.Next(DefaultValues.loyaltyID_count) + 1),
                                                    "");
                // A high percentage of transactions should be purchases.
                int selector = r.Next(100) + 1;     // 1 to 100
                if (selector >= Config.percentageOfPurchaseTransactions)
                {
                    // It can be another type of transaction so we will look it up randomly
                    tp.transactionTypeID = (int)Utils.MyDLookup("transactionTypeID",
                                                                "(SELECT ROW_NUMBER() OVER (ORDER BY transactionTypeID) AS RowNum, * FROM tTransactionType) sub ",
                                                                " RowNum = " + (r.Next(DefaultValues.transactionTypeID_count) + 1),
                                                                "");
                }
                else
                {
                    // It has to be a purchase transaction
                    tp.transactionTypeID = DefaultValues.transactionTypeID_Purchase;
                }
            } catch (Exception ex) {
                // Something went wrong.
                txtResults.AppendText(Environment.NewLine + "AddTransactions.computeRandomValuesForTransaction: " + ex.Message);
            }
        }
Esempio n. 15
0
        // GET: api/Emp/5
        public IHttpActionResult GetById(int id)
        {
            Empl e = new Empl();

            var myObjectResponse = GetObjectFromDb(id);
        }