private void FillHypLink(WebControl spanContrel, string type, Dictionary <int, string> regions, int?selectedId, int?parentId, out WebControl divContrel) { divContrel = new WebControl(HtmlTextWriterTag.Div); divContrel.Attributes.Add("class", "ap_content ap_" + type + " dp_address"); divContrel.Attributes.Add("id", RegionSelector.IDPrev + type + "_floor"); divContrel.Controls.Add(RegionSelector.CreateTag("<div class=\"dp_address_list " + type + " clearfix\" id=\"" + RegionSelector.IDPrev + type + "_info\"> <ul id=\"" + RegionSelector.IDPrev + type + "_select\">")); foreach (int key in regions.Keys) { if (selectedId.HasValue && key == selectedId.Value) { spanContrel.Controls.RemoveAt(0); spanContrel.Controls.AddAt(0, RegionSelector.CreateTag(regions[key])); } divContrel.Controls.Add(RegionSelector.CreateTag("<li><a href=\"javascript:;\" id=\"select_new_" + RegionSelector.IDPrev + type + "_" + key + "\">" + regions[key] + "</a></li>")); } if (this.IsShowClear) { if (parentId.HasValue) { divContrel.Controls.Add(RegionSelector.CreateTag("<li><a href=\"javascript:;\" t=\"clear\" id=\"select_new_" + RegionSelector.IDPrev + type + "_" + parentId + "\">[清空]</a></li>")); } else { divContrel.Controls.Add(RegionSelector.CreateTag("<li><a href=\"javascript:;\" t=\"clear\" id=\"select_new_" + RegionSelector.IDPrev + type + "_clear\" >[清空]</a></li>")); } } divContrel.Controls.Add(RegionSelector.CreateTag("</ul></div>")); }
protected override void CreateChildControls() { this.Controls.Clear(); if (!this.dataLoaded) { if (!string.IsNullOrEmpty(this.Context.Request.Form["regionSelectorValue"])) { this.currentRegionId = new int?(int.Parse(this.Context.Request.Form["regionSelectorValue"])); } this.dataLoaded = true; } if (this.currentRegionId.HasValue) { XmlNode region = RegionHelper.GetRegion(this.currentRegionId.Value); if (region != null) { if (region.Name == "county") { this.countyId = new int?(this.currentRegionId.Value); this.cityId = new int?(int.Parse(region.ParentNode.Attributes["id"].Value)); this.provinceId = new int?(int.Parse(region.ParentNode.ParentNode.Attributes["id"].Value)); } else if (region.Name == "city") { this.cityId = new int?(this.currentRegionId.Value); this.provinceId = new int?(int.Parse(region.ParentNode.Attributes["id"].Value)); } else if (region.Name == "province") { this.provinceId = new int?(this.currentRegionId.Value); } } } this.ddlProvinces = this.CreateDropDownList("ddlRegions1", "-请选择省-"); RegionSelector.FillDropDownList(this.ddlProvinces, RegionHelper.GetAllProvinces(), this.provinceId); this.Controls.Add(RegionSelector.CreateTag("<span>")); this.Controls.Add(this.ddlProvinces); this.Controls.Add(RegionSelector.CreateTag("</span>")); this.ddlCitys = this.CreateDropDownList("ddlRegions2", "-请选择市-"); if (this.provinceId.HasValue) { RegionSelector.FillDropDownList(this.ddlCitys, RegionHelper.GetCitys(this.provinceId.Value), this.cityId); } this.Controls.Add(RegionSelector.CreateTag("<span>")); this.Controls.Add(this.ddlCitys); this.Controls.Add(RegionSelector.CreateTag("</span>")); this.ddlCountys = this.CreateDropDownList("ddlRegions3", "-请选择区-"); if (this.cityId.HasValue) { RegionSelector.FillDropDownList(this.ddlCountys, RegionHelper.GetCountys(this.cityId.Value), this.countyId); } this.Controls.Add(RegionSelector.CreateTag("<span>")); this.Controls.Add(this.ddlCountys); this.Controls.Add(RegionSelector.CreateTag("</span>")); }
private WebControl CreateHypLink(string controlId, string spanId, int?selectedId, string showname, int width, out WebControl webSpan) { WebControl webControl = new WebControl(HtmlTextWriterTag.A); webControl.Attributes.Add("id", RegionSelector.IDPrev + controlId); webControl.Attributes.Add("href", "javascript:"); webControl.Attributes.Add("class", "dropdown_box"); if (width > 0) { webControl.Attributes.Add("style", "width:" + width + "px"); } webSpan = new WebControl(HtmlTextWriterTag.Span); webSpan.Attributes.Add("id", RegionSelector.IDPrev + spanId); webSpan.Attributes.Add("class", "dropdown_selected"); webSpan.Controls.Add(RegionSelector.CreateTag(showname)); if (selectedId.HasValue) { webSpan.Attributes.Add("value", selectedId.Value.ToString()); } webControl.Controls.Add(webSpan); webControl.Controls.Add(RegionSelector.CreateTag("<span class=\"dropdown_button\"></span>")); return(webControl); }
protected override void CreateChildControls() { this.Controls.Clear(); if (!this.dataLoaded) { if (!string.IsNullOrEmpty(this.Context.Request.Form[RegionSelector.IDPrev + "regionSelectorValue"])) { this.currentRegionId = int.Parse(this.Context.Request.Form[RegionSelector.IDPrev + "regionSelectorValue"]); } this.dataLoaded = true; } if (this.currentRegionId.HasValue) { Hidistro.Entities.Store.RegionInfo region = RegionHelper.GetRegion(this.currentRegionId.Value, true); if (region != null) { if (region.Depth == 4) { this.streetId = this.currentRegionId; this.countyId = region.ParentRegionId; this.cityId = RegionHelper.GetCityId(region.ParentRegionId); this.provinceId = RegionHelper.GetTopRegionId(region.ParentRegionId, true); } if (region.Depth == 3) { this.countyId = this.currentRegionId.Value; this.cityId = region.ParentRegionId; this.provinceId = RegionHelper.GetTopRegionId(region.ParentRegionId, true); } else if (region.Depth == 2) { this.cityId = this.currentRegionId.Value; this.provinceId = region.ParentRegionId; } else if (region.Depth == 1) { this.provinceId = this.currentRegionId.Value; } } } this.Controls.Add(RegionSelector.CreateTag("<div class=\"address_wap\"><div class=\"dp_border\"></div><div class=\"dp_address\">")); this.ddlProvinces = this.CreateHypLink("province_top", "provincename", this.provinceId, this.ProvinceTitle, this.ProvinceWidth, out this.proviceSpan); this.FillHypLink(this.proviceSpan, "province", (Dictionary <int, string>)RegionHelper.GetAllProvinces(false), this.provinceId, (int?)0, out this.proviceDiv); this.ddlCitys = this.CreateHypLink("city_top", "cityname", this.cityId, this.CityTitle, this.CityWidth, out this.citySpan); Dictionary <int, string> regions = new Dictionary <int, string>(); if (this.provinceId.HasValue) { regions = RegionHelper.GetCitys(this.provinceId.Value, false); } this.FillHypLink(this.citySpan, "city", regions, this.cityId, this.provinceId, out this.cityDiv); this.ddlCountys = this.CreateHypLink("area_top", "areaname", this.countyId, this.CountyTitle, this.CountyWidth, out this.areaSpan); Dictionary <int, string> regions2 = new Dictionary <int, string>(); if (this.cityId.HasValue) { regions2 = RegionHelper.GetCountys(this.cityId.Value, false); } this.FillHypLink(this.areaSpan, "area", regions2, this.countyId, this.cityId, out this.areaDiv); if (this.DisplayStreet) { this.ddlStreets = this.CreateHypLink("street_top", "streetname", this.streetId, this.StreetTitle, this.StreetWidth, out this.streetSpan); Dictionary <int, string> regions3 = new Dictionary <int, string>(); if (this.countyId.HasValue) { regions3 = RegionHelper.GetStreets(this.countyId.Value, false); } this.FillHypLink(this.streetSpan, "street", regions3, this.streetId, this.countyId, out this.streetDiv); } this.Controls.Add(this.ddlProvinces); this.Controls.Add(this.ddlCitys); this.Controls.Add(this.ddlCountys); if (this.DisplayStreet) { this.Controls.Add(this.ddlStreets); } this.Controls.Add(RegionSelector.CreateTag("</div>")); this.Controls.Add(this.proviceDiv); this.Controls.Add(this.cityDiv); this.Controls.Add(this.areaDiv); if (this.DisplayStreet) { this.Controls.Add(this.streetDiv); } this.Controls.Add(RegionSelector.CreateTag("</div>")); if (!this.CustomerCss) { Literal literal = new Literal(); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("<style type=\"text/css\">"); stringBuilder.AppendLine(".dropdown_button {" + string.Format("background: url('{0}') no-repeat;", "/Admin/images/combo_arrow.jpg") + "}"); stringBuilder.AppendLine(".dp_address a:hover .dropdown_button {" + string.Format("background: url('{0}') no-repeat;", "/Admin/images/combo_arrow1.jpg") + "}"); stringBuilder.AppendLine("</style>"); literal.Text = stringBuilder.ToString(); this.Controls.Add(literal); WebControl webControl = new WebControl(HtmlTextWriterTag.Link); webControl.Attributes.Add("rel", "stylesheet"); webControl.Attributes.Add("href", "/Admin/css/region.css"); webControl.Attributes.Add("type", "text/css"); webControl.Attributes.Add("media", "screen"); webControl.ID = "regionStyle"; this.Controls.Add(webControl); } }