private void LoadData(int ruleId)
        {
            RuleGateway ruleGateway = new RuleGateway(ruleTDS);

            if (ruleGateway.Table.Rows.Count > 0)
            {
                tbxName.Text = ruleGateway.GetName(ruleId);
                cbxMtoDot.Checked = ruleGateway.GetMto(ruleId);
                tbxDescription.Text = ruleGateway.GetDescription(ruleId);
                tbxFrecuency.Text = ruleGateway.GetFrequency(ruleId);
                tbxServicesRequestDaysBefore.Text = ""; if (ruleGateway.GetServiceRequestDays(ruleId).HasValue) tbxServicesRequestDaysBefore.Text = ((int)(ruleGateway.GetServiceRequestDays(ruleId))).ToString();

                // Load Trees
                GetNodeForCategory(tvCategoriesRoot.Nodes, 0);
                GetNodeForCompanyLevels(tvCompanyLevelsRoot.Nodes, 0);

                // Load Units
                int companyId = Int32.Parse(hdfCompanyId.Value);
                string category = "";
                UnitsList unitsList = new UnitsList(new DataSet());

                foreach (int categoryId in arrayCategoriesSelected)
                {
                    CategoryGateway categoryGateway = new CategoryGateway();

                    //Verify the location of the unit
                    foreach (int companyLevelId in arrayCompanyLevelsSelected)
                    {
                        // Load the unit if corresponds
                        categoryGateway.LoadByCategoryId(categoryId, Int32.Parse(hdfCompanyId.Value));
                        category = categoryGateway.GetName(categoryId);

                        unitsList.LoadAndAddItemByCategoryCompanyLevelId(category, companyLevelId, companyId);
                    }
                }

                if (unitsList.Table != null)
                {
                    cbxlUnitsSelected.DataSource = RemoveDuplicateRows(unitsList.Table, "UnitID");
                    cbxlUnitsSelected.DataValueField = "UnitID";
                    cbxlUnitsSelected.DataTextField = "UnitCode";
                    cbxlUnitsSelected.DataBind();

                    // Total units
                    lblTotalUnits.Text = "Total Units: " + cbxlUnitsSelected.Items.Count;
                }
                else
                {
                    // Total units
                    lblTotalUnits.Text = "Total Units: 0";
                }
            }
        }
        private void LoadBasicData(int serviceId)
        {
            ServiceInformationBasicInformationGateway serviceInformationBasicInformationGateway = new ServiceInformationBasicInformationGateway(serviceInformationTDS);
            if (serviceInformationBasicInformationGateway.Table.Rows.Count > 0)
            {
                // Load service basic data
                tbxServiceState.Text = serviceInformationBasicInformationGateway.GetServiceState(serviceId);
                tbxServiceNumber.Text = serviceInformationBasicInformationGateway.GetServiceNumber(serviceId);
                tbxDateTime.Text = serviceInformationBasicInformationGateway.GetDateTime_(serviceId).ToString();
                ckbxMtoDto.Checked = serviceInformationBasicInformationGateway.GetMtoDto(serviceId);
                tbxServiceDescription.Text = serviceInformationBasicInformationGateway.GetServiceDescription(serviceId);

                // Load unit basic data
                tbxUnitCode.Text = serviceInformationBasicInformationGateway.GetUnitCode(serviceId);
                tbxUnitDescription.Text = serviceInformationBasicInformationGateway.GetUnitDescription(serviceId);
                tbxVinSn.Text = serviceInformationBasicInformationGateway.GetVinSn(serviceId);
                tbxUnitState.Text = serviceInformationBasicInformationGateway.GetUnitState(serviceId);

                // Load checklist data
                tbxAssociatedChecklistRule.Text = serviceInformationBasicInformationGateway.GetAssociatedChecklistRule(serviceId);
                tbxChecklistState.Text = serviceInformationBasicInformationGateway.GetAssociatedChecklistRuleState(serviceId);

                if (serviceInformationBasicInformationGateway.GetRuleId(serviceId).HasValue)
                {
                    RuleGateway ruleGateway = new RuleGateway();
                    int? ruleId = serviceInformationBasicInformationGateway.GetRuleId(serviceId);
                    ruleGateway.LoadAllByRuleId(ruleId.Value, Int32.Parse(hdfCompanyId.Value));
                    int? serviceRequestDays = ruleGateway.GetServiceRequestDays(ruleId.Value);

                    if (ruleGateway.GetMto(ruleId.Value) && serviceInformationBasicInformationGateway.GetAssociatedChecklistLastService(serviceId).HasValue)
                    {
                        tbxChecklistNextDueDate.Text = serviceInformationBasicInformationGateway.GetAssociatedChecklistLastService(serviceId).Value.ToShortDateString();
                    }
                    else
                    {
                        if (serviceRequestDays.HasValue)
                        {
                            int negValue = -1;
                            serviceRequestDays = serviceRequestDays.Value * negValue;
                            DateTime serviceRequestCreationDate = serviceInformationBasicInformationGateway.GetDateTime_(serviceId);
                            tbxChecklistNextDueDate.Text = serviceInformationBasicInformationGateway.GetAssociatedChecklistNextDue(serviceId).Value.AddDays(Convert.ToDouble(serviceRequestDays.Value)).ToShortDateString();
                        }
                    }
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!(Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_SERVICES_VIEW"]) && Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_SERVICES_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["state"] == null) || ((string)Request.QueryString["source_page"] == null) || ((string)Request.QueryString["service_id"] == null) || ((string)Request.QueryString["active_tab"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in services_state.aspx");
                }

                // Tag page
                TagPage();

                // If coming from services_summary.aspx
                if ((string)Request.QueryString["source_page"] == "services_summary.aspx")
                {
                    // Store Navigator State and Update control
                    StoreNavigatorState();
                    ViewState["update"] = Request.QueryString["update"];

                    // Get project record
                    int serviceId = Int32.Parse(hdfServiceId.Value);
                    int companyId = Int32.Parse(hdfCompanyId.Value);

                    serviceInformationTDS = (ServiceInformationTDS)Session["serviceInformationTDS"];
                    ServiceInformationBasicInformationGateway serviceInformationBasicInformationGateway = new ServiceInformationBasicInformationGateway(serviceInformationTDS);
                    serviceInformationBasicInformationGateway.LoadByServiceId(serviceId, companyId);

                    if (serviceInformationBasicInformationGateway.GetRuleId(serviceId).HasValue)
                    {
                        RuleGateway ruleGateway = new RuleGateway();
                        int? ruleId = serviceInformationBasicInformationGateway.GetRuleId(serviceId);
                        ruleGateway.LoadAllByRuleId(ruleId.Value, Int32.Parse(hdfCompanyId.Value));
                        int? serviceRequestDays = ruleGateway.GetServiceRequestDays(ruleId.Value);

                        if (serviceRequestDays.HasValue)
                        {
                            DateTime serviceRequestCreationDate = serviceInformationBasicInformationGateway.GetDateTime_(serviceId);
                            tkrdpPnlAssignDeadlineDate.SelectedDate = serviceRequestCreationDate.AddDays(Convert.ToDouble(serviceRequestDays.Value));
                        }
                    }

                    // Store datasets
                    Session["serviceInformationTDS"] = serviceInformationTDS;
                }

                // If coming from wucSRUnassigned.aspx
                if ((string)Request.QueryString["source_page"] == "wucSRUnassigned.ascx")
                {
                    // Store Navigator State and Update control
                    StoreNavigatorState();
                    ViewState["update"] = Request.QueryString["update"];

                    // Get project record
                    int serviceId = Int32.Parse(hdfServiceId.Value);
                    int companyId = Int32.Parse(hdfCompanyId.Value);

                    serviceInformationTDS = new ServiceInformationTDS();
                    ServiceInformationBasicInformationGateway serviceInformationBasicInformationGateway = new ServiceInformationBasicInformationGateway(serviceInformationTDS);
                    serviceInformationBasicInformationGateway.LoadByServiceId(serviceId, companyId);

                    if (serviceInformationBasicInformationGateway.GetRuleId(serviceId).HasValue)
                    {
                        RuleGateway ruleGateway = new RuleGateway();
                        int? ruleId = serviceInformationBasicInformationGateway.GetRuleId(serviceId);
                        ruleGateway.LoadAllByRuleId(ruleId.Value, Int32.Parse(hdfCompanyId.Value));
                        int? serviceRequestDays = ruleGateway.GetServiceRequestDays(ruleId.Value);

                        if (serviceRequestDays.HasValue)
                        {
                            DateTime serviceRequestCreationDate = serviceInformationBasicInformationGateway.GetDateTime_(serviceId);
                            tkrdpPnlAssignDeadlineDate.SelectedDate = serviceRequestCreationDate.AddDays(Convert.ToDouble(serviceRequestDays.Value));
                        }
                    }

                    // Store datasets
                    Session["serviceInformationTDS"] = serviceInformationTDS;
                }

                // Restore dataset
                serviceInformationTDS = (ServiceInformationTDS)Session["serviceInformationTDS"];

                LoadMileage();
            }
            else
            {
                // Restore dataset
                serviceInformationTDS = (ServiceInformationTDS)Session["serviceInformationTDS"];
            }
        }