public JobTrackerHistory ConvertToHistory(JobTracker jobtracker)
        {
            JobTrackerHistory jthist = new JobTrackerHistory();
            jthist.JobTrackerId = jobtracker.Id;
            jthist.JobIdNumber = jobtracker.JobIdNumber;
            jthist.JobTypeId = jobtracker.JobTypeId;
            jthist.Remarks = jobtracker.Remarks;
            jthist.Description = jobtracker.Description;
            jthist.StartTime = jobtracker.StartTime;
            jthist.EndTime = jobtracker.EndTime;
            jthist.ApprovedBy = jobtracker.ApprovedBy;
            jthist.CreatedBy = jobtracker.CreatedBy;
            jthist.LastUpdateDate = jobtracker.LastUpdateDate;
            jthist.LastUpdatedBy = jobtracker.LastUpdatedBy;
            jthist.CreateDate = jobtracker.CreateDate;
            jthist.Status = jobtracker.Status;
            jthist.SupervisorRemarks = jobtracker.SupervisorRemarks;
            jthist.UserId = jobtracker.UserId;
            jthist.ScheduleDate = jobtracker.ScheduleDate;
            jthist.Action = jobtracker.ActionRequest;
            jthist.JobStatus = jobtracker.JobStatus;
            jthist.HWNo = jobtracker.HWNo;
            jthist.SWNo = jobtracker.SWNo;
            jthist.Customer = jobtracker.Customer;
            jthist.EvalNo = jobtracker.EvalNo;

            return jthist;
        }
        protected void gridLeftBtnAcceptAll_Click(object sender, EventArgs e)
        {
            foreach (GridViewRow row in gridViewLeftPanel1.Rows)
            {
                CheckBox cb = (CheckBox)row.FindControl("gridLeftChkBoxSelect");
                if (cb.Checked)
                {
                    int userid = Convert.ToInt32(Session["UserId"]);
                    JobTracker jobtracker = new JobTracker();
                    JobTrackerHistory jtHist = new JobTrackerHistory();
                    //var data = jobtracker.GetRequestNeededApproval(userid);
                    Label jobtrackId = (Label)row.FindControl("gridLeftlblJobTrackId");
                    jobtracker = jobtracker.GetJobTracker(Convert.ToInt32(jobtrackId.Text), false);

                    if (jobtracker.ActionRequest == "Delete")
                    {
                        jobtracker.Status = "Approved";
                        jtHist = jtHist.ConvertToHistory(jobtracker);
                        jobtracker.Delete(jobtracker.Id);
                    }
                    else
                    {
                        jobtracker.Status = "Approved";
                        jobtracker.Update(jobtracker);
                        jtHist = jtHist.ConvertToHistory(jobtracker);
                    }
                    jtHist.Insert(jtHist);
                }
            }
            gridLeftChkBoxSelectAll.Checked = false;
            InitializeGridViewLeftPanel1(new List<string>());
            InitializeGridViewLeftPanel2();
            InitializeGridViewLeftPanel3();
        }
 public void Insert(JobTrackerHistory jtHist)
 {
     T_JobTrackerHistory j = new T_JobTrackerHistory();
     ParseJobTracker(j, jtHist);
     using (TimeTrackerEntities db = new TimeTrackerEntities())
     {
         try
         {
             db.T_JobTrackerHistory.Add(j);
             db.SaveChanges();
         }
         catch (Exception ex)
         {
             string msg = ex.Message;
         }
     }
 }
        protected void modalBtnConfirm_Command(object sender, CommandEventArgs e)
        {
            string[] remarks = modalTxtBoxRemarks.Text.Replace("\n"," ").Trim().Split(' ');
            int counter = 0;
            Regex rgx = new Regex("[^a-zA-Z0-9]");
            for (int i = 0; i < remarks.Length; i++)
            {
                if (rgx.Replace(remarks[i],"").Trim() != "")
                {
                    counter++;
                }
            }
            if (counter > 2)
            {
                int userid = Convert.ToInt32(Session["UserId"]);
                if (e.CommandName == "RejectAll")
                {
                    foreach (GridViewRow row in gridViewLeftPanel1.Rows)
                    {
                        CheckBox cb = (CheckBox)row.FindControl("gridLeftChkBoxSelect");
                        if (cb.Checked)
                        {
                            JobTracker jobtracker = new JobTracker();
                            JobTrackerHistory jtHist = new JobTrackerHistory();
                            Label jobtrackId = (Label)row.FindControl("gridLeftlblJobTrackId");
                            jobtracker = jobtracker.GetJobTracker(Convert.ToInt32(jobtrackId.Text), false);
                            jobtracker.ApprovedBy = userid;
                            jobtracker.LastUpdatedBy = userid;
                            jobtracker.LastUpdateDate = DateTime.Now;
                            jobtracker.SupervisorRemarks = modalTxtBoxRemarks.Text;
                            jobtracker.Status = "Rejected";
                            jobtracker.Update(jobtracker);
                            jtHist = jtHist.ConvertToHistory(jobtracker);
                            jtHist.Insert(jtHist);
                        }
                    }
                    gridLeftChkBoxSelectAll.Checked = false;
                    InitializeGridViewLeftPanel1(new List<string>());
                }
                else
                {
                    JobTracker jobtracker = new JobTracker();
                    JobTrackerHistory jtHist = new JobTrackerHistory();
                    int id = Convert.ToInt32(e.CommandArgument);
                    jobtracker = jobtracker.GetJobTracker(id, false);
                    jobtracker.ApprovedBy = userid;
                    jobtracker.LastUpdatedBy = userid;
                    jobtracker.LastUpdateDate = DateTime.Now;
                    jobtracker.SupervisorRemarks = modalTxtBoxRemarks.Text;
                    jobtracker.Status = "Rejected";
                    jobtracker.Update(jobtracker);

                    jtHist = jtHist.ConvertToHistory(jobtracker);
                    jtHist.Insert(jtHist);
                    List<string> selectedJobtrackerId = GetGridViewLeftPanel1SelectedJobIds();
                    InitializeGridViewLeftPanel1(selectedJobtrackerId);
                }
                InitializeGridViewLeftPanel2();
                InitializeGridViewLeftPanel3();
            }
            else
            {
                modalBottomLabelError.Text = "Minimum Three(3) Words";
                modalBottomLabelError.Visible = true;
                programmaticModalPopup.Show();
            }
        }
 protected void gridViewLeftPanel1_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     int userid = Convert.ToInt32(Session["UserId"]);
     int index = Convert.ToInt32(e.CommandArgument);
     JobTracker jobtracker = new JobTracker();
     JobTrackerHistory jtHist = new JobTrackerHistory();
     //var data = jobtracker.GetRequestNeededApproval(userid);
     Label jobtrackId = (Label)gridViewLeftPanel1.Rows[index].FindControl("gridLeftlblJobTrackId");
     jobtracker = jobtracker.GetJobTracker(Convert.ToInt32(jobtrackId.Text),false);
     //data[index].LastUpdateDate = DateTime.Now;
     //data[index].LastUpdatedBy = userid;
     jobtracker.ApprovedBy = userid;
     jobtracker.LastUpdateDate = DateTime.Now;
     jobtracker.LastUpdatedBy = userid;
     if(e.CommandName == "AcceptRequest")
     {
         if (jobtracker.ActionRequest == "Delete")
         {
             jobtracker.Status = "Approved";
             jtHist = jtHist.ConvertToHistory(jobtracker);
             jobtracker.Delete(jobtracker.Id);
         }
         else
         {
             jobtracker.Status = "Approved";
             jobtracker.Update(jobtracker);
             jtHist = jtHist.ConvertToHistory(jobtracker);
         }
         jtHist.Insert(jtHist);
         List<string> selectedJobtrackerId = GetGridViewLeftPanel1SelectedJobIds();
         InitializeGridViewLeftPanel1(selectedJobtrackerId);
         InitializeGridViewLeftPanel2();
         InitializeGridViewLeftPanel3();
     }
     else if (e.CommandName == "RejectRequest")
     {
         //data[index].Status = "Rejected";
         modalBottomLabelError.Visible = false;
         modalBottomLabelError.Text = "";
         modalBtnConfirm.CommandArgument = jobtracker.Id.ToString();
         modalBtnConfirm.CommandName = "Reject";
         modalTxtBoxRemarks.Text = "";
         programmaticModalPopup.Show();
         //jobtracker.Update(data[index]);
         //InitializeGridViewLeft();
     }
 }
        protected void modalBtnSubmit_Command(object sender, CommandEventArgs e)
        {
            bool haserror = false;
            string errormessage = "";

            if (modalLabelError.Visible == true)
            {
                errormessage = modalLabelError.Text;
                haserror = true;
            }
            else if (modalReqJobStatus.Enabled == true && modalDropDownJobStatus.SelectedItem.Value == "Completed" && modalDropDownEndTimeHour.SelectedItem.Text == "--")
            {
                errormessage = "Cannot set job status as Completed without selecting End Time.";
                haserror = true;
            }

            if (haserror)
            {
                //System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('Error: "+errormessage+"')</SCRIPT>");
                panelAlertHeader2.CssClass = "modalAlertHeader";
                alertModalBtnOK2.CssClass = "buttonalert";
                labelAlertHeader2.Text = "Error";
                labelAlertMessage2.Text = errormessage;
                this.programmaticModalPopup.Show();
                programmaticAlertModalPopup2.Show();

            }
            else
            {
                DateTime selectedDate = DateTime.Parse(txtBoxDate.Text);
                int userid = Convert.ToInt32(Session["UserId"]);
                JobTracker jobTracker = new JobTracker();
                JobTrackerHistory jtHist = new JobTrackerHistory();
                //DateTime startTime = DateTime.Parse(selectedDate.Year + "-" + selectedDate.Month + "-" + selectedDate.Day + " " + modalDropDownStartTime.SelectedValue + ":00");
                DateTime startTime = DateTime.Parse(selectedDate.Year + "-" + selectedDate.Month + "-" + selectedDate.Day + " " + modalDropDownStartTimeHour.SelectedValue+":"+modalDropDownStartTimeMin.SelectedValue + ":00");
                //DateTime endTime = DateTime.Parse(selectedDate.Year + "-" + selectedDate.Month + "-" + selectedDate.Day + " " + modalDropDownEndTime.SelectedValue + ":00");
                DateTime endTime;
                if (modalDropDownEndTimeHour.SelectedValue == "24") //end date selected is 12:00 AM next day
                {
                    endTime = DateTime.Parse((selectedDate.AddDays(1)).Year + "-" + (selectedDate.AddDays(1)).Month + "-" + (selectedDate.AddDays(1)).Day + " 00:00:00");
                }
                else
                {
                    endTime = DateTime.Parse(selectedDate.Year + "-" + selectedDate.Month + "-" + selectedDate.Day + " " + modalDropDownEndTimeHour.SelectedValue + ":" + modalDropDownEndTimeMin.SelectedValue + ":00");
                }
                jobTracker.StartTime = startTime;
                jobTracker.ScheduleDate = selectedDate;
                //if (modalDropDownEndTime.SelectedItem.Text != "Select End Time")
                if (modalDropDownEndTimeHour.SelectedItem.Text != "--")
                {
                    jobTracker.EndTime = endTime;
                }
                jobTracker.JobTypeId = Convert.ToInt32(modalDropDownJobType.SelectedValue);
                jobTracker.JobIdNumber = modalTxtBoxJobId.Text.Trim();
                jobTracker.Remarks = modalTxtBoxRemarks.Text.Trim();
                jobTracker.LastUpdateDate = DateTime.Now;
                jobTracker.LastUpdatedBy = userid;
                jobTracker.UserId = userid;
                jobTracker.HWNo = modalLabelHWSW.Text;
                jobTracker.SWNo = modalLabelHWSW.ToolTip;
                jobTracker.Customer = modallabelCustomer.Text;
                jobTracker.EvalNo = modalLabelEvalNo.Text;
                jobTracker.Description = modallabelBoxJobDescription.Text;
                //if (jobTracker.JobIdNumber.Trim() != "")
                jobTracker.JobStatus = modalDropDownJobStatus.SelectedItem.Value;
                if (modalReqJobStatus.Enabled == false) // Put blank on task that does not require job status.
                    jobTracker.JobStatus = "";

                if (selectedDate.CompareTo(DateTime.Today) == 0)
                {
                    jobTracker.ApprovedBy = userid;
                    //if (modalDropDownEndTime.SelectedItem.Text != "Select End Time")
                    if (modalDropDownEndTimeHour.SelectedItem.Text != "--")
                        jobTracker.Status = "Approved";
                    else
                        jobTracker.Status = "Pending";
                }
                else
                {
                    jobTracker.Status = "For Approval";
                }

                if (e.CommandArgument.ToString() == "Add")
                {
                    if (selectedDate.CompareTo(DateTime.Today) != 0)
                    {
                        if ((DateTime.Now.Subtract(startTime)).TotalHours < 24)
                        {
                            jobTracker.Status = "Approved";
                            jobTracker.ApprovedBy = userid;
                        }
                    }
                    jobTracker.CreateDate = DateTime.Now;
                    jobTracker.SupervisorRemarks = "";
                    jobTracker.CreatedBy = userid;
                    jobTracker.ActionRequest = "Add";
                    jobTracker.Insert(jobTracker);
                    jobTracker = jobTracker.GetJobTracker(Convert.ToInt32(jobTracker.CreatedBy), Convert.ToInt32(jobTracker.LastUpdatedBy), Convert.ToDateTime(jobTracker.StartTime), Convert.ToInt32(jobTracker.JobTypeId), jobTracker.ActionRequest, jobTracker.Status,false);
                }
                else
                {
                    if (selectedDate.CompareTo(DateTime.Today) != 0)
                    {
                        if ((DateTime.Now.Subtract(startTime)).TotalHours < 2)
                        {
                            jobTracker.Status = "Approved";
                            jobTracker.ApprovedBy = userid;
                        }
                    }
                    jobTracker.Id = Convert.ToInt32(e.CommandArgument);
                    jobTracker.ActionRequest = "Update";
                    jobTracker.Update(jobTracker);
                }
                //jobTracker.CreateDate = DateTime.Now;
                jtHist = jtHist.ConvertToHistory(jobTracker);
                jtHist.Insert(jtHist);
                InitializeWorkingHours();
                InitializeGrid();
                this.programmaticModalPopup.Hide();
            }
        }
 protected void modalBtnDelete_Command(object sender, CommandEventArgs e)
 {
     DateTime selectedDate = DateTime.Parse(txtBoxDate.Text);
     int userid = Convert.ToInt32(Session["UserId"]);
     JobTracker jobTracker = new JobTracker();
     JobTrackerHistory jtHist = new JobTrackerHistory();
     jobTracker.Id = Convert.ToInt32(e.CommandArgument);
     jobTracker = jobTracker.GetJobTracker(jobTracker.Id,false);
     if (selectedDate.CompareTo(DateTime.Today) == 0 || (jobTracker.Status == "Rejected" && jobTracker.ActionRequest != "Delete"))
     {
         jobTracker.ActionRequest = "Delete";
         jobTracker.Status = "Approved";
         jobTracker.LastUpdateDate = DateTime.Now;
         jobTracker.LastUpdatedBy = userid;
         jtHist = jtHist.ConvertToHistory(jobTracker);
         jobTracker.Delete(jobTracker.Id);
     }
     else
     {
         jobTracker.ActionRequest = "Delete";
         jobTracker.Status = "For Approval";
         jobTracker.LastUpdateDate = DateTime.Now;
         jobTracker.LastUpdatedBy = userid;
         jobTracker.Update(jobTracker);
         jtHist = jtHist.ConvertToHistory(jobTracker);
     }
     jtHist.Insert(jtHist);
     InitializeWorkingHours();
     InitializeGrid();
 }
 public void Update(JobTrackerHistory jthist)
 {
     using (TimeTrackerEntities db = new TimeTrackerEntities())
     {
         try
         {
             T_JobTrackerHistory t_jthist= db.T_JobTrackerHistory.FirstOrDefault(j => j.Id == jthist.Id);
             UpdateParse(t_jthist, jthist);
             db.SaveChanges();
         }
         catch (Exception ex)
         {
             string msg = ex.Message;
         }
     }
 }
 private void UpdateParse(T_JobTrackerHistory t_jthist, JobTrackerHistory jthist)
 {
     t_jthist.JobIdNumber = jthist.JobIdNumber;
     t_jthist.JobTrackerId = jthist.JobTrackerId;
     t_jthist.JobTypeId = jthist.JobTypeId;
     t_jthist.Remarks = jthist.Remarks;
     t_jthist.Description = jthist.Description;
     t_jthist.StartTime = jthist.StartTime;
     t_jthist.EndTime = jthist.EndTime;
     t_jthist.ApprovedBy = jthist.ApprovedBy;
     t_jthist.LastUpdateDate = jthist.LastUpdateDate;
     t_jthist.LastUpdatedBy = jthist.LastUpdatedBy;
     t_jthist.Status = jthist.Status;
     t_jthist.SupervisorRemarks = jthist.SupervisorRemarks;
     t_jthist.UserId = jthist.UserId;
     t_jthist.ScheduleDate = jthist.ScheduleDate;
     t_jthist.Action = jthist.Action;
     t_jthist.JobStatus = jthist.JobStatus;
     t_jthist.HWNo = jthist.HWNo;
     t_jthist.SWNo = jthist.SWNo;
     t_jthist.Customer = jthist.Customer;
     t_jthist.EvalNo = jthist.EvalNo;
 }
 private void ParseJobTracker(T_JobTrackerHistory data, JobTrackerHistory jtHist)
 {
     data.Id = jtHist.Id;
     data.JobTrackerId = jtHist.JobTrackerId;
     data.JobIdNumber = jtHist.JobIdNumber;
     data.JobTypeId = jtHist.JobTypeId;
     data.Remarks = jtHist.Remarks;
     data.Description = jtHist.Description;
     data.StartTime = jtHist.StartTime;
     data.EndTime = jtHist.EndTime;
     data.ApprovedBy = jtHist.ApprovedBy;
     data.CreatedBy = jtHist.CreatedBy;
     data.LastUpdateDate = jtHist.LastUpdateDate;
     data.LastUpdatedBy = jtHist.LastUpdatedBy;
     data.CreateDate = jtHist.CreateDate;
     data.Status = jtHist.Status;
     data.SupervisorRemarks = jtHist.SupervisorRemarks;
     data.UserId = jtHist.UserId;
     data.ScheduleDate = jtHist.ScheduleDate;
     data.Action = jtHist.Action;
     data.JobStatus = jtHist.JobStatus;
     data.HWNo = jtHist.HWNo;
     data.SWNo = jtHist.SWNo;
     data.Customer = jtHist.Customer;
     data.EvalNo = jtHist.EvalNo;
 }