<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 閱讀(209) 評論(0)  編輯  收藏 所屬分類: .Net
    主站蜘蛛池模板: 香蕉免费一区二区三区| 在线精品自拍亚洲第一区| 亚洲精品蜜桃久久久久久| 亚洲精品高清无码视频| 一级特级aaaa毛片免费观看 | 91福利免费网站在线观看| 久久精品毛片免费观看| 日本妇人成熟免费中文字幕| 午夜免费福利网站| 亚洲综合另类小说色区色噜噜| 亚洲国产精品成人精品无码区| 亚洲人成色77777在线观看| free哆拍拍免费永久视频| 亚洲欧洲免费无码| 亚洲国产精品无码专区| 精品亚洲永久免费精品| 亚洲av成人一区二区三区在线观看| 亚洲毛片在线观看| 香港经典a毛片免费观看看| 亚洲免费一级视频| 亚洲香蕉网久久综合影视| 亚洲精品人成网线在线播放va| 少妇太爽了在线观看免费视频| 久久久久亚洲精品无码蜜桃| 日韩毛片免费一二三| 蜜桃精品免费久久久久影院| 国产亚洲福利一区二区免费看| 自拍偷自拍亚洲精品被多人伦好爽| 亚洲熟妇无码一区二区三区导航| 久草免费福利资源站| 国产亚洲美日韩AV中文字幕无码成人| 亚洲乱码在线观看| 最近中文字幕完整版免费高清| 亚洲an日韩专区在线| 日本一道本不卡免费| 国产精品高清视亚洲精品| 91精品全国免费观看含羞草| 亚洲国产精品成人AV在线 | 亚洲人成图片小说网站| 国产在线观看片a免费观看| 一级特黄a大片免费|