ios swift uipickerview with 3 columns which have relations - ios

I want to make a uipickerview with 3 columns. But this columns has relation in database.
For example brands are first row. These are BMW,Seat,Mercedes ...
Brand's models are second row. These are 1 Series,2 Series,3 Series for BMW and Ibiza,Leon,Altea for Seat and so Mercedes have its own models. And three column is engine capacity. For example for 1 series 1.4,1.6..., for 3 series 1.6,2.0. And for ibiza 1.2TSI,1.4TSI, 1.6TDI and Leon and Altea and Mercedes' models have their own engine capacity.
In my DB i have three tables. First table is brand(brandId,brand). Second table is model(modelId,brandId,model) and third table is engineCapacity(id,brandId,engineCapacity).
If i have all these brand,model and engine capacity how can i show this relation to user? I mean if user select brand SEAT, second column only shows SEAT's models(Ibiza,Leon,Altea) and then user select Leon and third column only shows LEON's engine capacities(1.2,1.4,1.6).
How can i do this?

Implement the UIPickerViewDelegate method pickerView(_:didSelectRow:inComponent:). In your implementation, if the user changes the brand (component 0) then call reloadComponent(_:) on the model and engine size components, and have the data source methods use the currently selected brand to determine which items to return for models and engine sizes.
(When you first display the picker view, have a specific brand and model selected, and populate the model component with the list of available models for the selected brand, and have the engine sizes component populated for the selected brand & model.)

Related

Two UIPickerViews with Large Data Set

I would like to create a simple app in Xcode with two UIPickerViews that reference a data set where the second UIPickerView is dependent on the first one. I want to create an app where the user can select the manufacturer of a vehicle; Chevrolet, Dodge, Ford, etc. Then, the user can select the vehicle based on the first choice. For example if "Ford" was selected in the first UIPickerView, then only Ford vehicles show up in the second - F150, Focus, Mustang etc. After selecting both values, the user can search for the average price where the prices are kept in a data set. I found many examples with one UIPickerView referencing arrays, but I want to reference a much larger data set. How would I go about doing this? I am fairly new to Xcode, but I write SAS and SQL code daily.
I am assuming you have all of records saved in the database. I did something similar with 250k+ records.
Do not fetch all of your models' full representation into memory, fetch only one property (string column needed for current picker) with a DISTINCT on it - both SQLite & CoreData allow this.
Your subsequent pickers (2nd, 3rd & so on) will automatically see less data becuase of the previous filter applied (only Ford vehicles possible options).
Rule #1 applies to all of your pickers, only the relevant field as String pulled into memory with right filters.
I had no issues at all with above approach with my dataset. Not sure how big your dataset is.

How can make a group of data from 2 tables using a tcxGrid in Delphi?

I'm trying to implement a functionality using TcxGrid in Delphi RAD STUDIO:
I have 2 tables, CARS BRANDS and MODELS, I want to show all the Car Brands and Models (on the grid), and let the user pick any Cars brands (BMW, Mercedez, Ferrari) (previouslly created on the CAR BRANDS table) and then pick any of the Models for each brand. For instance, User picks BMW and decides to pick for that brand the models 1A, 2B, 3C (previouslly created on the MODELS table). Then, picks Ferrari and the models 1A, 3C, 4D for that brand. Finally he clicks "SAVE" and it will create a third table: CAR BRANDS/MODELS with the information:
(BMW, 1A);(BMW,2B);(BMW,3C);(FERRARI,1A);(FERRARI, 3C);(FERRARI, 4D)
I'm looking for some way to implement this, thank you in advice!
Your wish come true by simple approach. You need use usual master/detail grids. In the top of your form you need to place master grid with data from table CAR BRANDS, and in the bottom part of your form you need place the secong grid(detail) with data from MODELS.
In detail grid you need make one field with checkbox for selecting models.
These two forms will be works by following way: when user clicks on row in master grid, then you must update detail grid and show for user all models for selected car brand.
If you use devexpress you can find interesting examples in demo for VCL.

Related tables, filters and conditions

I have a new table where one of his fields is related to Table Items. I want to place a filter in one of the function fields Item Category pointing register the Item table, but do not know how this dual role. I hope it was not too confusing ..

How in MVC accumulate data in model

I am just started learn Web Application Programming and will appreciate any help.
I am using MVC 4 and the problem I trying to solve is:
I want to calculate total energy spent in daily activities.
I have 20 different categories of activities. Each of these categories has subcategories mapped into DB table.
I want repeatedly to select categories in the view. For selected category get data from table and select any number of subcategories and show them in the main view.
I solved this in a way which probably the worst (according to performance). I will appreciate any help.
Here is my approach:
I select a category in the View_1 and pass it into the View_2. I make selections in View_2 and submit them to controller C_2 , where selected items are accumulated in the TempData. I put all accumulated items at the final stage into a Model.

DB grid : How to use a column of the current row of one as an index into another?

I am not sure if the question title is clear enough, please feel free to edit it.
Basically, I have two DB grids which reflect two database tables, each grid showing one.
When the user selects a row in the first table (let's call it oders), I want to update the second with details of any rows matching a column of the selected row of the first table.
Say, for instance that table orders has a column customer_id and I want to populate the second table (let's call it order_details) with details of all orders from that customer, one order per row.
I can connect up 2 # datasource, query and connection to the two TDbGrids, but I am stuck as to how to code order_details SQL.
The SQL for orders is just SELECT * from orders, but the other?
I want something like SELECT * from order_details WHERE cutomer_id=<orderQuery>.currentRow.FieldByName("customer_id").AsInteger - but I don't know how to do that ...
Can someone help me with some Delphi code?
Also, once I set up that relationship, will selecting a new row in the orders DB grid automatically update the order_details DB grid? Or do I need to add code for that.
P.s I know that there is no books tag anymore (more's the pity), but can someone recommend a good book which explains the fundamentals of programming DB aware controls? I obviously need one. Thanks
Use a parameterized query for the detail (child) database:
SELECT * FROM Order_Details od WHERE od.CustomerID = :CustomerID
Then set the child query's MasterSource to the parent (Order) datasource, and the MasterFields to CustomerID. (If there are multiple columns that link the two, separate them by ;, as in CustomerID;OrderNumber.)
Every time you scroll the parent (change the selected record in the parent DBGrid), the child query will be executed with the ID of the parent row passed as a parameter automatically.

Resources