/// <summary>
        /// 初始化/刷新门诊患者列表树
        /// </summary>
        public void LoadOutpatient()
        {
            Neusoft.FrameWork.WinForms.Classes.Function.ShowWaitForm("正在加载患者信息...");
            Application.DoEvents();
            // 业务层

            Neusoft.HISFC.BizProcess.Integrate.Terminal.Confirm confirmIntegrate = new Neusoft.HISFC.BizProcess.Integrate.Terminal.Confirm();
            // 患者树结点
            TreeNode treeNode = new TreeNode();

            treeNode.ImageIndex         = 2;
            treeNode.SelectedImageIndex = 2;
            // 结果
            Neusoft.HISFC.BizProcess.Integrate.Terminal.Result result = new Result();

            this.isLoad = true;

            // 获取树结点

            result = confirmIntegrate.GetOutpatientTreeNode(ref treeNode);
            if (result == Neusoft.HISFC.BizProcess.Integrate.Terminal.Result.Failure)
            {
                MessageBox.Show(confirmIntegrate.Err);
                this.isLoad = false;
                return;
            }
            this.treeView1.Nodes.Clear();
            // 添加结点数组到树
            this.treeView1.Nodes.Add(treeNode);
            // 展开所有树结点
            this.treeView1.ExpandAll();

            this.isLoad = false;
            Neusoft.FrameWork.WinForms.Classes.Function.HideWaitForm();
        }
        /// <summary>
        /// 初始化/刷新住院患者列表数
        /// </summary>
        void LoadInpatient()
        {
            // 业务层

            Neusoft.HISFC.BizProcess.Integrate.Terminal.Confirm confirmIntegrate = new Neusoft.HISFC.BizProcess.Integrate.Terminal.Confirm();
            // 患者树结点
            TreeNode treeNode = new TreeNode();

            treeNode.ImageIndex         = 0;
            treeNode.SelectedImageIndex = 1;
            // 结果
            Neusoft.HISFC.BizProcess.Integrate.Terminal.Result result = new Result();

            this.isLoad = true;

            // 获取树结点

            result = confirmIntegrate.GetOutpatientTreeNode(ref treeNode);
            if (result == Neusoft.HISFC.BizProcess.Integrate.Terminal.Result.Failure)
            {
                MessageBox.Show(confirmIntegrate.Err);
                this.isLoad = false;
                return;
            }
            // 添加结点数组到树
            this.treeView1.Nodes.Add(treeNode);
            // 展开所有树结点
            this.treeView1.ExpandAll();

            this.isLoad = false;
        }
        /// <summary>
        /// 获取挂号科室和合同单位


        /// </summary>
        /// <param name="argRegister">返回的挂号实体</param>
        public int SetPactAndRegDept(ref Neusoft.HISFC.Models.Registration.Register argRegister)
        {
            Neusoft.HISFC.BizProcess.Integrate.Terminal.Result result = new Result();
            // 业务
            Neusoft.HISFC.BizProcess.Integrate.Terminal.Confirm confirmIntegrate = new Neusoft.HISFC.BizProcess.Integrate.Terminal.Confirm();
            // 合同单位实体
            Neusoft.HISFC.Models.Base.PactInfo pact = new PactInfo();
            // 科室实体
            Neusoft.HISFC.Models.Base.Department dept = new Neusoft.HISFC.Models.Base.Department();

            // 获取合同单位信息
            result = confirmIntegrate.GetPact(ref pact, argRegister.Pact.ID);
            if (result != Result.Success)
            {
                Neusoft.FrameWork.Management.Language.Msg("获取合同单位失败。" + confirmIntegrate.Err);

                return(-1);
            }

            argRegister.Pact = pact;
            // 获取科室信息
            result = confirmIntegrate.GetDept(ref dept, argRegister.DoctorInfo.Templet.Dept.ID);
            if (result != Result.Success)
            {
                Neusoft.FrameWork.Management.Language.Msg("获取科室信息失败。" + confirmIntegrate.Err);

                return(-1);
            }
            argRegister.DoctorInfo.Templet.Dept = dept;

            return(1);
        }
        /// <summary>
        /// 显示业务明细
        /// [参数: ArrayList alDetail - 业务明细数组]
        /// </summary>
        /// <param name="terminalConfirmDetailList">业务明细数组</param>
        private void DisplayDetail(ArrayList terminalConfirmDetailList)
        {
            // 员工实体
            Neusoft.HISFC.Models.Base.Employee employee = new Employee();
            // 科室实体
            Neusoft.HISFC.Models.Base.Department department = new Neusoft.HISFC.Models.Base.Department();
            // 业务层


            Neusoft.HISFC.BizProcess.Integrate.Terminal.Confirm confirmIntegrate = new Neusoft.HISFC.BizProcess.Integrate.Terminal.Confirm();

            // 清空
            this.neuSpreadItemDetail_SheetItemDetail.RowCount = 0;
            foreach (Neusoft.HISFC.Models.Terminal.TerminalConfirmDetail tempConfirmDetail in terminalConfirmDetailList)
            {
                // 增加一行新记录
                this.neuSpreadItemDetail_SheetItemDetail.AddRows(this.neuSpreadItemDetail_SheetItemDetail.RowCount, 1);
                // 取增加的行号
                this.row = this.neuSpreadItemDetail_SheetItemDetail.RowCount - 1;
                // 状态


                if (tempConfirmDetail.Status.ID.Equals("0"))
                {
                    this.neuSpreadItemDetail_SheetItemDetail.Cells[this.row, (int)DetailField.Status].Text = "正常";
                }
                else
                {
                    this.neuSpreadItemDetail_SheetItemDetail.Cells[this.row, (int)DetailField.Status].Text = "取消";
                }
                // 执行科室
                confirmIntegrate.GetDept(ref department, tempConfirmDetail.Apply.Item.ConfirmOper.Dept.ID);
                this.neuSpreadItemDetail_SheetItemDetail.Cells[this.row, (int)DetailField.ConfirmDepartment].Text = department.Name;
                // 执行时间
                this.neuSpreadItemDetail_SheetItemDetail.Cells[this.row, (int)DetailField.ConfirmTime].Text = tempConfirmDetail.Apply.ConfirmOperEnvironment.OperTime.ToString();
                // 确认人


                confirmIntegrate.GetEmployee(ref employee, tempConfirmDetail.Apply.ConfirmOperEnvironment.ID);
                this.neuSpreadItemDetail_SheetItemDetail.Cells[this.row, (int)DetailField.ConfirmEmployee].Text = employee.Name;
                this.neuSpreadItemDetail_SheetItemDetail.Columns[(int)DetailField.FreeQty].Visible = false; // 隐藏这列,如果发生多次确认后退费,次数不准,之所以保留是为了便与根据旧发票号查询当时的情况


                // 确认数量
                this.neuSpreadItemDetail_SheetItemDetail.Cells[this.row, (int)DetailField.ConfirmQty].Text = tempConfirmDetail.Apply.Item.ConfirmedQty.ToString();
                // 剩余数量
                this.neuSpreadItemDetail_SheetItemDetail.Cells[this.row, (int)DetailField.FreeQty].Text = tempConfirmDetail.FreeCount.ToString();

                // 保存Tag为实体


                this.neuSpreadItemDetail_SheetItemDetail.Rows[this.row].Tag = tempConfirmDetail;
            }
        }
        /// <summary>
        /// 执行查询
        /// </summary>
        protected void TerminalQuery()
        {
            // 申请单数组


            ArrayList alApply = new ArrayList();

            // 业务层


            Neusoft.HISFC.BizProcess.Integrate.Terminal.Confirm confirmIntegrate = new Neusoft.HISFC.BizProcess.Integrate.Terminal.Confirm();
            // 结果
            Neusoft.HISFC.BizProcess.Integrate.Terminal.Result result = new Result();
            // 如果病历号为空,那么返回
            if (this.neuTextBoxCardNO.Text.Equals("") || this.neuTextBoxCardNO.Text == null)
            {
                return;
            }
            // 填充病历号


            this.neuTextBoxCardNO.Text = this.neuTextBoxCardNO.Text.PadLeft(10, '0');
            //
            // 根据病历号获取申请单明细
            //
            Neusoft.FrameWork.WinForms.Classes.Function.ShowWaitForm("正在获取项目信息...");

            Application.DoEvents();
            // 获取申请单明细


            result = confirmIntegrate.QueryApplyListByCardNO(this.neuTextBoxCardNO.Text, ref alApply);
            if (Neusoft.HISFC.BizProcess.Integrate.Terminal.Result.Failure == result)
            {
                Neusoft.FrameWork.WinForms.Classes.Function.HideWaitForm();
                MessageBox.Show("获取记录失败!" + "\n" + confirmIntegrate.Err);
                return;
            }
            //
            // 显示申请单明细


            //
            if (alApply.Count == 0)
            {
                Neusoft.FrameWork.WinForms.Classes.Function.HideWaitForm();
                MessageBox.Show("该患者不存在终端确认信息或病例号录入错误!" + "\n" + confirmIntegrate.Err);
                return;
            }
            this.DisplayApply(alApply);
            // 隐藏等待信息
            Neusoft.FrameWork.WinForms.Classes.Function.HideWaitForm();
        }
        /// <summary>
        /// 收费项目双击选择事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void neuSpreadItem_CellDoubleClick(object sender, FarPoint.Win.Spread.CellClickEventArgs e)
        {
            //
            // 如果没有记录,那么返回
            //
            if (this.neuSpreadItem_SheetItem.RowCount == 0)
            {
                return;
            }
            // 业务层


            Neusoft.HISFC.BizProcess.Integrate.Terminal.Confirm confirmIntegrate = new Neusoft.HISFC.BizProcess.Integrate.Terminal.Confirm();
            // 结果
            Neusoft.HISFC.BizProcess.Integrate.Terminal.Result result = new Result();

            Neusoft.FrameWork.WinForms.Classes.Function.ShowWaitForm("正在获取项目信息...");
            //
            // 获取当前选择的记录


            //
            this.terminalApply = new TerminalApply();
            this.terminalApply = (Neusoft.HISFC.Models.Terminal.TerminalApply) this.neuSpreadItem_SheetItem.Rows[this.neuSpreadItem_SheetItem.ActiveRowIndex].Tag;
            //
            // 根据申请单号获取业务明细
            //
            confirmDetailList = new ArrayList();
            result            = confirmIntegrate.QueryDetailsByApply(terminalApply, ref confirmDetailList);
            if (result == Neusoft.HISFC.BizProcess.Integrate.Terminal.Result.Failure)
            {
                Neusoft.FrameWork.WinForms.Classes.Function.HideWaitForm();
                MessageBox.Show("获取业务明细失败!" + "\n" + confirmIntegrate.Err);
                return;
            }
            //
            // 设置业务明细
            //
            this.DisplayDetail(confirmDetailList);
            //
            // 显示项目名称
            //
            this.neuLabelConfirmTitle.Text = "开立的收费项目对应的执行明细 —— " + terminalApply.Item.Name;

            Neusoft.FrameWork.WinForms.Classes.Function.HideWaitForm();
        }
        /// <summary>
        /// 根据申请单流水号获取业务明细,初始化窗口


        /// </summary>
        /// <returns>1-成功;-1-失败</returns>
        private int InitByApplySequence()
        {
            // 结果
            Neusoft.HISFC.BizProcess.Integrate.Terminal.Result result = new Result();
            // 业务层


            Neusoft.HISFC.BizProcess.Integrate.Terminal.Confirm confirmIntegrate = new Neusoft.HISFC.BizProcess.Integrate.Terminal.Confirm();
            // 业务明细数组
            ArrayList detailList = new ArrayList();
            // 申请单数组


            ArrayList applyList = new ArrayList();

            //
            // 根据申请单获取业务明细


            //
            result = confirmIntegrate.QueryDetailsByApply(this.terminalApply, ref detailList);
            if (result == Neusoft.HISFC.BizProcess.Integrate.Terminal.Result.Failure)
            {
                MessageBox.Show(confirmIntegrate.Err);
                return(-1);
            }
            //
            // 设置业务明细
            //
            this.DisplayDetail(detailList);
            //
            // 设置申请单


            //
            applyList.Add(this.terminalApply);
            this.DisplayApply(applyList);

            return(1);
        }
        /// <summary>
        /// 显示申请单


        /// [参数: ArrayList alApply - 申请单数组]
        /// </summary>
        /// <param name="alApply">申请单数组</param>
        private void DisplayApply(ArrayList alApply)
        {
            // 业务层


            Neusoft.HISFC.BizProcess.Integrate.Terminal.Confirm confirmIntegrate = new Neusoft.HISFC.BizProcess.Integrate.Terminal.Confirm();
            // 员工实体
            Neusoft.HISFC.Models.Base.Employee employee = new Employee();
            // 科室实体
            Neusoft.HISFC.Models.Base.Department department = new Neusoft.HISFC.Models.Base.Department();

            this.neuSpreadItem_SheetItem.RowCount = 0;

            foreach (Neusoft.HISFC.Models.Terminal.TerminalApply tempTerminalApply in alApply)
            {
                // 增加一行


                this.neuSpreadItem_SheetItem.AddRows(this.neuSpreadItem_SheetItem.RowCount, 1);
                // 当前行号
                this.row = this.neuSpreadItem_SheetItem.RowCount - 1;
                // 状态


                if (tempTerminalApply.ItemStatus.Equals("1"))
                {
                    this.neuSpreadItem_SheetItem.Cells[this.row, (int)ApplyField.Status].Text = "未执行";
                }
                else
                {
                    if (tempTerminalApply.AlreadyConfirmCount == 0)
                    {
                        this.neuSpreadItem_SheetItem.Cells[this.row, (int)ApplyField.Status].Text = "未执行";
                    }
                    else
                    {
                        this.neuSpreadItem_SheetItem.Cells[this.row, (int)ApplyField.Status].Text = "已执行";
                    }
                }
                // 项目名称
                this.neuSpreadItem_SheetItem.Cells[this.row, (int)ApplyField.ItemName].Text = tempTerminalApply.Item.Item.Name;
                // 开立数量


                this.neuSpreadItem_SheetItem.Cells[this.row, (int)ApplyField.Qty].Text = tempTerminalApply.Item.Item.Qty.ToString();
                // 剩余数量
                this.neuSpreadItem_SheetItem.Cells[this.row, (int)ApplyField.FreeQty].Text = (tempTerminalApply.Item.Item.Qty - tempTerminalApply.AlreadyConfirmCount).ToString();
                // 开立医生


                confirmIntegrate.GetEmployee(ref employee, tempTerminalApply.Item.Order.Doctor.ID);
                this.neuSpreadItem_SheetItem.Cells[this.row, (int)ApplyField.Doctor].Text = employee.Name;
                // 开立科室


                confirmIntegrate.GetDept(ref department, tempTerminalApply.Item.ExecOper.Dept.ID);
                this.neuSpreadItem_SheetItem.Cells[this.row, (int)ApplyField.Department].Text = department.Name;
                // 保存Tag为实体


                this.neuSpreadItem_SheetItem.Rows[this.row].Tag = tempTerminalApply;
                // 患者姓名


                this.neuTextBoxName.Text = tempTerminalApply.Patient.Name;
            }
            if (alApply.Count > 0)
            {
                Neusoft.HISFC.Models.Terminal.TerminalApply tempTerminalApply = (Neusoft.HISFC.Models.Terminal.TerminalApply)alApply[0];
                if (tempTerminalApply.PatientType == "1" || tempTerminalApply.PatientType == "4" || tempTerminalApply.PatientType == "5")
                {
                    //门诊 或体检患者


                    Neusoft.HISFC.Models.Registration.Register obj = new Neusoft.HISFC.Models.Registration.Register();
                    obj = confirmMgr.GetByClinic(tempTerminalApply.Patient.PID.ID);
                    if (obj == null)
                    {
                        MessageBox.Show("获取患者基本信息失败");
                        return;
                    }
                    tempTerminalApply.Patient.Sex.ID = obj.Sex.ID;
                }
                else if (tempTerminalApply.PatientType == "2")
                {//住院
                }
                else if (tempTerminalApply.PatientType == "3")
                {
                    //急诊
                }
                if (tempTerminalApply.Patient.Sex.ID == null)
                {
                    //this.neuTextBoxSex.Text = "未知";
                }
                else if (tempTerminalApply.Patient.Sex.ID.Equals("M"))
                {
                    this.neuTextBoxSex.Text = "男";
                }
                else if (tempTerminalApply.Patient.Sex.ID.Equals("F"))
                {
                    this.neuTextBoxSex.Text = "女";
                }
                else
                {
                    this.neuTextBoxSex.Text = "未知";
                }
            }
        }
        /// <summary>
        /// 保存
        /// </summary>
        public void Save()
        {
            #region 变量和trans
            // 操作结果
            Neusoft.HISFC.BizProcess.Integrate.Terminal.Result result = new Result();
            // 业务层

            Neusoft.HISFC.BizProcess.Integrate.Terminal.Confirm confirmIntegrate = new Neusoft.HISFC.BizProcess.Integrate.Terminal.Confirm();
            // 申请单实体

            Neusoft.HISFC.Models.Terminal.TerminalApply apply = new TerminalApply();
            //是否有预约

            bool hasApply = false;

            //{04B57368-8DE0-4e46-8F27-1374F37C36AE}无需保存
            if (this.neuSpread2_Sheet1.RowCount <= 0)
            {
                return;
            }

            Neusoft.FrameWork.Management.PublicTrans.BeginTransaction();
            this.confirmIntegrate.SetTrans(Neusoft.FrameWork.Management.PublicTrans.Trans);
            #endregion

            //逐条保存sheet2中的数据
            foreach (FarPoint.Win.Spread.Row r in this.neuSpread2_Sheet1.Rows)
            {
                decimal cancelQty       = 0m;
                decimal oldConfirmedQty = 0m;
                //将表格数据赋值给apply实体
                apply = this.neuSpread2_Sheet1.Rows[r.Index].Tag as TerminalApply;
                //{8351D2B0-8C72-43e0-ADE6-4CEFF6ED3C2C}
                if (apply == null)
                {
                    return;
                }
                apply.Item.User03 = apply.Item.ConfirmedQty.ToString();
                oldConfirmedQty   = Neusoft.FrameWork.Function.NConvert.ToDecimal(apply.Item.User03);
                cancelQty         = Neusoft.FrameWork.Function.NConvert.ToDecimal(this.neuSpread2_Sheet1.Cells[r.Index, 2].Value.ToString());//取消数量

                if (cancelQty > oldConfirmedQty)
                {
                    Neusoft.FrameWork.Management.Language.Msg("取消数量不能大于已确认数量");
                    return;
                }
                //剩余已确认数量

                apply.Item.ConfirmedQty = apply.Item.ConfirmedQty - cancelQty;//已确认数量变更

                ////如果有申请预约记录则不允许取消,需要先取消预约申请
                //hasApply = confirmIntegrate.GetTerminalApply(apply.Order.ID);
                //if (hasApply == true)
                //{
                //    MessageBox.Show("存在“" + apply.Item.Name + "”的预约信息,请先取消预约。");
                //    return;
                //}
                //更新met_tec_terminalapply中的确认数量
                result = confirmIntegrate.UpdateApplyConfirmQty(apply.User02, cancelQty);//confirm_num=confirm_num-cancelQty
                if (result != Result.Success)
                {
                    Neusoft.FrameWork.Management.PublicTrans.RollBack();
                    MessageBox.Show("更新终端确认申请表中的确认数量失败。" + confirmIntegrate.Err);

                    return;
                }
                //更新fin_opb_feedetail中对应医嘱的可退数量
                result = confirmIntegrate.UpdateNobackNum(apply.Order.ID, apply.Item.ID, cancelQty);//noback_num=noback_num+cancelQty;confirm_num=confirm_num-cancelQty
                if (result != Result.Success)
                {
                    Neusoft.FrameWork.Management.PublicTrans.RollBack();
                    MessageBox.Show("更新可退数量失败。" + confirmIntegrate.Err);

                    return;
                }
                //直接更新met_tec_ta_detail中的已确认数量,将之前的已确认数量存入extend_field3
                result = confirmIntegrate.UpdateConfirmedQty(apply.ID, apply.Item.ConfirmedQty, oldConfirmedQty.ToString());
                if (result != Result.Success)
                {
                    Neusoft.FrameWork.Management.PublicTrans.RollBack();
                    MessageBox.Show("更新已确认数量失败。" + confirmIntegrate.Err);

                    return;
                }

                //更新作废标志
                //部分确认暂不考虑-即不允许部分确认
                //直接更新met_tec_ta_detail中的已确认数量,将之前的已确认数量存入extend_field3
                result = confirmIntegrate.UpdateConfirmedFlag(apply.ID, Neusoft.FrameWork.Management.Connection.Operator.ID, "");
                if (result != Result.Success)
                {
                    Neusoft.FrameWork.Management.PublicTrans.RollBack();
                    MessageBox.Show("更新已确认标志。" + confirmIntegrate.Err);

                    return;
                }
            }
            Neusoft.FrameWork.Management.PublicTrans.Commit();
            MessageBox.Show("终端确认取消成功。");
        }