protected void InitializeModalGridView()
        {
            int userid = Convert.ToInt32(modalDropDownUsers.SelectedItem.Value);
            SupervisorMapping supmap = new SupervisorMapping();
            List<SupervisorMapping> supervisors = supmap.GetActiveSupervisors(userid);
            gridViewModal.DataSource = supervisors;
            gridViewModal.DataBind();

            for (int i = 0; i < gridViewModal.Rows.Count; i++)
            {
                CheckBox cb = (CheckBox)gridViewModal.Rows[i].FindControl("modalChkSupervisor");
                Label labelSupId = (Label)gridViewModal.Rows[i].FindControl("modalLabelSupId");
                //cb.Checked = true;
                labelSupId.ToolTip = supervisors[i].Id.ToString();
            }
            Session["SupMap"] = supervisors;
        }
        protected void gridViewJobTrack_Command(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                modalBtnDelete.Visible = true;
                DateTime date = Convert.ToDateTime(txtBoxDate.Text);
                int i = Convert.ToInt32(e.CommandArgument);
                int userid = Convert.ToInt32(Session["UserId"]);
                int jobtrackerId = Convert.ToInt32(((Label)gridJobTrack.Rows[i].FindControl("labelJobTrackId")).Text);
                bool noError = true;
                if (date.CompareTo(DateTime.Today) < 0)
                {
                    SupervisorMapping supmap = new SupervisorMapping();
                    if (supmap.GetActiveSupervisors(userid).Count < 1)
                    {
                        noError = false;
                        panelAlertHeader2.CssClass = "modalAlertHeader";
                        alertModalBtnOK2.CssClass = "buttonalert";
                        labelAlertHeader2.Text = "Error";
                        labelAlertMessage2.Text = "Sorry you cannot edit job on previous date without a direct supervisor. Please contact your system administrator.";
                        programmaticAlertModalPopup2.Show();
                    }
                }
                else
                {
                    JobTracker jobtracker = new JobTracker();
                    string errMsg = "";
                    errMsg = jobtracker.GetError(userid, date, 7);
                    if (errMsg.Trim() != "")
                    {
                        noError = false;
                        panelAlertHeader2.CssClass = "modalAlertHeader";
                        alertModalBtnOK2.CssClass = "buttonalert";
                        labelAlertHeader2.Text = "Error";
                        labelAlertMessage2.Text = errMsg.Trim() + " Please settle error first.";
                        programmaticAlertModalPopup2.Show();
                    }
                }
                if(noError)
                {
                    JobTracker jobtracker = new JobTracker();
                    jobtracker = jobtracker.GetJobTracker(jobtrackerId,false);
                    //List<JobTracker> datalist = new List<JobTracker>();
                    //datalist = jobtracker.GetJobTrackerList(userid, date);
                    modalLabelError.Text = "";
                    modalLabelError.Visible = false;
                    modalBtnSubmit.CommandArgument = jobtracker.Id.ToString();
                    modalBtnDelete.CommandArgument = jobtracker.Id.ToString();

                    InitializeModalJobType(jobtracker.JobTypeId.ToString());
                    //InitializeModalStartTime(jobtracker.StartTime.ToString());
                    InitializeModalJobStatus(jobtracker.JobStatus == null ? "" : jobtracker.JobStatus.Trim());

                    bool generateBlank = false;
                    if (date.CompareTo(DateTime.Today) == 0)
                        generateBlank = true;

                    Session["StartTime"] = Convert.ToDateTime(jobtracker.StartTime).TimeOfDay.ToString();
                    GenerateStartHour(Convert.ToDateTime(jobtracker.StartTime).TimeOfDay.ToString());
                    GenerateStartMin(Convert.ToInt32(modalDropDownStartTimeHour.SelectedItem.Value), Convert.ToDateTime(jobtracker.StartTime).TimeOfDay.ToString());

                    string endtime = "";
                    if (jobtracker.EndTime != null)
                        endtime = jobtracker.EndTime.ToString();
                    //InitializeModalEndTime(endtime);

                    GenerateEndHour(Convert.ToInt32(modalDropDownStartTimeHour.SelectedItem.Value), Convert.ToInt32(modalDropDownStartTimeMin.SelectedItem.Value), generateBlank, endtime == "" ? "" : Convert.ToDateTime(jobtracker.EndTime).ToString());
                    GenerateEndMin(Convert.ToInt32(modalDropDownStartTimeHour.SelectedItem.Value), Convert.ToInt32(modalDropDownStartTimeMin.SelectedItem.Value), modalDropDownEndTimeHour.SelectedItem.Text.Trim(), endtime == "" ? "" : Convert.ToDateTime(jobtracker.EndTime).TimeOfDay.ToString());
                    //if (datalist[i].ApprovedBy != null && datalist[i].ApprovedBy != userid && datalist[i].ApprovedBy != 0)
                    //{
                    //    //InitializeModalSupervisor(datalist[i].ApprovedBy.ToString());
                    //    //modalLabelSupervisor.Visible = true;
                    //    //modalLabelSupColon.Visible = true;
                    //    //modalDropDownSupervisor.Visible = true;
                    //}
                    //else if (date.CompareTo(DateTime.Today) < 0)
                    //{
                    //InitializeModalSupervisor();
                    //modalLabelSupervisor.Visible = true;
                    //modalLabelSupColon.Visible = true;
                    //modalDropDownSupervisor.Visible = true;
                    //}
                    //else
                    //{
                    //    //modalLabelSupervisor.Visible = false;
                    //    //modalLabelSupColon.Visible = false;
                    //    //modalDropDownSupervisor.Visible = false;
                    //}
                    if (jobtracker.JobIdNumber != null && jobtracker.JobIdNumber.Trim() != "")
                    {

                        modalTxtBoxJobId.Text = jobtracker.JobIdNumber;
                        JobTracker jobTracker = new JobTracker();
                        jobTracker = jobTracker.GenerateHWAndSW(modalTxtBoxJobId.Text.Trim());
                        modallabelBoxJobDescription.Text = jobTracker.Description;
                        modallabelCustomer.Text = jobTracker.Customer;
                        modalLabelHWSW.Text = jobTracker.HWNo;
                        modalLabelHWSW.ToolTip = jobTracker.SWNo;
                        modalLabelEvalNo.Text = jobTracker.EvalNo;
                    }

                    modalTxtBoxRemarks.Text = jobtracker.Remarks == null ? "" : jobtracker.Remarks.Trim();

                    Page.Validate();
                    this.programmaticModalPopup.Show();
                }
            }
        }
Пример #3
0
        //Get all available users that is not yet selected as a supervisor by a specific user
        public List<User> GetAvailableSupervisors(int userid,int departmentId)
        {
            TimeTrackerEntities db = new TimeTrackerEntities();

            SupervisorMapping supmap = new SupervisorMapping();
            var data = (from u in db.T_Users
                        where u.DepartmentId == departmentId
                        && u.Status == "Active"
                        select new User()
                        {
                            Id = u.Id,
                            Username = u.Username,
                            Password = u.Password,
                            Firstname = u.Firstname,
                            Lastname = u.Lastname,
                            Phone = u.Phone,
                            Mobile = u.Mobile,
                            Fax = u.Fax,
                            Email = u.Email,
                            DepartmentId = u.DepartmentId,
                            RoleId = u.RoleId,
                            CreateDate = u.CreateDate,
                            CreatedBy = u.CreatedBy,
                            LastUpdateDate = u.LastUpdateDate,
                            LastUpdatedBy = u.LastUpdatedBy,
                            Status = u.Status,
                            fullname = u.Firstname + " " + u.Lastname,
                            role = u.M_Role.Description,
                            department = u.M_Department.Description,
                            EmployeeNumber = u.EmployeeNumber,
                            currentSalary = 0,
                            currentOffDay = 0,
                            currentSpecialOffDay = 0,
                            currentOptOffDay1 = 0,
                            currentOptOffDay2 = 0,
                            currentOptOffDay3 = 0,
                            currentOptOffDay4 = 0,
                            noOTpay = false,
                            startTime = "",
                            endTime = "",
                            shifting = false,
                            currentRateStartDate = DateTime.Today,
                            currentRateCreateDate = DateTime.Today
                        }).ToList();
            db.Dispose();

            var suplist = supmap.GetActiveSupervisors(userid, departmentId);

            foreach (SupervisorMapping s in suplist)
            {
                for (int i = 0; i < data.Count; i++)
                {
                    if (data[i].Id == s.SupervisorId)
                    {
                        data.RemoveAt(i);
                        break;
                    }
                }
            }

            return data;
        }
        //Action triggered when the users click the add job track button
        protected void linkBtnAddJobTrack_Click(object sender, EventArgs e)
        {
            Session["StartTime"] = null;
            JobTracker jobtracker = new JobTracker();
            DateTime selectedDate = DateTime.Parse(txtBoxDate.Text);
            int userid = Convert.ToInt32(Session["UserId"]);
            bool noError = true;

            if (jobtracker.HasUnclosedJobs(userid)) //check if user has unclosed jobs
            {
                noError = false;
                panelAlertHeader2.CssClass = "modalAlertHeader";
                alertModalBtnOK2.CssClass = "buttonalert";
                labelAlertHeader2.Text = "Error";
                labelAlertMessage2.Text = "Please close all jobs before adding a new one.";
                programmaticAlertModalPopup2.Show();
            }
            if (selectedDate.CompareTo(DateTime.Today) < 0)
            {
                SupervisorMapping supmap = new SupervisorMapping();
                if (supmap.GetActiveSupervisors(userid).Count < 1)
                {
                    noError = false;
                    panelAlertHeader2.CssClass = "modalAlertHeader";
                    alertModalBtnOK2.CssClass = "buttonalert";
                    labelAlertHeader2.Text = "Error";
                    labelAlertMessage2.Text = "Sorry you cannot add job on previous date without a direct supervisor. Please contact your system administrator.";
                    programmaticAlertModalPopup2.Show();
                }
            }
            else
            {
                string errMsg = "";
                errMsg = jobtracker.GetError(userid, selectedDate, 30); //check if there is an error
                if (errMsg.Trim() != "")
                {
                    noError = false;
                    panelAlertHeader2.CssClass = "modalAlertHeader";
                    alertModalBtnOK2.CssClass = "buttonalert";
                    labelAlertHeader2.Text = "Error";
                    labelAlertMessage2.Text = errMsg.Trim() + " Please settle error first.";
                    programmaticAlertModalPopup2.Show();
                }
            }
            if(noError)
            {
                InitializeModalJobType();
                //InitializeModalStartTime();
                //InitializeModalEndTime();
                InitializeModalJobStatus();

                bool generateBlank = false;
                if (selectedDate.CompareTo(DateTime.Today) == 0)
                    generateBlank = true;
                GenerateStartHour();
                GenerateStartMin(Convert.ToInt32(modalDropDownStartTimeHour.SelectedItem.Value));
                GenerateEndHour(Convert.ToInt32(modalDropDownStartTimeHour.SelectedItem.Value), Convert.ToInt32(modalDropDownStartTimeMin.SelectedItem.Value), generateBlank);
                GenerateEndMin(Convert.ToInt32(modalDropDownStartTimeHour.SelectedItem.Value), Convert.ToInt32(modalDropDownStartTimeMin.SelectedItem.Value), modalDropDownEndTimeHour.SelectedItem.Text.Trim());

                modalBtnSubmit.CommandArgument = "Add";

                modalBtnDelete.Visible = false;
                modalTxtBoxRemarks.Text = "";
                modalLabelError.Text = "";
                modalLabelError.Visible = false;
                modallabelBoxJobDescription.Text = "";
                modallabelCustomer.Text = "";
                modalTxtBoxJobId.Text = "";
                modalLabelHWSW.Text = "";
                modalLabelHWSW.ToolTip = "";
                modalLabelEvalNo.Text = "";
                //modalTxtBoxJobId.Enabled = false;
                Page.Validate();

                this.programmaticModalPopup.Show();
            }
        }