Beispiel #1
0
        /// <summary>行の追加</summary>
        /// <param name="dr">行</param>
        public void Add(DTRow dr)
        {
            // 列情報が同じ場合のみ追加を許可する。
            if (this._cols.ColsInfo.Equals(dr.ColsInfo))
            {
                // 列情報が同じ
                this._rows.Add(dr);

                // 行ステータスを "Added"(追加された行) に変更
                dr.RowState = DataRowState.Added;

                // 行数をインクリメント
                this._tblStat.RowsCount++;
            }
            else
            {
                // 列情報が異なる
                throw new Exception("column information differs. ");
            }
        }
Beispiel #2
0
        /// <summary>行の生成と追加</summary>
        public DTRow AddNew()
        {
            // 列コレクションをチェック
            if (this._cols.Count == 0)
            {
                // 列がない
                throw new Exception("The column is not set up. ");
            }
            else
            {
                // 列がある
                DTRow dr = new DTRow(this._cols);

                // 行ステータスを "Added"(追加された行) に変更
                dr.RowState = DataRowState.Added;

                this._rows.Add(dr);

                // 行数をインクリメント
                this._tblStat.RowsCount++;

                return(dr);
            }
        }
Beispiel #3
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
                {
                    // 捨て
                }
            }
        }
Beispiel #4
0
        /// <summary>行の生成と追加</summary>
        public DTRow AddNew()
        {
            // 列コレクションをチェック
            if (this._cols.Count == 0)
            {
                // 列がない
                throw new Exception("The column is not set up. ");
            }
            else
            {
                // 列がある
                DTRow dr = new DTRow(this._cols);

                // 行ステータスを "Added"(追加された行) に変更
                dr.RowState = DataRowState.Added;

                this._rows.Add(dr);

                // 行数をインクリメント
                this._tblStat.RowsCount++;

                return dr;
            }
        }
Beispiel #5
0
        /// <summary>行の追加</summary>
        /// <param name="dr">行</param>
        public void Add(DTRow dr)
        {
            // 列情報が同じ場合のみ追加を許可する。
            if (this._cols.ColsInfo.Equals(dr.ColsInfo))
            {
                // 列情報が同じ
                this._rows.Add(dr);

                // 行ステータスを "Added"(追加された行) に変更
                dr.RowState = DataRowState.Added;

                // 行数をインクリメント
                this._tblStat.RowsCount++;
            }
            else
            {
                // 列情報が異なる
                throw new Exception("column information differs. ");
            }
        }
Beispiel #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
                            {
                                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
                {
                    // 捨て
                }
            }
        }
Beispiel #7
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());
                        }
                    }
                }
            }
        }
Beispiel #8
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());
                        }
                    }
                }
            }
        }