Example #1
0
        /// <summary>
        /// SaveJson Method(To save records in Json Format)
        /// </summary>
        /// <returns>string</returns>
        public string SaveJson()
        {
            TableRecords tableRecords = null;

            List <TableRecords> lstTableRecords = new List <TableRecords>();

            int tblNo = -1;

            foreach (DTTable dt in this._tbls)
            {
                tblNo++;

                tableRecords = new TableRecords();

                tableRecords.tbl = dt.TableName;

                tableRecords.col = new Dictionary <string, string>();
                foreach (DTColumn col in dt.Cols)
                {
                    tableRecords.col.Add(col.ColName, DTColumn.EnumToString(col.ColType));
                }

                tableRecords.row = new ArrayList();
                Dictionary <string, object> rowDetails = null;
                int colNo        = 0;
                int rowStateFlag = 0;

                foreach (DTRow dr in dt.Rows)
                {
                    rowDetails   = new Dictionary <string, object>();
                    rowStateFlag = 1;
                    foreach (DTColumn col in dt.Cols)
                    {
                        colNo = colNo + 1;
                        object colValue;
                        colValue = dr[col.ColName];

                        // add values to rowdetails based on colvalue.
                        string strTemp = CustomMarshaler.StringFromPrimitivetype(colValue, false);
                        rowDetails.Add(col.ColName, strTemp);

                        // adding rowState in rowDeatils.
                        if (rowStateFlag == 1 && colNo == dt.Cols.Count)
                        {
                            rowDetails.Add("rowstate", (int)dr.RowState);
                            rowStateFlag = 0;
                            colNo        = 0;
                        }
                    }
                    tableRecords.row.Add(rowDetails);
                }
                lstTableRecords.Add(tableRecords);
            }

            //converting the list into json format and return that string value
            string json = JsonConvert.SerializeObject(lstTableRecords);

            return(json);
        }
Example #2
0
        /// <summary>テキストとしてセーブする</summary>
        /// <param name="tw">任意のTextWriter </param>
        public void Save(TextWriter tw)
        {
            // 表番号の初期化(負荷テスト用のID用)
            int tblNo = -1;

            foreach (DTTable dt in this._tbls)
            {
                // 表番号のインクリメント
                tblNo++;

                // 表名
                tw.WriteLine("tbl:" + dt.TableName);

                tw.WriteLine("---");

                // 列情報
                foreach (DTColumn col in dt.Cols)
                {
                    tw.WriteLine("col:" + col.ColName + "," + DTColumn.EnumToString(col.ColType));
                }

                tw.WriteLine("---");

                // 行番号の初期化(負荷テスト用のID用)
                int rowNo = -1;

                // 行のセル
                foreach (DTRow dr in dt.Rows)
                {
                    // 行番号のインクリメント
                    rowNo++;

                    // 列番号の初期化(負荷テスト用のID用)
                    int colNo = -1;

                    foreach (object o in dr)
                    {
                        // 列番号のインクリメント
                        colNo++;

                        string strTemp = CustomMarshaler.StringFromPrimitivetype(o, true);
                        tw.WriteLine(
                            "cel:"
                            + tblNo.ToString() + "," + rowNo.ToString() + "," + colNo.ToString() +
                            ":" + strTemp);
                    }

                    // 行ステータス
                    tw.WriteLine("row:" + (int)dr.RowState);

                    tw.WriteLine("---");
                }
            }
        }
Example #3
0
        /// <summary>列の追加</summary>
        /// <param name="dtCol">列</param>
        public void Add(DTColumn dtCol)
        {
            // 列の確認
            if (this._tblStat.RowsCount == 0)
            {
                // 列の追加
                this._cols.Add(dtCol);

                // 列名 ⇒ 列インデックスのマップ
                if (this.ColNameIndexMap.ContainsKey(dtCol.ColName))
                {
                    // 列名が重複している。
                    throw new Exception("The column name overlaps. ");
                }
                else
                {
                    this.ColNameIndexMap.Add(dtCol.ColName, this._cols.Count - 1);
                }
            }
            else
            {
                throw new Exception("Since a row already exists, a column cannot be added. ");
            }
        }
Example #4
0
        /// <summary>列の追加</summary>
        /// <param name="dtCol">列</param>
        public void Add(DTColumn dtCol)
        {
            // 列の確認
            if (this._tblStat.RowsCount == 0)
            {
                // 列の追加
                this._cols.Add(dtCol);

                // 列名 ⇒ 列インデックスのマップ
                if (this.ColNameIndexMap.ContainsKey(dtCol.ColName))
                {
                    // 列名が重複している。
                    throw new Exception("The column name overlaps. ");
                }
                else
                {
                    this.ColNameIndexMap.Add(dtCol.ColName, this._cols.Count - 1);
                }
            }
            else
            {
                throw new Exception("Since a row already exists, a column cannot be added. ");
            }
        }
Example #5
0
        /// <summary>セルにアクセスするためのインデクサ</summary>
        /// <param name="index">インデックス</param>
        /// <returns>セルの値</returns>
        public object this[int index]
        {
            get
            {
                return(this._row[index]);
            }
            set
            {
                //object temp = null;

                // 列を確認し
                DTColumn dtCol = (DTColumn)this._cols[index];

                // 値の null チェック
                if (value == null)
                {
                    // セットする値が null または DBNull の場合は、null をセットする

                    // 2011.08.22 もともと null だった場合は何もしないように修正
                    if (this._row[index] == null)
                    {
                        // もともと null だった場合は何もしない
                        return;
                    }
                    else
                    {
                        // 設定
                        this._row[index] = null;
                    }
                }
                else
                {
                    // セットする値が null でも DBNull でもない場合は、値の型チェックを行う

                    // 型が
                    if (DTColumn.CheckType(value, dtCol.ColType))
                    {
                        // 一致
                    }
                    else
                    {
                        // 一致しない

                        // 自動変換
                        value = DTColumn.AutoCast(dtCol.ColType, value);
                    }

                    // 2011.08.22 変更前後で値が変わらなかった場合は何もしないように修正
                    if (dtCol.ColType == DTType.ByteArray)
                    {
                        if (((byte[])value).SequenceEqual((byte[])this._row[index]))
                        {
                            // 変更前後で値が変わらなかった場合は何もしない
                            return;
                        }
                        else
                        {
                            // 設定
                            this._row[index] = value;
                        }
                    }
                    else
                    {
                        if (value.Equals(this._row[index]))
                        {
                            // 変更前後で値が変わらなかった場合は何もしない
                            return;
                        }
                        else
                        {
                            // 設定
                            this._row[index] = value;
                        }
                    }
                }

                // 行ステータス
                if (this.RowState == DataRowState.Added || this.RowState == DataRowState.Deleted)
                {
                    // 行ステータスが "Added"(追加された行) または "Deleted"(削除された行) の場合は、行ステータスを変更しない
                }
                else
                {
                    // 上記以外の場合は、行ステータスを "Modified"(変更された行) に変更
                    this.RowState = DataRowState.Modified;
                }
            }
        }
Example #6
0
        /// <summary>テキストからロードする</summary>
        /// <param name="tr">任意のTextReader </param>
        public void Load(TextReader tr)
        {
            // 初期化
            this._tbls             = new List <DTTable>();
            this._tblsNameIndexMap = new Dictionary <string, int>();

            // ワーク
            string temp = "";

            DTTable  tbl = null;
            DTColumn col = null;
            DTRow    row = null;

            int bkColIndex = 0;

            while (true)
            {
                string line = tr.ReadLine();

                // 入力がなくなったら、ループを抜ける
                if (line == null)
                {
                    break;
                }

                if (line.Length >= 4) // rnn:,rnrも考慮し「>=」とした。
                {
                    switch (line.Substring(0, 4))
                    {
                    case "tbl:":

                        // 表名
                        string tblName = line.Substring(4);

                        // 表を生成
                        tbl = new DTTable(tblName);

                        // 表を追加
                        this.Add(tbl);

                        break;

                    case "col:":

                        // 列情報
                        temp = line.Substring(4);
                        string colName = temp.Split(',')[0];
                        string colType = temp.Split(',')[1];

                        // 列を生成
                        col = new DTColumn(colName, DTColumn.StringToEnum(colType));

                        // 列を追加
                        tbl.Cols.Add(col);

                        break;

                    case "row:":

                        // 行ステータス
                        row.RowState = (DataRowState)int.Parse(line.Substring(4));

                        break;

                    case "cel:":

                        // セル情報
                        temp = line.Substring(4);
                        int    clnIndex  = temp.IndexOf(":");
                        int    colIndex  = int.Parse(temp.Substring(0, clnIndex).Split(',')[2]);
                        string celString = temp.Substring(clnIndex + 1);

                        // 列インデックスをチェック
                        if (colIndex == 0)
                        {
                            // 新しい行
                            row = tbl.Rows.AddNew();
                        }
                        else
                        {
                            // 継続行
                        }

                        // セルに値を設定
                        if (celString == "null")
                        {
                            // row[colIndex] = null;
                        }
                        else
                        {
                            // 列情報
                            col = (DTColumn)tbl.Cols.ColsInfo[colIndex];

                            if (col.ColType == DTType.String)
                            {
                                // そのまま
                                row[colIndex] = celString;
                                // インデックスを退避
                                bkColIndex = colIndex;
                            }
                            else if (col.ColType == DTType.ByteArray)
                            {
                                // バイト配列は、Base64デコードする。
                                byte[] celByte = Convert.FromBase64String(celString);
                                row[colIndex] = celByte;
                            }
                            else if (col.ColType == DTType.DateTime)
                            {
                                // DateTimeは、yyyy/M/d-H:m:s.fff
                                string ymd  = celString.Split('-')[0];
                                string hmsf = celString.Split('-')[1];

                                DateTime cellDttm = new DateTime(
                                    int.Parse(ymd.Split('/')[0]),
                                    int.Parse(ymd.Split('/')[1]),
                                    int.Parse(ymd.Split('/')[2]),
                                    int.Parse(hmsf.Split(':')[0]),
                                    int.Parse(hmsf.Split(':')[1]),
                                    int.Parse(hmsf.Split(':')[2].Split('.')[0]),
                                    int.Parse(hmsf.Split(':')[2].Split('.')[1]));

                                row[colIndex] = cellDttm;
                            }
                            else
                            {
                                // 型変換を試みる。
                                row[colIndex] = DTColumn.AutoCast(col.ColType, celString);
                            }
                        }

                        break;

                    case "rnr:":

                        // 文字列の続き

                        temp             = line.Substring(4);
                        row[bkColIndex] += "\r" + temp;

                        break;

                    case "rnn:":

                        // 文字列の続き

                        temp             = line.Substring(4);
                        row[bkColIndex] += "\n" + temp;

                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    // 捨て
                }
            }
        }
Example #7
0
        /// <summary>テキストとしてセーブする</summary>
        /// <param name="tw">任意のTextWriter </param>
        public void Save(TextWriter tw)
        {
            // 表番号の初期化(負荷テスト用のID用)
            int tblNo = -1;

            foreach (DTTable dt in this._tbls)
            {
                // 表番号のインクリメント
                tblNo++;

                // 表名
                tw.WriteLine("tbl:" + dt.TableName);

                tw.WriteLine("---");

                // 列情報
                foreach (DTColumn col in dt.Cols)
                {
                    tw.WriteLine("col:" + col.ColName + "," + DTColumn.EnumToString(col.ColType));
                }

                tw.WriteLine("---");

                // 行番号の初期化(負荷テスト用のID用)
                int rowNo = -1;

                // 行のセル
                foreach (DTRow dr in dt.Rows)
                {
                    // 行番号のインクリメント
                    rowNo++;

                    // 列番号の初期化(負荷テスト用のID用)
                    int colNo = -1;

                    foreach (object o in dr)
                    {
                        // 列番号のインクリメント
                        colNo++;

                        if (o == null)
                        {
                            // null値はnullと出力する。
                            tw.WriteLine(
                                "cel:"
                                + tblNo.ToString() + "," + rowNo.ToString() + "," + colNo.ToString() +
                                ":" + "null");
                        }
                        else if (DTColumn.CheckType(o, DTType.String))
                        {
                            // 文字列は改行を処理する
                            string strTemp = ((string)o);
                            strTemp = strTemp.Replace("\r", "\rrnr:");
                            strTemp = strTemp.Replace("\n", "\rrnn:");

                            strTemp = strTemp.Replace("\r", "\r\n");
                            tw.WriteLine(
                                "cel:"
                                + tblNo.ToString() + "," + rowNo.ToString() + "," + colNo.ToString() +
                                ":" + strTemp);
                        }
                        else if (DTColumn.CheckType(o, DTType.ByteArray))
                        {
                            // バイト配列は、Base64エンコードして電文に乗せる
                            string strBase64 = Convert.ToBase64String((byte[])o);
                            tw.WriteLine(
                                "cel:"
                                + tblNo.ToString() + "," + rowNo.ToString() + "," + colNo.ToString() +
                                ":" + strBase64);
                        }
                        else if (DTColumn.CheckType(o, DTType.DateTime))
                        {
                            // DateTimeは、yyyy/M/d-H:m:s.fffとする。
                            DateTime dttm    = (DateTime)o;
                            string   strDttm = "";

                            strDttm += dttm.Year + "/";
                            strDttm += dttm.Month + "/";
                            strDttm += dttm.Day + "-";

                            strDttm += dttm.Hour + ":";
                            strDttm += dttm.Minute + ":";
                            strDttm += dttm.Second + ".";
                            strDttm += dttm.Millisecond;

                            tw.WriteLine(
                                "cel:"
                                + tblNo.ToString() + "," + rowNo.ToString() + "," + colNo.ToString() +
                                ":" + strDttm);
                        }
                        else
                        {
                            // 通常通り、ToStringして出力
                            tw.WriteLine(
                                "cel:"
                                + tblNo.ToString() + "," + rowNo.ToString() + "," + colNo.ToString() +
                                ":" + o.ToString());
                        }
                    }

                    // 行ステータス
                    tw.WriteLine("row:" + (int)dr.RowState);

                    tw.WriteLine("---");
                }
            }
        }
Example #8
0
        /// <summary>テキストからロードする</summary>
        /// <param name="tr">任意のTextReader </param>
        public void Load(TextReader tr)
        {
            // 初期化
            this._tbls = new List<DTTable>();
            this._tblsNameIndexMap = new Dictionary<string, int>();

            // ワーク
            string temp = "";

            DTTable tbl = null;
            DTColumn col = null;
            DTRow row = null;

            int bkColIndex = 0;

            while (true)
            {
                string line = tr.ReadLine();

                // 入力がなくなったら、ループを抜ける
                if (line == null) { break; }

                if (line.Length >= 4) // rnn:,rnrも考慮し「>=」とした。
                {
                    switch (line.Substring(0, 4))
                    {
                        case "tbl:":

                            // 表名
                            string tblName = line.Substring(4);

                            // 表を生成
                            tbl = new DTTable(tblName);

                            // 表を追加
                            this.Add(tbl);

                            break;

                        case "col:":

                            // 列情報
                            temp = line.Substring(4);
                            string colName = temp.Split(',')[0];
                            string colType = temp.Split(',')[1];

                            // 列を生成
                            col = new DTColumn(colName, DTColumn.StringToEnum(colType));

                            // 列を追加
                            tbl.Cols.Add(col);

                            break;

                        case "row:":

                            // 行ステータス
                            row.RowState = (DataRowState)int.Parse(line.Substring(4));

                            break;

                        case "cel:":

                            // セル情報
                            temp = line.Substring(4);
                            int clnIndex = temp.IndexOf(":");
                            int colIndex = int.Parse(temp.Substring(0, clnIndex).Split(',')[2]);
                            string celString = temp.Substring(clnIndex + 1);

                            // 列インデックスをチェック
                            if (colIndex == 0)
                            {
                                // 新しい行
                                row = tbl.Rows.AddNew();
                            }
                            else
                            {
                                // 継続行
                            }

                            // セルに値を設定
                            if (celString == "null")
                            {
                                // row[colIndex] = null;
                            }
                            else
                            {
                                // 列情報
                                col = (DTColumn)tbl.Cols.ColsInfo[colIndex];

                                if (col.ColType == DTType.String)
                                {
                                    // そのまま
                                    row[colIndex] = celString;
                                    // インデックスを退避
                                    bkColIndex = colIndex;
                                }
                                else if (col.ColType == DTType.ByteArray)
                                {
                                    // バイト配列は、Base64デコードする。
                                    byte[] celByte = Convert.FromBase64String(celString);
                                    row[colIndex] = celByte;
                                }
                                else if (col.ColType == DTType.DateTime)
                                {
                                    // DateTimeは、yyyy/M/d-H:m:s.fff
                                    string ymd = celString.Split('-')[0];
                                    string hmsf = celString.Split('-')[1];

                                    DateTime cellDttm = new DateTime(
                                        int.Parse(ymd.Split('/')[0]),
                                        int.Parse(ymd.Split('/')[1]),
                                        int.Parse(ymd.Split('/')[2]),
                                        int.Parse(hmsf.Split(':')[0]),
                                        int.Parse(hmsf.Split(':')[1]),
                                        int.Parse(hmsf.Split(':')[2].Split('.')[0]),
                                        int.Parse(hmsf.Split(':')[2].Split('.')[1]));

                                    row[colIndex] = cellDttm;
                                }
                                else
                                {
                                    // 型変換を試みる。
                                    row[colIndex] = DTColumn.AutoCast(col.ColType, celString);
                                }
                            }

                            break;

                        case "rnr:":

                            // 文字列の続き

                            temp = line.Substring(4);
                            row[bkColIndex] += "\r" + temp;

                            break;

                        case "rnn:":

                            // 文字列の続き

                            temp = line.Substring(4);
                            row[bkColIndex] += "\n" + temp;

                            break;

                        default:
                            break;
                    }
                }
                else
                {
                    // 捨て
                }
            }
        }
Example #9
0
        /// <summary>テキストからロードする</summary>
        /// <param name="tr">任意のTextReader </param>
        public void Load(TextReader tr)
        {
            // 初期化
            this._tbls = new List<DTTable>();
            this._tblsNameIndexMap = new Dictionary<string, int>();

            // ワーク
            string temp = "";

            DTTable tbl = null;
            DTColumn col = null;
            DTRow row = null;

            int bkColIndex = 0;

            while (true)
            {
                string line = tr.ReadLine();

                // 入力がなくなったら、ループを抜ける
                if (line == null) { break; }

                if (line.Length >= 4) // rnn:,rnrも考慮し「>=」とした。
                {
                    switch (line.Substring(0, 4))
                    {
                        case "tbl:":

                            // 表名
                            string tblName = line.Substring(4);

                            // 表を生成
                            tbl = new DTTable(tblName);

                            // 表を追加
                            this.Add(tbl);

                            break;

                        case "col:":

                            // 列情報
                            temp = line.Substring(4);
                            string colName = temp.Split(',')[0];
                            string colType = temp.Split(',')[1];

                            // 列を生成
                            col = new DTColumn(colName, DTColumn.StringToEnum(colType));

                            // 列を追加
                            tbl.Cols.Add(col);

                            break;

                        case "row:":

                            // 行ステータス
                            row.RowState = (DataRowState)int.Parse(line.Substring(4));

                            break;

                        case "cel:":

                            // セル情報
                            temp = line.Substring(4);
                            int clnIndex = temp.IndexOf(":");
                            int colIndex = int.Parse(temp.Substring(0, clnIndex).Split(',')[2]);
                            string celString = temp.Substring(clnIndex + 1);

                            // 列インデックスをチェック
                            if (colIndex == 0)
                            {
                                // 新しい行
                                row = tbl.Rows.AddNew();
                            }
                            else
                            {
                                // 継続行
                            }

                            // セルに値を設定
                            if (celString == "null")
                            {
                                // row[colIndex] = null;
                            }
                            else
                            {
                                col = (DTColumn)tbl.Cols.ColsInfo[colIndex];
                                if (col.ColType == DTType.String)
                                {
                                    // そのまま
                                    row[colIndex] = celString;
                                    // インデックスを退避
                                    bkColIndex = colIndex;
                                }
                                else
                                {
                                    object primitiveData = CustomMarshaler.PrimitivetypeFromString(col.ColType, celString.ToString());
                                    row[colIndex] = primitiveData;
                                }
                            }

                            break;

                        case "rnr:":

                            // 文字列の続き

                            temp = line.Substring(4);
                            row[bkColIndex] += "\r" + temp;

                            break;

                        case "rnn:":

                            // 文字列の続き

                            temp = line.Substring(4);
                            row[bkColIndex] += "\n" + temp;

                            break;

                        default:
                            break;
                    }
                }
                else
                {
                    // 捨て
                }
            }
        }
Example #10
0
        /// <summary>セルにアクセスするためのインデクサ</summary>
        /// <param name="index">インデックス</param>
        /// <returns>セルの値</returns>
        public object this[int index]
        {
            get
            {
                return(this._row[index]);
            }
            set
            {
                //object temp = null;

                // 列を確認し
                DTColumn dtCol = (DTColumn)this._cols[index];

                // 値の null チェック
                if (value == null || value is System.DBNull)
                {
                    // セットする値が null または DBNull の場合は、null をセットする

                    // 2011.08.22 もともと null だった場合は何もしないように修正
                    if (this._row[index] == null)
                    {
                        // もともと null だった場合は何もしない
                        return;
                    }
                    else
                    {
                        // 設定
                        this._row[index] = null;
                    }
                }
                else
                {
                    // セットする値が null でも DBNull でもない場合は、値の型チェックを行う

                    // 型が
                    if (DTColumn.CheckType(value, dtCol.ColType))
                    {
                        // 一致
                    }
                    else
                    {
                        // 一致しない

                        // 自動変換
                        value = DTColumn.AutoCast(dtCol.ColType, value);
                    }

                    // 2011.08.22 変更前後で値が変わらなかった場合は何もしないように修正
                    if (dtCol.ColType == DTType.ByteArray)
                    {
                        int len = ((byte[])value).Length;

                        // nullチェック
                        if (this._row[index] == null)
                        {
                            // nullの場合、設定
                            this._row[index] = value;
                        }
                        else
                        {
                            // nullでない場合、チェック
                            if (((byte[])this._row[index]).Length == len)
                            {
                                // 変更フラグ
                                bool isChanged = false;

                                // ループ
                                for (int i = 0; i < len; i++)
                                {
                                    if (((byte)(((byte[])this._row[index])[i])) != ((byte)((byte[])value)[i]))
                                    {
                                        // 異なる場合、設定して
                                        this._row[index] = value;
                                        // フラグを立てて
                                        isChanged = true;
                                        // ブレイク
                                        break;
                                    }
                                }

                                // 変更されていない場合、
                                if (!isChanged)
                                {
                                    // 変更前後で値が変わらなかった場合は何もしない
                                    return;
                                }
                            }
                            else
                            {
                                // 異なる場合、設定
                                this._row[index] = value;
                            }

                            //if (((byte[])value).SequenceEqual((byte[])this._row[index]))
                            //{
                            //    // 変更前後で値が変わらなかった場合は何もしない
                            //    return;
                            //}
                            //else
                            //{
                            //    // 設定
                            //    this._row[index] = value;
                            //}
                        }
                    }
                    else
                    {
                        if (value.Equals(this._row[index]))
                        {
                            // 変更前後で値が変わらなかった場合は何もしない
                            return;
                        }
                        else
                        {
                            // 設定
                            this._row[index] = value;
                        }
                    }
                }

                // 行ステータス
                if (this.RowState == DataRowState.Added || this.RowState == DataRowState.Deleted)
                {
                    // 行ステータスが "Added"(追加された行) または "Deleted"(削除された行) の場合は、行ステータスを変更しない
                }
                else
                {
                    // 上記以外の場合は、行ステータスを "Modified"(変更された行) に変更
                    this.RowState = DataRowState.Modified;
                }
            }
        }
Example #11
0
        /// <summary>テキストからロードする</summary>
        /// <param name="tr">任意のTextReader </param>
        public void Load(TextReader tr)
        {
            // 初期化
            this._tbls             = new List <DTTable>();
            this._tblsNameIndexMap = new Dictionary <string, int>();

            // ワーク
            string temp = "";

            DTTable  tbl = null;
            DTColumn col = null;
            DTRow    row = null;

            int bkColIndex = 0;

            while (true)
            {
                string line = tr.ReadLine();

                // 入力がなくなったら、ループを抜ける
                if (line == null)
                {
                    break;
                }

                if (line.Length >= 4) // rnn:,rnrも考慮し「>=」とした。
                {
                    switch (line.Substring(0, 4))
                    {
                    case "tbl:":

                        // 表名
                        string tblName = line.Substring(4);

                        // 表を生成
                        tbl = new DTTable(tblName);

                        // 表を追加
                        this.Add(tbl);

                        break;

                    case "col:":

                        // 列情報
                        temp = line.Substring(4);
                        string colName = temp.Split(',')[0];
                        string colType = temp.Split(',')[1];

                        // 列を生成
                        col = new DTColumn(colName, DTColumn.StringToEnum(colType));

                        // 列を追加
                        tbl.Cols.Add(col);

                        break;

                    case "row:":

                        // 行ステータス
                        row.RowState = (DataRowState)int.Parse(line.Substring(4));

                        break;

                    case "cel:":

                        // セル情報
                        temp = line.Substring(4);
                        int    clnIndex  = temp.IndexOf(":");
                        int    colIndex  = int.Parse(temp.Substring(0, clnIndex).Split(',')[2]);
                        string celString = temp.Substring(clnIndex + 1);

                        // 列インデックスをチェック
                        if (colIndex == 0)
                        {
                            // 新しい行
                            row = tbl.Rows.AddNew();
                        }
                        else
                        {
                            // 継続行
                        }

                        // セルに値を設定
                        if (celString == "null")
                        {
                            // row[colIndex] = null;
                        }
                        else
                        {
                            col = (DTColumn)tbl.Cols.ColsInfo[colIndex];
                            if (col.ColType == DTType.String)
                            {
                                // そのまま
                                row[colIndex] = celString;
                                // インデックスを退避
                                bkColIndex = colIndex;
                            }
                            else
                            {
                                object primitiveData = CustomMarshaler.PrimitivetypeFromString(col.ColType, celString.ToString());
                                row[colIndex] = primitiveData;
                            }
                        }

                        break;

                    case "rnr:":

                        // 文字列の続き

                        temp             = line.Substring(4);
                        row[bkColIndex] += "\r" + temp;

                        break;

                    case "rnn:":

                        // 文字列の続き

                        temp             = line.Substring(4);
                        row[bkColIndex] += "\n" + temp;

                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    // 捨て
                }
            }
        }
Example #12
0
        /// <summary>
        /// LoadJson Method(To Load records from Json format)
        /// </summary>
        /// <param name="sr">StreamReader</param>
        public void LoadJson(StreamReader sr)
        {
            List <TableRecords> lstTableRecords = new List <TableRecords>();
            string json = sr.ReadToEnd();

            lstTableRecords = JsonConvert.DeserializeObject <List <TableRecords> >(json);

            DTTable  tbl        = null;
            DTColumn col        = null;
            DTRow    row        = null;
            int      bkColIndex = 0;

            for (int i = 0; i < lstTableRecords.Count; i++)
            {
                string tblName = lstTableRecords[i].tbl;

                //add the DTTable present in lstTableRecords into tbl
                tbl = new DTTable(tblName);

                // add the tbl into DTTables
                this.Add(tbl);

                Dictionary <string, string> tempCol = lstTableRecords[i].col;

                foreach (string key in tempCol.Keys)
                {
                    string colName = key;
                    string colType = tempCol[key];

                    //add the colName and colValue into DTColumn
                    col = new DTColumn(colName, DTColumn.StringToEnum(colType));

                    // add the col into tbl
                    tbl.Cols.Add(col);
                }

                ArrayList tempRow = lstTableRecords[i].row;
                for (int j = 0; j < lstTableRecords[i].row.Count; j++)
                {
                    //deserialize the first value inside row of lstTableRecords
                    object rowJson = JsonConvert.DeserializeObject(lstTableRecords[i].row[j].ToString());

                    //Convert the deserialized value into dictionary
                    Dictionary <string, object> rowDetails = JsonConvert.DeserializeObject <Dictionary <string, object> >(rowJson.ToString());

                    int colIndex = 0;
                    if (colIndex == 0)
                    {
                        // add new row
                        row = tbl.Rows.AddNew();
                    }
                    else
                    {
                        // do nothing
                    }
                    foreach (var key in rowDetails)
                    {
                        string colName  = key.Key;
                        object colValue = rowDetails[colName];
                        // getting the values and adding it to rows
                        if (colName != "rowstate")
                        {
                            col = (DTColumn)tbl.Cols.ColsInfo[colIndex];
                            if (colValue == null)
                            {
                                row[colIndex] = null;
                            }
                            else if (col.ColType == DTType.String)
                            {
                                // そのまま
                                row[colIndex] = colValue;
                                // インデックスを退避
                                bkColIndex = colIndex;
                            }
                            else if (col.ColType == DTType.ByteArray)
                            {
                                // バイト配列は、Base64デコードする。
                                byte[] celByte = Convert.FromBase64String(colValue.ToString());
                                row[colIndex] = celByte;
                            }
                            else if (col.ColType == DTType.DateTime)
                            {
                                // DateTimeは、yyyy/M/d-H:m:s.fff
                                string ymd  = colValue.ToString().Split('-')[0];
                                string hmsf = colValue.ToString().Split('-')[1];

                                DateTime cellDttm = new DateTime(
                                    int.Parse(ymd.Split('/')[0]),
                                    int.Parse(ymd.Split('/')[1]),
                                    int.Parse(ymd.Split('/')[2]),
                                    int.Parse(hmsf.Split(':')[0]),
                                    int.Parse(hmsf.Split(':')[1]),
                                    int.Parse(hmsf.Split(':')[2].Split('.')[0]),
                                    int.Parse(hmsf.Split(':')[2].Split('.')[1]));

                                row[colIndex] = cellDttm;
                            }
                            else
                            {
                                // 型変換を試みる。
                                row[colIndex] = DTColumn.AutoCast(col.ColType, colValue.ToString());
                            }

                            colIndex = colIndex + 1;
                        }
                        else
                        {
                            row.RowState = (DataRowState)(int.Parse)(colValue.ToString());
                        }
                    }
                }
            }
        }
Example #13
0
        /// <summary>
        /// SaveJson Method(To save records in Json Format)
        /// </summary>
        /// <returns>string</returns>
        public string SaveJson()
        {
            TableRecords        tableRecords    = null;
            List <TableRecords> lstTableRecords = new List <TableRecords>();

            int tblNo = -1;

            foreach (DTTable dt in this._tbls)
            {
                tblNo++;

                tableRecords = new TableRecords();

                tableRecords.tbl = dt.TableName;

                tableRecords.col = new Dictionary <string, string>();
                foreach (DTColumn col in dt.Cols)
                {
                    tableRecords.col.Add(col.ColName, DTColumn.EnumToString(col.ColType));
                }

                tableRecords.row = new ArrayList();
                Dictionary <string, object> rowDetails = null;
                int colNo        = 0;
                int rowStateFlag = 0;

                foreach (DTRow dr in dt.Rows)
                {
                    rowDetails   = new Dictionary <string, object>();
                    rowStateFlag = 1;
                    foreach (DTColumn col in dt.Cols)
                    {
                        colNo = colNo + 1;
                        object colValue;
                        colValue = dr[col.ColName];
                        if (colValue == null)
                        {
                            //add null to rowDetails
                            rowDetails.Add(col.ColName, null);
                        }
                        else if (DTColumn.CheckType(colValue, DTType.String))
                        {
                            string strTemp = ((string)colValue);
                            rowDetails.Add(col.ColName, strTemp);
                        }
                        else if (DTColumn.CheckType(colValue, DTType.ByteArray))
                        {
                            // バイト配列は、Base64エンコードして電文に乗せる
                            string strBase64 = Convert.ToBase64String((byte[])colValue);
                            rowDetails.Add(col.ColName, strBase64);
                        }
                        else if (DTColumn.CheckType(colValue, DTType.DateTime))
                        {
                            // DateTimeは、yyyy/M/d-H:m:s.fffとする。
                            DateTime dttm    = (DateTime)colValue;
                            string   strDttm = "";

                            strDttm += dttm.Year + "/";
                            strDttm += dttm.Month + "/";
                            strDttm += dttm.Day + "-";

                            strDttm += dttm.Hour + ":";
                            strDttm += dttm.Minute + ":";
                            strDttm += dttm.Second + ".";
                            strDttm += dttm.Millisecond;
                            rowDetails.Add(col.ColName, strDttm);
                        }
                        else
                        {
                            rowDetails.Add(col.ColName, colValue.ToString());
                        }
                        //adding rowState in rowDeatils
                        if (rowStateFlag == 1 && colNo == dt.Cols.Count)
                        {
                            rowDetails.Add("rowstate", (int)dr.RowState);
                            rowStateFlag = 0;
                            colNo        = 0;
                        }
                    }
                    tableRecords.row.Add(rowDetails);
                }
                lstTableRecords.Add(tableRecords);
            }

            //converting the list into json format and return that string value
            string json = JsonConvert.SerializeObject(lstTableRecords);

            return(json);
        }
Example #14
0
        /// <summary>
        /// LoadJson Method(To Load records from Json format)
        /// </summary>
        /// <param name="sr">StreamReader</param>
        public void LoadJson(StreamReader sr)
        {
            List<TableRecords> lstTableRecords = new List<TableRecords>();
            string json = sr.ReadToEnd();
            lstTableRecords = JsonConvert.DeserializeObject<List<TableRecords>>(json);

            DTTable tbl = null;
            DTColumn col = null;
            DTRow row = null;
            int bkColIndex = 0;
            for (int i = 0; i < lstTableRecords.Count; i++)
            {
                string tblName = lstTableRecords[i].tbl;

                //add the DTTable present in lstTableRecords into tbl
                tbl = new DTTable(tblName);

                // add the tbl into DTTables
                this.Add(tbl);

                Dictionary<string, string> tempCol = lstTableRecords[i].col;

                foreach (string key in tempCol.Keys)
                {
                    string colName = key;
                    string colType = tempCol[key];

                    //add the colName and colValue into DTColumn
                    col = new DTColumn(colName, DTColumn.StringToEnum(colType));

                    // add the col into tbl
                    tbl.Cols.Add(col);
                }

                ArrayList tempRow = lstTableRecords[i].row;
                for (int j = 0; j < lstTableRecords[i].row.Count; j++)
                {
                    //deserialize the first value inside row of lstTableRecords
                    object rowJson = JsonConvert.DeserializeObject(lstTableRecords[i].row[j].ToString());

                    //Convert the deserialized value into dictionary
                    Dictionary<string, object> rowDetails = JsonConvert.DeserializeObject<Dictionary<string, object>>(rowJson.ToString());

                    int colIndex = 0;
                    if (colIndex == 0)
                    {
                        // add new row
                        row = tbl.Rows.AddNew();
                    }
                    else
                    {
                        // do nothing
                    }
                    foreach (var key in rowDetails)
                    {
                        string colName = key.Key;
                        object colValue = rowDetails[colName];

                        // getting the values and adding it to rows
                        if (colName != "rowstate")
                        {
                            col = (DTColumn)tbl.Cols.ColsInfo[colIndex];

                            if (colValue == null)
                            {
                                row[colIndex] = null;
                            }
                            else if (col.ColType == DTType.String)
                            {
                                // そのまま
                                row[colIndex] = colValue;
                                // インデックスを退避
                                bkColIndex = colIndex;
                            }
                            else
                            {
                                object primitiveData = CustomMarshaler.PrimitivetypeFromString(col.ColType, colValue.ToString());
                                row[colIndex] = primitiveData;
                            }
                            colIndex = colIndex + 1;
                        }
                        else
                        {
                            row.RowState = (DataRowState)(int.Parse)(colValue.ToString());
                        }
                    }
                }
            }
        }
Example #15
0
        /// <summary>
        /// LoadJson Method(To Load records from Json format)
        /// </summary>
        /// <param name="sr">StreamReader</param>
        public void LoadJson(StreamReader sr)
        {
            List <TableRecords> lstTableRecords = new List <TableRecords>();
            string json = sr.ReadToEnd();

            lstTableRecords = JsonConvert.DeserializeObject <List <TableRecords> >(json);

            DTTable  tbl        = null;
            DTColumn col        = null;
            DTRow    row        = null;
            int      bkColIndex = 0;

            for (int i = 0; i < lstTableRecords.Count; i++)
            {
                string tblName = lstTableRecords[i].tbl;

                //add the DTTable present in lstTableRecords into tbl
                tbl = new DTTable(tblName);

                // add the tbl into DTTables
                this.Add(tbl);

                Dictionary <string, string> tempCol = lstTableRecords[i].col;

                foreach (string key in tempCol.Keys)
                {
                    string colName = key;
                    string colType = tempCol[key];

                    //add the colName and colValue into DTColumn
                    col = new DTColumn(colName, DTColumn.StringToEnum(colType));

                    // add the col into tbl
                    tbl.Cols.Add(col);
                }

                ArrayList tempRow = lstTableRecords[i].row;
                for (int j = 0; j < lstTableRecords[i].row.Count; j++)
                {
                    //deserialize the first value inside row of lstTableRecords
                    object rowJson = JsonConvert.DeserializeObject(lstTableRecords[i].row[j].ToString());

                    //Convert the deserialized value into dictionary
                    Dictionary <string, object> rowDetails = JsonConvert.DeserializeObject <Dictionary <string, object> >(rowJson.ToString());

                    int colIndex = 0;
                    if (colIndex == 0)
                    {
                        // add new row
                        row = tbl.Rows.AddNew();
                    }
                    else
                    {
                        // do nothing
                    }
                    foreach (var key in rowDetails)
                    {
                        string colName  = key.Key;
                        object colValue = rowDetails[colName];

                        // getting the values and adding it to rows
                        if (colName != "rowstate")
                        {
                            col = (DTColumn)tbl.Cols.ColsInfo[colIndex];

                            if (colValue == null)
                            {
                                row[colIndex] = null;
                            }
                            else if (col.ColType == DTType.String)
                            {
                                // そのまま
                                row[colIndex] = colValue;
                                // インデックスを退避
                                bkColIndex = colIndex;
                            }
                            else
                            {
                                object primitiveData = CustomMarshaler.PrimitivetypeFromString(col.ColType, colValue.ToString());
                                row[colIndex] = primitiveData;
                            }
                            colIndex = colIndex + 1;
                        }
                        else
                        {
                            row.RowState = (DataRowState)(int.Parse)(colValue.ToString());
                        }
                    }
                }
            }
        }
Example #16
0
        /// <summary>
        /// LoadJson Method(To Load records from Json format)
        /// </summary>
        /// <param name="sr">StreamReader</param>
        public void LoadJson(StreamReader sr)
        {
            List<TableRecords> lstTableRecords = new List<TableRecords>();
            string json = sr.ReadToEnd();
            lstTableRecords = JsonConvert.DeserializeObject<List<TableRecords>>(json);

            DTTable tbl = null;
            DTColumn col = null;
            DTRow row = null;
            int bkColIndex = 0;
            for (int i = 0; i < lstTableRecords.Count; i++)
            {
                string tblName = lstTableRecords[i].tbl;

                //add the DTTable present in lstTableRecords into tbl
                tbl = new DTTable(tblName);

                // add the tbl into DTTables
                this.Add(tbl);

                Dictionary<string, string> tempCol = lstTableRecords[i].col;
               
                foreach (string key in tempCol.Keys)
                {
                    string colName = key;
                    string colType = tempCol[key];
                    
                    //add the colName and colValue into DTColumn
                    col = new DTColumn(colName, DTColumn.StringToEnum(colType));

                    // add the col into tbl
                    tbl.Cols.Add(col);
                }

                ArrayList tempRow = lstTableRecords[i].row;              
                for (int j = 0; j < lstTableRecords[i].row.Count; j++)
                {
                    //deserialize the first value inside row of lstTableRecords
                    object rowJson = JsonConvert.DeserializeObject(lstTableRecords[i].row[j].ToString());
                    
                    //Convert the deserialized value into dictionary
                    Dictionary<string, object> rowDetails = JsonConvert.DeserializeObject<Dictionary<string, object>>(rowJson.ToString());
                  
                    int colIndex = 0;
                    if (colIndex == 0)
                    {
                        // add new row
                        row = tbl.Rows.AddNew();
                    }
                    else
                    {
                        // do nothing
                    }
                    foreach (var key in rowDetails)
                    {
                        string colName = key.Key;
                        object colValue = rowDetails[colName];
                        // getting the values and adding it to rows
                        if (colName != "rowstate")
                        {
                            col = (DTColumn)tbl.Cols.ColsInfo[colIndex];
                            if (colValue == null)
                            {
                                row[colIndex] = null;
                            }
                            else if (col.ColType == DTType.String)
                            {
                                // そのまま
                                row[colIndex] = colValue;
                                // インデックスを退避
                                bkColIndex = colIndex;
                            }
                            else if (col.ColType == DTType.ByteArray)
                            {
                                // バイト配列は、Base64デコードする。
                                byte[] celByte = Convert.FromBase64String(colValue.ToString());
                                row[colIndex] = celByte;
                            }
                            else if (col.ColType == DTType.DateTime)
                            {
                                // DateTimeは、yyyy/M/d-H:m:s.fff
                                string ymd = colValue.ToString().Split('-')[0];
                                string hmsf = colValue.ToString().Split('-')[1];

                                DateTime cellDttm = new DateTime(
                                    int.Parse(ymd.Split('/')[0]),
                                    int.Parse(ymd.Split('/')[1]),
                                    int.Parse(ymd.Split('/')[2]),
                                    int.Parse(hmsf.Split(':')[0]),
                                    int.Parse(hmsf.Split(':')[1]),
                                    int.Parse(hmsf.Split(':')[2].Split('.')[0]),
                                    int.Parse(hmsf.Split(':')[2].Split('.')[1]));

                                row[colIndex] = cellDttm;
                            }
                            else
                            {
                                // 型変換を試みる。
                                row[colIndex] = DTColumn.AutoCast(col.ColType, colValue.ToString());
                            }

                            colIndex = colIndex + 1;
                        }
                        else
                        {
                            row.RowState = (DataRowState)(int.Parse)(colValue.ToString());
                        }
                    }
                }
            }
        }