using AIMSBLL;
using AIMSExtension;
using AxNsoOfficeLib;
using DrawGraph;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace AIMS.OperationAanesthesia
{
    public partial class frmOpeRecoverInInfo : Form
    {
        /// 
        /// 手术记录
        /// 
        public OperationRecord _record;
        public frmOpeRecoverInInfo()
        {
            InitializeComponent();
        }
        private void frmInPACUConditionSYD_Load(object sender, EventArgs e)
        {
            try
            {
                if (_record.OpeRecoverInInfo != null)
                {
                    cboMZPM.Text = _record.OpeRecoverInInfo.AnestheticPlane;
                    txtZPF.Text = _record.OpeRecoverInInfo.PACUStewardScore.ToString();
                    cboJSHF.Text = _record.OpeRecoverInInfo.MuscleRelaxation;//肌力评分 
                    cboPF.Text = _record.OpeRecoverInInfo.Skin;//皮肤破损 
                    cboTT.Text = _record.OpeRecoverInInfo.Pain;//VAS评分
                    cboJMTC.Text = _record.OpeRecoverInInfo.VenousPatency;//液路通畅
                    cboYLBS.Text = _record.OpeRecoverInInfo.DrainageIdentification;//引流管通畅
                    cboYLWZ.Text = _record.OpeRecoverInInfo.DrainagePosition;//尿管通畅
                    cboYLMC.Text = _record.OpeRecoverInInfo.DrainageName;//导管名称
                    if (_record.OpeRecoverInInfo.LightReflection != null) SetSpecialResult(_record.OpeRecoverInInfo.LightReflection);
                    txtT.Text = _record.OpeRecoverInInfo.Temp;//入室体温  
                    txtSQTSQK.Text = _record.OpeRecoverInInfo.Remark;
                    //if (_record.OpeRecoverInInfo.StewardSober != null && _record.OpeRecoverInInfo.StewardSober != "")
                    //{
                    //    foreach (string item in cboQXCD.Items)
                    //    {
                    //        if (item.Contains(_record.OpeRecoverInInfo.StewardSober))
                    //        {
                    //            cboQXCD.Text = item;
                    //        }
                    //    }
                    //}
                    //if (_record.OpeRecoverInInfo.StewardBreathing != null && _record.OpeRecoverInInfo.StewardBreathing != "")
                    //{
                    //    foreach (string item in cboHXDTCCD.Items)
                    //    {
                    //        if (item.Contains(_record.OpeRecoverInInfo.StewardBreathing))
                    //        {
                    //            cboHXDTCCD.Text = item;
                    //        }
                    //    }
                    //}
                    //if (_record.OpeRecoverInInfo.StewardLimbActivity != null && _record.OpeRecoverInInfo.StewardLimbActivity != "")
                    //{
                    //    foreach (string item in cboZTHDD.Items)
                    //    {
                    //        if (item.Contains(_record.OpeRecoverInInfo.StewardLimbActivity))
                    //        {
                    //            cboZTHDD.Text = item;
                    //        }
                    //    }
                    //}
                    //if (_record.OpeRecoverInInfo.BP != null && _record.OpeRecoverInInfo.BP != "")
                    //{
                    //    foreach (string item in txtBP.Items)
                    //    {
                    //        if (item.Contains(_record.OpeRecoverInInfo.BP))
                    //        {
                    //            txtBP.Text = item;
                    //        }
                    //    }
                    //}
                    //if (_record.OpeRecoverInInfo.SPO2 != null && _record.OpeRecoverInInfo.SPO2 != "")
                    //{
                    //    foreach (string item in txtSPO2.Items)
                    //    {
                    //        if (item.Contains(_record.OpeRecoverInInfo.SPO2))
                    //        {
                    //            txtSPO2.Text = item;
                    //        }
                    //    }
                    //}
                    cboQXCD.Text = _record.OpeRecoverInInfo.StewardSober;
                    cboHXDTCCD.Text = _record.OpeRecoverInInfo.StewardBreathing;
                    cboZTHDD.Text = _record.OpeRecoverInInfo.StewardLimbActivity;
                    txtBP.Text = _record.OpeRecoverInInfo.BP;//Aldrete血压
                    txtSPO2.Text = _record.OpeRecoverInInfo.SPO2;//AldreteSPO2
                    if (_record.ControlledAnalgesia != null && _record.ControlledAnalgesia != "")
                    {
                        checkBox5.Checked = true;
                    }
                    if (_record.OpeRecoverInInfo.Nausea != null && _record.OpeRecoverInInfo.Nausea != "")
                    {
                        txtPain.Text = _record.OpeRecoverInInfo.Nausea;
                        slider1.Value = int.Parse(_record.OpeRecoverInInfo.Nausea);
                    }
                    cmbYs.Text = _record.OpeRecoverInInfo.Consciousness;
                    xbohxxt.Text = _record.OpeRecoverInInfo.RespiratorySystem;
                    txtCQL.Text = _record.OpeRecoverInInfo.Iiquid;
                    txtQYXRL.Text = _record.OpeRecoverInInfo.Blood;
                    TXTXY.Text = _record.OpeRecoverInInfo.AutologousBlood;
                }
            }
            catch (Exception exp)
            {
                PublicMethod.WriteLog(exp, ""); return;
            }
        }
        /// 
        /// 关闭时保存
        /// 
        /// 
        /// 
        private void btExit_Click(object sender, EventArgs e)
        {
            try
            {
                if (_record.OpeRecoverInInfo != null)
                {
                    _record.OpeRecoverInInfo.PatientId = _record.PatientId;
                    _record.OpeRecoverInInfo.ApplyId = _record.OperationApplyId;
                    _record.OpeRecoverInInfo.OperationRecordId = _record.Id;
                    if (txtZPF.Text.Trim() != "") _record.OpeRecoverInInfo.PACUStewardScore = int.Parse(txtZPF.Text);
                    _record.OpeRecoverInInfo.MuscleRelaxation = cboJSHF.Text;
                    _record.OpeRecoverInInfo.Temp = txtT.Text;
                    _record.OpeRecoverInInfo.Skin = cboPF.Text;
                    _record.OpeRecoverInInfo.Nausea = txtPain.Text;
                    _record.OpeRecoverInInfo.Pain = cboTT.Text;
                    _record.OpeRecoverInInfo.VenousPatency = cboJMTC.Text;
                    _record.OpeRecoverInInfo.DrainageIdentification = cboYLBS.Text;
                    _record.OpeRecoverInInfo.DrainagePosition = cboYLWZ.Text;
                    _record.OpeRecoverInInfo.DrainageName = cboYLMC.Text;
                    _record.OpeRecoverInInfo.LightReflection = GetSpecialResult();
                    _record.OpeRecoverInInfo.AnestheticPlane = cboMZPM.Text;
                    _record.OpeRecoverInInfo.Remark = txtSQTSQK.Text;
                    _record.OpeRecoverInInfo.StewardSober = cboQXCD.Text;
                    _record.OpeRecoverInInfo.StewardBreathing = cboHXDTCCD.Text;
                    _record.OpeRecoverInInfo.StewardLimbActivity = cboZTHDD.Text;
                    _record.OpeRecoverInInfo.BP = txtBP.Text;
                    _record.OpeRecoverInInfo.SPO2 = txtSPO2.Text;
                    _record.OpeRecoverInInfo.Consciousness = cmbYs.Text;
                    _record.OpeRecoverInInfo.RespiratorySystem = xbohxxt.Text;
                    _record.OpeRecoverInInfo.Iiquid = txtCQL.Text;
                    _record.OpeRecoverInInfo.Blood = txtQYXRL.Text;
                    _record.OpeRecoverInInfo.AutologousBlood = TXTXY.Text;
                    //if (cboQXCD.Text != "")
                    //    _record.OpeRecoverInInfo.StewardSober = cboQXCD.Text.Substring(0, cboQXCD.Text.LastIndexOf('(') - 1);
                    //else
                    //    _record.OpeRecoverInInfo.StewardSober = "";
                    //if (cboHXDTCCD.Text != "")
                    //    _record.OpeRecoverInInfo.StewardBreathing = cboHXDTCCD.Text.Substring(0, cboHXDTCCD.Text.LastIndexOf('(') - 1);
                    //else
                    //    _record.OpeRecoverInInfo.StewardBreathing = "";
                    //if (cboZTHDD.Text != "")
                    //    _record.OpeRecoverInInfo.StewardLimbActivity = cboZTHDD.Text.Substring(0, cboZTHDD.Text.LastIndexOf('(') - 1);
                    //else
                    //    _record.OpeRecoverInInfo.StewardLimbActivity = "";
                    //if (txtBP.Text != "")
                    //    _record.OpeRecoverInInfo.BP = txtBP.Text.Substring(0, txtBP.Text.LastIndexOf('(') - 1);
                    //else
                    //    _record.OpeRecoverInInfo.BP = "";
                    //if (txtSPO2.Text != "")
                    //    _record.OpeRecoverInInfo.SPO2 = txtSPO2.Text.Substring(0, txtSPO2.Text.LastIndexOf('(') - 1);
                    //else
                    //    _record.OpeRecoverInInfo.SPO2 = "";
                    _record.OpeRecoverInInfo.OperatorId = PublicMethod.OperatorId;
                    _record.OpeRecoverInInfo.OperatorTime = DateTime.Now;
                    if (_record.OpeRecoverInInfo.Id == null)
                    {
                        _record.OpeRecoverInInfo.Id = BOperationRecoverInInfo.Insert(_record.OpeRecoverInInfo);
                    }
                    else
                    {
                        BOperationRecoverInInfo.Update(_record.OpeRecoverInInfo);
                    }
                }
            }
            catch (Exception exp)
            {
                PublicMethod.WriteLog(exp, ""); return;
            }
        }
        private void frmInPACUConditionSYD_FormClosing(object sender, FormClosingEventArgs e)
        {
            btExit_Click(null, null);
        }
        /// 
        /// 意识
        /// 
        int StewardSober = 0;
        /// 
        /// 呼吸
        /// 
        int StewardBreathing = 0;
        /// 
        /// 活动
        /// 
        int StewardLimbActivity = 0;
        /// 
        /// 血压
        /// 
        int StewardBP = 0;
        /// 
        /// Spo2
        /// 
        int StewardSpo2 = 0;
        /// 
        /// 总评分
        /// 
        /// 
        /// 
        private void cboQXCD_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboQXCD.Text != null && cboQXCD.Text.Trim() != "") StewardSober = GetSourcesDate(cboQXCD).Value;
            if (cboHXDTCCD.Text != null && cboHXDTCCD.Text.Trim() != "") StewardBreathing = GetSourcesDate(cboHXDTCCD).Value;
            if (cboZTHDD.Text != null && cboZTHDD.Text.Trim() != "") StewardLimbActivity = GetSourcesDate(cboZTHDD).Value;
            if (txtBP.Text != null && txtBP.Text.Trim() != "") StewardBP = GetSourcesDate(txtBP).Value;
            if (txtSPO2.Text != null && txtSPO2.Text.Trim() != "") StewardSpo2 = GetSourcesDate(txtSPO2).Value;
            txtZPF.Text = (StewardSober + StewardBreathing + StewardLimbActivity + StewardBP + StewardSpo2).ToString();
        }
        public int? GetSourcesDate(ComboBox SelCombo)
        {
            int? res = null;
            string text = SelCombo.Text.Substring(0, 4);
            if (text.Contains("0"))
            {
                res = 0;
            }
            if (text.Contains("1"))
            {
                res = 1;
            }
            if (text.Contains("2"))
            {
                res = 2;
            }
            if (text.Contains("3"))
            {
                res = 3;
            }
            return res;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (cboJMTC.Text == "") cboJMTC.Text = "是";
            //if (cboYLBS.Text == "") cboYLBS.Text = "是";
            //if (cboYLWZ.Text == "") cboYLWZ.Text = "是";
            if (cboPF.Text == "") cboPF.Text = "未见异常";
            if (cboZTHDD.Text == "") cboZTHDD.Text = "2分-自主或遵嘱活动四肢和抬头";
            if (cboHXDTCCD.Text == "") cboHXDTCCD.Text = "2分-能深呼吸和有效咳嗽,呼吸频率和幅度正常";
            if (txtBP.Text == "") txtBP.Text = "2分-麻醉前±20%以内";
            if (cboQXCD.Text == "") cboQXCD.Text = "2分-完全清醒(准确回答)";
            if (txtSPO2.Text == "") txtSPO2.Text = "2分-呼吸空气SpO2≥92%";
            //入室肌力评分无意义
            if (cboJSHF.Text == "") cboJSHF.Text = "Ⅴ级 肌力正常,运动自如";
            if (cboTT.Text == "") cboTT.Text = "0分-无疼痛";
            if (txtSQTSQK.Text == "") txtSQTSQK.Text = "  /";
            if (txtT.Text == "") txtT.Text = " /";
            if (cmbYs.Text == "") cmbYs.Text = "未醒";
            if (xbohxxt.Text == "") xbohxxt.Text = "皮囊控制呼吸";
            if (txtCQL.Text == "") txtCQL.Text = " /";
            if (txtQYXRL.Text == "") txtQYXRL.Text = " /";
            if (TXTXY.Text == "") TXTXY.Text = " /";
            if (cboYLBS.Text == "") cboYLBS.Text = " /";
            if (cboYLWZ.Text == "") cboYLWZ.Text = " /";
            slider1.Value = 5;
        }
        private void cboMZPM_SelectedIndexChanged(object sender, EventArgs e)
        {
        }
        public string GetSpecialResult()
        {
            string specila = "";
            List strs = new List();
            if (checkBox1.Checked == true)
            {
                strs.Add(checkBox1.Text);
            }
            if (checkBox2.Checked == true)
            {
                strs.Add(checkBox2.Text);
            }
            if (checkBox3.Checked == true)
            {
                strs.Add(checkBox3.Text);
            }
            if (checkBox4.Checked == true)
            {
                strs.Add(checkBox4.Text);
            }
            if (checkBox5.Checked == true)
            {
                strs.Add(checkBox5.Text);
            }
            if (checkBox6.Checked == true)
            {
                //strs.Add(checkBox6.Text);
                strs.Add(uText1.Text);
            }
            if (strs.Count > 0)
            {
                specila = String.Join(" ", strs);
            }
            return specila;
        }
        public void SetSpecialResult(string specila)
        {
            List strs = new List();
            strs = specila.Split(' ').ToList();
            foreach (string item in strs)
            {
                if (item == checkBox1.Text)
                {
                    checkBox1.Checked = true;
                    continue;
                }
                else if (item == checkBox2.Text)
                {
                    checkBox2.Checked = true;
                    continue;
                }
                else if (item == checkBox3.Text)
                {
                    checkBox3.Checked = true;
                    continue;
                }
                else if (item == checkBox4.Text)
                {
                    checkBox4.Checked = true;
                    continue;
                }
                else if (item == checkBox5.Text)
                {
                    checkBox5.Checked = true;
                    continue;
                }
                //else if (item == checkBox6.Text)
                //{
                //    checkBox6.Checked = true;
                //    continue;
                //}
                else if (item != "")
                {
                    checkBox6.Checked = true;
                    uText1.Text = item;
                    continue;
                }
            }
        }
        private void checkBox6_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox6.Checked == true)
            {
                uText1.ReadOnly = false;
                uText1.Focus();
            }
            else
            {
                uText1.ReadOnly = true;
                uText1.Text = "";
            }
        }
        private void slider1_ValueChanged(object sender, EventArgs e)
        {
            txtPain.Text = slider1.Value.ToString();
        }
        private void groupBox1_Enter(object sender, EventArgs e)
        {
        }
    }
}