G3017_グリッドビューの実験
2025年2月24日
8:09
G3017_pc_goma_note_grid_view_mobile_alignment
解説
スマホの検索データの取り込み
取り込みするグリッドビューの設計
グリッドビューの定義
Goma_note/グリッド |
グリッドフォルダ |
000_sys/グリッド配置 |
グリッド配置フォルダ |
000_sys/グリッドパス定義 |
グリッドパス定義フォルダ |
000_sys/グリッド配置/作業 |
グリッド配置作業 |
000_sys/グリッドパス定義/作業 |
グリッドパス定義作業 |
Prm_name_add("グリッドフォルダ");
tmp_cst = Prm_dat_get("データルートフォルダ") + @"\グリッド";
Prm_dat_upd("グリッドフォルダ", tmp_cst);
Prm_name_add("グリッド配置フォルダ");
tmp_cst = Prm_dat_get("システムフォルダ") + @"\グリッド配置";
Prm_dat_upd("グリッド配置フォルダ", tmp_cst);
Prm_name_add("グリッドパス定義フォルダ");
tmp_cst = Prm_dat_get("システムフォルダ") + @"\グリッドパス定義";
Prm_dat_upd("グリッドパス定義フォルダ", tmp_cst);
Prm_name_add("グリッド配置作業");
tmp_cst = Prm_dat_get("グリッド配置フォルダ") + @"\作業";
Prm_dat_upd("グリッド配置作業", tmp_cst);
Prm_name_add("グリッドパス定義作業");
tmp_cst = Prm_dat_get("グリッドパス定義フォルダ") + @"\作業";
Prm_dat_upd("グリッドパス定義作業", tmp_cst);
Com_folder_chk(Prm_dat_get("グリッドフォルダ"));
Com_folder_chk(Prm_dat_get("グリッド配置フォルダ"));
Com_folder_chk(Prm_dat_get("グリッドパス定義フォルダ"));
Com_folder_chk(Prm_dat_get("グリッド配置作業"));
Com_folder_chk(Prm_dat_get("グリッドパス定義作業"));
パス定義テキストファイルはメモ帳で作成します
グリッド配置もメモ帳で作成します
スマホ検索キーのグリッド配置を画面表示します
Grid_name = "スマホ検索キー";
Grid_init(0, 270, 50, 800, 600, Grid_name); // グリッドの初期化処理
// グリッド初期化
private void Grid_init(
int prm_grno, // グリッド番号
int prm_x, // 座標
int prm_y, //
int prm_siz_x, // サイズ
int prm_siz_y, //
string prm_grid_name) // グリッド定義名
{
int fld_max;
int len;
string grid_name = prm_grid_name.Trim();
fld_max = Grid_fld_decompo(grid_name.Trim()); // バス定義分解
if (fld_max == 0)
{
msg2("Grid_init()", "グリッド配置がありません", "");
return;
}
Grid_tbl[prm_grno] = new DataGridView(); // グリッド配列
this.Controls.Add(Grid_tbl[prm_grno]);
Grid_tbl[prm_grno].ColumnHeadersDefaultCellStyle.BackColor = Color.Pink; //変化なし
Grid_tbl[prm_grno].ColumnHeadersDefaultCellStyle.ForeColor = Color.White; //変化なし
Grid_tbl[prm_grno].ForeColor = Color.Green; // セル内の文字色
Grid_tbl[prm_grno].BackgroundColor = Color.LightGray; // 非表示領域の色
Grid_tbl[prm_grno].Location = new Point(prm_x, prm_y);
Grid_tbl[prm_grno].Size = new Size(prm_siz_x, prm_siz_y);
Grid_tbl[prm_grno].ColumnCount = fld_max;
Grid_tbl[prm_grno].AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; // データ幅に合わせて広がる
Grid_tbl[prm_grno].AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
Grid_tbl[prm_grno].ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
Grid_tbl[prm_grno].CellBorderStyle = DataGridViewCellBorderStyle.Single;
Grid_tbl[prm_grno].GridColor = Color.Black;
Grid_tbl[prm_grno].RowHeadersVisible = true; // 行ヘッダー表示の有無
//Grid_tbl[prm_grno].MultiSelect = false; // コントロールでの複数選択有無
//Grid_tbl[prm_grno].Dock = DockStyle.None; // これでロケーションが自由になります 未定義でもよい
//Grid_tbl[prm_grno].ColumnHeadersHeight = 50; // 列ヘッダー高さ
//Grid_tbl[prm_grno].RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Sunken;
//Grid_tbl[prm_grno].Rows[0].Cells[0].Value = "メインモード";
//Grid_tbl[prm_grno].Rows[0].Cells[1].Value = "カレンダー";
for (int i = 0; i < fld_max; i++)
{
Grid_tbl[prm_grno].Columns[i].Name = Grid_fld_def_get("配置", i,grid_name, "名称");
if (int.TryParse(Grid_fld_def_get("配置", i,grid_name, "長さ"), out len) == false) len = 0;
Grid_tbl[prm_grno].Columns[i].Width = len * 16;
}
}
// グリッド配置定義の取得
private string Grid_fld_def_get(
string prm_type,
int prm_lin,
string prm_grd_name,
string prm_fld_name)
{
string fil_path = Grid_fld_def_path_get(prm_type,prm_lin,prm_grd_name, prm_fld_name);
string[] fld_tbl = new string[50];
int fld_max;
if (File.Exists(fil_path) == false) return "";
fld_max = Com_txt_tbl_red(fil_path, 0, fld_tbl, "");
if (fld_max == 0) return "";
return fld_tbl[0];
}
// グリッド配置、バス定義、作業パスの取得
private string Grid_fld_def_path_get(
string prm_type,
int prm_lin,
string prm_grd_name,
string prm_fld_name)
{
string folder_name = "";
if (prm_type == "配置")
folder_name = Prm_dat_get("グリッド配置作業");
else
folder_name = Prm_dat_get("グリッドパス定義作業");
return (folder_name + @"\" + prm_grd_name + "_" + prm_lin.ToString() + "_" + prm_fld_name + ".txt");
}
// グリッド配置の分解
private int Grid_fld_decompo(string prm_grid_name)
{
string work_path;
string fil_path;
string txt_buf;
string[] fld_tbl = new string[20];
string wrt_path;
int lin = 0;
string grid_name = prm_grid_name.Trim();
string def_name;
fil_path = Prm_dat_get("グリッド配置フォルダ") + @"\" + grid_name + ".fldtxt";
if (File.Exists(fil_path) == false)
{
msg2("Grid_fld_decompo()", "グリッド配置ファイルがありません", "");
return 0;
}
work_path = Prm_dat_get("グリッド配置作業");
// ワイルドカードで削除する
foreach (string pathFrom in System.IO.Directory.EnumerateFiles(work_path, "*.*", System.IO.SearchOption.AllDirectories))
System.IO.File.Delete(pathFrom);
Encoding enc = Encoding.GetEncoding("UTF-8");
using (StreamReader red = new StreamReader(fil_path, enc))
{
while (red.EndOfStream == false)
{
txt_buf = red.ReadLine();
if (txt_buf == null) continue;
if (txt_buf == "") continue;
fld_tbl = txt_buf.Split(',');
for (int i = 0; i < fld_tbl.Length; i++)
{
// 分解はフィールド番号で実行する
def_name = "";
switch(i)
{
case 0: def_name = "名称"; break;
case 1: def_name = "長さ"; break;
case 2: def_name = "少数桁"; break;
case 3: def_name = "IME"; break;
}
if(def_name != "")
{
wrt_path = Grid_fld_def_path_get("配置",lin, grid_name, def_name);
Txt_fil_lin_wrt(wrt_path, fld_tbl[i]);
}
}
++lin;
}
wrt_path = work_path + @"\" + grid_name + "_" + "配置個数.txt";
}
return lin;
}
// テキストファイル1行書き込み
private void Txt_fil_lin_wrt(string prm_path, string prm_dat)
{
Encoding enc = Encoding.GetEncoding("UTF-8");
using (StreamWriter wrt = new StreamWriter(prm_path, true, enc))
{
wrt.WriteLine(prm_dat);
}
}
// グリッドパス定義の分解
private int Grid_path_decompo(string prm_grid_name)
{
string work_path;
string fil_path;
string txt_buf;
string[] fld_tbl = new string[20];
string wrt_path;
int lin = 0;
string grid_name = prm_grid_name.Trim();
fil_path = Prm_dat_get("グリッドパス定義フォルダ") + @"\" + grid_name + ".pathtxt";
if (File.Exists(fil_path) == false)
{
msg2("Grid_path_decompo()", "グリッドパス定義ファイルがありません", "");
return 0;
}
work_path = Prm_dat_get("グリッドパス定義作業");
// ワイルドカードで削除する
foreach (string pathFrom in System.IO.Directory.EnumerateFiles(work_path, "*.*", System.IO.SearchOption.AllDirectories))
System.IO.File.Delete(pathFrom);
Encoding enc = Encoding.GetEncoding("UTF-8");
using (StreamReader red = new StreamReader(fil_path, enc))
{
while (red.EndOfStream == false)
{
txt_buf = red.ReadLine();
if (txt_buf == null) continue;
if (txt_buf == "") continue;
fld_tbl = txt_buf.Split(',');
if (fld_tbl.Length < 2) continue;
wrt_path = Grid_fld_def_path_get("パス定義", 0, grid_name, fld_tbl[0].Trim());
Txt_fil_lin_wrt(wrt_path, fld_tbl[1].Trim());
++lin;
}
}
return lin;
}
// グリッドパス定義データの取得
private string Grid_path_def_get(string prm_grid_name,string prm_path_name)
{
string fil_path = Grid_fld_def_path_get("パス定義", 0, prm_grid_name, prm_path_name);
string[] fld_tbl = new string[50];
int fld_max;
if (File.Exists(fil_path) == false) return "";
fld_max = Com_txt_tbl_red(fil_path, 0, fld_tbl, "");
if (fld_max == 0) return "";
return fld_tbl[0];
}
// グリッドデータ読み込み
private void Grid_data_red(int prm_grno,string prm_grid_name)
{
string fil_path = Grid_path_def_get(Grid_name, "フォルダ名") + @"\" + Grid_path_def_get(Grid_name, "ファイル名");
Encoding enc;
string fil_type = "UTF-8";
string txt_buf;
string[] fld_tbl = new string[100];
int lin;
if (File.Exists(fil_path) == false)
{
msg2("Grid_data_red()", "データファイルがありません", fil_path);
return;
}
if(fil_type == "ANSI")
enc = Encoding.GetEncoding("Shift_JIS");
else
enc = Encoding.GetEncoding("UTF-8");
lin = 0;
using (StreamReader red = new StreamReader(fil_path, enc))
{
while (red.EndOfStream == false)
{
txt_buf = red.ReadLine();
if (txt_buf == null) continue;
if (txt_buf == "") continue;
fld_tbl = txt_buf.Split(',');
if (fld_tbl.Length == 0) continue;
Grid_tbl[prm_grno].Rows.Add();
for (int i=0;i<fld_tbl.Length; i++)
Grid_tbl[prm_grno].Rows[lin].Cells[i].Value = fld_tbl[i];
++lin;
}
}
}
グリッドの外形を表示します
グリッド配置の分解結果です
1ファイル1データが保存されている分解ファイルを作っています
実行結果
パス定義の分解処理を確認します
Grid_path_decompo(Grid_name); // パス定義の分解
要素名で1ファイルに分解されています
データを読み込みしグリッドに展開します
000_キーワード.txt を編集します
1キーワード1ファイルに分解します
// 実験が終わったら削除します
string mobile_folder = Grid_path_def_get(Grid_name, "フォルダ名") + @"\key";
string mobile_path = "";
// スマホキーワード分解専用関数
// 実験が終わったら削除します
mobile_path = mobile_folder + @"\" + fld_tbl[0] + ".txt";
for(int i=1;i<fld_tbl.Length;i++) Txt_fil_lin_wrt(mobile_path, fld_tbl[i]);
コマンドと英単語の機能が分割できていません
仮の分解処理を修正します
// ひとつの配置(レコード定義)に複数のファイルを対応させるループは作らず
// 対象ファイルを関数に指示する方式とします
Grid_data_red(0, Grid_name, Grid_path_def_get(Grid_name, "フォルダ名"),"000_キーワード.txt");
Grid_data_red(0, Grid_name, Grid_path_def_get(Grid_name, "フォルダ名"), "000_コマンド.txt");
// グリッドデータ読み込み
private void Grid_data_red(
int prm_grno,
string prm_grid_name,
string prm_root_folder,
string prm_fil_name)
{
Encoding enc;
string fil_type = "UTF-8";
string txt_buf;
string[] fld_tbl = new string[100];
int lin,i,j;
string fil_path = prm_root_folder + @"\" + prm_fil_name;
// 実験が終わったら削除します
string mobile_key_folder = "";
string mobile_key_path = "";
string mobile_command_folder = "";
string mobile_command_path = "";
msg(fil_path);
if(prm_fil_name.Trim() == "000_キーワード.txt")
{
// 実験が終わったら削除します
mobile_key_folder = Grid_path_def_get(Grid_name, "フォルダ名") + @"\key";
Fil_wild_delete(mobile_key_folder, "*.*"); // ワイルドカードで削除する
}
if (prm_fil_name.Trim() == "000_コマンド.txt")
{
// 実験が終わったら削除します
mobile_command_folder = Grid_path_def_get(Grid_name, "フォルダ名") + @"\command";
Fil_wild_delete(mobile_command_folder, "*.*"); // ワイルドカードで削除する
}
if (File.Exists(fil_path) == false)
{
msg2("Grid_data_red()", "データファイルがありません", fil_path);
return;
}
if(fil_type == "ANSI")
enc = Encoding.GetEncoding("Shift_JIS");
else
enc = Encoding.GetEncoding("UTF-8");
lin = 0;
using (StreamReader red = new StreamReader(fil_path, enc))
{
while (red.EndOfStream == false)
{
txt_buf = red.ReadLine();
if (txt_buf == null) continue;
if (txt_buf == "") continue;
fld_tbl = txt_buf.Split(',');
if (fld_tbl.Length == 0) continue;
Grid_tbl[prm_grno].Rows.Add();
for (i = 0; i < fld_tbl.Length; i++)
Grid_tbl[prm_grno].Rows[lin].Cells[i].Value = fld_tbl[i];
if (fld_tbl[1].Trim() == "コマンド" || fld_tbl[1].Trim() == "除外ワード")
{
// スマホコマンド分解専用関数
// 実験が終わったら削除します
mobile_command_path = mobile_command_folder + @"\" + fld_tbl[0] + ".txt";
for (j = 1; j < fld_tbl.Length; j++) Txt_fil_lin_wrt(mobile_command_path, fld_tbl[j]);
}
else
{
// スマホキーワード分解専用関数
// 実験が終わったら削除します
mobile_key_path = mobile_key_folder + @"\" + fld_tbl[0] + ".txt";
for (j = 1; j < fld_tbl.Length; j++) Txt_fil_lin_wrt(mobile_key_path, fld_tbl[j]);
}
++lin;
}
}
}
このように、コマンドとキーワード(英単語)が分離できました
設計ミス発見
2025.02.26 WED (22:28) goma0099 -2931196-
除外ワードは合成せず、従来のまま分離して利用する
コマンドとキーワードは分離しなければいけない
コマンドのレコード構成 名称 , 種別 , 同義語
キーワードのレコード構成 名称 , スペル , 解説
グリッドを2種類作成します
Grid_name = "スマホ検索キー";
Grid_init(0, 270, 50, 800, 300, Grid_name); // グリッド(キーワード)の初期化処理
Grid_data_red(0, Grid_name, Grid_path_def_get(Grid_name, "フォルダ名"), "000_キーワード.txt");
Grid_init(1, 270, 400, 800, 300, Grid_name); // グリッド(コマンド)の初期化処理
Grid_data_red(1, Grid_name, Grid_path_def_get(Grid_name, "フォルダ名"), "000_コマンド.txt");
グリッドデータ読み込み処理に分解処理を追加します
// グリッドデータ読み込み
private void Grid_data_red(
int prm_grno,
string prm_grid_name,
string prm_root_folder,
string prm_fil_name)
{
Encoding enc;
string fil_type = "UTF-8";
string txt_buf;
string[] fld_tbl = new string[100];
int lin,i,j;
string fil_path = prm_root_folder + @"\" + prm_fil_name;
// 実験が終わったら削除します
string mobile_key_folder = "";
string mobile_key_path = "";
string mobile_command_folder = "";
string mobile_command_path = "";
if(prm_fil_name.Trim() == "000_キーワード.txt")
{
// 実験が終わったら削除します
mobile_key_folder = Grid_path_def_get(Grid_name, "フォルダ名") + @"\key";
Fil_wild_delete(mobile_key_folder, "*.*"); // ワイルドカードで削除する
}
if (prm_fil_name.Trim() == "000_コマンド.txt")
{
// 実験が終わったら削除します
mobile_command_folder = Grid_path_def_get(Grid_name, "フォルダ名") + @"\command";
Fil_wild_delete(mobile_command_folder, "*.*"); // ワイルドカードで削除する
}
if (File.Exists(fil_path) == false)
{
msg2("Grid_data_red()", "データファイルがありません", fil_path);
return;
}
if(fil_type == "ANSI")
enc = Encoding.GetEncoding("Shift_JIS");
else
enc = Encoding.GetEncoding("UTF-8");
lin = 0;
using (StreamReader red = new StreamReader(fil_path, enc))
{
while (red.EndOfStream == false)
{
txt_buf = red.ReadLine();
if (txt_buf == null) continue;
if (txt_buf == "") continue;
fld_tbl = txt_buf.Split(',');
if (fld_tbl.Length == 0) continue;
Grid_tbl[prm_grno].Rows.Add();
for (i = 0; i < fld_tbl.Length; i++)
Grid_tbl[prm_grno].Rows[lin].Cells[i].Value = fld_tbl[i];
if (prm_fil_name.Trim() == "000_コマンド.txt")
{
// スマホコマンド分解専用関数
// 実験が終わったら削除します
mobile_command_path = mobile_command_folder + @"\" + fld_tbl[0] + ".txt";
for (j = 1; j < fld_tbl.Length; j++) Txt_fil_lin_wrt(mobile_command_path, fld_tbl[j]);
}
if (prm_fil_name.Trim() == "000_キーワード.txt")
{
// スマホキーワード分解専用関数
// 実験が終わったら削除します
mobile_key_path = mobile_key_folder + @"\" + fld_tbl[0] + ".txt";
for (j = 1; j < fld_tbl.Length; j++) Txt_fil_lin_wrt(mobile_key_path, fld_tbl[j]);
}
++lin;
}
}
}
結果の画面表示です
スマホで利用する分解ファイルです