//Получение Tag параметра из SysTabl public static string TagS(string file, string param) { string stSql = "SELECT SysTabl.ParamTag FROM SysTabl WHERE (SysTabl.ParamName='" + param + "')"; using (var rec = new RecDao(file, stSql, RecordsetTypeEnum.dbOpenSnapshot, RecordsetOptionEnum.dbReadOnly)) return(rec.GetString("ParamTag")); }
//Открытие рекордсетов истории и добавление в историю первой записи после создания private void OpenHistoryRecs() { HistoryIsStable = false; HistoryDb = new DaoDb(_historyFile); History = new RecDao(HistoryDb, "History"); SuperHistory = new RecDao(HistoryDb, "SuperHistory"); if (_useSubHistory) { SubHistory = new RecDao(HistoryDb, "SubHistory"); } if (_useErrorsList) { ErrorsRec = new RecDao(HistoryDb, "ErrorsList"); } if (_reasonUpdate != null) { SubHistoryId = 0; try { StartLog("Создание нового файла истории", _reasonUpdate).Dispose(); _reasonUpdate = null; } catch (Exception ex) { AddErrorAboutHistory(ex); } LastHistoryId = 0; } }
private void OpenTables(bool useSubTabl) { _tabl = new RecDao(_db, "SELECT * FROM SysTabl"); if (useSubTabl) { _sub = new RecDao(_db, "SELECT SysSubTabl.*, SysTabl.ParamName FROM SysTabl INNER JOIN SysSubTabl ON SysTabl.ParamId = SysSubTabl.ParamId"); } }
//Получение Tag подпараметра из SysSubTabl public static string SubTagS(string file, string param, string subparam) { string stSql = "SELECT SysSubTabl.SubParamTag FROM SysTabl INNER JOIN SysSubTabl ON SysTabl.ParamId = SysSubTabl.ParamId " + " WHERE (SysTabl.ParamName='" + param + "') AND (SysSubTabl.SubParamName='" + subparam + "')"; using (var rec = new RecDao(file, stSql, RecordsetTypeEnum.dbOpenSnapshot, RecordsetOptionEnum.dbReadOnly)) return(rec.GetString("SubParamTag")); }
//Добавление параметров в SysTabl public void AddSysParam(string templatePath, string paramName) { using (var rec = new RecDao(File, "SELECT ParamId, ParamName FROM SysTabl WHERE ParamName='" + paramName + "'")) if (rec.HasRows()) { return; } Execute("INSERT INTO SysTabl SELECT ParamName, ParamType, ParamValue, ParamDescription, ParamTag " + "FROM [" + templatePath + "].SysTabl t1 WHERE t1.ParamName='" + paramName + "';"); }
//Добавление подпараметров в SysTabl public void AddSysSubParam(string templatePath, string paramName, string subParamName) { int paramId; using (var sysTablRS = new RecDao(templatePath, "SELECT ParamId,ParamName FROM SysTabl WHERE ParamName='" + paramName + "'")) paramId = sysTablRS.GetInt("ParamId"); Execute("INSERT INTO SysSubTabl " + "SELECT ParamId, SubParamNum, SubParamName,SubParamType, SubParamValue, SubParamDescription, SubParamTag, SubParamRowSource " + "FROM [" + templatePath + "].SysSubTabl t1 WHERE t1.ParamId=" + paramId + " AND t1.SubParamName='" + subParamName + "' AND NOT EXISTS(SELECT * FROM SysSubTabl t2 WHERE t1.SubParamName = t2.SubParamName)"); }
//Запись Tag параметра в SysTabl public static void PutTagS(string file, string param, string tag, string value = null) { string stSql = "SELECT SysTabl.ParamValue, SysTabl.ParamTag FROM SysTabl WHERE (SysTabl.ParamName='" + param + "')"; using (var rec = new RecDao(file, stSql)) { rec.Put("ParamTag", tag); if (value != null) { rec.Put("ParamValue", value); } rec.Update(); } }
//Запись Tag подпараметра в SysSubTabl public static void PutSubTagS(string file, string param, string subparam, string tag, string value = null) { string stSql = "SELECT SysSubTabl.SubParamValue, SysSubTabl.SubParamTag FROM SysTabl INNER JOIN SysSubTabl ON SysTabl.ParamId = SysSubTabl.ParamId " + " WHERE (SysTabl.ParamName='" + param + "') AND (SysSubTabl.SubParamName='" + subparam + "')"; using (var rec = new RecDao(file, stSql, RecordsetTypeEnum.dbOpenDynaset)) { rec.Put("SubParamTag", tag); if (value != null) { rec.Put("SubParamValue", value); } rec.Update(); } }
//Запись значения подпараметра в SysSubTabl public void PutSubValueS(string file, string param, string subparam, string value, string tag = null) { string stSql = "SELECT SysSubTabl.SubParamValue, SysSubTabl.SubParamTag FROM SysTabl INNER JOIN SysSubTabl ON SysTabl.ParamId = SysSubTabl.ParamId " + " WHERE (SysTabl.ParamName='" + param + "') AND (SysSubTabl.SubParamName='" + subparam + "')"; using (var rec = new RecDao(file, stSql)) { rec.Put("SubParamValue", value); if (tag != null) { rec.Put("SubParamTag", tag); } rec.Update(); } }
//То же самое, но база данных не задается public void SaveDicToTable <T>(DicS <T> dic, string tabl, string keyField = "Code", string keyField2 = "", string delField = "Del") where T : ISaveToRecDao { var old = new SetS(); var add = new SetS(); using (var rec = new RecDao(this, tabl, RecordsetTypeEnum.dbOpenTable)) while (rec.Read()) { var code = rec.GetString(keyField); if (!keyField2.IsEmpty()) { code += "." + rec.GetString(keyField2); } if (dic.ContainsKey(code)) { old.Add(code); } else { rec.Put(delField, true); } } Execute("DELETE * FROM " + tabl + " WHERE " + delField + "=True"); foreach (var ap in dic.Keys) { if (!old.Contains(ap)) { add.Add(ap); } } using (var rec = new RecDao(this, tabl, RecordsetTypeEnum.dbOpenTable)) { while (rec.Read()) { dic[rec.GetString(keyField) + (keyField2.IsEmpty() ? "" : ("." + rec.GetString(keyField2)))].ToRecordset(rec, false); } foreach (var p in add.Keys) { dic[p].ToRecordset(rec, true); } } }