// //////////////////////////////////////////////////////////////////////// // PUBLIC METHODS // /// <summary> /// UpdateForProcess /// </summary> public void UpdateForReport(int projectId, int companiesId, int companyId) { CompaniesGateway companiesGateway = new CompaniesGateway(); companiesGateway.LoadAllByCompaniesId(companiesId, companyId); // For LFS_PROJECT_SUBCONTRACTORS // ... for subcontractor Name foreach (ProjectSynopsisReportTDS.LFS_PROJECT_SUBCONTRACTORRow row in this.Table.Rows) { if (row.ProjectID == projectId) { companiesGateway.LoadAllByCompaniesId((int)row.SubcontractorID, companyId); try { row.Name = companiesGateway.GetName((int)row.SubcontractorID); } catch { row.Name = ""; } } } }
// //////////////////////////////////////////////////////////////////////// // EVENTS // protected void Page_Load(object sender, EventArgs e) { // Register client scripts this.RegisterClientScripts(); if (!IsPostBack) { // Security check if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_VIEW"])) { Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator."); } // Validate query string if (Request.QueryString["source_page"] == null) { Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in project_sections_navigator2.aspx"); } projectTDS = (ProjectTDS)Session["lfsProjectTDS"]; assetsTDS = new AssetsTDS(); lfsAssetsTDS = new LfsAssetsTDS(); workTDS = new WorkTDS(); // Tag page hdfCompanyId.Value = Session["companyID"].ToString(); hdfProjectId.Value = Request.QueryString["project_id"]; hdfDataChanged.Value = Request.QueryString["data_changed"]; hdfDataChangedMessage.Value = "Changes made to this project will not be saved."; ViewState["state"] = Request.QueryString["state"]; ViewState["active_tab"] = Request.QueryString["active_tab"]; ViewState["origin"] = Request.QueryString["origin"]; ViewState["update"] = Request.QueryString["update"]; Session.Remove("projectSectionsNavigatorNewDummy"); Session.Remove("projectSectionsNavigator"); // Prepare initial data lblError.Visible = false; // ... for project int currentProjectId = Int32.Parse(hdfProjectId.Value.ToString()); ProjectGateway projectGateway = new ProjectGateway(); projectGateway.LoadByProjectId(currentProjectId); string name = projectGateway.GetName(currentProjectId); if (name.Length > 23) name = name.Substring(0, 20) + "..."; lblTitleProjectName.Text = name + " (" + projectGateway.GetProjectNumber(currentProjectId) + ")"; // ... for client int companyId = Int32.Parse(hdfCompanyId.Value.Trim()); int currentClientId = projectGateway.GetClientID(Int32.Parse(hdfProjectId.Value.ToString())); CompaniesGateway companiesGateway = new CompaniesGateway(); companiesGateway.LoadAllByCompaniesId(currentClientId, companyId); lblTitleClientName.Text = "Client: " + companiesGateway.GetName(currentClientId); hdfClientId.Value = projectGateway.GetClientID(int.Parse(hdfProjectId.Value)).ToString(); // Store navigator state at projects navigator StoreNavigatorState(); // ... project_sections_navigator.aspx or project_sections_navigator2.aspx if ((Request.QueryString["source_page"] == "project_sections_navigator.aspx") || (Request.QueryString["source_page"] == "project_sections_navigator2.aspx")) { // Restore navigator state RestoreNavigatorState(); // Restore data projectSectionsNavigatorTDS = (ProjectSectionsNavigatorTDS)Session["lfsProjectSectionsNavigatorTDS"]; projectSectionsNavigator = projectSectionsNavigatorTDS.LFS_PROJECT_SECTIONS_NAVIGATOR; // Store data Session["projectSectionsNavigator"] = projectSectionsNavigatorTDS.LFS_PROJECT_SECTIONS_NAVIGATOR; if (Request.QueryString["update_section"] == "no") { // Restore data projectSectionsNavigatorTDS = (ProjectSectionsNavigatorTDS)Session["lfsProjectSectionsNavigatorTDS"]; projectSectionsNavigator = projectSectionsNavigatorTDS.LFS_PROJECT_SECTIONS_NAVIGATOR; // Store data Session["projectSectionsNavigator"] = projectSectionsNavigatorTDS.LFS_PROJECT_SECTIONS_NAVIGATOR; } else { // ... Delete store data Session.Contents.Remove("lfsProjectSectionsNavigatorTDS"); // ... Search data with updates projectSectionsNavigatorTDS = SubmitSearch(); // ... store datasets Session["lfsProjectSectionsNavigatorTDS"] = projectSectionsNavigatorTDS; Session["projectSectionsNavigator"] = projectSectionsNavigatorTDS.LFS_PROJECT_SECTIONS_NAVIGATOR; } //... for the total rows if (projectSectionsNavigatorTDS.LFS_PROJECT_SECTIONS_NAVIGATOR.Rows.Count > 0) { lblTotalRows.Text = "Total Rows: " + projectSectionsNavigatorTDS.LFS_PROJECT_SECTIONS_NAVIGATOR.Rows.Count; lblTotalRows.Visible = true; } else { lblTotalRows.Visible = false; } } } else { // Restore dataset projectTDS = (ProjectTDS)Session["lfsProjectTDS"]; projectSectionsNavigatorTDS = (ProjectSectionsNavigatorTDS)Session["lfsProjectSectionsNavigatorTDS"]; assetsTDS = (AssetsTDS)Session["assetsTDS"]; lfsAssetsTDS = (LfsAssetsTDS)Session["lfsAssetsTDS"]; workTDS = (WorkTDS)Session["workTDS"]; // ... for project int currentProjectId = Int32.Parse(hdfProjectId.Value.ToString()); ProjectGateway projectGateway = new ProjectGateway(); projectGateway.LoadByProjectId(currentProjectId); string name = projectGateway.GetName(currentProjectId); if (name.Length > 23) name = name.Substring(0, 20) + "..."; lblTitleProjectName.Text = name + " (" + projectGateway.GetProjectNumber(currentProjectId) + ")"; // ... for client int companyId = Int32.Parse(hdfCompanyId.Value); int currentClientId = projectGateway.GetClientID(Int32.Parse(hdfProjectId.Value.ToString())); CompaniesGateway companiesGateway = new CompaniesGateway(); companiesGateway.LoadAllByCompaniesId(currentClientId, companyId); lblTitleClientName.Text = "Client: " + companiesGateway.GetName(currentClientId); // Restore searched data (if any) projectSectionsNavigatorTDS = (ProjectSectionsNavigatorTDS)Session["lfsProjectSectionsNavigatorTDS"]; projectSectionsNavigator = projectSectionsNavigatorTDS.LFS_PROJECT_SECTIONS_NAVIGATOR; //... for the total rows if (projectSectionsNavigatorTDS.LFS_PROJECT_SECTIONS_NAVIGATOR.Rows.Count > 0) { lblTotalRows.Text = "Total Rows: " + projectSectionsNavigatorTDS.LFS_PROJECT_SECTIONS_NAVIGATOR.Rows.Count; } else { lblTotalRows.Visible = false; } } }
// //////////////////////////////////////////////////////////////////////// // 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) && ((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"]; } }
// //////////////////////////////////////////////////////////////////////// // INITIAL EVENTS // protected void Page_Load(object sender, EventArgs e) { // Register client scripts this.RegisterClientScripts(); if (!IsPostBack) { // Security check if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_COSTINGSHEETS_ADMIN"])) { if (!(Convert.ToBoolean(Session["sgLFS_PROJECTS_COSTINGSHEETS_VIEW"]) && Convert.ToBoolean(Session["sgLFS_PROJECTS_COSTINGSHEETS_EDIT"]))) { 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["costing_sheet_id"] == null)) { Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in project_combined_costing_sheets_edit.aspx"); } // Tag Page hdfCostingSheetId.Value = Request.QueryString["costing_sheet_id"].ToString(); hdfCompanyId.Value = Session["companyID"].ToString(); hdfProjectId.Value = Request.QueryString["project_id"]; hdfDataChanged.Value = Request.QueryString["data_changed"]; hdfDataChangedMessage.Value = "Changes made to this project will not be saved."; ViewState["state"] = Request.QueryString["state"]; ViewState["active_tab"] = Request.QueryString["active_tab"]; ViewState["origin"] = Request.QueryString["origin"]; ViewState["update"] = Request.QueryString["update"]; projectTDS = (ProjectTDS)Session["lfsProjectTDS"]; Session.Remove("labourHoursInformationDummy"); Session.Remove("unitsInformationDummy"); Session.Remove("subcontractorsInformationDummy"); Session.Remove("materialsInformationDummy"); Session.Remove("otherCostsInformationDummy"); Session.Remove("revenueInformationDummy"); // If coming from project_combined_costing_sheets_navigator.aspx or project_combined_costing_sheets_add.aspx int companyId = Int32.Parse(hdfCompanyId.Value); if (Request.QueryString["source_page"] == "project_costing_sheets_navigator.aspx" || Request.QueryString["source_page"] == "project_combined_costing_sheets_add.aspx") { // Store Navigator State and Update control StoreNavigatorState(); ViewState["update"] = "no"; // Get Costing sheet ID int costingSheetId = Int32.Parse(hdfCostingSheetId.Value.Trim()); // Get dataset projectTDS = (ProjectTDS)Session["lfsProjectTDS"]; projectCostingSheetInformationTDS = new ProjectCostingSheetInformationTDS(); labourHoursInformation = new ProjectCostingSheetInformationTDS.CombinedLabourHoursInformationDataTable(); unitsInformation = new ProjectCostingSheetInformationTDS.CombinedUnitsInformationDataTable(); subcontractorsInformation = new ProjectCostingSheetInformationTDS.CombinedSubcontractorsInformationDataTable(); materialsInformation = new ProjectCostingSheetInformationTDS.CombinedMaterialsInformationDataTable(); otherCostsInformation = new ProjectCostingSheetInformationTDS.CombinedOtherCostsInformationDataTable(); revenueInformation = new ProjectCostingSheetInformationTDS.CombinedRevenueInformationDataTable(); // Get General Data ProjectCombinedCostingSheetInformationBasicInformation projectCostingSheetInformationBasicInformation = new ProjectCombinedCostingSheetInformationBasicInformation(projectCostingSheetInformationTDS); projectCostingSheetInformationBasicInformation.LoadByCostingSheetId(costingSheetId, companyId); ProjectCombinedCostingSheetInformationLabourHoursInformationGateway projectCostingSheetInformationLabourHoursInformationGateway = new ProjectCombinedCostingSheetInformationLabourHoursInformationGateway(projectCostingSheetInformationTDS); projectCostingSheetInformationLabourHoursInformationGateway.LoadByCostingSheetId(costingSheetId, companyId); ProjectCombinedCostingSheetInformationUnitsInformationGateway projectCostingSheetInformationUnitsInformationGateway = new ProjectCombinedCostingSheetInformationUnitsInformationGateway(projectCostingSheetInformationTDS); projectCostingSheetInformationUnitsInformationGateway.LoadByCostingSheetId(costingSheetId, companyId); ProjectCombinedCostingSheetInformationSubcontractorsInformationGateway projectCostingSheetInformationSubcontractorsInformationGateway = new ProjectCombinedCostingSheetInformationSubcontractorsInformationGateway(projectCostingSheetInformationTDS); projectCostingSheetInformationSubcontractorsInformationGateway.LoadByCostingSheetId(costingSheetId, companyId); ProjectCombinedCostingSheetInformationMaterialsInformationGateway projectCostingSheetInformationMaterialsInformationGateway = new ProjectCombinedCostingSheetInformationMaterialsInformationGateway(projectCostingSheetInformationTDS); projectCostingSheetInformationMaterialsInformationGateway.LoadByCostingSheetId(costingSheetId, companyId); ProjectCombinedCostingSheetInformationOtherCostsInformationGateway projectCostingSheetInformationOtherCostsInformationGateway = new ProjectCombinedCostingSheetInformationOtherCostsInformationGateway(projectCostingSheetInformationTDS); projectCostingSheetInformationOtherCostsInformationGateway.LoadByCostingSheetId(costingSheetId, companyId); projectCombinedCostingSheetInformationRevenueInformationGateway projectCombinedCostingSheetInformationRevenueInformationGateway = new projectCombinedCostingSheetInformationRevenueInformationGateway(projectCostingSheetInformationTDS); projectCombinedCostingSheetInformationRevenueInformationGateway.LoadByCostingSheetId(costingSheetId, companyId); Session["lfsProjectTDS"] = projectTDS; Session["projectCostingSheetInformationTDS"] = projectCostingSheetInformationTDS; Session["labourHoursInformation"] = projectCostingSheetInformationTDS.CombinedLabourHoursInformation; Session["unitsInformation"] = projectCostingSheetInformationTDS.CombinedUnitsInformation; Session["subcontractorsInformation"] = projectCostingSheetInformationTDS.CombinedSubcontractorsInformation; Session["materialsInformation"] = projectCostingSheetInformationTDS.CombinedMaterialsInformation; Session["otherCostsInformation"] = projectCostingSheetInformationTDS.CombinedOtherCostsInformation; Session["revenueInformation"] = projectCostingSheetInformationTDS.CombinedRevenueInformation; labourHoursInformation = projectCostingSheetInformationTDS.CombinedLabourHoursInformation; unitsInformation = projectCostingSheetInformationTDS.CombinedUnitsInformation; subcontractorsInformation = projectCostingSheetInformationTDS.CombinedSubcontractorsInformation; materialsInformation = projectCostingSheetInformationTDS.CombinedMaterialsInformation; otherCostsInformation = projectCostingSheetInformationTDS.CombinedOtherCostsInformation; revenueInformation = projectCostingSheetInformationTDS.CombinedRevenueInformation; } // ... project_combined_costing_sheets_add.aspx if (Request.QueryString["source_page"] == "project_combined_costing_sheets_add.aspx") { ViewState["update"] = "yes"; } // ... left menu, project_combined_costing_sheets_edit.aspx, project_combined_costing_sheets_delete.aspx or project_combined_costing_sheets_state.aspx if ((Request.QueryString["source_page"] == "lm") || (Request.QueryString["source_page"] == "project_combined_costing_sheets_summary.aspx") || (Request.QueryString["source_page"] == "project_combined_costing_sheets_delete.aspx") || (Request.QueryString["source_page"] == "project_combined_costing_sheets_state.aspx")) { // Store Navigator State and Update control StoreNavigatorState(); ViewState["update"] = Request.QueryString["update"]; } // Restore dataset projectTDS = (ProjectTDS)Session["lfsProjectTDS"]; projectCostingSheetInformationTDS = (ProjectCostingSheetInformationTDS)Session["projectCostingSheetInformationTDS"]; labourHoursInformation = (ProjectCostingSheetInformationTDS.CombinedLabourHoursInformationDataTable)Session["labourHoursInformation"]; unitsInformation = (ProjectCostingSheetInformationTDS.CombinedUnitsInformationDataTable)Session["unitsInformation"]; subcontractorsInformation = (ProjectCostingSheetInformationTDS.CombinedSubcontractorsInformationDataTable)Session["subcontractorsInformation"]; materialsInformation = (ProjectCostingSheetInformationTDS.CombinedMaterialsInformationDataTable)Session["materialsInformation"]; otherCostsInformation = (ProjectCostingSheetInformationTDS.CombinedOtherCostsInformationDataTable)Session["otherCostsInformation"]; revenueInformation = (ProjectCostingSheetInformationTDS.CombinedRevenueInformationDataTable)Session["revenueInformation"]; if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_COSTINGSHEETS_ADMIN"])) { // Costing Sheet state check ProjectCombinedCostingSheetInformationBasicInformationGateway projectCostingSheetInformationBasicInformationGatewayForValidate = new ProjectCombinedCostingSheetInformationBasicInformationGateway(projectCostingSheetInformationTDS); string state = projectCostingSheetInformationBasicInformationGatewayForValidate.GetState(Int32.Parse(hdfCostingSheetId.Value)); if (state == "Approved") { Response.Redirect("./../../error_page.aspx?error=" + "This costing sheet is approved, you can not edit it."); } } ProjectGateway projectGateway = new ProjectGateway(projectTDS); hdfClientId.Value = projectGateway.GetClientID(Int32.Parse(hdfProjectId.Value.ToString())).ToString(); // ... for project int currentProjectId = Int32.Parse(hdfProjectId.Value.ToString()); string name = projectGateway.GetName(currentProjectId); if (name.Length > 23) name = name.Substring(0, 20) + "..."; lblTitleProjectName.Text = name + " (" + projectGateway.GetProjectNumber(currentProjectId) + ")"; // ... for client int currentClientId = projectGateway.GetClientID(Int32.Parse(hdfProjectId.Value.ToString())); CompaniesGateway companiesGateway = new CompaniesGateway(); companiesGateway.LoadAllByCompaniesId(currentClientId, companyId); lblTitleClientName.Text = "Client: " + companiesGateway.GetName(currentClientId); LoadBasicData(); } else { // Restore dataset projectTDS = (ProjectTDS)Session["lfsProjectTDS"]; projectCostingSheetInformationTDS = (ProjectCostingSheetInformationTDS)Session["projectCostingSheetInformationTDS"]; labourHoursInformation = (ProjectCostingSheetInformationTDS.CombinedLabourHoursInformationDataTable)Session["labourHoursInformation"]; unitsInformation = (ProjectCostingSheetInformationTDS.CombinedUnitsInformationDataTable)Session["unitsInformation"]; subcontractorsInformation = (ProjectCostingSheetInformationTDS.CombinedSubcontractorsInformationDataTable)Session["subcontractorsInformation"]; materialsInformation = (ProjectCostingSheetInformationTDS.CombinedMaterialsInformationDataTable)Session["materialsInformation"]; otherCostsInformation = (ProjectCostingSheetInformationTDS.CombinedOtherCostsInformationDataTable)Session["otherCostsInformation"]; revenueInformation = (ProjectCostingSheetInformationTDS.CombinedRevenueInformationDataTable)Session["revenueInformation"]; } }
// //////////////////////////////////////////////////////////////////////// // PUBLIC METHODS // /// <summary> /// Load /// </summary> /// <param name="works">works</param> /// <param name="projectId">projectId</param> /// <param name="startDate">startDate</param> /// <param name="endDate">endDate</param> /// <param name="companyId">companyId</param> public void Load(ArrayList works, int projectId, DateTime startDate, DateTime endDate, int companyId, string month) { ProjectGateway projectGateway = new ProjectGateway(); projectGateway.LoadByProjectId(projectId); string projectName = projectGateway.GetName(projectId); int clientId = projectGateway.GetClientID(projectId); CompaniesGateway companiesGateway = new CompaniesGateway(); companiesGateway.LoadAllByCompaniesId(clientId, companyId); string clientName = companiesGateway.GetName(clientId); // General vars int overtimeByCountry = 40; //Default for USA Projects int refId = GetNewRefId(); // Foreach of Works (FLL, RA, JL, PR, MH Rehab, MOB, Other) foreach (string work_ in works) { // Load Functions by Work ProjectCostingSheetAddFunctionListGateway projectCostingSheetAddFunctionListGateway = new ProjectCostingSheetAddFunctionListGateway(); projectCostingSheetAddFunctionListGateway.LoadByWork_(work_); // Foreach of Functions foreach (ProjectCostingSheetAddTDS.FunctionListRow functionListRow in (ProjectCostingSheetAddTDS.FunctionListDataTable)projectCostingSheetAddFunctionListGateway.Table) { // Load Employees by ProjectId, StartDate, EndDate, Work ProjectCostingSheetAddEmployeeListGateway projectCostingSheetAddEmployeeListGateway = new ProjectCostingSheetAddEmployeeListGateway(Data); projectCostingSheetAddEmployeeListGateway.LoadByProjectIdStartDateEndDateWorkFunction(projectId, startDate, endDate, work_, functionListRow.Function_, companyId); foreach (ProjectCostingSheetAddTDS.EmployeeListRow employeeListRow in (ProjectCostingSheetAddTDS.EmployeeListDataTable)projectCostingSheetAddEmployeeListGateway.Table) { DateTime newStartDate = new DateTime(); newStartDate = startDate; DateTime newEndDate = new DateTime(); newEndDate = endDate; //If Project is from Canada we get overtime if (projectGateway.GetCountryID(projectId) == 1) { //Get Category of Employee EmployeeGateway employeeGateway = new EmployeeGateway(); employeeGateway.LoadByEmployeeId(employeeListRow.EmployeeID); switch (employeeGateway.GetCategory(employeeListRow.EmployeeID)) { case "Special Forces": overtimeByCountry = 50; break; case "Field": overtimeByCountry = 50; break; case "Field 44": overtimeByCountry = 44; break; case "Office/Admin": overtimeByCountry = 44; break; case "Mechanic/Manufactoring": overtimeByCountry = 44; break; } } ProjectCostingSheetAddEmployeePayPeriodGateway projectCostingSheetAddEmployeePayPeriodGateway = new ProjectCostingSheetAddEmployeePayPeriodGateway(Data); projectCostingSheetAddEmployeePayPeriodGateway.LoadByStartDateEndDateEmployeeId(startDate, endDate, employeeListRow.EmployeeID); if (projectCostingSheetAddEmployeePayPeriodGateway.Table.Rows.Count > 0) { foreach (ProjectCostingSheetAddTDS.EmployeePayPeriodRow employeePayPeriodRow in (ProjectCostingSheetAddTDS.EmployeePayPeriodDataTable)projectCostingSheetAddEmployeePayPeriodGateway.Table) { newEndDate = employeePayPeriodRow.Date_.AddDays(-1); ProjectCostingSheetAddOriginalLabourHourGateway projectCostingSheetAddOriginalLabourHourGateway = new ProjectCostingSheetAddOriginalLabourHourGateway(Data); projectCostingSheetAddOriginalLabourHourGateway.LoadByProjectStartDateEndDateWorkFunctionEmployeeId(projectId, newStartDate, newEndDate, work_, functionListRow.Function_, employeeListRow.EmployeeID); if (projectCostingSheetAddOriginalLabourHourGateway.Table.Rows.Count > 0) { double lhQuantity = 0; double overtime = 0; decimal mealsQuantity = 0; decimal motelQuantity = 0; string employeeName = ""; refId++; foreach (ProjectCostingSheetAddTDS.OriginalLabourHourRow originalRow in (ProjectCostingSheetAddTDS.OriginalLabourHourDataTable)projectCostingSheetAddOriginalLabourHourGateway.Table) { employeeName = originalRow.EmployeeName; // Meal hours quantity if (!originalRow.IsMealsCountryNull()) { if (originalRow.MealsAllowance > 0) { mealsQuantity++; } } double acumPeriod = GetTotalHoursByEmployeeIdPeriodId(originalRow.EmployeeID, originalRow.Date_, originalRow.ProjectTimeID); if (acumPeriod > overtimeByCountry) { overtime = overtime + originalRow.ProjectTime; } else { double newAcumPeriod = acumPeriod + originalRow.ProjectTime; if (newAcumPeriod > overtimeByCountry) { overtime = overtime + (newAcumPeriod - overtimeByCountry); lhQuantity = lhQuantity + (originalRow.ProjectTime - (newAcumPeriod - overtimeByCountry)); } else { lhQuantity = lhQuantity + originalRow.ProjectTime; } } } if (lhQuantity > 0) { ProjectCostingSheetAddTDS.LabourHoursInformationRow newRow = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow(); GetEmployeeData(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRow);// ... Get Costs newRow.CostingSheetID = 0; newRow.Work_ = work_; newRow.EmployeeID = employeeListRow.EmployeeID; newRow.RefID = refId; newRow.LHQuantity = lhQuantity; newRow.MealsQuantity = Convert.ToInt32(mealsQuantity); if (mealsQuantity > 0) newRow.MealsUnitOfMeasurement = "Day"; else newRow.MealsUnitOfMeasurement = ""; if (motelQuantity > 0) newRow.MotelUnitOfMeasurement = "Day"; else newRow.MotelUnitOfMeasurement = ""; newRow.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day"); newRow.MotelCostCad = 0; newRow.TotalCostCad = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostCad, 2)) + (mealsQuantity * newRow.MealsCostCad) + (motelQuantity * newRow.MotelCostCad); newRow.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day"); newRow.MotelCostUsd = 0; newRow.TotalCostUsd = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostUsd, 2)) + (mealsQuantity * newRow.MealsCostUsd) + (motelQuantity * newRow.MotelCostUsd); newRow.Deleted = false; newRow.InDatabase = false; newRow.COMPANY_ID = companyId; newRow.Name = employeeName; newRow.StartDate = newStartDate; newRow.EndDate = newEndDate; newRow.FromDatabase = true; newRow.Function_ = functionListRow.Function_; newRow.WorkFunction = work_ + " . " + functionListRow.Function_; newRow.Month = month; newRow.ClientName = clientName; newRow.ProjectName = projectName; ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRow); } if (overtime > 0) { refId++; ProjectCostingSheetAddTDS.LabourHoursInformationRow newRowOt = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow(); GetEmployeeDataOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt);// ... Get Costs for Overtime newRowOt.CostingSheetID = projectId; newRowOt.Work_ = work_; newRowOt.EmployeeID = employeeListRow.EmployeeID; newRowOt.RefID = refId; newRowOt.LHQuantity = overtime; newRowOt.MealsQuantity = 0;//This is 0 because this row is only for overtime data mealsQuantity = 0; motelQuantity = 0; newRowOt.MealsUnitOfMeasurement = ""; newRowOt.MotelUnitOfMeasurement = ""; newRowOt.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day"); newRowOt.MotelCostCad = 0; newRowOt.TotalCostCad = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostCad, 2)); newRowOt.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day"); newRowOt.MotelCostUsd = 0; newRowOt.TotalCostUsd = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostUsd, 2)); newRowOt.Deleted = false; newRowOt.InDatabase = false; newRowOt.COMPANY_ID = companyId; newRowOt.Name = employeeName + " - Overtime"; newRowOt.StartDate = newStartDate; newRowOt.EndDate = newEndDate; newRowOt.FromDatabase = true; newRowOt.Function_ = functionListRow.Function_; newRowOt.WorkFunction = work_ + " . " + functionListRow.Function_; newRowOt.Month = month; newRowOt.ClientName = clientName; newRowOt.ProjectName = projectName; ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRowOt); } } newStartDate = newEndDate.AddDays(1); } if (newEndDate <= endDate) { ProjectCostingSheetAddOriginalLabourHourGateway projectCostingSheetAddOriginalLabourHourGateway = new ProjectCostingSheetAddOriginalLabourHourGateway(Data); projectCostingSheetAddOriginalLabourHourGateway.LoadByProjectStartDateEndDateWorkFunctionEmployeeId(projectId, newStartDate, endDate, work_, functionListRow.Function_, employeeListRow.EmployeeID); if (projectCostingSheetAddOriginalLabourHourGateway.Table.Rows.Count > 0) { double lhQuantity = 0; double overtime = 0; decimal mealsQuantity = 0; decimal motelQuantity = 0; string employeeName = ""; refId++; foreach (ProjectCostingSheetAddTDS.OriginalLabourHourRow originalRow in (ProjectCostingSheetAddTDS.OriginalLabourHourDataTable)projectCostingSheetAddOriginalLabourHourGateway.Table) { employeeName = originalRow.EmployeeName; // Meal hours quantity if (!originalRow.IsMealsCountryNull()) { if (originalRow.MealsAllowance > 0) { mealsQuantity++; } } double acumPeriod = GetTotalHoursByEmployeeIdPeriodId(originalRow.EmployeeID, originalRow.Date_, originalRow.ProjectTimeID); if (acumPeriod > overtimeByCountry) { overtime = overtime + originalRow.ProjectTime; } else { double newAcumPeriod = acumPeriod + originalRow.ProjectTime; if (newAcumPeriod > overtimeByCountry) { overtime = overtime + (newAcumPeriod - overtimeByCountry); lhQuantity = lhQuantity + (originalRow.ProjectTime - (newAcumPeriod - overtimeByCountry)); } else { lhQuantity = lhQuantity + originalRow.ProjectTime; } } } if (lhQuantity > 0) { ProjectCostingSheetAddTDS.LabourHoursInformationRow newRow = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow(); GetEmployeeData(newStartDate, endDate, employeeListRow.EmployeeID, work_, newRow); newRow.CostingSheetID = 0; newRow.Work_ = work_; newRow.EmployeeID = employeeListRow.EmployeeID; newRow.RefID = refId; newRow.LHQuantity = lhQuantity; newRow.MealsQuantity = Convert.ToInt32(mealsQuantity); if (mealsQuantity > 0) newRow.MealsUnitOfMeasurement = "Day"; else newRow.MealsUnitOfMeasurement = ""; if (motelQuantity > 0) newRow.MotelUnitOfMeasurement = "Day"; else newRow.MotelUnitOfMeasurement = ""; newRow.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day"); newRow.MotelCostCad = 0; newRow.TotalCostCad = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostCad, 2)) + (mealsQuantity * newRow.MealsCostCad) + (motelQuantity * newRow.MotelCostCad); newRow.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day"); newRow.MotelCostUsd = 0; newRow.TotalCostUsd = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostUsd, 2)) + (mealsQuantity * newRow.MealsCostUsd) + (motelQuantity * newRow.MotelCostUsd); newRow.Deleted = false; newRow.InDatabase = false; newRow.COMPANY_ID = companyId; newRow.Name = employeeName; newRow.StartDate = newStartDate; newRow.EndDate = endDate; newRow.FromDatabase = true; newRow.Function_ = functionListRow.Function_; newRow.WorkFunction = work_ + " . " + functionListRow.Function_; newRow.Month = month; newRow.ClientName = clientName; newRow.ProjectName = projectName; ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRow); } if (overtime > 0) { refId++; ProjectCostingSheetAddTDS.LabourHoursInformationRow newRowOt = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow(); GetEmployeeDataOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt);// ... Get Costs for Overtime newRowOt.CostingSheetID = 0; newRowOt.Work_ = work_; newRowOt.EmployeeID = employeeListRow.EmployeeID; newRowOt.RefID = refId; newRowOt.LHQuantity = overtime; newRowOt.MealsQuantity = 0;//This is 0 because this row is only for overtime data mealsQuantity = 0; motelQuantity = 0; newRowOt.MealsUnitOfMeasurement = ""; newRowOt.MotelUnitOfMeasurement = ""; newRowOt.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day"); newRowOt.MotelCostCad = 0; newRowOt.TotalCostCad = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostCad, 2)); newRowOt.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day"); newRowOt.MotelCostUsd = 0; newRowOt.TotalCostUsd = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostUsd, 2)); newRowOt.Deleted = false; newRowOt.InDatabase = false; newRowOt.COMPANY_ID = companyId; newRowOt.Name = employeeName + " - Overtime"; newRowOt.StartDate = newStartDate; newRowOt.EndDate = endDate; newRowOt.FromDatabase = true; newRowOt.Function_ = functionListRow.Function_; newRowOt.WorkFunction = work_ + " . " + functionListRow.Function_; newRowOt.Month = month; newRowOt.ClientName = clientName; newRowOt.ProjectName = projectName; ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRowOt); } } } } else { ProjectCostingSheetAddOriginalLabourHourGateway projectCostingSheetAddOriginalLabourHourGateway = new ProjectCostingSheetAddOriginalLabourHourGateway(Data); projectCostingSheetAddOriginalLabourHourGateway.LoadByProjectStartDateEndDateWorkFunctionEmployeeId(projectId, startDate, endDate, work_, functionListRow.Function_, employeeListRow.EmployeeID); if (projectCostingSheetAddOriginalLabourHourGateway.Table.Rows.Count > 0) { double lhQuantity = 0; double overtime = 0; decimal mealsQuantity = 0; decimal motelQuantity = 0; string employeeName = ""; refId++; foreach (ProjectCostingSheetAddTDS.OriginalLabourHourRow originalRow in (ProjectCostingSheetAddTDS.OriginalLabourHourDataTable)projectCostingSheetAddOriginalLabourHourGateway.Table) { employeeName = originalRow.EmployeeName; // Meal hours quantity if (!originalRow.IsMealsCountryNull()) { if (originalRow.MealsAllowance > 0) { mealsQuantity++; } } double acumPeriod = GetTotalHoursByEmployeeIdPeriodId(originalRow.EmployeeID, originalRow.Date_, originalRow.ProjectTimeID); if (acumPeriod > overtimeByCountry) { overtime = overtime + originalRow.ProjectTime; } else { double newAcumPeriod = acumPeriod + originalRow.ProjectTime; if (newAcumPeriod > overtimeByCountry) { overtime = overtime + (newAcumPeriod - overtimeByCountry); lhQuantity = lhQuantity + (originalRow.ProjectTime - (newAcumPeriod - overtimeByCountry)); } else { lhQuantity = lhQuantity + originalRow.ProjectTime; } } } if (lhQuantity > 0) { ProjectCostingSheetAddTDS.LabourHoursInformationRow newRow = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow(); GetEmployeeData(startDate, endDate, employeeListRow.EmployeeID, work_, newRow); newRow.CostingSheetID = 0; newRow.Work_ = work_; newRow.EmployeeID = employeeListRow.EmployeeID; newRow.RefID = refId; newRow.LHQuantity = lhQuantity; newRow.MealsQuantity = Convert.ToInt32(mealsQuantity); if (mealsQuantity > 0) newRow.MealsUnitOfMeasurement = "Day"; else newRow.MealsUnitOfMeasurement = ""; if (motelQuantity > 0) newRow.MotelUnitOfMeasurement = "Day"; else newRow.MotelUnitOfMeasurement = ""; newRow.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day"); newRow.MotelCostCad = 0; newRow.TotalCostCad = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostCad, 2)) + (mealsQuantity * newRow.MealsCostCad) + (motelQuantity * newRow.MotelCostCad); newRow.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day"); newRow.MotelCostUsd = 0; newRow.TotalCostUsd = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostUsd, 2)) + (mealsQuantity * newRow.MealsCostUsd) + (motelQuantity * newRow.MotelCostUsd); newRow.Deleted = false; newRow.InDatabase = false; newRow.COMPANY_ID = companyId; newRow.Name = employeeName; newRow.StartDate = startDate; newRow.EndDate = endDate; newRow.FromDatabase = true; newRow.Function_ = functionListRow.Function_; newRow.WorkFunction = work_ + " . " + functionListRow.Function_; newRow.Month = month; newRow.ClientName = clientName; newRow.ProjectName = projectName; ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRow); } if (overtime > 0) { refId++; ProjectCostingSheetAddTDS.LabourHoursInformationRow newRowOt = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow(); GetEmployeeDataOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt);// ... Get Costs for Overtime newRowOt.CostingSheetID = 0; newRowOt.Work_ = work_; newRowOt.EmployeeID = employeeListRow.EmployeeID; newRowOt.RefID = refId; newRowOt.LHQuantity = overtime; newRowOt.MealsQuantity = 0;//This is 0 because this row is only for overtime data mealsQuantity = 0; motelQuantity = 0; newRowOt.MealsUnitOfMeasurement = ""; newRowOt.MotelUnitOfMeasurement = ""; newRowOt.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day"); newRowOt.MotelCostCad = 0; newRowOt.TotalCostCad = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostCad, 2)); newRowOt.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day"); newRowOt.MotelCostUsd = 0; newRowOt.TotalCostUsd = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostUsd, 2)); newRowOt.Deleted = false; newRowOt.InDatabase = false; newRowOt.COMPANY_ID = companyId; newRowOt.Name = employeeName + " - Overtime"; newRowOt.StartDate = startDate; newRowOt.EndDate = endDate; newRowOt.FromDatabase = true; newRowOt.Function_ = functionListRow.Function_; newRowOt.WorkFunction = work_ + " . " + functionListRow.Function_; newRowOt.Month = month; newRowOt.ClientName = clientName; newRowOt.ProjectName = projectName; ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRowOt); } } } } } } }
/// <summary> /// LoadFairWageProject /// </summary> /// <param name="works">works</param> /// <param name="jobClassType">jobClassType</param> /// <param name="projectId">projectId</param> /// <param name="startDate">startDate</param> /// <param name="endDate">endDate</param> /// <param name="companyId">companyId</param> public void LoadFairWageProject(ArrayList works, ArrayList jobClassType, int projectId, DateTime startDate, DateTime endDate, int companyId, string month) { ProjectGateway projectGateway = new ProjectGateway(); projectGateway.LoadByProjectId(projectId); string projectName = projectGateway.GetName(projectId); int clientId = projectGateway.GetClientID(projectId); CompaniesGateway companiesGateway = new CompaniesGateway(); companiesGateway.LoadAllByCompaniesId(clientId, companyId); string clientName = companiesGateway.GetName(clientId); // General vars int overtimeByCountry = 40; //Default for USA Projects int refId = GetNewRefId(); int countryId = 1; //Default Canada if (projectGateway.GetCountryID(projectId) == 2) { countryId = 2;//USA } // Foreach of Works (FLL, RA, JL, PR, MH Rehab, MOB, Other) foreach (string work_ in works) { // Load Functions by Work ProjectCostingSheetAddFunctionListGateway projectCostingSheetAddFunctionListGateway = new ProjectCostingSheetAddFunctionListGateway(); projectCostingSheetAddFunctionListGateway.LoadByWork_(work_); // Foreach of Functions foreach (ProjectCostingSheetAddTDS.FunctionListRow functionListRow in (ProjectCostingSheetAddTDS.FunctionListDataTable)projectCostingSheetAddFunctionListGateway.Table) { // Foreach of Job Class (Laborer Group 2, Laborer Group 6, Operator Group 1, Operator Group 2, Regular Rate) foreach (string jobClassType_ in jobClassType) { // Get Fringe Rate by Job Class decimal fringeRate = projectGateway.GetOperatorGroupFringeRate(projectId, jobClassType_); // Load Employees with Timesheet by ProjectId, StartDate, EndDate, Work, Function and Job Class ProjectCostingSheetAddEmployeeListGateway projectCostingSheetAddEmployeeListGateway = new ProjectCostingSheetAddEmployeeListGateway(Data); projectCostingSheetAddEmployeeListGateway.LoadByProjectIdStartDateEndDateWorkFunctionJobClass(projectId, startDate, endDate, work_, functionListRow.Function_, jobClassType_, companyId); // Foreach of Employees with Timesheet foreach (ProjectCostingSheetAddTDS.EmployeeListRow employeeListRow in (ProjectCostingSheetAddTDS.EmployeeListDataTable)projectCostingSheetAddEmployeeListGateway.Table) { DateTime newStartDate = new DateTime(); newStartDate = startDate; DateTime newEndDate = new DateTime(); newEndDate = endDate; // If Project is from Canada we get overtime if (projectGateway.GetCountryID(projectId) == 1) { // Get Category of Employee EmployeeGateway employeeGateway = new EmployeeGateway(); employeeGateway.LoadByEmployeeId(employeeListRow.EmployeeID); switch (employeeGateway.GetCategory(employeeListRow.EmployeeID)) { case "Special Forces": overtimeByCountry = 50; break; case "Field": overtimeByCountry = 50; break; case "Field 44": overtimeByCountry = 44; break; case "Office/Admin": overtimeByCountry = 44; break; case "Mechanic/Manufactoring": overtimeByCountry = 44; break; } } // Load Cost Pay Periods of Employee by StartDate and EndDate ProjectCostingSheetAddEmployeePayPeriodGateway projectCostingSheetAddEmployeePayPeriodGateway = new ProjectCostingSheetAddEmployeePayPeriodGateway(Data); projectCostingSheetAddEmployeePayPeriodGateway.LoadByStartDateEndDateEmployeeId(startDate, endDate, employeeListRow.EmployeeID); // If Employee has Cost Pay Periods between StartDate and EndDate if (projectCostingSheetAddEmployeePayPeriodGateway.Table.Rows.Count > 0) { // Foreach of Cost Pay Periods foreach (ProjectCostingSheetAddTDS.EmployeePayPeriodRow employeePayPeriodRow in (ProjectCostingSheetAddTDS.EmployeePayPeriodDataTable)projectCostingSheetAddEmployeePayPeriodGateway.Table) { // Update newEndDate with Date of Cost Pay Period newEndDate = employeePayPeriodRow.Date_.AddDays(-1); // Load Project Times of Employee by ProjectId, StartDate, EndDate, Work, Function, Job Class ProjectCostingSheetAddOriginalLabourHourGateway projectCostingSheetAddOriginalLabourHourGateway = new ProjectCostingSheetAddOriginalLabourHourGateway(Data); projectCostingSheetAddOriginalLabourHourGateway.LoadByProjectStartDateEndDateWorkFunctionJobClassTypeEmployeeId(projectId, newStartDate, newEndDate, work_, functionListRow.Function_, jobClassType_, employeeListRow.EmployeeID); // If Employee has ProjectTime if (projectCostingSheetAddOriginalLabourHourGateway.Table.Rows.Count > 0) { double lhQuantity = 0; double overtime = 0; decimal mealsQuantity = 0; decimal motelQuantity = 0; string employeeName = ""; refId++; // Foreach original ProjectTime foreach (ProjectCostingSheetAddTDS.OriginalLabourHourRow originalRow in (ProjectCostingSheetAddTDS.OriginalLabourHourDataTable)projectCostingSheetAddOriginalLabourHourGateway.Table) { employeeName = originalRow.EmployeeName; // Meal hours quantity if (!originalRow.IsMealsCountryNull()) { if (originalRow.MealsAllowance > 0) { mealsQuantity++; } } double acumPeriod = GetTotalHoursByEmployeeIdPeriodId(originalRow.EmployeeID, originalRow.Date_, originalRow.ProjectTimeID); if (acumPeriod > overtimeByCountry) { overtime = overtime + originalRow.ProjectTime; } else { double newAcumPeriod = acumPeriod + originalRow.ProjectTime; if (newAcumPeriod > overtimeByCountry) { overtime = overtime + (newAcumPeriod - overtimeByCountry); lhQuantity = lhQuantity + (originalRow.ProjectTime - (newAcumPeriod - overtimeByCountry)); } else { lhQuantity = lhQuantity + originalRow.ProjectTime; } } } if (lhQuantity > 0) { ProjectCostingSheetAddTDS.LabourHoursInformationRow newRow = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow(); if (projectGateway.IsFairWageProjectWorkFunction(projectId, work_, functionListRow.Function_)) { if (jobClassType_ != "Regular Rate") { decimal fairWageRate = projectGateway.GetOperatorGroupRate(projectId, jobClassType_); GetEmployeeDataFairWage(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRow, countryId, fringeRate, fairWageRate); } else { GetEmployeeData(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRow); // Is same to non fair wage project } } else { GetEmployeeData(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRow); // Is same to non fair wage project } newRow.CostingSheetID = 0; newRow.Work_ = work_; newRow.EmployeeID = employeeListRow.EmployeeID; newRow.RefID = refId; newRow.LHQuantity = lhQuantity; newRow.MealsQuantity = Convert.ToInt32(mealsQuantity); if (mealsQuantity > 0) newRow.MealsUnitOfMeasurement = "Day"; else newRow.MealsUnitOfMeasurement = ""; if (motelQuantity > 0) newRow.MotelUnitOfMeasurement = "Day"; else newRow.MotelUnitOfMeasurement = ""; newRow.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day"); newRow.MotelCostCad = 0; newRow.TotalCostCad = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostCad,2)) + (mealsQuantity * newRow.MealsCostCad) + (motelQuantity * newRow.MotelCostCad); newRow.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day"); newRow.MotelCostUsd = 0; newRow.TotalCostUsd = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostUsd,2)) + (mealsQuantity * newRow.MealsCostUsd) + (motelQuantity * newRow.MotelCostUsd); newRow.Deleted = false; newRow.InDatabase = false; newRow.COMPANY_ID = companyId; newRow.Name = employeeName; newRow.StartDate = newStartDate; newRow.EndDate = newEndDate; newRow.FromDatabase = true; newRow.Function_ = functionListRow.Function_; newRow.WorkFunction = work_ + " . " + functionListRow.Function_; newRow.Month = month; newRow.ClientName = clientName; newRow.ProjectName = projectName; ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRow); } if (overtime > 0) { refId++; ProjectCostingSheetAddTDS.LabourHoursInformationRow newRowOt = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow(); if (projectGateway.IsFairWageProjectWorkFunction(projectId, work_, functionListRow.Function_)) { if (jobClassType_ != "Regular Rate") { decimal fairWageRate = projectGateway.GetOperatorGroupRate(projectId, jobClassType_); GetEmployeeDataFairWageOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt, countryId, fringeRate, fairWageRate); } else { GetEmployeeDataOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt); // Is same to non fair wage project } } else { GetEmployeeDataOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt); // Is same to non fair wage project } newRowOt.CostingSheetID = 0; newRowOt.Work_ = work_; newRowOt.EmployeeID = employeeListRow.EmployeeID; newRowOt.RefID = refId; newRowOt.LHQuantity = overtime; newRowOt.MealsQuantity = 0; newRowOt.MealsUnitOfMeasurement = ""; newRowOt.MotelUnitOfMeasurement = ""; newRowOt.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day"); newRowOt.MotelCostCad = 0; newRowOt.TotalCostCad = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostCad,2)); newRowOt.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day"); newRowOt.MotelCostUsd = 0; newRowOt.TotalCostUsd = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostUsd,2)); newRowOt.Deleted = false; newRowOt.InDatabase = false; newRowOt.COMPANY_ID = companyId; newRowOt.Name = employeeName + " - Overtime"; newRowOt.StartDate = newStartDate; newRowOt.EndDate = newEndDate; newRowOt.FromDatabase = true; newRowOt.Function_ = functionListRow.Function_; newRowOt.WorkFunction = work_ + " . " + functionListRow.Function_; newRowOt.Month = month; newRowOt.ClientName = clientName; newRowOt.ProjectName = projectName; ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRowOt); } } newStartDate = newEndDate.AddDays(1); } if (newEndDate <= endDate) { ProjectCostingSheetAddOriginalLabourHourGateway projectCostingSheetAddOriginalLabourHourGateway = new ProjectCostingSheetAddOriginalLabourHourGateway(Data); projectCostingSheetAddOriginalLabourHourGateway.LoadByProjectStartDateEndDateWorkFunctionJobClassTypeEmployeeId(projectId, newStartDate, endDate, work_, functionListRow.Function_, jobClassType_, employeeListRow.EmployeeID); if (projectCostingSheetAddOriginalLabourHourGateway.Table.Rows.Count > 0) { double lhQuantity = 0; double overtime = 0; decimal mealsQuantity = 0; decimal motelQuantity = 0; string employeeName = ""; refId++; foreach (ProjectCostingSheetAddTDS.OriginalLabourHourRow originalRow in (ProjectCostingSheetAddTDS.OriginalLabourHourDataTable)projectCostingSheetAddOriginalLabourHourGateway.Table) { employeeName = originalRow.EmployeeName; // Meal hours quantity if (!originalRow.IsMealsCountryNull()) { if (originalRow.MealsAllowance > 0) { mealsQuantity++; } } double acumPeriod = GetTotalHoursByEmployeeIdPeriodId(originalRow.EmployeeID, originalRow.Date_, originalRow.ProjectTimeID); if (acumPeriod > overtimeByCountry) { overtime = overtime + originalRow.ProjectTime; } else { double newAcumPeriod = acumPeriod + originalRow.ProjectTime; if (newAcumPeriod > overtimeByCountry) { overtime = overtime + (newAcumPeriod - overtimeByCountry); lhQuantity = lhQuantity + (originalRow.ProjectTime - (newAcumPeriod - overtimeByCountry)); } else { lhQuantity = lhQuantity + originalRow.ProjectTime; } } } if (lhQuantity > 0) { ProjectCostingSheetAddTDS.LabourHoursInformationRow newRow = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow(); if (projectGateway.IsFairWageProjectWorkFunction(projectId, work_, functionListRow.Function_)) { if (jobClassType_ != "Regular Rate") { decimal fairWageRate = projectGateway.GetOperatorGroupRate(projectId, jobClassType_); GetEmployeeDataFairWage(newStartDate, endDate, employeeListRow.EmployeeID, work_, newRow, countryId, fringeRate, fairWageRate); } else { GetEmployeeData(newStartDate, endDate, employeeListRow.EmployeeID, work_, newRow); } } else { GetEmployeeData(newStartDate, endDate, employeeListRow.EmployeeID, work_, newRow); } newRow.CostingSheetID = 0; newRow.Work_ = work_; newRow.EmployeeID = employeeListRow.EmployeeID; newRow.RefID = refId; newRow.LHQuantity = lhQuantity; newRow.MealsQuantity = Convert.ToInt32(mealsQuantity); if (mealsQuantity > 0) newRow.MealsUnitOfMeasurement = "Day"; else newRow.MealsUnitOfMeasurement = ""; if (motelQuantity > 0) newRow.MotelUnitOfMeasurement = "Day"; else newRow.MotelUnitOfMeasurement = ""; newRow.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day"); newRow.MotelCostCad = 0; newRow.TotalCostCad = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostCad,2)) + (mealsQuantity * newRow.MealsCostCad) + (motelQuantity * newRow.MotelCostCad); newRow.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day"); newRow.MotelCostUsd = 0; newRow.TotalCostUsd = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostUsd,2)) + (mealsQuantity * newRow.MealsCostUsd) + (motelQuantity * newRow.MotelCostUsd); newRow.Deleted = false; newRow.InDatabase = false; newRow.COMPANY_ID = companyId; newRow.Name = employeeName; newRow.StartDate = newStartDate; newRow.EndDate = endDate; newRow.FromDatabase = true; newRow.Function_ = functionListRow.Function_; newRow.WorkFunction = work_ + " . " + functionListRow.Function_; newRow.Month = month; newRow.ClientName = clientName; newRow.ProjectName = projectName; ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRow); } if (overtime > 0) { refId++; ProjectCostingSheetAddTDS.LabourHoursInformationRow newRowOt = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow(); if (projectGateway.IsFairWageProjectWorkFunction(projectId, work_, functionListRow.Function_)) { if (jobClassType_ != "Regular Rate") { decimal fairWageRate = projectGateway.GetOperatorGroupRate(projectId, jobClassType_); GetEmployeeDataFairWageOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt, countryId, fringeRate, fairWageRate); } else { GetEmployeeDataOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt); // Is same to non fair wage project } } else { GetEmployeeDataOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt); // Is same to non fair wage project } newRowOt.CostingSheetID = 0; newRowOt.Work_ = work_; newRowOt.EmployeeID = employeeListRow.EmployeeID; newRowOt.RefID = refId; newRowOt.LHQuantity = overtime; newRowOt.MealsQuantity = 0; newRowOt.MealsUnitOfMeasurement = ""; newRowOt.MotelUnitOfMeasurement = ""; newRowOt.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day"); newRowOt.MotelCostCad = 0; newRowOt.TotalCostCad = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostCad,2)); newRowOt.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day"); newRowOt.MotelCostUsd = 0; newRowOt.TotalCostUsd = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostUsd,2)); newRowOt.Deleted = false; newRowOt.InDatabase = false; newRowOt.COMPANY_ID = companyId; newRowOt.Name = employeeName + " - Overtime"; newRowOt.StartDate = newStartDate; newRowOt.EndDate = endDate; newRowOt.FromDatabase = true; newRowOt.Function_ = functionListRow.Function_; newRowOt.WorkFunction = work_ + " . " + functionListRow.Function_; newRowOt.Month = month; newRowOt.ClientName = clientName; newRowOt.ProjectName = projectName; ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRowOt); } } } } else { ProjectCostingSheetAddOriginalLabourHourGateway projectCostingSheetAddOriginalLabourHourGateway = new ProjectCostingSheetAddOriginalLabourHourGateway(Data); projectCostingSheetAddOriginalLabourHourGateway.LoadByProjectStartDateEndDateWorkFunctionJobClassTypeEmployeeId(projectId, startDate, endDate, work_, functionListRow.Function_, jobClassType_, employeeListRow.EmployeeID); if (projectCostingSheetAddOriginalLabourHourGateway.Table.Rows.Count > 0) { double lhQuantity = 0; double overtime = 0; decimal mealsQuantity = 0; decimal motelQuantity = 0; string employeeName = ""; refId++; foreach (ProjectCostingSheetAddTDS.OriginalLabourHourRow originalRow in (ProjectCostingSheetAddTDS.OriginalLabourHourDataTable)projectCostingSheetAddOriginalLabourHourGateway.Table) { employeeName = originalRow.EmployeeName; // Meal hours quantity if (!originalRow.IsMealsCountryNull()) { if (originalRow.MealsAllowance > 0) { mealsQuantity++; } } double acumPeriod = GetTotalHoursByEmployeeIdPeriodId(originalRow.EmployeeID, originalRow.Date_, originalRow.ProjectTimeID); if (acumPeriod > overtimeByCountry) { overtime = overtime + originalRow.ProjectTime; } else { double newAcumPeriod = acumPeriod + originalRow.ProjectTime; if (newAcumPeriod > overtimeByCountry) { overtime = overtime + (newAcumPeriod - overtimeByCountry); lhQuantity = lhQuantity + (originalRow.ProjectTime - (newAcumPeriod - overtimeByCountry)); } else { lhQuantity = lhQuantity + originalRow.ProjectTime; } } } if (lhQuantity > 0) { ProjectCostingSheetAddTDS.LabourHoursInformationRow newRow = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow(); if (projectGateway.IsFairWageProjectWorkFunction(projectId, work_, functionListRow.Function_)) { if (jobClassType_ != "Regular Rate") { decimal fairWageRate = projectGateway.GetOperatorGroupRate(projectId, jobClassType_); GetEmployeeDataFairWage(startDate, endDate, employeeListRow.EmployeeID, work_, newRow, countryId, fringeRate, fairWageRate); } else { GetEmployeeData(startDate, endDate, employeeListRow.EmployeeID, work_, newRow); } } else { GetEmployeeData(startDate, endDate, employeeListRow.EmployeeID, work_, newRow); } newRow.CostingSheetID = 0; newRow.Work_ = work_; newRow.EmployeeID = employeeListRow.EmployeeID; newRow.RefID = refId; newRow.LHQuantity = lhQuantity; newRow.MealsQuantity = Convert.ToInt32(mealsQuantity); if (mealsQuantity > 0) newRow.MealsUnitOfMeasurement = "Day"; else newRow.MealsUnitOfMeasurement = ""; if (motelQuantity > 0) newRow.MotelUnitOfMeasurement = "Day"; else newRow.MotelUnitOfMeasurement = ""; newRow.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day"); newRow.MotelCostCad = 0; newRow.TotalCostCad = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostCad,2)) + (mealsQuantity * newRow.MealsCostCad) + (motelQuantity * newRow.MotelCostCad); newRow.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day"); newRow.MotelCostUsd = 0; newRow.TotalCostUsd = (Convert.ToDecimal(lhQuantity) * decimal.Round(newRow.LHCostUsd,2)) + (mealsQuantity * newRow.MealsCostUsd) + (motelQuantity * newRow.MotelCostUsd); newRow.Deleted = false; newRow.InDatabase = false; newRow.COMPANY_ID = companyId; newRow.Name = employeeName; newRow.StartDate = startDate; newRow.EndDate = endDate; newRow.FromDatabase = true; newRow.Function_ = functionListRow.Function_; newRow.WorkFunction = work_ + " . " + functionListRow.Function_; newRow.Month = month; newRow.ClientName = clientName; newRow.ProjectName = projectName; ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRow); } if (overtime > 0) { refId++; ProjectCostingSheetAddTDS.LabourHoursInformationRow newRowOt = ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).NewLabourHoursInformationRow(); if (projectGateway.IsFairWageProjectWorkFunction(projectId, work_, functionListRow.Function_)) { if (jobClassType_ != "Regular Rate") { decimal fairWageRate = projectGateway.GetOperatorGroupRate(projectId, jobClassType_); GetEmployeeDataFairWageOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt, countryId, fringeRate, fairWageRate); } else { GetEmployeeDataOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt); // Is same to non fair wage project } } else { GetEmployeeDataOvertime(newStartDate, newEndDate, employeeListRow.EmployeeID, work_, newRowOt); // Is same to non fair wage project } newRowOt.CostingSheetID = 0; newRowOt.Work_ = work_; newRowOt.EmployeeID = employeeListRow.EmployeeID; newRowOt.RefID = refId; newRowOt.LHQuantity = overtime; newRowOt.MealsQuantity = 0; newRowOt.MealsUnitOfMeasurement = ""; newRowOt.MotelUnitOfMeasurement = ""; newRowOt.MealsCostCad = MealsAllowance.GetMealsAllowance(1, true, "Full Day"); newRowOt.MotelCostCad = 0; newRowOt.TotalCostCad = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostCad,2)); newRowOt.MealsCostUsd = MealsAllowance.GetMealsAllowance(2, true, "Full Day"); newRowOt.MotelCostUsd = 0; newRowOt.TotalCostUsd = (Convert.ToDecimal(overtime) * decimal.Round(newRowOt.LHCostUsd,2)); newRowOt.Deleted = false; newRowOt.InDatabase = false; newRowOt.COMPANY_ID = companyId; newRowOt.Name = employeeName + " - Overtime"; newRowOt.StartDate = startDate; newRowOt.EndDate = endDate; newRowOt.FromDatabase = true; newRowOt.Function_ = functionListRow.Function_; newRowOt.WorkFunction = work_ + " . " + functionListRow.Function_; newRowOt.Month = month; newRowOt.ClientName = clientName; newRowOt.ProjectName = projectName; ((ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Table).AddLabourHoursInformationRow(newRowOt); } } } } } } } }
// //////////////////////////////////////////////////////////////////////// // PUBLIC METHODS // /// <summary> /// Insert /// </summary> /// <param name="projectId">projectId</param> /// <param name="name">name</param> /// <param name="startDate">startDate</param> /// <param name="endDate">endDate</param> /// <param name="totalLabourHoursCad">totalLabourHoursCad</param> /// <param name="totalLabourHoursUsd">totalLabourHoursUsd</param> /// <param name="totalMaterialsCad">totalMaterialsCad</param> /// <param name="totalMaterialsUsd">totalMaterialsUsd</param> /// <param name="totalUnitsCad">totalUnitsCad</param> /// <param name="totalUnitsUsd">totalUnitsUsd</param> /// <param name="totalOtherCostsCad">totalOtherCostsCad</param> /// <param name="totalOtherCostsUsd">totalOtherCostsUsd</param> /// <param name="grandTotalCad">grandTotalCad</param> /// <param name="grandTotalUsd">grandTotalUsd</param> /// <param name="state">state</param> /// <param name="deleted">deleted</param> /// <param name="companyId">companyId</param> /// <param name="totalSubcontractorsCad">totalSubcontractorsCad</param> /// <param name="totalSubcontractorsUsd">totalSubcontractorsUsd</param> public void Insert(int projectId, string name, DateTime startDate, DateTime endDate, decimal totalLabourHoursCad, decimal totalLabourHoursUsd, decimal totalMaterialsCad, decimal totalMaterialsUsd, decimal totalUnitsCad, decimal totalUnitsUsd, decimal totalOtherCostsCad, decimal totalOtherCostsUsd, decimal grandTotalCad, decimal grandTotalUsd, string state, bool deleted, int companyId, decimal totalSubcontractorsCad, decimal totalSubcontractorsUsd, decimal grandRevenue, decimal grandProfit, decimal grandGrossMargin, decimal totalHotels, decimal totalBondings, decimal totalInsurances, decimal totalOtherCategory, string month) { ProjectCostingSheetAddTDS.BasicInformationRow row = ((ProjectCostingSheetAddTDS.BasicInformationDataTable)Table).NewBasicInformationRow(); row.CostingSheetID = 0; row.ProjectID = projectId; row.Name = name; row.StartDate = startDate; row.EndDate = endDate; row.TotalLabourHoursCad = totalLabourHoursCad; row.TotalLabourHoursUsd = totalLabourHoursUsd; row.TotalMaterialsCad = totalMaterialsCad; row.TotalMaterialsUsd = totalMaterialsUsd; row.TotalUnitsCad = totalUnitsCad; row.TotalUnitsUsd = totalUnitsUsd; row.TotalOtherCostsCad = totalOtherCostsCad; row.TotalOtherCostsUsd = totalOtherCostsUsd; row.GrantTotalCostCad = grandTotalCad; row.GrantTotalCostUsd = grandTotalUsd; row.Deleted = deleted; row.COMPANY_ID = companyId; row.TotalSubcontractorsCad = totalSubcontractorsCad; row.TotalSubcontractorsUsd = totalSubcontractorsUsd; row.TotalHotelCosts = totalHotels; row.TotalBondingCosts = totalBondings; row.TotalInsuranceCosts = totalInsurances; row.TotalOtherCategoryCosts = totalOtherCategory; row.GrantTotalCostCad = totalLabourHoursCad + totalUnitsCad + totalMaterialsCad + totalOtherCostsCad + totalSubcontractorsCad + totalHotels + totalBondings + totalInsurances + totalOtherCategory; row.GrantTotalCostUsd = totalLabourHoursUsd + totalUnitsUsd + totalMaterialsUsd + totalOtherCostsUsd + totalSubcontractorsUsd + totalHotels + totalBondings + totalInsurances + totalOtherCategory; row.State = "In Progress"; row.GrandRevenue = grandRevenue; row.GrandProfit = grandProfit; row.GrandGrossMargin = grandGrossMargin; row.Month = month; ProjectGateway projectGateway = new ProjectGateway(); projectGateway.LoadByProjectId(projectId); row.ProjectName = projectGateway.GetName(projectId); int clientId = projectGateway.GetClientID(projectId); CompaniesGateway companiesGateway = new CompaniesGateway(); companiesGateway.LoadAllByCompaniesId(clientId, companyId); row.ClientName = companiesGateway.GetName(clientId); ((ProjectCostingSheetAddTDS.BasicInformationDataTable)Table).AddBasicInformationRow(row); }
// //////////////////////////////////////////////////////////////////////// // EVENTS // protected void Page_Load(object sender, EventArgs e) { // Register client scripts this.RegisterClientScripts(); if (!IsPostBack) { // Security check if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_COSTINGSHEETS_ADMIN"])) { if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_COSTINGSHEETS_VIEW"])) { Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator."); } } // Validate query string if (Request.QueryString["source_page"] == null) { Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in project_costing_sheets_navigator.aspx"); } // Tag page hdfCompanyId.Value = Session["companyID"].ToString(); hdfProjectId.Value = Request.QueryString["project_id"]; hdfDataChanged.Value = Request.QueryString["data_changed"]; hdfDataChangedMessage.Value = "Changes made to this project will not be saved."; ViewState["state"] = Request.QueryString["state"]; ViewState["active_tab"] = Request.QueryString["active_tab"]; ViewState["origin"] = Request.QueryString["origin"]; ViewState["update"] = Request.QueryString["update"]; projectTDS = (ProjectTDS)Session["lfsProjectTDS"]; // Prepare initial data //lblResults.Visible = false; // ... for project int currentProjectId = Int32.Parse(hdfProjectId.Value.ToString()); ProjectGateway projectGateway = new ProjectGateway(); projectGateway.LoadByProjectId(currentProjectId); string name = projectGateway.GetName(currentProjectId); if (name.Length > 23) name = name.Substring(0, 20) + "..."; lblTitleProjectName.Text = name + " (" + projectGateway.GetProjectNumber(currentProjectId) + ")"; // ... for client int companyId = Int32.Parse(hdfCompanyId.Value); int currentCompanyId = projectGateway.GetClientID(Int32.Parse(hdfProjectId.Value.ToString())); CompaniesGateway companiesGateway = new CompaniesGateway(); companiesGateway.LoadAllByCompaniesId(currentCompanyId, companyId); lblTitleClientName.Text = "Client: " + companiesGateway.GetName(currentCompanyId); hdfClientId.Value = projectGateway.GetClientID(int.Parse(hdfProjectId.Value)).ToString(); // Store navigator state at projects navigator StoreNavigatorState(); // If coming from // ... project_summary.aspx, project_edit.aspx, project_sections_navigator.aspx or project_sections_navigator2.aspx if ((Request.QueryString["source_page"] == "project_summary.aspx") || (Request.QueryString["source_page"] == "project_edit.aspx") || (Request.QueryString["source_page"] == "project_sections_navigator.aspx") || (Request.QueryString["source_page"] == "project_sections_navigator2.aspx")) { projectCostingSheetsNavigatorTDS = new ProjectCostingSheetsNavigatorTDS(); // ... Search data with updates projectCostingSheetsNavigatorTDS = SubmitSearch(); // ... Store datasets Session["projectCostingSheetsNavigatorTDS"] = projectCostingSheetsNavigatorTDS; } // ... project_costing_sheets_edit.aspx, project_costing_sheets_summary.aspx or project_costing_sheets_delete.aspx if ((Request.QueryString["source_page"] == "project_costing_sheets_edit.aspx") || (Request.QueryString["source_page"] == "project_costing_sheets_summary.aspx") || (Request.QueryString["source_page"] == "project_costing_sheets_delete.aspx") || (Request.QueryString["source_page"] == "project_combined_costing_sheets_edit.aspx") || (Request.QueryString["source_page"] == "project_combined_costing_sheets_summary.aspx") || (Request.QueryString["source_page"] == "project_combined_costing_sheets_delete.aspx")) { if (Request.QueryString["update"] == "no") { projectCostingSheetsNavigatorTDS = (ProjectCostingSheetsNavigatorTDS)Session["projectCostingSheetsNavigatorTDS"]; } else { // ... Delete store data Session.Contents.Remove("projectCostingSheetsNavigatorTDS"); projectCostingSheetsNavigatorTDS = SubmitSearch(); // ... store datasets Session["projectCostingSheetsNavigatorTDS"] = projectCostingSheetsNavigatorTDS; } } // For the grid grdCostingSheetsNavigator.DataSource = projectCostingSheetsNavigatorTDS.ProjectCostingSheetsNavigator; grdCostingSheetsNavigator.DataBind(); grdCombinedCostingSheetsNavigator.DataSource = projectCostingSheetsNavigatorTDS.ProjectCombinedCostingSheetsNavigator; grdCombinedCostingSheetsNavigator.DataBind(); //lblResults.Visible = false; // ... For the total rows if (projectCostingSheetsNavigatorTDS.ProjectCostingSheetsNavigator.Rows.Count > 0) { lblTotalRows.Text = "Total Rows: " + projectCostingSheetsNavigatorTDS.ProjectCostingSheetsNavigator.Rows.Count; lblTotalRows.Visible = true; //lblResults.Visible = true; btnOpen.Visible = true; btnEdit.Visible = true; btnDelete.Visible = true; ddlAction.Visible = true; pnlHorizontalRule.Visible = true; lblCostingSheetsTitle.Visible = true; } else { lblTotalRows.Visible = false; btnOpen.Visible = false; btnEdit.Visible = false; btnDelete.Visible = false; ddlAction.Visible = false; pnlHorizontalRule.Visible = false; lblCostingSheetsTitle.Visible = false; } // ... For the total rows if (projectCostingSheetsNavigatorTDS.ProjectCombinedCostingSheetsNavigator.Rows.Count > 0) { //lblResults.Visible = true; lblCombinedCostingSheetsTotalRows.Text = "Total Rows: " + projectCostingSheetsNavigatorTDS.ProjectCombinedCostingSheetsNavigator.Rows.Count; lblCombinedCostingSheetsTotalRows.Visible = true; lblCombinedCostingSheetsTitle.Visible = true; lblCombinedCostingSheetsTotalRows.Visible = true; btnOpenCombinedCostingSheet.Visible = true; btnEditCombinedCostingSheet.Visible = true; btnDeleteCombinedCostingSheet.Visible = true; pnlHorizontalRuleCombinedCostingSheet.Visible = true; ddlActionCombinedCostingSheet.Visible = true; } else { lblCombinedCostingSheetsTotalRows.Visible = false; lblCombinedCostingSheetsTitle.Visible = false; lblCombinedCostingSheetsTotalRows.Visible = false; btnOpenCombinedCostingSheet.Visible = false; btnEditCombinedCostingSheet.Visible = false; btnDeleteCombinedCostingSheet.Visible = false; pnlHorizontalRuleCombinedCostingSheet.Visible = false; ddlActionCombinedCostingSheet.Visible = false; } } else { // Restore TDS projectTDS = (ProjectTDS)Session["lfsProjectTDS"]; projectCostingSheetsNavigatorTDS = (ProjectCostingSheetsNavigatorTDS)Session["projectCostingSheetsNavigatorTDS"]; // ... for project int currentProjectId = Int32.Parse(hdfProjectId.Value.ToString()); ProjectGateway projectGateway = new ProjectGateway(); projectGateway.LoadByProjectId(currentProjectId); string name = projectGateway.GetName(currentProjectId); if (name.Length > 23) name = name.Substring(0, 20) + "..."; lblTitleProjectName.Text = name + " (" + projectGateway.GetProjectNumber(currentProjectId) + ")"; // ... for client int companyId = Int32.Parse(hdfCompanyId.Value); int currentClientId = projectGateway.GetClientID(Int32.Parse(hdfProjectId.Value.ToString())); CompaniesGateway companiesGateway = new CompaniesGateway(); companiesGateway.LoadAllByCompaniesId(currentClientId, companyId); lblTitleClientName.Text = "Client: " + companiesGateway.GetName(currentClientId); // ... For the total rows if (projectCostingSheetsNavigatorTDS.ProjectCostingSheetsNavigator.Rows.Count > 0) { lblTotalRows.Text = "Total Rows: " + projectCostingSheetsNavigatorTDS.ProjectCostingSheetsNavigator.Rows.Count; lblTotalRows.Visible = true; //lblResults.Visible = true; btnOpen.Visible = true; btnEdit.Visible = true; btnDelete.Visible = true; ddlAction.Visible = true; pnlHorizontalRule.Visible = true; lblCostingSheetsTitle.Visible = true; } else { lblTotalRows.Visible = false; btnOpen.Visible = false; btnEdit.Visible = false; btnDelete.Visible = false; ddlAction.Visible = false; pnlHorizontalRule.Visible = false; lblCostingSheetsTitle.Visible = false; } // ... For the total rows if (projectCostingSheetsNavigatorTDS.ProjectCombinedCostingSheetsNavigator.Rows.Count > 0) { //lblResults.Visible = true; lblCombinedCostingSheetsTotalRows.Text = "Total Rows: " + projectCostingSheetsNavigatorTDS.ProjectCombinedCostingSheetsNavigator.Rows.Count; lblCombinedCostingSheetsTotalRows.Visible = true; lblCombinedCostingSheetsTitle.Visible = true; lblCombinedCostingSheetsTotalRows.Visible = true; btnOpenCombinedCostingSheet.Visible = true; btnEditCombinedCostingSheet.Visible = true; btnDeleteCombinedCostingSheet.Visible = true; pnlHorizontalRuleCombinedCostingSheet.Visible = true; ddlActionCombinedCostingSheet.Visible = true; } else { lblCombinedCostingSheetsTotalRows.Visible = false; lblCombinedCostingSheetsTitle.Visible = false; lblCombinedCostingSheetsTotalRows.Visible = false; btnOpenCombinedCostingSheet.Visible = false; btnEditCombinedCostingSheet.Visible = false; btnDeleteCombinedCostingSheet.Visible = false; pnlHorizontalRuleCombinedCostingSheet.Visible = false; ddlActionCombinedCostingSheet.Visible = false; } } }
// //////////////////////////////////////////////////////////////////////// // EVENTS // protected void Page_Load(object sender, EventArgs e) { // Register client scripts this.RegisterClientScripts(); if (!IsPostBack) { // Security check if (!(Convert.ToBoolean(Session["sgLFS_PROJECTS_VIEW"]) && Convert.ToBoolean(Session["sgLFS_PROJECTS_DELETE"]))) { 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["project_id"] == null)) { Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in project_delete.aspx"); } // Tag page hdfCompanyId.Value = Session["companyID"].ToString(); hdfProjectId.Value = Request.QueryString["project_id"]; // If coming from project_summary.aspx or projects2.aspx if (((string)Request.QueryString["source_page"] == "project_summary.aspx") || ((string)Request.QueryString["source_page"] == "projects2.aspx")) { // Store Navigator State and Update control StoreNavigatorState(); ViewState["update"] = Request.QueryString["update"]; // Get project record projectTDS = new ProjectTDS(); ProjectGateway projectGatewayForLoad = new ProjectGateway(projectTDS); projectGatewayForLoad.LoadByProjectId(int.Parse(hdfProjectId.Value)); // Store datasets Session["lfsProjectTDS"] = projectTDS; } // Restore dataset projectTDS = (ProjectTDS)Session["lfsProjectTDS"]; // Prepare initial data // ... for project int currentProjectId = Int32.Parse(hdfProjectId.Value.ToString()); ProjectGateway projectGateway = new ProjectGateway(); projectGateway.LoadByProjectId(currentProjectId); string name = projectGateway.GetName(currentProjectId); if (name.Length > 23) name = name.Substring(0, 20) + "..."; lblTitleProjectName.Text = name + " (" + projectGateway.GetProjectNumber(currentProjectId) + ")"; // ... for client int currentClientId = projectGateway.GetClientID(Int32.Parse(hdfProjectId.Value.ToString())); int companyId = Int32.Parse(hdfCompanyId.Value); CompaniesGateway companiesGateway = new CompaniesGateway(); companiesGateway.LoadAllByCompaniesId(currentClientId, companyId); lblTitleClientName.Text = "Client: " + companiesGateway.GetName(currentClientId); } else { // Restore dataset projectTDS = (ProjectTDS)Session["lfsProjectTDS"]; } }
// //////////////////////////////////////////////////////////////////////// // EVENTS // protected void Page_Load(object sender, EventArgs e) { // Register client scripts this.RegisterClientScripts(); if (!IsPostBack) { // Security check if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_VIEW"])) { 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) { Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in project_sections_navigator.aspx"); } // If coming from // ... Left Menu or Out if ((Request.QueryString["source_page"] == "lm") || (Request.QueryString["source_page"] == "out")) { // Store Navigator State and Update control StoreNavigatorState(); ViewState["update"] = Request.QueryString["update"]; projectTDS = (ProjectTDS)Session["lfsProjectTDS"]; tNoResults.Visible = false; } // ... project_sections_navigator2.aspx if (Request.QueryString["source_page"] == "project_sections_navigator2.aspx") { RestoreNavigatorState(); if ((string)Request.QueryString["no_results"] == "yes") { tNoResults.Visible = true; } else { tNoResults.Visible = false; } } // Tag page hdfCompanyId.Value = Session["companyID"].ToString(); hdfProjectId.Value = Request.QueryString["project_id"]; ViewState["origin"] = Request.QueryString["origin"]; ViewState["state"] = Request.QueryString["state"]; ViewState["active_tab"] = Request.QueryString["active_tab"]; hdfDataChanged.Value = Request.QueryString["data_changed"]; hdfDataChangedMessage.Value = "Changes made to this project will not be saved."; projectTDS = (ProjectTDS)Session["lfsProjectTDS"]; // ... for project int currentProjectId = Int32.Parse(hdfProjectId.Value.ToString()); ProjectGateway projectGateway = new ProjectGateway(); projectGateway.LoadByProjectId(currentProjectId); string name = projectGateway.GetName(currentProjectId); if (name.Length > 23) name = name.Substring(0, 20) + "..."; lblTitleProjectName.Text = name + " (" + projectGateway.GetProjectNumber(currentProjectId) + ")"; // ... for client int currentCompanyId = projectGateway.GetClientID(Int32.Parse(hdfProjectId.Value.ToString())); int companyId = Int32.Parse(hdfCompanyId.Value); CompaniesGateway companiesGateway = new CompaniesGateway(); companiesGateway.LoadAllByCompaniesId(currentCompanyId, companyId); lblTitleClientName.Text = "Client: " + companiesGateway.GetName(currentCompanyId); hdfClientId.Value = projectGateway.GetClientID(int.Parse(hdfProjectId.Value)).ToString(); } else { // Restore dataset projectTDS = (ProjectTDS)Session["lfsProjectTDS"]; // ... for project int currentProjectId = Int32.Parse(hdfProjectId.Value.ToString()); ProjectGateway projectGateway = new ProjectGateway(); projectGateway.LoadByProjectId(currentProjectId); string name = projectGateway.GetName(currentProjectId); if (name.Length > 23) name = name.Substring(0, 20) + "..."; lblTitleProjectName.Text = name + " (" + projectGateway.GetProjectNumber(currentProjectId) + ")"; // ... for client int currentCompanyId = projectGateway.GetClientID(Int32.Parse(hdfProjectId.Value.ToString())); int companyId = Int32.Parse(hdfCompanyId.Value); CompaniesGateway companiesGateway = new CompaniesGateway(); companiesGateway.LoadAllByCompaniesId(currentCompanyId, companyId); lblTitleClientName.Text = "Client: " + companiesGateway.GetName(currentCompanyId); } }
// //////////////////////////////////////////////////////////////////////// // STEP3 - DATA - METHODS // private void StepDataIn() { // Set instruction mWizard2 master = (mWizard2)this.Master; master.WizardInstruction = "Please define global data, it will be applied to your team members on the next step."; // Wizard type & step from check if ((hdfNewOrTemplate.Value == "New") && ((string)ViewState["StepFrom"] != "Employees")) { // Prepare initial data ddlClient.Enabled = true; ddlProject.Enabled = true; ProjectTimeWorkList projectTimeWorkList = new ProjectTimeWorkList(new DataSet()); projectTimeWorkList.LoadAndAddItem("(Select a Type)"); ddlTypeOfWork.DataSource = projectTimeWorkList.Table; ddlTypeOfWork.DataValueField = "Work_"; ddlTypeOfWork.DataTextField = "Work_"; ddlTypeOfWork.DataBind(); ddlTypeOfWork.SelectedIndex = 0; ProjectTimeWorkFunctionList projectTimeWorkFunctionList = new ProjectTimeWorkFunctionList(new DataSet()); projectTimeWorkFunctionList.LoadActiveForAddAndAddItem("(Select a Function)", "-1"); ddlFunction.DataSource = projectTimeWorkFunctionList.Table; ddlFunction.DataValueField = "Function_"; ddlFunction.DataTextField = "Function_"; ddlFunction.DataBind(); ddlFunction.SelectedIndex = 0; } else { TeamProjectTime2Gateway teamProjectTime2Gateway = new TeamProjectTime2Gateway(teamProjectTime2TDS); TeamProjectTime2DetailTemp teamProjectTime2DetailTemp = new TeamProjectTime2DetailTemp(teamProjectTime2TDS); // Prepare initial data if ((string)ViewState["StepFrom"] == "Template") { ViewState["teamProjectTimeId"] = Int32.Parse(hdfSelectedIdTemplate.Value); // ... for TeamProjectTime teamProjectTime2Gateway.LoadByTeamProjectTimeId((int)ViewState["teamProjectTimeId"]); // ... for TeamProjectTimeDetailTemp teamProjectTime2DetailTemp.LoadAllByTeamProjectTimeId((int)ViewState["teamProjectTimeId"]); } // ... for Client string companiesId = teamProjectTime2Gateway.GetCompaniesId((int)ViewState["teamProjectTimeId"]).ToString(); int companyId = Int32.Parse(hdfCompanyId.Value); CompaniesGateway companiesGateway = new CompaniesGateway(); companiesGateway.LoadAllByCompaniesId(Int32.Parse(companiesId), companyId); // ... If Company is active bool deleted = companiesGateway.GetDeleted(Int32.Parse(companiesId)); if (deleted) { ddlClient.SelectedIndex = -1; } else { ddlClient.SelectedValue = companiesId; } if (ddlClient.SelectedValue.Length == 0) { odsClient.DataBind(); ddlClient.DataSourceID = "odsClient"; ddlClient.DataValueField = "COMPANIES_ID"; ddlClient.DataTextField = "Name"; ddlClient.DataBind(); if (deleted) { ddlClient.SelectedIndex = -1; } else { ddlClient.SelectedValue = companiesId; } } if (!deleted) { // ... for project odsProjectsInternalProjectsBallparkProjects.SelectParameters.RemoveAt(2); odsProjectsInternalProjectsBallparkProjects.SelectParameters.Add("ClientId", ddlClient.SelectedValue); odsProjectsInternalProjectsBallparkProjects.Select(); odsProjectsInternalProjectsBallparkProjects.DataBind(); ddlProject.DataSourceID = "odsProjectsInternalProjectsBallparkProjects"; ddlProject.DataValueField = "ProjectID"; ddlProject.DataTextField = "NAME"; ddlProject.DataBind(); try { ddlProject.SelectedValue = teamProjectTime2Gateway.GetProjectId((int)ViewState["teamProjectTimeId"]).ToString(); } catch { ddlProject.SelectedIndex = -1; } } else { ddlProject.SelectedIndex = -1; } // ... for Date if ((string)ViewState["StepFrom"] == "Employees") { tkrdpDate_.SelectedDate = teamProjectTime2Gateway.GetDate_((int)ViewState["teamProjectTimeId"]); } // ... for Type of work ProjectTimeWorkList projectTimeWorkList = new ProjectTimeWorkList(new DataSet()); projectTimeWorkList.LoadAndAddItem("(Select a Type)"); ddlTypeOfWork.DataSource = projectTimeWorkList.Table; ddlTypeOfWork.DataValueField = "Work_"; ddlTypeOfWork.DataTextField = "Work_"; ddlTypeOfWork.DataBind(); if (teamProjectTime2Gateway.GetWork((int)ViewState["teamProjectTimeId"]).ToString() == "") { ddlTypeOfWork.SelectedValue = "(Select a Type)"; } else { ddlTypeOfWork.SelectedValue = (string)teamProjectTime2Gateway.GetWork((int)ViewState["teamProjectTimeId"]); } // ... for function ProjectTimeWorkFunctionList projectTimeWorkFunctionList = new ProjectTimeWorkFunctionList(new DataSet()); if (teamProjectTime2Gateway.GetWork((int)ViewState["teamProjectTimeId"]).ToString() == "") { // ... If there is no type of Work, no function should be loaded projectTimeWorkFunctionList.LoadActiveForAddAndAddItem("(Select a Function)", "-1"); } else { projectTimeWorkFunctionList.LoadActiveForAddAndAddItem("(Select a Function)", teamProjectTime2Gateway.GetWork((int)ViewState["teamProjectTimeId"])); } ddlFunction.DataSource = projectTimeWorkFunctionList.Table; ddlFunction.DataValueField = "Function_"; ddlFunction.DataTextField = "Function_"; ddlFunction.DataBind(); if (teamProjectTime2Gateway.GetWork((int)ViewState["teamProjectTimeId"]).ToString() == "") { ddlFunction.SelectedValue = "(Select a Function)"; } else { ddlFunction.SelectedValue = (string)teamProjectTime2Gateway.GetFunction((int)ViewState["teamProjectTimeId"]); } // ... for working details if (!deleted) { tbxWorkingDetails.Text = teamProjectTime2Gateway.GetWorkingDetails((int)ViewState["teamProjectTimeId"]); } else { tbxWorkingDetails.Text = ""; } // ... for start time if (teamProjectTime2Gateway.GetStartTime((int)ViewState["teamProjectTimeId"]).HasValue) { string startTime = ((DateTime)teamProjectTime2Gateway.GetStartTime((int)ViewState["teamProjectTimeId"])).ToString("H:mm"); string[] hoursMin1 = startTime.Split(':'); ddlStartTimeHour.SelectedValue = hoursMin1[0].Trim(); ddlStartTimeMinute.SelectedValue = hoursMin1[1].Trim(); } // ... for end time if (teamProjectTime2Gateway.GetEndTime((int)ViewState["teamProjectTimeId"]).HasValue) { string endTime = ((DateTime)teamProjectTime2Gateway.GetEndTime((int)ViewState["teamProjectTimeId"])).ToString("H:mm"); string[] endHoursMin1 = endTime.Split(':'); ddlEndTimeHour.SelectedValue = endHoursMin1[0].Trim(); ddlEndTimeMinute.SelectedValue = endHoursMin1[1].Trim(); } // ... for offset if (teamProjectTime2Gateway.GetOffset((int)ViewState["teamProjectTimeId"]).HasValue) ddlLunch.SelectedValue = Math.Round(teamProjectTime2Gateway.GetOffset((int)ViewState["teamProjectTimeId"]).Value, 2).ToString(); // ... for meals country if (!deleted) { if (teamProjectTime2Gateway.GetMealsCountry((int)ViewState["teamProjectTimeId"]).HasValue) { ddlMealsCountry.SelectedValue = teamProjectTime2Gateway.GetMealsCountry((int)ViewState["teamProjectTimeId"]).Value.ToString(); } else { ddlMealsCountry.SelectedIndex = 0; } } else { ddlMealsCountry.SelectedIndex = -1; } // ... for meals allowance //if (teamProjectTime2Gateway.GetMealsAllowance((int)ViewState["teamProjectTimeId"]) > 0) cbxMealsAllowance.Checked = true; // ... for fair wage if (teamProjectTime2Gateway.GetFairWage((int)ViewState["teamProjectTimeId"])) hdfFairWage.Value = "True"; // Store datasets Session["teamProjectTime2TDS"] = teamProjectTime2TDS; template = teamProjectTime2TDS.Template; Session["template"] = teamProjectTime2TDS.Template; } //cbxClearUnitAssigment.Checked = false; }