標籤

ASP.NET MVC (29) Visual C# (15) JQuery (10) Plugins (8) JQuery Plugins (6) JavaScript (6) MySQL (5) CSS (4) LinQ (4) Mac OS (4) CentOS (3) Design Pattern (3) Entity Framework (3) IIS (3) Python (3) Windows (3) php (3) Docker (2) LAMP (2) SQL Server (2) WCF (2) .NET (1) .NET Core (1) AWS (1) Browser (1) GIS (1) IE (1) Internet Security (1) Linux (1) Platform (1) React (1) SEO (1) Testing (1) VMware (1) Windows 7 (1) cookie (1) curl (1) laravel (1) phpBB (1) session (1) 中古屋 (1) 透天 (1) 閒言閒語 (1) 面試 (1) 鳥松 (1)

2011年7月28日 星期四

[Office] Excel中如何使用VBA快速尋找sheet

1. Excel2010 開啟巨集功能 : http://www.dotblogs.com.tw/chou/archive/2010/04/19/14690.aspx

2. 加個按鈕,執行下列程式碼:





Dim sh As Worksheet
Dim Message, Title, Default, MyValue
Message = "輸入查詢工作表名稱" ' 設定提示訊息。
Title = "查詢工作表名稱" ' 設定標題。
'Default = "1" ' 設定預設值。
ShSearch = InputBox(Message, Title, Default)
If ShSearch = "" Then Exit Sub

Application.ScreenUpdating = False
Application.DisplayAlerts = False

For Each sh In Sheets
If sh.Name <> "控制" Then
If InStr(1, sh.Name, ShSearch, 1) = 0 Then
' MsgBox sh.Name & " - " & InStr(1, sh.Name, ShSeek, 1)
' sh.Visible = xlSheetVeryHidden
'隱藏工作表: Sheet1.Visible = xlSheetVeryHidden
'顯示工作表: Sheet1.Visible = xlSheetVisible
Else
Msg = "你要到該工作表嗎? - " & sh.Name ' 定義訊息。
Style = vbYesNo + vbCritical + vbDefaultButton2 ' 定義按鈕。
Title = "查詢工作表名稱" ' 定義標題。
' Help = "DEMO.HLP" ' 定義說明檔。
' Ctxt = 1000 ' 定義內容代碼。
' 顯示訊息。
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' 若使用者按下 [是]。
MyString = "Yes" ' 產生相對回應。
Sheets(sh.Name).Select
Exit Sub
Else ' 若使用者按下 [否]。
MyString = "No" ' 產生相對回應。
End If

End If
End If
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
'MsgBox "完成"


2011年7月4日 星期一

[SEO] 網站搜尋引擎優化

[分析工具]
1. Google Chrome中的工具:SEO Site tools
2. 分析網站 http://www.woorank.com

[常見錯誤]



2011年6月7日 星期二

[ASP.NET MVC] 如何在主版頁面(Masterpage)中加入固定標題(Tilte)-續

之前寫了一篇:http://maidot.blogspot.com/2011/03/aspnet-mvc-masterpagetilte.html


如果我們希望Title是動態產生的該怎麼辦?其實很簡單,只需要:
< title>
< asp:ContentPlaceHolder ID="TitleContent" runat="server" />
<%: System.Web.Configuration.WebConfigurationManager.AppSettings["SiteTile"] %>
< /title>


沒錯,就是這樣簡單明瞭,其實如果使用Razor View是不會有任何問題的。

Reference:http://stackoverflow.com/questions/6291131/how-to-set-the-global-text-of-title-in-site-master-page-using-asp-net-mvc-2-3


====[以下為舊資料,請勿參考]====
現在發現如果要這樣搞:
   < title>
< asp:ContentPlaceHolder ID="TitleContent" runat="server" />
< asp:Literal ID="ltlTitleBack" runat="server" Text='<%: System.Web.Configuration.WebConfigurationManager.AppSettings["SiteTile"] %>' >
< /title>

是行不通的,它會顯示< asp:Literal不能包含子控制項,不過我找到一個可行的解決方案,但不知道是不是最好的:http://weblogs.asp.net/infinitiesloop/archive/2006/08/09/The-CodeExpressionBuilder.aspx

需要將Site.Master的程式碼改為:
   < title>
< asp:ContentPlaceHolder ID="TitleContent" runat="server" />
< asp:Literal ID="ltlTitleBack" runat="server" Text='<%$ Code: System.Web.Configuration.WebConfigurationManager.AppSettings["SiteTile"] %>' >
< /title>


然後某個Class中加入
using System.Web.Compilation;
using System.CodeDom;
using System.Web.UI;
//修正Literal
[System.Web.Compilation.ExpressionPrefix("Code")]
public class CodeExpressionBuilder : ExpressionBuilder
{
public override CodeExpression GetCodeExpression(BoundPropertyEntry entry,
object parsedData, ExpressionBuilderContext context)
{
return new CodeSnippetExpression(entry.Expression);
}
}


最後在Web.config中的區段中加入下列程式碼:
     

2011年6月3日 星期五

[ASP.NET MVC] 在View中取得目前的Controller, Action 的名稱

MVC3使用方式:
ViewContext.Controller.ValueProvider.GetValue("action").RawValue

ViewContext.Controller.ValueProvider.GetValue("controller").RawValue
ViewContext.Controller.ValueProvider.GetValue("id").RawValue

MVC2:
ViewContext.Controller.ValueProvider["action"].RawValue
ViewContext.Controller.ValueProvider["controller"].RawValue

ViewContext.Controller.ValueProvider["id"].RawValue

Reference:

ASP.NET MVC - Current Action

2011年5月31日 星期二

[Python] Django中將單筆資料轉換為json格式


最基礎的使用方式:
from django.core import serializers data = serializers.serialize("json", SomeModel.objects.all())

可以指定僅序列化某些資料欄位(ex: name & size):
from django.core import serializers data = serializers.serialize('json', SomeModel.objects.all(), fields=('name','size'))

如果我們只要序列化單筆資料,直覺是:
from django.core import serializers data = serializers.serialize("json", SomeModel.objects.get(pk=id))
不過上述是錯的,原來官方文件有這麼一段話:
The arguments to the serialize function are the format to serialize the data to (see Serialization formats) and a QuerySet to serialize. (Actually, the second argument can be any iterator that yields Django objects, but it'll almost always be a QuerySet).

是低~ 所以我們要使用filter()而不是用get():
from django.core import serializers data = serializers.serialize("json", SomeModel.objects.filter(pk=id))






2011年5月27日 星期五

[Python] Django血淚史

我的環境為:Python2.5.4 + Django1.3 + SQLite3
----------
0.錯誤訊息Django Short names for ENGINE DeprecationWarning
Django1.3中
'ENGINE': 'sqlite3' 改為 'ENGINE': 'django.db.backends.sqlite3'


1.錯誤訊息 IndentationError:expected an indented block
通常是縮排問題

2.錯誤訊息 TypeError: __init__() got an unexpected keyword argument 'maxlength'
Django1.3改為max_length

4.pysqlite2._sqlite.OperationalError: unable to open database file
兩個原因:1.目錄沒有權限 2.資料庫路徑錯誤
1. 請把目錄改為有read/write權限
2. 如果是Local測試,可以使用相對目錄,否則用完整路徑。
------------------------------------------------------------
Django官方教學文件:https://docs.djangoproject.com/en/1.3/

*在shell中執行p.was_published_today()命令會出現錯誤"NameError: global name 'datetime' is not defined"
[解決方法]:
因為沒有import datetime,所以要在models.py中加入"from datetime import date"。
或者:
from django.db import models
import datetime

*沒有建立Django的SuperUser
[解決方法]:命令列輸入 "manage.py createsuperuser"

------[Django SOP]-----
1. 建立專案
django-admin.py startproject mysite

2. 編輯設定,資料庫類型與名稱(路徑)
settings.py

3. 同步資料庫,建立資料庫超級使用者
python manage.py syncdb

4. 建立應用程式
python manage.py startapp polls


6. Settings 中 INSTALLED_APPS區段中加入應用程式

7. 觀看與同步資料庫
python manage.py sql polls #look
python manage.py syncdb

8. 安裝管理者工具,在Settings 中 INSTALLED_APPS區段中加入django.contrib.admin,且url.py取消admin的註解 (要在同步一次資料庫)

9. 運行Server測試admin(此時只有基礎admin功能)

10. 在使用的apps資料夾中加入admin.py,內包含要編輯的資料表,之後重啟Server(新增code不用,新增檔案需要)
from polls.models import Poll 
from django.contrib import admin  
admin.site.register(Poll)










-----




Django 外來鍵引用方式: Poll 1-n Choice[ForeignKey(Poll)]
poll參照choice:Poll.objects.get(pk=id).choice_set.all()
choice參照poll:choice.poll.---