fix: ordering with search v0
This commit is contained in:
@@ -15,8 +15,9 @@ namespace CarManagerV2
|
|||||||
string color;
|
string color;
|
||||||
int mileage;
|
int mileage;
|
||||||
decimal price;
|
decimal price;
|
||||||
|
int order;
|
||||||
|
|
||||||
public Car(int id, string make, string model, int year, string color, int mileage, decimal price)
|
public Car(int id, string make, string model, int year, string color, int mileage, decimal price, int order = 0)
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.make = make;
|
this.make = make;
|
||||||
@@ -25,6 +26,7 @@ namespace CarManagerV2
|
|||||||
this.color = color;
|
this.color = color;
|
||||||
this.mileage = mileage;
|
this.mileage = mileage;
|
||||||
this.price = price;
|
this.price = price;
|
||||||
|
this.order = order;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Id { get { return id; } set { id = value; } }
|
public int Id { get { return id; } set { id = value; } }
|
||||||
@@ -34,6 +36,7 @@ namespace CarManagerV2
|
|||||||
public string Color { get { return color; } set { color = value; } }
|
public string Color { get { return color; } set { color = value; } }
|
||||||
public int Mileage { get { return mileage; } set { mileage = value; } }
|
public int Mileage { get { return mileage; } set { mileage = value; } }
|
||||||
public decimal Price { get { return price; } set { price = value; } }
|
public decimal Price { get { return price; } set { price = value; } }
|
||||||
|
public int Order { get { return order; } set { order = value; } }
|
||||||
|
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ namespace CarManagerV2
|
|||||||
|
|
||||||
private async void refreshCars(List<Car> _cars, bool updateGlobal = true)
|
private async void refreshCars(List<Car> _cars, bool updateGlobal = true)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Sort by Car.Order. If equal, sort by ID
|
||||||
|
_cars = _cars.Count > 0 ? _cars.OrderBy(c => c.Order).ThenBy(c => c.Id).ToList() : _cars;
|
||||||
|
|
||||||
if (updateGlobal)
|
if (updateGlobal)
|
||||||
{
|
{
|
||||||
cars = _cars;
|
cars = _cars;
|
||||||
@@ -105,6 +109,9 @@ namespace CarManagerV2
|
|||||||
flpCars.Controls.Remove(card);
|
flpCars.Controls.Remove(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flpCars.Refresh();
|
||||||
|
flpCars.Invalidate();
|
||||||
|
flpCars.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -141,12 +148,15 @@ namespace CarManagerV2
|
|||||||
refreshCars(results, false);
|
refreshCars(results, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tbxSearch_TextChanged(object sender, EventArgs e)
|
private async void tbxSearch_TextChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
string query = tbxSearch.Text;
|
string query = tbxSearch.Text;
|
||||||
if(string.IsNullOrWhiteSpace(query))
|
await Task.Delay(300); // debounce
|
||||||
|
if(query != tbxSearch.Text) return; // text changed during delay
|
||||||
|
flpCars.Controls.Clear();
|
||||||
|
if (string.IsNullOrWhiteSpace(query))
|
||||||
{
|
{
|
||||||
refreshCars(cars, false);
|
refreshCars(cars);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user