public uint GetDictionaryItemID(FIS_Dictionary dictionary, string itemName) { #region Contracts if (string.IsNullOrWhiteSpace(itemName)) { throw new System.ArgumentException("Некорректное имя элемента.", nameof(itemName)); } #endregion List <object[]> list = _DB_Connection.Select( DB_Table.DICTIONARIES_ITEMS, new string[] { "item_id" }, new List <System.Tuple <string, Relation, object> > { new System.Tuple <string, Relation, object>("dictionary_id", Relation.EQUAL, (uint)dictionary), new System.Tuple <string, Relation, object>("name", Relation.EQUAL, itemName) }); if (list.Count == 0) { throw new System.ArgumentException("Не найден справочник либо элемент справочника с заданным наименованием."); } return((uint)list[0][0]); }
private void FillComboBox(ComboBox cb, FIS_Dictionary dictionary) { cb.Items.AddRange(_DB_Helper.GetDictionaryItems(dictionary).Values.ToArray()); if (cb.Items.Count > 0) { cb.SelectedIndex = 0; } }
public Dictionary <uint, string> GetDictionaryItems(FIS_Dictionary dictionary) { return(_DB_Connection.Select( DB_Table.DICTIONARIES_ITEMS, new string[] { "item_id", "name" }, new List <System.Tuple <string, Relation, object> > { new System.Tuple <string, Relation, object>("dictionary_id", Relation.EQUAL, (uint)dictionary) } ).ToDictionary(i1 => (uint)i1[0], i2 => i2[1].ToString())); }
public string GetDictionaryItemName(FIS_Dictionary dictionary, uint itemID) { List <object[]> list = _DB_Connection.Select( DB_Table.DICTIONARIES_ITEMS, new string[] { "name" }, new List <System.Tuple <string, Relation, object> > { new System.Tuple <string, Relation, object>("dictionary_id", Relation.EQUAL, (uint)dictionary), new System.Tuple <string, Relation, object>("item_id", Relation.EQUAL, itemID) }); if (list.Count == 0) { throw new System.ArgumentException("Не найден справочник либо элемент справочника с заданным ID."); } return(list[0][0].ToString()); }
private void UpdateDictionaryItems(FIS_Dictionary dictionary, string dictionaryName, Dictionary <uint, string> fisDictionaryItems) { Dictionary <uint, string> dbDictionaryItems = _DB_Helper.GetDictionaryItems(dictionary); string addedReport = "В справочник №" + dictionary + " \"" + dictionaryName + "\" добавлены элементы:"; ushort addedCount = 0; string deletedReport = ""; foreach (var item in fisDictionaryItems) { if (dbDictionaryItems.ContainsKey(item.Key)) { if (item.Value != dbDictionaryItems[item.Key] && SharedClasses.Utility.ShowChoiceMessageWithConfirmation( "Справочник №" + dictionary + " \"" + dictionaryName + "\":\nв ФИС изменилось наименование элемента с кодом " + item.Key + ":\nC \"" + dbDictionaryItems[item.Key] + "\"\nна \"" + item.Value + "\".\n\nОбновить наименование в БД?", "Действие" )) { _DB_Connection.Update(DB_Table.DICTIONARIES_ITEMS, new Dictionary <string, object> { { "name", item.Value } }, new Dictionary <string, object> { { "dictionary_id", dictionary }, { "item_id", item.Key } } ); } } else { _DB_Connection.Insert(DB_Table.DICTIONARIES_ITEMS, new Dictionary <string, object> { { "dictionary_id", dictionary }, { "item_id", item.Key }, { "name", item.Value } } ); addedReport += "\n" + item.Key + " \"" + item.Value + "\""; addedCount++; } } foreach (var item in dbDictionaryItems) { if (!fisDictionaryItems.ContainsKey(item.Key)) { deletedReport += item.Key + ", "; } } if (addedCount != 0) { addedReport += "\nВсего: " + addedCount; ShowUpdateMessage(addedReport); } if (deletedReport != "") { deletedReport = "Справочник №" + dictionary + ": в ФИС отсутствуют элементы с ID: " + deletedReport.Remove(deletedReport.Length - 2); MessageBox.Show(deletedReport, "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information); } }