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" } }
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 } }
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(); } }
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; }