webBrowser1.Navigate("網址");
Chih筆記
2011年9月20日 星期二
2011年8月15日 星期一
[FreeBSD] Pure-FTPd + MySQL架設
安裝Pure-FTPd
cd /usr/ports/ftp/pure-ftpd
make install clean(選MYSQL、UTF-8)
cd /usr/local/etc
cp pure-ftpd.conf.sample pure-ftpd.conf
設定Pure-FTPd
vim pure-ftpd.conf
更改pure-ftpd.conf設定,我列出我所用到的設定:
ChrootEveryone yes # 限制每個用戶到自己的根目錄
# List dot-files even when the client doesn't send "-a".
DisplayDotFiles no #是否顯示.XXX記錄檔(隱藏系統檔)
# Disallow anonymous connections. Only allow authenticated users.
NoAnonymous yes # 不允許匿名用戶
NoAnonymous yes # 不允許匿名用戶
# MySQL configuration file (see README.MySQL)
MySQLConfigFile /usr/local/etc/pureftpd-mysql.conf #設定使用MySQL管理虛擬帳戶
# File creation mask. <umask for files>:<umask for dirs> .
# 177:077 if you feel paranoid.
Umask 133 :022 #文件權限:目錄,777-133=644:777-022=755
# Allow FXP transfers for authenticated users.
AllowUserFXP yes #允許使用者使用FTP傳輸軟體
# Automatically create home directories if they are missing
CreateHomeDir yes #當使用者第一次存取FTP空間時,會依據帳號自動創資料夾
以上設定好後,儲存離開。
建立MySQL設定檔
vim pureftpd-mysql.conf
# If you want to use the Socket connect methode comment out the
# Lines with MMYSQLServer and MYSQLPort.
# If you want to use the Port methode comment out the MYSQLSocket line
#MYSQLSocket /var/lib/mysql/mysql.sock
MYSQLServer localhost
MYSQLPort 3306
MYSQLUser ftp #MySQL使用者 最好是設定非root
MYSQLPassword ftpuser #密碼
MYSQLDatabase pureftpd
MYSQLCrypt cleartext
MYSQLGetPW SELECT Password FROM ftpd WHERE User="\L" AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R")
MYSQLGetUID SELECT Uid FROM ftpd WHERE User="\L" AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R")
MYSQLGetGID SELECT Gid FROM ftpd WHERE User="\L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R")
MYSQLGetDir SELECT Dir FROM ftpd WHERE User="\L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R")
MySQLGetBandwidthUL SELECT ULBandwidth FROM ftpd WHERE User="\L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R")
MySQLGetBandwidthDL SELECT DLBandwidth FROM ftpd WHERE User="\L"AND status="1" AND (ipaccess = "*" OR ipaccess LIKE "\R")
MySQLGetQTASZ SELECT QuotaSize FROM ftpd WHERE User="\L"AND status="1"
MySQLGetQTAFS SELECT QuotaFiles FROM ftpd WHERE User="\L"AND status="1"
這樣Pure-FTPd就都設定好了,接著新建一個存放Pure-FTPd使用者帳號的pureftpd資料庫。
DROP TABLE IF EXISTS ftpd;CREATE TABLE ftpd (
User varchar(16) NOT NULL default '',
status enum('0','1') NOT NULL default '0',
Password varchar(64) NOT NULL default '',
Uid varchar(11) NOT NULL default '-1',
Gid varchar(11) NOT NULL default '-1',
Dir varchar(128) NOT NULL default '',
ULBandwidth smallint(5) NOT NULL default '0',
DLBandwidth smallint(5) NOT NULL default '0',
comment tinytext NOT NULL,
ipaccess varchar(15) NOT NULL default '*',
QuotaSize smallint(5) NOT NULL default '0',
QuotaFiles int(11) NOT NULL default 0,
PRIMARY KEY (User),
UNIQUE KEY User (User)
) TYPE=MyISAM;
設定開機自動啟動
vim /etc/rc.conf
加入pureftpd_enable="YES"
/usr/local/etc/rc.d/pure-ftpd start
資料庫欄位意義:
User: 使用者名稱status: 使用者狀態,1為可登入,0為不可登入
Password: 密碼
UID: 系統的 UID,要大於100以上(Uid,Gid會影響上傳下載權限,基本上是都設一樣)
GID: 系統的 GID,要大於100以上
Dir: 登入系統的使用者目錄
ULBandwidth: 上傳頻寬,單位 KB/s
DLBandwidth: 下載頻寬,單位 KB/s
comment: 使用者身份簡介說明
ipaccess: 連線來源 IP限制,* 為不限制
QuotaSize:家目錄的大小限制,單位 MB,0為不限制
QuotaFiles: 檔案數量限制,0為不限制
後記:關於使用FTP傳輸軟體以外的方式上傳中文檔名會變成亂碼,目前還未找到解決方法,但是使用FTP傳輸軟體就無此問題。
[Blogger] 撰寫程式碼文章 google-code-prettify
方便Blogger使用的方法:
在設計,修改HTML裡的</head>之前貼上下面這兩句,<link href=...的css連結可以更換樣式。
<link href="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css" rel="stylesheet" type="text/css"></link>
<script src="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js" type="text/javascript">
</script>
然後在網頁載入時啟動
<body onload='prettyprint()'>
使用時,用<pre class="prettyprint"></pre>框住程式碼就可以了。
可以與SyntaxHighlighter共用,只是class內容不同。
個人比較偏向使用SyntaxHighlighter,因為在測試google-code-prettify的時候,會有些程式碼跑不出來。
在設計,修改HTML裡的</head>之前貼上下面這兩句,<link href=...的css連結可以更換樣式。
<link href="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css" rel="stylesheet" type="text/css"></link>
<script src="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js" type="text/javascript">
</script>
然後在網頁載入時啟動
<body onload='prettyprint()'>
使用時,用<pre class="prettyprint"></pre>框住程式碼就可以了。
可以與SyntaxHighlighter共用,只是class內容不同。
個人比較偏向使用SyntaxHighlighter,因為在測試google-code-prettify的時候,會有些程式碼跑不出來。
[Blogger] 撰寫程式碼文章 SyntaxHighlighter
使用SyntaxHighlighter 提供的免費API,首先選取Blogger的設定 > 修改HTML,在</head>前貼上以下程式碼。
<!--SYNTAX HIGHLIGHTER BEGINS-->
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'/>
<script language='javascript'>
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf';
SyntaxHighlighter.all();
</script>
<!--SYNTAX HIGHLIGHTER ENDS-->
接著在撰寫程式碼文章時,切換到"修改HTML",在程式碼開頭及結束加上以下這兩行。
<pre class="brush: c#">
print "aaa";
</pre>
<!--SYNTAX HIGHLIGHTER BEGINS-->
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'/>
<script language='javascript'>
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf';
SyntaxHighlighter.all();
</script>
<!--SYNTAX HIGHLIGHTER ENDS-->
接著在撰寫程式碼文章時,切換到"修改HTML",在程式碼開頭及結束加上以下這兩行。
<pre class="brush: c#">
print "aaa";
</pre>
[PHP] Notice: Undefined index: 找不到該變數的值 解決方法
到apache找php資料夾的php.ini檔案,貼上這句關掉錯誤警告的設定
error_reporting(E_ALL ^ E_NOTICE);
上面的方法應該就可以解決錯誤訊息,如果想在程式碼中判斷變數是否存在也可以使用以下方法:
error_reporting(E_ALL ^ E_NOTICE);
上面的方法應該就可以解決錯誤訊息,如果想在程式碼中判斷變數是否存在也可以使用以下方法:
<?php //判斷該變數是否存在,ture or false isset() //判斷$變數中是否存在id索引鍵值 array_key_exists(id,$變數) ?>
2011年7月28日 星期四
[C#] 更新、新增、刪除MySQL資料庫資料語法
//引用MySQL套件參考 using MySql.Data.MySqlClient; //資料庫位址 MySqlConnection myConnection = new MySqlConnection("server=資料庫IP;user id=資料庫使用者帳號; password=帳號的密碼; database=資料庫名稱; CharSet=utf8"); //開啟資料庫 myConnection.Open(); /*更新*/ string update = string.Format("update 資料表 set 欄位1='{0}', 欄位2='{1}'", 值1,值2); MySqlCommand updateCmd = new MySqlCommand(update, myConnection); updateCmd.Connection = myConnection; //執行更新 updateCmd.ExecuteNonQuery(); /*新增*/ string AddNew = string.Format("INSERT INTO 資料表(欄位1, 欄位2) VALUES('{0}','{1}')", 值1, 值2); MySqlCommand AddNewCmd = new MySqlCommand(AddNew, myConnection); AddNewCmd.Connection = myConnection; //執行新增 AddNewCmd.ExecuteNonQuery(); /*刪除*/ string Del = string.Format("DELETE FROM 資料表 WHERE 欄位 = '{0}'", 值); MySqlCommand DelCmd = new MySqlCommand(Del, myConnection); DelCmd.Connection = myConnection; //執行刪除 DelCmd.ExecuteNonQuery(); //關閉資料庫 myConnection.Close();
2011年7月3日 星期日
[C#] 關閉執行中的程式
using System.Diagnostics; //關閉執行中程式 Process[] list = Process.GetProcessesByName("IExplore");//關閉"IExplore",也可以關閉火狐"firefox" foreach (Process p in list) { p.Kill(); }
[C#] 命令提示字元指令
//關機 System.Diagnostics.Process.Start("C:\\WINDOWS\\system32\\shutdown.exe", "-f -s -t 0"); //登出 System.Diagnostics.Process.Start("C:\\WINDOWS\\system32\\shutdown.exe", "-l"); //休眠 System.Diagnostics.Process.Start("C:\\WINDOWS\\system32\\rundll32.exe","powrprof.dll,SetSuspendState"); //重新開機 System.Diagnostics.Process.Start("C:\\WINDOWS\\system32\\shutdown.exe", "-f -r -t 0");
[C#] 倒數計時
private void Form1_Load(object sender, EventArgs e) { timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { //要倒數的時間,也可以倒數5秒,例:DateTime MyEndDate = DateTime.Now.AddSeconds(5); DateTime MyEndDate = new DateTime(YY,MM,DD,hh,mm, 0); //取得電腦現在時間 DateTime MyStartDate = DateTime.Now; //執行倒數 TimeSpan MySpan = MyEndDate.Subtract(MyStartDate); string diffDay = Convert.ToString(MySpan.Days); string diffHour = Convert.ToString(MySpan.Hours); string diffMin = Convert.ToString(MySpan.Minutes); string diffSec = Convert.ToString(MySpan.Seconds); //顯示秒數 label1.Text = diffDay + "天" + diffHour + "時" + diffMin + "分" + diffSec + "秒"; }
[C#] 列印
列印元件 printDocument
預覽列印 printPreviewDialog
預覽列印 printPreviewDialog
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { //列印圖片 e.Graphics.DrawImage(pictureBox1.Image, 160, 20, 250, 100); //列印文字 e.Graphics.DrawString(textBox1.Text, textBox1.Font, new SolidBrush(Color.Black), new Point(50, 50)); }也可以設定列印參數
//設定印A4的一半 直式 printDocument1.DefaultPageSettings.Landscape = true; printDocument1.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("pag",this.printDocument1.DefaultPageSettings.PaperSize.Width,this.printDocument1.DefaultPageSettings.PaperSize.Height / 2); //列印字體設定 textBox1.Font = new System.Drawing.Font("新細明體", 12F, System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Point, ((byte)(136)));執行列印
//預覽列印 printPreviewDialog1.ShowDialog(); //直接列印 printDocument1.Print();
[C#] DataGridView新增按鈕欄位
創建按鈕欄
using System.Windows.Forms; DataGridViewButtonColumn column3 = new DataGridViewButtonColumn(); column3.Name = "欄位名稱"; column3.UseColumnTextForButtonValue = true; column3.Text = "按鈕名稱"; column3.Width = 30; DataGridView1.Rows.Add(column3);新增按鈕跟資料
int Count = DataGridView1.Rows.Count - 2; DataGridView1.Rows[Count].Cells[1].Value = "值";
[C#] 點選DataGridView欄位取得欄位值
private void DataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e) { //取得欄位值 string value = DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Value.ToString(); }
[C#] 顯示其他程式介面
在From1的程式區宣告From2視窗並呼叫顯示
在From2程式區宣告
如果要把From1的資料傳到From2的物件,From2物件的 Modifiers 屬性(表示物件的可視性層級)要改成 Internal
//宣告From2視窗 From2 From2 = new From2(); From2.FM1 = this; //呼叫顯示From2視窗 From2.ShowDialog();
在From2程式區宣告
//宣告From1 public Form1 FM1 = null;
如果要把From1的資料傳到From2的物件,From2物件的 Modifiers 屬性(表示物件的可視性層級)要改成 Internal
[C#] 改變解析度
using System.Runtime.InteropServices; //改變解析度引用 [DllImport("user32.dll")] private static extern bool SetWindowPos(int hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); [DllImport("user32.dll")] public static extern int GetSystemMetrics(int screensize); public const int SM_CXSCREEN = 0; public const int SM_CYSCREEN = 1; private static IntPtr HWND_TOP = IntPtr.Zero; private const int SWP_SHOWWINDOW = 64;
[C#] 連結MySQL語法-DadataGridView顯示
using MySql.Data.MySqlClient;//安裝MySql.Data.msi套件,再引用參考 //資料庫位址,帳號,密碼,資料庫名稱,存取編碼 MySqlConnection myConnection = new MySqlConnection("server=localhost;user id=root; password=sa123; database=mer; CharSet=utf8"); MySqlDataReader sqlDataReader; MySqlCommand sqlCmd; myConnection.Open(); DataTable data; MySqlDataAdapter da; MySqlCommandBuilder cb; data = new DataTable(); da = new MySqlDataAdapter(string.Format("SELECT * FROM ABC"), myConnection); cb = new MySqlCommandBuilder(da); da.Fill(data); //放到DataGrid顯示 dataGridView1.DataSource = data; //關閉資料庫 myConnection.Close();
[C#] 連結MySQL語法
using MySql.Data.MySqlClient;//安裝MySql.Data.msi套件,再引用參考 //資料庫位址,帳號,密碼,資料庫名稱,存取編碼 MySqlConnection myConnection = new MySqlConnection("server=localhost;user id=root; password=sa123; database=mer; CharSet=utf8"); MySqlDataReader sqlDataReader; MySqlCommand sqlCmd; myConnection.Open(); string sql = string.Format("SELECT * FROM health_care where Account_number ='{0}' and Password = '{1}'",id_textBox.Text,pass_textBox.Text); sqlCmd = new MySqlCommand(sql, myConnection); sqlDataReader = sqlCmd.ExecuteReader(); if (sqlDataReader.Read()) { string 變數 = MaxCodeSqlData["資料表名稱"].ToString(); } sqlDataReader.Close(); myConnection.Close();
[MySQL] 資料庫存取權限開啟語法
GRANT ALL PRIVILEGES ON *.* TO 'root' @'%' IDENTIFIED BY 'sa123' WITH GRANT OPTION;
訂閱:
文章 (Atom)