Пример #1
0
        /// <summary>
        /// Update
        /// </summary>
        /// <param name="teamProjectTimeId">teamProjectTimeId</param>
        /// <param name="teamProjectTimeIdForReplace">teamProjectTimeIdForReplace</param>
        /// <param name="teamProjectTime2TDSToSave">teamProjectTime2TDSToSave</param>
        public void Update(int teamProjectTimeId, int teamProjectTimeIdForReplace, TeamProjectTime2TDS teamProjectTime2TDSToSave)
        {
            // Update existing row
            TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIMERow masterRow = GetRow(teamProjectTimeId);

            int companiesId = masterRow.CompaniesID;
            int projectId = masterRow.ProjectID;
            DateTime date_ = masterRow.Date_;
            DateTime? startTime = null; if (!masterRow.IsNull("StartTime")) startTime = masterRow.StartTime;
            DateTime? endTime = null; if (!masterRow.IsNull("EndTime")) endTime = masterRow.EndTime;
            double? offset = null; if (!masterRow.IsNull("Offset")) offset = masterRow.Offset;
            string workingDetails = ""; if (!masterRow.IsNull("WorkingDetails")) workingDetails = masterRow.WorkingDetails;
            string location = ""; if (!masterRow.IsNull("Location")) location = masterRow.Location;
            Int64? mealsCountry = null; if (!masterRow.IsNull("MealsCountry")) mealsCountry = masterRow.MealsCountry;
            String mealsAllowanceType = ""; if (!masterRow.IsNull("MealsAllowanceType")) mealsAllowanceType = masterRow.MealsAllowanceType;
            decimal mealsAllowance = masterRow.MealsAllowance;
            int? unitId = null; if (!masterRow.IsNull("UnitID")) unitId = masterRow.UnitID;
            int? towedUnitId = null; if (!masterRow.IsNull("TowedUnitID")) towedUnitId = masterRow.TowedUnitID;
            string comments = ""; if (!masterRow.IsNull("Comments")) comments = masterRow.Comments;
            string type = "Template";
            string state = "Done";
            int loginId = masterRow.LoginID;
            bool deleted = false;
            string work_ = masterRow.Work_;
            string function_ = masterRow.Function_;
            bool fairWage = masterRow.FairWage;

            // ... Load existing row
            TeamProjectTime2Gateway teamProjectTime2Gateway = new TeamProjectTime2Gateway(teamProjectTime2TDSToSave);
            teamProjectTime2Gateway.LoadByTeamProjectTimeId(teamProjectTimeIdForReplace);

            // ... Replace existing row
            TeamProjectTime2 teamProjectTime2ToSave = new TeamProjectTime2(teamProjectTime2TDSToSave);
            teamProjectTime2ToSave.Update(teamProjectTimeIdForReplace, teamProjectTime2Gateway.GetTemplateName(teamProjectTimeIdForReplace), companiesId, projectId, date_, startTime, endTime, offset, workingDetails, location, mealsCountry, mealsAllowanceType, mealsAllowance, unitId, towedUnitId, comments, type, state, loginId, deleted, work_, function_, fairWage);

            // Update or delete detail rows
            TeamProjectTime2Detail teamProjectTime2Detail = new TeamProjectTime2Detail(Data);
            teamProjectTime2Detail.Update(teamProjectTimeId, teamProjectTimeIdForReplace, teamProjectTime2TDSToSave);
        }
        private void PostStepDataChanges()
        {
            int teamProjectTimeId = (int)ViewState["teamProjectTimeId"];
            string templateName = "";
            int companiesId = int.Parse(ddlClient.SelectedValue);
            int projectId = int.Parse(ddlProject.SelectedValue);
            DateTime date_ = tkrdpDate_.SelectedDate.Value;
            string workingDetails = ""; if (tbxWorkingDetails.Text != "(Select)") workingDetails = tbxWorkingDetails.Text;
            string work_ = ddlTypeOfWork.SelectedValue;
            string function_ = ddlFunction.SelectedValue;

            ProjectGateway projectGateway = new ProjectGateway(new DataSet());
            projectGateway.LoadByProjectId(projectId);

            CountryGateway countryGateway = new CountryGateway(new DataSet());
            countryGateway.LoadByCountryId(projectGateway.GetCountryID(projectId));

            string location = countryGateway.GetName(projectGateway.GetCountryID(projectId));

            DateTime? startTime = null;
            if ((ddlStartTimeHour.SelectedValue.Trim() != "") && (ddlStartTimeMinute.SelectedValue.Trim() != "") )
            {
                startTime = new DateTime(date_.Year, date_.Month, date_.Day, Int32.Parse(ddlStartTimeHour.SelectedValue), Int32.Parse(ddlStartTimeMinute.SelectedValue), 0);
            }

            DateTime? endTime = null;
            if ((ddlEndTimeHour.SelectedValue.Trim() != "") && (ddlEndTimeMinute.SelectedValue.Trim() != "") )
            {
                endTime = new DateTime(date_.Year, date_.Month, date_.Day, Int32.Parse(ddlEndTimeHour.SelectedValue), Int32.Parse(ddlEndTimeMinute.SelectedValue), 0);
            }

            double? offset = 0; if (ddlLunch.SelectedValue != "0") offset = double.Parse(ddlLunch.SelectedValue);
            Int64? mealsCountry = null; if (ddlMealsCountry.SelectedValue != "-1") mealsCountry = Int64.Parse(ddlMealsCountry.SelectedValue);
            string mealsAllowanceType = ""; //if (cbxMealsAllowance.Checked) mealsAllowanceType = "Full Day";
            decimal mealsAllowance = MealsAllowance.GetMealsAllowance(mealsCountry, false, "Full Day");
            string comments = "";
            string type = "Template";
            string state = "Done";
            int loginId = Convert.ToInt32(Session["loginID"]);
            bool deleted = false;
            int? unitId = null;
            int? towedUnitId = null;
            bool fairWage = false; if (hdfFairWage.Value == "True") fairWage = true;

            // New template check
            TeamProjectTime2 teamProjectTime2 = new TeamProjectTime2(teamProjectTime2TDS);
            if (((int)ViewState["teamProjectTimeId"] == 0) && ((string)ViewState["StepFrom"] != "Employees"))
            {
                // ... Insert team project time
                teamProjectTime2.Insert(teamProjectTimeId, templateName, companiesId, projectId, date_, startTime, endTime, offset, workingDetails, location, mealsCountry, mealsAllowanceType, mealsAllowance, unitId, towedUnitId, comments, type, state, loginId, deleted, work_, function_, fairWage);
            }
            else
            {
                // ... Update team project time
                teamProjectTime2.Update(teamProjectTimeId, templateName, companiesId, projectId, date_, startTime, endTime, offset, workingDetails, location, mealsCountry, mealsAllowanceType, mealsAllowance, unitId, towedUnitId, comments, type, state, loginId, deleted, work_, function_, fairWage);
            }

            // Store date in date edit for employees step
            tbxDate.Text = tkrdpDate_.SelectedDate.Value.ToString();
            hdfDate.Value = tkrdpDate_.SelectedDate.Value.ToString();

            // Store data in hidden components for employees step
            hdfTeamProjectTimeID.Value = teamProjectTimeId.ToString();
            hdfCompaniesID.Value = companiesId.ToString();
            hdfProjectID.Value = projectId.ToString();

            string startTimeForNextStep = "";
            if ((ddlStartTimeHour.SelectedValue.Trim() != "") && (ddlStartTimeMinute.SelectedValue.Trim() != ""))
            {
                startTimeForNextStep = ddlStartTimeHour.SelectedValue.Trim() + ":" + ddlStartTimeMinute.SelectedValue.Trim();
            }
            hdfStartTime.Value = startTimeForNextStep;

            string endTimeForNextStep = "";
            if ((ddlEndTimeHour.SelectedValue.Trim() != "") && (ddlEndTimeMinute.SelectedValue.Trim() != ""))
            {
                endTimeForNextStep = ddlEndTimeHour.SelectedValue.Trim() + ":" + ddlEndTimeMinute.SelectedValue.Trim();
            }

            hdfEndTime.Value = endTimeForNextStep;
            if (offset != null) hdfOffset.Value = offset.ToString(); else hdfOffset.Value = "";
            hdfWorkingDetails.Value = workingDetails.ToString();
            hdfLocation.Value = location.ToString();
            hdfMealsCountry.Value = ddlMealsCountry.SelectedValue;
            hdfIsMealsAllowance.Value = "false";// cbxMealsAllowance.Checked.ToString();
            hdfMealsAllowance.Value = mealsAllowance.ToString();
            hdfProjectTimeState.Value = "For Approval"; if ((string)ViewState["LHMode"] == "Partial") hdfProjectTimeState.Value = "Approved";
            //if (cbxClearUnitAssigment.Checked)
            hdfClearUnitAssigment.Value = "false";

            // ... For work and function string
            hdfWork_.Value = work_;
            hdfFunction_.Value = function_;
            hdfWorkFunctionConcat.Value = work_ + " . " + function_;

            // Clear Unit Assigment validation
            //if (cbxClearUnitAssigment.Checked)
            //{
            //    // ... Update detail
            //    TeamProjectTime2DetailTemp teamProjectTime2DetailTemp = new TeamProjectTime2DetailTemp(teamProjectTime2TDS);
            //    teamProjectTime2DetailTemp.UpdateAll(teamProjectTimeId);
            //}
            //else
            //{
                // ... Update detail
                TeamProjectTime2DetailTemp teamProjectTime2DetailTemp = new TeamProjectTime2DetailTemp(teamProjectTime2TDS);
                teamProjectTime2DetailTemp.UpdateAll(teamProjectTimeId, false);
            //}

            // Store datasets
            Session["teamProjectTime2TDS"] = teamProjectTime2TDS;
            teamProjectTimeDetailTemp = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMP;
            Session["teamProjectTimeDetailTemp"] = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMP;
        }
        private bool PostStepEndChanges(int companyId)
        {
            // Update project times
            projectTime2TDS = new ProjectTimeTDS();
            if (cbxEndConfirm.Checked)
            {
                EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
                int employeeId = employeeGateway.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));

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

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

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

            return true;
        }
        private void DeleteTemplate(int teamProjectTimeId)
        {
            // Create TDS to save
            teamProjectTime2TDSToSave = new TeamProjectTime2TDS();

            // Delete Template
            TeamProjectTime2Template teamProjectTime2Template = new TeamProjectTime2Template(teamProjectTime2TDS);
            teamProjectTime2Template.Delete(teamProjectTimeId);

            // ... Store datasets for teplate
            Session.Remove("templateDummy");
            Session["teamProjectTime2TDS"] = teamProjectTime2TDS;
            template = teamProjectTime2TDS.Template;
            Session["template"] = teamProjectTime2TDS.Template;

            // Delete associated TeamProjectTime to Template
            // ... load TeamProjectTime
            TeamProjectTime2Gateway teamProjectTime2Gateway = new TeamProjectTime2Gateway(teamProjectTime2TDSToSave);
            teamProjectTime2Gateway.LoadByTeamProjectTimeId(teamProjectTimeId);

            // ... delete TeamProjectTime
            TeamProjectTime2 teamProjectTime2 = new TeamProjectTime2(teamProjectTime2TDSToSave);
            teamProjectTime2.Delete(teamProjectTimeId);

            // Delete associated TeamProjectTimeDetails to Template
            // ... load TeamProjectTimeDetails
            TeamProjectTime2DetailGateway teamProjectTime2DetailGateway = new TeamProjectTime2DetailGateway(teamProjectTime2TDSToSave);
            teamProjectTime2DetailGateway.LoadByTeamProjectTimeId(teamProjectTimeId);

            // ... delete TeamProjectTimeDetails
            TeamProjectTime2Detail teamProjectTime2Detail = new TeamProjectTime2Detail(teamProjectTime2TDSToSave);
            teamProjectTime2Detail.Delete(teamProjectTimeId);
        }