#include "wsubformHTML.h"	//サブフォーム専用ヘッダファイルをインクルードする。
#include <fcgi_stdio.h>

extern char gridtitles[MAX_POS][MAX_LEN];	//wsubformHTMLが利用するgridのタイトル。

extern TextBox	 *begin;	//textboxで使用する連鎖ポインタの開始位置
extern TextBox	 *tp;	//textboxで使用する連鎖ポインタ

typedef struct stat Dir;	//ファイル操作用
static Dir dirptr;
static Dir  *fptr = &dirptr;

char tmp[MAX_STR];
static int sqlcode = 0;	//PostgreSQLの返すコード

int DBcount[MAX_FORM];	//wsubformHTMLで利用するDBの現在の最大行数
extern char KEY[256][MAX_STR];	//INSERTとUPDATEが使用する更新項目
extern int IKEY[256];	//INSERTとUPDATEが使用する更新項目
char COMMANDNAME[128];

int DBConnect(void)
{
	// DB接続用変数宣言です。DB名、ユーザ名、パスワードを設定してください。
	EXEC SQL BEGIN DECLARE SECTION;
		char dbname[12];
		char user[12];
		char passwd[12];
	EXEC SQL END DECLARE SECTION;

	strcpy(dbname,"apsch");
	strcpy(user,"cms");
	strcpy(passwd,"cms");

#ifdef DEBUG
	// ECPGデバッグ文出力
	ECPGdebug (0, stderr);
#endif

	// 接続
	memset (sqlca.sqlstate, '0', 5);
	EXEC SQL CONNECT TO :dbname AS dbConnection user :user USING :passwd;
	if (memcmp (sqlca.sqlstate, "00000", 5) != 0)
	{
		sprintf(tmp,"CONNECT エラー。終了します。:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
		exit (EXIT_FAILURE);
	}
}

int Fetch_kokyaku_Fetch(int no)
{
	static char DBbuff[MAX_STR];
	int i = 0;
	char *qs;
	int qcount;

	DBConnect();

	memset (sqlca.sqlstate, '0', 5);

	EXEC SQL BEGIN DECLARE SECTION;
		int rec_count;
		char	 key[256][MAX_STR];
		int		johoID;		//NUMERIC
		char	kokyakuCD[5 + 1];	//TEXT
		int		outaikubunID;		//NUMERIC
		char	shimei[128 + 1];	//TEXT
		char	furigana[156 + 1];	//TEXT
		char	shokugyou[12 + 1];	//TEXT
		char	kaisyamei[64 + 1];	//TEXT
		char	yakushoku[12 + 1];	//TEXT
		char	yubin[7 + 1];	//TEXT
		char	todoufuken[24 + 1];	//TEXT
		char	jusho1[64 + 1];	//TEXT
		char	jusho2[64 + 1];	//TEXT
		char	mail[50 + 1];	//TEXT
		char	kaisyaTEL[13 + 1];	//TEXT
		char	naisenTEL[13 + 1];	//TEXT
		char	FAX[13 + 1];	//TEXT
		char	keitaiTEL[13 + 1];	//TEXT
		char	jitakuTEL[13 + 1];	//TEXT
		unsigned char		insatu;		//BOOL
		unsigned char		henjinashi;		//BOOL
		unsigned char		fumei;		//BOOL
		unsigned char		mocyu;		//BOOL
		char	bikou[1024 + 1];	//TEXT
		char	YahooID[32 + 1];	//TEXT
	EXEC SQL END DECLARE SECTION;

	sqlcode = 0;
	DBcount[no] = 0;

	rec_count = 0;

	if((qs = getenv("QUERY_STRING")) != (char *)NULL)
	{
		qcount = query_getHTML(qs,'&');
		for(i=0;i < qcount;i++)
		{
			sprintf(key[i],"%s",qt.get[i]);
		}
	}
	else
	{
		sprintf(key[0],"NONE");
		printf("%s<br>\n",key[0]);
	}

//	以下の部分はリレーションテーブルを利用する場合にコメントを外して使用可能にして利用してください。
	sprintf(KEY[0],"%s",key[0]);
	sprintf(KEY[1],"%s",key[1]);

	// DBの行数を取得
	EXEC SQL 
	SELECT 
	COUNT(*)
	INTO :rec_count
	FROM	kokyaku
	WHERE kokyakuCD = :key[0];

	// SELECTエラー 
	if(memcmp (sqlca.sqlstate, "00000", 5) != 0)
	{
		sprintf(tmp,"SELECT COUNTエラー:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
		return(-1) ;
	}

	DBcount[no] = rec_count;

	EXEC SQL DECLARE kokyaku_Fetch_CURSOR CURSOR FOR 
	SELECT 
		johoID,
		coalesce(kokyakuCD,' ','0'),
		outaikubunID,
		coalesce(shimei,' ','0'),
		coalesce(furigana,' ','0'),
		coalesce(shokugyou,' ','0'),
		coalesce(kaisyamei,' ','0'),
		coalesce(yakushoku,' ','0'),
		coalesce(yubin,' ','0'),
		coalesce(todoufuken,' ','0'),
		coalesce(jusho1,' ','0'),
		coalesce(jusho2,' ','0'),
		coalesce(mail,' ','0'),
		coalesce(kaisyaTEL,' ','0'),
		coalesce(naisenTEL,' ','0'),
		coalesce(FAX,' ','0'),
		coalesce(keitaiTEL,' ','0'),
		coalesce(jitakuTEL,' ','0'),
		insatu,
		henjinashi,
		fumei,
		mocyu,
		coalesce(bikou,' ','0'),
		coalesce(YahooID,' ','0')
	FROM	kokyaku
	WHERE kokyakuCD = :key[0]
	ORDER BY kokyakuCD;

	// カーソルオープン
	EXEC SQL OPEN kokyaku_Fetch_CURSOR;

	// CURSOR OPENエラー 
	if (memcmp (sqlca.sqlstate, "00000", 5) != 0)
	{
		sprintf(tmp,"CURSOR OPENエラー:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
		return(-1);
	}

	for(i=0;i<DBcount[no];i++)
	{
		EXEC SQL FETCH kokyaku_Fetch_CURSOR INTO
			:johoID,
			:kokyakuCD,
			:outaikubunID,
			:shimei,
			:furigana,
			:shokugyou,
			:kaisyamei,
			:yakushoku,
			:yubin,
			:todoufuken,
			:jusho1,
			:jusho2,
			:mail,
			:kaisyaTEL,
			:naisenTEL,
			:FAX,
			:keitaiTEL,
			:jitakuTEL,
			:insatu,
			:henjinashi,
			:fumei,
			:mocyu,
			:bikou,
			:YahooID;

	// テーブル項目をsplitbDBbuff[][]にセットする
		sf_to_text(johoID,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,0,DBbuff,5 + 1);
		sf_assgetDB(no,i,1,kokyakuCD,5 + 1);
		sf_to_text(outaikubunID,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,2,DBbuff,5 + 1);
		sf_assgetDB(no,i,3,shimei,128 + 1);
		sf_assgetDB(no,i,4,furigana,156 + 1);
		sf_assgetDB(no,i,5,shokugyou,12 + 1);
		sf_assgetDB(no,i,6,kaisyamei,64 + 1);
		sf_assgetDB(no,i,7,yakushoku,12 + 1);
		sf_assgetDB(no,i,8,yubin,7 + 1);
		sf_assgetDB(no,i,9,todoufuken,24 + 1);
		sf_assgetDB(no,i,10,jusho1,64 + 1);
		sf_assgetDB(no,i,11,jusho2,64 + 1);
		sf_assgetDB(no,i,12,mail,50 + 1);
		sf_assgetDB(no,i,13,kaisyaTEL,13 + 1);
		sf_assgetDB(no,i,14,naisenTEL,13 + 1);
		sf_assgetDB(no,i,15,FAX,13 + 1);
		sf_assgetDB(no,i,16,keitaiTEL,13 + 1);
		sf_assgetDB(no,i,17,jitakuTEL,13 + 1);
		sprintf(DBbuff,"%c",insatu);	//BOOL型(unsigned char)を文字に変換する。
		sf_assgetDB(no,i,18,DBbuff,2 + 1);
		sprintf(DBbuff,"%c",henjinashi);	//BOOL型(unsigned char)を文字に変換する。
		sf_assgetDB(no,i,19,DBbuff,2 + 1);
		sprintf(DBbuff,"%c",fumei);	//BOOL型(unsigned char)を文字に変換する。
		sf_assgetDB(no,i,20,DBbuff,2 + 1);
		sprintf(DBbuff,"%c",mocyu);	//BOOL型(unsigned char)を文字に変換する。
		sf_assgetDB(no,i,21,DBbuff,2 + 1);
		sf_assgetDB(no,i,22,bikou,1024 + 1);
		sf_assgetDB(no,i,23,YahooID,32 + 1);

	}
	// カーソルクローズ 
	EXEC SQL CLOSE kokyaku_Fetch_CURSOR;

	DBcount[no] = rec_count;

	// 結果チェック
	if (sqlca.sqlcode == 0)
	{
		sprintf(tmp,"FETCH結果チェック:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
	}
	// 切断
	sqlca.sqlcode = 0;
	EXEC SQL DISCONNECT dbConnection;
	return(0);
}

int Fetch_otodoke(int no)
{
	static char DBbuff[MAX_STR];
	int i = 0;
	char *env1,*env2;

	DBConnect();

	memset (sqlca.sqlstate, '0', 5);

	EXEC SQL BEGIN DECLARE SECTION;
		int rec_count;
		char key[256][MAX_STR];
		int	No;	//NUMERIC
		char	yubinNo[7 + 1];	//TEXT
		char	todofuken[24 + 1];	//TEXT
		char	jusho1[96 + 1];	//TEXT
		char	jusho2[96 + 1];	//TEXT
		char	shimei1[96 + 1];	//TEXT
		char	shimei_f1[192 + 1];	//TEXT
		char	shimei2[96 + 1];	//TEXT
		char	shimei_f2[200 + 1];	//TEXT
		char	TEL[13 + 1];	//TEXT
		char	hinmei[90 + 1];	//TEXT
		int		hinsyu;		//NUMERIC
		char	yoryo[5 + 1];	//TEXT
		char	hm_kubun[2 + 1];	//TEXT
		char	grade[144 + 1];	//TEXT
		char	size[10 + 1];	//TEXT
		int		kingaku;		//NUMERIC
		unsigned char		jikankibou;		//BOOL
		int		takuhai_s;		//NUMERIC
		unsigned char		tuchi;		//BOOL
		char	denNo[13 + 1];	//TEXT
		unsigned char		tokui;		//BOOL
		char	uketukeDATE[10 + 1];	//TEXT
		char	expDATE[10 + 1];	//TEXT
		char	hopeDATE[10 + 1];	//TEXT
		char	bikou[256 + 1];	//TEXT
		char	hassoCD[5 + 1];	//TEXT
		char	hatutenCD[7 + 1];	//TEXT
		unsigned char		hatuEND;		//BOOL
		unsigned char		prEND;		//BOOL
		int		denNUM;		//NUMERIC
		int		hakoNUM;		//NUMERIC
		char	memo[1024 + 1];	//TEXT
		unsigned char		reserve;		//BOOL
		char	resDATE[10 + 1];	//TEXT
		unsigned char		print;		//BOOL
		int		prNUM;		//NUMERIC
		char	daitaiCD[5 + 1];	//TEXT
		unsigned char		daitai;		//BOOL
		char	FAX[13 + 1];	//TEXT
		char	keitaiTEL[13 + 1];	//TEXT
		int		hopeTIME;		//NUMERIC
		int		hopeTIME2;		//NUMERIC
		int		hopeTIME3;		//NUMERIC
		unsigned char		umu;		//BOOL
		int		soryo;		//NUMERIC
		int		hatu_kosuu;		//NUMERIC
		int		hakodai;		//NUMERIC
		char	chitai[60 + 1];	//TEXT
		char	mail[50 + 1];	//TEXT
		int		tesuu;		//NUMERIC
		int		tac;		//NUMERIC
		unsigned char		reitou;		//BOOL
		char	YahooID[32 + 1];	//TEXT
		char	shiwakeCD[13 + 1];	//TEXT
		unsigned char		kariseikyu;		//BOOL
		int		cc_kingaku;		//NUMERIC
		int		st_kingaku;		//NUMERIC
		int		base_soryo;		//NUMERIC
		unsigned char		seikyuEND;		//BOOL
		int		den_hakoNUM;		//NUMERIC
		int		soukin_tesuuryo;		//NUMERIC
	EXEC SQL END DECLARE SECTION;

	sqlcode = 0;
	DBcount[no] = 0;

	rec_count = 0;

	// DBの行数を取得
	EXEC SQL 
	SELECT 
	COUNT(*)
	INTO :rec_count
	FROM	otodoke;

	// SELECTエラー 
	if(memcmp (sqlca.sqlstate, "00000", 5) != 0)
	{
		sprintf(tmp,"SELECT COUNTエラー:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
		return(-1) ;
	}

	DBcount[no] = rec_count;

	EXEC SQL DECLARE otodoke_CURSOR CURSOR FOR 
	SELECT 
		No,
		coalesce(yubinNo,' ','0'),
		coalesce(todofuken,' ','0'),
		coalesce(jusho1,' ','0'),
		coalesce(jusho2,' ','0'),
		coalesce(shimei1,' ','0'),
		coalesce(shimei_f1,' ','0'),
		coalesce(shimei2,' ','0'),
		coalesce(shimei_f2,' ','0'),
		coalesce(TEL,' ','0'),
		coalesce(hinmei,' ','0'),
		hinsyu,
		coalesce(yoryo,' ','0'),
		coalesce(hm_kubun,' ','0'),
		coalesce(grade,' ','0'),
		coalesce(size,' ','0'),
		kingaku,
		jikankibou,
		takuhai_s,
		tuchi,
		coalesce(denNo,' ','0'),
		tokui,
		coalesce(uketukeDATE,' ','0'),
		coalesce(expDATE,' ','0'),
		coalesce(hopeDATE,' ','0'),
		coalesce(bikou,' ','0'),
		coalesce(hassoCD,' ','0'),
		coalesce(hatutenCD,' ','0'),
		hatuEND,
		prEND,
		denNUM,
		hakoNUM,
		coalesce(memo,' ','0'),
		reserve,
		coalesce(resDATE,' ','0'),
		print,
		prNUM,
		coalesce(daitaiCD,' ','0'),
		daitai,
		coalesce(FAX,' ','0'),
		coalesce(keitaiTEL,' ','0'),
		hopeTIME,
		hopeTIME2,
		hopeTIME3,
		umu,
		soryo,
		hatu_kosuu,
		hakodai,
		coalesce(chitai,' ','0'),
		coalesce(mail,' ','0'),
		tesuu,
		tac,
		reitou,
		coalesce(YahooID,' ','0'),
		coalesce(shiwakeCD,' ','0'),
		kariseikyu,
		cc_kingaku,
		st_kingaku,
		base_soryo,
		seikyuEND,
		den_hakoNUM,
		soukin_tesuuryo
	FROM	otodoke
	ORDER BY hassoCD;

	// カーソルオープン
	EXEC SQL OPEN otodoke_CURSOR;

	// CURSOR OPENエラー 
	if (memcmp (sqlca.sqlstate, "00000", 5) != 0)
	{
		sprintf(tmp,"CURSOR OPENエラー:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
		fprintf(stderr,"%s\n",tmp);
	//	logmsg(tmp);
		return(-1);
	}

	printf("Content-type: text/html\n\n");
	printf("<html>\n");
	printf("<head>\n");
	printf("<meta http-equiv=\"content-script-type\" content=\"text/html;charset=utf-8\">\n"); 
	printf("<title>Wsubform-HTML-DBgrid</title>\n");
	printf("</head>\n");
	printf("<body>\n");
	printf("<table border=1>\n");
	printf("<tr bgcolor=\"#ffffff\">\n");
	for(i=0;i<DBcount[no];i++)
	{
		EXEC SQL FETCH otodoke_CURSOR INTO
			:No,
			:yubinNo,
			:todofuken,
			:jusho1,
			:jusho2,
			:shimei1,
			:shimei_f1,
			:shimei2,
			:shimei_f2,
			:TEL,
			:hinmei,
			:hinsyu,
			:yoryo,
			:hm_kubun,
			:grade,
			:size,
			:kingaku,
			:jikankibou,
			:takuhai_s,
			:tuchi,
			:denNo,
			:tokui,
			:uketukeDATE,
			:expDATE,
			:hopeDATE,
			:bikou,
			:hassoCD,
			:hatutenCD,
			:hatuEND,
			:prEND,
			:denNUM,
			:hakoNUM,
			:memo,
			:reserve,
			:resDATE,
			:print,
			:prNUM,
			:daitaiCD,
			:daitai,
			:FAX,
			:keitaiTEL,
			:hopeTIME,
			:hopeTIME2,
			:hopeTIME3,
			:umu,
			:soryo,
			:hatu_kosuu,
			:hakodai,
			:chitai,
			:mail,
			:tesuu,
			:tac,
			:reitou,
			:YahooID,
			:shiwakeCD,
			:kariseikyu,
			:cc_kingaku,
			:st_kingaku,
			:base_soryo,
			:seikyuEND,
			:den_hakoNUM,
			:soukin_tesuuryo;

			//送信はGETを使用します。
		//	printf("<th><form method=\"get\" action=\"/cgi-bin/otodoke_Menu.cgi\">\n");	//メニュー用
			//UPDATEを行うCGIを呼ぶ
			printf("<form method=\"get\" action=\"/cgi-bin/otodoke_Fetch2.fcgi\">\n");
			printf("%d</th>", No);
			printf("<td>%s</td>", yubinNo);
			printf("<td>%s</td>", todofuken);
			printf("<td>%s</td>", jusho1);
			printf("<td>%s</td>", jusho2);
			printf("<td>%s</td>", shimei1);
//				printf("<td>%s</td>", shimei_f1);
//				printf("<td>%s</td>", shimei2);
//				printf("<td>%s</td>", shimei_f2);
//				printf("<td>%s</td>", TEL);
			printf("<td>%s</td>", hinmei);
			printf("<td>%d</td>", hinsyu);
			printf("<td>%s</td>", yoryo);
			printf("<td>%s</td>", hm_kubun);
			printf("<td>%s</td>", grade);
			printf("<td>%s</td>", size);
			printf("<td>%d</td>", kingaku);
//				if(jikankibou == 'f')
//					printf("<td><input type=\"checkbox\" value=\"t\"></td>");
//				else
//					printf("<td><input type=\"checkbox\" value=\"t\" checked></td>");
			printf("<td>%d</td>", takuhai_s);
//				if(tuchi == 'f')
//					printf("<td><input type=\"checkbox\" value=\"t\"></td>");
//				else
//					printf("<td><input type=\"checkbox\" value=\"t\" checked></td>");
//				printf("<td>%s</td>", denNo);
//				if(tokui == 'f')
//					printf("<td><input type=\"checkbox\" value=\"t\"></td>");
//				else
//					printf("<td><input type=\"checkbox\" value=\"t\" checked></td>");
//				printf("<td>%s</td>", uketukeDATE);
			printf("<td>%s</td>", expDATE);
			printf("<td>%s</td>", hopeDATE);
//				printf("<td>%s</td>", bikou);
			printf("<td>%s</td>", hassoCD);
//				printf("<td>%s</td>", hatutenCD);
//				if(hatuEND == 'f')
//					printf("<td><input type=\"checkbox\" value=\"t\"></td>");
//				else
//					printf("<td><input type=\"checkbox\" value=\"t\" checked></td>");
//				if(prEND == 'f')
//					printf("<td><input type=\"checkbox\" value=\"t\"></td>");
//				else
//					printf("<td><input type=\"checkbox\" value=\"t\" checked></td>");
			printf("<td>%d</td>", denNUM);
			printf("<td>%d</td>", hakoNUM);
//				printf("<td>%s</td>", memo);
			if(reserve == 'f')
				printf("<td><input type=\"checkbox\" value=\"t\"></td>");
			else
				printf("<td><input type=\"checkbox\" value=\"t\" checked></td>");
			printf("<td>%s</td>", resDATE);
			if(print == 'f')
				printf("<td><input type=\"checkbox\" value=\"t\"></td>");
			else
				printf("<td><input type=\"checkbox\" value=\"t\" checked></td>");
			printf("<td>%d</td>", prNUM);
			printf("<td>%s</td>", daitaiCD);
			if(daitai == 'f')
				printf("<td><input type=\"checkbox\" value=\"t\"></td>");
			else
				printf("<td><input type=\"checkbox\" value=\"t\" checked></td>");
//				printf("<td>%s</td>", FAX);
//				printf("<td>%s</td>", keitaiTEL);
//				printf("<td>%d</td>", hopeTIME);
			printf("<td>%d</td>", hopeTIME2);
//				printf("<td>%d</td>", hopeTIME3);
//				if(umu == 'f')
//					printf("<td><input type=\"checkbox\" value=\"t\"></td>");
//				else
//					printf("<td><input type=\"checkbox\" value=\"t\" checked></td>");
//				printf("<td>%d</td>", soryo);
//				printf("<td>%d</td>", hatu_kosuu);
//				printf("<td>%d</td>", hakodai);
//				printf("<td>%s</td>", chitai);
//				printf("<td>%s</td>", mail);
//				printf("<td>%d</td>", tesuu);
//				printf("<td>%d</td>", tac);
			if(reitou == 'f')
				printf("<td><input type=\"checkbox\" value=\"t\"></td>");
			else
				printf("<td><input type=\"checkbox\" value=\"t\" checked></td>");
//				printf("<td>%s</td>", YahooID);
//				printf("<td>%s</td>", shiwakeCD);
//				if(kariseikyu == 'f')
//					printf("<td><input type=\"checkbox\" value=\"t\"></td>");
//				else
//					printf("<td><input type=\"checkbox\" value=\"t\" checked></td>");
//				printf("<td>%d</td>", cc_kingaku);
//				printf("<td>%d</td>", st_kingaku);
//				printf("<td>%d</td>", base_soryo);
//				if(seikyuEND == 'f')
//					printf("<td><input type=\"checkbox\" value=\"t\"></td>");
//				else
//					printf("<td><input type=\"checkbox\" value=\"t\" checked></td>");
			printf("<td>%d</td>", den_hakoNUM);
//				printf("<td>%d</td>", soukin_tesuuryo);
			printf("<td><input type=\"submit\" name=\"field\" value=\"%s\"></td>", hassoCD);
			printf("</tr>\n");

		if (memcmp (sqlca.sqlstate, "00000", 5) != 0)
		{
			EXEC SQL CLOSE otodoke_CURSOR;
			sprintf(tmp,"FETCH完了:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
		//	logmsg(tmp);
		}
	}
	printf("</table>\n");
	printf("</body>\n");
	printf("</html>\n\n");
	// カーソルクローズ 
	EXEC SQL CLOSE otodoke_CURSOR;

	DBcount[no] = rec_count;

	// 結果チェック
	if (sqlca.sqlcode == 0)
	{
		env1 = getenv("REMOTE_ADDR");
		env2 = getenv("HTTP_USER_AGENT");
		sprintf(tmp,"%s->FETCH結果チェック:%d - %s:%s:%s",COMMANDNAME,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc,env1,env2);
		logmsg(tmp);
	}
	// 切断
	sqlca.sqlcode = 0;
	EXEC SQL DISCONNECT dbConnection;
	return(0);
}
//---------------------------------------------------

int Fetch_yubin_Menu(int no, int line)
{
	static char DBbuff[MAX_STR];
	int i = 0;
	char *qs;
	int qcount;

	DBConnect();

	memset (sqlca.sqlstate, '0', 5);

	EXEC SQL BEGIN DECLARE SECTION;
		int rec_count;
		char	 key[256][MAX_STR];
		int	 ikey[256];
		char	chiikiCD[5 + 1];	//TEXT
		char	oldNO[5 + 1];	//TEXT
		char	newNO[7 + 1];	//TEXT
		char	kenmei_f[32 + 1];	//TEXT
		char	chikumei_f[128 + 1];	//TEXT
		char	banchikuikimei_f[256 + 1];	//TEXT
		char	kenmei[12 + 1];	//TEXT
		char	chikumeisho[32 + 1];	//TEXT
		char	banchikuikimei[256 + 1];	//TEXT
		int		a;		//NUMERIC
		int		b;		//NUMERIC
		int		c;		//NUMERIC
		int		d;		//NUMERIC
		int		e;		//NUMERIC
		int		f;		//NUMERIC
	EXEC SQL END DECLARE SECTION;

	sqlcode = 0;
	DBcount[no] = 0;

	rec_count = 0;

/*
	if((qs = getenv("QUERY_STRING")) != (char *)NULL)
	{
		qcount = query_getHTML(qs,'&');
		for(i=0;i < qcount;i++)
		{
			sprintf(key[i],"%s",qt.get[i]);
		}
	}
	else
	{
		sprintf(key[0],"NONE");
		printf("%s<br>\n",key[0]);
	}
*/

//	以下の部分はリレーションテーブルを利用する場合にコメントを外して使用可能にして利用してください。
//	sprintf(KEY[0],"%s",key[0]);

//	テーブルを連結して検索する対象は外部変数の場合splitDbbuffからホスト変数にコピーして利用出来ます。
	sprintf(key[0],"%s",ft[1].splitDBbuff[line][1]);
//	sprintf(key[1],"%s",ft[1].splitDBbuff[line][10]);
//	ikey[0] = atoi(key[1]);

	// DBの行数を取得
	EXEC SQL 
	SELECT 
	COUNT(*)
	INTO :rec_count
	FROM	yubin
	WHERE newNO = :key[0];


	// SELECTエラー 
	if(memcmp (sqlca.sqlstate, "00000", 5) != 0)
	{
		sprintf(tmp,"%s->SELECT COUNTエラー:%d - %s",COMMANDNAME,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
		logmsg(tmp);
		return(-1) ;
	}

	DBcount[no] = rec_count;

	// 以下の項目はユニークな項目を利用してインサート時の項目番号等を増加するために利用します
	// 利用する場合はコメントを外して下さい。
	// あるDB項目の最大数を取得
//	if(rec_count == 0)
//	{
//		sprintf(newNO,"%s",key[2]);
//		rec_max = 0;
//		DBcount[no] = 1;
//	}
//	else
//	{
//		EXEC SQL 
//		SELECT 
//		MAX(No)
//		INTO :rec_max
//		FROM	yubin;

//	// SELECTエラー 
//		if(memcmp (sqlca.sqlstate, "00000", 5) != 0)
//		{
//			sprintf(tmp,"%s->SELECT MAX()エラー:%d - %s",COMMANDNAME,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
//		//	logmsg(tmp);
//			return(-1) ;
//		}
//	}

	EXEC SQL DECLARE yubin_Menu_CURSOR CURSOR FOR 
	SELECT 
		coalesce(chiikiCD,' ','0'),
		coalesce(oldNO,' ','0'),
		coalesce(newNO,' ','0'),
		coalesce(kenmei_f,' ','0'),
		coalesce(chikumei_f,' ','0'),
		coalesce(banchikuikimei_f,' ','0'),
		coalesce(kenmei,' ','0'),
		coalesce(chikumeisho,' ','0'),
		coalesce(banchikuikimei,' ','0'),
		a,
		b,
		c,
		d,
		e,
		f
	FROM	yubin
	WHERE newNO = :key[0]
	ORDER BY newNO;

	// カーソルオープン
	EXEC SQL OPEN yubin_Menu_CURSOR;

	// CURSOR OPENエラー 
	if (memcmp (sqlca.sqlstate, "00000", 5) != 0)
	{
		sprintf(tmp,"%s->CURSOR OPENエラー:%d - %s",COMMANDNAME,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
		logmsg(tmp);
		return(-1);
	}

	for(i=0;i<DBcount[no];i++)
	{
		EXEC SQL FETCH yubin_Menu_CURSOR INTO
			:chiikiCD,
			:oldNO,
			:newNO,
			:kenmei_f,
			:chikumei_f,
			:banchikuikimei_f,
			:kenmei,
			:chikumeisho,
			:banchikuikimei,
			:a,
			:b,
			:c,
			:d,
			:e,
			:f;

	// テーブル項目をsplitbDBbuff[][]にセットする
		sf_assgetDB(no,i,0,chiikiCD,5 + 1);
		sf_assgetDB(no,i,1,oldNO,5 + 1);
		sf_assgetDB(no,i,2,newNO,7 + 1);
		sf_assgetDB(no,i,3,kenmei_f,32 + 1);
		sf_assgetDB(no,i,4,chikumei_f,128 + 1);
		sf_assgetDB(no,i,5,banchikuikimei_f,256 + 1);
		sf_assgetDB(no,i,6,kenmei,12 + 1);
		sf_assgetDB(no,i,7,chikumeisho,32 + 1);
		sf_assgetDB(no,i,8,banchikuikimei,256 + 1);
		sf_to_text(a,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,9,DBbuff,2 + 1);
		sf_to_text(b,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,10,DBbuff,2 + 1);
		sf_to_text(c,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,11,DBbuff,2 + 1);
		sf_to_text(d,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,12,DBbuff,2 + 1);
		sf_to_text(e,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,13,DBbuff,2 + 1);
		sf_to_text(f,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,14,DBbuff,2 + 1);

	}
	// カーソルクローズ 
	EXEC SQL CLOSE yubin_Menu_CURSOR;

	DBcount[no] = rec_count;
//logmsg(banchikuikimei);

	// 結果チェック
	if (sqlca.sqlcode == 0)
	{
		sprintf(tmp,"%s->FETCH結果チェック:%d - %s",COMMANDNAME,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
		logmsg(tmp);
	}
	// 切断
	sqlca.sqlcode = 0;
	EXEC SQL DISCONNECT dbConnection;
	return(0);
}

// DBから入出力(画面)ウインドウに書き込みます。
void yubin_Menu_text_writeHTML(int no, int post, int line,int maxcol, char **db_titles)
{
	int i;
	char s[MAX_TMP];

	printf("Content-type: text/html\n\n");
	printf("<html lang=\"ja\">\n");
	printf("<head>\n");
//	printf("<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">\n"); 
	printf("<meta http-equiv=\"content-script-type\" content=\"text/html;charset=utf-8\">\n"); 
	printf("<title>form Menu_text_writeHTML page</title>\n");
	printf("</head>\n");
	printf("<body>\n");
	printf("<br>\n");
	printf("<a href=\"http://sample.net/index.html\" target=\"_parent\">[TOPへ]</a>\n");
	printf("<a href=\"#\" onClick=\"history.back(); return false;\">[前に戻る]</a>\n");
// この下に実行するCGIへのGETメソッドを記述してください。以下がサンプルです。
	//	printf("<form method=\"get\" action=\"/cgi-bin/otodoke_Fetch.fcgi?field=%s\">\n",KEY[0]);
	//	printf("<input type=\"submit\" value=\"更新画面へ\"><br>\n");

	//送信はGETを使用します。
	printf("<form method=\"get\"  action=\"/cgi-bin/yubin.fcgi\">\n");
//	printf("<select name=\"field0\" size=\"8\" maxlength=\"64\"><br>\n");
	printf("<select name=\"field0\" size=\"8\"><br>\n");
	for(i=0;i<DBcount[no];i++)
	{
		printf("<option value=\"%s\"> %s</option>\n",ft[no].splitDBbuff[i][1],ft[no].splitDBbuff[i][1]);
	}
	printf("</select>\n");
	printf("<td><input type=\"submit\" name=\"field\" value=\"%s\"></td>",KEY[1]);
	printf("</form>\n");
}

// FETCHした後にHTMLのテーブルにDBの行列を書き込みます。
int yubin_Menu_grid_dispHTML(int no, int startline, int maxcol, int grid_ey, int grid_sy, int line)
{
	int i, j;
	char s[MAX_TMP];
	char hs[MAX_TMP];

	if((Fetch_yubin_Menu(no,line)) == 0)
	{
		for(i=startline;i<DBcount[no];i++)
		{
			for(j=0;j<maxcol;j++)
			{
				sf_gputDBHTML(no,i,j,startline,s);
			}
		}

		return(0);
	}
	else
	{
		return(-1);
	}
}


int subformHTML_yubin(line)
{
	int i;
	char s[MAX_STR];

	int startline;

//	int line;
	setlocale(LC_ALL,"");

//------------------------------------------------------------------------
//下ののハイフンのラインまでの以下の関数はDBと画面の設計を実際のフォームに適用します。
//これらの関数が無い場合は設計情報はDB設計以外は反映されません。

	static int xcol = 174;
	static int rows = 47;

//for label
	static int label_length[] = {0};
	static int label_no[] = {0};
	static int label_align[] = {0};
	static char *label_text[1][128] = {""};
	static int label_x[] = {0};
	static int label_y[] = {0};
//for textbox
	static int textbox_length[] = {5,5,7,32,64,128,12,32,128,2,2,2,2,2,2,0};
	static int textbox_no[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,0};
	static int textbox_align[] = {2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,0};
	static int textbox_action[] = {0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0};
	static int textbox_skipstep[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0};
	static int textbox_field[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0};
	static int textbox_x[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	static int textbox_y[] = {3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,0};


//for grid
	static int cell_length[] = {5,5,7,15,19,25,10,12,23,2,2,2,2,2,2,0};
	static int cell_align[] = {2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,0};
	static int cell_action[] = {0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0};
	static int grid_field[] = {1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,0};
	static int grid_skipstep[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0};
	char *grid_titles[16][128] = {"Grid_1","Grid_2","Grid_3","Grid_4","Grid_5","Grid_6","Grid_7","Grid_8","Grid_9","Grid_10","Grid_11","Grid_12","Grid_13","Grid_14","Grid_15",""};
	static char *db_titles[16][128] = {"chiikiCD","oldNO","newNO","kenmei_f","chikumei_f","banchikuikimei_f","kenmei","chikumeisho","banchikuikimei","a","b","c","d","e","f",0};
	static int grid_sx = 0;
	static int grid_ex = 146;
	static int grid_sy = 1;
	static int grid_ey = 1;

	static int maxtext;
	static int no = 5;

	char **gt;
	char **lt;

	gt = (char **)&grid_titles;

	xcol = MakeWsubFormHTML(no,xcol,rows,0,2,grid_sx,grid_sy,grid_ex,grid_ey,cell_length,cell_align,cell_action,grid_field,grid_skipstep,gt,15);

	lt = (char **)&label_text;

//	以下の関数は<SELECT>でコンボボックスを作成する場合、一つのCGIで重複して利用出来ませんのでどちらかを削除してください。
//	maxtext = MakeTextBoxHTML(no,0,2,xcol,rows,label_no,lt,label_x,label_y,label_length,textbox_no,textbox_x,textbox_y,textbox_length,textbox_align,textbox_action,textbox_field,textbox_skipstep, 15);

//------------------------------------------------------------------------

	for(i=0;i<MAX_POS;i++)
	{
		memset(gridtitles[i],'\0',MAX_LEN);
	}

	sf_startcell(0);

	startline = 0;	//画面初期行

	if(yubin_Menu_grid_dispHTML(no,startline,maxtext,grid_sy,grid_ey,line) == -1)	//	*splitDBbuff[][]を表示する。
	{
		printf("grid_dispHTML():error\n");
	}

	//DBへのメニュー用フォームの作成（selectタグでコンボボックス連結時この行は削除して利用してください。）
//	yubin_Menu_text_writeHTML(no,0,i,maxtext,*db_titles);
}

//---------------------------------------------

int Fetch_takuhai_gyosya_Menu_Joint(int no, int line)
{
	static char DBbuff[MAX_STR];
	int i = 0;
	char *qs;
	int qcount;

	DBConnect();

	memset (sqlca.sqlstate, '0', 5);

	EXEC SQL BEGIN DECLARE SECTION;
		int rec_count;
		char	 key[256][MAX_STR];
		int	 ikey[256];
		int		ID;		//NUMERIC
		char	takuhai_gyosya[36 + 1];	//TEXT
	EXEC SQL END DECLARE SECTION;

	sqlcode = 0;
	DBcount[no] = 0;

	rec_count = 0;

	if((qs = getenv("QUERY_STRING")) != (char *)NULL)
	{
		qcount = query_getHTML(qs,'&');
		for(i=0;i < qcount;i++)
		{
			sprintf(key[i],"%s",qt.get[i]);
		}
	}
	else
	{
		sprintf(key[0],"NONE");
		printf("%s<br>\n",key[0]);
	}

//	以下の部分はリレーションテーブルを利用する場合にコメントを外して使用可能にして利用してください。
//	sprintf(KEY[0],"%s",key[0]);

//	テーブルを連結して検索する対象は外部変数の場合splitDbbuffからホスト変数にコピーして利用出来ます。
//	sprintf(key[0],"%s",ft[1].splitDBbuff[line][13]);
//	sprintf(key[1],"%s",ft[1].splitDBbuff[line][10]);
//	ikey[0] = atoi(key[1]);

	// DBの行数を取得
	EXEC SQL 
	SELECT 
	COUNT(*)
	INTO :rec_count
	FROM	takuhai_gyosya;
	// SELECTエラー 
	if(memcmp (sqlca.sqlstate, "00000", 5) != 0)
	{
		sprintf(tmp,"%s->SELECT COUNTエラー:%d - %s",COMMANDNAME,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
		return(-1) ;
	}

	DBcount[no] = rec_count;

	EXEC SQL DECLARE takuhai_gyosya_Menu_CURSOR CURSOR FOR 
	SELECT 
		ID,
		coalesce(takuhai_gyosya,' ','0')
	FROM	takuhai_gyosya
	ORDER BY takuhai_gyosya;

	// カーソルオープン
	EXEC SQL OPEN takuhai_gyosya_Menu_CURSOR;

	// CURSOR OPENエラー 
	if (memcmp (sqlca.sqlstate, "00000", 5) != 0)
	{
		sprintf(tmp,"%s->CURSOR OPENエラー:%d - %s",COMMANDNAME,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
		return(-1);
	}

	for(i=0;i<DBcount[no];i++)
	{
		EXEC SQL FETCH takuhai_gyosya_Menu_CURSOR INTO
			:ID,
			:takuhai_gyosya;

	// テーブル項目をsplitbDBbuff[][]にセットする
		sf_to_text(ID,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,0,DBbuff,2 + 1);
		sf_assgetDB(no,i,1,takuhai_gyosya,36 + 1);

	}
	// カーソルクローズ 
	EXEC SQL CLOSE takuhai_gyosya_Menu_CURSOR;

	DBcount[no] = rec_count;

	// 結果チェック
	if (sqlca.sqlcode == 0)
	{
		sprintf(tmp,"%s->FETCH結果チェック:%d - %s",COMMANDNAME,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
	}
	// 切断
	sqlca.sqlcode = 0;
	EXEC SQL DISCONNECT dbConnection;
	return(0);
}

// DBから入出力(画面)ウインドウに書き込みます。
void takuhai_gyosya_Menu_text_writeHTML(int no, int post, int line,int maxcol, char **db_titles)
{
	int i;
	char s[MAX_TMP];

	printf("Content-type: text/html\n\n");
	printf("<html>\n");
	printf("<head>\n");
//	printf("<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">\n"); 
	printf("<meta http-equiv=\"content-script-type\" content=\"text/html;charset=utf-8\">\n"); 
	printf("<title>form Menu_text_writeHTML page</title>\n");
	printf("</head>\n");
	printf("<body>\n");
	printf("<br>\n");
	printf("<a href=\"http://sample.net/index.html\" target=\"_parent\">[TOPへ]</a>\n");
	printf("<a href=\"#\" onClick=\"history.back(); return false;\">[前に戻る]</a>\n");
// この下に実行するCGIへのGETメソッドを記述してください。以下がサンプルです。
	//	printf("<form method=\"get\" action=\"/cgi-bin/otodoke_Fetch.fcgi?field=%s\">\n",KEY[0]);
	//	printf("<input type=\"submit\" value=\"更新画面へ\"><br>\n");

	//送信はGETを使用します。
	printf("<form method=\"get\"  action=\"/cgi-bin/takuhai_gyosya.cgi\">\n");
//	printf("<select name=\"field0\" size=\"8\" maxlength=\"64\"><br>\n");
	printf("<select name=\"field0\" size=\"8\"><br>\n");
	for(i=0;i<DBcount[no];i++)
	{
		printf("<option value=\"%s\"> %s</option>\n",ft[no].splitDBbuff[i][1],ft[no].splitDBbuff[i][1]);
	}
	printf("</select>\n");
	printf("<td><input type=\"submit\" name=\"field\" value=\"%s\"></td>",KEY[1]);
	printf("</form>\n");
}

// FETCHした後にHTMLのテーブルにDBの行列を書き込みます。
int takuhai_gyosya_Menu_grid_dispHTML_Joint(int no, int startline, int maxcol, int grid_ey, int grid_sy, int line)
{
	int i, j;
	char s[MAX_TMP];
	char hs[MAX_TMP];

	if((Fetch_takuhai_gyosya_Menu_Joint(no,line)) == 0)
	{
		for(i=startline;i<DBcount[no];i++)
		{
			for(j=0;j<maxcol;j++)
			{
				sf_gputDBHTML(no,i,j,startline,s);
			}
		}

		return(0);
	}
	else
	{
		return(-1);
	}
}


int subformHTML_takuhai_gyosya_Joint(void)
{
	int i;
	char s[MAX_STR];

	int startline;

	int line;
	setlocale(LC_ALL,"");

//------------------------------------------------------------------------
//下ののハイフンのラインまでの以下の関数はDBと画面の設計を実際のフォームに適用します。
//これらの関数が無い場合は設計情報はDB設計以外は反映されません。

	static int xcol = 173;
	static int rows = 49;

//for label
	static int label_length[] = {0};
	static int label_no[] = {0};
	static int label_align[] = {0};
	static char *label_text[1][128] = {""};
	static int label_x[] = {0};
	static int label_y[] = {0};
//for textbox
	static int textbox_length[] = {2,35,0};
	static int textbox_no[] = {0,1,0};
	static int textbox_align[] = {1,2,0};
	static int textbox_action[] = {0,0,0};
	static int textbox_skipstep[] = {1,1,0};
	static int textbox_field[] = {1,1,0};
	static int textbox_x[] = {0,0,0};
	static int textbox_y[] = {3,4,0};


//for grid
	static int cell_length[] = {2,36,0};
	static int cell_align[] = {1,2,0};
	static int cell_action[] = {0,0,0};
	static int grid_field[] = {2,1,0};
	static int grid_skipstep[] = {1,1,0};
	char *grid_titles[3][128] = {"Grid_1","Grid_2",""};
	static char *db_titles[3][128] = {"ID","takuhai_gyosya",0};
	static int grid_sx = 0;
	static int grid_ex = 38;
	static int grid_sy = 1;
	static int grid_ey = 1;

	static int maxtext;
	static int no = 4;

	char **gt;
	char **lt;

	gt = (char **)&grid_titles;

	xcol = MakeWsubFormHTML(no,xcol,rows,0,2,grid_sx,grid_sy,grid_ex,grid_ey,cell_length,cell_align,cell_action,grid_field,grid_skipstep,gt,2);

	lt = (char **)&label_text;

//	以下の関数は<SELECT>でコンボボックスを作成する場合、一つのCGIで重複して利用出来ませんのでどちらかを削除してください。
//	maxtext = MakeTextBoxHTML(no,0,2,xcol,rows,label_no,lt,label_x,label_y,label_length,textbox_no,textbox_x,textbox_y,textbox_length,textbox_align,textbox_action,textbox_field,textbox_skipstep, 2);

//------------------------------------------------------------------------

	for(i=0;i<MAX_POS;i++)
	{
		memset(gridtitles[i],'\0',MAX_LEN);
	}

	sf_startcell(0);

	startline = 0;	//画面初期行

	if(takuhai_gyosya_Menu_grid_dispHTML_Joint(no,startline,maxtext,grid_sy,grid_ey,line) == -1)	//	*splitDBbuff[][]を表示する。
	{
		printf("grid_dispHTML():error\n");
	}

	//DBへのメニュー用フォームの作成（selectタグでコンボボックス連結時この行は削除して利用してください。）
//	takuhai_gyosya_Menu_text_writeHTML(no,0,i,maxtext,*db_titles);
}

//---------------------------------------------

int Fetch_meishokubun_Menu2_Joint(int no, int line)
{
	static char DBbuff[MAX_STR];
	int i = 0;
	char *qs;
	int qcount;

	DBConnect();

	memset (sqlca.sqlstate, '0', 5);

	EXEC SQL BEGIN DECLARE SECTION;
		int rec_count;
		char	 key[256][MAX_STR];
		char	meishokubun[2 + 1];	//TEXT
		int		edaban;		//NUMERIC
		char	meisho[90 + 1];	//TEXT
	EXEC SQL END DECLARE SECTION;

	sqlcode = 0;
	DBcount[no] = 0;

	rec_count = 0;

/*
	if((qs = getenv("QUERY_STRING")) != (char *)NULL)
	{
		qcount = query_getHTML(qs,'&');
		for(i=0;i < qcount;i++)
		{
			sprintf(key[i],"%s",qt.get[i]);
		}
	}
	else
	{
		sprintf(key[0],"NONE");
		printf("%s<br>\n",key[0]);
	}
*/

//	以下の部分はリレーションテーブルを利用する場合にコメントを外して使用可能にして利用してください。
//	sprintf(KEY[0],"%s",key[0]);
	sprintf(key[0],"%s",ft[1].splitDBbuff[line][10]);

	// DBの行数を取得
	EXEC SQL 
	SELECT 
	COUNT(*)
	INTO :rec_count
	FROM	meishokubun
	WHERE meisho = :key[0];

	// SELECTエラー 
	if(memcmp (sqlca.sqlstate, "00000", 5) != 0)
	{
		sprintf(tmp,"SELECT COUNTエラー:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
		return(-1) ;
	}

	DBcount[no] = rec_count;

	EXEC SQL DECLARE meishokubun_Menu2_CURSOR_JOINT CURSOR FOR 
	SELECT 
		coalesce(meishokubun,' ','0'),
		edaban,
		coalesce(meisho,' ','0')
	FROM	meishokubun
	WHERE meisho = :key[0]
	ORDER BY meishokubun;

	// カーソルオープン
	EXEC SQL OPEN meishokubun_Menu2_CURSOR_JOINT;

	// CURSOR OPENエラー 
	if (memcmp (sqlca.sqlstate, "00000", 5) != 0)
	{
		sprintf(tmp,"CURSOR OPENエラー:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
		return(-1);
	}

	for(i=0;i<DBcount[no];i++)
	{
		EXEC SQL FETCH meishokubun_Menu2_CURSOR_JOINT INTO
			:meishokubun,
			:edaban,
			:meisho;

	// テーブル項目をsplitbDBbuff[][]にセットする
		sf_assgetDB(no,i,0,meishokubun,2 + 1);
		sf_to_text(edaban,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,1,DBbuff,4 + 1);
		sf_assgetDB(no,i,2,meisho,90 + 1);

	}
	// カーソルクローズ 
	EXEC SQL CLOSE meishokubun_Menu2_CURSOR_JOINT;

	DBcount[no] = rec_count;

	// 結果チェック
	if (sqlca.sqlcode == 0)
	{
		sprintf(tmp,"FETCH結果チェック:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
	}
	// 切断
	sqlca.sqlcode = 0;
	EXEC SQL DISCONNECT dbConnection;
	return(0);
}

// FETCHした後にHTMLのテーブルにDBの行列を書き込みます。
int meishokubun_Menu_grid_dispHTML_Joint(int no, int startline, int maxcol, int grid_ey, int grid_sy,int line)
{
	int i, j;
	char s[MAX_TMP];
	char hs[MAX_TMP];

	if((Fetch_meishokubun_Menu2_Joint(no,line)) == 0)
	{
		for(i=startline;i<DBcount[no];i++)
		{
			for(j=0;j<maxcol;j++)
			{
				sf_gputDBHTML(no,i,j,startline,s);
			}
		}

		return(0);
	}
	else
	{
		return(-1);
	}
}


int subformHTML_meishokubun_Joint(int line)
{
	int i;
	char s[MAX_STR];

	int startline;

	setlocale(LC_ALL,"");

//------------------------------------------------------------------------
//下ののハイフンのラインまでの以下の関数はDBと画面の設計を実際のフォームに適用します。
//これらの関数が無い場合は設計情報はDB設計以外は反映されません。

	static int xcol = 172;
	static int rows = 47;

//for label
	static int label_length[] = {0};
	static int label_no[] = {0};
	static int label_align[] = {0};
	static char *label_text[1][128] = {""};
	static int label_x[] = {0};
	static int label_y[] = {0};
//for textbox
	static int textbox_length[] = {2,4,91,0};
	static int textbox_no[] = {0,1,2,0};
	static int textbox_align[] = {2,1,2,0};
	static int textbox_action[] = {0,0,0,0};
	static int textbox_skipstep[] = {1,1,1,0};
	static int textbox_field[] = {1,2,1,0};
	static int textbox_x[] = {0,0,0,0};
	static int textbox_y[] = {3,4,5,0};


//for grid
	static int cell_length[] = {2,4,91,0};
	static int cell_align[] = {2,1,2,0};
	static int cell_action[] = {0,0,0,0};
	static int grid_field[] = {1,2,1,0};
	static int grid_skipstep[] = {1,1,1,0};
	char *grid_titles[4][128] = {"Grid_1","Grid_2","Grid_3",""};
	static char *db_titles[4][128] = {"meishokubun","edaban","meisho",0};
	static int grid_sx = 0;
	static int grid_ex = 98;
	static int grid_sy = 1;
	static int grid_ey = 1;

	static int maxtext;
	static int no = 4;

	char **gt;
	char **lt;

	gt = (char **)&grid_titles;

	xcol = MakeWsubFormHTML(no,xcol,rows,0,2,grid_sx,grid_sy,grid_ex,grid_ey,cell_length,cell_align,cell_action,grid_field,grid_skipstep,gt,3);

	lt = (char **)&label_text;

//	以下の関数は<SELECT>でコンボボックスを作成する場合、一つのCGIで重複して利用出来ませんのでどちらかを削除してください。
//	maxtext = MakeTextBoxHTML(no,0,2,xcol,rows,label_no,lt,label_x,label_y,label_length,textbox_no,textbox_x,textbox_y,textbox_length,textbox_align,textbox_action,textbox_field,textbox_skipstep, 3);

//------------------------------------------------------------------------

	for(i=0;i<MAX_POS;i++)
	{
		memset(gridtitles[i],'\0',MAX_LEN);
	}

	sf_startcell(0);

	startline = 0;	//画面初期行

	if(meishokubun_Menu_grid_dispHTML_Joint(no,startline,maxtext,grid_sy,grid_ey,line) == -1)	//	*splitDBbuff[][]を表示する。
	{
		printf("grid_dispHTML():error\n");
	}

	//DBへのメニュー用フォームの作成
//	meishokubun_Menu_text_writeHTML(no,0,i,maxtext,*db_titles);
}

int Fetch_meishokubun_Menu(int no)
{
	static char DBbuff[MAX_STR];
	int i = 0;
	char *qs;
	int qcount;

	DBConnect();

	memset (sqlca.sqlstate, '0', 5);

	EXEC SQL BEGIN DECLARE SECTION;
		int rec_count;
		char	 key[256][MAX_STR];
		char	meishokubun[2 + 1];	//TEXT
		int		edaban;		//NUMERIC
		char	meisho[90 + 1];	//TEXT
	EXEC SQL END DECLARE SECTION;

	sqlcode = 0;
	DBcount[no] = 0;

	rec_count = 0;

/*
	if((qs = getenv("QUERY_STRING")) != (char *)NULL)
	{
		qcount = query_getHTML(qs,'&');
		for(i=0;i < qcount;i++)
		{
			sprintf(key[i],"%s",qt.get[i]);
		}
	}
	else
	{
		sprintf(key[0],"NONE");
		printf("%s<br>\n",key[0]);
	}
*/

//	以下の部分はリレーションテーブルを利用する場合にコメントを外して使用可能にして利用してください。
//	sprintf(KEY[0],"%s",key[0]);

	// DBの行数を取得
	EXEC SQL 
	SELECT 
	COUNT(*)
	INTO :rec_count
	FROM	meishokubun;

	// SELECTエラー 
	if(memcmp (sqlca.sqlstate, "00000", 5) != 0)
	{
		sprintf(tmp,"SELECT COUNTエラー:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
		return(-1) ;
	}

	DBcount[no] = rec_count;

	EXEC SQL DECLARE meishokubun_Menu_CURSOR CURSOR FOR 
	SELECT 
		coalesce(meishokubun,' ','0'),
		edaban,
		coalesce(meisho,' ','0')
	FROM	meishokubun
	ORDER BY meishokubun;

	// カーソルオープン
	EXEC SQL OPEN meishokubun_Menu_CURSOR;

	// CURSOR OPENエラー 
	if (memcmp (sqlca.sqlstate, "00000", 5) != 0)
	{
		sprintf(tmp,"CURSOR OPENエラー:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
		return(-1);
	}

	for(i=0;i<DBcount[no];i++)
	{
		EXEC SQL FETCH meishokubun_Menu_CURSOR INTO
			:meishokubun,
			:edaban,
			:meisho;

	// テーブル項目をsplitbDBbuff[][]にセットする
		sf_assgetDB(no,i,0,meishokubun,2 + 1);
		sf_to_text(edaban,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,1,DBbuff,4 + 1);
		sf_assgetDB(no,i,2,meisho,90 + 1);

	}
	// カーソルクローズ 
	EXEC SQL CLOSE meishokubun_Menu_CURSOR;

	DBcount[no] = rec_count;

	// 結果チェック
	if (sqlca.sqlcode == 0)
	{
		sprintf(tmp,"FETCH結果チェック:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
	}
	// 切断
	sqlca.sqlcode = 0;
	EXEC SQL DISCONNECT dbConnection;
	return(0);
}

// DBから入出力(画面)ウインドウに書き込みます。
void meishokubun_Menu_text_writeHTML(int no, int post, int line,int maxcol, char **db_titles)
{
	int i;
	char s[MAX_TMP];

	printf("Content-type: text/html\n\n");
	printf("<html>\n");
	printf("<head>\n");
//	printf("<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">\n"); 
	printf("<meta http-equiv=\"content-script-type\" content=\"text/html;charset=utf-8\">\n"); 
	printf("<title>form Menu_text_writeHTML page</title>\n");
	printf("</head>\n");
	printf("<body>\n");
	printf("<br>\n");
	printf("<a href=\"#\" onClick=\"history.back(); return false;\">戻る</a>\n");
	//送信はGETを使用します。
	printf("<form method=\"get\"  action=\"/cgi-bin/meishokubun.cgi\">\n");
//	printf("<select name=\"field0\" size=\"8\" maxlength=\"64\"><br>\n");
	printf("<select name=\"field0\" size=\"8\"><br>\n");
	for(i=0;i<DBcount[no];i++)
	{
		printf("<option value=\"%s\"> %s\n",ft[no].splitDBbuff[i][1],ft[no].splitDBbuff[i][1]);
	}
	printf("</select>\n");
	printf("<td><input type=\"submit\" name=\"field\" value=\"%s\"></td>",KEY[1]);
	printf("</form>\n");
}

// FETCHした後にHTMLのテーブルにDBの行列を書き込みます。
int meishokubun_Menu_grid_dispHTML(int no, int startline, int maxcol, int grid_ey, int grid_sy)
{
	int i, j;
	char s[MAX_TMP];
	char hs[MAX_TMP];

	if((Fetch_meishokubun_Menu(no)) == 0)
	{
		for(i=startline;i<DBcount[no];i++)
		{
			for(j=0;j<maxcol;j++)
			{
				sf_gputDBHTML(no,i,j,startline,s);
			}
		}

		return(0);
	}
	else
	{
		return(-1);
	}
}


int subformHTML_meishokubun(void)
{
	int i;
	char s[MAX_STR];

	int startline;

	int line;
	setlocale(LC_ALL,"");

//------------------------------------------------------------------------
//下ののハイフンのラインまでの以下の関数はDBと画面の設計を実際のフォームに適用します。
//これらの関数が無い場合は設計情報はDB設計以外は反映されません。

	static int xcol = 172;
	static int rows = 47;

//for label
	static int label_length[] = {0};
	static int label_no[] = {0};
	static int label_align[] = {0};
	static char *label_text[1][128] = {""};
	static int label_x[] = {0};
	static int label_y[] = {0};
//for textbox
	static int textbox_length[] = {2,4,91,0};
	static int textbox_no[] = {0,1,2,0};
	static int textbox_align[] = {2,1,2,0};
	static int textbox_action[] = {0,0,0,0};
	static int textbox_skipstep[] = {1,1,1,0};
	static int textbox_field[] = {1,2,1,0};
	static int textbox_x[] = {0,0,0,0};
	static int textbox_y[] = {3,4,5,0};


//for grid
	static int cell_length[] = {2,4,91,0};
	static int cell_align[] = {2,1,2,0};
	static int cell_action[] = {0,0,0,0};
	static int grid_field[] = {1,2,1,0};
	static int grid_skipstep[] = {1,1,1,0};
	char *grid_titles[4][128] = {"Grid_1","Grid_2","Grid_3",""};
	static char *db_titles[4][128] = {"meishokubun","edaban","meisho",0};
	static int grid_sx = 0;
	static int grid_ex = 98;
	static int grid_sy = 1;
	static int grid_ey = 1;

	static int maxtext;
	static int no = 3;

	char **gt;
	char **lt;

	gt = (char **)&grid_titles;

	xcol = MakeWsubFormHTML(no,xcol,rows,0,2,grid_sx,grid_sy,grid_ex,grid_ey,cell_length,cell_align,cell_action,grid_field,grid_skipstep,gt,3);

	lt = (char **)&label_text;

//	以下の関数は<SELECT>でコンボボックスを作成する場合、一つのCGIで重複して利用出来ませんのでどちらかを削除してください。
//	maxtext = MakeTextBoxHTML(no,0,2,xcol,rows,label_no,lt,label_x,label_y,label_length,textbox_no,textbox_x,textbox_y,textbox_length,textbox_align,textbox_action,textbox_field,textbox_skipstep, 3);

//------------------------------------------------------------------------

	for(i=0;i<MAX_POS;i++)
	{
		memset(gridtitles[i],'\0',MAX_LEN);
	}

	sf_startcell(0);

	startline = 0;	//画面初期行

	if(meishokubun_Menu_grid_dispHTML(no,startline,maxtext,grid_sy,grid_ey) == -1)	//	*splitDBbuff[][]を表示する。
	{
		printf("grid_dispHTML():error\n");
	}

	//DBへのメニュー用フォームの作成
//	meishokubun_Menu_text_writeHTML(no,0,i,maxtext,*db_titles);
}

int Fetch_grade_Fetch(int no, int line)
{
	static char DBbuff[MAX_STR];
	int i = 0;
	char *qs;
	int qcount;
	char *env1,*env2;

	DBConnect();

	memset (sqlca.sqlstate, '0', 5);

	EXEC SQL BEGIN DECLARE SECTION;
		int rec_count;
		char	 key[256][MAX_STR];
		int		No;		//NUMERIC
		char	toukyu[144 + 1];	//TEXT
		char	meisho_kubun[2 + 1];	//TEXT
		int		meisho_eda;		//NUMERIC
		char	yoryo[5 + 1];	//TEXT
		char	size[10 + 1];	//TEXT
		int		kingaku;		//NUMERIC
	EXEC SQL END DECLARE SECTION;

	sqlcode = 0;
	DBcount[2] = 0;

	rec_count = 0;

	/*
	if((qs = getenv("QUERY_STRING")) != (char *)NULL)
	{
		qcount = query_getHTML(qs,'&');
		for(i=0;i < qcount;i++)
		{
			sprintf(key[i],"%s",qt.get[i]);
		}
	}
	else
	{
		sprintf(key[0],"NONE");
		printf("%s<br>\n",key[0]);
	}
	*/

	//検索する対象は外部変数の場合splitDbbuffからホスト変数にコピーして利用しなければならない。
	sprintf(key[0],"%s",ft[1].splitDBbuff[0][13]);

	// DBの行数を取得
	EXEC SQL 
	SELECT 
	COUNT(*)
	INTO :rec_count
	FROM	grade;
//	WHERE meisho_kubun = :key[0];

	// SELECTエラー 
	if(memcmp (sqlca.sqlstate, "00000", 5) != 0)
	{
		sprintf(tmp,"SELECT COUNTエラー:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
		return(-1) ;
	}

	DBcount[2] = rec_count;

	EXEC SQL DECLARE grade_Fetch_CURSOR CURSOR FOR 
	SELECT 
		No,
		coalesce(toukyu,' ','0'),
		coalesce(meisho_kubun,' ','0'),
		meisho_eda,
		coalesce(yoryo,' ','0'),
		coalesce(size,' ','0'),
		kingaku
	FROM	grade
	ORDER BY No;

//	WHERE meisho_kubun = :key[0]

	// カーソルオープン
	EXEC SQL OPEN grade_Fetch_CURSOR;

	// CURSOR OPENエラー 
	if (memcmp (sqlca.sqlstate, "00000", 5) != 0)
	{
		sprintf(tmp,"CURSOR OPENエラー:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
		return(-1);
	}

	for(i=0;i<DBcount[2];i++)
	{
		EXEC SQL FETCH grade_Fetch_CURSOR INTO
			:No,
			:toukyu,
			:meisho_kubun,
			:meisho_eda,
			:yoryo,
			:size,
			:kingaku;

	// テーブル項目をsplitbDBbuff[][]にセットする
		sf_to_text(No,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,0,DBbuff,5 + 1);
		sf_assgetDB(no,i,1,toukyu,144 + 1);
		sf_assgetDB(no,i,2,meisho_kubun,2 + 1);
		sf_to_text(meisho_eda,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,3,DBbuff,4 + 1);
		sf_assgetDB(no,i,4,yoryo,5 + 1);
		sf_assgetDB(no,i,5,size,10 + 1);
		sf_to_text(kingaku,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,6,DBbuff,16 + 1);

	}
	// カーソルクローズ 
	EXEC SQL CLOSE grade_Fetch_CURSOR;

	DBcount[2] = rec_count;

	// 結果チェック
	if (sqlca.sqlcode == 0)
	{
		env1 = getenv("REMOTE_ADDR");
		env2 = getenv("HTTP_USER_AGENT");
		sprintf(tmp,"%s->FETCH結果チェック:%d - %s:%s:%s",COMMANDNAME,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc,env1,env2);
		logmsg(tmp);
	}
	// 切断
	sqlca.sqlcode = 0;
	EXEC SQL DISCONNECT dbConnection;
	return(0);
}

int Fetch_grade_Fetch_Joint(int no, int line)
{
	static char DBbuff[MAX_STR];
	int i = 0;
	char *qs;
	int qcount;

	DBConnect();

	memset (sqlca.sqlstate, '0', 5);

	EXEC SQL BEGIN DECLARE SECTION;
		int rec_count;
		char	 key[256][MAX_STR];
		int	 ikey[256];
		int		No;		//NUMERIC
		char	toukyu[144 + 1];	//TEXT
		char	meisho_kubun[2 + 1];	//TEXT
		int		meisho_eda;		//NUMERIC
		char	yoryo[5 + 1];	//TEXT
		char	size[10 + 1];	//TEXT
		int		kingaku;		//NUMERIC
	EXEC SQL END DECLARE SECTION;

	sqlcode = 0;
	DBcount[2] = 0;

	rec_count = 0;

	/*
	if((qs = getenv("QUERY_STRING")) != (char *)NULL)
	{
		qcount = query_getHTML(qs,'&');
		for(i=0;i < qcount;i++)
		{
			sprintf(key[i],"%s",qt.get[i]);
		}
	}
	else
	{
		sprintf(key[0],"NONE");
		printf("%s<br>\n",key[0]);
	}
	*/

	//検索する対象は外部変数の場合splitDbbuffからホスト変数にコピーして利用しなければならない。
	//otodokeテーブルの11番配列の項目つまりHINSYUをキー配列ゼロ番にコピーする
	sprintf(key[0],"%s",ft[1].splitDBbuff[line][11]);
	//otodokeテーブルの１３番配列の項目つまりHM_KUBUNをキー配列１番にコピーする
	sprintf(key[1],"%s",ft[1].splitDBbuff[line][13]);
	//HINSYUは数値なので数値用キーに変換する
	ikey[0] = atoi(key[0]);
//logmsg(key[1]);

	// DBの行数を取得
	EXEC SQL 
	SELECT 
	COUNT(*)
	INTO :rec_count
	FROM	grade
	WHERE meisho_kubun = :key[1] AND meisho_eda = :ikey[0];

	// SELECTエラー 
	if(memcmp (sqlca.sqlstate, "00000", 5) != 0)
	{
		sprintf(tmp,"SELECT COUNTエラー:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
		return(-1) ;
	}

	DBcount[2] = rec_count;

	EXEC SQL DECLARE grade_Fetch_CURSOR_JOINT CURSOR FOR 
	SELECT 
		No,
		coalesce(toukyu,' ','0'),
		coalesce(meisho_kubun,' ','0'),
		meisho_eda,
		coalesce(yoryo,' ','0'),
		coalesce(size,' ','0'),
		kingaku
	FROM	grade
	WHERE meisho_kubun = :key[1] AND meisho_eda = :ikey[0]
	ORDER BY No;


	// カーソルオープン
	EXEC SQL OPEN grade_Fetch_CURSOR_JOINT;

	// CURSOR OPENエラー 
	if (memcmp (sqlca.sqlstate, "00000", 5) != 0)
	{
		sprintf(tmp,"CURSOR OPENエラー:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
		return(-1);
	}

	for(i=0;i<DBcount[2];i++)
	{
		EXEC SQL FETCH grade_Fetch_CURSOR_JOINT INTO
			:No,
			:toukyu,
			:meisho_kubun,
			:meisho_eda,
			:yoryo,
			:size,
			:kingaku;

	// テーブル項目をsplitbDBbuff[][]にセットする
		sf_to_text(No,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,0,DBbuff,5 + 1);
		sf_assgetDB(no,i,1,toukyu,144 + 1);
		sf_assgetDB(no,i,2,meisho_kubun,2 + 1);
		sf_to_text(meisho_eda,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,3,DBbuff,4 + 1);
		sf_assgetDB(no,i,4,yoryo,5 + 1);
		sf_assgetDB(no,i,5,size,10 + 1);
		sf_to_text(kingaku,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,6,DBbuff,16 + 1);

	}
	// カーソルクローズ 
	EXEC SQL CLOSE grade_Fetch_CURSOR_JOINT;

	DBcount[2] = rec_count;

	// 結果チェック
	if (sqlca.sqlcode == 0)
	{
		sprintf(tmp,"FETCH結果チェック:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
	}
	// 切断
	sqlca.sqlcode = 0;
	EXEC SQL DISCONNECT dbConnection;
	return(0);
}

// FETCHした後にHTMLのテーブルにDBの行列を書き込みます。
int grade_Fetch_grid_dispHTML(int no, int startline, int maxcol, int grid_ey, int grid_sy, int line)
{
	int i, j;
	char s[MAX_TMP];
	char hs[MAX_TMP];

	if((Fetch_grade_Fetch(no,line) == 0))
	{
		for(i=startline;i<DBcount[1];i++)
		{
			for(j=0;j<maxcol;j++)
			{
				sf_gputDBHTML(no,i,j,startline,s);
			}
		}

		return(0);
	}
	else
	{
		return(-1);
	}
}

// FETCHした後にHTMLのテーブルにDBの行列を書き込みます。
int grade_Fetch_grid_dispHTML_Joint(int no, int startline, int maxcol, int grid_ey, int grid_sy, int line)
{
	int i, j;
	char s[MAX_TMP];
	char hs[MAX_TMP];

	if((Fetch_grade_Fetch_Joint(no,line) == 0))
	{
		for(i=startline;i<DBcount[1];i++)
		{
			for(j=0;j<maxcol;j++)
			{
				sf_gputDBHTML(no,i,j,startline,s);
			}
		}

		return(0);
	}
	else
	{
		return(-1);
	}
}


int subformHTML_grade(int joint, int line)
{
	int i;
	char s[MAX_STR];

	int startline;

	setlocale(LC_ALL,"");

//------------------------------------------------------------------------
//下ののハイフンのラインまでの以下の関数はDBと画面の設計を実際のフォームに適用します。
//これらの関数が無い場合は設計情報はDB設計以外は反映されません。

	static int xcol = 174;
	static int rows = 48;

//for label
	static int label_length[] = {0};
	static int label_no[] = {0};
	static int label_align[] = {0};
	static char *label_text[1][128] = {""};
	static int label_x[] = {0};
	static int label_y[] = {0};
//for textbox
	static int textbox_length[] = {3,144,2,2,6,10,16,0};
	static int textbox_no[] = {0,1,2,3,4,5,6,0};
	static int textbox_align[] = {1,2,2,2,2,2,1,0};
	static int textbox_action[] = {0,0,0,0,0,0,0,0};
	static int textbox_skipstep[] = {1,1,1,1,1,1,1,0};
	static int textbox_field[] = {2,1,1,2,1,1,4,0};
	static int textbox_x[] = {0,0,0,0,0,0,0,0};
	static int textbox_y[] = {3,4,5,6,7,8,9,0};


//for grid
	static int cell_length[] = {5,17,2,4,5,11,16,0};
	static int cell_align[] = {1,2,2,2,2,2,1,0};
	static int cell_action[] = {0,0,0,0,0,0,0,0};
	static int grid_field[] = {2,1,1,2,1,1,4,0};
	static int grid_skipstep[] = {1,1,1,1,1,1,1,0};
	char *grid_titles[8][128] = {"Grid_1","Grid_2","Grid_3","Grid_4","Grid_5","Grid_6","Grid_7",""};
	static char *db_titles[8][128] = {"No","toukyu","meisho_kubun","meisho_eda","yoryo","size","kingaku",0};
	static int grid_sx = 0;
	static int grid_ex = 65;
	static int grid_sy = 1;
	static int grid_ey = 1;

	static int maxtext;
	static int no = 2;

	char **gt;
	char **lt;

	gt = (char **)&grid_titles;

	xcol = MakeWsubFormHTML(no,xcol,rows,0,2,grid_sx,grid_sy,grid_ex,grid_ey,cell_length,cell_align,cell_action,grid_field,grid_skipstep,gt,7);

//	lt = (char **)&label_text;

//	maxtext = MakeTextBoxHTML(no,0,2,xcol,rows,label_no,lt,label_x,label_y,label_length,textbox_no,textbox_x,textbox_y,textbox_length,textbox_align,textbox_action,textbox_field,textbox_skipstep, 7);

//------------------------------------------------------------------------

	for(i=0;i<MAX_POS;i++)
	{
		memset(gridtitles[i],'\0',MAX_LEN);
	}

	sf_startcell(no);

	startline = 0;	//画面初期行

	if(joint)
	{
		if(grade_Fetch_grid_dispHTML_Joint(no,startline,maxtext,grid_sy,grid_ey,line) == -1)	//	*splitDBbuff[][]を表示する。
		{
			printf("grid_dispHTML():error\n");
		}
	}
	else
	{
		if(grade_Fetch_grid_dispHTML(no,startline,maxtext,grid_sy,grid_ey,line) == -1)	//	*splitDBbuff[][]を表示する。
		{
			printf("grid_dispHTML():error\n");
		}
	}

}

int Fetch_otodoke_Fetch2(int no)
{
	static char DBbuff[MAX_STR];
	int i = 0;
	char *qs;
	int qcount;
	char *env1,*env2;

	DBConnect();

	memset (sqlca.sqlstate, '0', 5);

	EXEC SQL BEGIN DECLARE SECTION;
		int rec_count;
		char	 key[256][MAX_STR];
		int	No;	//TEXT
		char	yubinNo[7 + 1];	//TEXT
		char	todofuken[24 + 1];	//TEXT
		char	jusho1[96 + 1];	//TEXT
		char	jusho2[96 + 1];	//TEXT
		char	shimei1[96 + 1];	//TEXT
		char	hinmei[90 + 1];	//TEXT
		int		hinsyu;		//NUMERIC
		char	yoryo[5 + 1];	//TEXT
		char	hm_kubun[2 + 1];	//TEXT
		char	grade[144 + 1];	//TEXT
		char	size[10 + 1];	//TEXT
		int		kingaku;		//NUMERIC
		int		takuhai_s;		//NUMERIC
		char	expDATE[10 + 1];	//TEXT
		char	hopeDATE[10 + 1];	//TEXT
		char	hassoCD[5 + 1];	//TEXT
		unsigned char		hatuEND;		//BOOL
		int		denNUM;		//NUMERIC
		int		hakoNUM;		//NUMERIC
		unsigned char		reserve;		//BOOL
		char	resDATE[10 + 1];	//TEXT
		unsigned char		print;		//BOOL
		int		prNUM;		//NUMERIC
		char	daitaiCD[5 + 1];	//TEXT
		unsigned char		daitai;		//BOOL
		int		hopeTIME2;		//NUMERIC
		unsigned char		reitou;		//BOOL
		int		den_hakoNUM;		//NUMERIC
	EXEC SQL END DECLARE SECTION;

	sqlcode = 0;
	DBcount[no] = 0;

	rec_count = 0;

	if((qs = getenv("QUERY_STRING")) != (char *)NULL)
	{
		qcount = query_getHTML(qs,'&');
		for(i=0;i < qcount;i++)
		{
			sprintf(key[i],"%s",qt.get[i]);
		}
	}
	else
	{
		sprintf(key[0],"NONE");
		printf("%s<br>\n",key[0]);
	}

//	以下の部分はリレーションテーブルを利用する場合にコメントを外して使用可能にして利用してください。
//	sprintf(KEY[0],"%s",key[0]);

	// DBの行数を取得
	EXEC SQL 
	SELECT 
	COUNT(*)
	INTO :rec_count
	FROM	otodoke
	WHERE hassoCD = :key[0];

	// SELECTエラー 
	if(memcmp (sqlca.sqlstate, "00000", 5) != 0)
	{
		sprintf(tmp,"SELECT COUNTエラー:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
		return(-1) ;
	}

	DBcount[no] = rec_count;

	EXEC SQL DECLARE otodoke_Fetch2_CURSOR CURSOR FOR 
	SELECT 
		No,
		coalesce(yubinNo,' ','0'),
		coalesce(todofuken,' ','0'),
		coalesce(jusho1,' ','0'),
		coalesce(jusho2,' ','0'),
		coalesce(shimei1,' ','0'),
		coalesce(hinmei,' ','0'),
		hinsyu,
		coalesce(yoryo,' ','0'),
		coalesce(hm_kubun,' ','0'),
		coalesce(grade,' ','0'),
		coalesce(size,' ','0'),
		kingaku,
		takuhai_s,
		coalesce(expDATE,' ','0'),
		coalesce(hopeDATE,' ','0'),
		coalesce(hassoCD,' ','0'),
		hatuEND,
		denNUM,
		hakoNUM,
		reserve,
		coalesce(resDATE,' ','0'),
		print,
		prNUM,
		coalesce(daitaiCD,' ','0'),
		daitai,
		hopeTIME2,
		reitou,
		den_hakoNUM
	FROM	otodoke
	WHERE hassoCD = :key[0]
	ORDER BY No;

	// カーソルオープン
	EXEC SQL OPEN otodoke_Fetch2_CURSOR;

	// CURSOR OPENエラー 
	if (memcmp (sqlca.sqlstate, "00000", 5) != 0)
	{
		sprintf(tmp,"CURSOR OPENエラー:%d - %s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
	//	logmsg(tmp);
		return(-1);
	}

	for(i=0;i<DBcount[no];i++)
	{
		EXEC SQL FETCH otodoke_Fetch2_CURSOR INTO
			:No,
			:yubinNo,
			:todofuken,
			:jusho1,
			:jusho2,
			:shimei1,
			:hinmei,
			:hinsyu,
			:yoryo,
			:hm_kubun,
			:grade,
			:size,
			:kingaku,
			:takuhai_s,
			:expDATE,
			:hopeDATE,
			:hassoCD,
			:hatuEND,
			:denNUM,
			:hakoNUM,
			:reserve,
			:resDATE,
			:print,
			:prNUM,
			:daitaiCD,
			:daitai,
			:hopeTIME2,
			:reitou,
			:den_hakoNUM;

	// テーブル項目をsplitbDBbuff[][]にセットする
		sf_to_text(No,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,0,DBbuff,5 + 1);
		sf_assgetDB(no,i,1,yubinNo,7 + 1);
		sf_assgetDB(no,i,2,todofuken,24 + 1);
		sf_assgetDB(no,i,3,jusho1,96 + 1);
		sf_assgetDB(no,i,4,jusho2,96 + 1);
		sf_assgetDB(no,i,5,shimei1,96 + 1);
		sf_assgetDB(no,i,10,hinmei,90 + 1);
		sf_to_text(hinsyu,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,11,DBbuff,3 + 1);
		sf_assgetDB(no,i,12,yoryo,5 + 1);
		sf_assgetDB(no,i,13,hm_kubun,2 + 1);
		sf_assgetDB(no,i,14,grade,144 + 1);
		sf_assgetDB(no,i,15,size,10 + 1);
		sf_to_text(kingaku,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,16,DBbuff,5 + 1);
		sf_to_text(takuhai_s,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,18,DBbuff,3 + 1);
		sf_assgetDB(no,i,23,expDATE,10 + 1);
		sf_assgetDB(no,i,24,hopeDATE,10 + 1);
		sf_assgetDB(no,i,26,hassoCD,5 + 1);
		sprintf(DBbuff,"%c",hatuEND);	//BOOL型(unsigned char)を文字に変換する。
		sf_assgetDB(no,i,28,DBbuff,2 + 1);
		sf_to_text(denNUM,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,30,DBbuff,3 + 1);
		sf_to_text(hakoNUM,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,31,DBbuff,3 + 1);
		sprintf(DBbuff,"%c",reserve);	//BOOL型(unsigned char)を文字に変換する。
		sf_assgetDB(no,i,33,DBbuff,2 + 1);
		sf_assgetDB(no,i,34,resDATE,10 + 1);
		sprintf(DBbuff,"%c",print);	//BOOL型(unsigned char)を文字に変換する。
		sf_assgetDB(no,i,35,DBbuff,2 + 1);
		sf_to_text(prNUM,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,36,DBbuff,3 + 1);
		sf_assgetDB(no,i,37,daitaiCD,5 + 1);
		sprintf(DBbuff,"%c",daitai);	//BOOL型(unsigned char)を文字に変換する。
		sf_assgetDB(no,i,38,DBbuff,2 + 1);
		sf_to_text(hopeTIME2,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,42,DBbuff,2 + 1);
		sprintf(DBbuff,"%c",reitou);	//BOOL型(unsigned char)を文字に変換する。
		sf_assgetDB(no,i,52,DBbuff,2 + 1);
		sf_to_text(den_hakoNUM,DBbuff);	//NUMERIC型(int)を文字に変換する。
		sf_assgetDB(no,i,60,DBbuff,3 + 1);

	}
	// カーソルクローズ 
	EXEC SQL CLOSE otodoke_Fetch2_CURSOR;

	DBcount[no] = rec_count;

	// 結果チェック
	if (sqlca.sqlcode == 0)
	{
		env1 = getenv("REMOTE_ADDR");
		env2 = getenv("HTTP_USER_AGENT");
		sprintf(tmp,"%s->FETCH結果チェック:%d - %s:%s:%s",COMMANDNAME,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc,env1,env2);
		logmsg(tmp);
	}
	// 切断
	sqlca.sqlcode = 0;
	EXEC SQL DISCONNECT dbConnection;
	return(0);
}

// DBから入出力(画面)ウインドウに書き込みます。
void otodoke_Fetch2_text_writeHTML(int no, int post, int line,int maxcol, char **db_titles)
{
	int i;
	int j;
	int k;
	int x;
	char s[MAX_TMP];

//	printf("Content-type: text/html\n\n");
//	printf("<html>\n");
//	printf("<head>\n");
//	printf("<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">\n"); 
//	printf("<meta http-equiv=\"content-script-type\" content=\"text/html;charset=utf-8\">\n"); 
//	printf("<title>form text_writeHTML page</title>\n");
//	printf("</head>\n");
//	printf("<body>\n");
//	printf("<br>\n");
//	printf("<table border=0>\n");
//	printf("<tr bgcolor=\"#ffffff\">\n");

//	printf("<table border=0 width=1400>\n");
//	printf("<tr bgcolor=\"#ffffff\">\n");

//	printf("<td>%05d</td>\n",line+1);
	printf("%05d\n",line+1);
	printf("<hr size=\"3\" color=\"#000000\">");
	printf("<a name=\"form%05d\"></a>\n",line);

	printf("<form name=\"menu\" action=\"\">\n");
	printf("<a href=\"http://codoo2hk.corede.net/takuhai/takuhai.html\" target=\"_parent\">[TOPへ]</a>\n");
	printf("<a href=\"#\" onClick=\"window.top()\">[画面TOPへ]</a>\n");
	printf("<a href=\"#\" onClick=\"history.back(); return false;\">[前に戻る]</a>\n");
	printf("</form>\n");

	printf("<form name=\"delete\" method=\"post\"  action=\"/cgi-bin/otodoke_Delete.fcgi?field000=%s&amp;field01=%s\">\n",KEY[0],ft[no].splitDBbuff[line][0]);
	printf("<input type=\"submit\" value=\"お届け先削除\">\n",line);
	printf("</form>\n");

	printf("<form name=\"insert\" method=\"post\" action=\"/cgi-bin/otodoke_Fetch.fcgi?field00=%s&amp;field01=%s\">\n",KEY[0],ft[no].splitDBbuff[line][0]);
	printf("<input type=\"submit\" value=\"お届け先追加画面へ\">\n");
	printf("</form>\n");

//	printf("<form name=\"update\" method=\"post\" action=\"/cgi-bin/otodoke_Fetch_all.fcgi?field00=%s&amp;field01=%s&amp;field02=%05d\">\n",KEY[0],ft[no].splitDBbuff[line][0],line);
	printf("<form name=\"update\" method=\"post\" action=\"/cgi-bin/otodoke_Fetch_all.fcgi?field00=%s&amp;field01=%s&amp;field02=%05d\">\n",KEY[0],ft[no].splitDBbuff[line][0],line);
	printf("<input type=\"submit\" value=\"お届け先更新画面へ\">\n");
	printf("</form>\n");

//テーブル名_Menu.pgc のコードを利用する場合、デバッグ時の送信試験はGETを使用すると便利です。
	//送信はPOSTを使用します。
	printf("<form name=\"form%05d\" method=\"post\" action=\"/cgi-bin/otodoke_Update2.fcgi\">\n",line);
	printf("<input type=\"reset\" value=\"元に戻す\">\n");
	printf("<input type=\"submit\" value=\"お届け先更新\" onclick=\"submit%d()\"><br>\n",line);

//	printf("</tr>\n");

//	printf("<table border=0 width=1400>\n");
//	printf("<tr bgcolor=\"#ffffff\">\n");

	k = 0;
	sf_tbegin();
	for(i=0;tp->next !=(TextBox *)NULL;i++)
	{
		if(ft[no].splitDBbuff[line][i] != (char *)NULL)
		{
			switch(ft[no].pos[i].ftype)
			{
			case TEXT:
				if(ft[no].pos[i].stype == 1)
				{
				if(ft[no].pos[i].action == 0)
				{
//以下の部分はコンボボックスを定義する場合に利用して下さい。その場合 テーブル名_Menu.pgc のコードを利用します。
//テーブル名_Menu.pgc のコードはMakeTextBox()の関数呼び出しを省いて利用してください。
//連結先のDBcount[フォーム番号]は必ず確認してください。
					switch(i)
					{
/*
				//	郵便番号
					case 1:
						printf("%s:",*(db_titles+i));
						subformHTML_yubin(line);
//printf("<script language=\"JavaScript\" type=\"text/javascript\">\n\n");
printf("<script type=\"text/javascript\">\n\n");
printf("<!--\n");
printf("function MkArray2(n)\n");
printf("{\n");
printf("	this.length = n;\n");
printf("	for (var i=1;i<=n;i++)\n");
printf("	{\n");
printf("		this[i] = 0\n");
printf("		return this\n");
printf("	}\n");
printf("}\n");

printf("function change_yubin%d()\n",line);
printf("{\n");
printf("	var index1 = 0;\n");
printf("	var index2 = 0;\n");
printf("	var index3 = 0;\n");
printf("	s1 = new MkArray2(%d);\n",DBcount[5]);
printf("	s2 = new MkArray2(%d);\n",DBcount[5]);
printf("	s3 = new MkArray2(%d);\n",DBcount[5]);
			for(x=0;x<DBcount[5];x++)
			{
				printf("		s1[%d] = \"%s\";\n",x,ft[5].splitDBbuff[x][6]);
				printf("		s2[%d] = \"%s\";\n",x,ft[5].splitDBbuff[x][7]);
				printf("		s3[%d] = \"%s\";\n",x,ft[5].splitDBbuff[x][8]);
			}
printf("	document.form%05d.field%02d.value = s1[%d];\n",line,2,line);
printf("	document.form%05d.field%02d.value = s2[%d] + s3[%d];\n",line,3,line,3);
//printf("	alert(document.form%05d.field%02d.value);\n",line,3);
printf("	alert(s1[%d]);\n",line);
printf("	alert(s2[%d]);\n",line);
printf("	alert(s3[%d]);\n",line);
printf("}\n");
printf("-->\n");
printf("</script>\n\n");
						printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\"  onchange=\"change_yubin%d()\">\n",k,k,ft[no].pos[i].len/2,ft[no].splitDBbuff[line][i],ft[no].pos[i].len,line);
						break;
*/
				//	品名
					case 10:
						printf("%s:",*(db_titles+i));
//ここにフォーム毎に実行するJavaScriptを記述します。
//printf("<script language=\"JavaScript\" type=\"text/javascript\">\n\n");
printf("<script type=\"text/javascript\">\n\n");
printf("<!--\n");
printf("function submit%d()\n",line);
printf("{\n");
printf("	document.form%05d.tmp.value = \"%05d\";\n",line,line);
printf("}\n");
printf("\n");

/*
printf("function MkArray(n)\n");
printf("{\n");
printf("	this.length = n;\n");
printf("	for (var i=1;i<=n;i++)\n");
printf("	{\n");
printf("		this[i] = 0\n");
printf("		return this\n");
printf("	}\n");
printf("}\n");
*/

printf("function select_1st%d()\n",line);
printf("{\n");
printf("	var index1 = 0;\n");
printf("	var index2 = 0;\n");
printf("	s1 = new MkArray(%d);\n",DBcount[3]);
printf("	s2 = new MkArray(%d);\n",DBcount[3]);
			for(x=0;x<DBcount[3];x++)
			{
				printf("		s1[%d] = \"%s\";\n",x,ft[3].splitDBbuff[x][1]);
				printf("		s2[%d] = \"%s\";\n",x,ft[3].splitDBbuff[x][0]);
			}
printf("	index1 = document.form%05d.field%02d.selectedIndex;\n",line,k);
printf("	index2 = document.form%05d.field%02d.selectedIndex;\n",line,k);
//printf("	alert(document.form%05d.field%02d.selectedIndex);\n",line,k);
printf("	document.form%05d.field%02d.value = s1[index1-1];\n",line,k+1);
printf("	document.form%05d.field%02d.value = s2[index2-1];\n",line,k+3);
printf("	submit%d();\n",line);
printf("	document.form%05d.submit();\n",line);
printf("}\n");
printf("function select_2nd%d()\n",line);
printf("{\n");
printf("	submit%d();\n",line);
printf("	document.form%05d.submit();\n",line);
printf("}\n");
printf("\n");
//printf("//-->\n");
printf("-->\n");
printf("</script>\n\n");
						printf("<select name=\"field%02d\" size=\"1\" onchange=\"select_1st%d()\">\n",k,line);
					//	printf("<select name=\"field%02d\" size=\"1\" maxlength=\"64\">\n",k);
					//	printf("<option value=\"選択なし\" maxlength=\"%d\">選択なし</option>\n",ft[no].pos[i].len);
					//	printf("<option value=\"\" maxlength=\"%d\">選択なし</option>\n",ft[no].pos[i].len);
						printf("<option value=\"\">選択なし</option>\n");
						//テーブルmeisho_kubunnを全件検索する
						for(j=0;j<DBcount[3];j++)
						{
							//otodokeテーブルの"hinmei"項目と一致するmeishokubunテーブルの2番項目(meisho)をselectする
							if(!strcmp(ft[no].splitDBbuff[line][i],ft[3].splitDBbuff[j][2]))
								printf("<option value=\"%s\" selected> %s</option>\n",ft[3].splitDBbuff[j][2],ft[3].splitDBbuff[j][2]);
							else
								printf("<option value=\"%s\"> %s</option>\n",ft[3].splitDBbuff[j][2],ft[3].splitDBbuff[j][2]);
						}
						printf("</select>\n");
						break;
					case 3:
				//	住所１
						printf("%s:",*(db_titles+i));
						printf("<input accesskey=\"C\" tabindex=\"%d\"  type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\">\n",k,k,ft[no].pos[i].len/2,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
						break;
					case 4:
				//	住所２
						printf("%s:",*(db_titles+i));
						printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\"><br>\n",k,k,ft[no].pos[i].len/2,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
						break;
					case 5:
				//	氏名１
						printf("%s:",*(db_titles+i));
						printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\">\n",k,k,ft[no].pos[i].len/3,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
						break;
					/*
					case 11:
				//	品種
						printf("%s:",*(db_titles+i));
						printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"hidden\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
					//	printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
						break;
						*/
					case 13: case 26:
				//	品名区分 発送元CD
					//	printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"hidden\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
						printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
						break;
					case 14:
				//	グレード
					subformHTML_grade(1,line);
//ここにフォーム毎に実行するJavaScriptを記述します。
//printf("<script language=\"JavaScript\" type=\"text/javascript\">\n\n");
printf("<script type=\"text/javascript\">\n\n");
printf("<!--\n");
printf("function submit%d()\n",line);
printf("{\n");
printf("	document.form%05d.tmp.value = \"%05d\";\n",line,line);
printf("}\n");
printf("\n");

/*
printf("function MkArray(n)\n");
printf("{\n");
printf("	this.length = n;\n");
printf("	for (var i=1;i<=n;i++)\n");
printf("	{\n");
printf("		this[i] = 0\n");
printf("		return this\n");
printf("	}\n");
printf("}\n");
*/
printf("function select_grade%d()\n",line);
printf("{\n");
printf("	var index1 = 0;\n");
printf("	var index2 = 0;\n");
printf("	var index3 = 0;\n");
printf("	s1 = new MkArray(%d);\n",DBcount[2]);
printf("	s2 = new MkArray(%d);\n",DBcount[2]);
printf("	s3 = new MkArray(%d);\n",DBcount[2]);
			for(x=0;x<DBcount[2];x++)
			{
				printf("		s1[%d] = \"%s\";\n",x,ft[2].splitDBbuff[x][4]);
				printf("		s2[%d] = \"%s\";\n",x,ft[2].splitDBbuff[x][5]);
				printf("		s3[%d] = \"%s\";\n",x,ft[2].splitDBbuff[x][6]);
			}
printf("	index1 = document.form%05d.field%02d.selectedIndex;\n",line,k);
printf("	index2 = document.form%05d.field%02d.selectedIndex;\n",line,k);
printf("	index3 = document.form%05d.field%02d.selectedIndex;\n",line,k);
//printf("//	alert(document.form%05d.field%02d.selectedIndex);\n",line,k);
printf("	document.form%05d.field%02d.value = s1[index1-1];\n",line,k-2);
printf("	document.form%05d.field%02d.value = s2[index2-1];\n",line,k+1);
printf("	document.form%05d.field%02d.value = s3[index3-1];\n",line,k+2);
//printf("//	submit%d();\n",line);
//printf("//	document.form%05d.submit();\n",line);
printf("}\n");
printf("function select_3rd%d()\n",line);
printf("{\n");
printf("	submit%d();\n",line);
printf("	document.form%05d.submit();\n",line);
printf("}\n");
printf("\n");
//printf("//-->\n");
printf("-->\n");
printf("</script>\n\n");
						printf("%s:",*(db_titles+i));
						//(1)UPDATEを実行するsubmitを実行するJavaScriptをselect項目の変更によって実行する
						printf("<select name=\"field%02d\" size=\"1\" onchange=\"select_grade%d()\">\n",k,line);
					//	printf("<select name=\"field%02d\" size=\"1\"  maxlength=\"%d\">\n",k,ft[no].pos[i].len);

						//(2)otodokeテーブルの"hm_kubun"項目及び"hinsyu"項目と一致するgradeテーブルを検索する
						subformHTML_grade(1,line);
					//	printf("<option value=\"\" maxlength=\"%d\">選択なし</option>\n",ft[no].pos[i].len);
						printf("<option value=\"\">選択なし</option>\n");
						//(3) (2)で検索されたgradeテーブルから適合した2番項目(meisho_kubun)をselectedし、表示は1番項目の(toukyu)で行う
						for(j=0;j<DBcount[2];j++)
						{
							if(!strcmp(ft[no].splitDBbuff[line][i],ft[2].splitDBbuff[j][1]))
							{
								printf("<option value=\"%s\" selected>%s</option>\n",ft[2].splitDBbuff[j][1],ft[2].splitDBbuff[j][1]);
							}
							else
							{
								printf("<option value=\"%s\">%s</option>\n",ft[2].splitDBbuff[j][1],ft[2].splitDBbuff[j][1]);
							}
						}
						printf("</select>\n");
						break;

					default:
						printf("%s:",*(db_titles+i));
						printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
				//	printf("<input type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" >\n",k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
						break;
					}
				}
				else
				{
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" readonly >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
				}
					k++;
				}
				break;
			case DATE:
				if(ft[no].pos[i].stype == 1)
				{
					printf("%s:",*(db_titles+i));
				if(ft[no].pos[i].action == 0)
				{
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
				}
				else
				{
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" readonly >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
				}
					k++;
				}
				break;
			case NUMERIC:
				if(ft[no].pos[i].stype == 1)
				{
				if(ft[no].pos[i].action == 0)
				{
					switch(i)
					{
					case 11:
				//	品種
					//	printf("%s:",*(db_titles+i));
						printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"hidden\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
						break;
					case 18:
				//	宅配業者
						printf("%s:",*(db_titles+i));
						printf("<select name=\"field%02d\" size=\"1\">\n",k);
					//	printf("<option value=\"\" maxlength=\"%d\">選択なし</option>\n",ft[no].pos[i].len);
						printf("<option value=\"\">選択なし</option>\n");
						for(j=0;j<DBcount[4];j++)
						{
							if(!strcmp(ft[no].splitDBbuff[line][i],ft[4].splitDBbuff[j][0]))
							{
								printf("<option value=\"%s\" selected>%s</option>\n",ft[4].splitDBbuff[j][0],ft[4].splitDBbuff[j][1]);
							}
							else
							{
								printf("<option value=\"%s\">%s</option>\n",ft[4].splitDBbuff[j][0],ft[4].splitDBbuff[j][1]);
							}
						}
						printf("</select><br>\n");
						break;
					case 30: case 60:
						printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"hidden\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
						break;
					default:
						printf("%s:",*(db_titles+i));
						printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
						break;
					}
				}
				else
				{
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" readonly >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
				}
					k++;
				}
				break;
			case BOOL:
				if(ft[no].pos[i].stype == 1)
				{
					printf("%s:",*(db_titles+i));
				if(ft[no].pos[i].action == 0)
				{
					if(ft[no].splitDBbuff[line][i][0] == 'f')
						printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"checkbox\" name=\"field%02d\" size=\"%d\" value=\"t\">\n",k,k,ft[no].pos[i].len);
					else
						printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"checkbox\" name=\"field%02d\" size=\"%d\" value=\"%s\" checked>\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i]);
				//	printf("<input type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"1\">\n",k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i]);
				}
				else
				{
				//この部分はチェックボックスに使用出来ますが更新や追加には使用出来ません。表示のみに利用可能です。
					if(ft[no].splitDBbuff[line][i][0] == 'f')
						printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"checkbox\" name=\"field%02d\" size=\"%d\" value=\"%s\" readonly>\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i]);
					else
						printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"checkbox\" name=\"field%02d\" size=\"%d\" value=\"%s\" checked readonly>\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i]);
				//	printf("<input type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"1\" readonly>\n",k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i]);
				}
					k++;
				}
				break;
			case CURRENCY:
				if(ft[no].pos[i].stype == 1)
				{
					printf("%s:",*(db_titles+i));
				if(ft[no].pos[i].action == 0)
				{
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"15\" >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i]);
				}
				else
				{
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"15\" readonly >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i]);
				}
					k++;
				}
				break;
			case DOUBLE:
				if(ft[no].pos[i].stype == 1)
				{
					printf("%s:",*(db_titles+i));
				if(ft[no].pos[i].action == 0)
				{
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%s\" >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
				}
				else
				{
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%s\" readonly >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
				}
					k++;
				}
				break;
			default:
				if(ft[no].pos[i].stype == 1)
				{
					printf("%s:",*(db_titles+i));
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i]);
					k++;
				}
				break;
			}
		//	sprintf(s,"%s",ft[no].splitDBbuff[line][i]);
		//	sf_tput(no,k,s);
			sf_tnext();
		}
		else
		{
			sf_tnext();
		}
	}
	if(ft[no].splitDBbuff[line][i] != (char *)NULL)
	{
		switch(ft[no].pos[i].ftype)
		{
		case TEXT:
			if(ft[no].pos[i].stype == 1)
			{
				printf("%s:",*(db_titles+i));
			if(ft[no].pos[i].action == 0)
			{
//以下の部分はコンボボックスを定義する場合に利用して下さい。その場合 テーブル名_Menu.pgc のコードを利用します。
//テーブル名_Menu.pgc のコードはMakeTextBox()の関数呼び出しを省いて利用してください。
//連結先のDBcount[フォーム番号]は必ず確認してください。
			//	品名
				switch(i)
				{
				case 10:
					printf("%s:",*(db_titles+i));
//ここにフォーム毎に実行するJavaScriptを記述します。
//printf("<script language=\"JavaScript\" type=\"text/javascript\">\n\n");
printf("<script type=\"text/javascript\">\n\n");
printf("<!--\n");
printf("function submit%d()\n",line);
printf("{\n");
printf("	document.form%05d.tmp.value = \"%05d\";\n",line,line);
printf("}\n");
printf("\n");

/*
printf("function MkArray(n)\n");
printf("{\n");
printf("	this.length = n;\n");
printf("	for (var i=1;i<=n;i++)\n");
printf("	{\n");
printf("		this[i] = 0\n");
printf("		return this\n");
printf("	}\n");
printf("}\n");
*/
printf("function select_1st%d()\n",line);
printf("{\n");
printf("	var index1 = 0;\n");
printf("	var index2 = 0;\n");
printf("	s1 = new MkArray(%d);\n",DBcount[3]);
printf("	s2 = new MkArray(%d);\n",DBcount[3]);
			for(x=0;x<DBcount[3];x++)
			{
				printf("		s1[%d] = \"%s\";\n",x,ft[3].splitDBbuff[x][1]);
				printf("		s2[%d] = \"%s\";\n",x,ft[3].splitDBbuff[x][0]);
			}
printf("	index1 = document.form%05d.field%02d.selectedIndex;\n",line,k);
printf("	index2 = document.form%05d.field%02d.selectedIndex;\n",line,k);
//printf("	alert(document.form%05d.field%02d.selectedIndex);\n",line,k);
printf("	document.form%05d.field%02d.value = s1[index1-1];\n",line,k+1);
printf("	document.form%05d.field%02d.value = s2[index2-1];\n",line,k+3);
printf("	submit%d();\n",line);
printf("	document.form%05d.submit();\n",line);
printf("}\n");
printf("function select_2nd%d()\n",line);
printf("{\n");
printf("	submit%d();\n",line);
printf("	document.form%05d.submit();\n",line);
printf("}\n");
printf("\n");
//printf("//-->\n");
printf("-->\n");
printf("</script>\n\n");
					printf("<select name=\"field%02d\" size=\"1\" onchange=\"select_1st%d()\">\n",k,line);
				//	printf("<select name=\"field%02d\" size=\"1\" maxlength=\"64\">\n",k);
				//	printf("<option value=\"\" maxlength=\"%d\">選択なし</option>\n",ft[no].pos[i].len);
					printf("<option value=\"\">選択なし</option>\n");
					//テーブルmeisho_kubunnを全件検索する
					for(j=0;j<DBcount[3];j++)
					{
						//otodokeテーブルの"hinmei"項目と一致するmeishokubunテーブルの2番項目(meisho)をselectする
						if(!strcmp(ft[no].splitDBbuff[line][i],ft[3].splitDBbuff[j][2]))
							printf("<option value=\"%s\" selected> %s</option>\n",ft[3].splitDBbuff[j][2],ft[3].splitDBbuff[j][2]);
						else
							printf("<option value=\"%s\"> %s</option>\n",ft[3].splitDBbuff[j][2],ft[3].splitDBbuff[j][2]);
					}
					printf("</select>\n");
					break;
					case 3:
				//	住所１
						printf("%s:",*(db_titles+i));
						printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\">\n",k,k,ft[no].pos[i].len/2,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
						break;
					case 4:
				//	住所２
						printf("%s:",*(db_titles+i));
						printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\"><br>\n",k,k,ft[no].pos[i].len/2,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
						break;
					case 5:
				//	氏名１
						printf("%s:",*(db_titles+i));
						printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\">\n",k,k,ft[no].pos[i].len/3,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
						break;
				/*
				case 11:
				//	品種
				//	printf("%s:",*(db_titles+i));
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"hidden\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\">\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
					break;
					*/
				case 13: case 26:
			//	品名区分 発送元CD
				//	printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"hidden\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\">\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\">\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
					break;
				case 14:
			//	グレード
				subformHTML_grade(1,line);
//ここにフォーム毎に実行するJavaScriptを記述します。
//printf("<script language=\"JavaScript\" type=\"text/javascript\">\n\n");
printf("<script type=\"text/javascript\">\n\n");
printf("<!--\n");
printf("function submit%d()\n",line);
printf("{\n");
printf("	document.form%05d.tmp.value = \"%05d\";\n",line,line);
printf("}\n");
printf("\n");

/*
printf("function MkArray(n)\n");
printf("{\n");
printf("	this.length = n;\n");
printf("	for (var i=1;i<=n;i++)\n");
printf("	{\n");
printf("		this[i] = 0\n");
printf("		return this\n");
printf("	}\n");
printf("}\n");
*/
printf("function select_grade%d()\n",line);
printf("{\n");
printf("	var index1 = 0;\n");
printf("	var index2 = 0;\n");
printf("	var index3 = 0;\n");
printf("	s1 = new MkArray(%d);\n",DBcount[2]);
printf("	s2 = new MkArray(%d);\n",DBcount[2]);
printf("	s3 = new MkArray(%d);\n",DBcount[2]);
			for(x=0;x<DBcount[2];x++)
			{
				printf("		s1[%d] = \"%s\";\n",x,ft[2].splitDBbuff[x][4]);
				printf("		s2[%d] = \"%s\";\n",x,ft[2].splitDBbuff[x][5]);
				printf("		s3[%d] = \"%s\";\n",x,ft[2].splitDBbuff[x][6]);
			}
printf("	index1 = document.form%05d.field%02d.selectedIndex;\n",line,k);
printf("	index2 = document.form%05d.field%02d.selectedIndex;\n",line,k);
printf("	index3 = document.form%05d.field%02d.selectedIndex;\n",line,k);
printf("//	alert(document.form%05d.field%02d.selectedIndex);\n",line,k);
printf("	document.form%05d.field%02d.value = s1[index1-1];\n",line,k-2);
printf("	document.form%05d.field%02d.value = s2[index2-1];\n",line,k+1);
printf("	document.form%05d.field%02d.value = s3[index3-1];\n",line,k+2);
printf("//	submit%d();\n",line);
printf("//	document.form%05d.submit();\n",line);
printf("}\n");
printf("function select_3rd%d()\n",line);
printf("{\n");
printf("	submit%d();\n",line);
printf("	document.form%05d.submit();\n",line);
printf("}\n");
printf("\n");
printf("//-->\n");
//printf("-->\n");
printf("</script>\n\n");
					printf("%s:",*(db_titles+i));
					//(1)UPDATEを実行するsubmitを実行するJavaScriptをselect項目の変更によって実行する
					printf("<select name=\"field%02d\" size=\"1\" onchange=\"select_grade%d()\">\n",k,line);
				//	printf("<select name=\"field%02d\" size=\"1\"  maxlength=\"%d\">\n",k,ft[no].pos[i].len);

					//(2)otodokeテーブルの"hm_kubun"項目及び"hinsyu"項目と一致するgradeテーブルを検索する
					subformHTML_grade(1,line);
				//	printf("<option value=\"\" maxlength=\"%d\">選択なし</option>\n",ft[no].pos[i].len);
					printf("<option value=\"\">選択なし</option>\n");
					//(3) (2)で検索されたgradeテーブルから適合した2番項目(meisho_kubun)をselectedし、表示は1番項目の(toukyu)で行う
					for(j=0;j<DBcount[2];j++)
					{
						if(!strcmp(ft[no].splitDBbuff[line][i],ft[2].splitDBbuff[j][1]))
						{
							printf("<option value=\"%s\" selected>%s</option>\n",ft[2].splitDBbuff[j][1],ft[2].splitDBbuff[j][1]);
						}
						else
						{
							printf("<option value=\"%s\">%s</option>\n",ft[2].splitDBbuff[j][1],ft[2].splitDBbuff[j][1]);
						}
					}
					printf("</select>\n");
					break;
				default:
					printf("%s:",*(db_titles+i));
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
			//	printf("<input type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" >\n",k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
					break;
				}
			}
			else
			{
				printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" readonly >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
			}
					k++;
			}
				break;
		case DATE:
			if(ft[no].pos[i].stype == 1)
			{
				printf("%s:",*(db_titles+i));
			if(ft[no].pos[i].action == 0)
			{
				printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
			}
			else
			{
				printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" readonly >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
			}
			}
			break;
		case NUMERIC:
			if(ft[no].pos[i].stype == 1)
			{
			//	printf("%s:",*(db_titles+i));
			if(ft[no].pos[i].action == 0)
			{
				switch(i)
				{
				case 11:
			//	品種
				//	printf("%s:",*(db_titles+i));
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"hidden\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
					break;
				case 18:
			//	宅配業者
					printf("%s:",*(db_titles+i));
					printf("<select name=\"field%02d\" size=\"1\">\n",k);
				//	printf("<option value=\"\" maxlength=\"%d\">選択なし</option>\n",ft[no].pos[i].len);
					printf("<option value=\"\">選択なし</option>\n");
					for(j=0;j<DBcount[4];j++)
					{
						if(!strcmp(ft[no].splitDBbuff[line][i],ft[4].splitDBbuff[j][0]))
						{
							printf("<option value=\"%s\" selected>%s</option>\n",ft[4].splitDBbuff[j][0],ft[4].splitDBbuff[j][1]);
						}
						else
						{
							printf("<option value=\"%s\">%s</option>\n",ft[4].splitDBbuff[j][0],ft[4].splitDBbuff[j][1]);
						}
					}
					printf("</select><br>\n");
					break;
				case 30: case 60:
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"hidden\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
					break;
				default:
					printf("%s:",*(db_titles+i));
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
					break;
				}
			}
			else
			{
				printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" readonly >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
			}
			}
			break;
		case BOOL:
			if(ft[no].pos[i].stype == 1)
			{
				printf("%s:",*(db_titles+i));
			if(ft[no].pos[i].action == 0)
			{
				if(ft[no].splitDBbuff[line][i][0] == 'f')
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"checkbox\" name=\"field%02d\" size=\"%d\" value=\"t\">\n",k,k,ft[no].pos[i].len);
				else
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"checkbox\" name=\"field%02d\" size=\"%d\" value=\"%s\" checked>\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i]);
			//	printf("<input type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"1\">\n",k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i]);
			}
			else
			{
			//この部分はチェックボックスに使用出来ますが更新や追加には使用出来ません。表示のみに利用可能です。
				if(ft[no].splitDBbuff[line][i][0] == 'f')
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"checkbox\" name=\"field%02d\" size=\"%d\" value=\"%s\" readonly>\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i]);
				else
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"checkbox\" name=\"field%02d\" size=\"%d\" value=\"%s\" checked readonly>\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i]);
			//	printf("<input type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"1\" readonly>\n",k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i]);
			}
			}
			break;
		case CURRENCY:
			if(ft[no].pos[i].stype == 1)
			{
				printf("%s:",*(db_titles+i));
			if(ft[no].pos[i].action == 0)
			{
				printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"15\" >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i]);
			}
			else
			{
				printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"15\" readonly >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i]);
			}
			}
			break;
		case DOUBLE:
			if(ft[no].pos[i].stype == 1)
			{
				printf("%s:",*(db_titles+i));
			if(ft[no].pos[i].action == 0)
			{
				printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
			}
			else
			{
				printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" readonly >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i],ft[no].pos[i].len);
			}
			}
			break;
		default:
			if(ft[no].pos[i].stype == 1)
			{
				printf("%s:",*(db_titles+i));
				printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" >\n",k,k,ft[no].pos[i].len,ft[no].splitDBbuff[line][i]);
			}
			break;
		}
		sprintf(s,"%s",ft[no].splitDBbuff[line][i]);
		sf_tput(no,k,s);
	}
	printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"hidden\" name=\"tmp\" size=\"4\" value=\"\" >\n");
//	printf("</tr>\n");
//	printf("<input type=\"submit\" value=\"更新実行\" onclick=\"submit%d()\">\n",line);
	printf("</form>\n");
//	printf("</table>\n");
//	printf("</body>\n");
//	printf("</html>\n");

}

// FETCHした後にHTMLのテーブルにDBの行列を書き込みます。
int otodoke_Fetch2_grid_dispHTML(int no, int startline, int maxcol, int grid_ey, int grid_sy)
{
	int i, j;
	char s[MAX_TMP];
	char hs[MAX_TMP];

	if((Fetch_otodoke_Fetch2(no)) == 0)
	{
		for(i=startline;i<DBcount[no];i++)
		{
			for(j=0;j<maxcol;j++)
			{
				if(ft[no].cp[0][j].stype == 1)
					sf_gputDBHTML(no,i,j,startline,s);
			}
		}

		return(0);
	}
	else
	{
		return(-1);
	}
}


int subformHTML_otodoke(void)
{
	int i;
	char s[MAX_STR];

	int startline;

	int line;
	setlocale(LC_ALL,"");

//------------------------------------------------------------------------
//下ののハイフンのラインまでの以下の関数はDBと画面の設計を実際のフォームに適用します。
//これらの関数が無い場合は設計情報はDB設計以外は反映されません。

	static int xcol = 242;
	static int rows = 73;

//for label
	static int label_length[] = {0};
	static int label_no[] = {0};
	static int label_align[] = {0};
	static char *label_text[1][128] = {""};
	static int label_x[] = {0};
	static int label_y[] = {0};
//for textbox
	static int textbox_length[] = {5,7,12,96,96,96,192,96,200,13,90,5,5,2,144,10,15,3,3,3,13,3,10,10,10,209,5,7,3,3,5,5,209,2,10,2,5,5,2,13,13,3,2,3,3,15,6,15,60,50,15,15,2,32,13,3,15,15,15,3,5,15,0};
//	static int textbox_length[] = {5,7,24,96,96,96,192,96,200,13,90,5,5,2,144,10,15,3,3,3,13,3,10,10,10,209,5,7,3,3,5,5,209,2,10,2,5,5,2,13,13,3,2,3,3,15,6,15,60,50,15,15,2,32,13,3,15,15,15,3,5,15,0};
	static int textbox_no[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,0};
	static int textbox_align[] = {2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,1,2,1,2,2,2,2,2,2,2,2,2,2,2,1,1,2,2,2,2,1,2,2,2,2,1,1,1,2,1,1,1,2,2,1,1,2,2,2,2,1,1,1,2,1,1,0};
	static int textbox_action[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	static int textbox_skipstep[] = {1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,0,1,0,0,0,0,1,1,0,1,0,1,0,1,1,0,1,1,1,1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0};
	static int textbox_field[] = {2,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,4,3,2,3,1,3,1,1,1,1,1,1,3,3,2,2,1,3,1,3,2,1,3,1,1,1,1,1,3,4,4,4,1,1,4,4,3,1,1,3,4,4,4,3,2,4,0};
	static int textbox_x[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	static int textbox_y[] = {6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,0};


//for grid
	static int cell_length[] = {2,2,2,2,2,2,3,3,3,3,2,3,2,2,2,2,5,3,3,3,3,3,3,3,3,3,2,3,3,3,3,3,3,2,3,2,3,2,2,3,3,3,2,3,3,4,4,4,3,3,4,4,2,3,3,3,4,4,4,3,3,4,0};
	static int cell_align[] = {2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,1,2,1,2,2,2,2,2,2,2,2,2,2,2,1,1,2,2,2,2,1,2,2,2,2,1,1,1,2,1,1,1,2,2,1,1,2,2,2,2,1,1,1,2,1,1,0};
	static int cell_action[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	static int grid_field[] = {2,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,4,3,2,3,1,3,1,1,1,1,1,1,3,3,2,2,1,3,1,3,2,1,3,1,1,2,2,2,3,4,4,4,1,1,4,4,3,1,1,3,4,4,4,3,2,4,0};
	static int grid_skipstep[] = {1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,0,1,0,0,0,0,1,1,0,1,0,1,0,1,1,0,1,1,1,1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0};
	char *grid_titles[63][128] = {"Grid_1","Grid_2","Grid_3","Grid_4","Grid_5","Grid_6","Grid_7","Grid_8","Grid_9","Grid_10","Grid_11","Grid_12","Grid_13","Grid_14","Grid_15","Grid_16","Grid_17","Grid_18","Grid_19","Grid_20","Grid_21","Grid_22","Grid_23","Grid_24","Grid_25","Grid_26","Grid_27","Grid_28","Grid_29","Grid_30","Grid_31","Grid_32","Grid_33","Grid_34","Grid_35","Grid_36","Grid_37","Grid_38","Grid_39","Grid_40","Grid_41","Grid_42","Grid_43","Grid_44","Grid_45","Grid_46","Grid_47","Grid_48","Grid_49","Grid_50","Grid_51","Grid_52","Grid_53","Grid_54","Grid_55","Grid_56","Grid_57","Grid_58","Grid_59","Grid_60","Grid_61","Grid_62",""};
	static char *db_titles[63][128] = {"No","郵便番号","都道府県","住所１","住所２","氏名１","シメイ","氏名２","シメイ２","TEL","品名","品種","容量","品名区分","グレード","サイズ","金額","到着時間希望","宅配業者","お届け通知","伝票番号","得意客","受付日","発送日","希望日","備考","発送元CD","発店CD","発送済","印刷済","伝票番号","箱数","メモ","予約","予約日","印字可","印字枚数","のし","代替","FAX","携帯TEL","希望時間帯１","希望時間帯２","希望時間帯３","お届け通知の有無","送料","発送個数","箱代","地域帯","メール","手数料","消費税額","冷凍と冷蔵","YahooID","仕分CD","仮請求","チルドとクール料金","速達とタイム料金","基本送料","請求書作成済","伝票毎の箱数","送金手数料",0};
//	static char *db_titles[63][128] = {"No","yubinNo","todofuken","jusho1","jusho2","shimei1","shimei_f1","shimei2","shimei_f2","TEL","hinmei","hinsyu","yoryo","hm_kubun","grade","size","kingaku","jikankibou","takuhai_s","tuchi","denNo","tokui","uketukeDATE","expDATE","hopeDATE","bikou","hassoCD","hatutenCD","hatuEND","prEND","denNUM","hakoNUM","memo","reserve","resDATE","print","prNUM","daitaiCD","daitai","FAX","keitaiTEL","hopeTIME","hopeTIME2","hopeTIME3","umu","soryo","hatu_kosuu","hakodai","chitai","mail","tesuu","tac","reitou","YahooID","shiwakeCD","kariseikyu","cc_kingaku","st_kingaku","base_soryo","seikyuEND","den_hakoNUM","soukin_tesuuryo",0};

	static int grid_sx = 0;
	static int grid_ex = 239;
	static int grid_sy = 4;
	static int grid_ey = 4;

	static int maxtext;
	static int no = 1;

	char **gt;
	char **lt;

	gt = (char **)&grid_titles;

	xcol = MakeWsubFormHTML(no,xcol,rows,0,2,grid_sx,grid_sy,grid_ex,grid_ey,cell_length,cell_align,cell_action,grid_field,grid_skipstep,gt,62);

	lt = (char **)&label_text;

//	以下の関数は<SELECT>でコンボボックスを作成する場合、一つのCGIで重複して利用出来ませんのでどちらかを削除してください。
	maxtext = MakeTextBoxHTML(no,0,2,xcol,rows,label_no,lt,label_x,label_y,label_length,textbox_no,textbox_x,textbox_y,textbox_length,textbox_align,textbox_action,textbox_field,textbox_skipstep, 62);

//------------------------------------------------------------------------

	for(i=0;i<MAX_POS;i++)
	{
		memset(gridtitles[i],'\0',MAX_LEN);
	}

	sf_startcell(0);

	startline = 0;	//画面初期行

	if(otodoke_Fetch2_grid_dispHTML(no,startline,maxtext,grid_sy,grid_ey) == -1)	//	*splitDBbuff[][]を表示する。
	{
		printf("grid_dispHTML():error\n");
	}

	//DBへの入力用フォームの作成
	for(i=startline;i<DBcount[no];i++)
	{
		otodoke_Fetch2_text_writeHTML(no,0,i,maxtext,*db_titles);
	}

}

// DBから入出力(画面)ウインドウに書き込みます。
void kokyaku_Fetch_text_writeHTML(int no, int post, int line,int maxcol, char **db_titles)
{
	int i;
	int j;
	char s[MAX_TMP];

	printf("Content-type: text/html\n\n");
//	printf("Set-Cookie: sessId=%s\n",create_session_id());
	printf("<html lang=\"ja\">\n");
	printf("<head>\n");
	printf("<meta http-equiv=\"content-script-type\" content=\"text/html;charset=utf-8\">\n"); 
	printf("<title>form text_writeHTML page</title>\n");

//printf("<script language=\"JavaScript\" type=\"text/javascript\">\n\n");
printf("<script type=\"text/javascript\">\n\n");
printf("<!--\n");
printf("function MkArray(n)\n");
printf("{\n");
printf("	this.length = n;\n");
printf("	for (var i=1;i<=n;i++)\n");
printf("	{\n");
printf("		this[i] = 0\n");
printf("		return this\n");
printf("	}\n");
printf("}\n");
printf("-->\n");
printf("</script>\n\n");

	printf("</head>\n");
	printf("<body>\n");
	printf("<br>\n");

//	printf("<table border=0>\n");
//	printf("<tr bgcolor=\"#ffffff\">\n");


	printf("<a href=\"http://codoo2hk.corede.net/takuhai/takuhai.html\" target=\"_parent\">TOPへ</a>\n");
	printf("<a href=\"#\" onClick=\"history.back(); return false;\">戻る</a>\n");

	printf("<form method=\"post\" action=\"/cgi-bin/kokyaku_Delete.fcgi?field00=%s\">\n",KEY[0]);
	printf("<input tabindex=\"1\" accesskey=\"A\" type=\"submit\" value=\"顧客削除\">\n");
	printf("</form>\n");

	printf("<form method=\"post\" action=\"/cgi-bin/kokyaku_Fetch_New.fcgi?field00=%s\">\n",KEY[0]);
	printf("<input tabindex=\"2\" accesskey=\"A\" type=\"submit\" value=\"新規顧客の登録\">\n");
	printf("</form>\n");

	printf("<form method=\"post\" action=\"/cgi-bin/otodoke_Fetch_New.fcgi?field00=%s\">\n",KEY[0]);
	printf("<input tabindex=\"3\" accesskey=\"A\" type=\"submit\" value=\"新規お届け先追加画面へ\">\n");
	printf("</form>\n");

	//送信はPOSTを使用します。
//テーブル名_Menu.pgc のコードを利用する場合、デバッグ時の送信試験はGETを使用すると便利です。
	printf("<form method=\"post\" action=\"/cgi-bin/kokyaku_Update.fcgi\">\n");
	printf("<input tabindex=\"4\" accesskey=\"A\" type=\"submit\" value=\"顧客の更新\">\n");
	printf("<input tabindex=\"5\" accesskey=\"A\" type=\"reset\" value=\"元に戻す\">\n");

//	printf("</tr>");

	printf("<table border=0>\n");
//	printf("<tr bgcolor=\"#ffffff\">\n");
//	printf("<bgcolor=\"#ffffff\">\n");

	sf_tbegin();
	for(i=0;tp->next !=(TextBox *)NULL;i++)
	{
		printf("<tr>");
		if(ft[no].splitDBbuff[line][i] != (char *)NULL)
		{
			printf("<td>");
			printf("%s:",*(db_titles+i));
			printf("</td>");
			printf("<td>");
			switch(tp->ftype)
			{
			case TEXT:
				if(tp->action == 0)
				{
					switch(i)
					{
					case 22:
				//	if(!strcmp(*(db_titles+i),"備考"))
						printf("<textarea  name=\"field%02d\" rows=\"4\" cols=\"%d\" >%s</textarea>\n",i,tp->len/2,ft[no].splitDBbuff[line][i]);
						break;
					default:
						printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\">\n",i,i,tp->len,ft[no].splitDBbuff[line][i],tp->len);
						break;
					}
				}
				else
				{
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" readonly>\n",i,i,tp->len,ft[no].splitDBbuff[line][i],tp->len);
				}
				break;
			case DATE:
				if(tp->action == 0)
				{
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\">\n",i,i,tp->len,ft[no].splitDBbuff[line][i],tp->len);
				}
				else
				{
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" readonly>\n",i,i,tp->len,ft[no].splitDBbuff[line][i],tp->len);
				}
				break;
			case NUMERIC:
				if(tp->action == 0)
				{
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\">\n",i,i,tp->len,ft[no].splitDBbuff[line][i],tp->len);
				}
				else
				{
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" readonly>\n",i,i,tp->len,ft[no].splitDBbuff[line][i],tp->len);
				}
				break;
			case BOOL:
				if(tp->action == 0)
				{
				//	printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"1\">\n",i,i,tp->len,ft[no].splitDBbuff[line][i]);
				//この部分はチェックボックスに使用出来ます。
					if(ft[no].splitDBbuff[line][i][0] == 'f')
						printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"checkbox\" name=\"field%02d\" size=\"%d\" value=\"t\">\n",i,i,tp->len);
					else
						printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"checkbox\" name=\"field%02d\" size=\"%d\" value=\"%s\" checked>\n",i,i,tp->len,ft[no].splitDBbuff[line][i]);
				}
				else
				{
				//この部分はチェックボックスに使用出来ますが更新や追加には使用出来ません。表示のみに利用可能です。
					if(ft[no].splitDBbuff[line][i][0] == 'f')
						printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"checkbox\" name=\"field%02d\" size=\"%d\" value=\"%s\" readonly>\n",i,i,tp->len,ft[no].splitDBbuff[line][i]);
					else
						printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"checkbox\" name=\"field%02d\" size=\"%d\" value=\"%s\" checked readonly>\n",i,i,tp->len,ft[no].splitDBbuff[line][i]);
				//	printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"1\" readonly>\n",i,i,tp->len,ft[no].splitDBbuff[line][i]);
				}
				break;
			case CURRENCY:
				if(tp->action == 0)
				{
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"15\" >\n",i,i,tp->len,ft[no].splitDBbuff[line][i]);
				}
				else
				{
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"15\" readonly>\n",i,i,tp->len,ft[no].splitDBbuff[line][i]);
				}
				break;
			case DOUBLE:
				if(tp->action == 0)
				{
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%s\">\n",i,i,tp->len,ft[no].splitDBbuff[line][i],tp->len);
				}
				else
				{
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%s\" readonly>\n",i,i,tp->len,ft[no].splitDBbuff[line][i],tp->len);
				}
				break;
			default:
				printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\">\n",i,i,tp->len,ft[no].splitDBbuff[line][i]);
				break;
			}
			sprintf(s,"%s",ft[no].splitDBbuff[line][i]);
			sf_tput(no,i,s);
			sf_tnext();
			printf("</td>");
		}
		else
		{
			sf_tnext();
		}
		printf("</tr>");
	}
	printf("<tr>");
	if(ft[no].splitDBbuff[line][i] != (char *)NULL)
	{
		printf("<td>");
		printf("%s:",*(db_titles+i));
		printf("</td>");
		printf("<td>");
		switch(tp->ftype)
		{
		case TEXT:
			if(tp->action == 0)
			{
				switch(i)
				{
				case 22:
				//	if(!strcmp(*(db_titles+i),"備考"))
					printf("<textarea  name=\"field%02d\" rows=\"4\" cols=\"%d\" >%s</textarea>\n",i,tp->len/2,ft[no].splitDBbuff[line][i]);
					break;
				default:
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\">\n",i,i,tp->len,ft[no].splitDBbuff[line][i],tp->len);
					break;
				}
			}
			else
			{
				printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" readonly>\n",i,i,tp->len,ft[no].splitDBbuff[line][i],tp->len);
			}
			break;
		case DATE:
			if(tp->action == 0)
			{
				printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\">\n",i,i,tp->len,ft[no].splitDBbuff[line][i],tp->len);
			}
			else
			{
				printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" readonly>\n",i,i,tp->len,ft[no].splitDBbuff[line][i],tp->len);
			}
			break;
		case NUMERIC:
			if(tp->action == 0)
			{
				printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\">\n",i,i,tp->len,ft[no].splitDBbuff[line][i],tp->len);
			}
			else
			{
				printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" readonly>\n",i,i,tp->len,ft[no].splitDBbuff[line][i],tp->len);
			}
			break;
		case BOOL:
			if(tp->action == 0)
			{
			//	printf("<input type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"1\">\n",i,tp->len,ft[no].splitDBbuff[line][i]);
			//この部分はチェックボックスに使用出来ます。
				if(ft[no].splitDBbuff[line][i][0] == 'f')
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"checkbox\" name=\"field%02d\" size=\"%d\" value=\"t\">\n",i,i,tp->len);
				else
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"checkbox\" name=\"field%02d\" size=\"%d\" value=\"%s\" checked>\n",i,i,tp->len,ft[no].splitDBbuff[line][i]);
			}
			else
			{
			//この部分はチェックボックスに使用出来ますが更新や追加には使用出来ません。表示のみに利用可能です。
				if(ft[no].splitDBbuff[line][i][0] == 'f')
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"checkbox\" name=\"field%02d\" size=\"%d\" value=\"%s\" readonly>\n",i,i,tp->len,ft[no].splitDBbuff[line][i]);
				else
					printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"checkbox\" name=\"field%02d\" size=\"%d\" value=\"%s\" checked readonly>\n",i,i,tp->len,ft[no].splitDBbuff[line][i]);
			//	printf("<input type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"1\" readonly>\n",i,tp->len,ft[no].splitDBbuff[line][i]);
			}
			break;
		case CURRENCY:
			if(tp->action == 0)
			{
				printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"15\">\n",i,i,tp->len,ft[no].splitDBbuff[line][i]);
			}
			else
			{
				printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"15\" readonly>\n",i,i,tp->len,ft[no].splitDBbuff[line][i]);
			}
			break;
		case DOUBLE:
			if(tp->action == 0)
			{
				printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\">\n",i,i,tp->len,ft[no].splitDBbuff[line][i],tp->len);
			}
			else
			{
				printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\" maxlength=\"%d\" readonly>\n",i,i,tp->len,ft[no].splitDBbuff[line][i],tp->len);
			}
			break;
		default:
			printf("<input accesskey=\"C\" tabindex=\"%d\" type=\"text\" name=\"field%02d\" size=\"%d\" value=\"%s\">\n",i,i,tp->len,ft[no].splitDBbuff[line][i]);
			break;
		}
		sprintf(s,"%s",ft[no].splitDBbuff[line][i]);
		sf_tput(no,i,s);
		printf("</td>");
	}
	printf("</tr>");
//	printf("<input type=\"submit\" value=\"更新実行\">\n");
	printf("</table>\n");
	printf("</form>\n");
//	printf("</body>\n");
//	printf("</html>\n");
}
// FETCHした後にHTMLのテーブルにDBの行列を書き込みます。
int kokyaku_Fetch_grid_dispHTML(int no, int startline, int maxcol, int grid_ey, int grid_sy)
{
	int i, j;
	char s[MAX_TMP];
	char hs[MAX_TMP];

	if((Fetch_kokyaku_Fetch(no)) == 0)
	{
		for(i=startline;i<DBcount[no];i++)
		{
			for(j=0;j<maxcol;j++)
			{
				sf_gputDBHTML(no,i,j,startline,s);
			}
		}

		return(0);
	}
	else
	{
		return(-1);
	}
}


int subformHTML(void)
{
	int i;
	char s[MAX_STR];

	int startline;

	int line;
	setlocale(LC_ALL,"");

//------------------------------------------------------------------------
//下ののハイフンのラインまでの以下の関数はDBと画面の設計を実際のフォームに適用します。
//これらの関数が無い場合は設計情報はDB設計以外は反映されません。

	static int xcol = 174;
	static int rows = 47;

//for label
	static int label_length[] = {0};
	static int label_no[] = {0};
	static int label_align[] = {0};
	static char *label_text[1][128] = {""};
	static int label_x[] = {0};
	static int label_y[] = {0};
//for textbox
	static int textbox_length[] = {5,5,5,64,64,12,64,12,7,20,64,64,50,13,13,13,13,13,2,2,2,2,128,32,0};
	static int textbox_no[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0};
	static int textbox_align[] = {1,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0};
	static int textbox_action[] = {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	static int textbox_skipstep[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0};
	static int textbox_field[] = {2,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,3,3,3,1,1,0};
	static int textbox_x[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	static int textbox_y[] = {6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,0};


//for grid
	static int cell_length[] = {5,5,5,4,4,4,4,4,4,7,8,8,6,11,9,8,7,7,2,2,2,2,9,20,0};
	static int cell_align[] = {1,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0};
	static int cell_action[] = {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	static int grid_field[] = {2,1,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,3,3,3,1,1,0};
	static int grid_skipstep[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0};
	char *grid_titles[25][128] = {"Grid_1","Grid_2","Grid_3","Grid_4","Grid_5","Grid_6","Grid_7","Grid_8","Grid_9","Grid_10","Grid_11","Grid_12","Grid_13","Grid_14","Grid_15","Grid_16","Grid_17","Grid_18","Grid_19","Grid_20","Grid_21","Grid_22","Grid_23","Grid_24",""};
	static char *db_titles[25][128] = {"顧客情報ID","顧客コード","応対区分","氏名","シメイ","職業","会社名","役職","〒","都道府県名","住所１","住所２","MAIL","会社TEL","内線番号","FAX","携帯TEL","自宅TEL","印刷する","返事なし","住所不明","喪中","備考","YahooID",0};
//	static char *db_titles[25][128] = {"johoID","kokyakuCD","outaikubunID","shimei","furigana","shokugyou","kaisyamei","yakushoku","yubin","todoufuken","jusho1","jusho2","mail","kaisyaTEL","naisenTEL","FAX","keitaiTEL","jitakuTEL","insatu","henjinashi","fumei","mocyu","bikou","YahooID",0};
	static int grid_sx = 0;
	static int grid_ex = 169;
	static int grid_sy = 3;
	static int grid_ey = 4;

	static int maxtext;
	static int no = 0;

	char **gt;
	char **lt;

	gt = (char **)&grid_titles;

	xcol = MakeWsubFormHTML(no,xcol,rows,0,2,grid_sx,grid_sy,grid_ex,grid_ey,cell_length,cell_align,cell_action,grid_field,grid_skipstep,gt,24);

	lt = (char **)&label_text;

//	以下の関数は<SELECT>でコンボボックスを作成する場合、一つのCGIで重複して利用出来ませんのでどちらかを削除してください。
	maxtext = MakeTextBoxHTML(no,0,2,xcol,rows,label_no,lt,label_x,label_y,label_length,textbox_no,textbox_x,textbox_y,textbox_length,textbox_align,textbox_action,textbox_field,textbox_skipstep, 24);

//------------------------------------------------------------------------

	for(i=0;i<MAX_POS;i++)
	{
		memset(gridtitles[i],'\0',MAX_LEN);
	}

	sf_startcell(0);

	startline = 0;	//画面初期行

	if(kokyaku_Fetch_grid_dispHTML(no,startline,maxtext,grid_sy,grid_ey) == -1)	//	*splitDBbuff[][]を表示する。
	{
		printf("grid_dispHTML():error\n");
	}

	//DBへの入力用フォームの作成
	for(i=startline;i<DBcount[no];i++)
	{
		kokyaku_Fetch_text_writeHTML(no,0,i,maxtext,*db_titles);
	}
	subformHTML_otodoke();
//	Fetch_otodoke(no);

}

int main(int argc, char *argv[])
{
	sprintf(COMMANDNAME,"%s",argv[0]);
	while (FCGI_Accept() >= 0)
	{
		subformHTML_takuhai_gyosya_Joint();
		subformHTML_meishokubun();
		subformHTML();
		printf("</body>\n");
		printf("</html>\n");
	}
}

