public string Hex2Int2Binary(string strHex)
{
int intNum = Convert.ToInt32(strHex, 16);
string strBinary = Convert.ToString(intNum, 2);
return strBinary;
}
2014年10月22日 星期三
2014年10月8日 星期三
滑鼠畫筆[Processing]
點選滑鼠左右鍵,觸發事件
void setup(){
size (800,800);
noStroke();
background(255);
// fill(0,102,153,204);
rectMode(CENTER);
}
void draw(){
if(mousePressed && (mouseButton == LEFT)) {
fill(0,102,153,204);
rect(width-mouseX,height-mouseY,50,50);
rect(mouseX,mouseY,50,50);
}
if(mousePressed && (mouseButton == RIGHT)){
fill(102,102,153,204);
ellipse(width-mouseX,height-mouseY,50,50);
ellipse(mouseX,mouseY,50,50);
}
}
void setup(){
size (800,800);
noStroke();
background(255);
// fill(0,102,153,204);
rectMode(CENTER);
}
void draw(){
if(mousePressed && (mouseButton == LEFT)) {
fill(0,102,153,204);
rect(width-mouseX,height-mouseY,50,50);
rect(mouseX,mouseY,50,50);
}
if(mousePressed && (mouseButton == RIGHT)){
fill(102,102,153,204);
ellipse(width-mouseX,height-mouseY,50,50);
ellipse(mouseX,mouseY,50,50);
}
}
2014年10月7日 星期二
C# FTP 目錄底下檔案搜尋
// ftpPath:FTP 位置
//ftpUser:FTP帳號
//ftpPassword:FTP密碼
//strExtension:被搜尋的副檔名
//strFileList:回傳的檔案名稱(數量要先計算,要先new好該有的數量,另一篇會教如何計算數量)
計算方式
public bool CheckFTPFileList(string ftpPath, string ftpUser, string ftpPassword, string strExtension, ref string[] strFileList)
{
bool success = false;
FtpWebRequest ftpWebRequest = null;
WebResponse webResponse = null;
StreamReader reader = null;
try
{
string url = ftpPath;
//new 一個FTP連線
ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri(url));
//建立FTP連線
ftpWebRequest.Credentials = new NetworkCredential(ftpUser, ftpPassword);
//選擇通訊協定方法
ftpWebRequest.Method = WebRequestMethods.Ftp.ListDirectory;
//完成要求動做後,關閉連線
ftpWebRequest.KeepAlive = false;
// 取得FTP回應
webResponse = ftpWebRequest.GetResponse();
//讀取FTP資訊
reader = new StreamReader(webResponse.GetResponseStream());
string line = "";
int intFileCount = 0;
while (line != null)
{
//讀取目錄下檔案名稱及根目錄名稱
line = reader.ReadLine();
//如有包含指定副檔名,即可記錄
if (line.Contains(strExtension))
{
strFileList[intFileCount] = line;
intFileCount++;
}
}
}
catch (Exception)
{
success = false;
}
finally
{
if (reader != null)
{
reader.Close();
}
if (webResponse != null)
{
webResponse.Close();
}
}
return success;
}
C# FTP根目錄底下,指定副檔名,檔案計算數量
//ftpPath:FTP位置
//ftpUser:FTP帳號
//ftpPassword:FTP密碼
//strExtension:副檔案名稱
//intFileCount:回傳計算結果
public bool CheckFTPCount(string ftpPath, string ftpUser, string ftpPassword, string strExtension, ref int intFileCount)
{
bool success = false;
FtpWebRequest ftpWebRequest = null;
WebResponse webResponse = null;
StreamReader reader = null;
try
{
string url = ftpPath;
//new 一個FTP連線
ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri(url));
//建立FTP連線
ftpWebRequest.Credentials = new NetworkCredential(ftpUser, ftpPassword);
//選擇通訊協定方法
ftpWebRequest.Method = WebRequestMethods.Ftp.ListDirectory;
//完成要求動做後,關閉連線
ftpWebRequest.KeepAlive = false;
// 取得FTP回應
webResponse = ftpWebRequest.GetResponse();
//讀取FTP資訊
reader = new StreamReader(webResponse.GetResponseStream());
string line = "";
intFileCount = 0;
while (line != null)
{
//讀取目錄下檔案名稱及根目錄名稱
line = reader.ReadLine();
//如有包含指定副檔名,即可記錄
if (line.Contains(strExtension))
{
intFileCount++;
}
}
}
catch (Exception)
{
success = false;
}
finally
{
if (reader != null)
{
reader.Close();
}
if (webResponse != null)
{
webResponse.Close();
}
}
return success;
}
//ftpUser:FTP帳號
//ftpPassword:FTP密碼
//strExtension:副檔案名稱
//intFileCount:回傳計算結果
public bool CheckFTPCount(string ftpPath, string ftpUser, string ftpPassword, string strExtension, ref int intFileCount)
{
bool success = false;
FtpWebRequest ftpWebRequest = null;
WebResponse webResponse = null;
StreamReader reader = null;
try
{
string url = ftpPath;
//new 一個FTP連線
ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri(url));
//建立FTP連線
ftpWebRequest.Credentials = new NetworkCredential(ftpUser, ftpPassword);
//選擇通訊協定方法
ftpWebRequest.Method = WebRequestMethods.Ftp.ListDirectory;
//完成要求動做後,關閉連線
ftpWebRequest.KeepAlive = false;
// 取得FTP回應
webResponse = ftpWebRequest.GetResponse();
//讀取FTP資訊
reader = new StreamReader(webResponse.GetResponseStream());
string line = "";
intFileCount = 0;
while (line != null)
{
//讀取目錄下檔案名稱及根目錄名稱
line = reader.ReadLine();
//如有包含指定副檔名,即可記錄
if (line.Contains(strExtension))
{
intFileCount++;
}
}
}
catch (Exception)
{
success = false;
}
finally
{
if (reader != null)
{
reader.Close();
}
if (webResponse != null)
{
webResponse.Close();
}
}
return success;
}
C# EASendMail Lib 程式寄信教學
下載處:EASendMail
// strReceiver :收件者
//strTitle:信件標題
//strBody:信件內容
//strUserName:信箱帳號
//strPW:信箱密碼
public void SendEmail(string strReceiver, string strTitle, string strBody, string strUserName, string strPW)
{
try
{
SmtpMail oMail = new SmtpMail("TryIt");
EASendMail.SmtpClient oSmtp = new EASendMail.SmtpClient();
// Set sender email address, please change it to yours
oMail.From = "XXX@gamil.com";
// Set recipient email address, please change it to yours
oMail.To = strReceiver;
// Set email subject
oMail.Subject = strTitle;
// Set email body
oMail.TextBody = strBody;
// Your SMTP server address
SmtpServer oServer = new SmtpServer("smtp.gmail.com");
// User and password for ESMTP authentication, if your server doesn't require
// User authentication, please remove the following codes.
oServer.User = strUserName;
oServer.Password = strPW;
// If your smtp server requires TLS connection, please add this line
// oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;
// If your smtp server requires implicit SSL connection on 465 port, please add this line
oServer.Port = 465;
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;
try
{
oSmtp.SendMail(oServer, oMail);
}
catch (Exception ep)
{
MessageBox.Show(ep.Message);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
來源參考
// strReceiver :收件者
//strTitle:信件標題
//strBody:信件內容
//strUserName:信箱帳號
//strPW:信箱密碼
public void SendEmail(string strReceiver, string strTitle, string strBody, string strUserName, string strPW)
{
try
{
SmtpMail oMail = new SmtpMail("TryIt");
EASendMail.SmtpClient oSmtp = new EASendMail.SmtpClient();
// Set sender email address, please change it to yours
oMail.From = "XXX@gamil.com";
// Set recipient email address, please change it to yours
oMail.To = strReceiver;
// Set email subject
oMail.Subject = strTitle;
// Set email body
oMail.TextBody = strBody;
// Your SMTP server address
SmtpServer oServer = new SmtpServer("smtp.gmail.com");
// User and password for ESMTP authentication, if your server doesn't require
// User authentication, please remove the following codes.
oServer.User = strUserName;
oServer.Password = strPW;
// If your smtp server requires TLS connection, please add this line
// oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;
// If your smtp server requires implicit SSL connection on 465 port, please add this line
oServer.Port = 465;
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;
try
{
oSmtp.SendMail(oServer, oMail);
}
catch (Exception ep)
{
MessageBox.Show(ep.Message);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
來源參考
訂閱:
文章 (Atom)