/// <summary>
 /// InitData
 /// </summary>
 protected override void InitData()
 {
     _data = new ProjectTimeTDS();
 }
        // ////////////////////////////////////////////////////////////////////////
        // 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) && ((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_summary.aspx");
                }

                // Security check
                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))
                {
                    if (Request.QueryString["others"] == "no")
                    {
                        if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_VIEW"]))
                        {
                            if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"]))
                            {
                                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"]))
                                {
                                    Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                                }
                            }
                        }
                    }
                    else
                    {
                        if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_VIEW"]))
                        {
                            if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"]))
                            {
                                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"]))
                                {
                                    if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_VIEW"]))
                                    {
                                        if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT"]))
                                        {
                                            if (!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.");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // Initialize viewstate's variables
                ViewState["others"] = Request.QueryString["others"];
                ViewState["employee_id"] = int.Parse(Request.QueryString["employee_id"]);
                ViewState["period_id"] = int.Parse(Request.QueryString["period_id"]);
                ViewState["projecttime_id"] = int.Parse(Request.QueryString["projecttime_id"]);
                System.Configuration.AppSettingsReader appSettingReader = new System.Configuration.AppSettingsReader();
                ViewState["LHMode"] = appSettingReader.GetValue("LABOUR_HOURS_OPERATION_MODE", typeof(System.String)).ToString();

                // Get ProjectTime record
                projectTimeTDS =  new ProjectTimeTDS();

                ProjectTimeGateway projectTimeGateway = new ProjectTimeGateway(projectTimeTDS);
                projectTimeGateway.LoadByProjectTimeId((int)ViewState["projecttime_id"]);

                // Store datasets
                Session["projectTimeTDS"] = projectTimeTDS;

                // Databind
                tbxDate.DataBind();
                tbxWorkingDetails.DataBind();
                tbxStartTime.DataBind();
                tbxEndTime.DataBind();
                tbxLunch.DataBind();
                tbxComments.DataBind();
                tbxState.DataBind();

                // Prepare initial data for client
                StoreNavigatorState();

                EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
                employeeGateway.LoadByEmployeeId((int)ViewState["employee_id"]);
                tbxEmployee.Text = employeeGateway.GetFullName((int)ViewState["employee_id"]);

                int companyId = Int32.Parse(Session["companyID"].ToString());

                CompaniesGateway companiesGateway = new CompaniesGateway(new DataSet());
                companiesGateway.LoadAllByCompaniesId(projectTimeGateway.GetCompaniesId((int)ViewState["projecttime_id"]), companyId);
                tbxClient.Text = companiesGateway.GetName(projectTimeGateway.GetCompaniesId((int)ViewState["projecttime_id"]));

                ProjectGateway projectGateway = new ProjectGateway(new DataSet());
                projectGateway.LoadByProjectId(projectTimeGateway.GetProjectId((int)ViewState["projecttime_id"]));
                tbxProject.Text = projectGateway.GetName(projectTimeGateway.GetProjectId((int)ViewState["projecttime_id"])) + "(" + projectGateway.GetProjectNumber(projectTimeGateway.GetProjectId((int)ViewState["projecttime_id"])) + ")";

                if (projectGateway.GetFairWageApplies(projectTimeGateway.GetProjectId((int)ViewState["projecttime_id"])))
                {
                    tbxJobClassType.Visible = true;
                    lblJobClassType.Visible = true;
                    tbxJobClassType.Text = projectTimeGateway.GetJobClassType((int)ViewState["projecttime_id"]);
                }
                else
                {
                    tbxJobClassType.Visible = false;
                    lblJobClassType.Visible = false;
                }

                if (projectTimeGateway.GetMealsCountry((int)ViewState["projecttime_id"]).HasValue)
                {
                    CountryGateway countryGateway = new CountryGateway(new DataSet());
                    countryGateway.LoadByCountryId((Int64)projectTimeGateway.GetMealsCountry((int)ViewState["projecttime_id"]));
                    tbxMealsCountry.Text = countryGateway.GetName((Int64)projectTimeGateway.GetMealsCountry((int)ViewState["projecttime_id"]));
                }

                //if (projectTimeGateway.GetMealsAllowance((int)ViewState["projecttime_id"]) > 0)
                //{
                //    cbxMealsAllowance.Checked = true;
                //}

                //if (projectTimeGateway.GetFairWage((int)ViewState["projecttime_id"]))
                //{
                //    cbxFairWage.Checked = true;
                //}

                if (projectTimeGateway.GetUnitId((int)ViewState["projecttime_id"]).HasValue)
                {
                    UnitsGateway unitGateway = new UnitsGateway(new DataSet());
                    unitGateway.LoadByUnitId((int)projectTimeGateway.GetUnitId((int)ViewState["projecttime_id"]), Convert.ToInt32(Session["companyID"]));
                    tbxUnit.Text = unitGateway.GetUnitCode((int)projectTimeGateway.GetUnitId((int)ViewState["projecttime_id"]));
                }

                if (projectTimeGateway.GetTowedUnitId((int)ViewState["projecttime_id"]).HasValue)
                {
                    UnitsGateway unitGateway = new UnitsGateway(new DataSet());
                    unitGateway.LoadByUnitId((int)projectTimeGateway.GetTowedUnitId((int)ViewState["projecttime_id"]), Convert.ToInt32(Session["companyID"]));
                    tbxTowed.Text = unitGateway.GetUnitCode((int)projectTimeGateway.GetTowedUnitId((int)ViewState["projecttime_id"]));
                }

                tbxTypeOfWork.Text = "";
                if (projectTimeGateway.GetWork((int)ViewState["projecttime_id"]) != "")
                {
                    tbxTypeOfWork.Text = projectTimeGateway.GetWork((int)ViewState["projecttime_id"]);
                }

                tbxFunction.Text = "";
                if (projectTimeGateway.GetFunction((int)ViewState["projecttime_id"]) != "")
                {
                    tbxFunction.Text = projectTimeGateway.GetFunction((int)ViewState["projecttime_id"]);
                }
            }
            else
            {
                // Restore datasets
                projectTimeTDS = (ProjectTimeTDS)Session["projectTimeTDS"];
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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) && ((string)Request.QueryString["others"] == null) && ((string)Request.QueryString["employee_id"] == null) && ((string)Request.QueryString["period_id"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in timesheet_add.aspx");
                }

                // Security check
                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))
                {
                    if (Request.QueryString["others"] == "no")
                    {
                        if (!(Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_VIEW"]) && Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_ADD"])))
                        {
                            if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"]))
                            {
                                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"]))
                                {
                                    Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                                }
                            }
                        }
                    }
                    else
                    {
                        if (!(Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_VIEW"]) && Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_ADD"])))
                        {
                            if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"]))
                            {
                                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"]))
                                {
                                    if (!(Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_VIEW"]) && Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_ADD"])))
                                    {
                                        if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT"]))
                                        {
                                            if (!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.");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // Tag Page
                hdfSaveClick.Value = "false";
                hdfEmployeeID.Value = Request.QueryString["employee_id"].ToString();
                hdfPeriodId.Value = Request.QueryString["period_id"];
                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfIsMoreThan15.Value = "false";
                hdfIsMoreThan15Edit.Value = "false";
                Session.Remove("projectTimeTempNewDummy");

                // Initialize viewstate variables
                ViewState["others"] = Request.QueryString["others"];
                ViewState["timesheetState"] = "For Approval";

                // Get State
                int employeeId = Int32.Parse(hdfEmployeeID.Value);
                int periodId = Int32.Parse(hdfPeriodId.Value);

                TimesheetGateway timesheet = new TimesheetGateway();
                timesheet.LoadByEmployeeIdPayPeriodId(employeeId, periodId);
                if (timesheet.Table.Rows.Count != 0)
                {
                    ViewState["timesheetState"] = timesheet.GetStateByEmployeeIdPayPeriodId(employeeId, periodId);
                }

                if (Request.QueryString["source_page"] == "timesheet_summary.aspx" || Request.QueryString["source_page"] == "timesheet_summary_from_approve_project_times.aspx")
                {
                    ViewState["projecttime_id"] = int.Parse(Request.QueryString["projecttime_id"]);
                }

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

                // Timesheet state check
                if (((string)ViewState["LHMode"] == "Full") && (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"])))
                {
                    TimesheetGateway timesheetGateway = new TimesheetGateway();
                    timesheetGateway.LoadByEmployeeIdPayPeriodId(employeeId, periodId);

                    if ((timesheetGateway.Table.Rows.Count != 0) && (timesheetGateway.GetStateByEmployeeIdPayPeriodId(employeeId, periodId) != "Rejected"))
                    {
                        Response.Redirect("./../../error_page.aspx?error=" + "You cannot add project time to an approved or submitted timesheet.");
                    }
                }

                // Prepare initial data for client
                EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
                employeeGateway.LoadByEmployeeId(employeeId);
                tbxEmployee.Text = employeeGateway.GetFullName(employeeId);

                tbxState.Text = "For Approval";

                int companyId = Int32.Parse(hdfCompanyId.Value);
                CompaniesList companiesList = new CompaniesList(new DataSet());
                companiesList.LoadAndAddItem(-1, "(Select a client)", companyId);
                ddlClient.DataSource = companiesList.Table;
                ddlClient.DataValueField = "COMPANIES_ID";
                ddlClient.DataTextField = "Name";
                ddlClient.DataBind();
                ddlClient.SelectedIndex = 0;

                ProjectList projectList = new ProjectList();
                projectList.LoadActiveProjectsActiveInternalProjectsActiveBallparkProjectsAndAddItem(-1, "(Select a project)", -1);
                ddlProject.DataSource = projectList.Table;
                ddlProject.DataValueField = "ProjectID";
                ddlProject.DataTextField = "Name";
                ddlProject.DataBind();
                ddlProject.SelectedIndex = 0;

                CountryList countryList = new CountryList(new DataSet());
                countryList.LoadAndAddItem(-1, " ");
                ddlMealsCountry.DataSource = countryList.Table;
                ddlMealsCountry.DataValueField = "CountryID";
                ddlMealsCountry.DataTextField = "Name";
                ddlMealsCountry.DataBind();

                tkrdpStartDate.SelectedDate = DateTime.Now;
                tkrdpEndDate.SelectedDate = DateTime.Now;

                // Store timesheet dataset
                projectTimeTDS = new ProjectTimeTDS();
                Session["projectTimeTDS"] = projectTimeTDS;
                projectTimeTemp = projectTimeTDS.LFS_PROJECT_TIME_TEMP;
                Session["projectTimeTemp"] = projectTimeTDS.LFS_PROJECT_TIME_TEMP;
            }
            else
            {
                // Restore datasets
                projectTimeTDS = (ProjectTimeTDS)Session["projectTimeTDS"];
                projectTimeTemp = projectTimeTDS.LFS_PROJECT_TIME_TEMP;

                // Store datasets
                Session["projectTimeTemp"] = projectTimeTemp;
            }
        }
        private void PostPageChanges()
        {
            EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
            int employeeId = employeeGateway.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));

            projectTimeTDSToSave = new ProjectTimeTDS();
            LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTime projectTime = new LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTime(projectTimeTDS);
            projectTime.Insert(projectTimeTDSToSave, employeeId);
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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) && ((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_edit.aspx");
                }

                // Security check
                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))
                {
                    if (Request.QueryString["others"] == "no")
                    {
                        if (!(Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_VIEW"]) && Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_EDIT"])))
                        {
                            if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"]))
                            {
                                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"]))
                                {
                                    Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                                }
                            }
                        }
                    }
                    else
                    {
                        if (!(Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_VIEW"]) && Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_EDIT"])))
                        {
                            if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"]))
                            {
                                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"]))
                                {
                                    if (!(Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_VIEW"]) && Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_EDIT"])))
                                    {
                                        if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT"]))
                                        {
                                            if (!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.");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // Initialize viewstate variables
                ViewState["others"] = Request.QueryString["others"];
                ViewState["employee_id"] = int.Parse(Request.QueryString["employee_id"]);
                ViewState["period_id"] = int.Parse(Request.QueryString["period_id"]);
                ViewState["projecttime_id"] = int.Parse(Request.QueryString["projecttime_id"]);
                System.Configuration.AppSettingsReader appSettingReader = new System.Configuration.AppSettingsReader();
                ViewState["LHMode"] = appSettingReader.GetValue("LABOUR_HOURS_OPERATION_MODE", typeof(System.String)).ToString();
                hdfCompanyId.Value = Session["companyID"].ToString();

                // Get ProjectTime record
                ProjectTimeGateway projectTimeGateway = new ProjectTimeGateway(projectTimeTDS);
                projectTimeGateway.LoadByProjectTimeId((int)ViewState["projecttime_id"]);

                // Project time state check
                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))
                {
                    if (projectTimeGateway.GetProjectTimeState((int)ViewState["projecttime_id"]) == "Approved")
                    {
                        Response.Redirect("./../../error_page.aspx?error=" + "You cannot edit an approved project time.");
                    }
                }

                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))
                {
                    if (Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT"]))
                    {
                        bool isValidLimitPayPeriodToManagementEdit = LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTime.ValidateLimitedPayPeriodToManagementEdit(projectTimeGateway.GetDate_((int)ViewState["projecttime_id"]), projectTimeGateway.GetProjectId((int)ViewState["projecttime_id"]));

                        if (!isValidLimitPayPeriodToManagementEdit)
                        {
                            Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                        }
                    }
                    else
                    {
                        if (Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT_WED"]))
                        {
                            bool isValidLimitPayPeriodToManagementEdit = LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTime.ValidateLimitedPayPeriodToWednesdayManagementEdit(projectTimeGateway.GetDate_((int)ViewState["projecttime_id"]), projectTimeGateway.GetProjectId((int)ViewState["projecttime_id"]));

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

                // Store datasets
                Session["projectTimeTDS"] = projectTimeTDS;

                // Databind
                tkrdpDate_.DataBind();
                ddlLunch.DataBind();
                tbxComments.DataBind();
                tbxState.DataBind();

                // Prepare initial data for client
                StoreNavigatorState();

                EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
                employeeGateway.LoadByEmployeeId((int)ViewState["employee_id"]);
                tbxEmployee.Text = employeeGateway.GetFullName(int.Parse(Request.QueryString["employee_id"]));

                int companyId = Int32.Parse(hdfCompanyId.Value);
                CompaniesList companiesList = new CompaniesList();
                companiesList.LoadAndAddItem(-1, "(Select a client)", companyId);
                ddlClient.DataSource = companiesList.Table;
                ddlClient.DataValueField = "COMPANIES_ID";
                ddlClient.DataTextField = "Name";
                ddlClient.DataBind();

                CompaniesGateway companiesGateway = new CompaniesGateway();
                companiesGateway.LoadAllByCompaniesId(Int32.Parse(DataBinder.Eval(projectTimeTDS, "Tables[LFS_PROJECT_TIME].DefaultView.[0].CompaniesID").ToString()), companyId);

                // ... If Company is active
                bool deleted = companiesGateway.GetDeleted(Int32.Parse(DataBinder.Eval(projectTimeTDS, "Tables[LFS_PROJECT_TIME].DefaultView.[0].CompaniesID").ToString()));

                if (deleted)
                {
                    ddlClient.SelectedIndex = -1;
                }
                else
                {
                    ddlClient.SelectedValue = DataBinder.Eval(projectTimeTDS, "Tables[LFS_PROJECT_TIME].DefaultView.[0].CompaniesID").ToString();
                }

                ProjectList projectList = new ProjectList();
                projectList.LoadProjectsInternalProjectsBallparkProjectsAndAddItem(-1, "(Select a project)", int.Parse(ddlClient.SelectedValue));
                ddlProject.DataSource = projectList.Table;
                ddlProject.DataValueField = "ProjectID";
                ddlProject.DataTextField = "Name";
                ddlProject.DataBind();

                if (!deleted)
                {
                    try
                    {
                        ddlProject.SelectedValue = DataBinder.Eval(projectTimeTDS, "Tables[LFS_PROJECT_TIME].DefaultView.[0].ProjectID").ToString();
                    }
                    catch
                    {
                        ddlProject.SelectedIndex = -1;
                    }
                }
                else
                {
                    ddlProject.SelectedIndex = -1;
                }

                if (ddlProject.SelectedIndex != 0)
                {
                    ProjectGateway projectGateway = new ProjectGateway();
                    projectGateway.LoadByProjectId(Int32.Parse(ddlProject.SelectedValue));

                    if (projectGateway.GetCountryID(Int32.Parse(ddlProject.SelectedValue)) == 1) //Canada
                    {
                        if (projectGateway.GetFairWageApplies(int.Parse(ddlProject.SelectedValue)))
                        {
                            ddlJobClassType.Visible = true;
                            lblJobClassType.Visible = true;

                            ProjectTimeJobClassTypeList projectTimeJobClassTypeList = new ProjectTimeJobClassTypeList();
                            projectTimeJobClassTypeList.LoadAndAddItem(1, companyId, "(Select a Job Class Type)");
                            ddlJobClassType.DataSource = projectTimeJobClassTypeList.Table;
                            ddlJobClassType.DataValueField = "JobClassType";
                            ddlJobClassType.DataTextField = "JobClassType";
                            ddlJobClassType.DataBind();

                            if (projectTimeGateway.GetJobClassType((int)ViewState["projecttime_id"]).ToString() == "")
                            {
                                ddlJobClassType.SelectedIndex = 0;
                            }
                            else
                            {
                                ddlJobClassType.SelectedValue = (string)DataBinder.Eval(projectTimeTDS, "Tables[LFS_PROJECT_TIME].DefaultView.[0].JobClassType");
                            }
                        }
                        else
                        {
                            ddlJobClassType.Visible = false;
                            lblJobClassType.Visible = false;
                        }
                    }
                    else
                    {
                        if (projectGateway.GetFairWageApplies(int.Parse(ddlProject.SelectedValue)))
                        {
                            ddlJobClassType.Visible = true;
                            lblJobClassType.Visible = true;

                            ProjectTimeJobClassTypeList projectTimeJobClassTypeList = new ProjectTimeJobClassTypeList();
                            projectTimeJobClassTypeList.LoadAndAddItem(2, companyId, "(Select a Job Class Type)");
                            ddlJobClassType.DataSource = projectTimeJobClassTypeList.Table;
                            ddlJobClassType.DataValueField = "JobClassType";
                            ddlJobClassType.DataTextField = "JobClassType";
                            ddlJobClassType.DataBind();

                            if (projectTimeGateway.GetJobClassType((int)ViewState["projecttime_id"]).ToString() == "")
                            {
                                ddlJobClassType.SelectedIndex = 0;
                            }
                            else
                            {
                                ddlJobClassType.SelectedValue = (string)DataBinder.Eval(projectTimeTDS, "Tables[LFS_PROJECT_TIME].DefaultView.[0].JobClassType");
                            }
                        }
                        else
                        {
                            ddlJobClassType.Visible = false;
                            lblJobClassType.Visible = false;
                        }
                    }
                }
                else
                {
                    ddlJobClassType.Visible = false;
                    lblJobClassType.Visible = false;
                }

                WorkingDetailsGateway workingDetailsGateway = new WorkingDetailsGateway(new DataSet());
                workingDetailsGateway.Load();
                ddlWorkingDetails.DataSource = workingDetailsGateway.Table;
                ddlWorkingDetails.DataValueField = "WorkingDetails";
                ddlWorkingDetails.DataTextField = "WorkingDetails";
                ddlWorkingDetails.DataBind();

                if (!deleted)
                {
                    ddlWorkingDetails.SelectedValue = projectTimeGateway.GetWorkingDetails((int)ViewState["projecttime_id"]);
                }
                else
                {
                    ddlWorkingDetails.SelectedIndex = -1;
                }

                ProjectTimeWorkList projectTimeWorkList = new ProjectTimeWorkList(new DataSet());

                int projectId = 0;
                try
                {
                    projectId = Int32.Parse(ddlProject.SelectedValue);
                }
                catch
                {
                }

                if (projectId == 35 || projectId == 39 || projectId == 716)
                {
                    projectTimeWorkList.LoadAndAddItem("");
                }
                else
                {
                    projectTimeWorkList.LoadAndAddItem("(Select a Type)");
                }

                // Setting start time, end time
                string startTime = DataBinder.Eval(projectTimeTDS, "Tables[LFS_PROJECT_TIME].DefaultView.[0].StartTime", "{0:H:mm}").ToString();
                if (!String.IsNullOrEmpty(startTime))
                {
                    string[] hoursMin1 = startTime.Split(':');
                    ddlStartTimeHour.SelectedValue = hoursMin1[0].Trim();
                    ddlStartTimeMinute.SelectedValue = hoursMin1[1].Trim();
                }
                else
                {
                    ddlStartTimeHour.SelectedIndex = 0;
                    ddlStartTimeMinute.SelectedIndex = 0;
                }

                string endTime = DataBinder.Eval(projectTimeTDS, "Tables[LFS_PROJECT_TIME].DefaultView.[0].EndTime", "{0:H:mm}").ToString();
                if (!String.IsNullOrEmpty(endTime))
                {
                    string[] endHoursMin1 = endTime.Split(':');
                    ddlEndTimeHour.SelectedValue = endHoursMin1[0].Trim();
                    ddlEndTimeMinute.SelectedValue = endHoursMin1[1].Trim();
                }
                else
                {
                    ddlEndTimeHour.SelectedIndex = 0;
                    ddlEndTimeMinute.SelectedIndex = 0;
                }

                // Setting type of Work
                ddlTypeOfWork.DataSource = projectTimeWorkList.Table;
                ddlTypeOfWork.DataValueField = "Work_";
                ddlTypeOfWork.DataTextField = "Work_";
                ddlTypeOfWork.DataBind();
                if (projectTimeGateway.GetWork((int)ViewState["projecttime_id"]) == "") ddlTypeOfWork.SelectedIndex = -1; else ddlTypeOfWork.SelectedValue = projectTimeGateway.GetWork((int)ViewState["projecttime_id"]);

                ProjectTimeWorkFunctionList projectTimeWorkFunctionList = new ProjectTimeWorkFunctionList(new DataSet());
                if (projectTimeGateway.GetWork((int)ViewState["projecttime_id"]) == "")
                {
                    // ... If there is no type of Work, no function should be loaded
                    projectTimeWorkFunctionList.LoadAndAddItem("", "-1");
                }
                else
                {
                    projectTimeWorkFunctionList.LoadAndAddItem("(Select a Function)", projectTimeGateway.GetWork((int)ViewState["projecttime_id"]).ToString());
                }
                ddlFunction.DataSource = projectTimeWorkFunctionList.Table;
                ddlFunction.DataValueField = "Function_";
                ddlFunction.DataTextField = "Function_";
                ddlFunction.DataBind();
                if (projectTimeGateway.GetWork((int)ViewState["projecttime_id"]).ToString() == "")
                {
                    ddlFunction.SelectedValue = "";
                }
                else
                {
                    ddlFunction.SelectedValue = (string)DataBinder.Eval(projectTimeTDS, "Tables[LFS_PROJECT_TIME].DefaultView.[0].Function_");
                }

                CountryList countryList = new CountryList(new DataSet());
                countryList.LoadAndAddItem(-1, " ");
                ddlMealsCountry.DataSource = countryList.Table;
                ddlMealsCountry.DataValueField = "CountryID";
                ddlMealsCountry.DataTextField = "Name";
                ddlMealsCountry.DataBind();

                if (!deleted)
                {
                    if (projectTimeGateway.GetMealsCountry((int)ViewState["projecttime_id"]).HasValue)
                    {
                        ddlMealsCountry.SelectedValue = projectTimeGateway.GetMealsCountry((int)ViewState["projecttime_id"]).ToString();
                    }
                    else
                    {
                        ddlMealsCountry.SelectedValue = "-1";
                    }
                }
                else
                {
                    ddlMealsCountry.SelectedIndex = -1;
                }

                //if (projectTimeGateway.GetMealsAllowance((int)ViewState["projecttime_id"]) > 0)
                //{
                //    cbxMealsAllowance.Checked = true;
                //}

                string unitType = "Vehicle";
                UnitsList unitsList = new UnitsList(new DataSet());
                unitsList.LoadAndAddItem("-1", " ", Int32.Parse(Session["companyID"].ToString()), true, 0, unitType);
                ddlUnit.DataSource = unitsList.Table;
                ddlUnit.DataValueField = "UnitID";
                ddlUnit.DataTextField = "UnitCode";
                ddlUnit.DataBind();
                if (projectTimeGateway.GetUnitId((int)ViewState["projecttime_id"]).HasValue)
                {
                    ddlUnit.SelectedValue = ((int)projectTimeGateway.GetUnitId((int)ViewState["projecttime_id"])).ToString();
                }

                UnitsList towed = new UnitsList(new DataSet());
                towed.LoadAndAddItem("-1", " ", Int32.Parse(Session["companyID"].ToString()), true, 1, unitType);
                ddlTowed.DataSource = towed.Table;
                ddlTowed.DataValueField = "UnitID";
                ddlTowed.DataTextField = "UnitCode";
                ddlTowed.DataBind();
                if (projectTimeGateway.GetTowedUnitId((int)ViewState["projecttime_id"]).HasValue)
                {
                    ddlTowed.SelectedValue = ((int)projectTimeGateway.GetTowedUnitId((int)ViewState["projecttime_id"])).ToString();
                }
            }
            else
            {
                // Restore datasets
                projectTimeTDS = (ProjectTimeTDS)Session["projectTimeTDS"];
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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) && ((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_delete.aspx");
                }

                // Security check
                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))
                {
                    if (Request.QueryString["others"] == "no")
                    {
                        if (!(Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_VIEW"]) && Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_DELETE"])))
                        {
                            if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"]))
                            {
                                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"]))
                                {
                                    Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                                }
                            }
                        }
                    }
                    else
                    {
                        if (!(Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_VIEW"]) && Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_DELETE"])))
                        {
                            if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"]))
                            {
                                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"]))
                                {
                                    if (!(Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_VIEW"]) && Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_DELETE"])))
                                    {
                                        if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT"]))
                                        {
                                            if (!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.");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // Initialize viewstate variables
                ViewState["others"] = Request.QueryString["others"];
                ViewState["employee_id"] = int.Parse(Request.QueryString["employee_id"]);
                ViewState["period_id"] = int.Parse(Request.QueryString["period_id"]);
                ViewState["projecttime_id"] = int.Parse(Request.QueryString["projecttime_id"]);
                System.Configuration.AppSettingsReader appSettingReader = new System.Configuration.AppSettingsReader();
                ViewState["LHMode"] = appSettingReader.GetValue("LABOUR_HOURS_OPERATION_MODE", typeof(System.String)).ToString();

                // Get ProjectTime record
                projectTimeTDS = new ProjectTimeTDS();

                ProjectTimeGateway projectTimeGateway = new ProjectTimeGateway(projectTimeTDS);
                projectTimeGateway.LoadByProjectTimeId((int)ViewState["projecttime_id"]);

                // Project time state check
                if ((!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"])))
                {
                    if (projectTimeGateway.GetProjectTimeState((int)ViewState["projecttime_id"]) == "Approved")
                    {
                        Response.Redirect("./../../error_page.aspx?error=" + "You cannot delete an approved project time.");
                    }
                }

                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))
                {
                    if (Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT"]))
                    {
                        bool isValidLimitPayPeriodToManagementEdit = LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTime.ValidateLimitedPayPeriodToManagementEdit(projectTimeGateway.GetDate_((int)ViewState["projecttime_id"]), projectTimeGateway.GetProjectId((int)ViewState["projecttime_id"]));

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

                    if (Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT_WED"]))
                    {
                        bool isValidLimitPayPeriodToManagementEdit = LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTime.ValidateLimitedPayPeriodToWednesdayManagementEdit(projectTimeGateway.GetDate_((int)ViewState["projecttime_id"]), projectTimeGateway.GetProjectId((int)ViewState["projecttime_id"]));

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

                // Prepare initial data for client
                StoreNavigatorState();

                // Store datasets
                Session["projectTimeTDS"] = projectTimeTDS;
            }
            else
            {
                // Restore datasets
                projectTimeTDS = (ProjectTimeTDS)Session["projectTimeTDS"];
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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) && ((string)Request.QueryString["others"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in timesheet_state.aspx");
                }

                // Security check
                EmployeeGateway employeeGateway1 = new EmployeeGateway(new DataSet());
                int employeeId = employeeGateway1.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));
                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.");
                }
                else
                {
                    if (!ValidateWedManagement())
                    {
                        Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                    }
                }

                // Initialize viewstate variables
                System.Configuration.AppSettingsReader appSettingReader = new System.Configuration.AppSettingsReader();
                ViewState["LHMode"] = appSettingReader.GetValue("LABOUR_HOURS_OPERATION_MODE", typeof(System.String)).ToString();
                ViewState["others"] = Request.QueryString["others"];
                ViewState["employee_id"] = int.Parse(Request.QueryString["employee_id"]);
                ViewState["period_id"] = int.Parse(Request.QueryString["period_id"]);
                ViewState["source_page"] = Request.QueryString["source_page"];
                if ((string)ViewState["source_page"] == "timesheet_summary.aspx")
                {
                    ViewState["projecttime_id"] = int.Parse(Request.QueryString["projecttime_id"]);
                }

                // 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.");
                }

                // Timesheet state check
                projectTimeTDSForState = new ProjectTimeTDS();
                ProjectTimeGateway projectTimeGateway = new ProjectTimeGateway(projectTimeTDSForState);
                projectTimeGateway.ClearBeforeFill = false;

                if ((string)ViewState["source_page"] == "timesheet_approve.aspx")
                {
                    List<int> projectTimesIdSelected = ((List<int>)Session["projectTimesIdSelected"]);
                    foreach (int projectTimeId in projectTimesIdSelected)
                    {
                        projectTimeGateway.LoadByProjectTimeId(projectTimeId);
                    }
                }
                else
                {
                    if ((string)ViewState["source_page"] == "timesheet_summary.aspx")
                    {
                        int projecttime_id = Int32.Parse(ViewState["projecttime_id"].ToString());
                        projectTimeGateway.LoadByProjectTimeId(projecttime_id);
                    }
                }

                projectTimeGateway.ClearBeforeFill = true;

                // Store datasets
                Session["projectTimeTDSForState"] = projectTimeTDSForState;
            }
            else
            {
                // Restore datasets
                projectTimeTDSForState = (ProjectTimeTDS)Session["projectTimeTDSForState"];
            }
        }
 private void InitializeComponent()
 {
     this.projectTimeTDS = new ProjectTimeTDS();
 }
        /// <summary>
        /// Update TeamProjectTime, TeamProjectTimeDetail and ProjectTimes
        /// </summary>
        /// <param name="projectTime2TDS">ProjectTime2TDS</param>
        public void Update(ProjectTimeTDS projectTime2TDS)
        {
            TeamProjectTime2DetailGateway teamProjectTime2DetailGateway = new TeamProjectTime2DetailGateway(Data);
            ProjectTimeGateway projectTime2Gateway = new ProjectTimeGateway(projectTime2TDS);
            ProjectTimeSectionGateway projectTime2SectionGateway = new ProjectTimeSectionGateway(projectTime2TDS);

            DataTable teamProjectTime2Changes = Table.GetChanges();
            DataTable teamProjectTime2DetailChanges = teamProjectTime2DetailGateway.Table.GetChanges();
            DataTable projectTime2Changes = projectTime2Gateway.Table.GetChanges();
            DataTable projectTime2SectionChanges = projectTime2SectionGateway.Table.GetChanges();

            if ((teamProjectTime2Changes == null) && (teamProjectTime2DetailChanges == null) && (projectTime2Changes == null)) return;

            try
            {
                DB.Open();
                DB.BeginTransaction();

                Adapter.InsertCommand.Transaction = DB.Transaction;
                Adapter.UpdateCommand.Transaction = DB.Transaction;
                Adapter.DeleteCommand.Transaction = DB.Transaction;

                teamProjectTime2DetailGateway.Adapter.InsertCommand.Transaction = DB.Transaction;
                teamProjectTime2DetailGateway.Adapter.UpdateCommand.Transaction = DB.Transaction;
                teamProjectTime2DetailGateway.Adapter.DeleteCommand.Transaction = DB.Transaction;

                projectTime2Gateway.Adapter.InsertCommand.Transaction = DB.Transaction;
                projectTime2Gateway.Adapter.UpdateCommand.Transaction = DB.Transaction;
                projectTime2Gateway.Adapter.DeleteCommand.Transaction = DB.Transaction;

                projectTime2SectionGateway.Adapter.InsertCommand.Transaction = DB.Transaction;
                projectTime2SectionGateway.Adapter.UpdateCommand.Transaction = DB.Transaction;
                projectTime2SectionGateway.Adapter.DeleteCommand.Transaction = DB.Transaction;

                if ((teamProjectTime2Changes != null) && (teamProjectTime2Changes.Rows.Count > 0))
                {
                    int lastTeamProjectTimeId = DB.GetIdentCurrent("LFS_TEAM_PROJECT_TIME", DB.Transaction);
                    Adapter.Update(teamProjectTime2Changes);
                    int newTeamProjectTimeId = DB.GetIdentCurrent("LFS_TEAM_PROJECT_TIME", DB.Transaction);
                    if (lastTeamProjectTimeId != newTeamProjectTimeId)
                    {
                        TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIMERow row = ((TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIMEDataTable)Table).FindByTeamProjectTimeID(0);
                        row.TeamProjectTimeID = newTeamProjectTimeId;
                        teamProjectTime2DetailChanges = teamProjectTime2DetailGateway.Table.GetChanges();
                    }
                }

                if ((teamProjectTime2DetailChanges != null) && (teamProjectTime2DetailChanges.Rows.Count > 0))
                {
                    teamProjectTime2DetailGateway.Adapter.Update(teamProjectTime2DetailChanges);
                }

                if ((projectTime2Changes != null) && (projectTime2Changes.Rows.Count > 0))
                {
                    projectTime2Gateway.Adapter.Update(projectTime2Changes);
                }

                if ((projectTime2SectionChanges != null) && (projectTime2SectionChanges.Rows.Count > 0))
                {
                    projectTime2SectionGateway.Adapter.Update(projectTime2SectionChanges);
                }

                DB.CommitTransaction();
            }
            catch (DBConcurrencyException dBConcurrencyException)
            {
                DB.RollbackTransaction();
                throw new Exception("Concurrency error: Another user already updated the data you are working on.  Your operation has been cancelled.", dBConcurrencyException);
            }
            catch (SqlException sqlException)
            {
                DB.RollbackTransaction();
                byte severityLevel = sqlException.Class;
                if (severityLevel <= 16)
                {
                    throw new Exception("Low severity error. Your operation has been cancelled.  SQL Error " + severityLevel + ".");
                }
                if ((severityLevel >= 17) && (severityLevel <= 19))
                {
                    throw new Exception("Mid severity error. Your operation has been cancelled.  SQL Error " + severityLevel + ".");
                }
                if (severityLevel >= 20)
                {
                    throw new Exception("High severity error. Your operation has been cancelled.  SQL Error " + severityLevel + ".");
                }
            }
            catch (Exception e)
            {
                DB.RollbackTransaction();
                throw new Exception("Unknow error. Your operation has been cancelled.", e);
            }
            finally
            {
                DB.Close();
            }
        }
        /// <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;
        }
Example #11
0
        /// <summary>
        /// Insert
        /// </summary>
        /// <param name="projectTimeTDSToSave">projectTimeTDSToSave</param>
        public void Insert(ProjectTimeTDS projectTimeTDSToSave, int createdById)
        {
            foreach (ProjectTimeTDS.LFS_PROJECT_TIME_TEMPRow projectTimeRow in ((ProjectTimeTDS)Data).LFS_PROJECT_TIME_TEMP)
            {
                if (!projectTimeRow.Deleted)
                {
                    int employeeId = projectTimeRow.EmployeeID;
                    int companiesId = projectTimeRow.CompaniesID;
                    int projectId = projectTimeRow.ProjectID;
                    DateTime date_ = projectTimeRow.Date_;
                    DateTime? startTime = null;
                    if (!projectTimeRow.IsStartTimeNull())
                    {
                        string[] startTimeSplit = projectTimeRow.StartTime.Split(':');
                        int startTimeHour = Int32.Parse(startTimeSplit[0].ToString());
                        int startTimeMinute = Int32.Parse(startTimeSplit[1].ToString());
                        startTime = new DateTime(date_.Year, date_.Month, date_.Day, startTimeHour, startTimeMinute, 0);
                    }
                    DateTime? endTime = null;
                    if (!projectTimeRow.IsEndTimeNull())
                    {
                        string[] endTimeSplit = projectTimeRow.EndTime.Split(':');
                        int endTimeHour = Int32.Parse(endTimeSplit[0].ToString());
                        int endTimeMinute = Int32.Parse(endTimeSplit[1].ToString());
                        endTime = new DateTime(date_.Year, date_.Month, date_.Day, endTimeHour, endTimeMinute, 0);

                        if (endTime < startTime)
                        {
                            endTime.Value.AddDays(1);
                        }
                    }
                    double? offset = null; if (!projectTimeRow.IsOffsetNull()) offset = projectTimeRow.Offset;
                    string workingDetails = ""; if (!projectTimeRow.IsWorkingDetailsNull()) workingDetails = projectTimeRow.WorkingDetails;
                    string location = ""; if (!projectTimeRow.IsLocationNull()) location = projectTimeRow.Location;
                    Int64? mealsCountry = null; if (!projectTimeRow.IsMealsCountryNull()) mealsCountry = projectTimeRow.MealsCountry;
                    string mealsAllowanceType = ""; if (!projectTimeRow.IsMealsAllowanceTypeNull()) mealsAllowanceType = projectTimeRow.MealsAllowanceType;
                    decimal mealsAllowance = projectTimeRow.MealsAllowance;
                    string comments = ""; if (!projectTimeRow.IsCommentsNull()) comments = projectTimeRow.Comments;
                    int? unitId = null; if (!projectTimeRow.IsUnitIDNull()) unitId = projectTimeRow.UnitID;
                    int? towedUnitId = null; if (!projectTimeRow.IsTowedUnitIDNull()) towedUnitId = projectTimeRow.TowedUnitID;
                    string projectTimeState = projectTimeRow.ProjectTimeState;
                    bool deleted = projectTimeRow.Deleted;
                    string work_ = ""; if (!projectTimeRow.IsWork_Null()) work_ = projectTimeRow.Work_;
                    string function_ = ""; if (!projectTimeRow.IsFunction_Null()) function_ = projectTimeRow.Function_;
                    bool fairWage = projectTimeRow.FairWage;
                    string jobClassType = ""; if (!projectTimeRow.IsJobClassTypeNull()) jobClassType = projectTimeRow.JobClassType;

                    ProjectTime projectTimeToSave = new ProjectTime(Data);
                    projectTimeToSave.Insert(employeeId, companiesId, projectId, date_, startTime, endTime, offset, workingDetails, location, mealsCountry, mealsAllowanceType, mealsAllowance, unitId, towedUnitId, projectTimeState, comments, work_, function_, fairWage, jobClassType, createdById);
                }
            }
        }
        /// <summary>
        /// Insert
        /// </summary>
        /// <param name="projectTimeTDSToSave">projectTimeTDSToSave</param>
        public void Insert(ProjectTimeTDS projectTimeTDSToSave)
        {
            foreach (ProjectTimeTDS.LFS_PROJECT_TIME_SECTION_TEMPRow projectTimeSectionTempRow in ((ProjectTimeTDS)Data).LFS_PROJECT_TIME_SECTION_TEMP)
            {
                if (!projectTimeSectionTempRow.Deleted)
                {
                    int projectTimeId = projectTimeSectionTempRow.ProjectTimeID;
                    string sectionId = projectTimeSectionTempRow.SectionID;
                    string flowOrderId = projectTimeSectionTempRow.FlowOrderID;
                    bool completed = projectTimeSectionTempRow.Completed;
                    DateTime date_ = projectTimeSectionTempRow.Date_;
                    int percentageOpened = projectTimeSectionTempRow.PercentageOpened;
                    int percentageBrushed = projectTimeSectionTempRow.PercentageBrushed;
                    bool deleted = projectTimeSectionTempRow.Deleted;
                    int companyId = projectTimeSectionTempRow.COMPANY_ID;

                    ProjectTimeSection projectTimeSectionToSave = new ProjectTimeSection(Data);
                    projectTimeSectionToSave.Insert(projectTimeId, sectionId, flowOrderId, completed, date_, percentageOpened, percentageBrushed, deleted, companyId);
                }
            }
        }
        private bool PostStepEndChanges(int companyId)
        {
            // Update project times
            projectTime2TDS = new ProjectTimeTDS();
            if (cbxEndConfirm.Checked)
            {
                EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
                int employeeId = employeeGateway.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));

                TeamProjectTime2Detail teamProjectTime2Detail = new TeamProjectTime2Detail(teamProjectTime2TDS);
                string error = teamProjectTime2Detail.MoveToProjectTime(projectTime2TDS, (string)ViewState["LHMode"], Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]), ddlTypeOfWork.SelectedValue, ddlFunction.SelectedValue, companyId, employeeId);

                if (error != "")
                {
                    return false;
                }
            }

            // Update team project time
            teamProjectTime2TDSToSave = new TeamProjectTime2TDS();
            if (cbxEndSave.Checked)
            {
                TeamProjectTime2 teamProjectTime2 = new TeamProjectTime2(teamProjectTime2TDS);
                if (rbtnEndSaveNew.Checked)
                {
                    teamProjectTime2.Insert((int)ViewState["teamProjectTimeId"], tbxEndSaveNew.Text.Trim(), teamProjectTime2TDSToSave);
                }
                else
                {
                    teamProjectTime2.Update((int)ViewState["teamProjectTimeId"], int.Parse(luEndSaveTemplate.SelectedValue.ToString()), teamProjectTime2TDSToSave);
                }
            }

            return true;
        }