Ejemplo n.º 1
0
        Worker loadedWorker;        // global holder for current worker we're editing

        /// <summary>
        /// Event handler for our page being loaded.
        /// Will generate the table from our database every time.
        /// Ensures data being seen is the most up-to-date.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            // load up our table data from our db
            //Worker[] tableWorkers = DBL.GetEmployeeList();
            tableWorkers = DBL.GetEmployeeList();

            // quick check if we're posting back and if we stored a 'selection' from the user clicking
            // on one of our dynamic radiobuttons
            if (IsPostBack && !(HttpContext.Current.Session["selectedIndex"] == null))
            {
                if (!((int)HttpContext.Current.Session["selectedIndex"] < 0)) // napkin error checking
                {
                    loadedWorker = tableWorkers[(int)HttpContext.Current.Session["selectedIndex"]];
                }
            }

            int currentWorker = 0; // used to increment button ID

            // do a foreach through each object and add required data to our table
            // we create new item instances every loop so we don't overwrite existing pointers
            foreach (Worker thisWorker in tableWorkers)
            {
                // create an empty tablerow
                TableRow thisRow = new TableRow();

                // create two arrays to store our data for looping
                string[]    workerData = thisWorker.GetTableData();
                TableCell[] newCells   = new TableCell[workerData.Length + 1];

                // we create our radio button in the first slot
                // so we format the tablecell first
                newCells[0] = new TableCell();

                // create our radiobutton control
                RadioButton rdButton = new RadioButton();
                rdButton.GroupName       = "WorkerTable";             // assign a group so only one can be selected
                rdButton.ID              = "Worker_" + currentWorker; // use our incrementing value to assign a unique ID
                rdButton.CheckedChanged += CellRadioButtonClicked;    // add an event handler
                rdButton.AutoPostBack    = true;                      // set the buttons to cause a postback

                newCells[0].Controls.Add(rdButton);                   // add our button

                // set our data via loop
                for (int count = 1; count < newCells.Length; count++)
                {
                    newCells[count]      = new TableCell(); // init tablecell
                    newCells[count].Text = workerData[count - 1];
                }

                // add all cells to our row
                foreach (TableCell currentCell in newCells)
                {
                    thisRow.Cells.Add(currentCell);
                }

                // add our row to our table
                tblWorker.Rows.Add(thisRow);

                currentWorker++; // increment
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Returns the total employee count in the database
 /// </summary>
 /// <returns>Integer</returns>
 protected internal int ReturnEmployeeCount()
 {
     return(DBL.GetEmployeeTotal());
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Returns the total pay given to all workers in the database
 /// </summary>
 /// <returns>Decimal</returns>
 protected internal decimal ReturnPayCount()
 {
     return(DBL.GetPayTotal());
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Returns a total of messages sent by all workers
 /// </summary>
 /// <returns>Integer</returns>
 protected internal int ReturnMessagesCount()
 {
     return(DBL.GetMessagesTotal());
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Pulls our employee list from the database as a list of objects
 /// </summary>
 /// <returns>List of PieceworkWorker</returns>
 protected internal List <Worker> ReturnAllWorkers()
 {
     return(DBL.GetEmployeeList());
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Deletes this worker's database entry
 /// </summary>
 protected internal void DeleteThisWorkerDB()
 {
     DBL.DeleteRow(this.Id);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Updates this worker's database entry
 /// </summary>
 protected internal void UpdateThisWorkerDB()
 {
     DBL.UpdateExistingRow(this);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Adds this worker to the database after timestamping it
 /// </summary>
 protected internal void AddWorkerToDB()
 {
     creationDate = DateTime.Now;
     DBL.InsertNewRecord(this);
 }