/// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="argPriInvoice">前一个发票号</param>
 /// <param name="argCurrInvoice">当前发票号</param>
 /// <param name="argOwnCost">实收金额</param>
 /// <param name="argLeftCost">记帐金额</param>
 /// <param name="argTotalCost">总金额</param>
 /// <param name="argAccount">记帐单数</param>
 /// <param name="argDayBalance">返回的实体</param>
 public void SetEntity(string argPriInvoice, string argCurrInvoice, string argItem,
                       decimal argOwnCost, decimal argLeftCost, decimal argTotalCost,
                       int argAccount, ref Class.ClinicDayBalance argDayBalance)
 {
     // 发票号
     if (argPriInvoice != argCurrInvoice)
     {
         argDayBalance.InvoiceNo = argPriInvoice + "~" + argCurrInvoice;
     }
     else
     {
         argDayBalance.InvoiceNo = argCurrInvoice;
     }
     // 发票张数
     argDayBalance.Memo = (long.Parse(argCurrInvoice) - long.Parse(argPriInvoice) + 1).ToString();
     // 实收金额
     argDayBalance.Cost.OwnCost = argOwnCost;
     // 记帐金额
     argDayBalance.Cost.LeftCost = argLeftCost;
     // 总金额
     argDayBalance.Cost.TotCost = argTotalCost;
     // 日结项目
     if (argItem == "1")
     {
         argDayBalance.BalanceItem = Neusoft.HISFC.Models.Base.CancelTypes.Valid;
     }
     else if (argItem == "0")
     {
         argDayBalance.BalanceItem = Neusoft.HISFC.Models.Base.CancelTypes.Canceled;
     }
     else if (argItem == "2")
     {
         argDayBalance.BalanceItem = Neusoft.HISFC.Models.Base.CancelTypes.Reprint;
     }
     else
     {
         argDayBalance.BalanceItem = Neusoft.HISFC.Models.Base.CancelTypes.LogOut;
     }
     // 记帐单数目
     argDayBalance.AccountNumber = argAccount;
     // 起始时间
     if (DateTime.MinValue == DateTime.Parse(this.lastDate))
     {
         // 如果没有作过日结,那么将上次日结时间设置成去年今天的零点
         DateTime dtToday = new DateTime();
         dtToday                 = this.clinicDayBalance.GetDateTimeFromSysDateTime();
         this.lastDate           = (new System.DateTime(dtToday.Year - 1, dtToday.Month, dtToday.Day, 0, 1, 1)).ToString();
         argDayBalance.BeginDate = DateTime.Parse(this.lastDate);
     }
     else
     {
         argDayBalance.BeginDate = NConvert.ToDateTime(this.lastDate);
     }
     // 截止时间
     argDayBalance.EndDate = NConvert.ToDateTime(this.dayBalanceDate);
     // 操作员编码
     argDayBalance.BalanceOperator = this.currentOperator;
     // 财务审核
     argDayBalance.CheckFlag = "1";
     // 审核人
     argDayBalance.CheckOperator = new NeuObject();
     // 审核时间
     argDayBalance.CheckDate = DateTime.MinValue;
 }
        /// <summary>
        /// 计算日结数据
        /// </summary>
        /// <param name="dsBalanceData">获取的日结数据</param>
        /// <param name="argArrayList">返回的实体数组</param>
        public void Calculate(DataSet dsBalanceData, ref ArrayList argArrayList)
        {
            #region 变量定义

            // 实体数组
            ArrayList alDayBalance = new ArrayList();
            // 前一个发票号
            string priviousInvoice = "";
            // 第一个发票号
            string firstInvoice = "";
            // 是否出现与上一张发票号不同的现象
            bool boolDifferent = false;
            // 发生前后不同的次数
            long intDifferent = 0;
            // 实收金额
            decimal ownCost = 0;
            // 记帐金额
            decimal accountCost = 0;
            // 总金额
            decimal totalCost = 0;
            // 记帐单数
            int accountCount = 0;
            // 前一个日结项目
            string priviousBalanceItem = "";
            // 是否出现与前一张发票不同的日结项目
            bool boolItem = false;
            #endregion

            #region 循环计算
            // 保存第一个发票号
            firstInvoice = dsBalanceData.Tables[0].Rows[0][0].ToString();
            // 初始化前一个发票号
            priviousInvoice = dsBalanceData.Tables[0].Rows[0][0].ToString();
            // 保存第一个日结项目
            priviousBalanceItem = dsBalanceData.Tables[0].Rows[0][4].ToString();

            // 循环计算
            foreach (DataRow drData in dsBalanceData.Tables[0].Rows)
            {
                // 日结实体类
                Class.ClinicDayBalance dayBalance = new Class.ClinicDayBalance();
                // 当前发票号
                string currentInvoice = "";
                // 实收金额
                decimal decOwnCost = 0;
                // 记帐金额
                decimal decAccountCost = 0;
                // 总金额
                decimal decTotalCost = 0;
                // 记帐单数
                //int intAccountCount = 0;
                // 日结项目
                string stringItem = "";

                // 获取当前发票号
                currentInvoice = drData[0].ToString();

                // 获取当前日结项目
                stringItem = drData[4].ToString();

                // 获取各种金额
                decOwnCost     = Neusoft.FrameWork.Function.NConvert.ToDecimal(drData[1].ToString());
                decAccountCost = Neusoft.FrameWork.Function.NConvert.ToDecimal(drData[2].ToString());
                decTotalCost   = Neusoft.FrameWork.Function.NConvert.ToDecimal(drData[5].ToString());

                // 如果前一次循环发生发票号不连续,那么重新获取第一张发票号
                if (boolDifferent)
                {
                    firstInvoice  = priviousInvoice;
                    boolDifferent = false;
                }

                // 如果前一次循环发生项目不同,那么重新获取前一次项目
                if (boolItem)
                {
                    firstInvoice = priviousInvoice;
                    boolItem     = false;
                }

                //
                // 如果当前日结项目与前一个日结项目不同,需要作为一个实体,并且设置第一张发票号为当前发票号
                //
                if (stringItem != priviousBalanceItem)
                {
                    //
                    // 设置实体
                    //
                    this.SetEntity(firstInvoice, priviousInvoice, priviousBalanceItem, ownCost, accountCost, totalCost, accountCount, ref dayBalance);

                    // 存储到实体数组
                    alDayBalance.Add(dayBalance);

                    // 设置辅助变量
                    priviousInvoice = currentInvoice;
                    firstInvoice    = currentInvoice;
                    boolItem        = true;
                    intDifferent++;
                    ownCost      = 0;
                    accountCost  = 0;
                    totalCost    = 0;
                    accountCount = 0;
                }
                else if ((currentInvoice != priviousInvoice) && (long.Parse(priviousInvoice) != (long.Parse(currentInvoice) - 1)))
                {
                    //
                    // 如果发生发票号不连续,则计算发票数据,同时计数
                    //
                    // 设置实体
                    //
                    this.SetEntity(firstInvoice, priviousInvoice, priviousBalanceItem, ownCost, accountCost, totalCost, accountCount, ref dayBalance);

                    // 存储到实体数组
                    alDayBalance.Add(dayBalance);

                    // 设置辅助变量
                    boolDifferent = true;
                    firstInvoice  = currentInvoice;
                    intDifferent++;
                    ownCost      = 0;
                    accountCost  = 0;
                    totalCost    = 0;
                    accountCount = 0;
                }
                //else
                {
                    // 汇总各种金额
                    ownCost     += decOwnCost;
                    accountCost += decAccountCost;
                    totalCost   += decTotalCost;

                    // 合计记帐单数
                    if (drData[5].ToString() == "2")
                    {
                        accountCount++;
                    }
                }

                // 存储当前发票号作为下次循环的上一次发票号
                priviousInvoice = drData[0].ToString();

                // 存储当前项目类别作为下次循环的上一次日结项目
                priviousBalanceItem = drData[4].ToString();
            }

            // 如果计数器为0,说明一个不同项目、断号都没有
            if (intDifferent == 0)
            {
                // 日结实体类
                Class.ClinicDayBalance dayBalance = new Class.ClinicDayBalance();
                // 当前发票号
                string currentInvoice = "";
                firstInvoice = dsBalanceData.Tables[0].Rows[0][0].ToString();

                ownCost      = 0;
                totalCost    = 0;
                accountCost  = 0;
                accountCount = 0;
                foreach (DataRow drData in dsBalanceData.Tables[0].Rows)
                {
                    // 当前发票号
                    currentInvoice = drData[0].ToString();
                    // 实收金额
                    ownCost += decimal.Parse(drData[1].ToString());
                    // 记帐金额
                    accountCost += decimal.Parse(drData[2].ToString());
                    // 总金额
                    totalCost += decimal.Parse(drData[5].ToString());
                    // 记帐单数量
                    if (drData[5].ToString() == "2")
                    {
                        accountCount++;
                    }
                    // 日结项目
                    priviousBalanceItem = drData[3].ToString();
                }

                // 设置实体
                this.SetEntity(firstInvoice, currentInvoice, priviousBalanceItem, ownCost, accountCost, totalCost, accountCount, ref dayBalance);
                alDayBalance.Add(dayBalance);
            }
            else
            {
                Class.ClinicDayBalance dayBalance = new Class.ClinicDayBalance();
                this.SetEntity(firstInvoice, priviousInvoice, priviousBalanceItem, ownCost, accountCost, totalCost, accountCount, ref dayBalance);
                alDayBalance.Add(dayBalance);
            }
            argArrayList = alDayBalance;
            #endregion
        }