卡西卡的小寶庫
寶庫寶庫寶庫

  • 一般組態
    web.config
    <?xml version="1.0"?>
    <configuration>
      <appSettings file="out.config">
        <add key="in_string" value="IN"/>
      </appSettings>
    </configuration>

    out.config
    <?xml version="1.0" encoding="utf-8"?>
    <appSettings>
      <add key="out_string" value="out" />
    </appSettings>

    讀取組態:
    System.Configuration.ConfigurationManager.AppSettings["in_string"]
    System.Configuration.ConfigurationManager.AppSettings["out_string"]
  • 連線組態

    讀取組態:
    System.Configuration.ConfigurationManager.ConnectionStrings["default"].ConnectionString
    內部
    <?xml version="1.0"?>
    <configuration>
      <connectionStrings
        <add name="default" connectionString="Data Source=localhost;Initial Catalog=Northwind;Integrated Security=True" providerName="System.Data.SqlClient"/>
      </connectionStrings>
    </configuration>

    外部
    <!-- web.config -->
    <?xml version="1.0"?>
    <configuration>
      <connectionStrings configSource="conn.config" />
    </configuration>

    <!-- conn.config -->
    <connectionStrings>
      <add name="default" connectionString ="data=out;uid=;pid=;"/>
    </connectionStrings>

ASP.NET 1.1 是用 System.Configuration.ConfigurationSettings.AppSettings["default"]

 

Customers.aspx
=AJAX, 向web service請求資料。
[script]
function displayCustomers(result) {
$get("customers").innerHTML = result;
}
[script]

[body]
<asp:ScriptManager ID="ScriptManager1" runat="server" >
<Services>
<asp:ServiceReference Path="~/CustomerService.asmx" />
</Services>
</asp:ScriptManager>

Enter Country: <input id="Country" type="text" />
<a href="javascript:CustomerService.GetCustomersByCountry($get('Country').value, displayCustomers)">Show Customers</a>
<div id="customers"></div>
[/body]

CustomerService.cs
=這個AJAX用的web service是宣告 System.Web.Script.Services.ScriptService
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class CustomerService : System.Web.Services.WebService {

[WebMethod]
public string GetCustomersByCountry(string country)
{
NorthwindTableAdapters.CustomersTableAdapter customersAdapter = new NorthwindTableAdapters.CustomersTableAdapter();
Northwind.CustomersDataTable customers = customersAdapter.GetCustomersByCountry(country);

if (customers.Rows.Count > 0)
return ViewManager.RenderView("~/App_Views/Customers.ascx", customers);
else
return ViewManager.RenderView("~/App_Views/NoCustomers.ascx", null);
}
}

Customers.ascx.cs
=View
using System;

public partial class App_Views_Customers : System.Web.UI.UserControl
{
public object Data;

protected void Page_Load(object sender, EventArgs e)
{
Repeater1.DataSource = Data;
Repeater1.DataBind();
}
}

ViewManager.cs
=Controller
using System;
using System.Web;
using System.Web.UI;
using System.IO;
using System.Reflection;

public class ViewManager
{
public static string RenderView(string path)
{
return RenderView(path, null);
}

public static string RenderView(string path, object data)
{
Page pageHolder = new Page();
UserControl viewControl = (UserControl) pageHolder.LoadControl(path);

if (data != null)
{
Type viewControlType = viewControl.GetType();
FieldInfo field = viewControlType.GetField("Data");

if (field != null)
{
field.SetValue(viewControl, data);
}
else
{
throw new Exception("View file: " + path + " does not have a public Data property");
}
}

pageHolder.Controls.Add(viewControl);

StringWriter output = new StringWriter();
HttpContext.Current.Server.Execute(pageHolder, output, false);

return output.ToString();
}
}
 


ASP.NET 1.1 只能用在.aspx上
StringWriter output = new StringWriter();
HttpContext.Current.Server.Execute("~/ajax.aspx", output);
return output.ToString();

參考資料:

 

Google Map API (5) AJAX

Posted In: , . By 卡西卡

參考資料:

 

GTileLayer:自己提供地圖圖檔在GMap上呈現。

重點在覆寫getTileUrl提供圖檔url。
b_tileLayers[0].getTileUrl = function(tile, zoom) {
  return "http://140.109.174.55/googlemap/stereo/"+zoom+
    '/'+tile.x+'/IMG_'+tile.x + '_' + tile.y + '_'+zoom+".jpg";
}

實例:

 

snap022

參考資料:

 

[筆記]Google Map API (2)

Posted In: . By 卡西卡

  • 處理地圖移動事件[]
    // 移動地圖後在中心點顯示座標
    GEvent.addListener(map, "moveend",
      function() { 
        var center = map.getCenter();
        map.openInfoWindow(map.getCenter(),document.createTextNode(center.toString()));
      }
    );

    // 縮放地圖後顯示前後級別
    GEvent.addListener(map, "zoomend",
      function(oldLevel,newLevel) { 
        document.getElementById("out").innerHTML = "oldLevel="+oldLevel+" , newLevel="+newLevel;
      }
    );
    // 顯示滑鼠點到的座標   
    GEvent.addListener(map, "click",
      function(overlay,latlng) {
        document.getElementById("log").value = latlng.toString();
      }
    );
  • 取得目前地圖的可視範圍,隨機加入10個標籤,並畫線[GLatLngBounds, GPolyline, ] 
    var bounds = map.getBounds();
    var southWest = bounds.getSouthWest(); // 返回矩形西南角的點
    var northEast = bounds.getNorthEast(); // 返回矩形東北角的點
    var lngSpan = northEast.lng() - southWest.lng();
    var latSpan = northEast.lat() - southWest.lat();
    var points = [];
    for (var i = 0; i < 10; i++){
        var point = new GLatLng(
            southWest.lat() + latSpan * Math.random(),
            southWest.lng() + lngSpan * Math.random());
        points.push(point);
        map.addOverlay(new GMarker(point));
    } // for
    // 排序
    points.sort(function(p1, p2) { return p1.lng() - p2.lng();});
    map.addOverlay(new GPolyline(points));

    snap021
  • 多邊形並著色[GPolygon, ]
    // 地圖 (400x400)
    map.setCenter(new GLatLng(25.02837276205344, 121.48509979248047), 12);
    var points = [];
    points.push(new GLatLng(25.030000,121.490556)); // 萬華
    points.push(new GLatLng(25.035556,121.424722)); // 新莊
    points.push(new GLatLng(25.063611,121.518056)); // 中山
    points.push(new GLatLng(24.978889,121.529167)); // 新店
    points.push(new GLatLng(25.013611,121.466667)); // 板橋
    points.push(new GLatLng(25.030000,121.490556)); // 萬華(封閉)
    map.addOverlay(new GPolygon(points,'#FF0000',3,0.5,'#ffff00',0.5));

    snap020

 

[JavaScript]Closure

Posted In: . By 卡西卡

Closure:閉包, 閉鎖空間, 封絕

  • 看起來有點像是“巨集”的,可以產生(return)新的函式。
// 打折
function Discount(percent) {
    return function(price) { return price * percent / 100.0; }
}

var VIP_Pay      = Discount(60); // 貴賓6 折
var Member_Pay   = Discount(80); // 會員8 折
var Consumer_Pay = Discount(95); // 門市95折
var dvd_price = 500;
print("DVD定價 "+dvd_price);
print("貴賓特惠價 "+VIP_Pay(dvd_price));
print("會員優待價 "+Member_Pay(dvd_price));
print("門市售價 "+Consumer_Pay(dvd_price));
/* 結果
DVD定價 500
貴賓特惠價 300
會員優待價 400
門市售價 475
*/

 

var i = 0; 
var funcSet = []; 
function run_funcSet() { 
    for (var j=0, func=funcSet[j] ; func ; func=funcSet[++j] ) { 
        func(); 
    } // for
} 
print('Pure anonymous function'); 
for ( i=0 ; i<3 ; i++ ) { 
    funcSet[i] = function() {print(i);} 
} // for
run_funcSet(); 
print('Closure'); 
for ( i=0 ; i<3 ; i++ ) { 
    funcSet[i] = (
        function(i) {
            return function(){print(i);} 
        }
// function
    )(i); 
} // for
run_funcSet(); 
/* 結果
Pure anonymous function
3
3
3
Closure
0
1
2
*/

 

參考資料: