private void ShowServiceSheet(bool readOnly, Serviceheader serH)
    {
        _finish = readOnly;
        readOnlyForm = readOnly;
        AddExchange1.readOnlyMode = readOnly;

        if (serH != null)
        {
            //_exchangeHeader = RepairListDataSource.GetExchangeHeaderFromServiceSheet(serH.Id);

            #region header section
            // warranty info
            // WarrantyInfo warrInfo = ServiceTools.GetWarrantyInfo(serH.Enginenumber);

            _sVehileColor = serH.Colorcode;
            _sVehicleDealer = serH.Dealercode;
            _sVehicleType = serH.Itemtype;
            _feeAmount = serH.Feeamount.ToString();

            txtSheetNo.Text = serH.Servicesheetnumber;
            txtEngineNo.Text = serH.Enginenumber;

            txtErrorStatus.Text = serH.Damaged;
            txtRepair.Text = serH.Repairresult;

            viewmodeDealer = serH.Dealercode;
            if (ListContainsValue(ddlDealer.Items, viewmodeDealer)) ddlDealer.SelectedValue = viewmodeDealer;
            else ddlDealer.Items.Clear();
            GetBranchs();

            btnCheck_Click(null, null); // donot clear
            EnableButtonAfterCheck(true, true);

            // service type
            bool maint = false, rep = false, warr = false;
            switch ((ServiceType)serH.Servicetype)
            {
                case ServiceType.Repair: rep = true; break;
                case ServiceType.Warranty: warr = true; break;
                case ServiceType.Maintain: maint = true; break;
                case ServiceType.MaintainAndRepair: maint = true; rep = true; break;
                case ServiceType.MaintainAndWarranty: maint = true; warr = true; break;
                case ServiceType.WarrantyAndRepair: warr = true; rep = true; break;
                case ServiceType.RepairAndMaintainAndWarranty: maint = true; rep = true; warr = true; break;
            }
            chblSerList.Items[0].Selected = maint; chblSerList.Items[1].Selected = rep; chblSerList.Items[2].Selected = warr;
            #endregion

            gvSpareList.DataSourceTable.Rows.Clear();

            #region repair section
            _feeAmount = serH.Feeamount.ToString();

            // service detail: spares
            RepairListDataSource ds = new RepairListDataSource();
            ArrayList serDs = ds.GetServiceDetails(serH.Id);
            for (int i = 0; i < serDs.Count; i++)
            {
                Servicedetail serD = (Servicedetail)serDs[i];
                DataRow row = gvSpareList.DataSourceTable.NewRow();
                Warrantycondition spareInfo = WarrantyContent.GetWarrantyCondition(serD.Partcode);

                row["SpareNo"] = i + 1;
                row["SpareNumber"] = serD.Partcode;
                row["Quantity"] = serD.Partqty;
                row["SpareCost"] = serD.Unitprice;
                row["IsExchangeSpare"] = string.Empty;
                row["ItemId"] = serD.Id;

                if (spareInfo != null)
                {
                    row["SpareNameEn"] = spareInfo.Partnameen;
                    row["SpareNameVn"] = spareInfo.Partnamevn;
                    row["SpareName"] = (Thread.CurrentThread.CurrentCulture.Name == "vi-VN") ? spareInfo.Partnamevn : spareInfo.Partnameen;
                }
                else
                {
                    row["SpareNameEn"] = serD.Partname;
                    row["SpareNameVn"] = serD.Partname;
                    row["SpareName"] = serD.Partname;
                }

                CalculateAmount(row, null);
                gvSpareList.DataSourceTable.Rows.Add(row);
            }
            #endregion

            #region exchangeSection
            if (ds == null) ds = new RepairListDataSource();
            Exchangepartheader exch = ds.GetExchangeHeader(serH.Id);
            _exchangeHeader = exch;
            if (exch != null)
            {
                AddExchange1.ExchangeHeader = _exchangeHeader;
                AddExchange1.InitUC();
                AddExchange1.SpareList.Rows.Clear();

                ArrayList exchDs = ds.GetExchangeDetails(exch.Id);
                AddExchange1.RawSpareList = AddExchange.SpareListOnServiceSchema;

                for (int i = 0; i < exchDs.Count; i++)
                {
                    Exchangepartdetail exchD = (Exchangepartdetail)exchDs[i];
                    Warrantycondition spareInfo = WarrantyContent.GetWarrantyCondition(exchD.Partcodem);

                    #region Display on SRS
                    DataRow row = gvSpareList.DataSourceTable.NewRow();
                    row["SpareNo"] = i + 1;
                    row["SpareNumber"] = exchD.Partcodem;
                    row["Quantity"] = exchD.Partqtym;
                    row["SpareCost"] = exchD.Unitpricem;
                    row["ExchangeNumber"] = exch.Vouchernumber;
                    row["IsExchangeSpare"] = "true";
                    row["ItemId"] = exchD.Id;
                    if (spareInfo != null)
                    {
                        row["SpareNameEn"] = spareInfo.Partnameen;
                        row["SpareNameVn"] = spareInfo.Partnamevn;
                        row["SpareName"] = (Thread.CurrentThread.CurrentCulture.Name == "vi-VN") ? spareInfo.Partnamevn : spareInfo.Partnameen;
                    }
                    else
                    {
                        row["SpareNameEn"] = Message.DataLost;
                        row["SpareNameVn"] = Message.DataLost;
                        row["SpareName"] = Message.DataLost;
                    }

                    //_feeAmount = exch.Feeamount.ToString();
                    //CalculateAmount(row, null);
                    gvSpareList.DataSourceTable.Rows.InsertAt(row, 0);
                    #endregion

                    #region display on PCV
                    row = AddExchange1.RawSpareList.NewRow();

                    row["ItemId"] = exchD.Id;
                    row["SpareNo"] = i + 1;
                    row["SpareNumber"] = exchD.Partcodem;
                    row["Quantity"] = exchD.Partqtym;
                    row["BrokenCode"] = exchD.Broken.Brokencode;
                    row["SerialNumber"] = exchD.Serialnumber;

                    AddExchange1.AddNewItem(row);
                    AddExchange1.RawSpareList.Rows.Add(row);
                    #endregion
                }
            }
            #endregion

            CalculateTotalAmount();
            gvSpareList.DataBind();
            CheckFinish();

            // cust info n' buy date
            _custInfo = serH.Customer;
            ShowCustInfo();
            txtRepairDate.Text = (serH.Servicedate > DateTime.MinValue) ? serH.Servicedate.ToShortDateString() : "";
        }
    }
    private void ShowExchangeVoucher()
    {
        readOnlyForm = true;
        AddExchange1.readOnlyMode = readOnlyForm;

        Exchangepartheader exH = RepairListDataSource.GetExchangeHeader(showExchangeSparesNumber);
        _exchangeHeader = exH;
        if (
            (exH == null) ||
            (UserHelper.IsDealer && (exH.Dealercode != UserHelper.DealerCode))
           )
        {
            AddError(WarrantyContentErrorCode.ExchangeNumberNotFound);
            SetAvtiveView(vwNoSheetToViewIndex);
        }
        else
        {
            viewmodeDealer = exH.Dealercode;
            AddExchange1.ExchangeHeader = exH;
            AddExchange1.InitUC();
            RepairListDataSource ds = new RepairListDataSource();
            ArrayList exDs = ds.GetExchangeDetails(exH.Id);
            if ((exDs != null) && (exDs.Count > 0))
            {
                DataTable tbl = AddExchange.SpareListOnServiceSchema;
                foreach (Exchangepartdetail exD in exDs)
                {
                    DataRow row = tbl.NewRow();
                    AddExchange1.GetSpareInfo(exD.Partcodem, row);
                    row["Quantity"] = exD.Partqtym;
                    row["SpareCost"] = exD.Unitpricem;
                    row["BrokenCode"] = exD.Broken.Brokencode;
                    row["SerialNumber"] = exD.Serialnumber;
                    AddExchange1.CalculateAmount(row, null);
                    tbl.Rows.Add(row);
                }
                AddExchange1.RawSpareList = tbl;
            }
            SetAvtiveView(vwAddExchangeIndex);
        }
    }