Ejemplo n.º 1
0
 /// <summary>
 /// ValidateExistPayPeriod
 /// </summary>
 /// <param name="date">date</param>
 public static bool ValidateExistPayPeriod(DateTime date)
 {
     PayPeriodGateway payPeriodGateway = new PayPeriodGateway();
     payPeriodGateway.LoadByDate(date.Year, date.Month, date.Day);
     if (payPeriodGateway.Table.Rows.Count > 0)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
        protected int SaveSelectedId()
        {
            int numOfProjectTimesSelected = 0;
            int idForUpdate = 0;
            int employeeIdForUpdate = 0;
            bool selected = false;
            hdfSelectedProjectTimeId.Value = "0";

            ProjectTimeApprove projectTimeApprove = new ProjectTimeApprove(projectTimeApproveTDS);

            foreach (GridViewRow row in grdProjectTimeApprove.Rows)
            {
                // ... Update all rows
                selected = ((CheckBox)row.FindControl("cbxSelected")).Checked;
                idForUpdate = Int32.Parse(((Label)row.FindControl("lblProjectTimeID")).Text.Trim());
                employeeIdForUpdate = Int32.Parse(((Label)row.FindControl("lblEmployeeID")).Text.Trim());

                projectTimeApprove.Update(idForUpdate, selected);

                // ... Save selected id
                if (selected)
                {
                    hdfSelectedProjectTimeId.Value = idForUpdate.ToString();
                    hdfSelectedEmployeeId.Value = employeeIdForUpdate.ToString();
                    DateTime date_ = DateTime.Parse(((Label)row.FindControl("lblDate")).Text.Trim());

                    PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
                    hdfSelectedPeriodId.Value = payPeriodGateway.GetPayPeriodId(date_).ToString();

                    numOfProjectTimesSelected++;

                    Session["projectTimeIdSelected"] = row.RowIndex;
                }
            }

            projectTimeApprove.Data.AcceptChanges();

            // ... Store datasets
            Session["projectTimeApproveTDS"] = projectTimeApproveTDS;
            Session["projectTimeApprove"] = projectTimeApproveTDS.ProjectTimeApprove;

            return numOfProjectTimesSelected;
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Validate query string
                if ((string)Request.QueryString["source_page"] == null)
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in timesheet_approve.aspx");
                }

                // Security check
                EmployeeGateway employeeGateway1 = new EmployeeGateway(new DataSet());
                int employeeId = employeeGateway1.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));
                hdfCurrentEmployeeId.Value = employeeGateway1.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"])).ToString();
                employeeGateway1.LoadByEmployeeId(employeeId);

                if (!employeeGateway1.GetApproveTimesheets(employeeId))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                }

                // Tag page
                Session.Remove("projectTimeApproveDummy");

                // Initialize  variables
                lblError.Visible = false;

                // ... Initialize viewstate variables
                System.Configuration.AppSettingsReader appSettingReader = new System.Configuration.AppSettingsReader();
                ViewState["LHMode"] = appSettingReader.GetValue("LABOUR_HOURS_OPERATION_MODE", typeof(System.String)).ToString();

                // Labour Hours Mode check
                if ((string)ViewState["LHMode"] == "Partial")
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "The system is on partial mode. Contact your system administrator.");
                }

                ViewState["others"] = Request.QueryString["others"];

                PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
                ViewState["period_id"] = payPeriodGateway.GetPayPeriodId(DateTime.Now);

                // Load data
                // ... Loading employees accordingly to the admins country.
                EmployeeList employeeList = new EmployeeList(new DataSet());
                string employeeType = employeeGateway1.GetType(employeeId);
                odsClient.SelectParameters.RemoveAt(2);
                if (employeeType.Contains("CA"))
                {
                    employeeList.LoadByRequestProjectTimeEmployeeTypeEmployeeIdApproveManagerAndAddItem(1, "CA", -1, "(All)", employeeId);

                    odsClient.SelectParameters.Add("countryId", "1");
                }
                else
                {
                    if (employeeType.Contains("US"))
                    {
                        employeeList.LoadByRequestProjectTimeEmployeeTypeEmployeeIdApproveManagerAndAddItem(1, "US", -1, "(All)", employeeId);

                        odsClient.SelectParameters.Add("countryId", "2");
                    }
                    else
                    {
                        employeeList.LoadByRequestProjectTimeEmployeeTypeEmployeeIdApproveManagerAndAddItem(1, "SOTA", -1, "(All)", employeeId);

                        odsClient.SelectParameters.Add("countryId", "-1");
                    }
                }

                odsClient.Select();
                ddlClient.SelectedIndex = 0;
                upnlClient.Update();

                ddlTeamMember.DataSource = employeeList.Table;
                ddlTeamMember.DataValueField = "EmployeeID";
                ddlTeamMember.DataTextField = "FullName";
                ddlTeamMember.DataBind();

                odsProject.SelectParameters.RemoveAt(2);
                odsProject.SelectParameters.Add("clientId", "-1");
                odsProject.Select();
                ddlProject.DataBind();
                ddlProject.SelectedIndex = 0;
                upnlProject.Update();

                projectTimeApproveTDS = this.SubmitSearch();

                // Store Datasets
                Session["projectTimeApproveTDS"] = projectTimeApproveTDS;
                projectTimeApprove = projectTimeApproveTDS.ProjectTimeApprove;
                Session["projectTimeApprove"] = projectTimeApproveTDS.ProjectTimeApprove;

                // If coming from
                // ... timesheet_edit.aspx, timesheet_summary.aspx or timesheet_delete.aspx
                if ((Request.QueryString["source_page"] == "timesheet_edit.aspx") || (Request.QueryString["source_page"] == "timesheet_summary.aspx") || (Request.QueryString["source_page"] == "timesheet_delete.aspx"))
                {
                    // ... restore top values
                    RestoreNavigatorState();

                    // ... filter grid information
                    //SetFilterByCountryIdClientIdProjectId();
                    //SetFilterByEmployeeIdDate();
                    SetFilterByClientIdProjectIdEmployeeIdDate();
                }

                ViewState["filter_expression"] = "Deleted = 0";

                SetFocus();
            }
            else
            {
                // Restore dataset
                projectTimeApproveTDS = (ProjectTimeApproveTDS)Session["projectTimeApproveTDS"];
                projectTimeApprove = projectTimeApproveTDS.ProjectTimeApprove;
                Session["projectTimeApprove"] = projectTimeApproveTDS.ProjectTimeApprove;
            }
        }
Ejemplo n.º 4
0
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))
                {
                    if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_VIEW"]) && !Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_VIEW"]) && !Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"]) && !Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"]) && !Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT"]) && !Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT_WED"]))
                    {
                        Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                    }
                }

                // Validate query string
                if (((string)Request.QueryString["source_page"] == null) && ((string)Request.QueryString["others"] == null) && ((string)Request.QueryString["employee_id"] == null) && ((string)Request.QueryString["period_id"] == null) && ((string)Request.QueryString["projecttime_id"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in timesheet.aspx");
                }

                // Tag page
                Session.Remove("timesheetNavigatorDummy");

                // Initialize  variables
                lblError.Visible = false;

                // ... Labour Hours Mode
                System.Configuration.AppSettingsReader appSettingReader = new System.Configuration.AppSettingsReader();
                ViewState["LHMode"] = appSettingReader.GetValue("LABOUR_HOURS_OPERATION_MODE", typeof(System.String)).ToString();

                // ... If coming from out
                if ((string)Request.QueryString["source_page"] == "out")
                {
                    Session.Remove("ddlOthersForSelectedValue");

                    // Store search parameters
                    ViewState["current"] = "yes";
                    if (Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_VIEW"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT_WED"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))
                    {
                        ViewState["others"] = "yes";
                    }
                    else
                    {
                        ViewState["others"] = "no";
                    }

                    EmployeeGateway employeeGateway1 = new EmployeeGateway(new DataSet());
                    ViewState["employee_id"] = employeeGateway1.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));

                    PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
                    ViewState["period_id"] = payPeriodGateway.GetPayPeriodId(DateTime.Now);

                    if (Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_AUTOREPORT"]))
                    {
                        string script = "<script language='javascript'>";
                        script += "window.open('./../projecttime/timesheet_missing.aspx?source_page=timesheet.aspx', '_blank', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=550, height=420')";
                        script += "</script>";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Report", script, false);
                    }
                }

                // ... If coming from left menu
                if ((string)Request.QueryString["source_page"] == "lm")
                {
                    // Store search parameters
                    ViewState["current"] = "yes";
                    ViewState["others"] = Request.QueryString["others"];

                    if (Request.QueryString["others"] == "yes")
                    {
                        ViewState["employee_id"] = int.Parse((string)Request.QueryString["employee_id"]);
                    }
                    else
                    {
                        EmployeeGateway employeeGateway1 = new EmployeeGateway(new DataSet());
                        ViewState["employee_id"] = employeeGateway1.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));
                    }

                    PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
                    ViewState["period_id"] = payPeriodGateway.GetPayPeriodId(DateTime.Now);
                }

                // ... If coming from timesheet_all.aspx
                if ((string)Request.QueryString["source_page"] == "timesheet_all.aspx")
                {
                    // Store search parameters
                    PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
                    int currentPeriod = payPeriodGateway.GetCurrent();

                    if (currentPeriod == int.Parse((string)Request.QueryString["period_id"]))
                    {
                        ViewState["current"] = "yes";
                    }
                    else
                    {
                        ViewState["current"] = "no";
                    }

                    ViewState["others"] = Request.QueryString["others"];
                    ViewState["employee_id"] = int.Parse((string)Request.QueryString["employee_id"]);
                    ViewState["period_id"] = int.Parse((string)Request.QueryString["period_id"]);
                }

                // ... If coming from timesheet.aspx
                if ((string)Request.QueryString["source_page"] == "timesheet.aspx")
                {
                    // Store search parameters
                    PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
                    int currentPeriod = payPeriodGateway.GetCurrent();

                    if (currentPeriod == int.Parse((string)Request.QueryString["period_id"]))
                    {
                        ViewState["current"] = "yes";
                    }
                    else
                    {
                        ViewState["current"] = "no";
                    }

                    ViewState["others"] = Request.QueryString["others"];
                    ViewState["employee_id"] = int.Parse((string)Request.QueryString["employee_id"]);
                    ViewState["period_id"] = int.Parse((string)Request.QueryString["period_id"]);

                    if (Session["OpenTimesheetMissing"] == null)
                    {
                        if (Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_AUTOREPORT"]))
                        {
                            string script = "<script language='javascript'>";
                            script += "window.open('./../projecttime/timesheet_missing.aspx?source_page=timesheet.aspx', '_blank', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=550, height=420')";
                            script += "</script>";
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Report", script, false);
                        }
                    }
                }

                // ... If coming from timesheet_summary.aspx, timesheet_add.aspx, timesheet_edit.aspx, timesheet_delete.aspx or timesheet_state.aspx
                if (((string)Request.QueryString["source_page"] == "timesheet_summary.aspx") || ((string)Request.QueryString["source_page"] == "timesheet_add.aspx") || ((string)Request.QueryString["source_page"] == "timesheet_edit.aspx") || ((string)Request.QueryString["source_page"] == "timesheet_delete.aspx") || ((string)Request.QueryString["source_page"] == "timesheet_state.aspx"))
                {
                    // Store search parameters
                    PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
                    int currentPeriod = payPeriodGateway.GetCurrent();

                    if (currentPeriod == int.Parse((string)Request.QueryString["period_id"]))
                    {
                        ViewState["current"] = "yes";
                    }
                    else
                    {
                        ViewState["current"] = "no";
                    }

                    ViewState["others"] = Request.QueryString["others"];
                    ViewState["employee_id"] = int.Parse((string)Request.QueryString["employee_id"]);
                    ViewState["period_id"] = int.Parse((string)Request.QueryString["period_id"]);
                }

                // ... If coming from timesheet_approve.aspx
                if ((string)Request.QueryString["source_page"] == "timesheet_approve.aspx")
                {
                    // Store search parameters
                    PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
                    int currentPeriod = payPeriodGateway.GetCurrent();
                    EmployeeGateway employeeGateway1 = new EmployeeGateway(new DataSet());

                    ViewState["current"] = "yes";
                    ViewState["others"] = "yes";
                    ViewState["employee_id"] = employeeGateway1.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));
                    ViewState["period_id"] = currentPeriod;
                }

                // Access control
                // ... Employees
                EmployeeListGateway employeeListGateway = new EmployeeListGateway(new DataSet());

                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))
                {
                    employeeListGateway.LoadByRequestProjectTimeWithoutEmployeeId(1, (int)ViewState["employee_id"]);
                }
                else
                {
                    employeeListGateway.LoadByRequestProjectTime(1);
                }

                DropDownList ddlOthersFor = (DropDownList)tkrpbLeftMenuOthersTimesheets.FindItemByValue("nbOthersTimesheetsDDL").FindControl("ddlOthersFor");
                ddlOthersFor.DataSource = employeeListGateway.Table;
                ddlOthersFor.DataValueField = "EmployeeID";
                ddlOthersFor.DataTextField = "FullName";
                ddlOthersFor.DataBind();

                // ... Title
                EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());

                if ((int)ViewState["employee_id"] != 0)
                {
                    employeeGateway.LoadByEmployeeId((int)ViewState["employee_id"]);
                    if ((string)ViewState["others"] == "no")
                    {
                        if ((Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_VIEW"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"])) && (employeeGateway.GetRequestProjectTime((int)ViewState["employee_id"])))
                        {
                            if ((string)ViewState["current"] == "yes")
                            {
                                lblTitle.Text = "Current Timesheet For " + employeeGateway.GetFullName((int)ViewState["employee_id"]);
                            }
                            else
                            {
                                PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
                                payPeriodGateway.LoadByPayPeriodId((int)ViewState["period_id"]);
                                lblTitle.Text = "Timesheet For " + employeeGateway.GetFullName((int)ViewState["employee_id"]) + " From " + payPeriodGateway.GetStartDate((int)ViewState["period_id"]).ToShortDateString() + " To " + payPeriodGateway.GetEndDate((int)ViewState["period_id"]).ToShortDateString();
                            }
                        }
                        else
                        {
                            Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                        }
                    }
                    else
                    {
                        EmployeeGateway employeeGateway1 = new EmployeeGateway(new DataSet());
                        int employeeIdNow = employeeGateway1.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));

                        if ((int)ViewState["employee_id"] == employeeIdNow)
                        {
                            if (((Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_VIEW"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"])) && (employeeGateway.GetRequestProjectTime((int)ViewState["employee_id"]))))
                            {
                                if ((string)ViewState["current"] == "yes")
                                {
                                    lblTitle.Text = "Current Timesheet For " + employeeGateway.GetFullName((int)ViewState["employee_id"]);
                                }
                                else
                                {
                                    PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
                                    payPeriodGateway.LoadByPayPeriodId((int)ViewState["period_id"]);
                                    lblTitle.Text = "Timesheet For " + employeeGateway.GetFullName((int)ViewState["employee_id"]) + " From " + payPeriodGateway.GetStartDate((int)ViewState["period_id"]).ToShortDateString() + " To " + payPeriodGateway.GetEndDate((int)ViewState["period_id"]).ToShortDateString();
                                }
                            }
                            else
                            {
                                if (ddlOthersFor.Items.Count > 0)
                                {
                                    Session["ddlOthersForSelectedValue"] = ddlOthersFor.SelectedValue;
                                    Response.Redirect("./timesheet.aspx?source_page=timesheet.aspx&others=yes&employee_id=" + ddlOthersFor.SelectedValue + "&period_id=" + ((int)ViewState["period_id"]).ToString());
                                }
                                else
                                {
                                    Response.Redirect("./../../error_page.aspx?error=" + "No team members with 'Request Timesheet' property are defined in the system. Contact your system administrator for further assistance.");
                                }
                            }
                        }
                        else
                        {
                            if ((string)ViewState["current"] == "yes")
                            {
                                lblTitle.Text = "Current Timesheet For " + employeeGateway.GetFullName((int)ViewState["employee_id"]);
                            }
                            else
                            {
                                PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
                                payPeriodGateway.LoadByPayPeriodId((int)ViewState["period_id"]);
                                lblTitle.Text = "Timesheet For " + employeeGateway.GetFullName((int)ViewState["employee_id"]) + " From " + payPeriodGateway.GetStartDate((int)ViewState["period_id"]).ToShortDateString() + " To " + payPeriodGateway.GetEndDate((int)ViewState["period_id"]).ToShortDateString();
                            }
                        }
                    }
                }
                else
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "You cannot use the Labour Hours subsystem since you are not registered as a team member in LFS Live. Please contact your system administrator for further assistance."); ;
                }

                // Load data
                timesheetNavigatorTDS = this.SubmitSearch();
                Session["timesheetNavigatorTDS"] = timesheetNavigatorTDS;
                timesheetNavigator = timesheetNavigatorTDS.LFS_PROJECT_TIME;
                Session["timesheetNavigator"] = timesheetNavigator;

                // Set Total project time
                TimesheetNavigator timesheetNavigatorForTotal = new TimesheetNavigator(timesheetNavigatorTDS);
                tbxTotalCost.Text = timesheetNavigatorForTotal.GetTotalProjectTime().ToString();
            }
            else
            {
                // Restore dataset
                timesheetNavigatorTDS = (TimesheetNavigatorTDS)Session["timesheetNavigatorTDS"];
                timesheetNavigator = timesheetNavigatorTDS.LFS_PROJECT_TIME;

                // Store datase
                Session["timesheetNavigator"] = timesheetNavigator;
            }
        }
Ejemplo n.º 5
0
        protected void btnPriorTimesheet_Click(object sender, EventArgs e)
        {
            lblError.Visible = false;

            DropDownList ddlOthersFor = (DropDownList)tkrpbLeftMenuOthersTimesheets.FindItemByValue("nbOthersTimesheetsDDL").FindControl("ddlOthersFor");
            Session["ddlOthersForSelectedValue"] = ddlOthersFor.SelectedValue;

            PayPeriodGateway priorPayPeriodGateway = new PayPeriodGateway();
            int priorPayPeriodId = priorPayPeriodGateway.GetPriorPayPeriodId((int)ViewState["period_id"]);

            if (priorPayPeriodId > 0)
            {
                Response.Redirect("./timesheet.aspx?source_page=timesheet.aspx&others=" + ViewState["others"] + "&employee_id=" + ViewState["employee_id"] + "&period_id=" + priorPayPeriodId.ToString());
            }
        }
        /// <summary>
        /// GetTotalHoursByEmployeeIdPeriodId
        /// </summary>
        /// <param name="employeeId">employeeId</param>
        /// <param name="date">date</param>
        /// <param name="projectTimeId">projectTimeId</param>
        /// <returns>total</returns>
        private double GetTotalHoursByEmployeeIdPeriodId(int employeeId, DateTime date, int projectTimeId)
        {
            double total = 0;
            PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
            int periodId = payPeriodGateway.GetPayPeriodId(date);

            TimesheetNavigatorGateway timesheetNavigatorGateway = new TimesheetNavigatorGateway();
            timesheetNavigatorGateway.LoadByEmployeIdPayPeriodId(employeeId, periodId);

            foreach (TimesheetNavigatorTDS.LFS_PROJECT_TIMERow row in (TimesheetNavigatorTDS.LFS_PROJECT_TIMEDataTable)timesheetNavigatorGateway.Table)
            {
                if ((!row.IsStartTimeNull() && (!row.IsEndTimeNull())))
                {
                    if ((row.Date_ <= date) && (row.ProjectTimeID != projectTimeId))
                    {
                        if (!row.Deleted)
                        {
                            total = total + row.ProjectTime;
                        }
                    }
                    else
                    {
                        return total;
                    }
                }
            }

            return total;
        }
        /// <summary>
        /// GetTotalHoursByEmployeeIdPeriodId
        /// </summary>
        /// <param name="employeeId">employeeId</param>
        /// <param name="date">date</param>
        /// <returns>total</returns>
        private double GetTotalHoursByEmployeeIdPeriodId(int employeeId, DateTime date)
        {
            double total = 0;
            PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
            int periodId = payPeriodGateway.GetPayPeriodId(date);

            TimesheetNavigatorGateway timesheetNavigatorGateway = new TimesheetNavigatorGateway();
            timesheetNavigatorGateway.LoadByEmployeIdPayPeriodId(employeeId, periodId);

            foreach (TimesheetNavigatorTDS.LFS_PROJECT_TIMERow row in (TimesheetNavigatorTDS.LFS_PROJECT_TIMEDataTable)timesheetNavigatorGateway.Table)
            {
                if (row.Date_ < date)
                {
                    if (!row.Deleted)
                    {
                        total = total + double.Parse(row.ProjectTime.ToString());
                    }
                }
            }

            return total;
        }
        /// <summary>
        /// MoveToProjectTime
        /// </summary>
        /// <param name="projectTimeTDS">projectTimeTDS</param>
        /// <param name="LHMode">LHMode</param>
        /// <param name="fullEditing">fullEditing</param>
        /// <param name="typeOfWork">typeOfWork</param>
        /// <param name="function">function</param>
        /// <param name="companyId">companyId</param>
        /// <param name="createdById">createdById</param>
        /// <returns></returns>
        public string MoveToProjectTime(ProjectTimeTDS projectTimeTDS, string LHMode, bool fullEditing, string typeOfWork, string function, int companyId, int createdById)
        {
            PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
            TimesheetGateway timesheetGateway = new TimesheetGateway(new DataSet());
            EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
            LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTime projectTime = new LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTime(projectTimeTDS);
            string errorMessage = "";

            // Clear before project times
            projectTime.Table.Rows.Clear();

            // Insert new project times
            foreach (TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAILRow row in ((TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAILDataTable)Table))
            {
                if (!row.Deleted)
                {
                    int employeeId = row.EmployeeID;
                    int companiesId = row.CompaniesID;
                    int projectId = row.ProjectID;
                    DateTime date_ = row.Date_;

                    DateTime? startTime = null;
                    if (!row.IsStartTimeNull())
                    {
                        string[] startTimeSplit = row.StartTime.Split(':');
                        int startTimeHour = Int32.Parse(startTimeSplit[0].ToString());
                        string[] startTimeMinuteSplit = startTimeSplit[1].Split(' ');
                        int startTimeMinute = Int32.Parse(startTimeMinuteSplit[0].ToString());
                        startTime = new DateTime(date_.Year, date_.Month, date_.Day, startTimeHour, startTimeMinute, 0);
                    }
                    DateTime? endTime = null;
                    if (!row.IsEndTimeNull())
                    {
                        string[] endTimeSplit = row.EndTime.Split(':');
                        int endTimeHour = Int32.Parse(endTimeSplit[0].ToString());
                        string[] endTimeMinuteSplit = endTimeSplit[1].Split(' ');
                        int endTimeMinute = Int32.Parse(endTimeMinuteSplit[0].ToString());
                        endTime = new DateTime(date_.Year, date_.Month, date_.Day, endTimeHour, endTimeMinute, 0);
                    }
                    double? offset = null; if (!row.IsOffsetNull()) offset = row.Offset;
                    double projectTimeValue = row.ProjectTime;
                    string workingDetails = ""; if (!row.IsWorkingDetailsNull()) workingDetails = row.WorkingDetails;
                    string location = ""; if (!row.IsLocationNull()) location = row.Location;
                    Int64? mealsCountry = null; if (!row.IsMealsCountryNull()) mealsCountry = row.MealsCountry;
                    string mealsAllowanceType = ""; if (!row.IsMealsAllowanceTypeNull()) mealsAllowanceType = row.MealsAllowanceType;
                    decimal mealsAllowance = row.MealsAllowance;
                    int? unitId = null; if (!row.IsUnitIDNull()) unitId = row.UnitID;
                    int? towedUnitId = null; if (!row.IsTowedUnitIDNull()) towedUnitId = row.TowedUnitID;
                    string comments = ""; if (!row.IsCommentsNull()) comments = row.Comments;
                    string work_ = row.Work_;
                    string function_ = row.Function_;
                    bool fairWage = row.FairWage;
                    string jobClass = ""; if (!row.IsJobClassTypeNull()) jobClass = row.JobClassType;

                    string projectTimeState = row.ProjectTimeState;

                   int projectTimeId = projectTime.Insert(employeeId, companiesId, projectId, date_, startTime, endTime, offset, workingDetails, location, mealsCountry, mealsAllowanceType, mealsAllowance, unitId, towedUnitId, projectTimeState, comments, work_, function_, fairWage, jobClass, createdById);

                   if (typeOfWork == "Full Length")
                   {
                       LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTimeSection projectTimeSection = new LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTimeSection(projectTimeTDS);

                       switch (function)
                       {
                           case "Install":
                               foreach (TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_SECTIONRow projectTimeRow in ((TeamProjectTime2TDS)Data).LFS_TEAM_PROJECT_TIME_SECTION)
                               {
                                   if (projectTimeRow.Selected)
                                   {
                                       projectTimeSection.Insert(projectTimeId, projectTimeRow.SectionID, projectTimeRow.FlowOrderID, true, projectTimeRow._Date, 0, 0, false, companyId);
                                   }
                               }
                               break;

                           case "Prep & Measure":
                               foreach (TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_SECTIONRow projectTimeRow in ((TeamProjectTime2TDS)Data).LFS_TEAM_PROJECT_TIME_SECTION)
                               {
                                   if (projectTimeRow.Selected)
                                   {
                                       projectTimeSection.Insert(projectTimeId, projectTimeRow.SectionID, projectTimeRow.FlowOrderID, projectTimeRow.Completed, projectTimeRow._Date, 0, 0, false, companyId);
                                   }
                               }
                               break;

                           case "Reinstate & Post Video":
                               foreach (TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_SECTIONRow projectTimeRow in ((TeamProjectTime2TDS)Data).LFS_TEAM_PROJECT_TIME_SECTION)
                               {
                                   if (projectTimeRow.Selected)
                                   {
                                       projectTimeSection.Insert(projectTimeId, projectTimeRow.SectionID, projectTimeRow.FlowOrderID, projectTimeRow.Completed, projectTimeRow._Date, projectTimeRow.PercentageOpened, projectTimeRow.PercentageBrushed, false, companyId);
                                   }
                               }
                               break;
                       }
                   }

                   //if (typeOfWork == "MH Rehab")//TODO MH
                   //{
                   //    LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTimeSection projectTimeSection = new LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTimeSection(projectTimeTDS);

                   //    switch (function)
                   //    {
                   //        case "Prep":
                   //            foreach (TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_SECTIONRow projectTimeRow in ((TeamProjectTime2TDS)Data).LFS_TEAM_PROJECT_TIME_SECTION)
                   //            {
                   //                if (projectTimeRow.Selected)
                   //                {
                   //                    projectTimeSection.Insert(projectTimeId, projectTimeRow.SectionID, projectTimeRow.FlowOrderID, true, projectTimeRow._Date, 0, 0, false, companyId);
                   //                }
                   //            }
                   //            break;

                   //        case "Spray":
                   //            foreach (TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_SECTIONRow projectTimeRow in ((TeamProjectTime2TDS)Data).LFS_TEAM_PROJECT_TIME_SECTION)
                   //            {
                   //                if (projectTimeRow.Selected)
                   //                {
                   //                    projectTimeSection.Insert(projectTimeId, projectTimeRow.SectionID, projectTimeRow.FlowOrderID, true, projectTimeRow._Date, 0, 0, false, companyId);
                   //                }
                   //            }
                   //            break;
                   //    }
                   //}
                }
            }

            return errorMessage;
        }