2016年3月8日 星期二

利用 Webdav 取得Exchange Serivce Mail 資訊

工作時遇到一個需求希望程式能自動連線到Exchange Server 取得指定帳號的Mail 資料

並依據收到的信件標題作相對應的動作

當時是用一個老前輩開發的物件完成這個需求但是對其運行原理很好奇因此針對該物件作分析

發現他是使用Webdav 協定與Exchange Server 做連線的

WebDAV 相關文件

http://technet.microsoft.com/zh-tw/library/ms876446.aspx

下面就介紹我是如何使用的

使用方式

在實地介紹時請先按照下列步驟進行前置作業

l 請先找一個Exchange Server 下的一個Mail Account

l 確認該Exchange Server 支援Webdav

l 請根據您實際的帳號資訊於TestFixtureSetUp 下填寫對應的帳號設定

使用程式碼

using System;

using System.Collections.Generic;

using System.Linq;

using System.Windows.Forms;

using System.IO;

using System.Net;

using System.Text;

using System.Web;

using System.Xml;

using NUnit.Framework;

namespace Webdav_Test

{

[TestFixture]

public class WebDAV_Test

{

private string _domain;

private string _mailAccount;

private string _password;

private string _server;

private string _userName;

private string _mailFolder;

[TestFixtureSetUp]

public void TestFixtureSetup()

{

//Domain 名稱

_domain = "Domain Name";

//Mail 帳號

_mailAccount = "Mail Account";

//AD Server 主機名稱 (IP 也可以)

_server = "Mail Server";

//使用者 帳號

_userName = "User Name";

//使用者 密碼

_password = "User Password";

//要讀取的郵件資料夾

_mailFolder = "Mail Folder";

//求ReceivedDate以後的信件資料

_receivedDate = Convert.ToDateTime("2012/09/20");

}

[Test]

//利用WebDAV 取得Exchange 的Mail 資料夾並 取得 2012/09/20 以後送到的信件資料

//列出搜尋到Mail 的 Tile 與 檔案名稱 與 顯示該Mail 是否有夾帶檔案

public void WebDAV_GetMails_Test()

{

List<MailItem> mails = new List<MailItem>();

// Variables.

string strRootURI = string.Format("http://{0}/exchange/{1}/{2}", _server, _mailAccount, _mailFolder);

// Build the SQL query.

string strQuery = " "

+ " "

+ " SELECT \"urn:schemas:httpmail:subject\", \"urn:schemas:httpmail:hasattachment\",\"urn:schemas:httpmail:datereceived\" "

+ "FROM scope('shallow traversal of \"" + strRootURI +"\"') "

+ " WHERE \"DAV:ishidden\"=False AND \"DAV:isfolder\"=False ORDER BY \"urn:schemas:httpmail:datereceived\" DESC ";

// Create a new CredentialCache object and fill it with the network

// credentials required to access the server.

CredentialCache MyCredentialCache = new CredentialCache();

MyCredentialCache.Add(new Uri(strRootURI),

"NTLM",

new NetworkCredential(_userName, _password, _domain)

);

// Create the HttpWebRequest object.

HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(strRootURI);

// Add the network credentials to the request.

Request.Credentials = MyCredentialCache;

// Specify the method.

Request.Method = "SEARCH";

// Encode the body using UTF-8.

byte[] bytes = Encoding.UTF8.GetBytes(strQuery);

// Set the content header length. This must be

// done before writing data to the request stream.

Request.ContentLength = bytes.Length;

// Get a reference to the request stream.

Stream RequestStream = Request.GetRequestStream();

// Write the SQL query to the request stream.

RequestStream.Write(bytes, 0, bytes.Length);

// Close the Stream object to release the connection

// for further use.

RequestStream.Close();

// Set the content type header.

Request.ContentType = "text/xml";

// Send the SEARCH method request and get the

// response from the server.

WebResponse Response = Request.GetResponse();

// Get the XML response stream.

Stream ResponseStream = Response.GetResponseStream();

// Create the XmlTextReader object from the XML

// response stream.

XmlTextReader XmlReader = new XmlTextReader(ResponseStream);

// Read through the XML response, node by node.

while (XmlReader.Read())

{

// Console.WriteLine("{0}, {1}", XmlReader.Name, XmlReader.Value);

// Look for the opening DAV:href node. The DAV: namespace is

//typically assigned the a: prefix in the XML response body.

if (XmlReader.Name == "a:href")

{

// Advance the reader to the text node.

XmlReader.Read();

// Console.WriteLine("{0}, {1}", XmlReader.Name, XmlReader.Value);

string path = XmlReader.Value;

string title = "";

string hasAttachment = "0";

DateTime dateReceived = DateTime.MinValue;

//ahref close tag

XmlReader.Read();

// Console.WriteLine("{0}, {1}", XmlReader.Name, XmlReader.Value);

while (XmlReader.Name != "a:prop")

{

XmlReader.Read();

// Console.WriteLine("{0}, {1}", XmlReader.Name, XmlReader.Value);

}

XmlReader.Read();

// Console.WriteLine("{0}, {1}", XmlReader.Name, XmlReader.Value);

while (XmlReader.Name != "a:prop")

{

switch (XmlReader.Name)

{

case "d:subject":

XmlReader.Read();

title = XmlReader.Value;

XmlReader.Read();

break;

case "d:hasattachment":

XmlReader.Read();

hasAttachment = XmlReader.Value;

XmlReader.Read();

break;

case "d:datereceived":

XmlReader.Read();

dateReceived = Convert.ToDateTime(XmlReader.Value);

XmlReader.Read();

break;

}

XmlReader.Read();

}

if (dateReceived < _receivedDate)

{

break;

}

MailItem item = new MailItem(title, path);

item.HasAttachment = hasAttachment == "1";

mails.Add(item);

//Advance the reader to the closing DAV:href node.

XmlReader.Read();

// Console.WriteLine("{0}, {1}", XmlReader.Name, XmlReader.Value);

}

}

// Clean up.

XmlReader.Close();

ResponseStream.Close();

Response.Close();

Console.WriteLine("以下為信箱所有Mial的標題與檔案名稱");

foreach (var mail in mails)

{

Console.WriteLine("Mail Title:" + mail.Title);

Console.WriteLine("Mail Path:" + mail.Path);

Console.WriteLine("Mail have Attachment :" + mail.HasAttachment.ToString());

}

}

}

}

------ Test started: Assembly: IonicZipProject.dll ------

以下為信箱所有Mial的標題與檔案名稱

Mail Title: TEST Mail From Robin

Mail Path: http:// Domain /exchange/Feng.Robin/ TEST%20Mail%20From%20Robin.EML

Mail have Attachment :True

程式細部說明

連線前請將Domain 名稱 , Mail 帳號 , AD Server 主機名稱 (IP 也可以), 使用者 帳號, 使用者 密碼, 要讀取的郵件資料夾 , ReceivedDate設定好

Mail 帳號 只要取Mail帳號@之前的名稱及可

ReceivedDate 的設定主要是要跟程式說你只要收到日期大於ReceivedDate 的Mail

範例程式使用的設定為了保護個資用的都是假的 如果直接照抄程式碼的話那我保障跑到死都跑不出來

以下為信箱所有Mial的標題與檔案名稱

當設定部分都沒問題了 程式就會列出所有的信件資料

包含信件的標題 , 信件放置的檔案位置 , 以及判定Mail 是否有夾帶檔案

P.S.我測試都是使用NUnit 配合 TestDriven.NET 來測試結果因此沒有裝的人可以參考我網站的 簡介與使用> 和簡介與使用>

進行安裝 在此不贅述了~~~~

以上教學歡迎轉載但是請註明源頭來自

胖雀鳥的妄想天地http://tw.myblog.yahoo.com/big-suzume

2016年3月7日 星期一

PHP-中文目錄修正

<?php
$base_dir="D:/httpd/09/uploads";
$base_url="http://localhost/09/uploads";
$_REQUEST['to']=mb_convert_encoding($_REQUEST['to'], "Big5", "Big5,UTF-8");
$dir=(empty($_REQUEST['to']))?$base_dir:str_replace("\\","/",realpath($_REQUEST['to']));
$dir=(ereg("^".$base_dir,$dir))?$dir:$base_dir;
$url=str_replace($base_dir,$base_url,$dir);
define("_UPLOAD_DIR",$dir);
define("_UPLOAD_URL",$url);
if($_GET['op']=="del"){
    $file=mb_convert_encoding($_GET['file'], "Big5", "Big5,UTF-8");
    @unlink(_UPLOAD_DIR."/".$file);
    header("location:"._UPLOAD_DIR);
}elseif($_POST['op']=="del"){
        if(is_array($_POST['files'])){
        foreach($_POST['files'] as $file){
            $file=mb_convert_encoding($file, "Big5", "Big5,UTF-8");
            @unlink(_UPLOAD_DIR."/".$file);
        }
        header("location:"._UPLOAD_DIR);
    }
}elseif($_POST['op']=="move"){
        if(is_array($_POST['files'])){
        foreach($_POST['files'] as $file){
            $file=mb_convert_encoding($file, "Big5", "Big5,UTF-8");
            @rename(_UPLOAD_DIR."/".$file,$_POST['new_folder']."/".$file);
        }
        header("location:"._UPLOAD_DIR);
    }
}elseif(!empty($_POST['mk_folder'])){
        $mk_folder=mb_convert_encoding($_POST['mk_folder'], "Big5", "Big5,UTF-8");
      mk_dir(_UPLOAD_DIR."/{$mk_folder}");
    header("location:"._UPLOAD_DIR);
}elseif(!empty($_FILES['pic']['tmp_name'])){
  foreach($_FILES['pic']['tmp_name'] as $i => $tmpname){
        $up_pic=mb_convert_encoding($_FILES['pic']['name'][$i], "Big5", "Big5,UTF-8");
    move_uploaded_file($tmpname , _UPLOAD_DIR."/{$up_pic}");
  }
  header("location:"._UPLOAD_DIR);
}
$dh=opendir(_UPLOAD_DIR);
$show_dir=mb_convert_encoding($dir, "UTF-8", "Big5,UTF-8");
$main="
<script src='js/jquery-1.3.2.min.js' type='text/javascript'></script>
<script src='js/jquery.MultiFile.js' type='text/javascript'></script>
<form action='{$_SERVER['PHP_SELF']}' method='post'  enctype='multipart/form-data'>
<table class='tinytable'>
<tr><td colspan=4>$show_dir</td></tr>
<tr><th>檔名</th><th>大小</th><th>類型</th><th>功能</th></tr>";
while($file=readdir($dh)){
    if($file==".")continue;
    $type=filetype(_UPLOAD_DIR."/".$file);
    if($type=="dir"){
        $dir_arr[]=$file;
    }else{
        $file_arr[]=$file;
    }
}
//秀出目錄
if(is_array($dir_arr)){
    foreach($dir_arr as $sub_dir){
        $size=($sub_dir=="..")?"":dirSize(_UPLOAD_DIR."/".$sub_dir);
        $size=($sub_dir=="..")?"":formatBytes($size,1);
        $sub_dir=mb_convert_encoding($sub_dir, "UTF-8", "Big5,UTF-8");
        $to_url=urlencode(_UPLOAD_DIR."/".$sub_dir);
        $main.= "<tr><td><a href='index.php?to=$to_url'>$sub_dir</a></td><td>$size</td><td>目錄</td><td></td></tr>";
    }
}
//秀出檔案
if(is_array($file_arr)){
    foreach($file_arr as $file){
        $size=filesize(_UPLOAD_DIR."/".$file);
        $size=formatBytes($size,1);
        $file=mb_convert_encoding($file, "UTF-8", "Big5,UTF-8");
        $main.= "<tr><td><a href='"._UPLOAD_URL."/{$file}'>$file</a></td><td>$size</td><td>檔案</td><td>
            <input type='checkbox' name='files[]' value='$file'>
            <a href='{$_SERVER['PHP_SELF']}?file=$file&op=del& to="._UPLOAD_DIR."'>刪除</a></td></tr>";
    }
}
$to_dir=mb_convert_encoding(_UPLOAD_DIR, "UTF-8", "Big5,UTF-8");
$main.="
<tr><th colspan=4>
<input type='hidden' name='to' value='$to_dir'>
將勾選的檔案 <input type='radio' name='op' value='del'>刪除
<input type='radio' name='op' value='move'>搬到:".folder_select($base_dir,"new_folder")."<br>
建立新目錄:<input type='text' name='mk_folder'><br>
上傳檔案:<input type='file' name='pic[]' class='multi' />
<input type='submit' value='送出'>
</th></tr>
</table>
</form>";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title></title>
  <link rel="stylesheet" href="tinytable.css" />
  <link rel="stylesheet" href="iconize_l.css" />
  </head>
  <body>
    <?php echo $main;?>
  </body>
</html>
<?php
//計算目錄大小
function dirSize($directory) {
    $size = 0;
    foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file){
        $size+=$file->getSize();
    }
    return $size;
}
//把 bytes 轉換成其他單位
function formatBytes($bytes, $precision = 2) {
    $units = array('B', 'KB', 'MB', 'GB', 'TB');
    $bytes = max($bytes, 0);
    $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
    $pow = min($pow, count($units) - 1);
    $bytes /= pow(1024, $pow);
    return round($bytes, $precision) . ' ' . $units[$pow];
}
//目錄選單
function folder_select($base_dir="",$name="",$i=0){
  $prefix=str_repeat("--",$i);
  $i++;
  $option="";
  $dh=opendir($base_dir);
  while($file=readdir($dh)){
    if($file=="." or $file=="..")continue;
    $type=filetype($base_dir."/".$file);
    if($type=="dir"){
        $option.="<option value='{$base_dir}/{$file}'>{$prefix}{$file}</option>";
        $option.=folder_select("{$base_dir}/{$file}",$name,$i);
    }
    }
    if($i==1){
        $main="<select name='$name'>
        $option
        </select>";
    }else{
    $main=$option;
    }
    return $main;
}
//建立目錄
function mk_dir($dir=""){
    //若無目錄名稱秀出警告訊息
    if(empty($dir))die("沒有目錄名稱");
    //若目錄不存在的話建立目錄
    if (!is_dir($dir)) {
        umask(000);
        //若建立失敗秀出警告訊息
        if(!mkdir($dir, 0777)){
            die("$dir 建立失敗!");
        }
    }
}
?>

2013年6月17日 星期一

IOS APP 名稱本地化(多國語言)

IOS APP 名稱本地化(多國語言)

1.找到您專案裏的檔案副檔名為 .plist (通常是您的bundle名稱+Info.plist)
新增一個key值,名為 Application has localized display name ,Value選擇Yes
意思為應用程式將使用本地顯示名稱

2.在專案上按右鍵,New File->選擇 IOS->Resource->Strings Files
輸入檔案名稱為InfoPlist.strings

3.點選InfoPlist.strings 在右側欄找到Localization的按鍵

4.新增您要本地化的語言

5.在各語言的InfoPlist.strings檔案中新增"CFBundleDisplayName"="您要顯示的App名稱";


2013年3月14日 星期四

Outlook2003設定密碼



Outlook2003設定個人資料匣密碼

1.在第一個資料匣上按Mouse右鍵
2.點選"xxx"的內容

3.點選右下角[進階]按鈕
4.點選變更密碼
5.若有舊密碼,則輸入舊密碼,
若第一次設定請留空白,
輸入新密碼及確認密碼
(輸入一樣的密碼)

6.點選[確認]按鈕

關閉Outlook後,重新登入就會出現
密碼的對話框了

2013年1月14日 星期一

UISearchBar-搜尋列整理

無搜尋結果顯示

image

代理:<UISearchBarDelegate>

@protocol UISearchBarDelegate <NSObject>

@optional

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar;                      // return NO to not become first responder
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar;                     // called when text starts editing
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar;                        // return NO to not resign first responder
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar;                       // called when text ends editing
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText;   // called when text changes (including clear)
- (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text NS_AVAILABLE_IOS(3_0); // called before text changes

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar;                     // called when keyboard search button pressed
- (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar;                   // called when bookmark button pressed
- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar;                    // called when cancel button pressed
- (void)searchBarResultsListButtonClicked:(UISearchBar *)searchBar NS_AVAILABLE_IOS(3_2); // called when search results button pressed

- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope NS_AVAILABLE_IOS(3_0);

@end

帶有搜尋結果顯示

 image

代理:<UITableViewDataSource, UITableViewDelegate,UISearchBarDelegate,UISearchDisplayDelegate>

@protocol UISearchDisplayDelegate <NSObject>

@optional

// when we start/end showing the search UI
- (void) searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller;
- (void) searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller;
- (void) searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller;
- (void) searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller;

// called when the table is created destroyed, shown or hidden. configure as necessary.
- (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView;
- (void)searchDisplayController:(UISearchDisplayController *)controller willUnloadSearchResultsTableView:(UITableView *)tableView;

// called when table is shown/hidden
- (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView;
- (void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView;
- (void)searchDisplayController:(UISearchDisplayController *)controller willHideSearchResultsTableView:(UITableView *)tableView;
- (void)searchDisplayController:(UISearchDisplayController *)controller didHideSearchResultsTableView:(UITableView *)tableView;

// return YES to reload table. called when search string/option changes. convenience methods on top UISearchBar delegate methods
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString;
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption;

@end

 

#以下範例為使用UISearchDisplayDelegate代理的方法

搜尋元件初始化:

無scope的設定方式

    searchData = [[NSMutableArray alloc] init];
    searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    searchBar.tintColor=bgColor;
    jobList.backgroundColor=bgColor;
    //searchBar.tintColor=[UIColor1 greenColor];
    // Do any additional setup after loading the view.
    /*the search bar widht must be > 1, the height must be at least 44
     (the real size of the search bar)*/
    searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
    /*contents controller is the UITableViewController, this let you to reuse
     the same TableViewController Delegate method used for the main table.*/
    searchDisplayController.delegate = self;
    searchDisplayController.searchResultsDataSource = self;
    searchDisplayController.searchResultsDelegate=self;
    //set the delegate = self. Previously declared in ViewController.h
    self.jobList.tableHeaderView = searchBar; //this line add the searchBar

引用代理方法:

//-----------------------------------搜尋----------------------------------------
-(void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView
{
    //載入搜尋的table,設定cell背景色
    tableView.backgroundColor=[UIColor colorWithRed:(222.0f/255.0f) green:(255.0f/255.0f) blue:(200.0f/255.0f) alpha:1];
}

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{

    [searchData removeAllObjects];
    jobBas *jobbas;
    for(jobbas in tablearr) //take the n group (eg. group1, group2, group3)
        //in the original data
    {
        NSLog(@"%@:%@",jobbas.jobReason,searchString);
        NSRange range = [jobbas.jobReason rangeOfString:searchString options:NSCaseInsensitiveSearch];
        if (range.length > 0) { //if the substring match
            [searchData addObject:jobbas]; //add the element to group
        }
    }
    return YES;
}

 

 

有scope的設定方式

searchData = [[NSMutableArray alloc] init];

    searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];

    searchBar.scopeButtonTitles=[NSArray arrayWithObjects:@"全部",@"加點",@"扣點", nil];

    searchBar.tintColor=jobList.backgroundColor;

    //searchBar.tintColor=[UIColor greenColor];

    // Do any additional setup after loading the view.

    /*the search bar widht must be > 1, the height must be at least 44

     (the real size of the search bar)*/

    searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];

    /*contents controller is the UITableViewController, this let you to reuse

     the same TableViewController Delegate method used for the main table.*/

    searchDisplayController.delegate = self;

    searchDisplayController.searchResultsDataSource = self;

    searchDisplayController.searchResultsDelegate=self;

    //set the delegate = self. Previously declared in ViewController.h

    for (id subview in searchDisplayController.searchBar.subviews )

    {

        if([subview isMemberOfClass:[UISegmentedControl class]])

        {

            UISegmentedControl *scopeBar=(UISegmentedControl *) subview;

            [scopeBar setSegmentedControlStyle:UISegmentedControlStyleBordered];

            [scopeBar setTintColor: [UIColor greenColor]];//you can also set RGB color here

            //scopeBar.tintColor =  [UIColor blackColor];

        }

    }

    self.jobList.tableHeaderView = searchBar; //this line add the searchBar

引用代理方法:

//-----------------------------------搜尋----------------------------------------

-(void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView
{
    //載入搜尋的table,設定cell背景色
    tableView.backgroundColor=[UIColor colorWithRed:(222.0f/255.0f) green:(255.0f/255.0f) blue:(200.0f/255.0f) alpha:1];
}

//
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
    /*
     Update the filtered array based on the search text and scope.
     */
    [searchData removeAllObjects]; // First clear the filtered array.
    /*
     Search the main list for products whose type matches the scope (if selected) and whose name matches searchText; add items that match to the filtered array.
     */
    for (jobBas *jobbas in tablearr)
    {
        NSString *wscope;
        if (jobbas.is_GoodJob) {
            wscope=@"加點";
        }else wscope=@"扣點";
        if ([scope isEqualToString:@"全部"] || [wscope isEqualToString:scope])
        {
            NSComparisonResult result = [jobbas.jobReason compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])];
            if (result == NSOrderedSame)
            {
                [searchData addObject:jobbas];
            }
        }
    }
}

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    [self filterContentForSearchText:searchString scope:
     [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
    // Return YES to cause the search result table view to be reloaded.
    return YES;
}

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption
{
    [self filterContentForSearchText:[self.searchDisplayController.searchBar text] scope:
     [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]];
    // Return YES to cause the search result table view to be reloaded.
    return YES;
}

 

   

2012年10月7日 星期日

XCODE 4.6 多國語言問題排除

按照XCODE國際化的作法做完之後,發現並不會自動切換

網路查到解決的方式

http://stackoverflow.com/questions/4297051/nslocalizedstring-problem

If you use xCode 4 you will face with such problem. Try next steps:

  1. Remove application from device
  2. Select root node of project tree to get project's properties
  3. Select "Build Phases" tab
  4. Click "Add build phase" and select "Copy files"
  5. Select "Resources" in "Copy files" view
  6. Add Localizable.strings file
  7. Perform "Clean" for the project
  8. "Build and Run"

事實上不用做這麼多

只要兩個步驟:

1.從裝置移除應用程式

2.Product->Clear

image

2012年6月6日 星期三

DOS 指令匯整

蒐集及整理一些實用的DOS指令:

1.使用批次檔備份原始檔案,並在檔案後加上日期時間(YYYYMMHHMM)

首先要先了解目前的日期格式如何:

執行CMD進到DOS命令視窗

打 echo %date%

image

如圖示,得到我電腦的日期格式為 MM/DD/YYYY

(要設定此格式,請至 [控制台]->[地區及語言選項]->[自訂地區選項]->[日期]->修改簡短日期樣式 即可)

要取得YYYY(西元年)的語法為:

%date:~6,4%

以下解釋:

0123456789 <--第0位起算,YYYY的第一位位置在6,要取4個數字,所以是 6,4

MM/DD/YYYY

以此類推:

%date:~0,2% -->可取得月

%date:~3,2% -->可取得日

執行以下指令即可得到YYYYMMDD

echo %date:~6,4%%date:~0,2%%date:~3,2%

結果: 20120607 (當時的日期)

同樣的,時間也可以使用此方式取得部分字元

這樣做的目的為在備份等應用時,可以儲存正確的檔名(斜線(/)不是合法的檔名字元)

 

例如:

COPY  "C:\Program Files\Infolight\VD30_Client\SALING30tw.VDS" D:\VDS_BAK\saling30tw_%date:~6,4%%date:~0,2%%date:~3,2%.vds /Y

結果:

image