示例#1
0
        /// <summary>
        /// System.Data.DataTableをDTTableに変換する
        /// </summary>
        /// <param name="table">変換元のSystem.Data.DataTable</param>
        /// <returns>変換後のDTTable</returns>
        public static DTTable FromDataTable(DataTable table)
        {
            // テーブル定義
            DTTable dt = new DTTable(table.TableName);

            // 列定義
            foreach (DataColumn col in table.Columns)
            {
                DTType type = ConvertTypeToDTType(col.DataType);
                dt.Cols.Add(new DTColumn(col.ColumnName, type));
            }

            // 値追加(削除された行以外)
            DTRow dr;

            foreach (DataRow row in table.Rows)
            {
                // 行をテーブルに追加
                dr = dt.Rows.AddNew();

                // 各列ごとに値を追加
                foreach (DataColumn col in table.Columns)
                {
                    if (row.RowState != System.Data.DataRowState.Deleted)
                    {
                        dr[col.ColumnName] = row[col.ColumnName];
                    }
                    else
                    {
                        // 行が削除されている場合は、元の値を取得する
                        dr[col.ColumnName] = row[col.ColumnName, DataRowVersion.Original];
                    }
                }

                // 行ステータスを復元
                if (row.RowState == System.Data.DataRowState.Detached)
                {
                    dr.RowState = DataRowState.Detached;
                }
                else if (row.RowState == System.Data.DataRowState.Added)
                {
                    dr.RowState = DataRowState.Added;
                }
                else if (row.RowState == System.Data.DataRowState.Modified)
                {
                    dr.RowState = DataRowState.Modified;
                }
                else if (row.RowState == System.Data.DataRowState.Deleted)
                {
                    dr.RowState = DataRowState.Deleted;
                }
                else
                {
                    dr.RowState = DataRowState.Unchanged;
                }
            }

            // DTTableを返す
            return(dt);
        }
        /// <summary>ListViewの初期化</summary>
        async private void InitListView()
        {
            // テーブル@汎用DTOにデータを詰めてバインディングさせる。

            // 引数1:コンテキスト
            string Context = "User1";

            // 引数2:共通部
            MuServiceReference.ArrayOfString param
                = new MuServiceReference.ArrayOfString();

            // 共通部を生成
            param.Add(this.Name);               // 画面名
            param.Add("Page_Loaded");           // ボタン名
            param.Add("InitDataGrid");          // メソッド名
            param.Add("ActionType");            // アクションタイプ

            // 引数3:汎用DTOデータ部

            // 空のDTTables
            DTTables dtts = new DTTables();
            dtts.Add(this.Dtt);

            // 汎用サービスI/FのWebサービスは通常のWeb参照を用いる。
            MuServiceReference.ServiceForMuSoapClient client = new MuServiceReference.ServiceForMuSoapClient();

            // 非同期呼出しを行う
            MuServiceReference.CallResponse response = await client.CallAsync(Context, "muWebService", param, DTTables.DTTablesToString(dtts));

            // データバインド(ToDataSourceでは、削除行を除いたリストを返す)
            this.Dtt = DTTables.StringToDTTables(response.Body.returnValue)[0];
            this.ListView1.ItemsSource = this.Dtt.Rows.ToDataSource();
        }
    /// <summary>
    /// GetProductData method for fetching product table data.
    /// </summary>
    public Message GetProductData()
    {
        HttpContext.Current.Session["DAP"] = "SQL";
        HttpContext.Current.Session["DBMS"] = DbEnum.DBMSType.SQLServer;

        NameValueCollection queryStrings = HttpContext.Current.Request.QueryString;

        HttpContext.Current.Session["SortExpression"] = queryStrings["sidx"];
        HttpContext.Current.Session["SortDirection"] = queryStrings["sord"];
        string currentPage = queryStrings["page"];
        string rows = queryStrings["rows"];
        int startIndex = (int.Parse(currentPage) - 1) * int.Parse(rows);
        int maximumRows = int.Parse(rows) - 1;

        ProductsTableAdapter productTableAdapter = new ProductsTableAdapter();
        DataTable productTableData = productTableAdapter.SelectMethod(startIndex, maximumRows);
        int totalCount = productTableAdapter.SelectCountMethod();

        // Calling SavejqGridJson
        DTTable dtTable = new DTTable("Product");
        object jqGridObject = dtTable.SavejqGridJson(productTableData, totalCount, currentPage, rows);

        // Converts Product table into JSon strig
        string jsonData = JsonConvert.SerializeObject(jqGridObject);

        // Converts JSON data to Message format.
        WebOperationContext.Current.OutgoingResponse.Headers.Add("X-Content-Type-Options", "nosniff");

        // returns JSON string in Message format
        return WebOperationContext.Current.CreateTextResponse(jsonData, "application/json; charset=utf-8", Encoding.UTF8);
    }
示例#4
0
        /// <summary>表の追加</summary>
        /// <param name="dtTbl">表</param>
        public void Add(DTTable dtTbl)
        {
            // 表の追加
            this._tbls.Add(dtTbl);

            // 表名 ⇒ 表インデックスのマップ
            if (this._tblsNameIndexMap.ContainsKey(dtTbl.TableName))
            {
                // 表名が重複している。
                throw new Exception("Table name overlaps. ");
            }
            else
            {
                this._tblsNameIndexMap.Add(dtTbl.TableName, this._tbls.Count - 1);
            }
        }
示例#5
0
        /// <summary>表の追加</summary>
        /// <param name="dtTbl">表</param>
        public void Add(DTTable dtTbl)
        {
            // 表の追加
            this._tbls.Add(dtTbl);

            // 表名 ⇒ 表インデックスのマップ
            if (this._tblsNameIndexMap.ContainsKey(dtTbl.TableName))
            {
                // 表名が重複している。
                throw new Exception("Table name overlaps. ");
            }
            else
            {
                this._tblsNameIndexMap.Add(dtTbl.TableName, this._tbls.Count - 1);
            }
        }
        /// <summary>更新処理</summary>
        async private void button8_Click(object sender, RoutedEventArgs e)
        {
            // 引数1:コンテキスト
            string context = "User1";

            // 引数2:共通部
            MuServiceReference.ArrayOfString param
                = new MuServiceReference.ArrayOfString();

            // 共通部を生成
            string actionType =
                ((ComboBoxItem)this.ddlDap.SelectedItem).Value + "%"
                + ((ComboBoxItem)this.ddlMode1.SelectedItem).Value + "%"
                + ((ComboBoxItem)this.ddlMode2.SelectedItem).Value + "%"
                + ((ComboBoxItem)this.ddlExRollback.SelectedItem).Value;

            param.Add(this.Name);               // 画面名
            param.Add(((Button)sender).Name);   // ボタン名
            param.Add("Update");                // メソッド名
            param.Add(actionType);              // アクションタイプ

            // 引数3:汎用DTOデータ部

            // 引数のDTTables
            DTTables dtts = new DTTables();
            DTTable dtt = new DTTable("param");
            DTRow dtrow = null;
            dtt.Cols.Add(new DTColumn("ShipperID", DTType.String));
            dtt.Cols.Add(new DTColumn("CompanyName", DTType.String));
            dtt.Cols.Add(new DTColumn("Phone", DTType.String));
            dtrow = dtt.Rows.AddNew();
            dtrow["ShipperID"] = this.textBox1.Text;
            dtrow["CompanyName"] = this.textBox2.Text;
            dtrow["Phone"] = this.textBox3.Text;
            dtts.Add(dtt);

            // SOAP汎用Webメソッドは通常のWeb参照を用いる。
            MuServiceReference.ServiceForMuSoapClient client = new MuServiceReference.ServiceForMuSoapClient();

            // 非同期呼出しを行う
            MuServiceReference.CallResponse response = await client.CallAsync(context, "muWebService", param, DTTables.DTTablesToString(dtts));

            if (response.Body.CallResult != "")
            {
                // 例外発生時
                WSErrorInfo wse = new WSErrorInfo(response.Body.CallResult);
                MessageDialog dialog = new MessageDialog("以下のエラーが発生しました\r\nメッセージ : " + response.Body.CallResult + " , " + response.Body.returnValue + " , " + wse.MessageID + " , " + wse.Message + " , " + wse.Information);
                await dialog.ShowAsync();
            }
            else
            {
                // 結果(正常系)
                this.labelMessage.Text = response.Body.returnValue + "件更新";
            }
        }
        /// <summary>一覧取得(動的sql)</summary>
        async private void button5_Click(object sender, RoutedEventArgs e)
        {
            // 引数1:コンテキスト
            string context = "User1";

            // 引数2:共通部
            MuServiceReference.ArrayOfString param
                = new MuServiceReference.ArrayOfString();

            // 共通部を生成
            string actionType =
                ((ComboBoxItem)this.ddlDap.SelectedItem).Value + "%"
                + ((ComboBoxItem)this.ddlMode1.SelectedItem).Value + "%"
                + ((ComboBoxItem)this.ddlMode2.SelectedItem).Value + "%"
                + ((ComboBoxItem)this.ddlExRollback.SelectedItem).Value;

            param.Add(this.Name);               // 画面名
            param.Add(((Button)sender).Name);   // ボタン名
            param.Add("SelectAll_DSQL");          // メソッド名
            param.Add(actionType);              // アクションタイプ

            // 引数3:汎用DTOデータ部

            // 引数のDTTables
            DTTables dtts = new DTTables();
            DTTable dtt = new DTTable("param");
            DTRow dtrow = null;
            dtt.Cols.Add(new DTColumn("OrderColumn", DTType.String));
            dtt.Cols.Add(new DTColumn("OrderSequence", DTType.String));
            dtrow = dtt.Rows.AddNew();
            dtrow["OrderColumn"] = ((ComboBoxItem)this.ddlOrderColumn.SelectedItem).Value;
            dtrow["OrderSequence"] = ((ComboBoxItem)this.ddlOrderSequence.SelectedItem).Value;
            dtts.Add(dtt);

            // SOAP汎用Webメソッドは通常のWeb参照を用いる。
            MuServiceReference.ServiceForMuSoapClient client = new MuServiceReference.ServiceForMuSoapClient();

            // 非同期呼出しを行う
            MuServiceReference.CallResponse response = await client.CallAsync(context, "muWebService", param, DTTables.DTTablesToString(dtts));

            if (response.Body.CallResult != "")
            {
                // 例外発生時
                WSErrorInfo wse = new WSErrorInfo(response.Body.CallResult);
                MessageDialog dialog = new MessageDialog("以下のエラーが発生しました\r\nメッセージ : " + response.Body.CallResult + " , " + response.Body.returnValue + " , " + wse.MessageID + " , " + wse.Message + " , " + wse.Information);
                await dialog.ShowAsync();
            }
            else
            {
                // 結果(正常系)
                // データバインド(ToDataSourceでは、削除行を除いたリストを返す)
                this.ListView1.ItemsSource = DTTables.StringToDTTables(response.Body.returnValue)[0].Rows.ToDataSource();
            }
        }
示例#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
                                {
                                    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
                {
                    // 捨て
                }
            }
        }
        /// <summary>
        /// Webサービスに汎用DTOデータを渡し
        /// Webサービス内で1行、行を追加する。
        /// </summary>
        async private void btnAddRow_CallWebService_Click(object sender, RoutedEventArgs e)
        {
            // 引数1:コンテキスト
            string Context = "User1";

            // 引数2:共通部
            MuServiceReference.ArrayOfString param
                = new MuServiceReference.ArrayOfString();

            // 共通部を生成
            param.Add(this.Name);               // 画面名
            param.Add(((Button)sender).Name);   // ボタン名
            param.Add("AddRow");                // メソッド名
            param.Add("ActionType");            // アクションタイプ

            // 引数3:汎用DTOデータ部

            // 空のDTTables
            DTTables dtts = new DTTables();
            dtts.Add(this.Dtt);

            // 汎用サービスI/FのWebサービスは通常のWeb参照を用いる。
            MuServiceReference.ServiceForMuSoapClient client
                = new MuServiceReference.ServiceForMuSoapClient();

            // 非同期呼出しを行う
            MuServiceReference.CallResponse response = await client.CallAsync(Context, "muWebService", param, DTTables.DTTablesToString(dtts));

            // データバインド(ToDataSourceでは、削除行を除いたリストを返す)
            this.Dtt = DTTables.StringToDTTables(response.Body.returnValue)[0];
            this.ListView1.ItemsSource = this.Dtt.Rows.ToDataSource();
        }
        /// <summary>更新処理</summary>
        private void button8_Click(object sender, RoutedEventArgs e)
        {
            // 引数1:コンテキスト
            string context = "User1";

            // 引数2:共通部
            MuServiceReference.ArrayOfString param
                = new MuServiceReference.ArrayOfString();

            // 共通部を生成
            string actionType =
                ((ComboBoxItem)this.ddlDap.SelectedItem).Value + "%"
                + ((ComboBoxItem)this.ddlMode1.SelectedItem).Value + "%"
                + ((ComboBoxItem)this.ddlMode2.SelectedItem).Value + "%"
                + ((ComboBoxItem)this.ddlExRollback.SelectedItem).Value;

            param.Add(this.Name);               // 画面名
            param.Add(((Button)sender).Name);   // ボタン名
            param.Add("Update");                // メソッド名
            param.Add(actionType);              // アクションタイプ

            // 引数3:汎用DTOデータ部

            // 引数のDTTables
            DTTables dtts = new DTTables();
            DTTable dtt = new DTTable("param");
            DTRow dtrow = null;
            dtt.Cols.Add(new DTColumn("ShipperID", DTType.String));
            dtt.Cols.Add(new DTColumn("CompanyName", DTType.String));
            dtt.Cols.Add(new DTColumn("Phone", DTType.String));
            dtrow = dtt.Rows.AddNew();
            dtrow["ShipperID"] = this.textBox1.Text;
            dtrow["CompanyName"] = this.textBox2.Text;
            dtrow["Phone"] = this.textBox3.Text;
            dtts.Add(dtt);

            // SOAP汎用Webメソッドは通常のWeb参照を用いる。
            MuServiceReference.ServiceForMuSoapClient client
                = new MuServiceReference.ServiceForMuSoapClient();

            // 呼び出しが完了した場合のイベントハンドラを設定する。
            client.CallCompleted += new EventHandler<MuServiceReference.CallCompletedEventArgs>(client_Update_CallCompleted);
            // 非同期呼出しを行う(Silverlightは非同期呼び出しのみサポートする)。
            client.CallAsync(context, "muWebService", param, DTTables.DTTablesToString(dtts));
        }
示例#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
                {
                    // 捨て
                }
            }
        }
示例#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());
                        }
                    }
                }
            }
        }
示例#13
0
 /// <summary>呼出しの完了後イベント(データグリッドの初期化)</summary>
 void client_InitDataGridCallCompleted(object sender, MuServiceReference.CallCompletedEventArgs e)
 {
     // データバインド(ToDataSourceでは、削除行を除いたリストを返す)
     this.Dtt = DTTables.StringToDTTables(e.returnValue)[0];
     this.dataGrid1.ItemsSource = this.Dtt.Rows.ToDataSource();
 }
示例#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());
                        }
                    }
                }
            }
        }
示例#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());
                        }
                    }
                }
            }
        }
示例#16
0
        /// <summary>
        /// System.Data.DataTableをDTTableに変換する
        /// </summary>
        /// <param name="table">変換元のSystem.Data.DataTable</param>
        /// <returns>変換後のDTTable</returns>
        public static DTTable FromDataTable(DataTable table)
        {
            // テーブル定義
            DTTable dt = new DTTable(table.TableName);

            // 列定義
            foreach (DataColumn col in table.Columns)
            {
                DTType type = ConvertTypeToDTType(col.DataType);
                dt.Cols.Add(new DTColumn(col.ColumnName, type));
            }

            // 値追加(削除された行以外)
            DTRow dr;
            foreach (DataRow row in table.Rows)
            {
                // 行をテーブルに追加
                dr = dt.Rows.AddNew();

                // 各列ごとに値を追加
                foreach (DataColumn col in table.Columns)
                {
                    if (row.RowState != System.Data.DataRowState.Deleted)
                    {
                        dr[col.ColumnName] = row[col.ColumnName];
                    }
                    else
                    {
                        // 行が削除されている場合は、元の値を取得する
                        dr[col.ColumnName] = row[col.ColumnName, DataRowVersion.Original];
                    }
                }

                // 行ステータスを復元
                if (row.RowState == System.Data.DataRowState.Detached)
                {
                    dr.RowState = DataRowState.Detached;
                }
                else if (row.RowState == System.Data.DataRowState.Added)
                {
                    dr.RowState = DataRowState.Added;
                }
                else if (row.RowState == System.Data.DataRowState.Modified)
                {
                    dr.RowState = DataRowState.Modified;
                }
                else if (row.RowState == System.Data.DataRowState.Deleted)
                {
                    dr.RowState = DataRowState.Deleted;
                }
                else
                {
                    dr.RowState = DataRowState.Unchanged;
                }
            }

            // DTTableを返す
            return dt;
        }
示例#17
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
                {
                    // 捨て
                }
            }
        }
示例#18
0
        /// <summary>Silverlight&汎用DTOのテスト(DataGrid初期化処理)</summary>
        /// <param name="muParameter">引数クラス</param>
        protected void UOC_InitDataGrid(MuParameterValue muParameter)
        {
            // 戻り値クラスを生成して、事前に戻り地に設定しておく。
            MuReturnValue muReturn = new MuReturnValue();
            this.ReturnValue = muReturn;

            // 引数をアンマーシャル
            //DTTables dtts_in = Marshalling.StringToDTTables(muParameter.Value);
            //DTTable dtt_in = dtts_in[0];
            //DTRow dtrow_in = dtt_in.Rows[0];

            DTTables dtts_out = null;
            DTTable dtt_out = null;
            DTRow dtrow_out = null;

            // テーブル生成@汎用DTO
            dtt_out = new DTTable("test");

            // カラム定義@汎用DTOテーブル
            dtt_out.Cols.Add(new DTColumn("boolVal", DTType.Boolean));
            dtt_out.Cols.Add(new DTColumn("charVal", DTType.Char));
            dtt_out.Cols.Add(new DTColumn("dateVal", DTType.DateTime));
            dtt_out.Cols.Add(new DTColumn("decimalVal", DTType.Decimal));
            dtt_out.Cols.Add(new DTColumn("doubleVal", DTType.Double));
            dtt_out.Cols.Add(new DTColumn("shortVal", DTType.Int16));
            dtt_out.Cols.Add(new DTColumn("intVal", DTType.Int32));
            dtt_out.Cols.Add(new DTColumn("longVal", DTType.Int64));
            dtt_out.Cols.Add(new DTColumn("singleVal", DTType.Single));
            dtt_out.Cols.Add(new DTColumn("stringVal", DTType.String));

            // 行追加@汎用DTOテーブル
            
            // 1行目
            dtrow_out = dtt_out.Rows.AddNew();
            dtrow_out["boolVal"] = true;
            dtrow_out["charVal"] = 'a';
            dtrow_out["dateVal"] = new DateTime(1977, 7, 22, 10, 20, 30, 444);
            dtrow_out["decimalVal"] = 10000;
            dtrow_out["doubleVal"] = 3.55D;
            dtrow_out["shortVal"] = 100;
            dtrow_out["intVal"] = 1000000;
            dtrow_out["longVal"] = 1000000000000;
            dtrow_out["singleVal"] = 3.5f;
            dtrow_out["stringVal"] = "test";

            // 2行目
            dtrow_out = dtt_out.Rows.AddNew();
            dtrow_out["boolVal"] = false;
            dtrow_out["charVal"] = 'b';
            dtrow_out["dateVal"] = new DateTime(1976, 4, 23, 10, 20, 30, 444);
            dtrow_out["decimalVal"] = 20000;
            dtrow_out["doubleVal"] = 6.11D;
            dtrow_out["shortVal"] = 200;
            dtrow_out["intVal"] = 2000000;
            dtrow_out["longVal"] = 2000000000000;
            dtrow_out["singleVal"] = 6.5f;
            dtrow_out["stringVal"] = "test2";

            // 3行目
            dtrow_out = dtt_out.Rows.AddNew();
            dtrow_out["boolVal"] = true;
            dtrow_out["charVal"] = 'c';
            dtrow_out["dateVal"] = new DateTime(1975, 1, 1, 10, 20, 30, 444);
            dtrow_out["decimalVal"] = 30000;
            dtrow_out["doubleVal"] = 8.25D;
            dtrow_out["shortVal"] = 300;
            dtrow_out["intVal"] = 3000000;
            dtrow_out["longVal"] = 3000000000000;
            dtrow_out["singleVal"] = 7.2f;
            dtrow_out["stringVal"] = "test3";

            // ここで変更を確定させる
            dtt_out.AcceptChanges();

            // 戻り値をマーシャリングして設定
            dtts_out = new DTTables();
            dtts_out.Add(dtt_out);
            ((MuReturnValue)this.ReturnValue).Value = DTTables.DTTablesToString(dtts_out);
        }
示例#19
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
                {
                    // 捨て
                }
            }
        }
示例#20
0
        /// <summary>業務処理を実装</summary>
        /// <param name="muParameter">汎用引数クラス</param>
        private void UOC_Select(MuParameterValue muParameter)
        {
            // 戻り値クラスを生成して、事前に戻り地に設定しておく。
            MuReturnValue muReturn = new MuReturnValue();
            this.ReturnValue = muReturn;

            // 引数をアンマーシャル
            //DTTables dtts_in = Marshalling.StringToDTTables(muParameter.Value);
            //DTTable dtt_in = dtts_in[0];
            //DTRow dtrow_in = dtt_in.Rows[0];

            DTTables dtts_out = null;
            DTTable dtt_out = null;
            DTRow dtrow_out = null;

            // ↓業務処理-----------------------------------------------------
            DataTable dt = null;

            switch ((muParameter.ActionType.Split('%'))[1])
            {
                case "common": // 共通Daoを使用する。

                    // 共通Daoを生成
                    CmnDao cmnDao = new CmnDao(this.GetDam());

                    switch ((muParameter.ActionType.Split('%'))[2])
                    {
                        case "static":
                            // 静的SQLを指定
                            cmnDao.SQLFileName = "ShipperSelect.sql";
                            break;

                        case "dynamic":
                            // 動的SQLを指定
                            cmnDao.SQLFileName = "ShipperSelect.xml";
                            break;
                    }

                    // パラメタ ライズド クエリのパラメタに対して、動的に値を設定する。
                    cmnDao.SetParameter("P1", muParameter.Value);

                    // 戻り値 dt
                    dt = new DataTable("rtn");

                    // 共通Daoを実行
                    cmnDao.ExecSelectFill_DT(dt);

                    // キャストの対策コードを挿入
                    dtt_out = new DTTable("ret");
                    dtt_out.Cols.Add(new DTColumn("ShipperID", DTType.Int32));
                    dtt_out.Cols.Add(new DTColumn("CompanyName", DTType.String));
                    dtt_out.Cols.Add(new DTColumn("Phone", DTType.String));
                    dtrow_out = dtt_out.Rows.AddNew();

                    // ・SQLの場合、ShipperIDのintがInt32型にマップされる。
                    // ・ODPの場合、ShipperIDのNUMBERがInt64型にマップされる。
                    // ・DB2の場合、ShipperIDのDECIMALがxxx型にマップされる。
                    if (dt.Rows[0].ItemArray.GetValue(0).GetType().ToString() == "System.Int32")
                    {
                        // Int32なのでキャスト
                        dtrow_out["ShipperID"] = (int)dt.Rows[0].ItemArray.GetValue(0);
                    }
                    else
                    {
                        // それ以外の場合、一度、文字列に変換してInt32.Parseする。
                        dtrow_out["ShipperID"] = int.Parse(dt.Rows[0].ItemArray.GetValue(0).ToString());
                    }

                    dtrow_out["CompanyName"] = (string)dt.Rows[0].ItemArray.GetValue(1);
                    dtrow_out["Phone"] = (string)dt.Rows[0].ItemArray.GetValue(2);

                    // 戻り値をマーシャリングして設定
                    dtts_out = new DTTables();
                    dtts_out.Add(dtt_out);
                    muReturn.Value = DTTables.DTTablesToString(dtts_out);

                    break;

                case "generate": // 自動生成Daoを使用する。

                    // 自動生成Daoを生成
                    DaoShippers genDao = new DaoShippers(this.GetDam());

                    // パラメタに対して、動的に値を設定する。
                    genDao.PK_ShipperID = muParameter.Value;

                    // 戻り値 dt
                    dt = new DataTable("rtn");

                    // 自動生成Daoを実行
                    genDao.S2_Select(dt);

                    // キャストの対策コードを挿入
                    dtt_out = new DTTable("ret");
                    dtt_out.Cols.Add(new DTColumn("ShipperID", DTType.Int32));
                    dtt_out.Cols.Add(new DTColumn("CompanyName", DTType.String));
                    dtt_out.Cols.Add(new DTColumn("Phone", DTType.String));
                    dtrow_out = dtt_out.Rows.AddNew();

                    // ・SQLの場合、ShipperIDのintがInt32型にマップされる。
                    // ・ODPの場合、ShipperIDのNUMBERがInt64型にマップされる。
                    // ・DB2の場合、ShipperIDのDECIMALがxxx型にマップされる。
                    if (dt.Rows[0].ItemArray.GetValue(0).GetType().ToString() == "System.Int32")
                    {
                        // Int32なのでキャスト
                        dtrow_out["ShipperID"] = (int)dt.Rows[0].ItemArray.GetValue(0);
                    }
                    else
                    {
                        // それ以外の場合、一度、文字列に変換してInt32.Parseする。
                        dtrow_out["ShipperID"] = int.Parse(dt.Rows[0].ItemArray.GetValue(0).ToString());
                    }

                    dtrow_out["CompanyName"] = (string)dt.Rows[0].ItemArray.GetValue(1);
                    dtrow_out["Phone"] = (string)dt.Rows[0].ItemArray.GetValue(2);

                    // 戻り値をマーシャリングして設定
                    dtts_out = new DTTables();
                    dtts_out.Add(dtt_out);
                    muReturn.Value = DTTables.DTTablesToString(dtts_out);

                    break;

                default: // 個別Daoを使用する。

                    // 個別Daoを実行
                    string companyName;
                    string phone;

                    LayerD myDao = new LayerD(this.GetDam());
                    myDao.Select(muParameter.ActionType, muParameter.Value,
                        out companyName, out phone);

                    // 戻り値をマーシャリングして設定
                    dtt_out = new DTTable("ret");
                    dtt_out.Cols.Add(new DTColumn("ShipperID", DTType.Int32));
                    dtt_out.Cols.Add(new DTColumn("CompanyName", DTType.String));
                    dtt_out.Cols.Add(new DTColumn("Phone", DTType.String));
                    dtrow_out = dtt_out.Rows.AddNew();

                    dtrow_out["ShipperID"] = int.Parse(muParameter.Value);
                    dtrow_out["CompanyName"] = companyName;
                    dtrow_out["Phone"] = phone;
                    
                    dtts_out = new DTTables();
                    dtts_out.Add(dtt_out);
                    muReturn.Value = DTTables.DTTablesToString(dtts_out);

                    break;
            }

            // ↑業務処理-----------------------------------------------------

            // ロールバックのテスト
            this.TestRollback(muParameter);
        }
示例#21
0
        /// <summary>業務処理を実装</summary>
        /// <param name="muParameter">汎用引数クラス</param>
        private void UOC_メソッド名(MuParameterValue muParameter)
        { //メソッド引数にBaseParameterValueの派生の型を定義可能。

            // 戻り値クラスを生成して、事前に戻り地に設定しておく。
            MuReturnValue muReturn = new MuReturnValue();
            this.ReturnValue = muReturn;

            // 引数をアンマーシャル
            DTTables dtts_in = DTTables.StringToDTTables(muParameter.Value);
            DTTable dtt_in = dtts_in[0];
            DTRow dtrow_in = dtt_in.Rows[0];

            DTTables dtts_out = null;
            DTTable dtt_out = null;
            DTRow dtrow_out = null;

            // ↓業務処理-----------------------------------------------------

            // 個別Dao
            LayerD myDao = new LayerD(this.GetDam());
            //myDao.xxxx(muParameter.ActionType, dtts, muReturn);

            // 共通Dao
            CmnDao cmnDao = new CmnDao(this.GetDam());
            cmnDao.ExecSelectScalar();

            // 戻り値をマーシャリングして設定
            dtts_out = new DTTables();
            dtt_out = new DTTable("ret");
            dtt_out.Cols.Add(new DTColumn("ret", DTType.String));
            dtrow_out = dtt_out.Rows.AddNew();
            dtrow_out["ret"] = "戻り値";
            dtts_out.Add(dtt_out);

            muReturn.Value = DTTables.DTTablesToString(dtts_out);

            // ↑業務処理-----------------------------------------------------
        }
示例#22
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());
                        }
                    }
                }
            }
        }