<?xml version="1.0" encoding="Shift_JIS"?><feed xmlns="http://www.w3.org/2005/Atom"> <title>BHT</title> <link rel="alternate" type="text/html" href="http://www.bht.co.jp/" /> <link rel="self" type="application/atom+xml" href="http://www.bht.co.jp/atom.xml" /> <id>tag:www.bht.co.jp,2008-10-10://2</id> <updated>2009-02-13T09:31:32Z</updated>  <generator uri="http://www.sixapart.com/movabletype/">Movable Type Pro 4.21-ja</generator><entry> <title>Javascript や JAVA, C# の IndexOf をPHPで実装する。</title> <link rel="alternate" type="text/html" href="http://www.bht.co.jp/2009/02/javascript-java-c-indexof-php.html" /> <id>tag:www.bht.co.jp,2009://2.23</id> <published>2009-02-13T09:06:31Z</published> <updated>2009-02-13T09:31:32Z</updated> <summary>ＰＨＰには、strposという関数が用意されていて、これがJavascript ...</summary> <author> <name>kazu</name>  </author>  <category term="PHP" scheme="http://www.sixapart.com/ns/types#category" />  <category term="技" scheme="http://www.sixapart.com/ns/types#category" />   <content type="html" xml:lang="ja" xml:base="http://www.bht.co.jp/"> <![CDATA[ＰＨＰには、strposという関数が用意されていて、これがJavascript や C# のＩｎｄｅｘＯｆと同じような働きをします。<br>
<br>
strpos というのに慣れてない等の場合は、次のように、indexOfという関数を自前で用意してみるのも良いかもしれません。<br>

<mtprecode>
function indexOf($haystack, $needle, $offset="") { 
        return strpos($haystack, $needle, $offset); 
}
</mtprecode>]]>  </content></entry><entry> <title>データベース接続からデータ取得まで</title> <link rel="alternate" type="text/html" href="http://www.bht.co.jp/2009/01/post-8.html" /> <id>tag:www.bht.co.jp,2009://2.22</id> <published>2009-01-28T05:43:04Z</published> <updated>2009-01-28T06:07:31Z</updated> <summary>PHPでデータベースに接続し、SQLを投げてから、データを取得し、そのデータを表...</summary> <author> <name>kazu</name>  </author>  <category term="PHP" scheme="http://www.sixapart.com/ns/types#category" />  <category term="ＤＢ連携" scheme="http://www.sixapart.com/ns/types#category" />   <content type="html" xml:lang="ja" xml:base="http://www.bht.co.jp/"> <![CDATA[PHPでデータベースに接続し、SQLを投げてから、データを取得し、そのデータを表示するところまでを記述してみようかと思います。<br>
（PHPやデータベースをやり始めたばかりのときは、これが「結構難儀やな〜」って思えたりするもんですが、次のような流れを掴んでしまえば、慣れちゃいます。）<br>
<br><br>

接続するデータベースは、PostgreSQLで、次のようなデータベースと仮定します。<br>
データベース名；DBNAME<br> 
ユーザー名；DBUSER<br> 
パスワード；DBPASSWD<br>
テーブル；TEST_TABLE<br>
TEST_TABLEに存在するカラム；A, B, C, D<br>
<br>

<MTPrecode> 
	// データベースに接続
	$con = @pg_connect( "dbname=DBNAME user=DBUSER password=DBPASSWD" ) ;
	// データベースに接続できなかったときの処理
	if ( !$con ) {
		print_errorpage( "データベースの接続に失敗しました:" . pg_last_error() ) ;
		exit( 1 ) ;
	}

	// SQL
	$sql = "SELECT A, B, C FROM TEST_TABLE; " ;

	// クエリ結果リソースを取得
	$result  = pg_query( $con, $sql ) ;
	// SQLクエリ実行が上手く行かない等、エラーが起こった場合の処理
	if ( !$result ) {
		echo "エラーが起こっちゃいました。\n" ;
		exit;
	}

	// 結果リソースから、すべての行 （レコード）を保持する配列を作成する
	$result _array = pg_fetch_all( $result ) ;

	// 3行目のカラムAの情報を表示する
	print $result _array[ 3 ][ 'A' ] ;

	// 5行目のカラムCの情報を表示する
	print $result _array[ 5 ][ 'C' ] ;

</MTPrecode> 
]]>  </content></entry><entry> <title>ドキュメンテーションコメント</title> <link rel="alternate" type="text/html" href="http://www.bht.co.jp/2009/01/post-7.html" /> <id>tag:www.bht.co.jp,2009://2.21</id> <published>2009-01-09T04:43:38Z</published> <updated>2009-01-09T04:55:32Z</updated> <summary>下記の///で始まるコメント、ドキュメンテーションコメントと言います。「///」...</summary> <author> <name>satoshi</name>  </author>  <category term="C#.Net" scheme="http://www.sixapart.com/ns/types#category" />   <content type="html" xml:lang="ja" xml:base="http://www.bht.co.jp/"> <![CDATA[下記の///で始まるコメント、ドキュメンテーションコメントと言います。「///」と入力すると勝手にでき、内容を入力します。<br><br>
１．メソッドを作成
<mtprecode>
private bool CheckDate(int year, int month, int day)
{
    :
}
</mtprecode>
２．「///」と入力するとコメントが出来ます
<mtprecode>
/// &lt;summary&gt;
/// 
/// &lt;/summary&gt;
/// &lt;param name="year"&gt;&lt;/param&gt;
/// &lt;param name="month"&gt;&lt;/param&gt;
/// &lt;param name="day"&gt;&lt;/param&gt;
/// &lt;returns&gt;&lt;/returns&gt;
private bool CheckDate(int year, int month, int day)
{
    :
}
</mtprecode>
３．コメント内容を入力
<mtprecode>
/// &lt;summary&gt;
/// 日付の正当性をチェックします。
/// &lt;/summary&gt;
/// &lt;param name="year"&gt;年を指定します&lt;/param&gt;
/// &lt;param name="month"&gt;月を指定します&lt;/param&gt;
/// &lt;param name="day"&gt;日を指定します&lt;/param&gt;
/// &lt;returns&gt;true/false&lt;/returns&gt;
private bool CheckDate(int year, int month, int day)
{
    :
}
</mtprecode>
※参考までにタグの説明<br>
&lt;c&gt;  コード(summaryなどの文中に書くもの)<br>
&lt;code&gt;  コード(複数行にわたるもの)<br>
&lt;example&gt;  サンプル コードの説明(codeと組み合わせて使う)<br>
&lt;exception&gt;  例外クラスの説明<br>
&lt;include&gt;  別のファイルの内容を取り込む<br>
&lt;list&gt;  アイテマイズしたいときに使う<br>
&lt;param&gt;  そのメソッドの引数に関する説明<br>
&lt;paramref&gt;  summaryなどの文中で引数を参照したいときに使う<br>
&lt;permission&gt;  メンバーへのアクセスのパーミッションを指定する<br>
&lt;remarks&gt;  クラスの説明<br>
&lt;returns&gt;  戻り値の説明<br>
&lt;see&gt;  他のメンバーを参照したいときに使う<br>
&lt;seealso&gt;  他に参照して欲しいものがあるときに使う<br>
&lt;summary&gt;  そのクラスやメソッドの概要<br>
&lt;value&gt;  プロパティの説明<br>]]>  </content></entry><entry> <title>春分の日、秋分の日の求め方(1980年から2099年で有効)</title> <link rel="alternate" type="text/html" href="http://www.bht.co.jp/2008/12/19802099.html" /> <id>tag:www.bht.co.jp,2008://2.20</id> <published>2008-12-16T17:15:56Z</published> <updated>2008-12-17T06:49:32Z</updated> <summary>カレンダーなどを作成するとき、予め日付が決まっている祝日は何の問題もないが、毎年...</summary> <author> <name>kazu</name>  </author>  <category term="C#.Net" scheme="http://www.sixapart.com/ns/types#category" />  <category term="Javascript" scheme="http://www.sixapart.com/ns/types#category" />  <category term="PHP" scheme="http://www.sixapart.com/ns/types#category" />  <category term="その他" scheme="http://www.sixapart.com/ns/types#category" />  <category term="日付" scheme="http://www.sixapart.com/ns/types#category" />  <category term="日付" scheme="http://www.sixapart.com/ns/types#category" />  <category term="日付" scheme="http://www.sixapart.com/ns/types#category" />   <content type="html" xml:lang="ja" xml:base="http://www.bht.co.jp/"> <![CDATA[カレンダーなどを作成するとき、予め日付が決まっている祝日は何の問題もないが、毎年日付が変わる祝日がある。<br>(といっても、最近は国会でハッピーマンデーやら何やら出来ちゃったりして結構変わったりしますが^_^;) <br>
それは、春分の日と秋分の日です。<br>
まず、この春分の日と秋分の日はどのようにして決められるかを知ることから始めましょう。<br>
1年は365日となっていますが、地球が太陽の周りを公転運動で1周するのに厳密には365.242194日かかります。<br>
この小数点以下の端数が存在するために、4年に1度閏年が存在しているわけです。<br>
春分の日と秋分の日は、地球の赤道上で太陽の南中高度90度になる日と定義されています。これを厳密に計算すると次のようになります。<br>
(春分の日は3月、秋分の日は9月で、以下はその日の値の求め方です。各変数$yearまたはyearにはその年の値が入ります。)<br><br>
●PHPの場合
<MtPrecode>
// 春分の日<br>
$vernalEquinox = floor( 20.8431 + 0.242194 * ( $year - 1980 ) ) - floor( ( $year - 1980 ) / 4 ) ;<br>
// 秋分の日<br>
$autumnalEquinox = floor( 23.2488 + 0.242194 * ( $year - 1980 ) ) - floor( ( $year - 1980 ) / 4 ) ;<br>
</MtPrecode>
<br><br>
●C#の場合
<MtPrecode>
// 春分の日<br>
int vernalEquinox = (int)Math.Floor(20.8431 + 0.242194 * (year - 1980) - Math.Floor((year - 1980) / 4));<br>
// 秋分の日<br>
int autumnalEquinox = (int)Math.Floor(23.2488 + 0.242194 * (year - 1980) - Math.Floor((year - 1980) / 4));<br>
</MtPrecode><br><br>
●javascriptの場合
<MtPrecode>
// 春分の日<br>
vernalEquinox = Math.floor(20.8431 + 0.242194 * (year - 1980) - Math.floor((year - 1980) / 4));<br>
// 秋分の日<br>
autumnalEquinox = Math.floor(23.2488 + 0.242194 * (year - 1980) - Math.floor((year - 1980) / 4));<br>
</MtPrecode><br><br>
上述の式から、「なぜ1980年が基準になっているのか？」という疑問がわいてくることでしょう。<br>
それは、厳密に計測した年が1980年だったからです。<br>
1980年の春分の日の厳密な日が20.8431日、秋分の日が23.2488日であったということからその値が基準となったわけです。また、その年から1980年を引いて4で割った値を引いているのは、前出の4年に一度に閏年があるからその分、4年に一度1日のズレが生じるからです。<br><br>


＊これらの式は、1980年〜2099年の間で使用可能だとされています。]]>  </content></entry><entry> <title>NULL(空文字)判定</title> <link rel="alternate" type="text/html" href="http://www.bht.co.jp/2008/12/null.html" /> <id>tag:www.bht.co.jp,2008://2.19</id> <published>2008-12-16T08:24:55Z</published> <updated>2008-12-16T08:27:41Z</updated> <summary>よく文字チェック等で行われるNULL(空文字)チェック。StringクラスのIs...</summary> <author> <name>satoshi</name>  </author>  <category term="技" scheme="http://www.sixapart.com/ns/types#category" />   <content type="html" xml:lang="ja" xml:base="http://www.bht.co.jp/"> <![CDATA[よく文字チェック等で行われるNULL(空文字)チェック。StringクラスのIsNullOrEmptyメソッドを使用すると簡単にチェックが行えます。

<MTPrecode>
if (String.IsNullOrEmpty(checkString))
{
    // NULL、もしくは空文字列である
}

if (!String.IsNullOrEmpty(checkString))
{
    // NULLではなく、かつ空文字列でもない
}
</MTPrecode>]]>  </content></entry><entry> <title>コントロールの表示・非表示設定</title> <link rel="alternate" type="text/html" href="http://www.bht.co.jp/2008/12/post-6.html" /> <id>tag:www.bht.co.jp,2008://2.18</id> <published>2008-12-05T11:00:49Z</published> <updated>2008-12-05T11:20:08Z</updated> <summary>データによってコントロールを表示したり非表示にしたりしたいことって、何気にありま...</summary> <author> <name>satoshi</name>  </author>  <category term="技" scheme="http://www.sixapart.com/ns/types#category" />   <content type="html" xml:lang="ja" xml:base="http://www.bht.co.jp/"> <![CDATA[データによってコントロールを表示したり非表示にしたりしたいことって、何気にありますよね〜<br>
そんな時は、「asp:PlaceHolder」タグを利用すると簡単にできます。<br>
コントロールを非表示にするには、Visible プロパティを false に設定します。<br>
また、非表示の状態から表示の状態に戻したい場合は true を設定します。<br><br>

例：電話番号フラグが"0"の場合は非表示、"1"の場合は表示<br>

aspx側

<MTPrecode>
// 「phTel」パラメータは「visible="false"」となっているので、非表示設定
&lt;asp:PlaceHolder ID="phTel" runat="server" visible="false"&gt;
    &lt;table cellpadding="0" cellspacing="0" border="0" style="border-style:none"&gt;
        &lt;tr&gt;
            &lt;td style="width:80px" valign="middle"&gt;電話番号&lt;/td&gt;
            &lt;td style="width:100px" valign="middle"&gt;
              &lt;asp:Label ID="lblTelNo" runat="server"&gt;&lt;/asp:Label&gt;
            &lt;/td&gt;
            &lt;td style="width:6px"&gt;&lt;/td&gt;
            &lt;td style="width:40px" valign="middle"&gt;備考&lt;/td&gt;
            &lt;td style="width:400px" valign="middle"&gt;
              &lt;asp:TextBox ID="txtRemark" Width="400" runat="server" MaxLength="250" TabIndex="3"&gt;&lt;/asp:TextBox&gt;
            &lt;/td&gt;
            &lt;td style="width:10px"&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/table&gt;
&lt;/asp:PlaceHolder&gt;
</MTPrecode>

aspx.cs側

<MTPrecode>
// 電話番号フラグ = "1"の場合はデータ出力
if (lblTelFlg.Text == "1")
{
    this.phTel.Visible = true;
    lblTelNo.Text = "03-1234-5678";
}
</MTPrecode>

表示結果は、以下の様になります。
<br>
<b>0の時は、コントロール非表示。</b><br>
<span class="mt-enclosure mt-enclosure-image" style="display: inline;"><img alt="ph0.gif" src="http://www.bht.co.jp/2008/12/05/ph0.gif" width="237" height="26" class="mt-image-none" style="" /></span><br><br>
<b>1の時は、コントロール表示。</b><br>
<span class="mt-enclosure mt-enclosure-image" style="display: inline;"><img alt="ph1.gif" src="http://www.bht.co.jp/2008/12/05/ph1.gif" width="651" height="60" class="mt-image-none" style="" /></span>]]>  </content></entry><entry> <title>休日かどうかをチェック</title> <link rel="alternate" type="text/html" href="http://www.bht.co.jp/2008/11/post-4.html" /> <id>tag:www.bht.co.jp,2008://2.17</id> <published>2008-11-21T08:05:49Z</published> <updated>2008-11-21T08:46:02Z</updated> <summary>その日が営業日か休日かで処理を変えたいことがあります。土日に関しては標準の st...</summary> <author> <name>さいとー</name>  </author>  <category term="日付" scheme="http://www.sixapart.com/ns/types#category" />   <content type="html" xml:lang="ja" xml:base="http://www.bht.co.jp/"> <![CDATA[その日が営業日か休日かで処理を変えたいことがあります。<br /><br />土日に関しては標準の strftime() などで確認可能なのですが<br />日本固有の「国民の祝日」や振り替え休日のチェックは<br />自分で書こうとするとなかなか厄介です。<br /><br />こんなとき…<br />ARTISAN PROJECT というところで、日本の暦に関するクラスが<br />提供されているので、これを使うと便利。<br /><a href="http://php.five-foxes.com/output/JapaneseDate/japaneseDate.html">http://php.five-foxes.com/output/JapaneseDate/japaneseDate.html<br /></a>スクリプト本体はここ： <a href="http://php.five-foxes.com/projects/jd.zip">http://php.five-foxes.com/projects/jd.zip<br /><br /></a>たとえばこんな使い方が可能。<br /><br />■スクリプトサンプル<br />#! /usr/local/bin/php -q<br />&lt;?php<br />$y = $argv[1];&nbsp; # 年<br />$m = $argv[2];&nbsp; # 月<br />$d = $argv[3];&nbsp; # 日<br /><br />require_once('jd/japaneseDate/japaneseDate.php'); # クラス読込<br />$jd =&amp; new japaneseDate(); # クラス初期化<br />$time_stamp = mktime(0, 0, 0, $m, $d, $y); # UNIX 形式タイムスタンプ生成<br />$holiday = 0; # 休日フラグ初期化<br /><br /># 土日チェック<br />if (in_array(strftime("%a", $time_stamp), array('Sun', 'Sat'))) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $holiday++;<br />}<br /># 祝日／代休チェック<br />if ('' != $jd-&gt;mb_strftime("%L", $time_stamp)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $holiday++;<br />}<br /># 結果出力<br />if ($holiday == 0) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Working day. (-_-)\n");<br />} else {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Holiday! (^-^)\n");<br />}<br /><br /># 年月日フォーマット出力<br />printf("%s\n", $jd-&gt;mb_strftime("%Y-%m-%d[%K]%L", $time_stamp));<br />?&gt;<br /><br />■実行例<br />% ./chk_holiday.php 2008 11 21<br />Working day. (-_-)<br />2008-11-21[金]<br />% ./chk_holiday.php 2008 11 22<br />Holiday! (^-^)<br />2008-11-22[土]<br />% ./chk_holiday.php 2008 11 23<br />Holiday! (^-^)<br />2008-11-23[日]勤労感謝の日<br />% ./chk_holiday.php 2008 11 24<br />Holiday! (^-^)<br />2008-11-24[月]振替休日<br />%<br /><br />その他、旧暦や六曜などにも対応していてなかなかマニアック。<br /><a href="http://php.five-foxes.com/output/JapaneseDate/japaneseDate.html#sec-method-summary">http://php.five-foxes.com/output/JapaneseDate/japaneseDate.html#sec-method-summary</a>]]>  </content></entry><entry> <title>ArrayListからString配列への変換</title> <link rel="alternate" type="text/html" href="http://www.bht.co.jp/2008/11/arrayliststring.html" /> <id>tag:www.bht.co.jp,2008://2.16</id> <published>2008-11-17T06:59:59Z</published> <updated>2008-11-17T07:14:46Z</updated> <summary>ArrayListの各要素がStringである場合、これをString配列にしよ...</summary> <author> <name>kazu</name>  </author>  <category term="型" scheme="http://www.sixapart.com/ns/types#category" />   <content type="html" xml:lang="ja" xml:base="http://www.bht.co.jp/"> <![CDATA[<p>ArrayListの各要素がStringである場合、これをString配列にしようとしてCastしてみるとCast Errorになっちゃって、「うわ〜〜〜どないしよ？」なんていう経験ありませんか？</p>
<p>(普通に考えたら、ObjectからStringにしちゃうわけだから、不可能な気もしますが。)</p>
<p>そんなときは、ArrayListに用意されているToArrayメソッドを使って次のようにすると出来ちゃいます。</p>
<MTPrecode>
ArrayList arraylist = new ArrayList();
arraylist.Add("a");
arraylist.Add("b");
arraylist.Add("c");
arraylist.Add("d");
arraylist.Add("e");
String[] stringArray = (String[])arraylist.ToArray(typeof(String));
</MTPrecode>
<p>この例ではArrayListからString配列にしていますが、ArrayListの各要素がint等だったりする場合は、int配列等に変換することができます。</p>]]>  </content></entry><entry> <title>型変換</title> <link rel="alternate" type="text/html" href="http://www.bht.co.jp/2008/11/post-5.html" /> <id>tag:www.bht.co.jp,2008://2.15</id> <published>2008-11-14T05:10:14Z</published> <updated>2008-11-14T05:11:41Z</updated> <summary>型変換の推移図 byte → short → int → long → floa...</summary> <author> <name>satoshi</name>  </author>  <category term="型" scheme="http://www.sixapart.com/ns/types#category" />   <content type="html" xml:lang="ja" xml:base="http://www.bht.co.jp/"> <![CDATA[型変換の推移図<br>
byte → short → int → long → float → double<br>
<br>
矢印の方向に代入すると暗黙的な型変換、矢印と逆方向に代入すると明示的な型変換(キャスト)となります。
<MTPrecode>
// 暗黙的な型変換
int a = 10;
long b = a; // 変数bには、10が入る

// 明示的な型変換(キャスト)
int a = 10;
byte b = (byte)a; // 変数bには、10が入る
</MTPrecode>]]>  </content></entry><entry> <title>DB連携〜（MS SQL Server 対応）</title> <link rel="alternate" type="text/html" href="http://www.bht.co.jp/2008/11/dbms-sql-server.html" /> <id>tag:www.bht.co.jp,2008://2.13</id> <published>2008-11-13T07:51:12Z</published> <updated>2008-11-13T08:42:04Z</updated> <summary>PHP で Microsoft SQL Server を使うための方法について ...</summary> <author> <name>さいとー</name>  </author>  <category term="ＤＢ連携" scheme="http://www.sixapart.com/ns/types#category" />  <category term="phpdbmicrosoftsqlserver" label="PHP DB Microsoft SQL Server" scheme="http://www.sixapart.com/ns/types#tag" />  <content type="html" xml:lang="ja" xml:base="http://www.bht.co.jp/"> <![CDATA[<p>PHP で Microsoft SQL Server を使うための方法について</p>
<p>■概要<br />PHP インストール時に、以下を行う必要がある。<br />・FreeTDS をインストール<br />・PHP を Microsoft SQL Server 対応オプションつきで configure、インストール</p>
<p>以下、それぞれソースからコンパイルする前提で手順を示す。</p>
<p><br />■FreeTDS インストール<br />以下の手順を行う。<br />- ソースの tar ball を取得し、適当な場所に展開。<br />- 展開したディレクトリー下に移動。<br />- ./configure を実行（このときのオプションで SQL Server 対応を指定）。<br />- make を実行。<br />- make install を実行（root 権限で実行する）。</p>
<p>ソースの取得先：<br /><a href="http://www.freetds.org/">http://www.freetds.org/</a></p>
<p>configure 時オプション：<br />-with-tdsver=8.0<br />を指定する必要がある。その他のオプションは必要に応じて。</p>
<p>オペレーション例：<br />% fetch 'http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz'<br />　　：（略）<br />% tar -zxf freetds-stable.tgz<br />% cd freetds-0.63<br />% ./configure -with-tdsver=8.0 --prefix=/usr/local/freetds/063/<br />　　：（略）<br />% make<br />% su<br />Password: （ここでパスワードを入力）<br /># make install<br />　　：（略）<br /># exit<br />% </p>
<p><br />■PHP インストール<br />以下の手順を行う。<br />- ソースの tar ball を取得し、適当な場所に展開。<br />- 展開したディレクトリー下に移動。<br />- ./configure を実行（このときのオプションで freetds〜SQL Server 対応を指定）。<br />- make を実行。<br />- make install を実行（root 権限で実行する）。</p>
<p>ソースの取得先：<br /><a href="http://www.php.net/">http://www.php.net/</a></p>
<p>configure 時オプション：<br />--with-sybase=&lt;freetds インストール先 PATH&gt;<br />を指定する必要がある。その他のオプションは必要に応じて。</p>
<p>オペレーション例：<br />% fetch 'http://br.php.net/distributions/php-5.2.4.tar.bz2'<br />　　：（略）<br />% bzip2 -dc php-5.2.4.tar.bz2 | tar -xf -<br />% cd php-5.2.4<br />% ./configure \<br />--prefix=/usr/local/php/524 \<br />--enable-mbstring \<br />--enable-mbstr-enc-trans \<br />--enable-mbregex \<br />--enable-sockets \<br />--with-mcrypt=/usr/local/lib \<br />--with-sybase=/usr/local/freetds/063 \<br />--enable-zend-multibyte \<br />--enable-inline-optimization \<br />--enable-sigchild \<br />--enable-track-vars \<br />--without-gd \<br />--enable-trans-sid \<br />--with-zlib-dir=/usr/lib \<br />--enable-ftp<br />　　：（略）<br />% make<br />% su<br />Password: （ここでパスワードを入力）<br /># make install<br />　　：（略）<br /># exit<br />% </p>
<p><br />■インストール後設定<br />最低限、FreeTDS の設定で接続先ＤＢの情報を記述する必要がある。<br />具体的には、 &lt;FreeTDS インストール先 PATH&gt;/etc/freetds.conf を編集する。</p>
<p>ファイル中（末尾でよい）に、次の形式で情報を追記する。</p>
<p>[&lt;接続名&gt;]<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; host = &lt;IPアドレス or dns名&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; port = 1433<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tds version = 8.0</p>
<p>記述例：<br />[DUVEL]<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; host = 192.168.0.30<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; port = 1433<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tds version = 8.0</p>
<p><br />■コーディング・実行に関しては、次を参照のこと<br /><a href="http://www.php.net/manual/ja/book.sybase.php">http://www.php.net/manual/ja/book.sybase.php</a></p>
<p>（以上）<br /></p>]]>  </content></entry><entry> <title>文字列中へ変数の値を入れる</title> <link rel="alternate" type="text/html" href="http://www.bht.co.jp/2008/11/post-3.html" /> <id>tag:www.bht.co.jp,2008://2.12</id> <published>2008-11-06T07:05:51Z</published> <updated>2008-11-06T07:13:59Z</updated> <summary>よく使われるStringクラスFormatメソッド。しかし、書き方をいつも忘れる...</summary> <author> <name>satoshi</name>  </author>  <category term="文字列" scheme="http://www.sixapart.com/ns/types#category" />   <content type="html" xml:lang="ja" xml:base="http://www.bht.co.jp/"> <![CDATA[よく使われるStringクラスFormatメソッド。しかし、書き方をいつも忘れるのでいつも調べてます…

<MTPrecode>
int month = 11;
int day = 6;

string test = String.Format("本日は{0}月{1}日です", month, day);
</MTPrecode>

「本日は11月6日です」と表示します。]]>  </content></entry><entry> <title>指定された日付文字列の正当性をチェック</title> <link rel="alternate" type="text/html" href="http://www.bht.co.jp/2008/10/post-2.html" /> <id>tag:www.bht.co.jp,2008://2.11</id> <published>2008-10-30T05:50:23Z</published> <updated>2008-10-30T05:55:26Z</updated> <summary>日付の正当性チェックは様々なやり方があるかと思いますが、ConvertクラスTo...</summary> <author> <name>satoshi</name>  </author>  <category term="日付" scheme="http://www.sixapart.com/ns/types#category" />   <content type="html" xml:lang="ja" xml:base="http://www.bht.co.jp/"> <![CDATA[日付の正当性チェックは様々なやり方があるかと思いますが、ConvertクラスToDateTimeメソッドを使用すると
比較的に簡単にチェックが行えます。

<MTPrecode>
public class Check
{
    public static bool IsDate(string year, string month, string day)
    {
        try
        {
            Convert.ToDateTime(String.Format("{0}/{1}/{2}", year, month, day));
        }
        catch (Exception)
        {
            return false;
        }
        
        return true;
    }
}
</MTPrecode>

// 正しく設定されている日付なので「true」が返ります。<br>
bool test1 = Check.IsDate("2008", "02", "29");<br>
// 正しく設定されていない日付なので「false」が返ります。<br>
bool test2 = Check.IsDate("2008", "02", "30");
]]>  </content></entry><entry> <title>指定された日付からのn日前、n日後を算出</title> <link rel="alternate" type="text/html" href="http://www.bht.co.jp/2008/10/nn.html" /> <id>tag:www.bht.co.jp,2008://2.9</id> <published>2008-10-24T01:33:29Z</published> <updated>2008-10-27T06:02:17Z</updated> <summary>指定された日付文字列（YYYY/mm/dd形式など）から、n日前・n日後を求める...</summary> <author> <name>hiro</name>  </author>  <category term="日付" scheme="http://www.sixapart.com/ns/types#category" />   <content type="html" xml:lang="ja" xml:base="http://www.bht.co.jp/"> <![CDATA[指定された日付文字列（YYYY/mm/dd形式など）から、n日前・n日後を求めるには、以下のようにstrtotime()、date()関数を利用します。

<MTPrecode>
    public static function calDate($date, $num)
    {
        $time = strtotime($date);
        if ($time == false)
            return false;

        $time += $num * (24 * 3600);
        return date('Y/m/d', $time);
    }

    $now = date('Y/m/d');
    echo calDate($now, -3) . ""\n"";    // 3日前を求める
    echo calDate($now, 7 * 3) . ""\n"";    // 3週間後を求める
</MTPrecode>]]>  </content></entry><entry> <title>DataGridでグループ分けされた部分複数行の一覧作成</title> <link rel="alternate" type="text/html" href="http://www.bht.co.jp/2008/10/datagrid.html" /> <id>tag:www.bht.co.jp,2008://2.8</id> <published>2008-10-23T02:36:12Z</published> <updated>2008-10-27T06:25:51Z</updated> <summary>C#では、DataGridを使用することで比較的簡単に一覧を作成できますが、複雑...</summary> <author> <name>jun</name>  </author>  <category term="C#.Net" scheme="http://www.sixapart.com/ns/types#category" />  <category term="DataGrid" scheme="http://www.sixapart.com/ns/types#category" />   <content type="html" xml:lang="ja" xml:base="http://www.bht.co.jp/"> <![CDATA[<p>C#では、DataGridを使用することで比較的簡単に一覧を作成できますが、複雑な一覧の場合には少し工夫が必要になってきます。</p>
<p>以下のコード例では、DataSetの内容の編集、DataGridのデータ連結時処理でのセルの操作でグループ分けされた部分複数行の一覧を作成しています。</p>
<p>まず、DataSetの各行を2行に補正し区切り線用の行を追加します。このメソッドはPage_Loadイベントなどで呼び出します。</p><mtprecode>
    private void SetDataTable()
    {
        // DataTableに各行の値を設定する
        dataSetList.List.AddListRow("1", "1", "TestA", "aaa-1", "bbb-1");
        dataSetList.List.AddListRow("2", "1", "TestB", "aaa-2", "bbb-2");
        dataSetList.List.AddListRow("3", "1", "TestC", "aaa-3", "bbb-3");
        dataSetList.List.AddListRow("4", "2", "TestD", "aaa-4", "bbb-4");
        dataSetList.List.AddListRow("5", "2", "TestE", "aaa-5", "bbb-5");
        dataSetList.List.AddListRow("6", "2", "TestF", "aaa-6", "bbb-6");
        dataSetList.List.AddListRow("7", "3", "TestD", "aaa-7", "bbb-7");
        dataSetList.List.AddListRow("8", "3", "TestE", "aaa-8", "bbb-8");
        dataSetList.List.AddListRow("9", "3", "TestF", "aaa-9", "bbb-9");

        // DatTableの全行を2行にする
        for (int i = 0; i < dataSetList.List.Rows.Count; i++) 
        {
            string id = dataSetList.List.Rows[i]["Id"].ToString();

            DataSetList.ListRow drItem2 = dataSetList.List.NewListRow();

            drItem2["Id"] = ("rows2_" + id);
            drItem2["Group"] = dataSetList.List.Rows[i]["Group"]; 
            drItem2["Name"] = dataSetList.List.Rows[i]["Name"]; 
            drItem2["CodeA"] = dataSetList.List.Rows[i]["CodeA"];
            drItem2["CodeB"] = dataSetList.List.Rows[i]["CodeB"];

            i++;
            dataSetList.List.Rows.InsertAt(drItem2, i);
        }

        // DataTableにグループ分けライン行を追加する
        string wkArea = string.Empty;
        for (int i = 0; i < dataSetList.List.Rows.Count; i++) 
        {
            string group = dataSetList.List.Rows[i]["Group"].ToString();
            string id = dataSetList.List.Rows[i]["Id"].ToString();

            if (wkArea.Equals(string.Empty))
            {
                wkArea = group;
            }
            else if (!wkArea.Equals(group))
            {
                wkArea = group;

                DataSetList.ListRow drLine = dataSetList.List.NewListRow();

                drLine["Id"] = ("line_" + id);
                drLine["Group"] = wkArea; 
                drLine["Name"] = ""; 
                drLine["CodeA"] = ""; 
                drLine["CodeB"] = ""; 

                dataSetList.List.Rows.InsertAt(drLine, i);
                i++;
            }
        }

        // DataTableにヘッダ2行目を追加する
        DataSetList.ListRow drHead2 = dataSetList.List.NewListRow();

        drHead2["Id"] = "head2";
        drHead2["Group"] = ""; 
        drHead2["Name"] = ""; 
        drHead2["CodeA"] = ""; 
        drHead2["CodeB"] = ""; 

        dataSetList.List.Rows.InsertAt(drHead2, 0);

        return;
    }
</mtprecode>
次に、DataGridのデータ連結時処理でセルのRowSpan、Visibleなどを操作します。

<mtprecode>
    private void DataGridList_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
        // ヘッダ1行目を設定する
        if (e.Item.ItemType == ListItemType.Header)
        {
            e.Item.Cells[0].RowSpan = 2;
            e.Item.Cells[1].RowSpan = 2;
            e.Item.Cells[2].RowSpan = 2;
            e.Item.Cells[4].Visible = false;
        }

        if (e.Item.ItemType == ListItemType.Item 
            || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            string id = ((Literal)e.Item.Cells[0].FindControl("dspId")).Text;

            // ヘッダ2行目を設定する
            if (id.Equals("head2"))
            {
                e.Item.Cells[0].Visible = false;
                e.Item.Cells[1].Visible = false;
                e.Item.Cells[2].Visible = false;
                e.Item.Cells[3].Visible = false;
                e.Item.Cells[4].Visible = true;
                e.Item.Cells[4].BackColor = Color.FromName("#C0C0C0");
                ((Literal)e.Item.Cells[4].FindControl("dspCodeB")).Visible = true;
                ((Literal)e.Item.Cells[4].FindControl("dspCodeB")).Text = "CodeB";

                return;
            }

            // グループ分けライン行を設定する
            if (id.StartsWith("line_"))
            {
                e.Item.Cells[1].Visible = false;
                e.Item.Cells[2].Visible = false;
                e.Item.Cells[3].Visible = false;
                e.Item.Cells[4].Visible = false;
                e.Item.Cells[0].ColumnSpan = 5;
                e.Item.Cells[0].Text = "";
                e.Item.Cells[0].BackColor = Color.Red;
                e.Item.Cells[0].Height = 2;

                return;
            }

            // アイテム1行目を設定する
            if (!id.StartsWith("rows2_"))
            {
                e.Item.Cells[0].RowSpan = 2;
                e.Item.Cells[1].RowSpan = 2;
                e.Item.Cells[2].RowSpan = 2;
                e.Item.Cells[4].Visible = false;

                grdIndex++;
            }

            // アイテム2行目を設定する
            if (id.StartsWith("rows2_"))
            {
                e.Item.Cells[0].Visible = false;
                e.Item.Cells[1].Visible = false;
                e.Item.Cells[2].Visible = false;
                e.Item.Cells[3].Visible = false;
                e.Item.Cells[4].Visible = true;
            }
        }

        return;
    }
</mtprecode>

するとこのような一覧が出来上がります。<br>
<span class="mt-enclosure mt-enclosure-image" style="DISPLAY: inline"><img class="mt-image-none" height="672" alt="DataGrid.jpg" src="http://www.bht.co.jp/2008/10/23/jun/DataGrid.jpg" width="488" /></p></span>]]>  </content></entry><entry> <title>指定の長さのランダム文字列生成</title> <link rel="alternate" type="text/html" href="http://www.bht.co.jp/2008/10/post.html" /> <id>tag:www.bht.co.jp,2008://2.7</id> <published>2008-10-23T00:28:27Z</published> <updated>2008-10-27T06:35:46Z</updated> <summary>自動パスワード発行など、ランダム文字列の生成が必要な場面がありますが、現在時刻な...</summary> <author> <name>jun</name>  </author>  <category term="C#.Net" scheme="http://www.sixapart.com/ns/types#category" />  <category term="文字列" scheme="http://www.sixapart.com/ns/types#category" />   <content type="html" xml:lang="ja" xml:base="http://www.bht.co.jp/"> <![CDATA[<p>自動パスワード発行など、ランダム文字列の生成が必要な場面がありますが、現在時刻などを利用した擬似乱数では完全なランダム文字列は生成できません。<br />C#には、暗号化サービス プロバイダ (CSP) という暗号化機能を使用した暗号乱数ジェネレータという便利な機能が用意されています。</p>
<p>以下のコード例では、暗号乱数ジェネレータを使用してパラメータで指定された長さの完全なランダム文字列を生成して返却しています。</p>
<mtprecode>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static string GetRandomValue(int size)<br/>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 使用文字を羅列し変数に格納する<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string　seedValue　=&nbsp;"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // パラメータで指定された長さの乱数を取得する<br/>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; byte[] seedByte = new byte[size];<br/>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; RNGCryptoServiceProvider rngcsp = new RNGCryptoServiceProvider();<br/>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rngcsp.GetNonZeroBytes(seedByte);<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 乱数をもとに使用文字を組み合わせる<br/>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; string returnValue = String.Empty;<br/>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; foreach (int seedNum in seedByte)<br/>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br/>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Random rnd = new Random(seedNum);<br/>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int seedIndex = rnd.Next(seedValue.Length);<br/>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; returnValue += seedValue[seedIndex];<br/>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return returnValue;<br/>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br/>
</mtprecode>]]>  </content></entry></feed>
