public void Read(int idListener, out List <ConnectionSettings> listConnSett, out int err, out string mes) { listConnSett = new List <ConnectionSettings> (); err = 0; mes = string.Empty; int i = -1; DbConnection conn = DbSources.Sources().GetConnection(idListener, out err); //DbConnection conn = DbTSQLInterface.GetConnection (m_ConnectionSettings, out err); if (err == 0) { DataTable tableSource = DbTSQLInterface.Select(ref conn, "SELECT * FROM SOURCE", null, null, out err), tablePsw; if (err == 0) { for (i = 0; i < tableSource.Rows.Count; i++) { listConnSett.Add(new ConnectionSettings()); listConnSett[i].id = Convert.ToInt32(tableSource.Rows[i]["ID"]); listConnSett[i].name = tableSource.Rows[i]["NAME_SHR"].ToString(); listConnSett [i].server = tableSource.Rows [i] ["IP"].ToString(); listConnSett[i].instance = (!(tableSource.Rows[i]["INSTANCE"] is DBNull)) ? tableSource.Rows[i]["INSTANCE"].ToString().Trim() : string.Empty; listConnSett[i].port = Convert.ToInt32(tableSource.Rows[i]["PORT"]); listConnSett[i].dbName = tableSource.Rows[i]["DB_NAME"].ToString(); listConnSett[i].userName = tableSource.Rows[i]["UID"].ToString(); ////Ignore //listConnSett[i].ignore = tableSource.Columns.IndexOf(@"IGNORE") < 0 ? false : Convert.ToInt32(tableSource.Rows[i]["IGNORE"].ToString()) == 1; //TYPE_DATABASE_CFG.CFG_200 = ??? tablePsw = DbTSQLInterface.Select(ref conn, PasswordRequest(Convert.ToInt32(tableSource.Rows[i]["ID"]), 501), null, null, out err); tableSource = GetConnectionSettings(ref tableSource, i, ref tablePsw, 0); //Password listConnSett[i].password = tableSource.Rows[i]["PASSWORD"].ToString(); } } else { ; } } else { ; } //DbTSQLInterface.CloseConnection (conn, out err); }
//private void fThreadProcConnSett (object obj, DoWorkEventArgs ev) //{ // INDEX_SYNCHRONIZE indx = INDEX_SYNCHRONIZE.UNKNOWN; // while (! (indx == INDEX_SYNCHRONIZE.EXIT)) // { // indx = (INDEX_SYNCHRONIZE) WaitHandle.WaitAny (m_arSyncProc); // switch (indx) // { // case INDEX_SYNCHRONIZE.EXIT: // break; // case INDEX_SYNCHRONIZE.REGISTER: // object []pars = m_queueToRegistered.Dequeue (); // m_queueResult.Enqueue (register (pars [0], (bool)pars [1], (string)pars [2], (bool)pars [3])); // break; // case INDEX_SYNCHRONIZE.UNREGISTER: // unRegister (m_queueToUnRegistered.Dequeue ()); // break; // default: // break; // } // m_arEvtComleted[(int)indx - 1].Set (); // } //} /// <summary> /// Функция для доступа к объекту /// </summary> /// <returns>Объект для управления установленными соединениями с источниками данных</returns> public static DbSources Sources() { if (m_this == null) { m_this = new DbSources(); } else { ; } return(m_this); }
public void Disconnect() { if (!(_iIdListener < 0)) { DbSources.Sources().UnRegister(_iIdListener); } else { ; } _iIdListener = -1; _dbConn = null; }
/*public static DataTable GetConnectionSettings (ConnectionSettings connSett, int id_ext, int id_role, out int er) * { * er = 0; * * DataTable tableRes = DbTSQLInterface.Select(connSett, ConnectionSettingsRequest(id_ext), out er), * tablePsw = DbTSQLInterface.Select(connSett, PasswordRequest(id_ext, id_role), out er); * * return GetConnectionSettings (ref tableRes, 0, ref tablePsw, 0); * }*/ public static DataTable GetConnectionSettings(/*TYPE_DATABASE_CFG typeCfg,*/ int idListener, int id_ext, int id_role, out int er) { DbConnection conn = DbSources.Sources().GetConnection(idListener, out er); if (er == 0) { return(GetConnectionSettings(ref conn, id_ext, id_role, out er)); } else { return(null); } }
/// <summary> /// Возвратить таблицу (!одна строка) с параметрами для устанвления соединения с БД /// </summary> /// <param name="iListenerId">Идентификатор актуального соединения с БД, в которой размещается информация о запрашиваемых параметрах (БД конфигурации)</param> /// <param name="id_ext">Идентификатор источника данных (параметры для соединения с источником данных)</param> /// <param name="id_role">Идентификатор типа источника данных</param> /// <param name="er">Признак ошибки впри выполнении запроса значений</param> /// <returns>Таблица (!одна строка) с параметрами соединения</returns> public static DataTable GetConnectionSettings(int iListenerId, int id_ext, int id_role, out int er) { DataTable tableRes = new DataTable(); DbConnection dbConn = DbSources.Sources().GetConnection(iListenerId, out er); if (er == 0) { tableRes = GetConnectionSettings(ref dbConn, id_ext, id_role, out er); } else { ; } return(tableRes); }
public void Save(int idListener, List <ConnectionSettings> listConnSett, out int err) { err = 1; int i = -1, c = -1; string strQuery, psw , hash; //char []hash; //StringBuilder sb; strQuery = psw = string.Empty; DbConnection conn = DbSources.Sources().GetConnection(idListener, out err); //DbConnection conn = DbTSQLInterface.GetConnection (m_ConnectionSettings, out err); if (err == 0) { DataTable tableSource = null, tablePsw = null; if (err == 0) { for (i = 0; i < listConnSett.Count; i++) { tableSource = DbTSQLInterface.Select(ref conn, ConnectionSettingsRequest(listConnSett[i].id), null, null, out err); //TYPE_DATABASE_CFG.CFG_200 = ??? tablePsw = DbTSQLInterface.Select(ref conn, PasswordRequest(listConnSett[i].id, 501), null, null, out err); if (tableSource.Rows.Count == 0) {//INSERT } else if (tableSource.Rows.Count == 1) { //UPDATE if ((listConnSett[i].server.Equals(tableSource.Rows [0]["IP"].ToString()) == false) || (listConnSett[i].instance.Equals((!(tableSource.Rows[0]["INSTANCE"] is DBNull)) ? tableSource.Rows[0]["INSTANCE"].ToString().Trim() : string.Empty) == false) || (listConnSett[i].dbName.Equals(tableSource.Rows[0]["DB_NAME"].ToString()) == false) || (listConnSett[i].userName.Equals(tableSource.Rows[0]["UID"].ToString()) == false) ) { strQuery += "UPDATE SOURCE SET "; strQuery += "IP='" + listConnSett[i].server + "',"; strQuery += "INSTANCE='" + listConnSett[i].instance + "',"; strQuery += "DB_NAME='" + listConnSett[i].dbName + "',"; strQuery += "UID='" + listConnSett[i].userName + "'"; strQuery += " WHERE ID=" + listConnSett[i].id + ";"; } else { ; //Ничего не изменилось } if (listConnSett[i].password.Length > 0) { //sb = new StringBuilder(listConnSett[i].password); //hash = Crypt.Crypting().to(sb, out err); hash = Crypt.Crypting().Encrypt(listConnSett[i].password, Crypt.KEY); //if (err > 0) if (hash.Length > 0) { if (tablePsw.Rows.Count == 0) { //INSERT strQuery += "INSERT INTO passwords (ID_EXT, ID_ROLE, HASH) VALUES ("; strQuery += listConnSett[i].id + ", "; strQuery += 501 + ", "; strQuery += "'" + hash + "'"; strQuery += ");"; } else if (tablePsw.Rows.Count == 1) { //UPDATE strQuery += "UPDATE passwords SET "; strQuery += "HASH='" + hash + "'"; strQuery += " WHERE ID_EXT=" + listConnSett[i].id; strQuery += " AND "; strQuery += "ID_ROLE=" + 501 + ";"; } else { ; } } else { ; //Ошибка шифрования пароля ИЛИ нет пароля } } else { ; //Нет пароля } } else { ; } } DbTSQLInterface.ExecNonQuery(ref conn, strQuery, null, null, out err); } else { ; } } else { ; } //DbTSQLInterface.CloseConnection (conn, out err); }