private void LoadDataForEdit(string autoId)
        {
            VehicleDbHelper db    = new VehicleDbHelper(this);
            ICursor         cData = db.getAutoById(int.Parse(autoId));

            if (cData.MoveToFirst())
            {
                txtYear.Text        = cData.GetString(cData.GetColumnIndex("Year"));
                txtMake.Text        = cData.GetString(cData.GetColumnIndex("Make"));
                txtModel.Text       = cData.GetString(cData.GetColumnIndex("Model"));
                txtColor.Text       = cData.GetString(cData.GetColumnIndex("Color"));
                txtDescription.Text = cData.GetString(cData.GetColumnIndex("Description"));

                sbPaint.Progress      = cData.GetInt(cData.GetColumnIndex("PercentagePaint"));
                sbBody.Progress       = cData.GetInt(cData.GetColumnIndex("PercentageBody"));
                sbGlass.Progress      = cData.GetInt(cData.GetColumnIndex("PercentageGlass"));
                sbTrim.Progress       = cData.GetInt(cData.GetColumnIndex("PercentageTrim"));
                sbUpholstery.Progress = cData.GetInt(cData.GetColumnIndex("PercentageUpholstery"));
                sbMechanical.Progress = cData.GetInt(cData.GetColumnIndex("PercentageMechanical"));
                sbElectrical.Progress = cData.GetInt(cData.GetColumnIndex("PercentageElectrical"));
                sbFrame.Progress      = cData.GetInt(cData.GetColumnIndex("PercentageFrame"));
                sbTires.Progress      = cData.GetInt(cData.GetColumnIndex("PercentageTires"));
                sbOverall.Progress    = cData.GetInt(cData.GetColumnIndex("PercentageOverall"));
            }
        }
예제 #2
0
        private void LoadAutosInList()
        {
            VehicleDbHelper dbVals = new VehicleDbHelper(this);

            if (txtSearch.Text.Trim().Length < 1)
            {
                listItsms = dbVals.GetAllAutos();
            }
            else
            {
                listItsms = dbVals.GetAutosBySearchName(txtSearch.Text.Trim());
            }


            lv.Adapter = new AutoListBaseAdapter(this, listItsms);

            lv.ItemLongClick += lv_ItemLongClick;
        }
        void buttonSave_Click(object sender, EventArgs e)
        {
            VehicleDbHelper db = new VehicleDbHelper(this);

            if (txtYear.Text.Trim().Length < 1)
            {
                Toast.MakeText(this, "Enter Year.", ToastLength.Short).Show();
                return;
            }

            if (txtMake.Text.Trim().Length < 1)
            {
                Toast.MakeText(this, "Enter Make.", ToastLength.Short).Show();
                return;
            }

            if (txtModel.Text.Trim().Length < 1)
            {
                Toast.MakeText(this, "Enter Model.", ToastLength.Short).Show();
                return;
            }

            if (txtColor.Text.Trim().Length < 1)
            {
                Toast.MakeText(this, "Enter Color.", ToastLength.Short).Show();
                return;
            }

            Vehicle ab = new Vehicle();

            if (txtId.Text.Trim().Length > 0)
            {
                ab.Id = int.Parse(txtId.Text);
            }
            ab.Year        = txtYear.Text;
            ab.Make        = txtMake.Text;
            ab.Model       = txtModel.Text;
            ab.Color       = txtColor.Text;
            ab.Description = txtDescription.Text;

            if (sbPaint.Progress > 0)
            {
                ab.PercentagePaint = sbPaint.Progress;
            }
            //Body
            if (sbBody.Progress > 0)
            {
                ab.PercentageBody = sbBody.Progress;
            }
            //Glass
            if (sbGlass.Progress > 0)
            {
                ab.PercentageGlass = sbGlass.Progress;
            }
            //Trim
            if (sbTrim.Progress > 0)
            {
                ab.PercentageTrim = sbTrim.Progress;
            }
            //Upholstery
            if (sbUpholstery.Progress > 0)
            {
                ab.PercentageUpholstery = sbUpholstery.Progress;
            }
            //Mechanical
            if (sbMechanical.Progress > 0)
            {
                ab.PercentageMechanical = sbMechanical.Progress;
            }
            //Electrical
            if (sbMechanical.Progress > 0)
            {
                ab.PercentageElectrical = sbMechanical.Progress;
            }
            //Frame
            if (sbFrame.Progress > 0)
            {
                ab.PercentageFrame = sbFrame.Progress;
            }
            //Tires
            if (sbTires.Progress > 0)
            {
                ab.PercentageTires = sbTires.Progress;
            }
            if (sbOverall.Progress > 0)
            {
                ab.PercentageOverall = sbOverall.Progress;
            }


            try
            {
                if (txtId.Text.Trim().Length > 0)
                {
                    db.UpdateAuto(ab);
                    Toast.MakeText(this, "Auto Updated Successfully.", ToastLength.Short).Show();
                }
                else
                {
                    db.AddNewAuto(ab);
                    Toast.MakeText(this, "New Auto Created Successfully.", ToastLength.Short).Show();
                }

                Finish();

                //Go to main activity after save/edit
                var mainActivity = new Intent(this, typeof(MainActivity));
                StartActivity(mainActivity);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
예제 #4
0
        private void DeleteSelectedAuto(string autoId)
        {
            VehicleDbHelper _db = new VehicleDbHelper(activity);

            _db.DeleteAuto(autoId);
        }