/// <summary> /// 保存当前配置到数据库(单项字典) /// </summary> /// <param name="dictionary"></param> /// <returns></returns> public string save(DBCommonDictionary dictionary) { string msg = ""; foreach (DBCommonDictionaryItem item in dictionary.items) { msg += save(item); } return(msg); }
/// <summary> /// 从数据库中加载数据 /// </summary> /// <param name="connection_string"></param> private void load(string connection_string) { this.connection_string = connection_string; var query = $"select {connection.left_quote}{dictionary_info.id_column}{connection.right_quote} as {connection.left_quote}id{connection.right_quote}, " + $"{connection.left_quote}{dictionary_info.type_column}{connection.right_quote} as {connection.left_quote}type{connection.right_quote}, " + $"{connection.left_quote}{dictionary_info.content_column}{connection.right_quote} as {connection.left_quote}content{connection.right_quote}, " + $"{connection.left_quote}{dictionary_info.shortcut_column}{connection.right_quote} as {connection.left_quote}shortcut{connection.right_quote}, " + $"{connection.left_quote}{dictionary_info.index_column}{connection.right_quote} as {connection.left_quote}index{connection.right_quote} " + $"from {connection.left_quote}{dictionary_info.table_name}{connection.right_quote} "; if (dictionary_info.domain_column.hasContents()) { query += $" where {connection.left_quote}{dictionary_info.domain_column}{connection.right_quote}={domain_id} "; } query += $" order by {connection.left_quote}{dictionary_info.type_column}{connection.right_quote},{connection.left_quote}{dictionary_info.index_column}{connection.right_quote} "; DataTable data = DBQuery.query(query, connection, null, out string msg); for (int i = 0; i < data.Rows.Count; i++) { try { string type = data.Rows[i]["type"].ToString(); DBCommonDictionary dic = dictionaryWithField(type); if (dic == null) { continue; } DBCommonDictionaryItem item = new DBCommonDictionaryItem(); item.id = Convert.ToInt32(data.Rows[i]["id"]); item.content = data.Rows[i]["content"].ToString(); item.shortcut = data.Rows[i]["shortcut"].ToString(); try { item.index = Convert.ToInt32(data.Rows[i]["index"]); } catch { } dic.items.Add(item); } catch { } } }
public string setItem(string content, string type) { DBCommonDictionary dic = dictionaryWithField(type); if (dic == null) { return("字典类型有误"); } DBCommonDictionaryItem item = dic.get(content); if (item == null) { item = new DBCommonDictionaryItem(); item.id = nextId(); item.content = content; item.dic_type = type; item.shortcut = CharacterUtil.getPinyinShort(content, 50); item.index = nextIndex(type); dic.items.Add(item); return(save(item)); } return(""); }