Skip to content

Commit

Permalink
NRCan#356 foxed structure format picklist problem.
Browse files Browse the repository at this point in the history
  • Loading branch information
ghuotvez committed Nov 22, 2024
1 parent 1c78e75 commit 232afc0
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 27 deletions.
Binary file modified GSCFieldApp/Resources/Raw/GSCFieldwork.gpkg
Binary file not shown.
38 changes: 38 additions & 0 deletions GSCFieldApp/Services/Database/DataAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,44 @@ public ComboBox GetComboboxListFromVocab(IEnumerable<Vocabularies> inVocab)
return outputVocabs;
}

/// <summary>
/// From a given list of vocabularies items (usually coming from a more define query), will
/// output a list of combobox items. Will also output as in the default value else -1 for no
/// selection
/// </summary>
/// <param name="inVocab">List of vocabularies that needs to be converted to picker</param>
/// <returns></returns>
public ComboBox GetComboboxListFromStrings(IEnumerable<string> inStrings)
{
//Outputs
List<ComboBoxItem> outputStringList = new List<ComboBoxItem>();
int defaultValueIndex = -1;

//Fill in cbox
foreach (string s in inStrings)
{
ComboBoxItem newItem = new ComboBoxItem();

newItem.itemValue = s;
newItem.itemName = s;

outputStringList.Add(newItem);
}

//If at the end there is onlye one record, make it a default
if (outputStringList.Count == 1)
{
defaultValueIndex = 0;
}

//Set
ComboBox outputCombo = new ComboBox();
outputCombo.cboxItems = outputStringList;
outputCombo.cboxDefaultItemIndex = defaultValueIndex;

return outputCombo;
}

/// <summary>
/// Will delete any record from given parameters.
/// TODO: The field name entry could be replace with the prime key if a TableMapping object is created. I think it returns the prime key field name. - Gab
Expand Down
56 changes: 29 additions & 27 deletions GSCFieldApp/ViewModel/PicklistViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,8 @@ public async void FillFieldValuesPicklist()
//Reset
_picklistValues.Clear();
OnPropertyChanged(nameof(PicklistValues));
_picklistParents.cboxItems.Clear();
OnPropertyChanged(nameof(PicklistParents));
//_picklistParents.cboxItems.Clear();
//OnPropertyChanged(nameof(PicklistParents));

//Get the values
List<Vocabularies> incomingValues = new List<Vocabularies>();
Expand All @@ -466,17 +466,17 @@ public async void FillFieldValuesPicklist()
//Get db AssignTo field from selection
if (assignToFields != null && assignToFields.Count() > 0)
{
incomingValues = await da.GetPicklistValuesAsync(ModelPicklist.PicklistName, assignToFields[0].ThemeAssignField, _modelPicklist.PicklistParent, true);
incomingValues = await da.GetPicklistValuesAsync(_modelPicklist.PicklistName, assignToFields[0].ThemeAssignField, _modelPicklist.PicklistParent, true);
}

}
else
{
if (assignToFields != null && assignToFields.Count() > 0)
{
incomingValues = await da.GetPicklistValuesAsync(ModelPicklist.PicklistName, assignToFields[0].ThemeAssignField, "", true);
incomingValues = await da.GetPicklistValuesAsync(_modelPicklist.PicklistName, assignToFields[0].ThemeAssignField, "", true);
}

}

if (incomingValues != null && incomingValues.Count > 0)
Expand Down Expand Up @@ -508,37 +508,39 @@ public async Task<bool> FillFieldParentValuesPicklist()
_picklistParents.cboxItems.Clear();
OnPropertyChanged(nameof(PicklistParents));

//Build query to retrieve unique parents
//select * from M_DICTIONARY m WHERE m.CODETHEME in
string querySelect_1 = "select * from " + TableDictionary + " m ";
string queryWhere_1 = " WHERE m." + FieldDictionaryCodedTheme + " in ";
string query = string.Format("SELECT DISTINCT(m2.{0}) FROM {1} as m2 WHERE m2.{2} = '{3}'",
FieldDictionaryRelatedTo, TableDictionary, FieldDictionaryCodedTheme, _modelPicklist.PicklistField);

////Build query to retrieve unique parents
////select * from M_DICTIONARY m WHERE m.CODETHEME in
//string querySelect_1 = "select * from " + TableDictionary + " m ";
//string queryWhere_1 = " WHERE m." + FieldDictionaryCodedTheme + " in ";

//(select m.CODETHEME from M_DICTIONARY m join M_DICTIONARY_MANAGER mdm on m.CODETHEME = mdm.CODETHEME WHERE m.CODE in
string querySelect_2 = "(select m." + FieldDictionaryCodedTheme + " from " + TableDictionary + " m ";
string querySelect_2_join = "join " + TableDictionaryManager + " mdm on m." + FieldDictionaryCodedTheme + " = mdm." + FieldDictionaryCodedTheme + " ";
string queryWhere_2 = " WHERE m." + FieldDictionaryCode + " in ";
////(select m.CODETHEME from M_DICTIONARY m join M_DICTIONARY_MANAGER mdm on m.CODETHEME = mdm.CODETHEME WHERE m.CODE in
//string querySelect_2 = "(select m." + FieldDictionaryCodedTheme + " from " + TableDictionary + " m ";
//string querySelect_2_join = "join " + TableDictionaryManager + " mdm on m." + FieldDictionaryCodedTheme + " = mdm." + FieldDictionaryCodedTheme + " ";
//string queryWhere_2 = " WHERE m." + FieldDictionaryCode + " in ";

//(select distinct(m.RELATEDTO) from M_DICTIONARY m WHERE m.CODETHEME = 'MODTEXTURE' ORDER BY m.RELATEDTO ) and mdm.ASSIGNTABLE in
string querySelect_3 = "(select distinct(m." + FieldDictionaryRelatedTo + ") from " + TableDictionary + " m ";
string queryWhere_3 = " WHERE m." + FieldDictionaryCodedTheme + " = '" + _modelPicklist.PicklistField + "'";
string queryOrderBy_3 = " ORDER BY m." + FieldDictionaryRelatedTo + " ) and mdm." + FieldDictionaryManagerAssignTable + " in ";
////(select distinct(m.RELATEDTO) from M_DICTIONARY m WHERE m.CODETHEME = 'MODTEXTURE' ORDER BY m.RELATEDTO ) and mdm.ASSIGNTABLE in
//string querySelect_3 = "(select distinct(m." + FieldDictionaryRelatedTo + ") from " + TableDictionary + " m ";
//string queryWhere_3 = " WHERE m." + FieldDictionaryCodedTheme + " = '" + _modelPicklist.PicklistField + "'";
//string queryOrderBy_3 = " ORDER BY m." + FieldDictionaryRelatedTo + " ) and mdm." + FieldDictionaryManagerAssignTable + " in ";

//(select mdm2.ASSIGNTABLE from M_DICTIONARY_MANAGER mdm2 where mdm2.CODETHEME = 'MODTEXTURE')) AND m.VISIBLE = 'Y' ORDER BY m.DESCRIPTIONEN ASC
string queryWhere_1_2 = "(select mdm2." + FieldDictionaryManagerAssignTable +
" from " + TableDictionaryManager + " mdm2 where mdm2." + FieldDictionaryCodedTheme +
" = '" + _modelPicklist.PicklistField + "'))";
string queryWhere_1_3 = " AND m." + FieldDictionaryVisible + " = '" + boolYes + "'";
string queryOrderby_1 = " ORDER BY m." + FieldDictionaryDescription + " ASC";
////(select mdm2.ASSIGNTABLE from M_DICTIONARY_MANAGER mdm2 where mdm2.CODETHEME = 'MODTEXTURE')) AND m.VISIBLE = 'Y' ORDER BY m.DESCRIPTIONEN ASC
//string queryWhere_1_2 = "(select mdm2." + FieldDictionaryManagerAssignTable +
// " from " + TableDictionaryManager + " mdm2 where mdm2." + FieldDictionaryCodedTheme +
// " = '" + _modelPicklist.PicklistField + "'))";
//string queryOrderby_1 = " ORDER BY m." + FieldDictionaryDescription + " ASC";

string queryFinal = querySelect_1 + queryWhere_1 + querySelect_2 + querySelect_2_join + queryWhere_2 + querySelect_3 + queryWhere_3 + queryOrderBy_3 + queryWhere_1_2 + queryWhere_1_3 + queryOrderby_1;
//string queryFinal = querySelect_1 + queryWhere_1 + querySelect_2 + querySelect_2_join + queryWhere_2 + querySelect_3 + queryWhere_3 + queryOrderBy_3 + queryWhere_1_2 + queryOrderby_1;

SQLiteAsyncConnection currentConnection = da.GetConnectionFromPath(da.PreferedDatabasePath);
List<Vocabularies> parentVocabs = await currentConnection.QueryAsync<Vocabularies>(queryFinal);
List<string> parentVocabs = await currentConnection.QueryScalarsAsync<string>(query);

if (parentVocabs != null && parentVocabs.Count() > 0)
{
//Convert to custom picker
_picklistParents = da.GetComboboxListFromVocab(parentVocabs);
_picklistParents = da.GetComboboxListFromStrings(parentVocabs);
OnPropertyChanged(nameof(PicklistParents));
doesHaveParents = true;
}
Expand Down

0 comments on commit 232afc0

Please sign in to comment.