protected void gridViewUser_Command(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Select") { GetMyAccessRights(); modalLabelError.Text = ""; modalLabelError.Visible = false; int index = Convert.ToInt32(e.CommandArgument); int userid = Convert.ToInt32(((Label)gridViewUser.Rows[index].FindControl("labelUserId")).Text); User user = new User(); user = user.GetUser(userid); modalBtnSubmit.Visible = Convert.ToBoolean(myAccessRights.CanUpdate); modalLabelUserId.Text = userid.ToString(); modalLabelEmployeeNo.Text = user.EmployeeNumber.ToString(); modalLabelFirstName.Text = user.Firstname.Trim(); modalLableLastName.Text = user.Lastname; modalTxtBoxStartTime.Text = user.startTime; modalTxtBoxEndTime.Text = user.endTime; modalTxtBoxSalary.Text = user.currentSalary.ToString(); modalTxtBoxBreakTimeMin.Text = user.currentMinBreak.ToString(); InitializeOffDayDropDown(modalDropDownOffDay,user.currentOffDay.ToString()); InitializeOffDayDropDown(modalDropDownSpecialOffDay, user.currentSpecialOffDay.ToString()); InitializeOffDayDropDown(modalDropDownOptionalOffDay1,user.currentOptOffDay1.ToString()); InitializeOffDayDropDown(modalDropDownOptionalOffDay2,user.currentOptOffDay2.ToString()); InitializeOffDayDropDown(modalDropDownOptionalOffDay3,user.currentOptOffDay3.ToString()); InitializeOffDayDropDown(modalDropDownOptionalOffDay4,user.currentOptOffDay4.ToString()); modalChckBoxNoOTPay.Checked = user.noOTpay; modalChckBoxOfficeWorker.Checked = user.isOfficeWorker; if (user.currentRateCreateDate == DateTime.Today) { modalTxtBoxStartDate.Text = user.currentRateStartDate.ToString("dd MMM yyyy"); calendarExtenderStartDate.SelectedDate = user.currentRateStartDate; } else { modalTxtBoxStartDate.Text = DateTime.Today.ToString("dd MMM yyyy"); calendarExtenderStartDate.SelectedDate = DateTime.Today; } UserRateSchedule prevUserRateSchedule= new UserRateSchedule(); prevUserRateSchedule = prevUserRateSchedule.GetPreviousUserScheduleRateByUserIdLastUpdateDate(user.Id, DateTime.Today); if (prevUserRateSchedule != null) { calendarExtenderStartDate.StartDate = prevUserRateSchedule.StartDate.AddDays(1); } else { calendarExtenderStartDate.StartDate = null; } modalChckBoxUsePattern.Checked = user.usePattern; ToggleReqField(user.usePattern); modalTxtBoxPattern.Text = user.offPattern.Trim(); modalTxtBoxPatternStartDate.Text = user.patternStartDate.ToString("dd MMM yyyy"); calendarExtenderPatternStartDate.SelectedDate = user.patternStartDate; if (modalChckBoxUsePattern.Checked == true) { cpeNormalUse.ClientState = "true"; cpePatternUse.ClientState = "false"; } else { cpePatternUse.ClientState = "true"; cpeNormalUse.ClientState = "false"; } this.programmaticModalPopup.Show(); } }
protected void modalBtnSubmit_Command(object sender, CommandEventArgs e) { //if (modalChkBoxUpdateRate.Checked == true) //Checks if starttime and endtime is in correct format //{ // TimeSpan starttime = new TimeSpan(); // TimeSpan endtime = new TimeSpan(); // if (TimeSpan.TryParse(modalTxtBoxStartTime.Text, out starttime)) // { // } // else // { // modalLabelError.Text = "Start Time not in valid format."; // modalLabelError.Visible = true; // } // if (TimeSpan.TryParse(modalTxtBoxEndTime.Text, out endtime)) // { // } // else // { // modalLabelError.Text = "End Time not in valid format."; // modalLabelError.Visible = true; // } //} if (modalLabelError.Visible == true) this.programmaticModalPopup.Show(); else { int userid = Convert.ToInt32(Session["UserId"]); User user = new User(); if (modalLabelUserId.Text.Trim() != "") //Update { user = user.GetUser(Convert.ToInt32(modalLabelUserId.Text)); } user.Firstname = modalTxtBoxFirstname.Text.Trim(); user.Lastname = modalTxtBoxLastname.Text.Trim(); user.RoleId = Convert.ToInt32(modalDropDownRole.SelectedItem.Value); user.DepartmentId = Convert.ToInt32(modalDropDownDepartment.SelectedItem.Value); user.Username = modalTxtBoxUsername.Text.Trim(); user.Password = modalTxtBoxPassword.Text.Trim(); user.Email = modalTxtBoxEmail.Text.Trim(); user.Phone = modalTxtBoxPhone.Text.Trim(); user.Fax = modalTxtBoxFax.Text.Trim(); user.Mobile = modalTxtBoxMobile.Text.Trim(); user.LastUpdatedBy = userid; user.LastUpdateDate = DateTime.Now; user.EmployeeNumber = Convert.ToInt32(modalTxtBoxEmployeeNo.Text); user.Status = modalDropDownStatus.SelectedItem.Value; //user.Shift = modalRadBtnListShift.SelectedItem.Value.Trim(); if (e.CommandArgument.ToString().Trim() == "Add") { user.CreateDate = DateTime.Now; user.CreatedBy = userid; user.Insert(user); user = user.GetLastInsertedUser(); //assign newly created user to variable user } else if (e.CommandArgument.ToString().Trim() == "Update") { user.Update(user); } if (modalChkBoxUpdateRate.Checked == true) //User intends to update salary rate { UserRateSchedule userRateSchedule = new UserRateSchedule(); userRateSchedule = userRateSchedule.GetUserScheduleRateByUserIdStartDate(user.Id, DateTime.Today); //Checks if there is already a schedule date with the same start date if (userRateSchedule != null) { userRateSchedule.StartTime = modalTxtBoxStartTime.Text.Trim(); userRateSchedule.EndTime = modalTxtBoxEndTime.Text.Trim(); userRateSchedule.OffDay = Convert.ToInt32(modalDropDownOffDay.SelectedItem.Value); userRateSchedule.SpecialOffDay = Convert.ToInt32(modalDropDownSpecialOffDay.SelectedItem.Value); userRateSchedule.NoOTPay = modalChckBoxNoOTPay.Checked; userRateSchedule.Update(userRateSchedule); userRateSchedule.IsOfficeWorker = modalChckBoxOfficeWorker.Checked; userRateSchedule.MinsBreak = Convert.ToInt32(modalTxtBoxBreakTimeMin.Text); } else { userRateSchedule = new UserRateSchedule(); UserRateSchedule prevUserRateSchedule = userRateSchedule.GetPreviousUserScheduleRateByUserIdLastUpdateDate(user.Id, DateTime.Today); userRateSchedule.StartTime = modalTxtBoxStartTime.Text.Trim(); userRateSchedule.EndTime = modalTxtBoxEndTime.Text.Trim(); userRateSchedule.UserId = user.Id; userRateSchedule.OffDay = Convert.ToInt32(modalDropDownOffDay.SelectedItem.Value); userRateSchedule.SpecialOffDay = Convert.ToInt32(modalDropDownSpecialOffDay.SelectedItem.Value); userRateSchedule.NoOTPay = modalChckBoxNoOTPay.Checked; userRateSchedule.IsOfficeWorker = modalChckBoxOfficeWorker.Checked; userRateSchedule.MinsBreak = Convert.ToInt32(modalTxtBoxBreakTimeMin.Text); userRateSchedule.StartDate = DateTime.Today; userRateSchedule.IsCurrentRate = true; if (prevUserRateSchedule != null) { prevUserRateSchedule.EndDate = Convert.ToDateTime(DateTime.Today.AddDays(-1).ToString("dd MMM yyyy") + " 23:59:59"); prevUserRateSchedule.IsCurrentRate = false; prevUserRateSchedule.Update(prevUserRateSchedule); } userRateSchedule.Insert(userRateSchedule); } } InitializeGridUser(); this.programmaticModalPopup.Hide(); } }
protected void modalBtnSubmit_Command(object sender, CommandEventArgs e) { if (modalLabelError.Visible == true) this.programmaticModalPopup.Show(); else { int userid = Convert.ToInt32(Session["UserId"]); User user = new User(); if (modalLabelUserId.Text.Trim() != "") //Update { user = user.GetUser(Convert.ToInt32(modalLabelUserId.Text)); } UserRateSchedule userRateSchedule = new UserRateSchedule(); UserRateSchedule prevUserRateSchedule = userRateSchedule.GetPreviousUserScheduleRateByUserIdLastUpdateDate(user.Id, DateTime.Today); userRateSchedule = userRateSchedule.GetUserScheduleRateByUserIdCreateDate(user.Id, DateTime.Today); //Checks if there is already a schedule date with the same start date if (userRateSchedule != null) { userRateSchedule.StartTime = modalTxtBoxStartTime.Text.Trim(); userRateSchedule.EndTime = modalTxtBoxEndTime.Text.Trim(); userRateSchedule.MonthlySalary = userRateSchedule.EncryptSalary(modalTxtBoxSalary.Text.Trim()); userRateSchedule.OffDay = Convert.ToInt32(modalDropDownOffDay.SelectedItem.Value); userRateSchedule.SpecialOffDay = Convert.ToInt32(modalDropDownSpecialOffDay.SelectedItem.Value); userRateSchedule.OptionalOffDay1 = Convert.ToInt32(modalDropDownOptionalOffDay1.SelectedItem.Value); userRateSchedule.OptionalOffDay2 = Convert.ToInt32(modalDropDownOptionalOffDay2.SelectedItem.Value); userRateSchedule.OptionalOffDay3 = Convert.ToInt32(modalDropDownOptionalOffDay3.SelectedItem.Value); userRateSchedule.OptionalOffDay4 = Convert.ToInt32(modalDropDownOptionalOffDay4.SelectedItem.Value); userRateSchedule.NoOTPay = modalChckBoxNoOTPay.Checked; userRateSchedule.IsOfficeWorker = modalChckBoxOfficeWorker.Checked; userRateSchedule.MinsBreak = Convert.ToInt32(modalTxtBoxBreakTimeMin.Text); userRateSchedule.StartDate = Convert.ToDateTime(modalTxtBoxStartDate.Text.Trim()); userRateSchedule.LastUpdatedDate = DateTime.Today; userRateSchedule.IsCurrentRate = true; userRateSchedule.UsePattern = modalChckBoxUsePattern.Checked; userRateSchedule.OffPattern = modalTxtBoxPattern.Text.Trim(); userRateSchedule.PatternStartDate = Convert.ToDateTime(modalTxtBoxPatternStartDate.Text.Trim()); userRateSchedule.Update(userRateSchedule); } else { userRateSchedule = new UserRateSchedule(); userRateSchedule.StartTime = modalTxtBoxStartTime.Text.Trim(); userRateSchedule.EndTime = modalTxtBoxEndTime.Text.Trim(); userRateSchedule.UserId = user.Id; userRateSchedule.MonthlySalary = userRateSchedule.EncryptSalary(modalTxtBoxSalary.Text.Trim()); userRateSchedule.OffDay = Convert.ToInt32(modalDropDownOffDay.SelectedItem.Value); userRateSchedule.SpecialOffDay = Convert.ToInt32(modalDropDownSpecialOffDay.SelectedItem.Value); userRateSchedule.OptionalOffDay1 = Convert.ToInt32(modalDropDownOptionalOffDay1.SelectedItem.Value); userRateSchedule.OptionalOffDay2 = Convert.ToInt32(modalDropDownOptionalOffDay2.SelectedItem.Value); userRateSchedule.OptionalOffDay3 = Convert.ToInt32(modalDropDownOptionalOffDay3.SelectedItem.Value); userRateSchedule.OptionalOffDay4 = Convert.ToInt32(modalDropDownOptionalOffDay4.SelectedItem.Value); userRateSchedule.NoOTPay = modalChckBoxNoOTPay.Checked; userRateSchedule.IsOfficeWorker = modalChckBoxOfficeWorker.Checked; userRateSchedule.MinsBreak = Convert.ToInt32(modalTxtBoxBreakTimeMin.Text); userRateSchedule.StartDate = Convert.ToDateTime(modalTxtBoxStartDate.Text.Trim()); userRateSchedule.IsCurrentRate = true; userRateSchedule.CreatedDate = DateTime.Today; userRateSchedule.LastUpdatedDate = DateTime.Today; userRateSchedule.UsePattern = modalChckBoxUsePattern.Checked; userRateSchedule.OffPattern = modalTxtBoxPattern.Text.Trim(); userRateSchedule.PatternStartDate = Convert.ToDateTime(modalTxtBoxPatternStartDate.Text.Trim()); userRateSchedule.Insert(userRateSchedule); } if (prevUserRateSchedule != null) { prevUserRateSchedule.EndDate = Convert.ToDateTime(modalTxtBoxStartDate.Text.Trim()+" 23:59:59"); prevUserRateSchedule.IsCurrentRate = false; prevUserRateSchedule.LastUpdatedDate = DateTime.Today; prevUserRateSchedule.Update(prevUserRateSchedule); } } }
private void GetMyRate(DateTime date) { UserRateSchedule URS = new UserRateSchedule(); URS = URS.GetUserScheduleRateByUserIdDate(Id, date); if (URS != null) { startTime = URS.StartTime == "" ? "08:00" : URS.StartTime; endTime = URS.EndTime == "" ? "17:00" : URS.EndTime; currentSalary = URS.GetMySalary(); currentOffDay = URS.OffDay; currentSpecialOffDay = URS.SpecialOffDay; currentOptOffDay1 = URS.OptionalOffDay1 == null ? 0 : Convert.ToInt32(URS.OptionalOffDay1); currentOptOffDay2 = URS.OptionalOffDay2 == null ? 0 : Convert.ToInt32(URS.OptionalOffDay2); currentOptOffDay3 = URS.OptionalOffDay3 == null ? 0 : Convert.ToInt32(URS.OptionalOffDay3); currentOptOffDay4 = URS.OptionalOffDay4 == null ? 0 : Convert.ToInt32(URS.OptionalOffDay4); noOTpay = URS.NoOTPay; currentMinBreak = URS.MinsBreak == null ? 0 : Convert.ToInt32(URS.MinsBreak); isOfficeWorker = URS.IsOfficeWorker == null ? false : Convert.ToBoolean(URS.IsOfficeWorker); currentRateStartDate = URS.StartDate; currentRateCreateDate = URS.CreatedDate == null ? DateTime.Today : Convert.ToDateTime(URS.CreatedDate); usePattern = URS.UsePattern == null ? false : Convert.ToBoolean(URS.UsePattern); offPattern = URS.OffPattern == null ? "" : URS.OffPattern.Trim(); patternStartDate = URS.PatternStartDate == null ? DateTime.Today : Convert.ToDateTime(URS.PatternStartDate); } else { startTime = "08:00"; endTime = "17:00"; currentSalary = 0; currentOffDay = 0; currentSpecialOffDay = 0; currentOptOffDay1 = 0; currentOptOffDay2 = 0; currentOptOffDay3 = 0; currentOptOffDay4 = 0; noOTpay = false; currentMinBreak = 0; isOfficeWorker = false; currentRateStartDate = DateTime.Today; currentRateCreateDate = DateTime.Today; usePattern = false; offPattern = ""; patternStartDate = DateTime.Today; } if (TimeSpan.Parse(startTime) > TimeSpan.Parse(endTime)) { shifting = true; } else { shifting = false; } TimeSpan stime = TimeSpan.Parse(startTime == "" ? "08:00" : startTime); TimeSpan etime = TimeSpan.Parse(endTime == "" ? "17:00" : endTime); if (stime > etime) { minsWorkPerDay = (int)Math.Floor(new TimeSpan(1,0,0,0).TotalMinutes - stime.TotalMinutes); minsWorkPerDay += (int)Math.Floor(etime.TotalMinutes); } else { minsWorkPerDay = (int)Math.Floor(etime.TotalMinutes - stime.TotalMinutes); } minsWorkPerDay -= currentMinBreak; }
private void GetMyRate() { UserRateSchedule URS = new UserRateSchedule(); URS = URS.GetCurrentUserScheduleRateByUserId(Id); if (URS != null) { startTime = URS.StartTime == "" ? "08:00" : URS.StartTime; endTime = URS.EndTime == "" ? "17:00" : URS.EndTime; currentSalary = URS.GetMySalary(); currentOffDay = URS.OffDay; currentSpecialOffDay = URS.SpecialOffDay; currentOptOffDay1 = URS.OptionalOffDay1 == null ? 0 : Convert.ToInt32(URS.OptionalOffDay1); currentOptOffDay2 = URS.OptionalOffDay2 == null ? 0 : Convert.ToInt32(URS.OptionalOffDay2); currentOptOffDay3 = URS.OptionalOffDay3 == null ? 0 : Convert.ToInt32(URS.OptionalOffDay3); currentOptOffDay4 = URS.OptionalOffDay4 == null ? 0 : Convert.ToInt32(URS.OptionalOffDay4); noOTpay = URS.NoOTPay; currentMinBreak = URS.MinsBreak == null ? 0 : Convert.ToInt32(URS.MinsBreak); isOfficeWorker = URS.IsOfficeWorker == null ? false : Convert.ToBoolean(URS.IsOfficeWorker); currentRateStartDate = URS.StartDate; currentRateCreateDate = URS.CreatedDate == null ? DateTime.Today: Convert.ToDateTime(URS.CreatedDate); usePattern = URS.UsePattern == null ? false : Convert.ToBoolean(URS.UsePattern); offPattern = URS.OffPattern == null ? "" : URS.OffPattern.Trim(); patternStartDate = URS.PatternStartDate == null ? DateTime.Today : Convert.ToDateTime(URS.PatternStartDate); } else { startTime = "08:00"; endTime = "17:00"; currentSalary = 0; currentOffDay = 0; currentSpecialOffDay = 0; currentOptOffDay1 = 0; currentOptOffDay2 = 0; currentOptOffDay3 = 0; currentOptOffDay4 = 0; noOTpay = false; currentMinBreak = 0; isOfficeWorker = false; currentRateStartDate = DateTime.Today; currentRateCreateDate = DateTime.Today; usePattern = false; offPattern = ""; patternStartDate = DateTime.Today; } if (TimeSpan.Parse(startTime) > TimeSpan.Parse(endTime)) { shifting = true; } else { shifting = false; } }
private void Parse(T_UserRateSchedule t_userRateSchedule, UserRateSchedule userRateSchedule) { t_userRateSchedule.Id = userRateSchedule.Id; t_userRateSchedule.UserId = userRateSchedule.UserId; t_userRateSchedule.StartTime = userRateSchedule.StartTime; t_userRateSchedule.EndTime = userRateSchedule.EndTime; t_userRateSchedule.StartDate = userRateSchedule.StartDate; t_userRateSchedule.EndDate = userRateSchedule.EndDate; t_userRateSchedule.MonthlySalary = userRateSchedule.MonthlySalary; t_userRateSchedule.IsCurrentRate = userRateSchedule.IsCurrentRate; t_userRateSchedule.OffDay = userRateSchedule.OffDay; t_userRateSchedule.SpecialOffDay = userRateSchedule.SpecialOffDay; t_userRateSchedule.NoOTPay = userRateSchedule.NoOTPay; t_userRateSchedule.MinsBreak = userRateSchedule.MinsBreak; t_userRateSchedule.IsOfficeWorker = userRateSchedule.IsOfficeWorker; t_userRateSchedule.OptionalOffDay1 = userRateSchedule.OptionalOffDay1; t_userRateSchedule.OptionalOffDay2 = userRateSchedule.OptionalOffDay2; t_userRateSchedule.OptionalOffDay3 = userRateSchedule.OptionalOffDay3; t_userRateSchedule.OptionalOffDay4 = userRateSchedule.OptionalOffDay4; t_userRateSchedule.CreatedDate = userRateSchedule.CreatedDate; t_userRateSchedule.LastUpdatedDate = userRateSchedule.LastUpdatedDate; t_userRateSchedule.UsePattern = userRateSchedule.UsePattern; t_userRateSchedule.OffPattern = userRateSchedule.OffPattern; t_userRateSchedule.PatternStartDate = userRateSchedule.PatternStartDate; }
//Update User record in the database public void Update(UserRateSchedule userRateSchedule) { using (TimeTrackerEntities db = new TimeTrackerEntities()) { try { T_UserRateSchedule t_userRateSchedule = db.T_UserRateSchedule.FirstOrDefault(u => u.Id == userRateSchedule.Id); Parse(t_userRateSchedule, userRateSchedule); db.SaveChanges(); } catch (Exception ex) { string msg = ex.Message; } } }
public void Insert(UserRateSchedule userRateSchedule) { T_UserRateSchedule t_userRateSchedule = new T_UserRateSchedule(); Parse(t_userRateSchedule, userRateSchedule); using (TimeTrackerEntities db = new TimeTrackerEntities()) { try { db.T_UserRateSchedule.Add(t_userRateSchedule); db.SaveChanges(); } catch (Exception ex) { string msg = ex.Message; } } }