private void UpdateTimesheet() { int employeeId = Int32.Parse(hdfEmployeeID.Value); int periodId = Int32.Parse(hdfPeriodId.Value); TimesheetTDS timesheetTDS = new TimesheetTDS(); TimesheetGateway timesheetGateway = new TimesheetGateway(timesheetTDS); timesheetGateway.LoadByEmployeeIdPayPeriodId(employeeId, periodId); LiquiForce.LFSLive.BL.LabourHours.Timesheet.Timesheet timesheet = new LiquiForce.LFSLive.BL.LabourHours.Timesheet.Timesheet(timesheetTDS); // Approve timesheet if (ViewState["timesheetState"].ToString() == "Approved") { EmployeeGateway employeeGateway1 = new EmployeeGateway(new DataSet()); ViewState["approved_by_id"] = employeeGateway1.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"])); timesheet.Approve(employeeId, periodId, (int)ViewState["approved_by_id"]); } // Reject timesheet if (ViewState["timesheetState"].ToString() == "Rejected") { timesheet.Reject(employeeId, periodId); } // Submit timesheet if (ViewState["timesheetState"].ToString() == "Submitted") { timesheet.Submit(employeeId, periodId); } try { timesheetGateway.Update2(); timesheetTDS.AcceptChanges(); } catch (Exception ex) { string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' ')); Response.Redirect(url); } }
// //////////////////////////////////////////////////////////////////////// // EVENTS // protected void Page_Load(object sender, EventArgs e) { // Register client scripts this.RegisterClientScripts(); if (!IsPostBack) { // Validate query string if (((string)Request.QueryString["source_page"] == null) && ((string)Request.QueryString["others"] == null) && ((string)Request.QueryString["employee_id"] == null) && ((string)Request.QueryString["period_id"] == null)) { Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in timesheet_add.aspx"); } // Security check if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"])) { if (Request.QueryString["others"] == "no") { if (!(Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_VIEW"]) && Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_ADD"]))) { if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"])) { if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"])) { Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator."); } } } } else { if (!(Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_VIEW"]) && Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_ADD"]))) { if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"])) { if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"])) { if (!(Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_VIEW"]) && Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_ADD"]))) { if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT"])) { if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT_WED"])) { Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator."); } } } } } } } } // Tag Page hdfSaveClick.Value = "false"; hdfEmployeeID.Value = Request.QueryString["employee_id"].ToString(); hdfPeriodId.Value = Request.QueryString["period_id"]; hdfCompanyId.Value = Session["companyID"].ToString(); hdfIsMoreThan15.Value = "false"; hdfIsMoreThan15Edit.Value = "false"; Session.Remove("projectTimeTempNewDummy"); // Initialize viewstate variables ViewState["others"] = Request.QueryString["others"]; ViewState["timesheetState"] = "For Approval"; // Get State int employeeId = Int32.Parse(hdfEmployeeID.Value); int periodId = Int32.Parse(hdfPeriodId.Value); TimesheetGateway timesheet = new TimesheetGateway(); timesheet.LoadByEmployeeIdPayPeriodId(employeeId, periodId); if (timesheet.Table.Rows.Count != 0) { ViewState["timesheetState"] = timesheet.GetStateByEmployeeIdPayPeriodId(employeeId, periodId); } if (Request.QueryString["source_page"] == "timesheet_summary.aspx" || Request.QueryString["source_page"] == "timesheet_summary_from_approve_project_times.aspx") { ViewState["projecttime_id"] = int.Parse(Request.QueryString["projecttime_id"]); } System.Configuration.AppSettingsReader appSettingReader = new System.Configuration.AppSettingsReader(); ViewState["LHMode"] = appSettingReader.GetValue("LABOUR_HOURS_OPERATION_MODE", typeof(System.String)).ToString(); // Timesheet state check if (((string)ViewState["LHMode"] == "Full") && (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))) { TimesheetGateway timesheetGateway = new TimesheetGateway(); timesheetGateway.LoadByEmployeeIdPayPeriodId(employeeId, periodId); if ((timesheetGateway.Table.Rows.Count != 0) && (timesheetGateway.GetStateByEmployeeIdPayPeriodId(employeeId, periodId) != "Rejected")) { Response.Redirect("./../../error_page.aspx?error=" + "You cannot add project time to an approved or submitted timesheet."); } } // Prepare initial data for client EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet()); employeeGateway.LoadByEmployeeId(employeeId); tbxEmployee.Text = employeeGateway.GetFullName(employeeId); tbxState.Text = "For Approval"; int companyId = Int32.Parse(hdfCompanyId.Value); CompaniesList companiesList = new CompaniesList(new DataSet()); companiesList.LoadAndAddItem(-1, "(Select a client)", companyId); ddlClient.DataSource = companiesList.Table; ddlClient.DataValueField = "COMPANIES_ID"; ddlClient.DataTextField = "Name"; ddlClient.DataBind(); ddlClient.SelectedIndex = 0; ProjectList projectList = new ProjectList(); projectList.LoadActiveProjectsActiveInternalProjectsActiveBallparkProjectsAndAddItem(-1, "(Select a project)", -1); ddlProject.DataSource = projectList.Table; ddlProject.DataValueField = "ProjectID"; ddlProject.DataTextField = "Name"; ddlProject.DataBind(); ddlProject.SelectedIndex = 0; CountryList countryList = new CountryList(new DataSet()); countryList.LoadAndAddItem(-1, " "); ddlMealsCountry.DataSource = countryList.Table; ddlMealsCountry.DataValueField = "CountryID"; ddlMealsCountry.DataTextField = "Name"; ddlMealsCountry.DataBind(); tkrdpStartDate.SelectedDate = DateTime.Now; tkrdpEndDate.SelectedDate = DateTime.Now; // Store timesheet dataset projectTimeTDS = new ProjectTimeTDS(); Session["projectTimeTDS"] = projectTimeTDS; projectTimeTemp = projectTimeTDS.LFS_PROJECT_TIME_TEMP; Session["projectTimeTemp"] = projectTimeTDS.LFS_PROJECT_TIME_TEMP; } else { // Restore datasets projectTimeTDS = (ProjectTimeTDS)Session["projectTimeTDS"]; projectTimeTemp = projectTimeTDS.LFS_PROJECT_TIME_TEMP; // Store datasets Session["projectTimeTemp"] = projectTimeTemp; } }