internal static SqlCeDataReader ExecuteReader(string req) { try { var con = new Connexion(); SqlCeConnection conne = con.OpenConnection(); var sqlCommand = new SqlCeCommand(req, conne); SqlCeDataReader myReader = sqlCommand.ExecuteReader(); return myReader; } catch (Exception e) { Console.WriteLine(e.ToString()); return null; } }
internal static int ExecuteUpdate(string requête) { // on gère les éventuelles exceptions try { var con = new Connexion(); // ouverture connexion SqlCeConnection conne = con.OpenConnection(); // exécute sqlCommand avec requête de mise à jour var sqlCommand = new SqlCeCommand(requête, conne); int nbLignes = sqlCommand.ExecuteNonQuery(); return nbLignes; } catch (Exception) { return -1; } }
internal static DataSet ExecuteSelect(string requête) { // on gère les éventuelles exceptions try { var con = new Connexion(); SqlCeConnection connexion = con.OpenConnection(); SqlCeCommand cmd = connexion.CreateCommand(); cmd.CommandText = requête; var da = new SqlCeDataAdapter(cmd); var ds = new DataSet(); da.Fill(ds); return ds; } catch (Exception e) { Console.WriteLine(e.ToString()); return null; } }
public DGVQuery(DataGridView dgv, Connexion.Connexion connexion) { this.dgv = dgv; this.connexion = connexion; }
public DGVQuery(Connexion.Connexion connexion) { this.connexion = connexion; }
private string DisplayQueryData(Connexion.Connexion connexion, string SQL, DataGridView dataGridViewOracleData, BackgroundWorker worker, DoWorkEventArgs eArgs) { string result = null; try { //string SelectedTable = treeViewOracleSchema.SelectedNode.Text; using (DbCommand cmd = connexion.Cnn.CreateCommand()) { cmd.Transaction = connexion.MyTransaction; int NumRec = 0; try { string SQLCount = "SELECT count(*) " + SQL.Substring(SQL.ToUpper().IndexOf("FROM")); cmd.CommandText = SQLCount; // string.Format("SELECT count(*) FROM {0}", SelectedTable); cmd.Prepare(); NumRec = Convert.ToInt32(cmd.ExecuteScalar()) + dataGridViewOracleData.Rows.Count; } catch (Exception e) { Console.WriteLine(e.Message); NumRec = 0; } //string SQL = string.Format("SELECT * FROM {0}", SelectedTable); cmd.CommandText = SQL; cmd.Prepare(); //int colno = 0; using (DbDataReader rd = cmd.ExecuteReader()) { if (ClearData) { if (dataGridViewOracleData.InvokeRequired) { if (!worker.CancellationPending) dataGridViewOracleData.Invoke(new datagridClear(ClearDataGrid)); } else { dataGridViewOracleData.Rows.Clear(); dataGridViewOracleData.Columns.Clear(); } for (int i = 0; i < rd.FieldCount && !worker.CancellationPending; i++) { if (dataGridViewOracleData.InvokeRequired) { dataGridViewOracleData.Invoke(new datagridAddCol(AddColDataGrid), new object[] { rd.GetName(i), rd.GetName(i) }); } else dataGridViewOracleData.Columns.Add(rd.GetName(i), rd.GetName(i)); } } while (rd.Read() && !worker.CancellationPending) { DataGridViewRow dgrv = new DataGridViewRow(); for (int i = 0; i < dataGridViewOracleData.Columns.Count; i++) { dgrv.Cells.Add(new DataGridViewTextBoxCell()); dgrv.Cells[i].Value = rd.GetValue(i); } if (dataGridViewOracleData.InvokeRequired) { dataGridViewOracleData.Invoke(new datagridAddRow(AddRowDataGrid), new object[] { dgrv }); } else dataGridViewOracleData.Rows.Add(dgrv); int CurrentNumRec = dataGridViewOracleData.Rows.Count; if (worker.WorkerReportsProgress) { if (NumRec != 0) { int percentComplete = (int)((float)CurrentNumRec / (float)NumRec * 100); worker.ReportProgress(percentComplete); } else { worker.ReportProgress(CurrentNumRec % 100); } } } if (worker.WorkerSupportsCancellation) { if (worker.CancellationPending) { eArgs.Cancel = true; result = string.Format("Aborted by user. {0} records found", dataGridViewOracleData.Rows.Count); } else { result = string.Format("{0} records found", dataGridViewOracleData.Rows.Count); } } if (dataGridViewOracleData.InvokeRequired) { dataGridViewOracleData.Invoke(new datagridAutoResizeColumns(DatagridAutoResizeColumns), new object[] { dataGridViewOracleData }); } else dataGridViewOracleData.AutoResizeColumns(); rd.Close(); } } return result; } catch (Exception e) { Exception ee = e; string errorMessage = e.Message; while (e.InnerException != null) { e = e.InnerException; errorMessage += "\n" + e.Message; } MessageBox.Show(errorMessage, "Unexpected error", MessageBoxButtons.OK, MessageBoxIcon.Error); return errorMessage; } }
// Transmit the unit on this node toward the relevant connexion's node bool SendUnit(Connexion relevantConnexion) { // Check if there is a unit to send if (_unitOnNode == null) { // Otherwise, // Return that it couldn't succesfully send the inexisting unit Debug.Log("Error - " +this +" : SendUnit() called with no unit to send."); return false; } // Check if the unit can start traveling to the relevant node if (!_unitOnNode.IsReadyToExecuteOrder()) { // Otherwise, // Return that it couldn't succesfully send the inexisting unit Debug.Log("Error - " + this + " : SendUnit() called but the unit isnt't ready to travel to it's new destination."); return false; } // Transmit the unit on this node to the target node system if (!relevantConnexion._connectedNode.RecieveUnit(_unitOnNode)) { // If the target node couldn't recive the unit, // Return that it couldn't succesfully send the unit Debug.Log("Error - " + this + " : SendUnit() called but couldn't successfully transmit the unit to it's destination node."); return false; } // Make the unit travel to it's relevant node _unitOnNode.RecieveOrder(relevantConnexion._path); // Set the target node on unit _unitOnNode._currentNode = relevantConnexion._connectedNode; // Set the last node on unit _unitOnNode._lastNode = this; // Check if the unit has a child if (_unitOnNode._childCount > 0) { // If it does, spawn it on this node _unitOnNode._childCount--; _unitOnNode = SpawnUnitOnNode(); // Calculate relevant destination _relevantConnexionFound = CalculateRelevantConnexion(ref _relevantConnexion); } else { // Otherwise, remove the stored unit from this node if it was sucessfully sent _unitOnNode = null; // Reset relevant connexion _relevantConnexionFound = false; } // Return that it succesfully send the unit return true; }
bool CalculateRelevantConnexion(ref Connexion relevantConnexion) { // Check if a unit is on this node if (_unitOnNode == null) { // Otherwise, return that it couldn't succesfully calculate the most relevant connexion Debug.Log("Error - " + this + " : SortFrontNodesByRelevancy() called but a unit on this node is needed to sort nodes by relevancy."); return false; } // Check if the front node list isn't empty if (_frontNodes.Count <= 0) { // Otherwise, return that it couldn't succesfully calculate the most relevant connexion Debug.Log("Debug - " + this + " : SortFrontNodesByRelevancy() : _frontNodes.Count <= 0"); return false; } // Select the only connexion if there is only one contained in the front node list if(_frontNodes.Count == 1) { // _debug_ Check if the the connexion is viable if (_frontNodes[0]._connectedNode != null && _unitOnNode._age <= _frontNodes[0]._age + pathAgeTolerance) { relevantConnexion = _frontNodes[0]; return true; } } else { // Select the most recent and accesible one if there are more bool firstRelevantConnexionFound = false; foreach (Connexion connexion in _frontNodes) { // If no relevant connexion has already been found if (!firstRelevantConnexionFound){ // _debug_ Check if the the connexion is viable if(connexion._connectedNode != null && _unitOnNode._age <= _frontNodes[0]._age + pathAgeTolerance) { relevantConnexion = connexion; firstRelevantConnexionFound = true; } } else if (connexion._creationTime >= relevantConnexion._creationTime) { // _debug_ Check if the the connexion is viable if (connexion._connectedNode != null && _unitOnNode._age <= _frontNodes[0]._age + pathAgeTolerance) { relevantConnexion = connexion; } } } if (firstRelevantConnexionFound) return true; } Debug.Log("Debug - " + this + " : SortFrontNodesByRelevancy() : firstRelevantConnexionFound = false"); // Return that no relevant connexions have been found return false; }
public static void SendConnectionInfo(Connexion.Connexion connexion, PlugEvent sender) { if (connexion.IsOpen && !String.IsNullOrEmpty(connexion.OracleConnexion.UserId) && !String.IsNullOrEmpty(connexion.OracleConnexion.Password) && !String.IsNullOrEmpty(connexion.OracleConnexion.DataSource)) { //Personnes personne = (Personnes)PersonListBox.SelectedItem; XmlDocument doc = new XmlDocument(); XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null); doc.AppendChild(docNode); XmlNode rootNode = doc.CreateElement("ToadDotNet"); doc.AppendChild(rootNode); XmlNode actionNode = doc.CreateElement("action"); actionNode.InnerText = "connect"; //XmlAttribute actionAttr = doc.CreateAttribute("connection") rootNode.AppendChild(actionNode); XmlNode productNode = doc.CreateElement("connection"); XmlAttribute productAttribute = doc.CreateAttribute("userid"); productAttribute.Value = connexion.OracleConnexion.UserId; productNode.Attributes.Append(productAttribute); productAttribute = doc.CreateAttribute("password"); productAttribute.Value = connexion.OracleConnexion.Password; productNode.Attributes.Append(productAttribute); productAttribute = doc.CreateAttribute("datasource"); productAttribute.Value = connexion.OracleConnexion.DataSource; productNode.Attributes.Append(productAttribute); actionNode.AppendChild(productNode); if (sender != null) sender.Send(doc.OuterXml); } }