using System;
using System.Collections.Generic;
using System.Text;
using DrawGraph;
using System.Drawing;
using System.Xml.Serialization;
using System.Data.SqlClient;
using HelperDB;
using System.Resources;
using AIMSExtension;
using System.Windows.Forms;
using System.Reflection;
namespace DrawGraph
{
    public class PhysioDataConfig : EventObj
    {
        #region 属性
        private int id;
        private int patientId;
        private string name;
        private string enname;
        private string color;
        private string imgPath;
        private int highLimit;
        private int lowLimit;
        private bool isValid;
        private string operatorNo;
        private string operatorName;
        private DateTime operateDate;
        private string configType;
        private bool showImg;
        private bool showText;
        private int warningHighLimit;
        private int warningLowLimit;
        private bool isSplit;
        private bool isDefalultShow;
        private string unit;
        private int physioOrder;
        /// 
        /// 
        /// 
        public int Id
        {
            get { return id; }
            set { id = value; }
        }
        /// 
        /// 手术ID
        /// 
        public int PatientId
        {
            get { return patientId; }
            set { patientId = value; }
        }
        /// 
        /// 
        /// 
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        /// 
        /// 
        /// 
        public string Enname
        {
            get { return enname; }
            set { enname = value; }
        }
        /// 
        /// 
        /// 
        public string Color
        {
            get { return color; }
            set { color = value; }
        }
        /// 
        /// 
        /// 
        public string ImgPath
        {
            get { return imgPath; }
            set { imgPath = value; }
        }
        /// 
        /// 
        /// 
        public int HighLimit
        {
            get { return highLimit; }
            set { highLimit = value; }
        }
        /// 
        /// 
        /// 
        public int LowLimit
        {
            get { return lowLimit; }
            set { lowLimit = value; }
        }
        /// 
        /// 
        /// 
        public bool IsValid
        {
            get { return isValid; }
            set { isValid = value; }
        }
        /// 
        /// 
        /// 
        public string OperatorNo
        {
            get { return operatorNo; }
            set { operatorNo = value; }
        }
        /// 
        /// 
        /// 
        public string OperatorName
        {
            get { return operatorName; }
            set { operatorName = value; }
        }
        /// 
        /// 
        /// 
        public DateTime OperateDate
        {
            get { return operateDate; }
            set { operateDate = value; }
        }
        /// 
        /// 
        /// 
        public string ConfigType
        {
            get { return configType; }
            set { configType = value; }
        }
        /// 
        /// 
        /// 
        public bool ShowImg
        {
            get { return showImg; }
            set { showImg = value; }
        }
        /// 
        /// 
        /// 
        public bool ShowText
        {
            get { return showText; }
            set { showText = value; }
        }
        /// 
        /// 
        /// 
        public int WarningHighLimit
        {
            get { return warningHighLimit; }
            set { warningHighLimit = value; }
        }
        /// 
        /// 
        /// 
        public int WarningLowLimit
        {
            get { return warningLowLimit; }
            set { warningLowLimit = value; }
        }
        /// 
        /// 
        /// 
        public bool IsSplit
        {
            get { return isSplit; }
            set { isSplit = value; }
        }
        /// 
        /// 
        /// 
        public bool IsDefalultShow
        {
            get { return isDefalultShow; }
            set { isDefalultShow = value; }
        }
        /// 
        /// 
        /// 
        public string Unit
        {
            get { return unit; }
            set { unit = value; }
        }
        /// 
        /// 
        /// 
        public int PhysioOrder
        {
            get { return physioOrder; }
            set { physioOrder = value; }
        }
        #endregion
        #region 私有变量 
        private int yAisx = 0;
        private Color conveColor;
        public double X_MINOR_GRID_STEP = 5.0; //步长
        private PointPairList aPhysioDatas;
        PhysioData pdTrue = null;
        public double YLocation { get; set; }
        [XmlIgnore]
        private LineItem curve1;
        [XmlIgnore]
        private bool isClick = false;
        [XmlIgnore]
        public LineItem curve
        {
            get { return curve1; }
            set { curve1 = value; }
        }
        [XmlIgnore]
        public bool IsClick
        {
            get { return isClick; }
            set { isClick = value; }
        }
        /// 
        /// 生理数据集合
        /// 
        public PointPairList APhysioParams
        {
            get { return aPhysioDatas; }
            set { aPhysioDatas = value; }
        }
        /// 
        /// 此曲线的Y轴
        /// 
        public int YAisx
        {
            get { return yAisx; }
            set { yAisx = value; }
        }
        /// 
        /// 线的着色
        /// 
        public Color ConveColor
        {
            get { return conveColor; }
            set { conveColor = value; }
        }
        /// 
        /// Panel动态填写对象
        /// 
        public AbleEditPackObj phListPack = null;
        public delegate void ClickEventHandler(object sender, EventArgs e);
        public event ClickEventHandler Click;
        public void onClick(EventArgs e)
        {
            if (Click != null)
            {
                Click(this, e);
            }
        }
        public PhysioDataConfig()
        {
            APhysioParams = new PointPairList();
        }
        #endregion
        #region 初始化
        /// 
        /// 画生理曲线,即初始化
        /// 
        public void initCurve(bool isValidLine = true)
        {
            if (zgcAnas == null)
            {
                return;
            }
            PointPairList ppl = new PointPairList();
            curve = ZUtil.AddCurve(Name, ppl, conveColor, imgPath, true, zgcAnas, TextPrefix.PI + Name + Id.ToString());
            curve.YAxisIndex = this.YAisx;
            curve.Label.IsVisible = this.isValid;
            curve.Symbol.IsVisible = this.isValid;
            curve.Line.IsVisible = isValidLine;
            curve.Label.FontSpec = new FontSpec("微软雅黑", 5.9f, System.Drawing.Color.Black, false, false, false);
            curve.Label.FontSpec.Border.IsVisible = false;
            curve.Label.FontSpec.Fill.IsVisible = false;
        }
        /// 
        /// 重新设置曲线属性
        /// 
        public void reSetCurve()
        {
            this.curve.Color = this.ConveColor;
            this.curve.Symbol.Fill = new Fill(new ZUtil().getImage(this.imgPath), System.Drawing.Drawing2D.WrapMode.Clamp);
            this.curve.IsVisible = this.isValid;
            this.curve.YAxisIndex = this.YAisx;
            curve.Label.IsVisible = this.isValid;
            curve.Line.IsVisible = this.isValid;
            curve.Symbol.IsVisible = this.isValid;
            if (!ShowText)
            {
                foreach (PointPair pp in APhysioParams)
                {
                    PhysioData pd = PointPairToPhysioData(pp);
                    if (pd != null)
                    {
                        delAddObj(pd);
                        SetPositionText(pd, "-1");
                    }
                }
            }
            else
            {
                foreach (PointPair pp in APhysioParams)
                {
                    PhysioData pd = PointPairToPhysioData(pp);
                    if (pd != null) DrawTextPhysioData(pd);
                }
            }
        }
        /// 
        /// 重新设置曲线属性
        /// 
        public void reSetCurveSpo2()
        {
            this.curve.Color = this.ConveColor;
            this.curve.Symbol.Fill = new Fill(new ZUtil().getImage(this.imgPath), System.Drawing.Drawing2D.WrapMode.Clamp);
            this.curve.IsVisible = this.isValid;
            this.curve.YAxisIndex = this.YAisx;
            curve.Label.IsVisible = this.isValid;
            curve.Line.IsVisible = this.isValid;
            curve.Symbol.IsVisible = this.isValid;
        }
        public static IList GetLifeList()
        {
            string sql = "Select * FROM PhysioDataConfig where ConfigType='生命体征' order by PhysioOrder asc";
            return GetListBySql(sql);
        }
        public static IList GetAnesList()
        {
            string sql = "Select * FROM PhysioDataConfig where ConfigType='麻醉体征' order by PhysioOrder asc";
            return GetListBySql(sql);
        }
        #endregion
        #region 数据操作
        public void AddPointItem(PhysioData pd, bool isInsertDB = true)
        {
            //如果是负数则不执行操作
            if (pd.Value <= 0) return;
            bool isHave = false;
            foreach (PointPair pptemp in APhysioParams)
            {
                PhysioData temp1 = PointPairToPhysioData(pptemp);
                if (pd.isEquert(temp1) && temp1.Value != Double.MaxValue)
                {
                    isHave = true;
                    break;
                }
            }
            if (isHave) return;
            if (APhysioParams.Count > 0)
            {
                PhysioData pdTemp = pd.Clone();
                //当前点的前一个点加步长时间的结点
                PhysioData pdQD = reMPhysioData(pdTemp);
                //插入的点大于之前点5分钟以上
                if (DateTime.Compare(pd.RecordTime, pdQD.RecordTime.AddMinutes(1)) > 0)
                {
                    pdTemp.Value = Double.MaxValue;
                    this.APhysioParams.Add(pdTemp);
                }
            }
            this.APhysioParams.Add(pd);
            Sort();
            curve.Points = APhysioParams;
            if (isInsertDB == true)
                PhysioDataService.AddPhysioData(pd);
            if (ShowText == true)
            {
                DrawTextPhysioData(pd);
            }
        }
        /// 
        /// 增加一点生理数据,往数据库中写入数据
        /// 
        /// 
        public void AddItem(PhysioData pd, bool isShouDong = true, bool isFillMissPoint = true)
        {
            //如果是负数则不执行操作
            if (pd.Value < 0) return;
            if (pdTrue == null)
                pdTrue = pd.Clone();
            if (APhysioParams.Count > 0)
            {
                PhysioData pdTemp = pd.Clone();
                //当前点的前一个点加步长时间的结点
                PhysioData pdQD = reMPhysioData(pdTemp);
                //插入的点大于之前点5分钟以上
                if (DateTime.Compare(pd.RecordTime, pdQD.RecordTime.AddMinutes(1)) > 0)
                {
                    pdTemp.Value = Double.MaxValue;
                    this.APhysioParams.Add(pdTemp);
                }
            }
            if (isShouDong)
                pd = reCnterValue(pd);
            //增加点时如果当前有点且是隐藏的则直接改值
            Sort();
            bool isHave = false;
            foreach (PointPair pptemp in APhysioParams)
            {
                PhysioData pdTemp = PointPairToPhysioData(pptemp);
                if (pdTemp.isEquert(pd) && pdTemp.Value == Double.MaxValue)
                {
                    pptemp.Y = pd.Value;
                    isHave = true;
                    break;
                }
                else if (pdTemp.isEquert(pd))
                {
                    isHave = true;
                    break;
                }
            }
            if (!isHave)
            {
                this.APhysioParams.Add(pd);
            }
            Sort();
            pd.ValueString = pd.Value.ToString();
            curve.Points = APhysioParams;
            PhysioDataService.AddPhysioData(pd);
            if (ShowText == true)
            {
                DrawTextPhysioData(pd);
            }
            if (isShouDong == true)
            {
                for (int i = APhysioParams.Count - 1; i > -1; i--)
                {
                    PhysioData maxPhysioData = PointPairToPhysioData(APhysioParams[i]);
                    if (i != 0 && i != APhysioParams.Count - 1)
                    {
                        if (maxPhysioData.Y == Double.MaxValue)
                        {
                            bool b = false;
                            for (int j = 0; j < APhysioParams.Count; j++)
                            {
                                PhysioData pdt = PointPairToPhysioData(APhysioParams[j]);
                                if (pdt.RecordTime == maxPhysioData.RecordTime && pdt.Value <= HighLimit)
                                {
                                    b = true;
                                    break;
                                }
                            }
                            if (b == true)
                                this.APhysioParams.Remove(maxPhysioData);
                        }
                    }
                }
            }
            if (isFillMissPoint == true && pdTrue != null)
            {
                //返回当前曲线上最大且不为空的点
                PhysioData maxPd = ReMaxAndGoodPhysioData();
                if (maxPd != null && pdTrue.RecordTime > maxPd.RecordTime)
                {
                    int timeDiff = DateTime.Compare(pdTrue.RecordTime, maxPd.RecordTime);
                    //因为插入的真实点大于曲线上最后一个点,则指增加生理数据
                    if (timeDiff > 0)
                    {
                        //如果新增加的点还小于真实的点,则批量增加生理数据
                        if (DateTime.Compare(pd.RecordTime, pdTrue.RecordTime) < 0 && pd.RecordTime.ToString("HH:mm") != pdTrue.RecordTime.ToString("HH:mm"))
                        {
                            pd.RecordTime = pd.RecordTime.AddMinutes(this.X_MINOR_GRID_STEP);
                            bool isHavechild = false;
                            foreach (PointPair pptemp in APhysioParams)
                            {
                                PhysioData pdTemp = PointPairToPhysioData(pptemp);
                                if (pdTemp.isEquert(pd) && pdTemp.Value != Double.MaxValue)
                                {
                                    isHavechild = true;
                                    break;
                                }
                            }
                            if (isHavechild == false)
                                AddItem(pd, isShouDong, isFillMissPoint);
                        }
                    }
                    else
                    {
                        pdTrue = null;
                    }
                }
                else
                {
                    pdTrue = null;
                }
            }
        }
        /// 
        /// 增加一点生理数据,往数据库中写入数据
        /// 
        /// 
        public void AddMultipleItem(PhysioData pd, DateTime endtime, int collectInterval)
        {
            //如果是负数则不执行操作
            pd = reCnterValue(pd);
            TimeSpan tsp = endtime - pd.RecordTime;
            if (tsp.TotalMinutes >= 20 && this.IsSplit == true)
            {
                pd.RecordTime = endtime;
                pd = reCnterValue(pd, false);
                AddItem(pd, false);
            }
            else
            {
                pd.RecordTime = endtime;
                AddItem(pd);
            }
        }
        /// 
        /// 仅修改值不修改数据库
        /// 
        /// 
        /// 
        /// 
        public PhysioData MoveItem(PhysioData newPd)
        {
            //如果是负数则不执行操作
            if (newPd.Value < 0) return null;
            newPd = reCnterValue(newPd);
            int index = indexOf(newPd);
            if (index == -1) return null;
            this.APhysioParams[index].Y = newPd.Y;
            Sort();
            curve.Points = APhysioParams;
            if (ShowText == true)
            {
                MoveText(newPd);
            }
            return newPd;
        }
        private void MoveText(PhysioData newPd)
        {
            TextObj text = (TextObj)zgcAnas.MasterPane.GraphObjList[this.Enname + newPd.RecordTime.ToString()];
            if (text != null)
            {
                text.Location.Y = YLocation;
                text.Text = ((int)newPd.Value).ToString();
            }
        }
        public void ModifyItem(PhysioData oldPd, PhysioData newPd)
        {
            //如果是负数则不执行操作
            if (newPd.Value < 0 && oldPd.PhysioDataConfigId != newPd.PhysioDataConfigId)
                return;
            int index = indexOf(newPd);
            if (index == -1) return;
            //newPd = reCnterValue(newPd, false);
            newPd.ValueString = newPd.Value.ToString();
            this.APhysioParams[index].Y = newPd.Y;
            Sort();
            curve.Points = APhysioParams;
            PhysioDataService.UpdatePhysioData(oldPd, newPd, PublicMethod.OperatorName);
            if (ShowText == true)
            {
                delAddObj(oldPd);
                DrawTextPhysioData(newPd);
            }
        }
        /// 
        /// 删除一点生理数据
        /// 
        /// 
        public void DelItem(PhysioData pd)
        {
            Sort();
            //如果是两头的点就删除,如果是中间的点就设置为无效
            bool isModmaxValue = false;
            for (int i = APhysioParams.Count - 1; i > -1; i--)
            {
                PhysioData maxPhysioData = PointPairToPhysioData(APhysioParams[i]);
                if (maxPhysioData.isEquert(pd) && i != 0 && i != APhysioParams.Count - 1)
                {
                    APhysioParams[i].Y = Double.MaxValue;
                    isModmaxValue = true;
                    break;
                }
            }
            if (!isModmaxValue)
                this.APhysioParams.Remove(pd);
            curve.Points = APhysioParams;
            Sort();
            if (ShowText == true || pd.Value == HighLimit)
            {
                delAddObj(pd);
                SetPositionText(pd, "-1");
            }
            PhysioDataService.DelPhysioByValueData(pd);
            for (int i = APhysioParams.Count - 1; i > -1; i--)
            {
                PhysioData maxPhysioData = PointPairToPhysioData(APhysioParams[i]);
                if (maxPhysioData.isEquert(pd) && maxPhysioData.Y != Double.MaxValue)
                {
                    this.APhysioParams.Remove(APhysioParams[i]);
                    break;
                }
            }
        }
        public void DelItems(DateTime RecordTime, DateTime EndTime)
        {
            PhysioDataService.DelPhysioasDataParameterID(RecordTime, EndTime, this.Id, this.PatientId);
        }
        public void DrawTextPhysioData(PhysioData pd)
        {
            delAddObj(pd);
            if (pd.RecordTime <= pageEnd && pd.RecordTime >= pageBegin)
            {
                string viewValue = "";
                if (pd.Value != Double.MaxValue && pd.Value > 0)
                {
                    viewValue = ((int)pd.Value).ToString();
                    if (Enname == "Temp")
                        viewValue = Math.Round(pd.Y, 1).ToString();
                }
                else
                {
                    viewValue = pd.ValueString;
                }
                if (viewValue != "")
                {
                    ZUtil.DrawText(viewValue, getXPositinByXDate(pd.RecordTime), YLocation, zgcAnas, this.Enname + pd.RecordTime.ToString(), 5f, true);
                    SetPositionText(pd, viewValue);
                }
            }
        }
        #endregion
        #region 通用方法
        /// 
        /// 为生理数据集合排序
        /// 
        public void Sort()
        {
            aPhysioDatas.Sort();
        }
        public int indexOf(PhysioData pd)
        {
            for (int i = 0; i < APhysioParams.Count; i++)
            {
                if (pd.isEquert(PointPairToPhysioData(APhysioParams[i])))
                {
                    return i;
                }
            }
            return -1;
        }
        public PhysioData PointPairToPhysioData(PointPair pp)
        {
            if (pp == null) return null;
            PhysioData pd = new PhysioData();
            pd.ValueString = pp.Y.ToString();
            pd.Value = pp.Y;
            pd.RecordTime = new XDate(pp.X);
            pd.PatientId = PatientId;
            pd.PhysioDataConfigId = Id;
            pd.config = this;
            return pd;
        }
        /// 
        /// 删除麻醉单上的曲线本身,不包含数据删除
        /// 
        /// 
        public override void clearAddObj(ZedGraphControl zgc)
        {
            if (zgcAnas == null || zgcAnas != zgc) zgcAnas = zgc;
            if (ShowText == true)
            {
                foreach (PointPair pp in APhysioParams)
                {
                    PhysioData pd = PointPairToPhysioData(pp);
                    if (pd != null)
                    {
                        delAddObj(pd);
                        SetPositionText(pd, "-1");
                    }
                }
            }
            if (APhysioParams == null || curve == null) return;
            APhysioParams.Clear();
            curve.Points = APhysioParams;
        }
        /// 
        /// 清除各种对象数据
        /// 
        /// 
        public void ClearTagstr(ZedGraphControl zgc)
        {
            if (zgcAnas == null || zgcAnas != zgc) zgcAnas = zgc;
            delAddObj("PP" + Enname);
            delAddObj("PP" + Enname + "unit");
            delAddObj("PP" + Enname + Id);
            delAddObj("PPP" + Enname);
            delAddObj("PPP" + Enname + "unit");
        }
        public void delAddObj(PhysioData newPd)
        {
            delAddObj(this.Enname + newPd.RecordTime.ToString());
        }
        /// 
        /// 控制画点的范围
        /// 
        /// 物理点
        /// 是否采集
        /// 
        private PhysioData reCnterValue(PhysioData pd, bool isShouDong = true)
        {
            if (pd != null)
            {
                //因为物理数据的值小于下标值或大于上标值中,取上下中间的值
                if (pd.Value < lowLimit)
                {
                    pd.Value = lowLimit;
                }
                if (pd.Value > highLimit && pd.Value < double.MaxValue)
                {
                    pd.Value = highLimit;
                }
                if (APhysioParams.Count > 0 && isShouDong)
                {
                    Sort();
                    pd = reMPhysioData(pd);
                }
            }
            return pd;
        }
        /// 
        /// 返回小于传入点里小于且最接近的点
        /// 
        /// 传入点
        /// 
        private PhysioData reMPhysioData(PhysioData pd)
        {
            PhysioData maxPhysioData = null;
            for (int i = APhysioParams.Count - 1; i > -1; i--)
            {
                maxPhysioData = PointPairToPhysioData(APhysioParams[i]);
                int inTime = DateTime.Compare(pd.RecordTime, maxPhysioData.RecordTime);
                //且被大于的值的点不空隐藏
                if (inTime > 0 && maxPhysioData.Value != Double.MaxValue)
                {
                    pd.RecordTime = maxPhysioData.RecordTime.AddMinutes(this.X_MINOR_GRID_STEP);
                    return pd;
                }
            }
            return pd;
        }
        /// 
        /// 返回当前曲线上最大且不为空的点
        /// 
        /// 
        private PhysioData ReMaxAndGoodPhysioData()
        {
            PhysioData rePd = null;
            for (int i = APhysioParams.Count - 1; i > -1; i--)
            {
                rePd = PointPairToPhysioData(APhysioParams[i]);
                //且被大于的值的点不空隐藏
                if (rePd.Value != Double.MaxValue)
                {
                    return rePd;
                }
            }
            return rePd;
        }
        #endregion
        #region 动态体征方法 
        public static int UpdatePhysioDataConfig(PhysioDataConfig physioDataConfig)
        {
            string sql = "Update PhysioDataConfig set HighLimit=@HighLimit, LowLimit=@LowLimit,ShowImg=@ShowImg, ShowText=@ShowText, WarningHighLimit=@WarningHighLimit, WarningLowLimit=@WarningLowLimit, IsSplit=@IsSplit, IsDefalultShow=@IsDefalultShow, Unit=@Unit, PhysioOrder=@PhysioOrder, YAisx=@YAisx where Id=@Id";
            SqlParameter[] para = new SqlParameter[]
                                     {
                                        new SqlParameter("@Id",physioDataConfig.Id), new SqlParameter("@HighLimit",physioDataConfig.HighLimit), new SqlParameter("@LowLimit",physioDataConfig.LowLimit),  new SqlParameter("@ShowImg",physioDataConfig.ShowImg), new SqlParameter("@ShowText",physioDataConfig.ShowText), new SqlParameter("@WarningHighLimit",physioDataConfig.WarningHighLimit), new SqlParameter("@WarningLowLimit",physioDataConfig.WarningLowLimit), new SqlParameter("@IsSplit",physioDataConfig.IsSplit), new SqlParameter("@IsDefalultShow",physioDataConfig.IsDefalultShow), new SqlParameter("@Unit",physioDataConfig.Unit), new SqlParameter("@PhysioOrder",physioDataConfig.PhysioOrder), new SqlParameter("@YAisx",physioDataConfig.YAisx)
                                  };
            return DBHelper.ExecNonQuery(sql, para);
        }
        private static IList GetListBySql(string sql, params SqlParameter[] para)
        {
            IList list = new List();
            using (SqlDataReader reader = DBHelper.GetReader(sql, para))
            {
                while (reader.Read())
                {
                    PhysioDataConfig temp = new PhysioDataConfig();
                    temp.Id = DBHelper.GetInt(reader["Id"]);
                    temp.Name = DBHelper.GetString(reader["Name"]);
                    temp.Enname = DBHelper.GetString(reader["Enname"]);
                    temp.Color = DBHelper.GetString(reader["Color"]);
                    temp.ImgPath = DBHelper.GetString(reader["imgPath"]);
                    temp.IsValid = DBHelper.GetInt(reader["IsValid"]) == 1 ? true : false;
                    temp.OperatorNo = DBHelper.GetString(reader["OperatorNo"]);
                    temp.OperatorName = DBHelper.GetString(reader["OperatorName"]);
                    temp.OperateDate = DBHelper.GetDateTime(reader["OperateDate"]);
                    temp.ConfigType = DBHelper.GetString(reader["ConfigType"]);
                    temp.ShowImg = DBHelper.GetInt(reader["ShowImg"]) == 1 ? true : false;
                    temp.ShowText = DBHelper.GetInt(reader["ShowText"]) == 1 ? true : false;
                    temp.HighLimit = DBHelper.GetInt(reader["HighLimit"]);
                    temp.LowLimit = DBHelper.GetInt(reader["LowLimit"]);
                    temp.WarningHighLimit = DBHelper.GetInt(reader["WarningHighLimit"]);
                    temp.WarningLowLimit = DBHelper.GetInt(reader["WarningLowLimit"]);
                    temp.IsSplit = DBHelper.GetInt(reader["IsSplit"]) == 1 ? true : false;
                    temp.IsDefalultShow = DBHelper.GetInt(reader["IsDefalultShow"]) == 1 ? true : false;
                    temp.Unit = DBHelper.GetString(reader["Unit"]);
                    temp.PhysioOrder = DBHelper.GetInt(reader["PhysioOrder"]);
                    temp.YAisx = DBHelper.GetInt(reader["YAisx"]);
                    list.Add(temp);
                }
                reader.Close();
                return list;
            }
        }
        public static PhysioData newPhysioData(PhysioDataConfig dataConfig, int Id, DateTime RecordTime, string Value)
        {
            PhysioData pdTemp = new PhysioData();
            pdTemp.RecordTime = RecordTime;
            pdTemp.ValueString = Value;
            pdTemp.PhysioDataConfigId = dataConfig.Id;
            pdTemp.PatientId = Id;
            pdTemp.config = dataConfig;
            return pdTemp;
        }
        public static PhysioData newPhysioData(PhysioDataConfig dataConfig, int Id, DateTime RecordTime, double Value)
        {
            PhysioData pdTemp = new PhysioData();
            pdTemp.RecordTime = RecordTime;
            pdTemp.ValueString = Value.ToString();
            pdTemp.PhysioDataConfigId = dataConfig.Id;
            pdTemp.PatientId = Id;
            pdTemp.config = dataConfig;
            return pdTemp;
        }
        public void EditAddItem(PhysioData pd)
        {
            PhysioDataService.AddPhysioData(pd);
            DrawTextPhysioData(pd);
        }
        public void EditModifyItem(PhysioData oldPd, PhysioData newPd)
        {
            //如果是负数则不执行操作
            if (oldPd.PhysioDataConfigId != newPd.PhysioDataConfigId)
                return;
            PhysioDataService.UpdatePhysioData(oldPd, newPd, PublicMethod.OperatorName);
            delAddObj(oldPd);
            DrawTextPhysioData(newPd);
        }
        public void EditDelItem(PhysioData pd)
        {
            delAddObj(pd);
            SetPositionText(pd, "-1");
            PhysioDataService.DelPhysioByValueData(pd);
        }
        public void SetPositionText(PhysioData pdTemp, string viewValue)
        {
            if (phListPack != null)
            {
                Panel pan3 = phListPack.CControl as Panel;
                if (pan3 != null)
                {
                    Control[] cs = pan3.Controls.Find(pdTemp.PhysioDataConfigId + "" + pdTemp.RecordTime.ToString("HHmm"), true);
                    if (cs != null && cs.Length > 0)
                    {
                        Control c = cs[0];
                        if (c != null)
                        {
                            if (viewValue == "-1")
                            {
                                pdTemp.Value = -1;
                                pdTemp.ValueString = "";
                                c.Tag = pdTemp;
                                c.Text = "";
                            }
                            else
                            {
                                c.Tag = pdTemp;
                                c.Text = viewValue.ToString();
                            }
                        }
                    }
                }
            }
        }
        public void AddText(PhysioData pd)
        {
            if (pd.ValueString == null || pd.ValueString == "") return;
            DrawTextPhysioData(pd);
        }
        #endregion
    }
}