<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を取得?設(shè)定します。
            
    /// </summary>
            //--------------------------------------------------------------
            public DataView Dv
            {
                get { return dv; }
                set { dv = value; }
            }

            //--------------------------------------------------------------
            /// <summary>
            
    /// CurrencyManagerを取得?設(shè)定します。
            
    /// </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); //テーブル名をキー値に設(shè)定
                    }
                }
                return viewSources;
            }

            //-----------------------------------------------------------------------
            /// <summary>
            
    /// バインディングコントロールリストを登録します。
            
    /// Control內(nèi)を走査
            
    /// </summary>
            
    /// <param name="top">このコントロール內(nèi)のバインディングコントロールを登録します。</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>
            
    /// コントロール內(nèi)の各コントロールに対し、バインディングコントロールリストから削除します。
            
    /// </summary>
            
    /// <param name="top">このコントロール內(nèi)のバインディングコントロールを登録します。</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>
            
    /// バインドを?qū)g行します。
            
    /// </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 //書式が設(shè)定されている場合
                                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 //書式が設(shè)定されている場合
                                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; //値の型を設(shè)定(テキストからコンボへのキャスト用)
                            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>
            
    /// バインディングプロパティ設(shè)定をチェックします。
            
    /// </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;

                //設(shè)定値取得
                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;
                }

                //設(shè)定エラーチェック
                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)))
                {
                    //テーブル名とフィールド名が設(shè)定されている場合はバインドする。
                    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;
                //バインドデータを取得します。(派生先を?qū)g行)
                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キーでのフォーカス制御を?qū)g裝しています。
            
    /// 適用する場合は派生先のクラスにて、KeyPreviewをTrueに設(shè)定して下さい。
            
    /// 但し、その場合DataGridViewにフォーカスが當(dāng)たっている場合であってもフォーカス移動されます。
            
    /// </summary>
            
    /// <param name="sender"></param>
            
    /// <param name="e"></param>
            //--------------------------------------------------------------
            private void FrmBase_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Enter)
                {
                    //DataGridView系統(tǒng)、RichTextBox系統(tǒng)のコントロールは除外されます。
                    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>
            
    /// テーブル名を取得?設(shè)定します。
            
    /// </summary>
            //--------------------------------------------------------------
            [DefaultValue("")]
            [Description("テーブル名")]
            public string TableName
            {
                get { return tableName; }
                set { tableName = value; }
            }

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

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

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

            //--------------------------------------------------------------
            /// <summary>
            
    /// リストテーブルの表示列を取得?設(shè)定します。
            
    /// </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
    主站蜘蛛池模板: 久久综合久久综合亚洲| 国产乱辈通伦影片在线播放亚洲| 国产亚洲精品岁国产微拍精品| 少妇亚洲免费精品| 日韩精品免费一区二区三区| 亚洲欧美综合精品成人导航| 成年女人午夜毛片免费视频| 亚洲色偷精品一区二区三区| 成在人线AV无码免费| 综合偷自拍亚洲乱中文字幕| 全部免费a级毛片| 免费无码国产在线观国内自拍中文字幕 | 国产乱子伦精品免费视频| 亚洲国产黄在线观看| 成人网站免费看黄A站视频| 日韩va亚洲va欧洲va国产| 在线观看片免费人成视频无码| 亚洲日本精品一区二区| 色se01短视频永久免费| 日韩亚洲不卡在线视频中文字幕在线观看| 成年18网站免费视频网站| 国产精品亚洲精品爽爽| 亚洲午夜福利717| 亚洲免费闲人蜜桃| 亚洲色大18成人网站WWW在线播放| 国产乱人免费视频| 久久久久免费视频| 亚洲视频在线不卡| 国产男女猛烈无遮挡免费网站 | 国产无遮挡又黄又爽免费视频| 香蕉国产在线观看免费| 亚洲精品一品区二品区三品区| 97av免费视频| 337P日本欧洲亚洲大胆精品| 人人狠狠综合久久亚洲88| 97热久久免费频精品99| 精品一区二区三区无码免费直播| 亚洲AV无码一区二区二三区入口 | 激情亚洲一区国产精品| 亚洲国产精品嫩草影院久久| 免费无遮挡无码永久视频|