切换城市功能

与切换城市类似,实例为切换不同的数据库源。

主要功能:

  1. 记录请求页面

  2. 切换数据库源

  3. 返回到请求页面

 1 public partial class SelectDB : BasePage
 2 {
 3     ......
 4     public string SrcUrl 
 5     {
 6         get { return Session["srcurl"] == null || Session["srcurl"].ToString().Equals("/SignOn.aspx") ? "QueryPlanByMonth.aspx" : Session["srcurl"].ToString(); }
 7         private set { Session["srcurl"] = value; } 
 8     }
 9     protected void Page_Load(object sender, EventArgs e)
10     {
11         if (!IsPostBack)
12         {
13             if (Request.UrlReferrer != null)
14             {
15                 SrcUrl = Request.UrlReferrer.AbsolutePath;
16             }
17         }
18     }
19     protected void LbtnFQ_Click(object sender, EventArgs e)
20     {
21         SetConnAndRedirect("AAConn");
22     }
23     protected void LbtnFG_Click(object sender, EventArgs e)
24     {
25         SetConnAndRedirect("BBGConn");
26     }
27 
28     private void SetConnAndRedirect(string conn)
29     {
30         base.DBConn = conn;
31         Response.Redirect(SrcUrl);
32     }
33 }
34 public class BasePage : Page
35 {
36     ......
37     protected string DBConn {
38         private get
39         {
40             return Session["DBConn"] == null ?
41                     "LFConn" :
42                     Session["DBConn"].ToString();
43             }
44         set { Session["DBConn"] = value; } 
45     }
46     ......
47 }
原文地址:https://www.cnblogs.com/zhuhc/p/3455094.html