/// <summary> /// 读取数据库中 _Dicts_Info 的信息 /// </summary> /// <returns></returns> public static List <DictInfo> GetDictsInfo(SqliteSingleton sqliteInstance) { try { if (dictinfoList != null) { return(dictinfoList); } dictinfoList = new List <DictInfo>(); using SQLiteConnection con = sqliteInstance.GetConnection(); string sql = $"SELECT * FROM [{_Dicts_Info_Table}]"; var sqlcmd = new SQLiteCommand(sql, con);//sql语句 SQLiteDataReader reader = sqlcmd.ExecuteReader(); DataTable dt = new DataTable(); if (reader != null) { dt.Load(reader, LoadOption.PreserveChanges, null); } int rowCount = dt.Rows.Count; //行数 int columnCount = dt.Columns.Count; //列数 if (columnCount != DictInfoItemCount) { ErrorLog.Insert("GetDictsInfo 得到的列数与结构体不匹配"); } for (int i = 0; i < rowCount; i++) { DictInfo di = new DictInfo(); di.DictName = dt.Rows[i][0].ToString(); di.WordCount = int.Parse(dt.Rows[i][1].ToString()); di.BriefIntro = dt.Rows[i][2].ToString(); di.Priority = int.Parse(dt.Rows[i][3].ToString()); di.IsChecked = int.Parse(dt.Rows[i][4].ToString()); dictinfoList.Add(di); } return(dictinfoList); } catch (Exception ex) { ErrorLog.Insert("GetTableNames获取数据库表名字列表出现异常!" + ex); return(null); } }
/// <summary> /// 设置_Dicts_Info的信息,每当有词典的导入、卸载、向上、向下时,都要设置 /// </summary> /// <param name="tableNames"></param> /// <param name="dictOop"></param> public static int SetupDictsInfo(List <DictInfo> toOpDictInfos, DictOps dictOp, SqliteSingleton sqliteInstance) { if (toOpDictInfos.Count == 0) { return(0); } int resultCount = 1; switch (dictOp) { case DictOps.AddDict: DictInfo toAddDictInfo = toOpDictInfos[0]; toAddDictInfo.Priority = dictinfoList.Count + 1; //其他信息已经设置 dictinfoList.Add(toAddDictInfo); break; case DictOps.RemoveDicts: foreach (DictInfo di in toOpDictInfos) //其实只允许选中一个 { dictinfoList.Remove(di); } for (int i = 0; i < dictinfoList.Count; i++) { DictInfo di = dictinfoList[i]; di.Priority = i + 1; } resultCount = toOpDictInfos.Count; break; case DictOps.DictToHigher: //TODO:暂时只向上移动一个 DictInfo toHigherDictInfo = toOpDictInfos[0]; toHigherDictInfo.Priority -= 1; DictInfo adjecent2Higher = GetAdjecentDictInfo(dictinfoList, toHigherDictInfo, Direction.ToHigher); adjecent2Higher.Priority += 1; Swap(dictinfoList, toHigherDictInfo, adjecent2Higher); break; case DictOps.DictToLower: //TODO:暂时只向下移动一个 DictInfo toLowerrDictInfo = toOpDictInfos[0]; DictInfo adjecent2Lower = GetAdjecentDictInfo(dictinfoList, toLowerrDictInfo, Direction.ToLower); toLowerrDictInfo.Priority += 1; adjecent2Lower.Priority -= 1; Swap(dictinfoList, toLowerrDictInfo, adjecent2Lower); break; case DictOps.DictChecked: DictInfo checkedDictInfo = toOpDictInfos[0]; checkedDictInfo.IsChecked = 1; break; case DictOps.DictUnchecked: DictInfo uncheckedDictInfo = toOpDictInfos[0]; uncheckedDictInfo.IsChecked = 0; break; } DataTable dt = ConvertDictInfoList(dictinfoList); sqliteInstance.WriteTable2Db(dt, _Dicts_Info_Table, Sql2CreatelDictsInfo); return(resultCount); }