unote 書けば書くほどに

20230213

void getString()
{
    string str = "9823-kko-A";
    string target = "-";

    int tgtFirst = str.IndexOf(target);
    int numFirst = tgtFirst + 1;

    int tgtSecond = str.IndexOf(target, numFirst);
    int numLast = tgtSecond - 1;

    string num = str.Substring(0, 1);
    Regex regex = new Regex(@"[0-9]");//正規表現使用(using必要)

    if (regex.IsMatch(num))
    {
        Console.WriteLine(target + "を取り除きました");
        Console.WriteLine(str.Substring(0, numFirst - 1));
    }
    else if (tgtFirst > 0 & tgtSecond > 0) //Indexofが2つ見つかった時
    {
        Console.WriteLine(target + "を取り除きました");
        Console.WriteLine(str.Substring(numFirst, (numLast - numFirst + 1)));

        str = str.Substring(numFirst, (numLast - numFirst + 1));

        if (str.Contains(target))
        {
            numLast = str.Length - str.LastIndexOf(target);
            Console.WriteLine(str.Substring(0, numLast));
        }
    }
    else
    {
        Console.WriteLine(target + "はありません");
        Console.WriteLine(str);
    }

}
//https://www.sejuku.net/blog/43619


//テーブル関数内に作成:検証

void B_TableMarge()
{
    DataTable dt = new DataTable();

    TN = "DEPT";
    repTN = "R_" + TN + " R";
    xbbTN = TN + "@FICUSR X";
    bkTN = TN + "_BK";

    col1 = "DEPTNO";

    whereON =
        "R." + col1 + " = X." + col1;

    string whereDEL_R = "R." + col1;
    string whereDEL_X = "X." + col1;

    colNum = 1;//★テーブルごとに設定★

    chkdata();
}

void chkdata()
{
    DataTable dt = new DataTable();

    //_BK作成
    Console.WriteLine("■BK作成...");
    strSql =
        "create table " + bkTN +
        " as select * from " + TN;
    Console.WriteLine(strSql);
    DBA_non_dt(strSql);//★置き換え必要★

    //minus:差分確認
    Console.WriteLine("■差分確認...");
    strSql =
        "select count(*) from " +
        "(select * from " + bkTN +
        " minus select * from " + repTN + ")";
    Console.WriteLine(strSql);
    dt = DBA(strSql);//★置き換え必要★
    Console.WriteLine(dt.Rows[0][0] + "件の差分あり\r\n");

    //レプリカを本体で更新
    if (dt.Rows[0][0].ToString() == "0")
    {
        Console.WriteLine("差分なし\r\n");
    }
    else
    {
        ComFunc();//update関数を実行

        //minus:差分確認(0になったかどうか)
        Console.WriteLine("■差分確認(0になったかどうか)...");
        strSql =
            "select count(*) from " +
            "(select * from " + bkTN +
            " minus select * from " + repTN + ")";
        Console.WriteLine(strSql);
        dt = DBA(strSql);//★置き換え必要★
        Console.WriteLine(dt.Rows[0][0] + "件の差分あり\r\n");

        //BKを更新後のレプリカでupdate
        repTN = bkTN + " R";//対象を入替
        xbbTN = TN + "_BK X";//対象を入替
        ComFunc();//update関数を実行

    }

    //_BK削除
    Console.WriteLine("■BK削除...");
    strSql = "drop table " + bkTN;
    Console.WriteLine(strSql);
    DBA_non_dt(strSql);//★置き換え必要★

}