/******************************************************************************
 * 文件名称: GridViewSetter.cs
 * 文件说明: GridView界面的设置
 * 当前版本: V1.0
 * 创建日期: 2022-04-14
 * 2020-04-14: 增加 AddDGVColumn 方法
 * 2020-04-14: 增加 AddDGVCheckBoxColumn 方法
 * 2020-04-14: 增加 SetHeaderTextOfDrug 方法
 * 2020-04-14: 增加 SetHeaderTextOfDiagnose 方法


******************************************************************************/
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DirectoryDownload.FormSetter
{
    class GridViewSetter
    {
        /// <summary>
        /// 动态增加datagridview列
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="headerText"></param>
        /// <param name="dataPropertyName"></param>
        private void AddDGVColumn(DataGridView dgv, string headerText, string dataPropertyName, int width = 120)
        {
            DataGridViewColumn newColumn = new DataGridViewTextBoxColumn();
            newColumn.HeaderText = headerText;
            newColumn.Width = width;
            newColumn.DataPropertyName = dataPropertyName;
            newColumn.Name = dataPropertyName;
            dgv.Columns.Add(newColumn);
        }

        private void AddDGVCheckBoxColumn(DataGridView dgv, string headerText, string dataPropertyName, int width = 120)
        {
            DataGridViewColumn newColumn = new DataGridViewCheckBoxColumn();
            newColumn.HeaderText = headerText;
            newColumn.Width = width;
            newColumn.DataPropertyName = dataPropertyName;
            newColumn.Name = dataPropertyName;
            dgv.Columns.Add(newColumn);
        }

        private void AddDGVComboxColumn(DataTable dt,DataGridView dgv, string headerText, string dataPropertyName, int width = 120)
        {
            DataGridViewComboBoxColumn newColumn = new DataGridViewComboBoxColumn();
            newColumn.DataSource = dt;
            newColumn.HeaderText = headerText;
            newColumn.Width = width;
            newColumn.DataPropertyName = dataPropertyName;
            newColumn.Name = dataPropertyName;
            newColumn.DisplayMember = "descripts";
            newColumn.ValueMember = "id";
            dgv.Columns.Add(newColumn);
        }

        #region 设置表格标题
        /// <summary>
        /// 设置接口维护界面标题
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="dgv"></param>
        public void SetHeaderTextOfInterfaceMaintain(DataTable dt, DataGridView dgv)
        {
            dgv.Columns.Clear();
            dgv.AutoGenerateColumns = false;
            AddDGVComboxColumn(dt,dgv, "医院ID", "HospitalDr", 200);
            AddDGVColumn(dgv, "编码", "InterfaceNO", 200);
            AddDGVColumn(dgv, "名称", "InterfaceName", 200);
            AddDGVColumn(dgv, "医院编码", "HospitalNO");
            AddDGVColumn(dgv, "医院名称", "HospitalName",200);
            AddDGVColumn(dgv, "医院等级", "HospitalLevel");
            AddDGVColumn(dgv, "中心网址", "CenterURL");
            AddDGVColumn(dgv, "中心网址2", "CenterURL2");
            AddDGVColumn(dgv, "对应DLL名称", "DLLName");
            AddDGVColumn(dgv, "区划代码", "AreaCode");
            AddDGVCheckBoxColumn(dgv, "使用标志", "UseFlag");
        }
        /// <summary>
        /// 设置药品列标题
        /// </summary>
        public void SetHeaderTextOfDrug(DataGridView dgv)
        {
            dgv.Columns.Clear();
            dgv.AutoGenerateColumns = false;
            AddDGVColumn(dgv, "编码", "Code", 200);
            AddDGVColumn(dgv, "名称", "Name", 200);
            AddDGVColumn(dgv, "批准文号", "ApprovalNO", 200);
            AddDGVColumn(dgv, "剂型", "DosageFormCode");
            AddDGVColumn(dgv, "剂型名称", "DosageFormName");
            AddDGVColumn(dgv, "规格", "Specification");
            AddDGVColumn(dgv, "包装单位", "UnitOfPackag");
            AddDGVColumn(dgv, "计价单位", "UnitOfValuation");
            AddDGVColumn(dgv, "有效标志", "ValidFlag");
            AddDGVCheckBoxColumn(dgv, "使用标志", "UseFlag");
            AddDGVColumn(dgv, "特殊药品标志", "SpecialFlag");
            AddDGVColumn(dgv, "限制标志", "LimitFlag");
            AddDGVColumn(dgv, "限制范围", "LimitRange");
            AddDGVColumn(dgv, "版本号", "VersionNO");
        }

        /// <summary>
        /// 设置诊断，手术，病种等列标题
        /// </summary>
        public void SetHeaderTextOfDiagnose(DataGridView dgv)
        {
            dgv.Columns.Clear();
            dgv.AutoGenerateColumns = false;
            AddDGVColumn(dgv, "编码", "Code", 200);
            AddDGVColumn(dgv, "名称", "Name", 500);

        }
        public void SetHeaderTextOfDictionary(DataGridView dgv)
        {
            dgv.Columns.Clear();
            dgv.AutoGenerateColumns = false;
            AddDGVColumn(dgv, "大类", "Type");
            AddDGVColumn(dgv, "编码", "Code");
            AddDGVColumn(dgv, "名称", "Name",500);//PinyinSearchCode
            AddDGVColumn(dgv, "查找码", "PinyinSearchCode",200);
        }
        public void SetHeaderTextOfMedicalService(DataGridView dgv)
        {
            dgv.Columns.Clear();
            dgv.AutoGenerateColumns = false;
            AddDGVColumn(dgv, "编码", "Code", 200);
            AddDGVColumn(dgv, "名称", "Name", 200);
            AddDGVColumn(dgv, "批准文号", "ApprovalNO", 200);
            AddDGVColumn(dgv, "剂型", "DosageFormCode");
            AddDGVColumn(dgv, "剂型名称", "DosageFormName");
            AddDGVColumn(dgv, "规格", "Specification");
            AddDGVColumn(dgv, "包装单位", "UnitOfPackag");
            AddDGVColumn(dgv, "计价单位", "UnitOfValuation");
            AddDGVColumn(dgv, "有效标志", "ValidFlag");
            AddDGVCheckBoxColumn(dgv, "使用标志", "UseFlag");
            AddDGVColumn(dgv, "特殊药品标志", "SpecialFlag");
            AddDGVColumn(dgv, "限制标志", "LimitFlag");
            AddDGVColumn(dgv, "限制范围", "LimitRange");
            AddDGVColumn(dgv, "版本号", "VersionNO");
        }
        /// <summary>
        /// 材料
        /// </summary>
        /// <param name="dgv"></param>
        public void SetHeaderTextOfMaterials(DataGridView dgv)
        {
            dgv.Columns.Clear();
            dgv.AutoGenerateColumns = false;
            AddDGVColumn(dgv, "编码", "Code", 200);
            AddDGVColumn(dgv, "名称", "Name", 200);
            AddDGVColumn(dgv, "批准文号", "ApprovalNO", 200);
            AddDGVColumn(dgv, "剂型", "DosageFormCode");
            AddDGVColumn(dgv, "剂型名称", "DosageFormName");
            AddDGVColumn(dgv, "规格", "Specification");
            AddDGVColumn(dgv, "包装单位", "UnitOfPackag");
            AddDGVColumn(dgv, "计价单位", "UnitOfValuation");
            AddDGVColumn(dgv, "有效标志", "ValidFlag");
            AddDGVCheckBoxColumn(dgv, "使用标志", "UseFlag");
            AddDGVColumn(dgv, "特殊药品标志", "SpecialFlag");
            AddDGVColumn(dgv, "限制标志", "LimitFlag");
            AddDGVColumn(dgv, "限制范围", "LimitRange");
            AddDGVColumn(dgv, "版本号", "VersionNO");
        }

        public void SetHeaderTextOfMapping_HisDirectory(DataGridView dgv)
        {
            dgv.Columns.Clear();
            dgv.AutoGenerateColumns = false;
            AddDGVColumn(dgv, "序号", "tind",30);
            AddDGVColumn(dgv, "医院编码", "itemCode", 80);
            AddDGVColumn(dgv, "医院名称", "itemDesc", 120);
            AddDGVColumn(dgv, "中心编码", "insuCode", 200);
            AddDGVColumn(dgv, "中心名称", "insuName");
            AddDGVColumn(dgv, "对照状态", "flag",80);
            AddDGVColumn(dgv, "规格", "spec",100);
            AddDGVColumn(dgv, "单位", "itemUnitDesc");
            AddDGVColumn(dgv, "批准文号", "pprovalNo",120);

        }
        #endregion
    }
    
}
