2021年3月22日月曜日

SQLを記述しないで手続きを記述したい

 SQLを記述しないで処理だけを記述したい。

そんなプログラム言語が欲しい。

テーブルをクラスに定義してもSQLを記述するのが面倒

LINQやEntity FrameworkでSQLを記述しないで済むが遅い。

DapperにするとSQLを記述しないといけない。

DapperがEntity FrameworkのようにSQLを記述してくれたらな~

 もしくは dbMAGICが C++言語のソースを出力する感じでもOK

 

2021-07-09 DapperAidという 素晴らしいライブラリがあった。

勉強不足でした。


2021年3月15日月曜日

C# SHIFT-JISで指定バイトで文字列を分割、分割時に最後の文字が漢字の左半分なら文字化けしないように全角で分割を行う

ある意味、力業

UniCodeからshift-jisに文字変換して指定バイトで文字列を分割しますが

分割の最後が全角の判定を行い、文字化けしないようにする。

 

using System;
using System.Collections.Generic;
using System.Text;

             var vList = new List<string>();
            var wordList = text.Split(new[] { "\r\n", "\n", "\r" }, StringSplitOptions.None);
            int vLoop, vStart, vLength;
            int vSize = 101;
            byte[] btBytes = null;
            string strTemp = null;
            bool vZenkaku;


            Encoding hEncoding = Encoding.GetEncoding("Shift_JIS");

            foreach (var item in wordList) {

                btBytes = hEncoding.GetBytes(item);
                vLength = btBytes.Length;

                if (vLength > vSize) {
                    vLoop = (vLength + vSize) / vSize;
                    vStart = 0;
                    for (int j = 0; j < vLoop; j++) {

                        if ((vStart + vSize) < vLength) {

                            //最後の文字が漢字の左半分の場合、切出の先頭は泣き別れになる
                            vZenkaku = is_zenkaku(btBytes[vStart + vSize - 1]);
                            if (vZenkaku) {
                                strTemp = hEncoding.GetString(btBytes, vStart, (vSize - 1));
                                vStart = vStart + vSize - 1;
                            }
                            else {
                                strTemp = hEncoding.GetString(btBytes, vStart, vSize);
                                vStart = vStart + vSize;
                            }

                            vList.Add(strTemp);
                        }
                        else {
                            //vList.Add(item.Substring(vStart, (item.Length - vStart)));
                            vList.Add(hEncoding.GetString(btBytes, vStart, (vLength - vStart)));
                        }
                    }
                }
                else {
                    vList.Add(item);
                }
            }

            foreach (var rec in vList) {
                Console.WriteLine(rec);
            }
        }

        // 全角判定(シフトJIS)
        static private bool is_zenkaku(byte c) {
            if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xfc)) {    // 全角の第1バイト
                return true;
            }
            return false;
        }

Shit-JIS 全角判定

 

全角判定

// 全角判定(シフトJIS)
is_zenkaku(char *s){
    unsigned char c = s[0];
    if ( (c>=0x81 && c<=0x9f) || (c>=0xe0 && c<=0xfc)){    // 全角の第1バイト
        c=s[1];
        if (c>=0x40 && c<=0xfc) return 1;    // 全角の第2バイト
    }
    return 0;
}


2021年3月13日土曜日

ASP.NET MVC RAZORでdesableにする方法

 ASP.NET MVC RAZORでdesableにする方法

 @Html.EditorFor(m => m.タイトル, new { htmlAttributes = new { id = "SPT_Title",
            @class = "SPT_Title", @disabled = "true" } }) 

@Html.TextAreaFor(m => m.問合せ内容,    // プロパティ
                10,                       // 行数
                600,                      // 桁数
                new { id = "SPT_Body", @class = "SPT_Body", @disabled = "true" }
            )