/// <summary>
        /// InsertDirect
        /// </summary>
        /// <param name="name">name</param>
        /// <param name="parentId">parentId</param>
        /// <param name="deleted">deleted</param>
        /// <param name="companyId">companyId</param>
        /// <param name="unitsUnitOfMeasurement">unitsUnitOfMeasurement</param>
        /// <returns>companyLevelId</returns>
        public int InsertDirect(string name, int? parentId, bool deleted, int companyId, string unitsUnitOfMeasurement)
        {
            CompanyLevelGateway companyLevelGateway = new CompanyLevelGateway(null);
            companyLevelGateway.Insert(name, parentId, deleted, companyId, unitsUnitOfMeasurement);

            int companyLevelId = companyLevelGateway.GetLastCompanyLevelId();

            return companyLevelId;
        }
        // /////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // STEP5 - SUMMARY
        //
        // ////////////////////////////////////////////////////////////////////////
        // STEP5 - SUMMARY - METHODS
        //
        private void StepSummaryIn()
        {
            // Set instruction
            Label instruction = (Label)this.Master.FindControl("lblInstruction");
            instruction.Text = "Summary";
            hdfUpdate.Value = "yes";

            string isTowable = "No"; if (cbxIsTowable.Checked) isTowable = "Yes"; else isTowable = "No";
            string unitType = (rbtnVehicle.Checked) ? unitType = "Vehicle" : unitType = "Equipment";
            string vinOrSerialNumber = (rbtnVehicle.Checked) ? vinOrSerialNumber = "VIN" : vinOrSerialNumber = "Serial Number";

            string categoriesSelected = "";
            foreach (int categoryId in arrayCategoriesSelected)
            {
                CategoryGateway categoryGateway = new CategoryGateway();
                categoryGateway.LoadByCategoryId(categoryId, Int32.Parse(hdfCompanyId.Value));
                categoriesSelected += categoryGateway.GetName(categoryId) + ", ";
            }

            if (categoriesSelected.Length > 2)
            {
                categoriesSelected = categoriesSelected.Substring(0, categoriesSelected.Length - 2);
            }

            string companyLevelsSelected = "";
            foreach (int companyLevelId in arrayCompanyLevelsSelected)
            {
                CompanyLevelGateway companyLevelGateway = new CompanyLevelGateway();
                companyLevelGateway.LoadByCompanyLevelId(companyLevelId, Int32.Parse(hdfCompanyId.Value));
                companyLevelsSelected += companyLevelGateway.GetName(companyLevelId) + ", ";
            }

            if (companyLevelsSelected.Length > 2)
            {
                companyLevelsSelected = companyLevelsSelected.Substring(0, companyLevelsSelected.Length - 2);
            }

            tbxSummary.Text = "Unit Type: " + unitType + "\nCode: " + tbxCode.Text + "\nDescription: " + tbxDescription.Text + "\n" + vinOrSerialNumber + ": " + tbxVinSerialNumber.Text + "\nManufacturer: " + tbxManufacturer.Text + "\nModel: " + tbxModel.Text + "\nYear: " + tbxYear.Text + "\nIs Towable?: " + isTowable + "\nCategories: " + categoriesSelected + "\nCompany Levels: " + companyLevelsSelected;

            if (rbtnVehicle.Checked)
            {
                string licenseCountry = "";
                string licenceState = "";

                if (ddlLicenseCountry.SelectedValue != "-1")
                {
                    licenseCountry = ddlLicenseCountry.SelectedItem.Text;

                    if (ddlLicenseState.SelectedValue != "-1" && ddlLicenseState.SelectedValue != "")
                    {
                        licenceState = ddlLicenseState.SelectedItem.Text;
                    }
                }

                tbxSummary.Text += "\nLicense Country: " + licenseCountry + "\nLicense State: " + licenceState + "\nLicense Plate Number: " + tbxLicensePlateNumber.Text + "\nApportioned Tag Number: " + tbxApportionedTagNumber.Text;
            }
        }
        // /////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // STEP6 - SUMMARY
        //
        // ////////////////////////////////////////////////////////////////////////
        // STEP6 - SUMMARY - METHODS
        //
        private void StepSummaryIn()
        {
            // Set instruction
            Label instruction = (Label)this.Master.FindControl("lblInstruction");
            instruction.Text = "Summary";
            hdfUpdate.Value = "yes";

            string mto = "No"; if (cbxMtoDot.Checked) mto = "Yes";
            string generateServiceRequest = tbxServicesRequestDaysBefore.Text + " days before";

            string categoriesSelected = "";

            foreach (int categoryId in arrayCategoriesSelected)
            {
                CategoryGateway categoryGateway = new CategoryGateway();
                categoryGateway.LoadByCategoryId(categoryId, Int32.Parse(hdfCompanyId.Value));
                categoriesSelected += categoryGateway.GetName(categoryId)+ ", ";
            }

            if (categoriesSelected.Length > 2)
            {
                categoriesSelected = categoriesSelected.Substring(0, categoriesSelected.Length - 2);
            }

            string unitsSelected = "";

            foreach (ListItem lst in cbxlUnitsSelected.Items)
            {
                if (lst.Selected)  unitsSelected += lst.Text + ", ";
            }

            if (unitsSelected.Length > 2)
            {
                unitsSelected = unitsSelected.Substring(0, unitsSelected.Length - 2);
            }

            string companyLevelsSelected = "";
            foreach (int companyLevelId in arrayCompanyLevelsSelected)
            {
                CompanyLevelGateway companyLevelGateway = new CompanyLevelGateway();
                companyLevelGateway.LoadByCompanyLevelId(companyLevelId, Int32.Parse(hdfCompanyId.Value));
                companyLevelsSelected += companyLevelGateway.GetName(companyLevelId) + ", ";
            }

            if (companyLevelsSelected.Length > 2)
            {
                companyLevelsSelected = companyLevelsSelected.Substring(0, companyLevelsSelected.Length - 2);
            }

            tbxSummary.Text = "Name: " + tbxName.Text + "\nFixed Date: " + mto + "\nDescription: " + tbxDescription.Text + "\nFrequency: " + ddlFrequency.SelectedValue + "\nGenerate Service Request?: " + generateServiceRequest + "\nCompany Levels: " + companyLevelsSelected+ "\nCategories: " + categoriesSelected + "\nUnits: " + unitsSelected ;
        }
 /// <summary>
 /// LoadNodes
 /// </summary>
 /// <param name="companyId">companyId</param>
 public void LoadNodes(int companyId)
 {
     CompanyLevelGateway companyLevelGateway = new CompanyLevelGateway(Data);
     companyLevelGateway.LoadNodes(companyId);
     UpdateData();
 }
 /// <summary>
 /// UpdateDirect
 /// </summary>
 /// <param name="originalCompanyLevelId">originalCompanyLevelId</param>
 /// <param name="originalName">originalName</param>
 /// <param name="originalParentId">originalParentId</param>
 /// <param name="originalDeleted">originalDeleted</param>
 /// <param name="originalCompanyId">originalCompanyId</param>
 /// <param name="originalUnitsUnitOfMeasurement">originalUnitsUnitOfMeasurement</param>
 /// <param name="newCompanyLevelId">newCompanyLevelId</param>        
 /// <param name="newName">newName</param>
 /// <param name="newParentId">newParentId</param>
 /// <param name="newDeleted">newDeleted</param>
 /// <param name="newCompanyId">newCompanyId</param>
 /// <param name="newUnitsUnitOfMeasurement">newUnitsUnitOfMeasurement</param>
 public void UpdateDirect(int originalCompanyLevelId, string originalName, int? originalParentId, bool originalDeleted, int originalCompanyId, string originalUnitsUnitOfMeasurement, int newCompanyLevelId, string newName, int? newParentId, bool newDeleted, int newCompanyId, string newUnitsUnitOfMeasurement)
 {
     CompanyLevelGateway companyLevelGateway = new CompanyLevelGateway(null);
     companyLevelGateway.Update(originalCompanyLevelId, originalName, originalParentId, originalDeleted, originalCompanyId, originalUnitsUnitOfMeasurement, newCompanyLevelId, newName, newParentId, newDeleted, newCompanyId, newUnitsUnitOfMeasurement);
 }
 /// <summary>
 /// DeletedDirect
 /// </summary>
 /// <param name="companyLevelId">companyLevelId</param>
 /// <param name="companyId">companyId</param>
 public void DeletedDirect(int companyLevelId, int companyId)
 {
     CompanyLevelGateway companyLevelGateway = new CompanyLevelGateway(null);
     companyLevelGateway.Delete(companyLevelId, companyId);
 }
        /// <summary>
        /// Save
        /// </summary>
        /// <returns>newCompanyLevelIdForInsert</returns>
        public int Save()
        {
            int companyLevelIdForManagers = 0 ;

            foreach (CompanyLevelsAddTDS.CompanyLevelsAddNewRow row in (CompanyLevelsAddTDS.CompanyLevelsAddNewDataTable)Data.Tables["CompanyLevelsAddNew"])
            {
                // Insert CompanyLevel
                if ((!row.Deleted) && (!row.InDatabase))
                {
                    int? parentId = null; if (!row.IsParentIDNull()) parentId = row.ParentID;
                    string unitsUnitOfMeasurement = ""; if (!row.IsUnitsUnitOfMeasurementNull()) unitsUnitOfMeasurement = row.UnitsUnitOfMeasurement;
                    companyLevelIdForManagers = InsertCompanyLevel(row.Name, parentId, row.Deleted, row.COMPANY_ID, unitsUnitOfMeasurement);
                }

                // Update CompanyLevel
                if ((!row.Deleted) && (row.InDatabase))
                {
                    int companyId = row.COMPANY_ID;
                    CompanyLevelGateway companyLevelGateway = new CompanyLevelGateway();
                    companyLevelGateway.LoadByCompanyLevelId(row.CompanyLevelID, companyId);

                    int companyLevelId = row.CompanyLevelID;
                    companyLevelIdForManagers = row.CompanyLevelID;
                    string originalName = companyLevelGateway.GetName(companyLevelId);
                    int? originalParentId = null; if (companyLevelGateway.GetParentId(companyLevelId).HasValue) originalParentId = (int)companyLevelGateway.GetParentId(companyLevelId);
                    bool originalDeleted = companyLevelGateway.GetDeleted(companyLevelId);

                    UpdateCompanyLevel(companyLevelId, originalName, originalParentId, originalDeleted, companyId, row.UnitsUnitOfMeasurement, companyLevelId, row.Name, originalParentId, row.Deleted, companyId, row.UnitsUnitOfMeasurement);
                }

                // Delete CompanyLevel
                if ((row.Deleted) && (row.InDatabase))
                {
                    int companyLevelId = row.CompanyLevelID;
                    companyLevelIdForManagers = row.CompanyLevelID;
                    int? newCompanyLevelId = null; if (!row.IsNewCompanyLevelIDNull()) newCompanyLevelId = row.NewCompanyLevelID;
                    int companyId = row.COMPANY_ID;

                    UpdateUnitsAndRulesCompanyLevels(companyLevelId, newCompanyLevelId, companyId);
                    DeleteCompanyLevel(companyLevelId, companyId);
                }
            }

            return companyLevelIdForManagers;
        }
        // ////////////////////////////////////////////////////////////////////////
        // STEP2 - STEPS INFORMATION - METHODS
        //
        private void StepStepsInformationIn()
        {
            // Set instruction
            Label instruction = (Label)this.Master.FindControl("lblInstruction");
            instruction.Text = "";

            // Load data for selected service request
            int serviceId = Int32.Parse(hdfSelectedSRId.Value);
            int companyId = Int32.Parse(hdfCompanyId.Value);

            ServiceRequestsManagerToolBasicInformation serviceRequestsManagerToolBasicInformation = new ServiceRequestsManagerToolBasicInformation(serviceRequestsManagerToolTDS);
            ServiceRequestsManagerToolCostInformation serviceRequestsManagerToolCostInformation = new ServiceRequestsManagerToolCostInformation(serviceRequestsManagerToolTDS);
            ServiceInformationServiceNote serviceInformationServiceNoteForEdit = new ServiceInformationServiceNote(serviceInformationTDS);

            if (Session["dialogOpenedServicesManagerTool"] == null)
            {
                // ... Load basic data
                serviceRequestsManagerToolBasicInformation.LoadByServiceId(serviceId, companyId);

                // ... Load costs
                serviceRequestsManagerToolCostInformation.LoadByServiceId(serviceId, companyId);

                //... Load notes
                serviceInformationServiceNoteForEdit.LoadByServiceId(serviceId, companyId);
            }
            else
            {
                ServiceRequestsManagerToolBasicInformationGateway serviceRequestsManagerToolBasicInformationGateway2 = new ServiceRequestsManagerToolBasicInformationGateway(serviceRequestsManagerToolBasicInformation.Data);

                Session.Remove("dialogOpenedServicesManagerTool");

                if (serviceRequestsManagerToolBasicInformationGateway2.GetAcceptedDateTime(serviceId).HasValue) ckbxAcceptSR.Checked = true;
                if (serviceRequestsManagerToolBasicInformationGateway2.GetStartWorkDateTime(serviceId).HasValue) ckbxStartSR.Checked = true;
                if (serviceRequestsManagerToolBasicInformationGateway2.GetUnitOutOfServiceDate(serviceId).HasValue) tkrdpStartWorkUnitOutOfServiceDate.SelectedDate = serviceRequestsManagerToolBasicInformationGateway2.GetUnitOutOfServiceDate(serviceId);
                tbxStartWorkStartMileage.Text = serviceRequestsManagerToolBasicInformationGateway2.GetStartWorkMileage(serviceId);
                if (serviceRequestsManagerToolBasicInformationGateway2.GetCompleteWorkDateTime(serviceId).HasValue) ckbxCompleteSR.Checked = true;
                if (serviceRequestsManagerToolBasicInformationGateway2.GetUnitBackInServiceDate(serviceId).HasValue) tkrdpCompleteWorkUnitBackInServiceDate.SelectedDate = serviceRequestsManagerToolBasicInformationGateway2.GetUnitBackInServiceDate(serviceId);
                tbxCompleteWorkCompleteMileage.Text = serviceRequestsManagerToolBasicInformationGateway2.GetCompleteWorkMileage(serviceId);
                tbxCompleteWorkDataDescription.Text = serviceRequestsManagerToolBasicInformationGateway2.GetCompleteWorkDetailDescription(serviceId);
                ckbxPreventableTPV.Checked = serviceRequestsManagerToolBasicInformationGateway2.GetCompleteWorkDetailPreventable(serviceId);
                tbxCompleteWorkDataLabourHours.Text = serviceRequestsManagerToolBasicInformationGateway2.GetCompleteWorkDetailTMLabourHours(serviceId).ToString();
            }

            ServiceRequestsManagerToolBasicInformationGateway serviceRequestsManagerToolBasicInformationGateway = new ServiceRequestsManagerToolBasicInformationGateway(serviceRequestsManagerToolBasicInformation.Data);

            // Validate panels and information
            string state = serviceRequestsManagerToolBasicInformationGateway.GetServiceStateOriginal(serviceId);
            hdfState.Value = state;
            hdfServiceNumber.Value = serviceRequestsManagerToolBasicInformationGateway.GetServiceNumberOriginal(serviceId);
            hdfServiceDescription.Value = serviceRequestsManagerToolBasicInformationGateway.GetServiceDescriptionOriginal(serviceId);

            string originalThirdsPartyVendor = serviceRequestsManagerToolBasicInformationGateway.GetAssignedThirdPartyVendor(serviceId);
            int? unitId = null;
            if (serviceRequestsManagerToolBasicInformationGateway.GetUnitId(serviceId).HasValue)
            {
                unitId = (int)serviceRequestsManagerToolBasicInformationGateway.GetUnitId(serviceId);
                hdfUnitId.Value = unitId.ToString();
            }

            // ... Validate vehicle information
            if (unitId.HasValue)
            {
                UnitsGateway unitsGateway = new UnitsGateway();
                unitsGateway.LoadByUnitId((int)unitId, companyId);
                string unitType = unitsGateway.GetType((int)unitId);
                hdfUnitType.Value = unitType;
                int companyLevel = unitsGateway.GetCompanyLevelId((int)unitId);
                hdfCompanyLevel.Value = unitsGateway.GetCompanyLevelId((int)unitId).ToString();

                CompanyLevelGateway companyLevelGateway = new CompanyLevelGateway();
                companyLevelGateway.LoadByCompanyLevelId(companyLevel, companyId);
                hdfMileageUnitOfMeasurement.Value = companyLevelGateway.GetUnitsUnitOfMeasurement(companyLevel);
                lblStartWorkStartMileageUnitOfMeasurement.Text = hdfMileageUnitOfMeasurement.Value;
                lblCompleteWorkCompleteMileageUnitOfMeasurement.Text = hdfMileageUnitOfMeasurement.Value;

                if (unitType == "Vehicle")
                {
                    lblStartWorkStartMileage.Visible = true;
                    tbxStartWorkStartMileage.Visible = true;
                    lblCompleteWorkCompleteMileage.Visible = true;
                    tbxCompleteWorkCompleteMileage.Visible = true;
                    lblStartWorkStartMileageUnitOfMeasurement.Visible = true;
                    lblCompleteWorkCompleteMileageUnitOfMeasurement.Visible = true;
                }
                else
                {
                    lblStartWorkStartMileage.Visible = false;
                    tbxStartWorkStartMileage.Visible = false;
                    lblStartWorkStartMileageUnitOfMeasurement.Visible = false;
                    lblCompleteWorkCompleteMileage.Visible = false;
                    tbxCompleteWorkCompleteMileage.Visible = false;
                    lblCompleteWorkCompleteMileageUnitOfMeasurement.Visible = false;
                }
            }

            // ... Validate visible internal panels (complete work info)
            if (state == "Unassigned")
            {
                if (!rbtnAssignToThirdPartyVendor.Checked)
                {
                    pnlAssignTeamMember.Visible = true;
                    pnlAssignThirdPartyVendor.Visible = false;
                }
                else
                {
                    pnlAssignThirdPartyVendor.Visible = true;
                    pnlAssignTeamMember.Visible = false;
                }
            }
            else
            {
                bool teamMemberAssigned = serviceRequestsManagerToolBasicInformationGateway.GetAssignTeamMember(serviceId);
                if (teamMemberAssigned)
                {
                    pnlAssignTeamMember.Visible = true;
                    pnlAssignThirdPartyVendor.Visible = false;
                }
                else
                {
                    pnlAssignThirdPartyVendor.Visible = true;
                    pnlAssignTeamMember.Visible = false;
                }
            }

            // ... Validate panels
            switch (state)
            {
                case "Unassigned":
                    pnlAssignmentInformation.Visible = true;
                    acceptInformationSeparator.Visible = true;
                    pnlAcceptInformation.Visible = true;
                    startWorkSeparator.Visible = true;
                    pnlStartWorkInformation.Visible = true;
                    completeWorkSeparator.Visible = true;
                    pnlCompleteWorkInformation.Visible = true;
                    break;

                case "Assigned":
                    pnlAssignmentInformation.Visible = false;
                    acceptInformationSeparator.Visible = false;
                    pnlAcceptInformation.Visible = true;
                    startWorkSeparator.Visible = true;
                    pnlStartWorkInformation.Visible = true;
                    completeWorkSeparator.Visible = true;
                    pnlCompleteWorkInformation.Visible = true;
                    break;

                case "Rejected":
                    pnlAssignmentInformation.Visible = true;
                    acceptInformationSeparator.Visible = true;
                    pnlAcceptInformation.Visible = true;
                    startWorkSeparator.Visible = true;
                    pnlStartWorkInformation.Visible = true;
                    completeWorkSeparator.Visible = true;
                    pnlCompleteWorkInformation.Visible = true;
                    break;

                case "Accepted":
                    pnlAssignmentInformation.Visible = false;
                    acceptInformationSeparator.Visible = false;
                    pnlAcceptInformation.Visible = false;
                    startWorkSeparator.Visible = false;
                    pnlStartWorkInformation.Visible = true;
                    completeWorkSeparator.Visible = true;
                    pnlCompleteWorkInformation.Visible = true;
                    break;

                case "In Progress":
                    pnlAssignmentInformation.Visible = false;
                    acceptInformationSeparator.Visible = false;
                    pnlAcceptInformation.Visible = false;
                    startWorkSeparator.Visible = false;
                    pnlStartWorkInformation.Visible = false;
                    completeWorkSeparator.Visible = false;
                    pnlCompleteWorkInformation.Visible = true;
                    break;

                default:
                    throw new Exception("The option for " + wzServices.ActiveStep.Name + " step in services_manager_tool.Wizard_ActiveStepChanged function does not exist");
            }

            hdfPnlAcceptInformation.Value = pnlAcceptInformation.Visible.ToString();
            hdfPnlAssignmentInformation.Value = pnlAssignmentInformation.Visible.ToString();
            hdfPnlStartWorkInformation.Value = pnlStartWorkInformation.Visible.ToString();
            hdfPnlCompleteWorkInformation.Value = pnlCompleteWorkInformation.Visible.ToString();

            // ... Load resource library
            int? libraryCategoriesId = null; if (serviceRequestsManagerToolBasicInformationGateway.GetLibraryCategoriesId(serviceId).HasValue) libraryCategoriesId = (int)serviceRequestsManagerToolBasicInformationGateway.GetLibraryCategoriesId(serviceId);

            if (libraryCategoriesId.HasValue)
            {
                ViewState["libraryCategoriesId"] = (int)libraryCategoriesId;
                tbxCategoryAssocited.Text = GetFullCategoryName((int)libraryCategoriesId, companyId);
                btnAssociate.Visible = false;
                btnUnassociate.Visible = true;
            }
            else
            {
                tbxCategoryAssocited.Text = "";
                btnAssociate.Visible = true;
                btnUnassociate.Visible = false;
            }

            // Store session
            Session["serviceRequestsManagerToolTDS"] = serviceRequestsManagerToolTDS;
        }
        // ////////////////////////////////////////////////////////////////////////
        // STEP2 - GENERAL INFORMATION - METHODS
        //
        private void StepGeneralInformationIn()
        {
            // Set instruction
            Label instruction = (Label)this.Master.FindControl("lblInstruction");
            instruction.Text = "";

            // Validate user - admin
            if (Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_SERVICES_ADMIN"]))
            {
                rbtnAssignToTeamMember.Visible = true;
                ddlAssignToTeamMember.Visible = true;
            }
            else
            {
                rbtnAssignToTeamMember.Visible = false;
                ddlAssignToTeamMember.Visible = false;
            }

            // Validate vehicle info
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int unitId = Int32.Parse(hdfUnitId.Value);

            UnitsGateway unitsGateway = new UnitsGateway();
            unitsGateway.LoadByUnitId(unitId, companyId);
            string unitType = unitsGateway.GetType(unitId);
            hdfUnitType.Value = unitType;
            int companyLevel = unitsGateway.GetCompanyLevelId(unitId);
            hdfCompanyLevel.Value = unitsGateway.GetCompanyLevelId(unitId).ToString();

            CompanyLevelGateway companyLevelGateway = new CompanyLevelGateway();
            companyLevelGateway.LoadByCompanyLevelId(companyLevel, companyId);
            lblMileageUnitOfMeasurement.Text = companyLevelGateway.GetUnitsUnitOfMeasurement(companyLevel);
            hdfMileageUnitOfMeasurement.Value = lblMileageUnitOfMeasurement.Text;
            lblStartWorkStartMileageUnitOfMeasurement.Text = hdfMileageUnitOfMeasurement.Value;
            lblCompleteWorkCompleteMileageUnitOfMeasurement.Text = hdfMileageUnitOfMeasurement.Value;

            if (unitType == "Vehicle")
            {
                lblMileage.Visible = true;
                tbxMileage.Visible = true;
                lblStartWorkStartMileage.Visible = true;
                tbxStartWorkStartMileage.Visible = true;
                lblCompleteWorkCompleteMileage.Visible = true;
                tbxCompleteWorkCompleteMileage.Visible = true;
                lblMileageUnitOfMeasurement.Visible = true;
                lblStartWorkStartMileageUnitOfMeasurement.Visible = true;
                lblCompleteWorkCompleteMileageUnitOfMeasurement.Visible = true;
            }
            else
            {
                lblMileage.Visible = false;
                tbxMileage.Visible = false;
                lblMileageUnitOfMeasurement.Visible = false;
                lblStartWorkStartMileage.Visible = false;
                tbxStartWorkStartMileage.Visible = false;
                lblStartWorkStartMileageUnitOfMeasurement.Visible = false;
                lblCompleteWorkCompleteMileage.Visible = false;
                tbxCompleteWorkCompleteMileage.Visible = false;
                lblCompleteWorkCompleteMileageUnitOfMeasurement.Visible = false;
            }

            // Validate panels
            if (rbtnUnassigned.Checked)
            {
                pnlAcceptInformation.Visible = false;
                pnlStartWorkInformation.Visible = false;
                pnlCompleteWorkInformation.Visible = false;
                pnlAssignThirdPartyVendor.Visible = false;
                pnlAssignTeamMember.Visible = false;
                acceptInformationSeparator.Visible = false;
                startWorkSeparator.Visible = false;
                completeWorkSeparator.Visible = false;
            }
            else
            {
                if ((rbtnAssignToMyself.Checked) || (rbtnAssignToTeamMember.Checked))
                {
                    pnlAssignThirdPartyVendor.Visible = false;
                    pnlAssignTeamMember.Visible = true;
                }
                if (rbtnAssignToThirdPartyVendor.Checked)
                {
                    pnlAssignThirdPartyVendor.Visible = true;
                    pnlAssignTeamMember.Visible = false;
                }
            }
        }
        private void TagPage()
        {
            hdfCompanyId.Value = Session["companyID"].ToString();
            hdfServiceId.Value = Request.QueryString["service_id"];
            hdfActiveTab.Value = Request.QueryString["active_tab"].ToString();

            int companyId = Int32.Parse(hdfCompanyId.Value);
            int serviceId = Int32.Parse(hdfServiceId.Value);

            ServiceInformationBasicInformationGateway serviceInformationBasicInformationGatewayForId = new ServiceInformationBasicInformationGateway();
            serviceInformationBasicInformationGatewayForId.LoadByServiceId(serviceId, companyId);
            int? unitId = serviceInformationBasicInformationGatewayForId.GetUnitID(serviceId);

            UnitsGateway unitsGateway = new UnitsGateway();
            unitsGateway.LoadByUnitId((int)unitId, companyId);
            hdfUnitType.Value = unitsGateway.GetType((int)unitId);
            hdfCompanyLevel.Value = unitsGateway.GetCompanyLevelId((int)unitId).ToString();

            int companyLevel = Int32.Parse(hdfCompanyLevel.Value);
            CompanyLevelGateway companyLevelGateway = new CompanyLevelGateway();
            companyLevelGateway.LoadByCompanyLevelId(companyLevel, companyId);
            hdfMileageUnitOfMeasurement.Value = companyLevelGateway.GetUnitsUnitOfMeasurement(companyLevel);
            lblPnlStartWorkStartMileageUnitOfMeasurement.Text = hdfMileageUnitOfMeasurement.Value;
            lblPnlCompleteWorkCompleteMileageUnitOfMeasurement.Text = hdfMileageUnitOfMeasurement.Value;
        }
        // /////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // STEP5 - SUMMARY
        //
        // ////////////////////////////////////////////////////////////////////////
        // STEP5 - SUMMARY - METHODS
        //
        private void StepSummaryIn()
        {
            // Set instruction
            Label instruction = (Label)this.Master.FindControl("lblInstruction");
            instruction.Text = "Summary";
            hdfUpdate.Value = "yes";

            // Operation
            if (rbtnAddCompanyLevel.Checked) tbxSummary.Text = "Operation: Add company level";
            if (rbtnDeleteCompanyLevel.Checked) tbxSummary.Text = "Operation: Delete company level";
            if (rbtnEditCompanyLevel.Checked) tbxSummary.Text = "Operation: Edit company level";

            // Update managers
            int companyId = Int32.Parse(hdfCompanyId.Value);
            foreach (int companyLevelIdInArray in arrayCompanyLevelsSelected)
            {
                if (rbtnDeleteCompanyLevel.Checked)
                {
                    CompanyLevelsAddManagers companyLevelMangers = new CompanyLevelsAddManagers(companyLevelsAddTDS);
                    companyLevelMangers.UpdateManagers(companyLevelIdInArray, companyId);
                }

                //Tag page
                hdfCompanyLevelId.Value = companyLevelIdInArray.ToString();
            }

            Session["companyLevelsAddTDS"] = companyLevelsAddTDS;
            Session["companyLevelManagers"] = companyLevelsAddTDS.CompanyLevelManagers;
            companyLevelManagers = companyLevelsAddTDS.CompanyLevelManagers;

            // Company Levels
            if (!rbtnDeleteCompanyLevel.Checked)
            {
                if (arrayCompanyLevelsSelected.Count > 0)
                {
                    foreach (int companyLevelIdInArray in arrayCompanyLevelsSelected)
                    {
                        CompanyLevelGateway companyLevelGateway = new CompanyLevelGateway();
                        companyLevelGateway.LoadByCompanyLevelId(companyLevelIdInArray, int.Parse(hdfCompanyId.Value));

                        tbxSummary.Text += "\nParent company level: " + companyLevelGateway.GetName(companyLevelIdInArray);
                    }
                }
                else
                {
                    tbxSummary.Text += "\nParent company level: (Empty)";
                }
            }

            // Name
            if (!rbtnDeleteCompanyLevel.Checked)
            {
                tbxSummary.Text += "\nName: " + tbxName.Text.Trim();
            }
            else
            {
                foreach (int companyLevelIdInArray in arrayCompanyLevelsSelected)
                {
                    CompanyLevelGateway companyLevelGateway = new CompanyLevelGateway();
                    companyLevelGateway.LoadByCompanyLevelId(companyLevelIdInArray, int.Parse(hdfCompanyId.Value));

                    tbxSummary.Text += "\nName: " + companyLevelGateway.GetName(companyLevelIdInArray);
                }
            }

            // Unit Of Measurement
            tbxSummary.Text += "\nUnit Of Measurement: " + tbxUnitsUnitOfMeasurement.Text.Trim();

            // Managers
            CompanyLevelsAddManagers companyLevelManagersForSummary = new CompanyLevelsAddManagers(companyLevelsAddTDS);
            tbxSummary.Text += "\nManagers: " + companyLevelManagersForSummary.GetManagers();
        }
        /// <summary>
        /// UpdateRuleCompanyLevel
        /// </summary>
        /// <param name="ruleId">ruleId</param>
        /// <param name="companyId">companyId</param>
        /// <param name="companyLevelsSected">companyLevelsSected</param>
        private void UpdateRuleCompanyLevel(int ruleId, int companyId, ArrayList companyLevelsSelected)
        {
            CompanyLevelGateway companyLevelGateway = new CompanyLevelGateway();
            companyLevelGateway.Load(companyId);

            if (companyLevelGateway.Table.Rows.Count > 0)
            {
                foreach (CompanyLevelsTDS.LFS_FM_COMPANYLEVELRow row in (CompanyLevelsTDS.LFS_FM_COMPANYLEVELDataTable)companyLevelGateway.Table)
                {
                    int companyLevelId = row.CompanyLevelID;

                    RuleCompanyLevelGateway ruleCompanyLevelGateway = new RuleCompanyLevelGateway(null);

                    if (ruleCompanyLevelGateway.IsUsedInRuleCompanyLevel(ruleId, companyLevelId, true))
                    {
                        if (!companyLevelsSelected.Contains(companyLevelId))
                        {
                            RuleCompanyLevel ruleCompanyLevel = new RuleCompanyLevel(null);
                            ruleCompanyLevel.DeleteDirect(ruleId, companyLevelId, companyId);
                        }
                        else
                        {
                            RuleCompanyLevel ruleCompanyLevel = new RuleCompanyLevel(null);
                            ruleCompanyLevel.UnDeleteDirect(ruleId, companyLevelId, companyId);
                        }
                    }
                    else
                    {
                        if (companyLevelsSelected.Contains(companyLevelId))
                        {
                            RuleCompanyLevel ruleCompanyLevel = new RuleCompanyLevel(null);
                            ruleCompanyLevel.InsertDirect(ruleId, companyLevelId, false, companyId);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// DeleteRuleCompanyLevel
        /// </summary>
        /// <param name="ruleId">ruleId</param>
        /// <param name="companyId">companyId</param>
        private void DeleteRuleCompanyLevel(int ruleId, int companyId)
        {
            CompanyLevelGateway companyLevelGateway = new CompanyLevelGateway();
            companyLevelGateway.Load(companyId);

            if (companyLevelGateway.Table.Rows.Count > 0)
            {
                foreach (CompanyLevelsTDS.LFS_FM_COMPANYLEVELRow row in (CompanyLevelsTDS.LFS_FM_COMPANYLEVELDataTable)companyLevelGateway.Table)
                {
                    int companyLevelId = row.CompanyLevelID;

                    RuleCompanyLevelGateway ruleCompanyLevelGateway = new RuleCompanyLevelGateway(null);

                    if (ruleCompanyLevelGateway.IsUsedInRuleCompanyLevel(ruleId, companyLevelId))
                    {
                        RuleCompanyLevel ruleCompanyLevel = new RuleCompanyLevel(null);
                        ruleCompanyLevel.DeleteDirect(ruleId, companyLevelId, companyId);
                    }
                }
            }
        }