Esempio n. 1
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;
                }
            }
        }
Esempio n. 2
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;
                }
            }
        }
Esempio n. 3
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("---");
                }
            }
        }
Esempio n. 4
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);
        }