private void GrdProjectTimeAdd() { Page.Validate("generalData"); int projectId = int.Parse(ddlProject.SelectedValue); if (Page.IsValid) { Page.Validate("footerValidData"); if (Page.IsValid) { Page.Validate("footerData"); if (Page.IsValid) { // Validate project times if (FooterValidate()) { // Save data int employeeId = Int32.Parse(hdfEmployeeID.Value); int companiesId = int.Parse(ddlClient.SelectedValue); if (projectId != 35 && projectId != 39 && projectId != 716) { DateTime date_ = tkrdpStartDate.SelectedDate.Value; Int64? mealsCountry = null; if (ddlMealsCountry.SelectedValue != "-1") mealsCountry = Int64.Parse(ddlMealsCountry.SelectedValue); string startTimeFooter = ""; string startHoursFooter = ""; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlStartTimeHourFooter")).SelectedValue != "") startHoursFooter = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlStartTimeHourFooter")).SelectedValue.Trim(); string startMinutesFooter = ""; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlStartTimeMinuteFooter")).SelectedValue != "") startMinutesFooter = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlStartTimeMinuteFooter")).SelectedValue.Trim(); if ((startHoursFooter != "") && (startMinutesFooter != "")) { startTimeFooter = startHoursFooter + ":" + startMinutesFooter; } string endTimeFooter = ""; string endHoursFooter = ""; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlEndTimeHourFooter")).SelectedValue != "") endHoursFooter = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlEndTimeHourFooter")).SelectedValue.Trim(); string endMinutesFooter = ""; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlEndTimeMinuteFooter")).SelectedValue != "") endMinutesFooter = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlEndTimeMinuteFooter")).SelectedValue.Trim(); if ((endHoursFooter != "") && (endMinutesFooter != "")) { endTimeFooter = endHoursFooter + ":" + endMinutesFooter; } decimal? offsetFooter = 0; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlLunchFooter")).SelectedValue != "0") offsetFooter = Decimal.Round(decimal.Parse(((DropDownList)grdProjectTime.FooterRow.FindControl("ddlLunchFooter")).SelectedValue), 2); double? offsetFooterFinal = null; if (offsetFooter.HasValue) offsetFooterFinal = double.Parse(((decimal)offsetFooter).ToString()); string typeOfWorkFooter = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlTypeOfWorkFooter")).SelectedValue; int? unitIdFooter = null; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlUnitFooter")).SelectedValue != "-1") unitIdFooter = Int32.Parse(((DropDownList)grdProjectTime.FooterRow.FindControl("ddlUnitFooter")).SelectedValue); int? towedIdFooter = null; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlTowedFooter")).SelectedValue != "-1") towedIdFooter = Int32.Parse(((DropDownList)grdProjectTime.FooterRow.FindControl("ddlTowedFooter")).SelectedValue); string workingDetailsFooter = "Canada"; workingDetailsFooter = hdfWorkingDetails.Value; bool isMealsAllowanceFooter = false;// ((CheckBox)grdProjectTime.FooterRow.FindControl("ckbxMealsAllowanceFooter")).Checked; string commentsFooter = ((TextBox)grdProjectTime.FooterRow.FindControl("tbxCommentsFooter")).Text; int companyId = Int32.Parse(hdfCompanyId.Value); ProjectGateway projectGateway = new ProjectGateway(new DataSet()); projectGateway.LoadByProjectId(projectId); bool fairWage = projectGateway.GetFairWageApplies(projectId); string projectTimeState = "For Approval"; if ((string)ViewState["LHMode"] == "Partial") projectTimeState = "Approved"; string work_ = ""; string function_ = ""; if (typeOfWorkFooter != "(Select)" && typeOfWorkFooter != "") { string[] workFunction = typeOfWorkFooter.ToString().Trim().Split('.'); work_ = workFunction[0].Trim(); function_ = workFunction[1].Trim(); } CountryGateway countryGateway = new CountryGateway(new DataSet()); countryGateway.LoadByCountryId(projectGateway.GetCountryID(projectId)); string location = ""; if (countryGateway.Table.Rows.Count > 0) { location = countryGateway.GetName(projectGateway.GetCountryID(projectId)); } string mealsAllowanceType = ""; if (isMealsAllowanceFooter) mealsAllowanceType = "Full Day"; decimal mealsAllowance = MealsAllowance.GetMealsAllowance(mealsCountry, isMealsAllowanceFooter, "Full Day"); string jobClassType = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlJobClassTypeFooter")).SelectedValue; // Insert Data ProjectTimeTemp model = new ProjectTimeTemp(projectTimeTDS); model.Insert(employeeId, companiesId, projectId, date_, startTimeFooter, endTimeFooter, offsetFooterFinal, workingDetailsFooter, location, mealsCountry, mealsAllowanceType, isMealsAllowanceFooter, mealsAllowance, unitIdFooter, towedIdFooter, projectTimeState, commentsFooter, work_, function_, typeOfWorkFooter, fairWage, jobClassType); // Store Dataset Session.Remove("projectTimeTempNewDummy"); Session["projectTimeTDS"] = projectTimeTDS; Session["projectTimeTemp"] = projectTimeTDS.LFS_PROJECT_TIME_TEMP; grdProjectTime.DataBind(); grdProjectTime.PageIndex = grdProjectTime.PageCount - 1; } } } } hdfIsMoreThan15.Value = "false"; upIsMoreThan15.Update(); } }
// //////////////////////////////////////////////////////////////////////// // NAVIGATION EVENTS // protected void tkrmTop_ItemClick(object sender, RadMenuEventArgs e) { DropDownList ddlOthersFor = (DropDownList)tkrpbLeftMenuOthersTimesheets.FindItemByValue("nbOthersTimesheetsDDL").FindControl("ddlOthersFor"); Session["ddlOthersForSelectedValue"] = ddlOthersFor.SelectedValue; int employeeId = Int32.Parse(hdfEmployeeID.Value); int periodId = Int32.Parse(hdfPeriodId.Value); switch (e.Item.Value) { case "mSave": if (ValidatePage()) { int companiesId = int.Parse(ddlClient.SelectedValue); int projectId = int.Parse(ddlProject.SelectedValue); if (projectId == 35 || projectId == 39 || projectId == 716) { Page.Validate("specialData"); if (Page.IsValid) { DateTime startDate = tkrdpStartDate.SelectedDate.Value; DateTime lastDate = tkrdpEndDate.SelectedDate.Value; DateTime date_ = startDate; while (date_ <= lastDate) { Int64? mealsCountry = null; string startTimeFooter = ""; string endTimeFooter = ""; double? offsetFooterFinal = 0; string typeOfWorkFooter = ""; int? unitIdFooter = null; int? towedIdFooter = null; string workingDetailsFooter = ddlWorkingDetails.SelectedValue; bool isMealsAllowanceFooter = false; string commentsFooter = tbxCommentsVacation.Text; int companyId = Int32.Parse(hdfCompanyId.Value); bool fairWage = false; string projectTimeState = "For Approval"; if ((string)ViewState["LHMode"] == "Partial") projectTimeState = "Approved"; string work_ = ""; string function_ = ""; ProjectGateway projectGateway = new ProjectGateway(new DataSet()); projectGateway.LoadByProjectId(projectId); CountryGateway countryGateway = new CountryGateway(new DataSet()); countryGateway.LoadByCountryId(projectGateway.GetCountryID(projectId)); string location = ""; if (countryGateway.Table.Rows.Count > 0) { location = countryGateway.GetName(projectGateway.GetCountryID(projectId)); } string mealsAllowanceType = ""; decimal mealsAllowance = MealsAllowance.GetMealsAllowance(mealsCountry, isMealsAllowanceFooter, "Full Day"); string jobClassType = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlJobClassTypeFooter")).SelectedValue; // Insert Data ProjectTimeTemp model = new ProjectTimeTemp(projectTimeTDS); model.Insert(employeeId, companiesId, projectId, date_, startTimeFooter, endTimeFooter, offsetFooterFinal, workingDetailsFooter, location, mealsCountry, mealsAllowanceType, isMealsAllowanceFooter, mealsAllowance, unitIdFooter, towedIdFooter, projectTimeState, commentsFooter, work_, function_, typeOfWorkFooter, fairWage, jobClassType); date_ = date_.AddDays(1); // ... ... Store Dataset Session.Remove("projectTimeTempNewDummy"); Session["projectTimeTDS"] = projectTimeTDS; Session["projectTimeTemp"] = projectTimeTDS.LFS_PROJECT_TIME_TEMP; } PostPageChanges(); UpdateDatabase(); Response.Redirect("./../timesheet/timesheet.aspx?source_page=timesheet_add.aspx&others=" + ViewState["others"] + "&employee_id=" + employeeId.ToString() + "&period_id=" + periodId.ToString() + "&projecttime_id=" + DB.GetIdentCurrent("LFS_PROJECT_TIME").ToString()); } } else { // Project time Gridview, if the gridview is edition mode if (grdProjectTime.EditIndex >= 0) { grdProjectTime.UpdateRow(grdProjectTime.EditIndex, true); } // Insert Data GrdProjectTimeAdd(); PostPageChanges(); UpdateDatabase(); Response.Redirect("./../timesheet/timesheet.aspx?source_page=timesheet_add.aspx&others=" + ViewState["others"] + "&employee_id=" + employeeId.ToString() + "&period_id=" + periodId.ToString() + "&projecttime_id=" + DB.GetIdentCurrent("LFS_PROJECT_TIME").ToString()); } } break; case "mCancel": if (Request.QueryString["source_page"] == "timesheet.aspx") { Response.Redirect("./../timesheet/timesheet.aspx?source_page=timesheet_add.aspx&others=" + ViewState["others"] + "&employee_id=" + employeeId.ToString() + "&period_id=" + periodId.ToString()); } else { if (Request.QueryString["source_page"] == "timesheet_summary_from_approve_project_times.aspx") { Response.Redirect("./timesheet_summary.aspx?source_page=timesheet_approve.aspx&others=" + ViewState["others"] + "&employee_id=" + employeeId.ToString() + "&period_id=" + periodId.ToString() + "&projecttime_id=" + ViewState["projecttime_id"]); } else { Response.Redirect("./timesheet_summary.aspx?source_page=timesheet_add.aspx&others=" + ViewState["others"] + "&employee_id=" + employeeId.ToString() + "&period_id=" + periodId.ToString() + "&projecttime_id=" + ViewState["projecttime_id"]); } } break; } }