Example #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
            }
        }
Example #2
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());
 }