protected void gridViewJobType_Command(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Select") { GetMyAccessRights(); modalLabelError.Text = ""; modalLabelError.Visible = false; modalChkboxAll.Checked = false; int index = Convert.ToInt32(e.CommandArgument); int jobtypeId = Convert.ToInt32(((Label)gridViewJobType.Rows[index].FindControl("labelJobTypeId")).Text); modalBtnSubmit.CommandArgument = "Update"; JobType jobtype = new JobType(); jobtype = jobtype.GetJobType(jobtypeId); modalLabelJobTypeId.Text = jobtype.Id.ToString(); modalTxtBoxDescription.Text = jobtype.Description; modalTxtBoxAcronym.Text = jobtype.Acronym; modalTxtBoxPosition.Text = jobtype.Position.ToString(); modalChkBoxComputeTime.Checked = Convert.ToBoolean(jobtype.ComputeTime); modalChkBoxRequiredJobId.Checked = Convert.ToBoolean(jobtype.RequiredJobId); modalChkBoxShowJobOverview.Checked = Convert.ToBoolean(jobtype.ShowInJobOverview); InitializeModalGridViewDepartment(jobtype.Id); //InitializeModalDropDownDepartment(jobtype.DepartmentId.ToString()); SetStatus(Convert.ToBoolean(myAccessRights.CanUpdate)); this.programmaticModalPopup.Show(); } }
protected void modalDescription_Changed(object sender, EventArgs e) { string errorMsg = "Description already used. "; if (modalTxtBoxDescription.Text.Trim() != "") { JobType jobtype = new JobType(); jobtype = jobtype.GetJobTypeByDescription(modalTxtBoxDescription.Text.Trim()); if (jobtype != null) { if (modalLabelJobTypeId.Text.Trim() == "") { modalLabelError.Text += errorMsg; modalLabelError.Visible = true; } else { JobType j = jobtype.GetJobType(Convert.ToInt32(modalLabelJobTypeId.Text)); if (j.Description.Trim().Equals(modalTxtBoxDescription.Text.Trim(), StringComparison.OrdinalIgnoreCase) == true) { modalLabelError.Text += errorMsg; modalLabelError.Visible = true; } else { modalLabelError.Text = modalLabelError.Text.Replace(errorMsg, "").Trim(); } } } else { modalLabelError.Text = modalLabelError.Text.Replace(errorMsg, "").Trim(); } } else { modalLabelError.Text = modalLabelError.Text.Replace(errorMsg, "").Trim(); } if (modalLabelError.Text.Trim().Length == 0) { modalLabelError.Visible = false; } this.programmaticModalPopup.Show(); }
protected void modalBtnSubmit_Command(object sender, CommandEventArgs e) { if (modalLabelError.Visible == true) this.programmaticModalPopup.Show(); else { bool ischkBoxEmpty = IsDeptCheckBoxEmpty(); int userid = Convert.ToInt32(Session["UserId"]); JobType jobtype = new JobType(); if (modalLabelJobTypeId.Text.Trim() != "") { jobtype = jobtype.GetJobType(Convert.ToInt32(modalLabelJobTypeId.Text)); } jobtype.Description = modalTxtBoxDescription.Text.Trim(); jobtype.Acronym = modalTxtBoxAcronym.Text.Trim(); jobtype.Position = Convert.ToInt32(modalTxtBoxPosition.Text); jobtype.LastUpdateDate = DateTime.Now; jobtype.LastUpdatedBy = userid; //jobtype.DepartmentId = Convert.ToInt32(modalDropDownDepartment.SelectedItem.Value); if (modalChkBoxRequiredJobId.Checked == true) jobtype.RequiredJobId = true; else jobtype.RequiredJobId = false; if (modalChkBoxComputeTime.Checked == true) jobtype.ComputeTime = true; else jobtype.ComputeTime = false; if (modalChkBoxShowJobOverview.Checked == true) jobtype.ShowInJobOverview = true; else jobtype.ShowInJobOverview = false; if (e.CommandArgument.ToString() == "Add" && ischkBoxEmpty == false) { jobtype.CreateDate = DateTime.Now; jobtype.CreatedBy = userid; jobtype.Insert(jobtype); jobtype = jobtype.GetJobTypeByAcronym(modalTxtBoxAcronym.Text.Trim()); JobTypeDepartmentAction(jobtype.Id); this.programmaticModalPopup.Hide(); } else if (e.CommandArgument.ToString() == "Update" && ischkBoxEmpty == false) { jobtype.Update(jobtype); JobTypeDepartmentAction(jobtype.Id); this.programmaticModalPopup.Hide(); } else if (e.CommandArgument.ToString() == "Update" && ischkBoxEmpty == true) { JobTypeDepartmentAction(jobtype.Id); jobtype.Delete(jobtype.Id); this.programmaticModalPopup.Hide(); } InitializeGridViewJobType(); } }
protected void modalDropDownJobType_IndexChanged(object sender, EventArgs e) { JobType jobType = new JobType(); jobType.Id = Convert.ToInt32(modalDropDownJobType.SelectedItem.Value); jobType = jobType.GetJobType(jobType.Id); if (jobType != null) { modalReqJobId.Enabled = Convert.ToBoolean(jobType.RequiredJobId); //Set jobid validation depending on the JobType setup. modalReqJobStatus.Enabled = Convert.ToBoolean(jobType.ComputeTime); //If time is computed, require Job Status, otherwise do not require it. } //if (modalTxtBoxJobId.Enabled == false) //{ // modallabelCustomer.Text = ""; // modallabelBoxJobDescription.Text = ""; // modalTxtBoxJobId.Text = ""; // modalLabelError.Visible = false; // InitializeModalJobStatus(); //} this.programmaticModalPopup.Show(); }
private void RunBreakButtonActionForShifting() { int userid = Convert.ToInt32(Session["UserId"]); JobType jobtype = new JobType(); jobtype = jobtype.GetDefaultBreak(); DateTime selectedDate = DateTime.Parse(txtBoxDate.Text); JobTracker jobtracker = new JobTracker(); int jobtrackid = 0; bool noError = true; User user = new User(); user = user.GetUser(userid, selectedDate); TimeSpan cutOffTime = user.GetMyCutOfTime(); if (BtnBreak.Text == "Take a break") { DateTime startTime = new DateTime(); if (gridJobTrack.Rows.Count > 0) { jobtrackid = Convert.ToInt32(((Label)gridJobTrack.Rows[gridJobTrack.Rows.Count - 1].FindControl("labelJobTrackId")).Text); jobtracker = jobtracker.GetJobTracker(jobtrackid, false); JobType jtype = jobtype.GetJobType(Convert.ToInt32(jobtracker.JobTypeId)); if (Convert.ToDateTime(jobtracker.StartTime).TimeOfDay < cutOffTime && DateTime.Now.TimeOfDay >= cutOffTime) { if (jobtracker.EndTime == null) { noError = false; TimeSetting tsetting = new TimeSetting(); tsetting = tsetting.GetTimeSetting(); panelAlertHeader2.CssClass = "modalAlertHeader"; alertModalBtnOK2.CssClass = "buttonalert"; labelAlertHeader2.Text = "Error"; labelAlertMessage2.Text = "Please close all task first."; } else { GenerateStartHour(); GenerateStartMin(Convert.ToInt32(modalDropDownStartTimeHour.SelectedItem.Value)); startTime = DateTime.Parse(selectedDate.Year + "-" + selectedDate.Month + "-" + selectedDate.Day + " " + modalDropDownStartTimeHour.SelectedValue + ":" + modalDropDownStartTimeMin.SelectedValue + ":00"); } } else { if (jobtracker.EndTime == null) { DateTime stime = Convert.ToDateTime(jobtracker.StartTime); GenerateEndHour(stime.Hour, stime.Minute, true); GenerateEndMin(stime.Hour, stime.Minute, "--"); modalDropDownEndTimeHour.SelectedIndex = (modalDropDownEndTimeHour.Items.Count - 1); GenerateEndMin(stime.Hour, stime.Minute, modalDropDownEndTimeHour.SelectedItem.Text.Trim(), modalDropDownEndTimeMin.Items.Count == 0 ? "" : modalDropDownEndTimeHour.Items[modalDropDownEndTimeHour.Items.Count - 1].Text.Trim() + ":" + modalDropDownEndTimeMin.SelectedItem.Text.Trim()); if (modalDropDownEndTimeHour.Items[modalDropDownEndTimeHour.Items.Count - 1].Text != "--") { if (modalDropDownEndTimeHour.SelectedValue == "24") //end date selected is 12:00 AM next day { jobtracker.EndTime = DateTime.Parse((selectedDate.AddDays(1)).Year + "-" + (selectedDate.AddDays(1)).Month + "-" + (selectedDate.AddDays(1)).Day + " 00:00:00"); } else { jobtracker.EndTime = DateTime.Parse(selectedDate.Year + "-" + selectedDate.Month + "-" + selectedDate.Day + " " + modalDropDownEndTimeHour.Items[modalDropDownEndTimeHour.Items.Count - 1].Value + ":" + modalDropDownEndTimeMin.Items[modalDropDownEndTimeMin.Items.Count - 1].Value + ":00"); } jobtracker.Status = "Approved"; jobtracker.ApprovedBy = userid; jobtracker.ActionRequest = "Update"; jobtracker.Update(jobtracker); startTime = Convert.ToDateTime(jobtracker.EndTime); InitializeGrid(); } else { noError = false; TimeSetting tsetting = new TimeSetting(); tsetting = tsetting.GetTimeSetting(); panelAlertHeader2.CssClass = "modalAlertHeader"; alertModalBtnOK2.CssClass = "buttonalert"; labelAlertHeader2.Text = "Error"; labelAlertMessage2.Text = "Cannot take a break without spending at least " + tsetting + " minutes on the last task."; } } else { startTime = Convert.ToDateTime(jobtracker.EndTime); } } } else { GenerateStartHour(); GenerateStartMin(Convert.ToInt32(modalDropDownStartTimeHour.SelectedItem.Value)); startTime = DateTime.Parse(selectedDate.Year + "-" + selectedDate.Month + "-" + selectedDate.Day + " " + modalDropDownStartTimeHour.SelectedValue + ":" + modalDropDownStartTimeMin.SelectedValue + ":00"); } if (noError) { jobtracker = new JobTracker(); jobtracker.StartTime = startTime; jobtracker.Status = "Pending"; jobtracker.JobStatus = ""; jobtracker.ApprovedBy = userid; jobtracker.ActionRequest = "Add"; jobtracker.UserId = userid; jobtracker.CreateDate = DateTime.Now; jobtracker.CreatedBy = userid; jobtracker.LastUpdateDate = DateTime.Now; jobtracker.LastUpdatedBy = userid; jobtracker.Description = jobtype.Description; jobtracker.JobTypeId = jobtype.Id; jobtracker.ScheduleDate = selectedDate; jobtracker.Remarks = ""; jobtracker.Insert(jobtracker); InitializeGrid(); } else { programmaticAlertModalPopup2.Show(); } } else if (BtnBreak.Text == "End break") { jobtrackid = Convert.ToInt32(((Label)gridJobTrack.Rows[gridJobTrack.Rows.Count - 1].FindControl("labelJobTrackId")).Text); jobtracker = jobtracker.GetJobTracker(jobtrackid, false); jobtracker.LastUpdateDate = DateTime.Now; jobtracker.LastUpdatedBy = userid; if (jobtracker.JobTypeId == jobtype.Id) { DateTime stime = Convert.ToDateTime(jobtracker.StartTime); GenerateEndHour(stime.Hour, stime.Minute, true); GenerateEndMin(stime.Hour, stime.Minute, "--"); modalDropDownEndTimeHour.SelectedIndex = (modalDropDownEndTimeHour.Items.Count - 1); GenerateEndMin(stime.Hour, stime.Minute, modalDropDownEndTimeHour.SelectedItem.Text.Trim(), modalDropDownEndTimeMin.Items.Count == 0 ? "" : modalDropDownEndTimeHour.Items[modalDropDownEndTimeHour.Items.Count - 1].Text.Trim() + ":" + modalDropDownEndTimeMin.SelectedItem.Text.Trim()); if (modalDropDownEndTimeHour.Items[modalDropDownEndTimeHour.Items.Count - 1].Text != "--") { if (modalDropDownEndTimeHour.SelectedValue == "24") //end date selected is 12:00 AM next day { jobtracker.EndTime = DateTime.Parse((selectedDate.AddDays(1)).Year + "-" + (selectedDate.AddDays(1)).Month + "-" + (selectedDate.AddDays(1)).Day + " 00:00:00"); } else { jobtracker.EndTime = DateTime.Parse(selectedDate.Year + "-" + selectedDate.Month + "-" + selectedDate.Day + " " + modalDropDownEndTimeHour.Items[modalDropDownEndTimeHour.Items.Count - 1].Value + ":" + modalDropDownEndTimeMin.Items[modalDropDownEndTimeMin.Items.Count - 1].Value + ":00"); } jobtracker.Status = "Approved"; jobtracker.ApprovedBy = userid; jobtracker.ActionRequest = "Update"; jobtracker.Update(jobtracker); InitializeGrid(); } else//delete break if start time and end time are the same { jobtracker.Delete(jobtracker.Id); InitializeGrid(); } } if (gridJobTrack.Rows.Count > 1) // continue the last created job { for (int i = gridJobTrack.Rows.Count - 1; i >= 0; i--) { jobtrackid = Convert.ToInt32(((Label)gridJobTrack.Rows[i].FindControl("labelJobTrackId")).Text); JobTracker jtracker = jobtracker.GetJobTracker(jobtrackid, false); JobType jtype = jobtype.GetJobType(Convert.ToInt32(jtracker.JobTypeId)); if (jtype.ComputeTime == true) { jtracker.StartTime = jobtracker.EndTime; jtracker.UserId = userid; jtracker.CreateDate = DateTime.Now; jtracker.CreatedBy = userid; jtracker.LastUpdateDate = DateTime.Now; jtracker.LastUpdatedBy = userid; jtracker.EndTime = null; jtracker.ActionRequest = "Add"; jtracker.Status = "Approved"; if(Convert.ToDateTime(jobtracker.EndTime).TimeOfDay != new TimeSpan(0,0,0)) //only insert if endtime is not equal to 24:00 (next day) jtracker.Insert(jtracker); InitializeGrid(); break; } } } } }
protected void InitializeGrid() { int userid = Convert.ToInt32(Session["UserId"]); JobTracker jobTracker = new JobTracker(); List<JobTracker> data = new List<JobTracker>(); DateTime date = Convert.ToDateTime(txtBoxDate.Text); data = jobTracker.GetJobTrackerList(userid,date,true); //Converter model = new Converter(); //DataTable table = model.ConvertToDataTable(data); gridJobTrack.DataSource = data; gridJobTrack.DataBind(); Session["StartTime"] = null; GenerateStartHour(); if (modalDropDownStartTimeHour.Items.Count < 1) { linkBtnAddJobTrack.Visible = false; } else { linkBtnAddJobTrack.Visible = true; } if (date.CompareTo(DateTime.Today) == 0)//If doing job track on the current day, show take a break button { BtnBreak.Text = "Take a break"; BtnBreak.CssClass = "buttongreen"; BtnBreak.Visible = true; if (data.Count > 0) { JobType jobtype = new JobType(); jobtype = jobtype.GetJobType(Convert.ToInt32(data[data.Count - 1].JobTypeId)); if (jobtype.IsDefaultBreak == true && data[data.Count - 1].Status == "Pending") { BtnBreak.Text = "End break"; BtnBreak.CssClass = "buttonred"; } } } else { BtnBreak.Visible = false; } }
//protected void InitializeModal() //{ // JobType jobtype = new JobType(); // var data = jobtype.GetJobTypeList(Convert.ToInt32(Session["DepartmentId"])); // modalDropDownJobType.DataSource = data; // modalDropDownJobType.DataTextField = "Description"; // modalDropDownJobType.DataValueField = "Id"; // modalDropDownJobType.DataBind(); // Time time = new Time(); // var starttime = time.GetStartTimeList(); // modalDropDownStartTime.DataSource = starttime; // modalDropDownStartTime.DataTextField = "Description"; // modalDropDownStartTime.DataValueField = "C24hrConversion"; // modalDropDownStartTime.DataBind(); // bool hasSelected = false; // foreach (ListItem i in modalDropDownStartTime.Items) // { // TimeSpan selectedTime = TimeSpan.Parse(i.Value); // TimeSpan curtime = TimeSpan.Parse(DateTime.Now.Hour + ":" + DateTime.Now.Minute); // if (selectedTime >= curtime && hasSelected == false) // { // i.Selected = true; // hasSelected = true; // } // else // i.Selected = false; // } // var endtime = time.GetEndTimeList(modalDropDownStartTime.SelectedValue); // modalDropDownEndTime.DataSource = endtime; // modalDropDownEndTime.DataTextField = "Description"; // modalDropDownEndTime.DataValueField = "C24hrConversion"; // modalDropDownEndTime.DataBind(); //} private void InitializeModalJobType(string value = "") { JobTypeDepartment jobtypeDepartment = new JobTypeDepartment(); var data = jobtypeDepartment.GetJobTypeList(Convert.ToInt32(Session["DepartmentId"])); modalDropDownJobType.DataSource = data; modalDropDownJobType.DataTextField = "Description"; modalDropDownJobType.DataValueField = "Id"; modalDropDownJobType.DataBind(); if (value.Trim() != "") { foreach (ListItem i in modalDropDownJobType.Items) { if (i.Value.Trim() == value.Trim()) { i.Selected = true; //if (jobType != null) //{ // //modalTxtBoxJobId.Enabled = Convert.ToBoolean(jobType.RequiredJobId); // modalReqJobId.Enabled = Convert.ToBoolean(jobType.RequiredJobId); //} //if (modalTxtBoxJobId.Enabled == false) //{ // modallabelCustomer.Text = ""; // modallabelBoxJobDescription.Text = ""; // modalTxtBoxJobId.Text = ""; // modalLabelError.Visible = false; //} break; } } } int jobtypeId = Convert.ToInt32(modalDropDownJobType.SelectedValue); JobType jobType = new JobType(); jobType = jobType.GetJobType(jobtypeId); if (jobType != null) { modalReqJobId.Enabled = Convert.ToBoolean(jobType.RequiredJobId); modalReqJobStatus.Enabled = Convert.ToBoolean(jobType.ComputeTime); //If time is computed, require Job Status, otherwise do not require it. //modalDropDownJobStatus.Enabled = Convert.ToBoolean(jobType.RequiredJobId); } }