Ejemplo n.º 1
0
 /// <summary>
 /// Method to access our Worker's exposed properties to update
 /// our displayed label totals
 /// </summary>
 private void DisplayPayOutputs()
 {
     lblWorkerCountOutput.Text    = PieceworkWorker.TotalEmployees.ToString();
     lblTotalMessagesOutput.Text  = PieceworkWorker.TotalMessages.ToString();
     lblOverallPayOutput.Text     = PieceworkWorker.TotalPay.ToString("c");
     lblOverallAverageOutput.Text = PieceworkWorker.GetAveragePay().ToString("c");
 }
Ejemplo n.º 2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     // populate our display labels with database information every time the page is loaded
     lblWorkerCountOutput.Text    = PieceworkWorker.TotalEmployees.ToString();
     lblTotalMessagesOutput.Text  = PieceworkWorker.TotalMessages.ToString();
     lblOverallPayOutput.Text     = PieceworkWorker.TotalPay.ToString("c");
     lblOverallAverageOutput.Text = PieceworkWorker.GetAveragePay().ToString("c");
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Event handler for the Calculate button
        /// Will attempt to process a worker based on the
        /// selected radiobutton and then update the screen
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnCalculate_OnClick(object sender, EventArgs e)
        {
            Page.Validate();
            if (Page.IsValid)                        // ensure our validation checks went through
            {
                Worker myWorker;                     // create an uninstantiated worker

                if (rdWorkerType.SelectedIndex == 0) // if our Piecework Worker radio button is selected
                {
                    // do normal worker
                    // myWorker = new PieceworkWorker(txtWorkerFirstNameEntry.Text, txtWorkerLastNameEntry.Text, txtMessagesEntry.Text);
                    myWorker = new PieceworkWorker(txtWorkerNameEntry.Text, txtMessagesEntry.Text);
                }
                else if (rdWorkerType.SelectedIndex == 1) // if our Senior worker radio button is selected
                {
                    // do senior worker
                    // myWorker = new SeniorWorker(txtWorkerFirstNameEntry.Text, txtWorkerLastNameEntry.Text, txtMessagesEntry.Text);
                    myWorker = new SeniorWorker(txtWorkerNameEntry.Text, txtMessagesEntry.Text);
                }
                else if (rdWorkerType.SelectedIndex == 2) // if our hourly worker radio button is selected
                {
                    // do hourly worker
                    myWorker = new HourlyWorker(txtWorkerNameEntry.Text, txtMessagesEntry.Text, txtHoursWorkedEntry.Text, txtHourlyPayEntry.Text);
                }
                else // in case something goes catastrophically wrong and our user has any other value
                {
                    ArgumentNullException ex = new ArgumentNullException("worker", "Worker type was not selected.");
                    throw ex;
                }

                // assume the data is valid and nothing went wrong
                // we've gone through client and then server side validation,
                // followed by class validation

                // increment our total data
                myWorker.UpdateTotals();

                // add our new worker to the database
                myWorker.AddWorkerToDB();

                // update our labels
                lblWorkerPayOutput.Text = myWorker.Pay.ToString("c");
                DisplayPayOutputs();

                // lock up our form and wait for the clear button to get pressed
                ToggleEnabledControls();

                // focus the clear button to make the user's life easier
                btnClear.Focus();

                lblOutNote.Text = myWorker.ToString() + "<br />This Worker has been successfully recorded.";
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Function used to select one row from database, takes workerID as the primary key
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        internal static object GetOneRow(int id)
        {
            // Declare new worker object and dbConnection
            PieceworkWorker returnWorker = new PieceworkWorker();
            SqlConnection   dbConnection = new SqlConnection();

            dbConnection.ConnectionString = Conn.GetConnectionString();

            // Create new SQL command, assign it prepared statement
            SqlCommand command = new SqlCommand();

            command.Connection  = dbConnection;
            command.CommandType = CommandType.Text;
            command.CommandText = SQLStatements.SelectById;
            command.Parameters.AddWithValue("@entryId", id);

            // Try to connect to the database, create a datareader. If successful, read from the database and fill created row
            // with information from matching record
            try
            {
                dbConnection.Open();
                IDataReader reader = command.ExecuteReader();
                if (reader.Read())
                {
                    returnWorker    = new PieceworkWorker(reader.GetString(1), reader.GetString(2), reader.GetString(3));
                    returnWorker.Id = id;
                }
            }
            catch (Exception ex)
            {
                // System.Windows.MessageBox.Show("A database error has been encountered: " + Environment.NewLine + ex.Message, "Database Error");
            }
            finally
            {
                dbConnection.Close();
            }

            // Return the populated row
            return(returnWorker);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Event handler for our reset totals button being pressed
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btnResetTotals_OnClick(object sender, EventArgs e)
 {
     PieceworkWorker.ResetTotals();
     DisplayPayOutputs();
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Returns all workers in the database as a list of worker objects
        /// </summary>
        /// <returns></returns>
        internal static List <Worker> GetEmployeeList()
        {
            // Declare the connection
            SqlConnection dbConnection = new SqlConnection(Conn.GetConnectionString());

            // Create new SQL command, assign it prepared statement
            SqlCommand     commandString = new SqlCommand(SQLStatements.SelectAll, dbConnection);
            SqlDataAdapter adapter       = new SqlDataAdapter(commandString);

            // Declare a DataTable object that will hold the return value
            DataTable employeeTable = new DataTable();

            // Declare a list of workers to store converted database pulls
            List <Worker> workerList = new List <Worker>();

            // Try to connect to the database, and use the adapter to fill the table
            try
            {
                dbConnection.Open();
                adapter.Fill(employeeTable);
            }
            catch (Exception ex)
            {
                // System.Windows.MessageBox.Show("A database error has been encountered: " + Environment.NewLine + ex.Message, "Database Error");
            }
            finally
            {
                dbConnection.Close();
            }

            // cycle through each row in our table
            foreach (DataRow item in employeeTable.Rows)
            {
                Worker thisWorker; // generic object creation

                // if tree to determine which worker type we want to create
                // uses enumerable comparisons in case things change later so we don't have
                // to worry about updating a bunch of static values everywhere
                if (Int32.Parse(item["workertype"].ToString()) == (int)IncIncEnumerables.WorkerTypes.Regular)
                {
                    thisWorker = new PieceworkWorker(
                        Int32.Parse(item["entryId"].ToString()),
                        item["firstName"].ToString(),
                        item["lastName"].ToString(),
                        item["messages"].ToString(),
                        Convert.ToDateTime(item["entryDate"])
                        );
                }
                else if (Int32.Parse(item["workertype"].ToString()) == (int)IncIncEnumerables.WorkerTypes.Senior)
                {
                    thisWorker = new SeniorWorker(
                        Int32.Parse(item["entryId"].ToString()),
                        item["firstName"].ToString(),
                        item["lastName"].ToString(),
                        item["messages"].ToString(),
                        Convert.ToDateTime(item["entryDate"])
                        );
                }
                else if (Int32.Parse(item["workertype"].ToString()) == (int)IncIncEnumerables.WorkerTypes.Hourly)
                {
                    thisWorker = new HourlyWorker(
                        Int32.Parse(item["entryId"].ToString()),
                        item["firstName"].ToString(),
                        item["lastName"].ToString(),
                        item["messages"].ToString(),
                        Convert.ToDateTime(item["entryDate"]),
                        Int32.Parse(item["hoursWorked"].ToString()),
                        Decimal.Parse(item["hourlyPay"].ToString())
                        );
                }
                else // catch-all we should never see unless some wise guy tampered with the db
                {
                    throw new ArgumentException("Non-existent worker type found in database.");
                }

                workerList.Add(thisWorker);
            }

            // Return an array of worker objects
            return(workerList);//.ToArray();

            // Return the populated DataTable's DataView
            // return employeeTable;
        }