private void CalculateSummary(RepairListHeader obj)
        {
            TotalRepairFee += obj.ServiceRecordSheet.RepairFeeAmount;
            foreach (RepairSpare spare in obj.ServiceRecordSheet.Items)
            {

                TotalSpareAmount += spare.Quantity * spare.UnitPrice;
            }
            foreach (ExchangeSpare spare in obj.ExchangeSpares.Items)
            {
                TotalWarrantyFee += spare.WarrantyFeeAmount;
                TotalWarrantyAmount += spare.Quantity * spare.UnitPrice;
            }
        }
        public TreeListObjects Select(int maximumRows, int startRowIndex)
        {
            // int page = startRowIndex / maximumRows;

            TreeListObjects data = new TreeListObjects(false); // do not bind exchange row if not exist
            RepairListHeader header = new RepairListHeader();
            RepairSpare rSpare;
            ExchangeSpare exSpare;

            Exchangepartheader exchH;
            ArrayList listED;
            ArrayList listSD;
            ArrayList listSH = GetServiceHeaders(branchCode);

            ItemCount = (listSH == null) ? 0 : listSH.Count;
            PageSize = maximumRows;
            FirstItemIndex = startRowIndex;

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

            if ((listSH == null) || (listSH.Count == 0)) return null;
            for (int i = 0; i < ItemCount; i++)
            {
                Serviceheader serH = (Serviceheader)listSH[i];
                // header section
                header = new RepairListHeader();
                header.No = i + 1;
                header.CustomerName = serH.Customer.Fullname;
                header.EngineNumber = serH.Enginenumber;
                header.RepairDate = serH.Servicedate;

                // repair section
                header.ServiceRecordSheet.BindOrder = 1;
                header.ServiceRecordSheet.ServiceSheetNumber = serH.Servicesheetnumber;
                header.ServiceRecordSheet.RepairFeeAmount = serH.Feeamount;
                listSD = GetServiceDetails(serH.Id);
                foreach (Servicedetail serD in listSD)
                {
                    rSpare = new RepairSpare(serD.Partcode, serD.Partqty, serD.Unitprice);
                    header.ServiceRecordSheet.Items.Add(rSpare);
                }

                // exchange section
                header.ExchangeSpares.BindOrder = 2;
                exchH = GetExchangeHeader(serH.Id);
                if (exchH != null)
                {
                    header.ExchangeSpares.ExchangeVoucherNumber = exchH.Vouchernumber;
                    listED = GetExchangeDetails(exchH.Id);
                    foreach (Exchangepartdetail exchD in listED)
                    {
                        exSpare = new ExchangeSpare(exchD.Partcodem, exchD.Partqtym, exchD.Unitpricem, exchD.Totalfeem);
                        header.ExchangeSpares.Items.Add(exSpare);
                    }
                }

                CalculateSummary(header);
                // add to top list
                if ((i >= FirstItemIndex) && (i < lastItem)) data.Items.Add(header);
            }

            return data;
        }