⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datasourceselector.cs

📁 EpiInfo 开源的导航系统远程序,不知道在哪里下的了,分享一下,有兴趣的
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using Epi.Data;
using Epi.Fields;

namespace Epi.Windows.MakeView.Dialogs.FieldDefinitionDialogs
{

    /// <summary>
    /// Dialog for selecting the data source of a dropdown field
    /// </summary>
    public partial class DataSourceSelector : Form
    {

        private DDLFieldOfLegalValues field;
        string fieldName;
        string tableName;
        string columnName;

        /// <summary>
        /// Constructor for the class
        /// </summary>
        public DataSourceSelector()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Constructor for the class
        /// </summary>
        /// <param name="field">The field</param>
        /// <param name="currentFieldName">The name of the field</param>
        public DataSourceSelector(DDLFieldOfLegalValues field, string currentFieldName)
        {
            InitializeComponent();
            this.field = field;
            this.fieldName = currentFieldName;
            dgCodeTable.CaptionText += currentFieldName;
            if (!string.IsNullOrEmpty(field.SourceTableName))
            {
                tableName = field.SourceTableName;
                columnName = field.TextColumnName;
                dgCodeTable.DataSource = field.GetSourceData();
                btnCreate.Enabled = false;
                btnExisting.Enabled = false;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void btnCreate_Click(object sender, EventArgs e)
        {
            CodeTableDefinition codeTableDialog = new CodeTableDefinition();
            DialogResult result = codeTableDialog.ShowDialog();
            if (result == DialogResult.OK)
            {
                tableName = codeTableDialog.CodeTableName;
                columnName = codeTableDialog.CodeTableName;
                DataTable table = new DataTable(codeTableDialog.CodeTableName);
                table.Columns.Add(codeTableDialog.CodeTableName);
                dgCodeTable.DataSource = table;
                codeTableDialog.Close();
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            field.GetMetadata().CreateCodeTable(tableName, columnName);
            field.GetMetadata().SaveCodeTableData((DataTable)dgCodeTable.DataSource, tableName, columnName);
            this.DialogResult = DialogResult.OK;
            this.Hide();
        }

        /// <summary>
        /// Gets the table name
        /// </summary>
        public string TableName
        {
            get
            {
                return this.tableName;
            }
        }

        /// <summary>
        /// Gets the column name
        /// </summary>
        public string ColumnName
        {
            get
            {
                return this.columnName;
            }
        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -