// for one page in report
        private void CalculateSummary(ExchangeListHeader obj)
        {
            foreach (ExchangeSpare spare in obj.ExchangeSpares.Items)
            {
                TotalSparesO += spare.QuantityO;
                TotalAmountO += spare.WarrantySpareAmountO;
                if (obj.Status == (int)ExchangeVoucherStatus.Approved)
                {
                    TotalSparesM += spare.QuantityM;
                    TotalAmountM += spare.WarrantySpareAmountM;
                    TotalFeeM += spare.WarrantyFeeAmountM;
                }
            }

            TotalFeeO += obj.ProposeFee;
            AllTotalM = TotalFeeM + TotalAmountM;
            AllTotalO = TotalFeeO + TotalAmountO;
        }
        public TreeListObjects Select(int maximumRows, int startRowIndex)
        {
            TreeListObjects data = new TreeListObjects();
            int items;
            //IList<Exchangepartheader> listEH = GetExchangeHeaders();
            IList<Exchangepartheader> listEH = GetExchangeHeaders(maximumRows, startRowIndex, out items);

            // dealer info when verify Proposal exchanges
            if (ForVerify)
            {
                if (!string.IsNullOrEmpty(VoucherNo))
                {
                    Exchangevoucherheader exchH = GetExchVoucherHeader(VoucherNo);
                    if (exchH != null)
                    {
                        DealerCode = exchH.Dealercode;
                        DealerName = DealerHelper.GetName(DealerCode);
                    }
                }
                else if ((this.ExchageNoFrom == this.ExchageNoTo) && (listEH.Count > 0))
                {
                    DealerCode = listEH[0].Dealercode;
                    DealerName = DealerHelper.GetName(DealerCode);
                }
            }

            //ItemCount = (listEH == null) ? 0 : listEH.Count;  // paging roi thi thoi
            ItemCount = items;

            PageSize = maximumRows;
            FirstItemIndex = startRowIndex;
            int lastItem = FirstItemIndex + PageSize;
            if (lastItem > ItemCount) lastItem = ItemCount;

            if ((listEH == null) || (listEH.Count == 0)) return null;
            for (int i = 0; i < listEH.Count; i++)
            {
                Exchangepartheader exch = listEH[i];

                #region header section
                ExchangeListHeader header = new ExchangeListHeader();
                header.No = i + 1;
                header.CustomerName = exch.Customer.Fullname;
                header.EngineNumber = exch.Enginenumber;
                header.RepairDate = exch.Exchangeddate;
                header.BuyDate = exch.Purchasedate;
                header.ConfirmedDate = (exch.Status == (int)ExchangeVoucherStatus.Approved) ? exch.Lastprocesseddate : DateTime.MinValue;
                header.ServiceSheetNumber = exch.Serviceheader.Servicesheetnumber;
                header.ExchangeVoucherNumber = exch.Vouchernumber;
                header.Status = exch.Status;
                header.StatusString = ServiceTools.GetNativeVMEPExchangeStatusName(exch.Status);
                header.Km = exch.Kmcount;
                header.Model = exch.Serviceheader.Itemtype;
                header.ProposeFee = (long)exch.Proposefeeamount;
                header.feeO = (long)exch.Proposefeeamount;
                header.feeM = exch.Feeamount;

                #endregion

                #region exchange section
                ArrayList listED = GetExchangeDetails(exch.Id);
                foreach (Exchangepartdetail exchD in listED)
                {
                    Warrantycondition warr;
                    ExchangeSpare exSpare = new ExchangeSpare();

                    warr = WarrantyContent.GetWarrantyCondition(exchD.Partcodeo);
                    if (warr != null) exSpare.LabourO = (long)warr.Labour;
                    warr = WarrantyContent.GetWarrantyCondition(exchD.Partcodem);
                    if (warr != null) exSpare.LabourM = (long)warr.Labour;

                    exSpare.SpareNumberO = exchD.Partcodeo;
                    exSpare.SpareNumberM = exchD.Partcodem;
                    exSpare.UnitPriceO = exchD.Unitpriceo;
                    exSpare.UnitPriceM = exchD.Unitpricem;
                    exSpare.QuantityO = exchD.Partqtyo;
                    exSpare.QuantityM = exchD.Partqtym;
                    exSpare.Comments = exchD.Vmepcomment;
                    exSpare.WarrantyFeeAmountO = exchD.Totalfeeo;
                    exSpare.WarrantyFeeAmountM = exchD.Totalfeem;

                    exSpare.ManPowerM = (exSpare.LabourM == 0) ? 0 : (double)((double)exSpare.WarrantyFeeAmountM / (double)exSpare.LabourM);
                    exSpare.ManPowerO = (exSpare.LabourO == 0) ? 0 : (double)((double)exSpare.WarrantyFeeAmountO / (double)exSpare.LabourO);

                    header.ExchangeSpares.Items.Add(exSpare);
                }
                #endregion

                CalculateSummary(header);

                // add to top list
                //if ((i >= FirstItemIndex) && (i < lastItem))   // paging roi thi thoi
                {
                    data.Items.Add(header);
                }
            }

            if (CalculateAllPageSummary) CalculateTotalSummary();
            return data;
        }