using PTMedicalInsurance.Variables;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PTMedicalInsurance.Business.Core.Forms.DischargeAudit
{
    public partial class AdmissionRegistration : Form
    {
        private Form mainForm;
        private string err;
        private GridViewSetter grdSetter = new GridViewSetter();

        // 定义一个公共事件
        public event EventHandler SaveClicked;

        public DataTable DtDisease { get; set; }
        public DataTable DtDiseaseType { get; set; }
        public DataTable DtInsuranceType { get; set; }
        public DataTable DtMedicalType { get; set; }
        public DataTable DtOperation { get; set; }
        public DataTable DtSettlementWay { get; set; }

        //险种
        public string insuType { get; set; }
        public string insuTypeName { get; set; }
        //医疗类别
        public string med_type { get; set; }
        public string med_type_name { get; set; }
        //诊断
        public string diseCodg { get; set; }
        public string diseName { get; set; }
        //手术
        public string oprn_oprt_code { get; set; }
        public string oprn_oprt_name { get; set; }
        //病种
        public string dise_type_code { get; set; }
        public string dise_type_name { get; set; }
        //结算方式
        public string psn_setlway { get; set; }
        public string psn_setlway_name { get; set; }

        //提示
        public string HintText
        {
            get { return lbHint.Text; }
            set
            {
                if (lbHint.InvokeRequired)
                {
                    lbHint.Invoke(new Action(() => lbHint.Text = value));
                }
                else
                {
                    lbHint.Text = value;
                }
            }
        }

        private bool isHintVisible;
        public bool IsHintVisible
        {
            get { return isHintVisible; }
            set
            {
                if (isHintVisible != value)
                {
                    isHintVisible = value;

                    if (lbHint.InvokeRequired)
                    {
                        lbHint.Invoke(new Action(() =>
                        {
                            lbHint.Visible = isHintVisible;
                        }));
                    }
                    else
                    {
                        lbHint.Visible = isHintVisible;
                    }
                }
            }
        }
        private DataTable dtDiagnose;

        public DataTable DtDiagnose 
        { 
            get { return dtDiagnose; }
            set 
            {
                dtDiagnose = value;
                dgvDiagnose.DataSource = dtDiagnose;
            }
        }

        public string personAccountUsedFlag = "-1";

        public string halfwaySettlementFlag = "-1";

        public AdmissionRegistration()
        {
            InitializeComponent();
        }
        public AdmissionRegistration(Form frm)
        {
            InitializeComponent();
            InitForm(frm);
            //InitComboxDatasource();
        }

        public void InitComboxDatasource()
        {
            grdSetter.SetDBLKCombox(ref dblkcbxDisease, DtDisease);
            grdSetter.SetDBLKCombox(ref dblkcbxDiseaseType, DtDiseaseType);
            grdSetter.SetDBLKCombox(ref dblkcbxInsuranceType, DtInsuranceType);
            grdSetter.SetDBLKCombox(ref dblkcbxMedicalType, DtMedicalType);
            grdSetter.SetDBLKCombox(ref dblkcbxOperation, DtOperation);
            //grdSetter.SetDBLKCombox(ref dblkcbxSettelmentWay, DtSettlementWay);

        }
        private void InitForm(Form frm)
        {

            mainForm = frm;
            CheckForIllegalCrossThreadCalls = false;
            // 禁用关闭按钮
            this.FormBorderStyle = FormBorderStyle.None;

            // 隐藏标题栏
            this.ControlBox = false;

            // 其他可能需要的配置
            if (mainForm != this)
            {
                this.TopLevel = false;
                this.Dock = DockStyle.Fill; // 根据需要设置 Dock 属性
            }
            else
            {
                this.WindowState = FormWindowState.Maximized;
            }

        }

        private void dblkcbxInsuranceType_AfterSelector(object sender, PTControl.AfterSelectorEventArgs e)
        {
            DataGridViewRow row = e.Value as DataGridViewRow;
            DataRowView dataRow = row.DataBoundItem as DataRowView;

            insuType = dataRow["Code"].ToString().Trim();
            insuTypeName = dataRow["Name"].ToString().Trim();
        }

        private void dblkcbxMedicalType_AfterSelector(object sender, PTControl.AfterSelectorEventArgs e)
        {
            DataGridViewRow row = e.Value as DataGridViewRow;
            DataRowView dataRow = row.DataBoundItem as DataRowView;

            med_type = dataRow["Code"].ToString().Trim();
            med_type_name = dataRow["Name"].ToString().Trim();
            Global.pat.medType = med_type;
        }

        private void dblkcbxDisease_AfterSelector(object sender, PTControl.AfterSelectorEventArgs e)
        {
            DataGridViewRow row = e.Value as DataGridViewRow;
            DataRowView dataRow = row.DataBoundItem as DataRowView;

            diseCodg = dataRow["Code"].ToString().Trim();
            diseName = dataRow["Name"].ToString().Trim();
        }

        private void dblkcbxOperation_AfterSelector(object sender, PTControl.AfterSelectorEventArgs e)
        {
            DataGridViewRow row = e.Value as DataGridViewRow;
            DataRowView dataRow = row.DataBoundItem as DataRowView;

            oprn_oprt_code = dataRow["Code"].ToString().Trim();
            oprn_oprt_name = dataRow["Name"].ToString().Trim();
        }

        private void dblkcbxSettelmentWay_AfterSelector(object sender, PTControl.AfterSelectorEventArgs e)
        {
            DataGridViewRow row = e.Value as DataGridViewRow;
            DataRowView dataRow = row.DataBoundItem as DataRowView;

            psn_setlway = dataRow["Code"].ToString().Trim();
            psn_setlway_name = dataRow["Name"].ToString().Trim();
        }

        private void dblkcbxDiseaseType_AfterSelector(object sender, PTControl.AfterSelectorEventArgs e)
        {
            DataGridViewRow row = e.Value as DataGridViewRow;
            DataRowView dataRow = row.DataBoundItem as DataRowView;

            dise_type_code = dataRow["Code"].ToString().Trim();
            dise_type_name = dataRow["Name"].ToString().Trim();
        }

        private void btSave_Click(object sender, EventArgs e)
        {
            SaveClicked?.Invoke(this, e);
        }
    }
}
