記得當初不知到是誰告訴我 WIN7 不支援 Telnet , 因為也不常用,所以都用 pietty 代替,
一直到這兩天在測postfix , 一直用到 , 想找回 CMD 的使用方式 , 沒想到設定一下就好了
今天要 CentOs 來跑 mailserver ,不知到為什麼一直裝不進去 , 一開始為RAID沒驅動的關係,後來該關的都關了,還是一樣,只好請示google 大神
錯誤訊息:
"Disk sda contains BIOS RAID metadata, but is not part of any recognized BIOS RAID sets. Ignoring disk sda"
我試了二塊版子 , 分別是 sb710 跟 ich7 , 二片都一樣 , 查的結果應該是 fakeraid 的問題 , 也就是MB內建RIAD 的問題,並不是真正的RAID卡,解決方法也不難, 只要在安裝光碟的第一個畫面按下 TAB鍵 在啟動命令 輸入:
"linux nodmraid"
再 Enter 進行安裝就可以解決這個問題.
Asp.Net 雖然有很多工具可以做到零程式碼 ,就能完整的撈出資料 , 但是有些功能還是手工 "卡實在"
第一件事是要引用 web.config 裡的連接語法 , 如果還沒有做的 , 請手工KEY進去 , 或建一個 SqlDataSoure ,VS 會幫你建好
1 |
<span style="color: #606060" id="lnum1"> 1:</span> <span style="color: #0000ff"><</span><span style="color: #800000">connectionStrings</span><span style="color: #0000ff">></span> |
1 |
<span style="color: #606060" id="lnum2"> 2:</span> <span style="color: #0000ff"><</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">="Conn"</span> <span style="color: #ff0000">connectionString</span><span style="color: #0000ff">="Data Source=sql_server;Initial Catalog=EIP;Persist Security Info=True;User ID=myid;Password=xxxxxx"</span> <span style="color: #ff0000">providerName</span><span style="color: #0000ff">="System.Data.SqlClient"</span><span style="color: #0000ff">/></span> |
1 |
<span style="color: #606060" id="lnum3"> 3:</span> <span style="color: #0000ff"></</span><span style="color: #800000">connectionStrings</span><span style="color: #0000ff">></span> |
name="Conn" =>連線名稱
Data Source=sql_server =>SQL伺服器
User ID=myid =>帳號
Password=xxxxxx =>密碼
再來介紹最常用的查詢(select)
C#:
1 |
<span style="color: #606060" id="lnum1"> 1:</span> SqlConnection conn = <span style="color: #0000ff">new</span> SqlConnection(ConfigurationManager.ConnectionStrings[<span style="color: #006080">"Conn"</span>].ToString()); |
1 |
<span style="color: #606060" id="lnum2"> 2:</span> <span style="color: #008000">//引用web.config 裡連線語法</span> |
1 |
<span style="color: #606060" id="lnum3"> 3:</span> <span style="color: #0000ff">string</span> cmdst = <span style="color: #006080">"select sys_dep_id from sys_dep where sys_dep_name ='ABC'"</span>; <span style="color: #008000">//sql語法</span> |
1 |
<span style="color: #606060" id="lnum4"> 4:</span> SqlCommand scmd = <span style="color: #0000ff">new</span> SqlCommand(cmdst, conn); <span style="color: #008000">//建立命令</span> |
1 |
<span style="color: #606060" id="lnum5"> 5:</span> conn.Open(); <span style="color: #008000">//開啟conn連線</span> |
1 |
<span style="color: #606060" id="lnum6"> 6:</span> SqlDataReader sdr = scmd.ExecuteReader(); <span style="color: #008000">//進行讀取資料</span> |
1 |
<span style="color: #606060" id="lnum7"> 7:</span> <span style="color: #0000ff">while</span> (sdr.Read()) <span style="color: #008000">//利用 while 讀出檔案 , Read() 每次讀一行 , 最後 fales 跳出</span> |
1 |
<span style="color: #606060" id="lnum8"> 8:</span> { |
1 |
<span style="color: #606060" id="lnum9"> 9:</span> Response.Write(ser[0].ToString()); |
1 |
<span style="color: #606060" id="lnum10"> 10:</span> } |
1 |
<span style="color: #606060" id="lnum11"> 11:</span> sdr.Close(); |
1 |
<span style="color: #606060" id="lnum12"> 12:</span> conn.Close(); <font color="#008000">//切記 , 有開啟, 就有關閉 , 不然連線會卡進(個人有慘痛經驗)</font> |
如果只是要確認有無資料可在 ExecuteReaDer 後 使用 if(sdr.HasRow) 來判斷 ,,
新增 (Insert)
C#
1 |
<span style="color: #606060" id="lnum1"> 1:</span> SqlConnection conn = <span style="color: #0000ff">new</span> SqlConnection(ConfigurationManager.ConnectionStrings[<span style="color: #006080">"Conn"</span>].ToString()); |
1 |
<span style="color: #606060" id="lnum2"> 2:</span> <span style="color: #0000ff">string</span> cmdst = <span style="color: #006080">"INSERT INTO [EIP].[dbo].[sys_docs_modify] ([橺位1]"</span> + |
1 |
<span style="color: #606060" id="lnum3"> 3:</span> <span style="color: #006080">",[欄位2]) VALUES ('插入資料1','插入資料2')"</span>; <span style="color: #008000">//T_SQL 插入語法</span> |
1 |
<span style="color: #606060" id="lnum4"> 4:</span> SqlCommand scmd = <span style="color: #0000ff">new</span> SqlCommand(cmdst, conn); |
1 |
<span style="color: #606060" id="lnum5"> 5:</span> conn.Open(); |
1 |
<span style="color: #606060" id="lnum6"> 6:</span> scmd.ExecuteNonQuery(); <span style="color: #008000">//重點在這行!! 針對連接執行 Transact-SQL 陳述式</span> |
1 |
<span style="color: #606060" id="lnum7"> 7:</span> conn.Close(); <font color="#008000">//同上 , 有開就有關 !!</font> |
修改 , 刪除 請待續..... !!!
本來拿寫修改記錄檔用的
1 |
<span style="color: #606060" id="lnum1"> 1:</span> StreamWriter sw = File.AppendText(filepath); <span style="color: #008000">//AppendText 使用附加方式</span> |
1 |
<span style="color: #606060" id="lnum2"> 2:</span> sw.WriteLine(<span style="color: #006080">"line 1 : "</span>+Time.Now.ToString(<span style="color: #006080">"yyyy/MM/dd hh:mm:ss"</span>)); |
1 |
<span style="color: #606060" id="lnum3"> 3:</span> sw.WriteLine(<span style="color: #006080">"line 2 : "</span>+Time.Now.ToString(<span style="color: #006080">"yyyy/MM/dd hh:mm:ss"</span>)); |
1 |
<span style="color: #606060" id="lnum4"> 4:</span> sw.Flush(); |
1 |
<span style="color: #606060" id="lnum5"> 5:</span> sw.Close(); |
遞迴 CTE 結構至少必須包含一個錨點成員與一個遞迴成員。下列虛擬程式碼顯示含有單一錨點成員與單一遞迴成員的簡單遞迴 CTE 所具備的元件。
1 |
<span style="color: #606060" id="lnum1"> 1:</span> <span style="color: #0000ff">WITH</span> cte_name ( column_name [,...n] ) |
1 |
<span style="color: #606060" id="lnum2"> 2:</span> <span style="color: #0000ff">AS</span> |
1 |
<span style="color: #606060" id="lnum3"> 3:</span> ( |
1 |
<span style="color: #606060" id="lnum4"> 4:</span> CTE_query_definition –- Anchor member <span style="color: #0000ff">is</span> defined. |
1 |
<span style="color: #606060" id="lnum5"> 5:</span> <span style="color: #0000ff">UNION</span> <span style="color: #0000ff">ALL</span> |
1 |
<span style="color: #606060" id="lnum6"> 6:</span> CTE_query_definition –- <span style="color: #0000ff">Recursive</span> member <span style="color: #0000ff">is</span> defined <span style="color: #0000ff">referencing</span> cte_name. |
1 |
<span style="color: #606060" id="lnum7"> 7:</span> ) |
1 |
<span style="color: #606060" id="lnum8"> 8:</span> <span style="color: #008000">-- Statement using the CTE</span> |
1 |
<span style="color: #606060" id="lnum9"> 9:</span> <span style="color: #0000ff">SELECT</span> * |
1 |
<span style="color: #606060" id="lnum10"> 10:</span> <span style="color: #0000ff">FROM</span> cte_name |
遞迴執行的語意如下:
將 CTE 運算式分割為錨點成員與遞迴成員。
執行錨點成員以建立第一個引動過程或基底結果集 (T0)。
執行遞迴成員,以 Ti 做為輸入,而以 Ti+1 做為輸出。
重複步驟 3,直到傳回空的結果集為止。
傳回結果集。這是 T0 至 Tn 的 UNION ALL。
版上範例 :
1 |
<span style="color: #606060" id="lnum1"> 1:</span> <span style="color: #0000ff">with</span> directsales(up_dno,dno,lvl) |
1 |
<span style="color: #606060" id="lnum2"> 2:</span> <span style="color: #0000ff">as</span>( |
1 |
<span style="color: #606060" id="lnum3"> 3:</span> --Anchor查詢 |
1 |
<span style="color: #606060" id="lnum4"> 4:</span> <span style="color: #0000ff">select</span> up_dno,dno,1 <span style="color: #0000ff">as</span> lvl |
1 |
<span style="color: #606060" id="lnum5"> 5:</span> <span style="color: #0000ff">from</span> dbo_dsales <span style="color: #0000ff">where</span> dno=<span style="color: #006080">'A'</span> |
1 |
<span style="color: #606060" id="lnum6"> 6:</span> <span style="color: #0000ff">union</span> <span style="color: #0000ff">all</span> |
1 |
<span style="color: #606060" id="lnum7"> 7:</span> --Recursive查詢 |
1 |
<span style="color: #606060" id="lnum8"> 8:</span> <span style="color: #0000ff">select</span> a.up_dno,a.dno,lvl+1 |
1 |
<span style="color: #606060" id="lnum9"> 9:</span> <span style="color: #0000ff">from</span> dbo_dsales a,directsales b |
1 |
<span style="color: #606060" id="lnum10"> 10:</span> <span style="color: #0000ff">where</span> a.up_dno=b.dno |
1 |
<span style="color: #606060" id="lnum11"> 11:</span> ) |
1 |
<span style="color: #606060" id="lnum12"> 12:</span> --執行CTE查詢 |
1 |
<span style="color: #606060" id="lnum13"> 13:</span> <span style="color: #0000ff">select</span> up_dno <span style="color: #0000ff">as</span> 上線直銷商,dno <span style="color: #0000ff">as</span> 直銷商,lvl <span style="color: #0000ff">as</span> 階層 |
1 |
<span style="color: #606060" id="lnum14"> 14:</span> <span style="color: #0000ff">from</span> directsales |
所以錨點成員是
select up_dno,dno,1 as lvl from dbo_dsales where dno='A'
也就是
up_dno,dno,lvl
null A 1
那遞迴成員是
select a.up_dno,a.dno,lvl+1 from dbo_dsales a,directsales b where a.up_dno=b.dno
也就是
在第一次跑時,b.dno = A
得到
up_dno,dno,lvl
A B 2
A C 2
在第二次跑時,b.dno = B,C
得到
up_dno,dno,lvl
B D 3
B E 3
C F 3
C G 3
C H 3
在第三次跑時,b.dno = D,E,F,G,H
得到
up_dno,dno,lvl
D I 4
D J 4
F K 4
G L 4
在第四次跑時,b.dno = I,J,K,L
得到
up_dno,dno,lvl
J M 5
L N 5
在第五次跑時,b.dno = M,N
得到 無符合資料(傳回空的結果集)
所以遞迴停止
所以最後得到結果為
up_dno,dno,lvl
null A 1
A B 2
A C 2
B D 3
B E 3
C F 3
C G 3
C H 3
D I 4
D J 4
F K 4
G L 4
J M 5
L N 5
個人實作:
資料庫結構大概是:
sys_dep_id(部門ID) | sys_dep_up(上層部門ID) |
201 | 101 |
301 | 201 |
302 | 201 |
401 | 301 |
402 | 301 |
403 | 301 |
501 | 401 |
1 |
<span style="color: #606060" id="lnum1"> 1:</span> <span style="color: #0000ff">with</span> myview (sys_dep_up,sys_dep_id ) <span style="color: #0000ff">as</span> |
1 |
<span style="color: #606060" id="lnum2"> 2:</span> (<span style="color: #0000ff">select</span> sys_dep_up,sys_dep_id |
1 |
<span style="color: #606060" id="lnum3"> 3:</span> <span style="color: #0000ff">from</span> dbo.sys_dep <span style="color: #0000ff">where</span> sys_dep_up = 301 |
1 |
<span style="color: #606060" id="lnum4"> 4:</span> <span style="color: #0000ff">union</span> <span style="color: #0000ff">all</span> |
1 |
<span style="color: #606060" id="lnum5"> 5:</span> <span style="color: #0000ff">select</span> a.sys_dep_up,a.sys_dep_id |
1 |
<span style="color: #606060" id="lnum6"> 6:</span> <span style="color: #0000ff">from</span> dbo.sys_dep a,myview b |
1 |
<span style="color: #606060" id="lnum7"> 7:</span> <span style="color: #0000ff">where</span> a.sys_dep_up=b.sys_dep_id) |
1 |
<span style="color: #606060" id="lnum8"> 8:</span> |
1 |
<span style="color: #606060" id="lnum9"> 9:</span> <span style="color: #0000ff">select</span> sys_dep_id <span style="color: #0000ff">as</span> alldepid |
1 |
<span style="color: #606060" id="lnum10"> 10:</span> <span style="color: #0000ff">from</span> myview |
結果為: 401,402,403,501
各元件說明
密碼驗證
Asp.Net:
1 |
<span id="lnum1" style="color: #606060;"> 1:</span> 密碼:<span style="color: #0000ff;"><</span><span style="color: #800000;">asp:TextBox</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="passwd"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span><span style="color: #0000ff;">></</span><span style="color: #800000;">asp:TextBox</span><span style="color: #0000ff;">></span> |
1 |
<span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">asp:RegularExpressionValidator</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="passrg"</span> |
1 |
<span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> |
1 |
<span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #ff0000;">ErrorMessage</span><span style="color: #0000ff;">="至少6碼與英數"</span> |
1 |
<span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #ff0000;">ControlToValidate</span><span style="color: #0000ff;">="passwd"</span> |
1 |
<span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #ff0000;">ValidationExpression</span><span style="color: #0000ff;">="^.*(?=.{6,})(?=.*\d)(?=.*[a-zA-Z]).*$"</span><span style="color: #0000ff;">></span> |
1 |
<span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">asp:RegularExpressionValidator</span><span style="color: #0000ff;">></span> |
1 |
<span id="lnum8" style="color: #606060;"> 8:</span> |
ValidationExpression 說明:
(?=.{10,}): 密碼長度 10 個以上,{10,20} 表示能輸入10至20個字元
(?=.*\d): 至少要有一個 0-9 的數字
(?=.*[a-z]): 至少要有一個小寫的英文字母 (a-z)
(?=.*[A-Z]): 至少要有一個大寫的英文字母 (A-Z)
(?=.*[a-zA-Z]):至少要有一個英文字母
(?!.*[^\x00-\xff]): 表示不允許輸入 ASCII 以外的字元.
(?!.*[^\x21-\x7e]):表示不允許特殊字元
(?=.*[@#$%^&+=]): 至少要有清單中的一個特殊符號 (@#$%^&+=)
信箱驗證:
Asp.Net:
1 |
<span id="lnum1" style="color: #606060;"> 1:</span> 帳號:<span style="color: #0000ff;"><</span><span style="color: #800000;">asp:TextBox</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="email"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span><span style="color: #0000ff;">></</span><span style="color: #800000;">asp:TextBox</span><span style="color: #0000ff;">></span> |
1 |
<span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">asp:RegularExpressionValidator</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="email_chk"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> |
1 |
<span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #ff0000;">ErrorMessage</span><span style="color: #0000ff;">="非E-MAIL 格式"</span> |
1 |
<span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #ff0000;">ControlToValidate</span><span style="color: #0000ff;">="email"</span> |
1 |
<span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #ff0000;">ValidationExpression</span><span style="color: #0000ff;">="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"</span><span style="color: #0000ff;">></span> |
1 |
<span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">asp:RegularExpressionValidator</span><span style="color: #0000ff;">></span> |
1 |
<span id="lnum7" style="color: #606060;"> 7:</span> |
同密碼驗證 , 只是換了驗證條件
密碼確認:
Asp.Net:
1 |
<span id="lnum1" style="color: #606060;"> 1:</span> 密碼:<span style="color: #0000ff;"><</span><span style="color: #800000;">asp:TextBox</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="passwd"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span><span style="color: #0000ff;">></</span><span style="color: #800000;">asp:TextBox</span><span style="color: #0000ff;">></span> |
1 |
<span id="lnum2" style="color: #606060;"> 2:</span> 確認密碼:<span style="color: #0000ff;"><</span><span style="color: #800000;">asp:TextBox</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="passwd_ck"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> <span style="color: #0000ff;">></</span><span style="color: #800000;">asp:TextBox</span><span style="color: #0000ff;">></span> |
1 |
<span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">asp:CompareValidator</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="CompareValidator1"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> |
1 |
<span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #ff0000;">ErrorMessage</span><span style="color: #0000ff;">="密碼不同"</span> |
1 |
<span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #ff0000;">ControlToCompare</span><span style="color: #0000ff;">="passwd"</span> |
1 |
<span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #ff0000;">ControlToValidate</span><span style="color: #0000ff;">="passwd_ck"</span> |
1 |
<span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">asp</span><span style="color: #ff0000;">:CompareValidator</span><span style="color: #0000ff;">></span> |
利用 CompareValidator 做二個輸入框的比對
空白驗證:
Asp.Net:
1 |
<span id="lnum1" style="color: #606060;"> 1:</span> 帳號:<span style="color: #0000ff;"><</span><span style="color: #800000;">asp:TextBox</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="email"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> <span style="color: #ff0000;">ValidationGroup</span><span style="color: #0000ff;">="ck_inst"</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"></</span><span style="color: #800000;">asp:TextBox</span><span style="color: #0000ff;">></span>(e-mail) |
1 |
<span id="lnum2" style="color: #606060;"> 2:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">asp:RequiredFieldValidator</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="email_empty"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> |
1 |
<span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #ff0000;">ErrorMessage</span><span style="color: #0000ff;">="不可空白"</span> |
1 |
<span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #ff0000;">ControlToValidate</span><span style="color: #0000ff;">="email"</span> |
1 |
<span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #ff0000;">Display</span><span style="color: #0000ff;">="Dynamic"</span><span style="color: #0000ff;">></span> |
1 |
<span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #0000ff;"></</span><span style="color: #800000;">asp:RequiredFieldValidator</span><span style="color: #0000ff;">></span> |
1 |
<span id="lnum7" style="color: #606060;"> 7:</span> |
Button 是否引發驗證:
2011-11-26 補充
進行空白驗證時,若表單為多 button , 若不要每個button 都進行驗證, 須將要驗證的物件 group 起來
Asp.Net:
1 |
<span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">asp:TextBox</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="user_pw"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> <span style="color: #ff0000;">CssClass</span><span style="color: #0000ff;">="login"</span> <span style="color: #ff0000;">TextMode</span><span style="color: #0000ff;">="Password"</span><span style="color: #0000ff;">></</span><span style="color: #800000;">asp:TextBox</span><span style="color: #0000ff;">></span> |
1 |
<span id="lnum2" style="color: #606060;"> 2:</span> |
1 |
<span id="lnum3" style="color: #606060;"> 3:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">asp:RequiredFieldValidator</span> |
1 |
<span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="user_pw_empty"</span> |
1 |
<span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> |
1 |
<span id="lnum6" style="color: #606060;"> 6:</span> <span style="color: #ff0000;">ControlToValidate</span><span style="color: #0000ff;">="user_pw"</span> |
1 |
<span id="lnum7" style="color: #606060;"> 7:</span> <span style="color: #ff0000;">Display</span><span style="color: #0000ff;">="Dynamic"</span> |
1 |
<span id="lnum8" style="color: #606060;"> 8:</span> <span style="color: #ff0000;">ErrorMessage</span><span style="color: #0000ff;">="密碼空白"</span> |
1 |
<span id="lnum9" style="color: #606060;"> 9:</span> <span style="color: #ff0000;">ForeColor</span><span style="color: #0000ff;">="Red"</span> |
1 |
<span id="lnum10" style="color: #606060;"> 10:</span> <span style="color: #ff0000;">Font-Names</span><span style="color: #0000ff;">="微軟正黑體"</span> |
1 |
<span id="lnum11" style="color: #606060;"> 11:</span> <span style="color: #ff0000;">ValidationGroup</span><span style="color: #0000ff;">="vg_login"</span> |
1 |
<span id="lnum12" style="color: #606060;"> 12:</span> <span style="color: #0000ff;">></</span><span style="color: #800000;">asp:RequiredFieldValidator</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><</span><span style="color: #800000;">br</span> <span style="color: #0000ff;">/></span> |
1 |
<span id="lnum13" style="color: #606060;"> 13:</span> |
1 |
<span id="lnum14" style="color: #606060;"> 14:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">asp:Button</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="login_ibtn"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> <span style="color: #ff0000;">ValidationGroup</span><span style="color: #0000ff;">="vg_login"</span> <span style="color: #0000ff;">/></span> |
1 |
<span id="lnum15" style="color: #606060;"> 15:</span> <span style="color: #0000ff;"><</span><span style="color: #800000;">asp:Button</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="reg_ibtn"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> <span style="color: #ff0000;">CausesValidation</span><span style="color: #0000ff;">="False"</span> <span style="color: #ff0000;">PostBackUrl</span><span style="color: #0000ff;">="~/register/reg.aspx"</span> <span style="color: #0000ff;">/></span> |
http://msdn.microsoft.com/zh-tw/library/system.directoryservices(v=VS.80).aspx
這裡一定要先了解一下
工作需求上要使用 AD帳號作為認證,找了一下實作,還挺不錯玩的
Asp.Net
2個 Textbox 跟1 個Button 就搞定了
1 |
<span style="color: #606060" id="lnum1"> 1:</span> <span style="color: #0000ff"><</span><span style="color: #800000">asp:TextBox</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="TextBox1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span><span style="color: #0000ff">></</span><span style="color: #800000">asp:TextBox</span><span style="color: #0000ff">></span> |
1 |
<span style="color: #606060" id="lnum2"> 2:</span> <span style="color: #0000ff"><</span><span style="color: #800000">br</span> <span style="color: #0000ff">/></span> |
1 |
<span style="color: #606060" id="lnum3"> 3:</span> <span style="color: #0000ff"><</span><span style="color: #800000">asp:TextBox</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="TextBox2"</span> <span style="color: #ff0000">TextMode</span><span style="color: #0000ff">="Password"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span><span style="color: #0000ff">></</span><span style="color: #800000">asp:TextBox</span><span style="color: #0000ff">></span> |
1 |
<span style="color: #606060" id="lnum4"> 4:</span> <span style="color: #0000ff"><</span><span style="color: #800000">br</span> <span style="color: #0000ff">/></span> |
1 |
<span style="color: #606060" id="lnum5"> 5:</span> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Button</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="Button1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">onclick</span><span style="color: #0000ff">="Button1_Click"</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="Button"</span> <span style="color: #0000ff">/></span> |
C#
請使用 using System.DirectoryServices; 若找不到請至方案總管新增參考, 找 .NET 裡的System.DirectorServices
1 |
<span style="color: #606060" id="lnum1"> 1:</span> <span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> Button1_Click(<span style="color: #0000ff">object</span> sender, EventArgs e) |
1 |
<span style="color: #606060" id="lnum2"> 2:</span> { |
1 |
<span style="color: #606060" id="lnum3"> 3:</span> <span style="color: #0000ff">string</span> ad_id = TextBox1.Text; |
1 |
<span style="color: #606060" id="lnum4"> 4:</span> <span style="color: #0000ff">string</span> ad_ps = TextBox2.Text; |
1 |
<span style="color: #606060" id="lnum5"> 5:</span> DirectoryEntry ent = <span style="color: #0000ff">new</span> DirectoryEntry(<span style="color: #006080">"LDAP://dc=abc,dc=com,dc=tw"</span>,ad_id,ad_ps); |
1 |
<span style="color: #606060" id="lnum6"> 6:</span> <span style="color: #008000">//網域名稱 , 以 "."為分隔 ,接續帳號,密碼</span> |
1 |
<span style="color: #606060" id="lnum7"> 7:</span> DirectorySearcher ds = <span style="color: #0000ff">new</span> DirectorySearcher(ent); <span style="color: #008000">//建立 搜尋 AD的物件</span> |
1 |
<span style="color: #606060" id="lnum8"> 8:</span> ds.Filter = <span style="color: #006080">"(sAMAccountName="</span> + ad_id + <span style="color: #006080">")"</span>; <span style="color: #008000">//設立條件 , 這裡是找帳號與輸入ID一樣</span> |
1 |
<span style="color: #606060" id="lnum9"> 9:</span> ds.PropertiesToLoad.Add(<span style="color: #006080">"displayName"</span>); <span style="color: #008000">//搜尋期間要擷取的屬性清單</span> |
1 |
<span style="color: #606060" id="lnum10"> 10:</span> ds.SearchScope = SearchScope.Subtree; <span style="color: #008000">//伺服器觀察的搜尋範圍</span> |
1 |
<span style="color: #606060" id="lnum11"> 11:</span> <span style="color: #0000ff">try</span> |
1 |
<span style="color: #606060" id="lnum12"> 12:</span> { |
1 |
<span style="color: #606060" id="lnum13"> 13:</span> SearchResult sr = ds.FindOne(); <span style="color: #008000">//搜尋到的第一個物年件</span> |
1 |
<span style="color: #606060" id="lnum14"> 14:</span> |
1 |
<span style="color: #606060" id="lnum15"> 15:</span> <span style="color: #0000ff">if</span> (sr == <span style="color: #0000ff">null</span>) |
1 |
<span style="color: #606060" id="lnum16"> 16:</span> { |
1 |
<span style="color: #606060" id="lnum17"> 17:</span> Response.Write(<span style="color: #006080">"找不到帳號"</span>); |
1 |
<span style="color: #606060" id="lnum18"> 18:</span> } |
1 |
<span style="color: #606060" id="lnum19"> 19:</span> <span style="color: #0000ff">else</span> |
1 |
<span style="color: #606060" id="lnum20"> 20:</span> { |
1 |
<span style="color: #606060" id="lnum21"> 21:</span> <span style="color: #0000ff">string</span> atest = sr.GetDirectoryEntry().Properties[<span style="color: #006080">"displayName"</span>].Value.ToString(); <span style="color: #008000">//取出顯示名稱</span> |
1 |
<span style="color: #606060" id="lnum22"> 22:</span> Response.Write(<span style="color: #006080">"你的帳號是: "</span>+atest); |
1 |
<span style="color: #606060" id="lnum23"> 23:</span> } |
1 |
<span style="color: #606060" id="lnum24"> 24:</span> } |
1 |
<span style="color: #606060" id="lnum25"> 25:</span> <span style="color: #0000ff">catch</span> (Exception ex) |
1 |
<span style="color: #606060" id="lnum26"> 26:</span> { |
1 |
<span style="color: #606060" id="lnum27"> 27:</span> Response.Write(<span style="color: #006080">"密碼錯誤 ,或無此帳號"</span>); |
1 |
<span style="color: #606060" id="lnum28"> 28:</span> } |
1 |
<span style="color: #606060" id="lnum29"> 29:</span> |
1 |
<span style="color: #606060" id="lnum30"> 30:</span> } |
工作訴求是 利用查詢出來的bind資料,再利用於 C#後台進行操作
Asp.net :
在EVAL處動點手腳
1 |
<span style="color: #606060" id="lnum1"> 1:</span> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Label</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="sys_dep_upLabel"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">='<%# Eval("sys_dep_up") %>'</span> <span style="color: #0000ff">/></span> |
改成這樣,目的是呼叫後台進行操作
1 |
<span style="color: #606060" id="lnum1"> 1:</span> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Label</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="sys_dep_upLabel"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">='<%# getdepname_byid(Convert.ToInt32(Eval("sys_dep_up"))) %>'</span> <span style="color: #0000ff">/></span> |
C#:
建立一個事件, 並回傳結果
1 |
<span style="color: #606060" id="lnum1"> 1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> getdepname_byid(<span style="color: #0000ff">int</span> depid) |
1 |
<span style="color: #606060" id="lnum2"> 2:</span> { |
1 |
<span style="color: #606060" id="lnum3"> 3:</span> <span style="color: #008000">// ..... </span> |
1 |
<span style="color: #606060" id="lnum4"> 4:</span> <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>; |
1 |
<span style="color: #606060" id="lnum5"> 5:</span> } |
Asp.Net ListView 內的InsertItemTemplate 標籤修改
1 |
<span style="color: #606060" id="lnum1"> 1:</span> <span style="color: #0000ff"><</span><span style="color: #800000">InsertItemTemplate</span><span style="color: #0000ff">></span> |
1 |
<span style="color: #606060" id="lnum2"> 2:</span> <span style="color: #0000ff"><</span><span style="color: #800000">tr</span> <span style="color: #ff0000">style</span><span style="color: #0000ff">=""</span><span style="color: #0000ff">></span> |
1 |
<span style="color: #606060" id="lnum3"> 3:</span> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span> |
1 |
<span style="color: #606060" id="lnum4"> 4:</span> <span style="color: #0000ff"><</span><span style="color: #800000">asp:DropDownList</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="ddl_depup"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> |
1 |
<span style="color: #606060" id="lnum5"> 5:</span> <span style="color: #ff0000">DataSourceID</span><span style="color: #0000ff">="dep_up_list"</span> |
1 |
<span style="color: #606060" id="lnum6"> 6:</span> <span style="color: #ff0000">DataTextField</span><span style="color: #0000ff">="sys_dep_name"</span> |
1 |
<span style="color: #606060" id="lnum7"> 7:</span> <span style="color: #ff0000">DataValueField</span><span style="color: #0000ff">="sys_dep_id"</span> |
1 |
<span style="color: #606060" id="lnum8"> 8:</span> <span style="color: #ff0000">SelectedValue</span><span style="color: #0000ff">='<%# Bind("sys_dep_up") %>'</span><span style="color: #0000ff">/></span> |
1 |
<span style="color: #606060" id="lnum9"> 9:</span> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span> |
1 |
<span style="color: #606060" id="lnum10"> 10:</span> <span style="color: #0000ff"></</span><span style="color: #800000">InsertItemTemplate</span><span style="color: #0000ff">></span> |
C#後台語法 , 指定插入時動作
1 |
<span style="color: #606060" id="lnum1"> 1:</span> <span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> ListView1_ItemInserting(<span style="color: #0000ff">object</span> sender, ListViewInsertEventArgs e) |
1 |
<span style="color: #606060" id="lnum2"> 2:</span> { |
1 |
<span style="color: #606060" id="lnum3"> 3:</span> DropDownList ddl_depup = (DropDownList)ListView1.InsertItem.FindControl(<span style="color: #006080">"ddl_depup"</span>); |
1 |
<span style="color: #606060" id="lnum4"> 4:</span> e.Values[<span style="color: #006080">"EmployeeID"</span>] = ddl_depup.SelectedValue; |
1 |
<span style="color: #606060" id="lnum5"> 5:</span> } |
難得用到一個 微軟提供的方法是有效的 !!
http://support.microsoft.com/kb/822005/zh-tw
如果要自動修正此問題,請按一下 [Fix it] 按鈕或連結,然後在 [檔案下載] 對話方塊中按一下 [執行],並依照「Fix it 精靈」中的步驟執行。
使用 微軟提供的 FIX
Microsoft Fix it 50599 重設 Word 中的使用者選項
範本問題以前有遇過 , 沒想到這次也看到正確解法
如果要避免通用範本 (Normalm.dot 或 Normal.dot) 中儲存的格式變更、自動圖文集項目和巨集影響 Word 和開啟文件的行為,請重新命名通用範本 (Normal.dotm 或 Normal.dot)。重新命名範本可以讓您迅速判斷問題是否由通用範本所造成。
在 Word 2007 或更新版本中重新命名 Normal.dot 範本,或是在 Word 2003 和舊版 Word 中重新命名 Normal.dot 範本時,會將數個選項重設回預設設定。這些重設的選項包括自訂樣式、自訂工具列、巨集和自動圖文集項目。我們強烈建議您不要刪除 Normal.dotm 或 Normal.dot 範本,而只重新命名範本。如果您確定問題源自範本,則可從重新命名的 Normal.dot 範本複製自訂樣式、自訂工具列、巨集和自動圖文集項目。
某些類型的組態可能會建立多個 Normal.dotm 或 Normal.dot 範本。這些情況包括:在同一部電腦上執行多種 Word 版本,或在同一部電腦上存有數種工作站安裝。在這些情況下,請確定您重新命名的是正確的範本。
如果要重新命名通用範本檔案,請依照下列步驟執行: