<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    namespace RCRS.AdoNetEF.Library.Presentation.AdoNet20
    {
        //------------------------------------------------------------------
        /// <summary>
        
    /// バインディングする畫面用インターフェース
        
    /// </summary>
        //------------------------------------------------------------------
        interface IBindUI
        {
            //--------------------------------------------------------------
            /// <summary>
            
    /// バインドするデータを取得するメソッドです。
            
    /// </summary>
            
    /// <returns></returns>
            //--------------------------------------------------------------
            bool GetData();
        }
    }

    using System.Data;
    using System.Windows.Forms;

    namespace RCRS.AdoNetEF.Library.Presentation.AdoNet20
    {
        //--------------------------------------------------------------
        /// <summary>
        
    /// DataViewとCurrencyManagerのペアセットです。
        
    /// </summary>
        //--------------------------------------------------------------
        public class ViewSource
        {
            private DataView        dv = null;
            private CurrencyManager cm = null;

            //--------------------------------------------------------------
            /// <summary>
            
    /// 新しいインスタンスを生成します。
            
    /// </summary>
            
    /// <param name="dv"></param>
            
    /// <param name="cm"></param>
            //--------------------------------------------------------------
            public ViewSource(DataView dv, CurrencyManager cm)
            {
                this.dv = dv;
                this.cm = cm;
            }

            //--------------------------------------------------------------
            /// <summary>
            
    /// DataViewを取得?設定します。
            
    /// </summary>
            //--------------------------------------------------------------
            public DataView Dv
            {
                get { return dv; }
                set { dv = value; }
            }

            //--------------------------------------------------------------
            /// <summary>
            
    /// CurrencyManagerを取得?設定します。
            
    /// </summary>
            //--------------------------------------------------------------
            public CurrencyManager Cm
            {
                get { return cm; }
                set { cm = value; }
            }
        }
    }

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Windows.Forms;

    namespace RCRS.AdoNetEF.Library.Presentation.AdoNet20
    {
        //-----------------------------------------------------------------------
        /// <summary>
        
    /// バインド用ビジネスロジックです。
        
    /// </summary>
        //-----------------------------------------------------------------------
        public class BizBind
        {
            //バインドエラー:テーブル
            private const string ERROR_BIND_TABLE     = "ERROR:BIND:TABLE";
            //バインドエラー:フィールド
            private const string ERROR_BIND_DATAFIELD = "ERROR:BIND:DATAFIELD";

            //-----------------------------------------------------------------------
            /// <summary>
            
    /// dsからViewSources(Dictionary<string, ViewSource>)を作成します。
            
    /// </summary>
            
    /// <param name="control"></param>
            
    /// <param name="ds"></param>
            
    /// <returns></returns>
            //-----------------------------------------------------------------------
            public static Dictionary<string, ViewSource> CreateViewSources(Control control, DataSet ds)
            {
                Dictionary<string, ViewSource> viewSources = new Dictionary<string, ViewSource>();
                if (ds != null)
                {
                    foreach (DataTable dt in ds.Tables)
                    {
                        DataView        dv = new DataView(dt);
                        CurrencyManager cm = (CurrencyManager)control.BindingContext[dv];
                        ViewSource      vs = new ViewSource(dv, cm);

                        viewSources.Add(dv.Table.TableName, vs); //テーブル名をキー値に設定
                    }
                }
                return viewSources;
            }

            //-----------------------------------------------------------------------
            /// <summary>
            
    /// バインディングコントロールリストを登録します。
            
    /// Control內を走査
            
    /// </summary>
            
    /// <param name="top">このコントロール內のバインディングコントロールを登録します。</param>
            
    /// <param name="bindControls">バインディングコントロールリスト</param>
            
    /// <returns></returns>
            //-----------------------------------------------------------------------
            public static List<KeyValuePair<string, Control>> CreateBindingControlList(Control top, List<KeyValuePair<string, Control>> bindControls)
            {
                if ((top.GetType()    == typeof(BTextBox))      || (top.GetType() == typeof(BComboBox))
                    || (top.GetType() == typeof(BDataGridView)) || (top.GetType() == typeof(BLabel))
                    || (top.GetType() == typeof(BCheckBox))     || (top.GetType() == typeof(BRichTextBox))
                    || (top.GetType() == typeof(BTextComboBox)) || (top.GetType() == typeof(BDecimalBox)))
                {
                    KeyValuePair<string, Control> cPair = new KeyValuePair<string, Control>(top.Name, top);
                    //bindControlに追加されていない場合は追加
                    if (bindControls.IndexOf(cPair) == -1)
                        bindControls.Add(cPair);
                }
                //子要素の走査
                foreach (Control c in top.Controls)
                    bindControls = CreateBindingControlList(c, bindControls);

                return bindControls;
            }

            //-----------------------------------------------------------------------
            /// <summary>
            
    /// コントロール內の各コントロールに対し、バインディングコントロールリストから削除します。
            
    /// </summary>
            
    /// <param name="top">このコントロール內のバインディングコントロールを登録します。</param>
            
    /// <param name="bindControls">バインディングコントロールリスト</param>
            //-----------------------------------------------------------------------
            public static void RemoveBindingControlList(Control top, List<KeyValuePair<string, Control>> bindControls)
            {
                if ((top.GetType()    == typeof(BTextBox))      || (top.GetType() == typeof(BComboBox))
                    || (top.GetType() == typeof(BDataGridView)) || (top.GetType() == typeof(BLabel))
                    || (top.GetType() == typeof(BCheckBox))     || (top.GetType() == typeof(BRichTextBox))
                    || (top.GetType() == typeof(BTextComboBox)) || (top.GetType() == typeof(BDecimalBox)))
                {
                    KeyValuePair<string, Control> cPair = new KeyValuePair<string, Control>(top.Name, top);
                    int indx = bindControls.IndexOf(cPair);
                    if (0 <= indx)
                    {
                        //バインドのクリア
                        cPair.Value.DataBindings.Clear();
                        //リストから削除
                        bindControls.Remove(cPair);
                    }
                }
                //子要素の走査
                foreach (Control c in top.Controls)
                    RemoveBindingControlList(c, bindControls);
            }

            //-----------------------------------------------------------------------
            /// <summary>
            
    /// バインドを実行します。
            
    /// </summary>
            
    /// <param name="viewSources">データソースリスト</param>
            
    /// <param name="bindControls">バインディングコントロールリスト</param>
            //-----------------------------------------------------------------------
            public static void Bind(Dictionary<string, ViewSource> viewSources, List<KeyValuePair<string, Control>> bindControls)
            {
                foreach (KeyValuePair<string, Control> ctrl in bindControls)
                {
                    if ((checkBindSettings(viewSources, ctrl.Value)) && (ctrl.Value.DataBindings.Count == 0))
                    {
                        if (ctrl.Value.GetType() == typeof(BDataGridView))
                        {
                            BDataGridView tmp = (BDataGridView)ctrl.Value;
                            tmp.DataSource = viewSources[tmp.TableName].Dv;
                        }
                        else if (ctrl.Value.GetType() == typeof(BLabel))
                        {
                            BLabel tmp = (BLabel)ctrl.Value;
                            ctrl.Value.DataBindings.Add("Text", viewSources[tmp.TableName].Dv, tmp.DataField);
                        }
                        else if (ctrl.Value.GetType() == typeof(BTextBox))
                        {
                            BTextBox tmp = (BTextBox)ctrl.Value;
                            if (tmp.FormatString == string.Empty)
                                ctrl.Value.DataBindings.Add("Text", viewSources[tmp.TableName].Dv, tmp.DataField);
                            else //書式が設定されている場合
                                ctrl.Value.DataBindings.Add("Text", viewSources[tmp.TableName].Dv, tmp.DataField, true, DataSourceUpdateMode.OnValidation, "", tmp.FormatString);
                        }
                        else if (ctrl.Value.GetType() == typeof(BRichTextBox))
                        {
                            BRichTextBox tmp = (BRichTextBox)ctrl.Value;
                            ctrl.Value.DataBindings.Add("Text", viewSources[tmp.TableName].Dv, tmp.DataField);
                        }
                        else if (ctrl.Value.GetType() == typeof(BDecimalBox))
                        {
                            BDecimalBox tmp = (BDecimalBox)ctrl.Value;
                            if (tmp.FormatString == string.Empty)
                                ctrl.Value.DataBindings.Add("Text", viewSources[tmp.TableName].Dv, tmp.DataField);
                            else //書式が設定されている場合
                                ctrl.Value.DataBindings.Add("Text", viewSources[tmp.TableName].Dv, tmp.DataField, true, DataSourceUpdateMode.OnValidation, "", tmp.FormatString);
                        }
                        else if (ctrl.Value.GetType() == typeof(BComboBox))
                        {
                            BComboBox tmp = (BComboBox)ctrl.Value;
                            if (tmp.TableName != null && tmp.DataField != null)
                            {
                                if (viewSources[tmp.TableName].Dv.Table.Columns.Contains(tmp.DataField))
                                    cmbBinding((ComboBox)ctrl.Value, viewSources[tmp.ListTableName].Dv, viewSources[tmp.TableName].Dv, tmp.DisplayField, tmp.ValueField, tmp.DataField);
                            }
                            else
                                cmbBinding((ComboBox)ctrl.Value, viewSources[tmp.ListTableName].Dv, null, tmp.DisplayField, tmp.ValueField, "");
                        }
                        else if (ctrl.Value.GetType() == typeof(BCheckBox))
                        {
                            BCheckBox tmp = (BCheckBox)ctrl.Value;
                            ctrl.Value.DataBindings.Add("Checked", viewSources[tmp.TableName].Dv, tmp.DataField);
                        }
                        else if (ctrl.Value.GetType() == typeof(BTextComboBox))
                        {
                            BTextComboBox tmp = (BTextComboBox)ctrl.Value;
                            tmp.ValueType = viewSources[tmp.ListTableName].Dv.Table.Columns[tmp.ValueField].DataType; //値の型を設定(テキストからコンボへのキャスト用)
                            tmp.txtBox.DataBindings.Add("Text", viewSources[tmp.TableName].Dv, tmp.DataField, true, DataSourceUpdateMode.OnPropertyChanged);
                            cmbBinding(tmp.cmbBox, viewSources[tmp.ListTableName].Dv, viewSources[tmp.TableName].Dv, tmp.DisplayField, tmp.ValueField, tmp.DataField);
                        }
                        Console.WriteLine(ctrl.Key + ":" + ctrl.Value.DataBindings.Count.ToString()); 
                    }
                }
            }
            
            //-------------------------------------------------------------------------
            /// <summary>
            
    /// バインディングプロパティ設定をチェックします。
            
    /// </summary>
            
    /// <param name="viewSources">バインドするViewSources</param>
            
    /// <param name="ctrl">バインディングコントロール</param>
            
    /// <returns>true:OK false:ERROR</returns>
            //-------------------------------------------------------------------------
            private static bool checkBindSettings(Dictionary<string, ViewSource> viewSources, Control ctrl)
            {
                bool   result        = false;
                string tableName     = string.Empty;
                string dataField     = string.Empty;
                string listTableName = string.Empty;
                string displayField  = string.Empty;
                string valueField    = string.Empty;

                //設定値取得
                if (ctrl.GetType() == typeof(BDataGridView))
                {
                    BDataGridView tmp = (BDataGridView)ctrl;
                    tableName         = tmp.TableName;
                }
                else if (ctrl.GetType() == typeof(BLabel))
                {
                    BLabel tmp = (BLabel)ctrl;
                    tableName  = tmp.TableName;
                    dataField  = tmp.DataField;
                }
                else if (ctrl.GetType() == typeof(BTextBox))
                {
                    BTextBox tmp = (BTextBox)ctrl;
                    tableName    = tmp.TableName;
                    dataField    = tmp.DataField;
                }
                else if (ctrl.GetType() == typeof(BDecimalBox))
                {
                    BDecimalBox tmp = (BDecimalBox)ctrl;
                    tableName = tmp.TableName;
                    dataField = tmp.DataField;
                }
                else if (ctrl.GetType() == typeof(BRichTextBox))
                {
                    BRichTextBox tmp = (BRichTextBox)ctrl;
                    tableName        = tmp.TableName;
                    dataField        = tmp.DataField;
                }
                else if (ctrl.GetType() == typeof(BComboBox))
                {
                    BComboBox tmp = (BComboBox)ctrl;
                    tableName     = tmp.TableName;
                    dataField     = tmp.DataField;
                    listTableName = tmp.ListTableName;
                    displayField  = tmp.DisplayField;
                    valueField    = tmp.ValueField;
                }
                else if (ctrl.GetType() == typeof(BCheckBox))
                {
                    BCheckBox tmp = (BCheckBox)ctrl;
                    tableName     = tmp.TableName;
                    dataField     = tmp.DataField;
                }
                else if (ctrl.GetType() == typeof(BTextComboBox))
                {
                    BTextComboBox tmp = (BTextComboBox)ctrl;
                    tableName         = tmp.TableName;
                    dataField         = tmp.DataField;
                    listTableName     = tmp.ListTableName;
                    displayField      = tmp.DisplayField;
                    valueField        = tmp.ValueField;
                }

                //設定エラーチェック
                if (ctrl.GetType() == typeof(BDataGridView) || ctrl.GetType() == typeof(BCheckBox))
                {
                    if ((!string.IsNullOrEmpty(tableName)) && (viewSources.Keys.Contains(tableName)))
                        result = true//バインド対象
                }
                else if ((ctrl.GetType() == typeof(BLabel)) || (ctrl.GetType() == typeof(BTextBox)) || (ctrl.GetType() == typeof(BRichTextBox)) || (ctrl.GetType() == typeof(BDecimalBox)))
                {
                    //テーブル名とフィールド名が設定されている場合はバインドする。
                    if (!string.IsNullOrEmpty(tableName) && (!string.IsNullOrEmpty(dataField)))
                    {
                        //テーブルの有無チェック
                        if (viewSources.Keys.Contains(tableName))
                        {
                            //フィールドの有無チェック
                            if (viewSources[tableName].Dv.Table.Columns.Contains(dataField))
                            {
                                ctrl.BackColor = Color.LemonChiffon;
                                result         = true//バインド対象
                            }
                            else
                            {
                                ctrl.Text      = ERROR_BIND_DATAFIELD;
                                ctrl.BackColor = Color.Red;
                            }
                        }
                        else
                        {
                            ctrl.Text      = ERROR_BIND_TABLE;
                            ctrl.BackColor = Color.Red;
                        }
                    }
                }
                else if ((ctrl.GetType() == typeof(BComboBox)) || (ctrl.GetType() == typeof(BTextComboBox)))
                {
                    //リストテーブルと表示列名?値列名が正しくセットされている場合はバインドを行う。
                    if ((!string.IsNullOrEmpty(listTableName)) && (viewSources.Keys.Contains(listTableName)))
                    {
                        //リストのフィールド有無チェック
                        if ((viewSources[listTableName].Dv.Table.Columns.Contains(valueField))
                            && (viewSources[listTableName].Dv.Table.Columns.Contains(displayField)))
                        {
                            ctrl.BackColor = Color.LemonChiffon;
                            result         = true;
                        }
                        else
                        {
                            ctrl.Text      = ERROR_BIND_DATAFIELD;
                            ctrl.BackColor = Color.Red;
                        }
                    }
                    else
                    {
                        ctrl.Text      = ERROR_BIND_TABLE;
                        ctrl.BackColor = Color.Red;
                    }
                }
                return result;
            }

            //-------------------------------------------------------------------------
            /// <summary>
            
    /// コンボボックスを指定したリストデータとバインディングします。
            
    /// </summary>
            
    /// <param name="cmb">コンボボックス</param>
            
    /// <param name="listDataSource">リストテーブル</param>
            
    /// <param name="dataSource">テーブル</param>
            
    /// <param name="displayMember">リストテーブルの表示列</param>
            
    /// <param name="valueMember">リストテーブルのバインド列</param>
            
    /// <param name="dataMember">テーブルのバインド列</param>
            //-------------------------------------------------------------------------
            private static void cmbBinding(ComboBox cmb, object listDataSource, object dataSource, string displayMember, string valueMember, string dataMember)
            {
                cmb.DisplayMember = displayMember;
                cmb.ValueMember   = valueMember;
                cmb.DataSource    = listDataSource;
                if ((dataSource != null) && (dataMember != ""))
                    cmb.DataBindings.Add("SelectedValue", dataSource, dataMember);
            }
        }
    }

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Windows.Forms;

    namespace RCRS.AdoNetEF.Library.Presentation.AdoNet20
    {
        //--------------------------------------------------------------
        /// <summary>
        
    /// 各畫面の基本クラスです。
        
    /// ログイン情報を保持します。
        
    /// </summary>
        //--------------------------------------------------------------
        public partial class FrmBase : Form, IBindUI
        {
            /// <summary></summary>
            protected DataSet ds;
            /// <summary></summary>
            protected Dictionary<string, ViewSource> ViewSources = new Dictionary<string, ViewSource>();
            /// <summary></summary>
            protected List<KeyValuePair<string, Control>> BindControls = new List<KeyValuePair<string, Control>>();

            //--------------------------------------------------------------
            /// <summary>
            
    /// 新しいインスタンスを生成します。
            
    /// </summary>
            //--------------------------------------------------------------
            public FrmBase()
            {
                InitializeComponent();
            }

            //--------------------------------------------------------------
            /// <summary>
            
    /// ロード時に発生します。
            
    /// </summary>
            
    /// <param name="sender"></param>
            
    /// <param name="e"></param>
            //--------------------------------------------------------------
            private void FrmBase_Load(object sender, EventArgs e)
            {
                if (DesignMode)
                    return;
                //バインドデータを取得します。(派生先を実行)
                GetData();
                //ViewSourcesを作成します。
                ViewSources  = BizBind.CreateViewSources(this, ds);
                BindControls = BizBind.CreateBindingControlList(this, BindControls);
                BizBind.Bind(ViewSources, BindControls);
            }

            //--------------------------------------------------------------
            /// <summary>
            
    /// インスタンス生成時のバインドデータ取得処理を記述します。
            
    /// </summary>
            
    /// <returns></returns>
            //--------------------------------------------------------------
            public virtual bool GetData()
            {
                return false;
            }

            //--------------------------------------------------------------
            /// <summary>
            
    /// キーダウン時発生します。
            
    /// Enterキーでのフォーカス制御を実裝しています。
            
    /// 適用する場合は派生先のクラスにて、KeyPreviewをTrueに設定して下さい。
            
    /// 但し、その場合DataGridViewにフォーカスが當たっている場合であってもフォーカス移動されます。
            
    /// </summary>
            
    /// <param name="sender"></param>
            
    /// <param name="e"></param>
            //--------------------------------------------------------------
            private void FrmBase_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Enter)
                {
                    //DataGridView系統、RichTextBox系統のコントロールは除外されます。
                    if ((typeof(BDataGridView) != ActiveControl.GetType()) && (typeof(DataGridView) != ActiveControl.GetType())
                        && (typeof(BRichTextBox) != ActiveControl.GetType()) && (typeof(RichTextBox) != ActiveControl.GetType()))
                    {
                        // 次のコントロールへフォーカス移動
                        SelectNextControl(ActiveControl, !e.Shift, truetruetrue);
                        e.Handled = true;
                    }
                }
            }
        }
    }

    using System.ComponentModel;
    using System.Windows.Forms;

    namespace RCRS.AdoNetEF.Library.Presentation.AdoNet20
    {
        //--------------------------------------------------------------
        /// <summary>
        
    /// バインディング用ComboBoxユーザーコントロールです。
        
    /// </summary>
        //--------------------------------------------------------------
        public partial class BComboBox : ComboBox, IBindCtrl
        {
            private string tableName     = string.Empty;
            private string dataField     = string.Empty;
            private string listTableName = string.Empty;
            private string valueField    = string.Empty;
            private string displayField  = string.Empty;

            //--------------------------------------------------------------
            /// <summary>
            
    /// テーブル名を取得?設定します。
            
    /// </summary>
            //--------------------------------------------------------------
            [DefaultValue("")]
            [Description("テーブル名")]
            public string TableName
            {
                get { return tableName; }
                set { tableName = value; }
            }

            //--------------------------------------------------------------
            /// <summary>
            
    /// テーブルのバインド列を取得?設定します。
            
    /// </summary>
            //--------------------------------------------------------------
            [DefaultValue("")]
            [Description("テーブルのバインド列")]
            public string DataField
            {
                get { return dataField; }
                set { dataField = value; }
            }

            //--------------------------------------------------------------
            /// <summary>
            
    /// リストテーブル名を取得?設定します。
            
    /// </summary>
            //--------------------------------------------------------------
            [DefaultValue("")]
            [Description("リストテーブル名")]
            public string ListTableName
            {
                get { return listTableName; }
                set { listTableName = value; }
            }

            //--------------------------------------------------------------
            /// <summary>
            
    /// リストテーブルのバインド列を取得?設定します。
            
    /// </summary>
            //--------------------------------------------------------------
            [DefaultValue("")]
            [Description("リストテーブルのバインド列")]
            public string ValueField
            {
                get { return valueField; }
                set { valueField = value; }
            }

            //--------------------------------------------------------------
            /// <summary>
            
    /// リストテーブルの表示列を取得?設定します。
            
    /// </summary>
            //--------------------------------------------------------------
            [DefaultValue("")]
            [Description("リストテーブルの表示列")]
            public string DisplayField
            {
                get { return displayField; }
                set { displayField = value; }
            }

            //--------------------------------------------------------------
            /// <summary>
            
    /// 新しいインスタンスを生成します。
            
    /// </summary>
            //--------------------------------------------------------------
            public BComboBox()
            {
                InitializeComponent();
            }

            //--------------------------------------------------------------
            /// <summary>
            
    /// 描畫時発生します。
            
    /// </summary>
            
    /// <param name="pe"></param>
            //--------------------------------------------------------------
            protected override void OnPaint(PaintEventArgs pe)
            {
                base.OnPaint(pe);
            }
        }
    }



                ViewSources  = BizBind.CreateViewSources(this, ds);
                BindControls = BizBind.CreateBindingControlList(this, BindControls);
                BizBind.Bind(ViewSources, BindControls);






    posted on 2016-12-23 14:29 Ying-er 閱讀(201) 評論(0)  編輯  收藏 所屬分類: .Net
    主站蜘蛛池模板: 夜夜春亚洲嫩草影院| 亚洲制服丝袜在线播放| 免费A级毛片无码A∨| 狠狠色伊人亚洲综合网站色| 国产免费一区二区三区VR| 国产免费伦精品一区二区三区| 337p日本欧洲亚洲大胆艺术| 国产一级理论免费版| 99久久免费精品视频| 国产精品亚洲а∨无码播放不卡 | 在线日韩av永久免费观看| 搜日本一区二区三区免费高清视频| 亚洲av色福利天堂| 日韩一级在线播放免费观看| 最近免费中文字幕MV在线视频3| 国产精品亚洲综合久久| 亚洲精品国产精品乱码视色| 成人毛片18女人毛片免费96 | 国产成人免费手机在线观看视频 | 久久青青草原亚洲av无码| 麻豆高清免费国产一区| 欧洲乱码伦视频免费国产| 亚洲高清视频在线播放| 亚洲综合精品网站| 夫妻免费无码V看片| 免费无码毛片一区二区APP| 国产精品亚洲а∨无码播放不卡 | 亚洲一级毛片视频| 国产美女亚洲精品久久久综合| 无码视频免费一区二三区| 久久免费视频网站| 日本高清不卡中文字幕免费| 亚洲AV无码久久久久网站蜜桃| 亚洲一区AV无码少妇电影☆| 一本色道久久88亚洲综合 | 又爽又高潮的BB视频免费看| 精品久久久久久久久免费影院| 精品亚洲永久免费精品| sss日本免费完整版在线观看| 亚洲天然素人无码专区| 亚洲欧洲国产成人精品|