using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using xabaraCOM;

public partial class inClude_cityNav : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string pca = "全国";

        long p = 0;
            long c = 0;
            long a = 0;

        if (!IsPostBack)
        {
            sqlServer sql = new sqlServer();
            DataTable dt;
            string strSql = string.Empty;            

            //route取值
            string ids = this.Page.RouteData.Values["IDs"].ToString().Replace(".htm", "");
            if (!string.IsNullOrEmpty(ids as string))
            {
                string[] id = ids.Split(new char[] { '-' });
                p = xabara.isNum(id[0]);
                c = xabara.isNum(id[1]);
                a = xabara.isNum(id[2]);

                HttpCookie ipCookies = new HttpCookie("XabaraWhere");  //cookies写入磁盘
                ipCookies.Values.Add("p", p.ToString());
                ipCookies.Values.Add("c", c.ToString());
                ipCookies.Values.Add("a", a.ToString());
                if (a > 0)
                {
                    dt = sql.getDataTable("select * from selectArea where areaID=" + a.ToString());
                    if (dt.Rows.Count > 0)
                    {
                        pca = dt.Rows[0]["areaTxt"].ToString().Trim();
                    }
                    dt.Dispose();
                }
                else
                {
                    if (c > 0)
                    {
                        dt = sql.getDataTable("select * from selectcity where cityID=" + c.ToString());
                        if (dt.Rows.Count > 0)
                        {
                            pca = dt.Rows[0]["cityTxt"].ToString().Trim();
                        }
                        dt.Dispose();
                    }
                    else
                    {
                        if (p > 0)
                        {
                            dt = sql.getDataTable("select * from selectprovince where provinceID=" + p.ToString());
                            if (dt.Rows.Count > 0)
                            {
                                pca = dt.Rows[0]["provinceTxt"].ToString().Trim();
                            }
                            dt.Dispose();
                        }
                    }
                }
                ipCookies.Values.Add("city", HttpUtility.UrlEncode(pca));
                ipCookies.Expires = DateTime.Now.AddDays(1);
                ipCookies.Domain = xml.read("xabara.config", "cookiesDomain", 180);
                ipCookies.Path = "/";
                Response.AppendCookie(ipCookies);
            }
        }

        string returnUrl = Server.UrlDecode(url.before);
        if (string.IsNullOrEmpty(returnUrl as string))
        {
            returnUrl = "/";
        }
        Response.Redirect(returnUrl, true);
    }
}