Exemplo n.º 1
0
        protected List <TimeTableRow> GenerateHoursTable(DateTime startDate, DateTime endDate, String UserID)
        {
            //read shifts from the shift table
            webtimeclockEntities db = new webtimeclockEntities();

            //query the table for shifts with the matching user id and within specified begin and end time
            var table = from row in db.shifts
                        where row.UserID == UserID
                        where row.Date >= startDate
                        where row.Date <= endDate
                        orderby row.Date
                        select row;

            //create time table rows with the selected shifts
            List <TimeTableRow> timeTableRows = new List <TimeTableRow>();

            foreach (shift row in table)
            {
                //read data from data table
                DateTime shiftDate          = row.Date.Date;
                string   timeIn             = row.TimeIn.ToShortTimeString();
                string   timeOut            = row.TimeOut.ToShortTimeString();
                TimeSpan timeWorked         = row.TimeWorked;
                string   totalHoursWorked   = timeWorked.Hours + ":" + timeWorked.Minutes + ":" + timeWorked.Seconds;
                TimeSpan rounded            = row.RoundedTimeWorked;
                string   roundedHoursWorked = rounded.Hours + ":" + rounded.Minutes;
                string   comment            = row.Comments;

                //add rows to time table
                TimeTableRow timeTableRowToAdd = new TimeTableRow(shiftDate.ToShortDateString(), timeIn, timeOut, totalHoursWorked, roundedHoursWorked, comment);
                timeTableRows.Add(timeTableRowToAdd);
            }
            return(timeTableRows);
        }
Exemplo n.º 2
0
        protected void getuserDDL(object sender, EventArgs e)
        {
            webtimeclockEntities db = new webtimeclockEntities();

            var uq = from use in db.users
                     select new { uid = use.UserID, fn = use.FirstName, ln = use.LastName };
            List <UsersDisp> u = new List <UsersDisp>();

            foreach (var item in uq)
            {
                string userid    = item.uid;
                string firstname = item.fn;
                string lastname  = item.ln;

                UsersDisp uta = new UsersDisp(userid, firstname, lastname);
                u.Add(uta);
            }


            foreach (UsersDisp row in u.AsEnumerable())
            {
                string dispstring = row.GetFirstName() + " " + row.GetLastName();
                string value      = row.GetUserID();
                UsersDDL.Items.Add(new ListItem(dispstring, value));
            }
        }
Exemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //check if current computer is verified for use of application
            try
            {
                webtimeclockEntities db = new webtimeclockEntities();

                String        userID    = Session["UserID"].ToString().Split(' ')[0];
                DomainAccount u         = new DomainAccount(userID);
                String        name      = u.FirstName;
                String        activated = Request.Cookies["ApplicationActivated"].Value;

                if (activated != "activated")
                {
                    Response.Redirect("~/Verify.aspx", false);
                }

                Boolean clockedIn = (from aUser in db.activeusers
                                     where aUser.UserID == userID
                                     select aUser).Count() == 1;

                if (clockedIn)
                {
                    Clock.Text = "Clock out.";
                }
            }
            catch (Exception ex)
            {
                Response.Redirect("~/Verify.aspx");
            }
        }
Exemplo n.º 4
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         db = new webtimeclockEntities();
         BindGridView();
     }
 }
Exemplo n.º 5
0
        protected void btnUserLogin_Click(object sender, EventArgs e)
        {
            webtimeclockEntities db = new webtimeclockEntities();

            //get the username from the username text box
            string userID   = txtUserName.Text.ToString();
            string password = txtPassword.Text.ToString();

            string checkUser = "";

            try
            {   //authenticates the username and password before it passes username to the database to set session login and role check.
                DomainAccount u = new DomainAccount(userID, password);
                if (u.IsAuthenticated)
                {
                    checkUser = u.Username;
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Active Users", "alert('Invalid S#/Password');", true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            try
            {   //retrieves db record with authenticated username
                var username = (from use in db.users
                                where use.UserID == checkUser
                                select use).Single();

                //sets session ID with username and role for use with clockin in
                Session["UserID"] = username.UserID + " " + username.Role.ToString();

                //User is student
                if (username.Role == 0)
                {
                    Response.Redirect("~/InputTime.aspx");
                }
                //user is student admin or admin
                else if (username.Role == 1 || username.Role == 2)
                {
                    Response.Redirect("~/Admin.aspx");
                }
                else
                {
                    Response.Redirect("~/LoginFailure.aspx");
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 6
0
        private void BindGridView()
        {
            db = new webtimeclockEntities();

            var shift = from s in db.shifts
                        select s;

            if (shift.Count() > 0)
            {
                GridViewShift.DataSource = shift.ToList();
                GridViewShift.DataBind();
            }
        }
Exemplo n.º 7
0
        protected void Button2_Click(object sencer, EventArgs e)
        {
            try
            {
                webtimeclockEntities db = new webtimeclockEntities();

                String userID = Session["UserID"].ToString().Split(' ')[0];
                var    user   = (from use in db.users
                                 where use.UserID == userID
                                 select use).Single();

                TimeReport s = new TimeReport();

                if (!radio_month.Checked && !radio_week.Checked)
                {
                    //say some stuff about needing to check it
                }
                else if (radio_month.Checked)
                {
                    DateTime time       = DateTime.Now;
                    DateTime monthStart = new DateTime(time.Year, time.Month, 1);
                    DateTime monthEnd   = new DateTime(time.Year, time.Month, DateTime.DaysInMonth(time.Year, time.Month));

                    //incorporates all the functions of report generation
                    s = new TimeReport(user.UserID, user.FirstName, user.LastName,
                                       TimeSpanString(monthStart, monthEnd), GenerateHoursTable(monthStart, monthEnd, userID));

                    DisplayReport(s);
                }
                else if (radio_week.Checked)
                {
                    DateTime time   = DateTime.Today;
                    int      offset = time.DayOfWeek - DayOfWeek.Sunday;

                    //last sunday
                    DateTime start = time.AddDays(-offset);
                    //this saturday
                    DateTime end = start.AddDays(6);

                    s = new TimeReport(user.UserID, user.FirstName, user.LastName,
                                       TimeSpanString(start, end), GenerateHoursTable(start, end, userID));

                    DisplayReport(s);
                }
            } catch (Exception ex)
            {
            }
        }
Exemplo n.º 8
0
        protected int?getUserRole()
        {
            int?role = 0;

            try
            {
                webtimeclockEntities db = new webtimeclockEntities();

                String        userID    = Session["UserID"].ToString().Split(' ')[0];
                DomainAccount u         = new DomainAccount(userID);
                String        activated = Request.Cookies["ApplicationActivated"].Value;

                if (activated != "activated")
                {
                    Response.Redirect("~/Verify.aspx", false);
                }

                role = (from aUser in db.users
                        where aUser.UserID == userID
                        select aUser.Role).First();

                if (role == 0)
                {
                    Response.Redirect("~/Default.aspx");
                }

                else if (role == 1)
                {
                    AddUsrBttn.Visible  = false;
                    editUsrBttn.Visible = false;
                }
            }

            catch (Exception ex)
            {
                Response.Redirect("~/Verify.aspx");
            }

            return(role);
        }
Exemplo n.º 9
0
        protected void GridViewShift_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            db = new webtimeclockEntities();

            try
            {
                string   shiftID           = GridViewShift.Rows[e.RowIndex].Cells[1].Text;
                string   userID            = ((TextBox)GridViewShift.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
                DateTime date              = Convert.ToDateTime(((TextBox)GridViewShift.Rows[e.RowIndex].Cells[3].Controls[0]).Text).Date;
                DateTime timeIn            = Convert.ToDateTime(((TextBox)GridViewShift.Rows[e.RowIndex].Cells[4].Controls[0]).Text);
                DateTime timeOut           = Convert.ToDateTime(((TextBox)GridViewShift.Rows[e.RowIndex].Cells[5].Controls[0]).Text);
                DateTime timeWorked        = Convert.ToDateTime(((TextBox)GridViewShift.Rows[e.RowIndex].Cells[6].Controls[0]).Text);
                DateTime roundedTimeWorked = Convert.ToDateTime(((TextBox)GridViewShift.Rows[e.RowIndex].Cells[7].Controls[0]).Text);
                string   comments          = ((TextBox)GridViewShift.Rows[e.RowIndex].Cells[8].Controls[0]).Text;

                int sInt = Convert.ToInt32(shiftID);

                var sh = (from shift in db.shifts
                          where shift.ShiftID == sInt
                          select shift).Single();

                sh.UserID            = userID;
                sh.Date              = date.Date;
                sh.TimeIn            = timeIn;
                sh.TimeOut           = timeOut;
                sh.TimeWorked        = timeWorked.TimeOfDay;
                sh.RoundedTimeWorked = roundedTimeWorked.TimeOfDay;
                sh.Comments          = comments;

                db.SaveChanges();

                GridViewShift.EditIndex = -1;
                BindGridView();
            }
            catch (Exception ex)
            {
                //TODO: write the thing to do the stuff with the prompt to do the datetime correctly like
                //format: "mm/dd/yyyy hh:mm:ss (A or P)M"
            }
        }
Exemplo n.º 10
0
        protected void GridViewShift_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            db = new webtimeclockEntities();

            string shiftID = GridViewShift.Rows[e.RowIndex].Cells[1].Text;
            int    s       = Convert.ToInt32(shiftID);

            try
            {
                var sh = (from shift in db.shifts
                          where shift.ShiftID == s
                          select shift).Single();

                db.shifts.Remove(sh);
                db.SaveChanges();

                BindGridView();
            }
            catch (Exception ex)
            {
                //no
            }
        }
Exemplo n.º 11
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            webtimeclockEntities db = new webtimeclockEntities();

            String userID = Session["UserID"].ToString().Split(' ')[0];

            //Check if userid is already in active users
            //if so, is clocked in
            Boolean clockedIn = (from aUser in db.activeusers
                                 where aUser.UserID == userID
                                 select aUser).Count() == 1;

            DateTime ClockTime = DateTime.Now;

            if (!clockedIn)
            {
                String comments = Comments.Text;
                Session["ClockedIn"] = "in " + ClockTime.ToString();
                Clock.Text           = "Clock out";
                ClockedinTime.Text   = "You clocked in at " + ClockTime.ToShortTimeString();

                activeuser s = new activeuser
                {
                    UserID   = userID,
                    Time     = ClockTime,
                    Comments = comments
                };

                db.activeusers.Add(s);
                db.SaveChanges();
            }

            else if (clockedIn)
            {
                Clock.Text = "Clock in";

                DateTime inTime = (from aUser in db.activeusers
                                   where aUser.UserID == userID
                                   select aUser).Single().Time;
                DateTime outTime           = DateTime.Now;
                TimeSpan difference        = outTime - inTime;
                TimeSpan roundedDifference = TimeSpan.FromMinutes(15 * Math.Ceiling((difference.TotalMinutes - 7) / 15));
                ClockedinTime.Text   = "You worked " + difference.ToString();
                Session["ClockedIn"] = "out " + ClockTime.ToString();

                //Add worked shift to the database
                shift s = new shift()
                {
                    UserID            = userID,
                    Date              = DateTime.Now,
                    TimeIn            = inTime,
                    TimeOut           = outTime,
                    TimeWorked        = difference,
                    RoundedTimeWorked = roundedDifference,
                    Comments          = Comments.Text
                };
                db.shifts.Add(s);
                db.SaveChanges();

                //Remove user as active user
                var user = (from aUser in db.activeusers
                            where aUser.UserID == userID
                            select aUser).Single();

                db.activeusers.Remove(user);
                db.SaveChanges();
            }
        }
Exemplo n.º 12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null)
            {
                Response.Redirect("~/Default.aspx", false);
            }

            try
            {
                webtimeclockEntities db = new webtimeclockEntities();

                // query active users, join with users table for name info
                var table = from row in db.activeusers
                            join name in db.users on row.UserID equals name.UserID
                            select new { uid = row.UserID, fn = name.FirstName, ln = name.LastName, t = row.Time };



                // create active user list
                List <ActiveUserDisp> auTableRows = new List <ActiveUserDisp>();

                foreach (var item in table)
                {
                    //read data from data table
                    string userid    = item.uid;
                    string firstname = item.fn;
                    string lastname  = item.ln;
                    string date      = item.t.ToShortDateString();
                    string time      = item.t.ToShortTimeString();


                    //add rows to active user list
                    ActiveUserDisp activeuserRowToAdd = new ActiveUserDisp(userid, firstname, lastname, date, time);
                    auTableRows.Add(activeuserRowToAdd);
                }

                // if no active users display empty warning
                if (!auTableRows.Any())
                {
                    empty_warning.Visible = true;
                }

                // if active users, display activeusers table
                else
                {
                    TableRow header = new TableRow
                    {
                        Cells =
                        {
                            new TableCell {
                                Text = "User ID", Wrap = false, HorizontalAlign = HorizontalAlign.Center
                            },
                            new TableCell {
                                Text = "First Name", Wrap = false, HorizontalAlign = HorizontalAlign.Center
                            },
                            new TableCell {
                                Text = "Last Name", Wrap = false, HorizontalAlign = HorizontalAlign.Center
                            },
                            new TableCell {
                                Text = "Clock In Date", Wrap = false, HorizontalAlign = HorizontalAlign.Center
                            },
                            new TableCell {
                                Text = "Clock In Time", Wrap = false, HorizontalAlign = HorizontalAlign.Center
                            },
                        }
                    };

                    table_activeusers.Rows.Add(header);
                    table_activeusers.CellSpacing = 10;

                    foreach (ActiveUserDisp row in auTableRows.AsEnumerable())
                    {
                        TableRow rowToAdd = new TableRow
                        {
                            Cells =
                            {
                                new TableCell {
                                    Text = row.GetUserID(), Wrap = false, HorizontalAlign = HorizontalAlign.Center
                                },
                                new TableCell {
                                    Text = row.GetFirstName(), Wrap = false, HorizontalAlign = HorizontalAlign.Center
                                },
                                new TableCell {
                                    Text = row.GetLastName(), Wrap = false, HorizontalAlign = HorizontalAlign.Center
                                },
                                new TableCell {
                                    Text = row.GetDate(), Wrap = false, HorizontalAlign = HorizontalAlign.Center
                                },
                                new TableCell {
                                    Text = row.GetTime(), Wrap = false, HorizontalAlign = HorizontalAlign.Center
                                },
                            }
                        };

                        table_activeusers.CellPadding = 7;
                        table_activeusers.Rows.Add(rowToAdd);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 13
0
        protected void CreateUserBttn_Click(object sender, EventArgs e)
        {
            webtimeclockEntities db = new webtimeclockEntities();

            // get info from text input
            String sNum  = SNumTxtBx.Text.ToString();
            String fName = FNameTxtBx.Text.ToString();
            String lName = LNameTxtBx.Text.ToString();
            int    role  = Int32.Parse(RoleDDL.SelectedItem.Value);

            try
            { // check if userid is in users table
                Boolean usercheck1 = (from use in db.users
                                      where use.UserID == sNum
                                      select use).Count() == 1;

                // if it is, display warning
                if (usercheck1)
                {
                    WarningLbl.Visible = true;
                    return;
                }

                // if not, create new user

                // have to add domain user name check
                // ex: s123 is not a valid user

                user u = new user
                {
                    UserID    = sNum,
                    FirstName = fName,
                    LastName  = lName,
                    Role      = role
                };

                db.users.Add(u);
                db.SaveChanges();

                Boolean usercheck2 = (from use in db.users
                                      where use.UserID == sNum
                                      select use).Count() == 1;

                Boolean success = false;

                String userAdded = "User " + fName + " was added successfully!  Please press OK on the page to be redirected!";

                ClientScript.RegisterStartupScript(this.GetType(), "User Added", "alert('" + userAdded + "');", true);


                // if it is, redirect to admin
                if (usercheck2)
                {
                    WarningLbl.Text    = "User was added! Press OK to be redirected to the admin page";
                    WarningLbl.Visible = true;

                    success = true;

                    if (success == true)
                    {
                        CreateUserBttn.Visible = false;

                        SuccessBttn.Visible = true;
                    }
                }

                else
                {
                    WarningLbl.Text    = "User was not added";
                    WarningLbl.Visible = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            //  Pseduo Code for checking a successful post to database
            // try
            //    if userID found in table users
            //       WarningLbl.Visible = treu;
            //       WarningLbl.Text = "User is already in the system!";
            //
            //    db append to table users...
            //    if userID found in table users
            //       Response.Redirect("~/Admin.aspx")
            //    else
            //       WarningLbl.Visible = true;
        }