G3511_And_note_英単語帳
2025年2月8日
17:10
G3511_andoroid_and_note_japan_to_english
説明
コマンドテキストを追加します
コマンド処理としてコードを作成します
そのままの処理をコピーペーストします
// コマンドボタン操作 (ボタン2 を押したときの処理です)
private void Command_but_action()
{
string tmp_cst = "";
string sub_name = "";
// コマンドボタン専用名 判定
switch (Command_but_name)
{
case "コマンド(開始)":
Voice_cst = Edt_tbl[0].Text = "";
voice_call(); // 音声変換呼び出し
command_but_name_set("コマンド(選択)");
break;
case "コマンド(選択)":
// コマンドは中間のスペースを削除します
tmp_cst = Edt_tbl[0].Text.Trim();
tmp_cst = Regex.Replace(tmp_cst, @"\s", "");
tmp_cst = command_name_sarch(tmp_cst);
if (tmp_cst != "")
{
// 登録コマンド発見しました
command_name_set(tmp_cst);
command_but_name_set("コマンド(実行)");
Voice_cst = Edt_tbl[0].Text = "";
}
else
{
// 指示されたコマンドはありませんので、戻ります
command_name_set("----- 未登録です -----");
command_but_name_set("コマンド(音声)");
}
break;
case "コマンド(実行)":
// 実行に先だって、Button4 を押してデータを入力します
switch (Command_name)
{
case "除外ワード":
fil_add_exclu_key(Edt_tbl[0].Text);
// 除外ワードテキストファイルをテーブルに読み込みします
Exclu_key_cnt = com_txt_tbl_red(Exclu_key_fil_path, 0, Exclu_key_tbl);
break;
case "削除":
case "抹消":
case "消去":
// どの文言でも同じ結果が得られます
txt_fil_rec_cpy("D", Edt_tbl[0].Text, "");
break;
case "結果登録":
case "フラグ登録":
case "状態登録":
case "完成":
case "フラグ":
note_flg_wrt(Edt_tbl[0].Text);
break;
case "英単語":
sub_name = "英単語";
tmp_cst = Edt_tbl[0].Text;
break;
}
Edt_tbl[0].Text = "";
break;
}
// ここは処理結果をテキストボックスに表示したい場合使います
switch(sub_name)
{
case "英単語":
Japan_to_english(tmp_cst);
break;
}
}
英単語ファイルの検索関数を作ります
// 英単語テキストファイルを検索して結果を表示します
private void Japan_to_english(string prm_japan)
{
string fil_path = Path_files + @"/000_英単語.txt";
string txt_buf;
string[] cut_tbl = new string[10];
bool find_flg = false;
if (prm_japan.Trim() == "") return;
if (File.Exists(fil_path) == false)
{
msg2("英単語ファイルが存在しません", fil_path, "");
return;
}
// テキストファイル読み込み
System.Text.Encoding.GetEncoding("utf-8");
using (StreamReader red = new StreamReader(fil_path))
{
while (red.EndOfStream == false)
{
txt_buf = red.ReadLine();
if (txt_buf == null) continue;
if (txt_buf == "") continue;
cut_tbl = txt_buf.Split(',');
if (cut_tbl.Length < 2) continue;
if (cut_tbl[0].Trim() == prm_japan.Trim())
{
Edt_tbl[0].Text = cut_tbl[0] + " " + cut_tbl[1];
find_flg = true;
break;
}
}
}
if (find_flg == false) Edt_tbl[0].Text = "---未登録です---";
}
ボタン4の処理を追加します
画面の流れ
連続変換する時、前回変換結果が消えないので消える仕様に変更します
現時点で下記の未登録を発見しましまた
テキストファイルに1行追加する共用関数を追加します
関数名を Txt_fil_rec_add() に変更する前に、古い名称を検索します
呼び出しは1か所だけです 修正します
Txt_fil_rec_add(Exclu_key_fil_path,Edt_tbl[0].Text);
関数の変更をします
// テキストファイルに1行追加します
private void Txt_fil_rec_add(string prm_fil_path,string prm_rec_buf)
{
string rec_buf = prm_rec_buf.Trim();
// ファイルを開く
System.Text.Encoding.GetEncoding("utf-8");
using (StreamWriter writer = new StreamWriter(prm_fil_path, true))
{
writer.WriteLine(rec_buf); // テキストを書き込む
writer.Flush(); // 書き込んだ内容をフラッシュする
}
}
未登録キーだけを追加登録します
// 未登録ワードのキーだけを追加しておきます
// 内容はパソコンで登録するものとします
Txt_fil_rec_add(fil_path,prm_japan.Trim() + ",");
パソコンのメモ帳で登録します
コマンドモードが初期化されないのでいちいちアプリを落としている
コマンドモード初期化関数を作成する
// コマンドモード名初期化
private void Command_mode_clr()
{
Command_mode_name = "コマンド(開始)";
But_tbl[4].Text = "";
}
「取消し」ボタンを修正します
// コマンドモードの初期化を追加します
if (Command_mode_name != "コマンド(開始)") Command_mode_clr();
同じ処理をボタン0にも追加します
コマンドモードボタン名関数を修正する
コマンドボタンモード初期化関数をもう一度変更します
// コマンドモード名初期化
private void Command_mode_clr()
{
Command_mode_name_button_set("コマンド(開始)");
But_tbl[4].Text = "";
}