private void cmsDeleteDataSparepart_Click(object sender, EventArgs e)
        {
            List <SPKDetailSparepartViewModel> listCurrent = SPKSparepartList;

            SPKDetailSparepartViewModel SparepartToRemove = gvSparepart.GetFocusedRow() as SPKDetailSparepartViewModel;


            List <SPKDetailSparepartDetailViewModel> listCurrentDetail = new List <SPKDetailSparepartDetailViewModel>();

            foreach (var item in this.SPKSparepartDetailList.Where(spd => spd.SPKDetailSparepartId == SparepartToRemove.SparepartId))
            {
                listCurrentDetail.Add(item);
            }

            _presenter.RestoreSparepartDetail(listCurrentDetail);

            foreach (var item in listCurrentDetail)
            {
                this.SPKSparepartDetailList.Remove(item);
            }

            listCurrent.Remove(SparepartToRemove);
            SPKSparepartList = listCurrent;

            RefreshSparepartGrid();
            CalculateTotalSparepart();
        }
        private void btnChangeWheel_Click(object sender, EventArgs e)
        {
            SPKWheelChange editor = Bootstrapper.Resolve <SPKWheelChange>();

            editor.SelectedSPK = this.SelectedSPK;
            editor.VehicleId   = this.VehicleId;

            if (this.VehicleWheelList != null)
            {
                editor.VehicleWheelList = this.VehicleWheelList;
            }

            editor.ShowDialog(this);
            this.VehicleWheelList = editor.VehicleWheelList;

            foreach (VehicleWheelViewModel vw in VehicleWheelList.Where(w => w.ReplaceWithWheelDetailId > 0))
            {
                if (!SPKSparepartList.Any(sp => sp.SparepartId == vw.SparepartId))
                {
                    this.SPKSparepartList.Add(new SPKDetailSparepartViewModel
                    {
                        Sparepart = new SparepartViewModel
                        {
                            Id   = vw.SparepartId,
                            Name = vw.ReplaceWithWheelDetailName,
                            Code = vw.WheelDetail.Sparepart.Code
                        },
                        SparepartId = vw.SparepartId,
                    });
                }

                //temp remove by Tegar

                SpecialSparepartDetailViewModel changedVwDetail = _presenter.GetSpecialSparepartDetail(vw.ReplaceWithWheelDetailId);
                if (changedVwDetail.PurchasingDetail != null)
                {
                    if (!SPKSparepartDetailList.Any(spd => spd.PurchasingDetail != null && spd.PurchasingDetailId == changedVwDetail.PurchasingDetailId))
                    {
                        this.SPKSparepartDetailList.Add(new SPKDetailSparepartDetailViewModel
                        {
                            PurchasingDetailId       = changedVwDetail.PurchasingDetailId,
                            PurchasingDetail         = changedVwDetail.PurchasingDetail,
                            SpecialSparepartDetailId = changedVwDetail.Id,
                            SpecialSparepartDetail   = changedVwDetail,
                            SPKDetailSparepartId     = changedVwDetail.SparepartId,
                            Qty = 1
                        });
                    }
                    else
                    {
                        SPKDetailSparepartDetailViewModel detail = SPKSparepartDetailList.Where(spd => spd.PurchasingDetail != null && spd.PurchasingDetailId == changedVwDetail.PurchasingDetailId).FirstOrDefault();
                        detail.Qty += 1;
                    }
                }

                if (changedVwDetail.SparepartManualTransaction != null)
                {
                    if (!SPKSparepartDetailList.Any(spd => spd.SparepartManualTransaction != null && spd.SparepartManualTransactionId == changedVwDetail.SparepartManualTransactionId))
                    {
                        this.SPKSparepartDetailList.Add(new SPKDetailSparepartDetailViewModel
                        {
                            SparepartManualTransactionId = changedVwDetail.SparepartManualTransactionId,
                            SparepartManualTransaction   = changedVwDetail.SparepartManualTransaction,
                            SpecialSparepartDetailId     = changedVwDetail.Id,
                            SpecialSparepartDetail       = changedVwDetail,
                            SPKDetailSparepartId         = changedVwDetail.SparepartId,
                            Qty = 1
                        });
                    }
                    else
                    {
                        SPKDetailSparepartDetailViewModel detail = SPKSparepartDetailList.Where(spd => spd.SparepartManualTransaction != null && spd.SparepartManualTransactionId == changedVwDetail.SparepartManualTransactionId).FirstOrDefault();
                        detail.Qty += 1;
                    }
                }

                SPKDetailSparepartViewModel spkSp = SPKSparepartList.Where(sp => sp.SparepartId == vw.SparepartId).FirstOrDefault();

                if (spkSp != null)
                {
                    spkSp.TotalQuantity++;
                    spkSp.TotalPrice = spkSp.TotalPrice + vw.Price;
                }
            }

            RefreshSparepartGrid();
            CalculateTotalSparepart();
        }