Exemplo n.º 1
0
        public int BatchInsertIncidentCollections(MatchCollection collections, ConfigInitializer.IncidentTableEntity incidentTable, out HashSet<string> duplicateHash, bool SKIP)
        {
            duplicateHash = new HashSet<string>();
            if (SKIP) return 0;

            var queryText = incidentTable.ToString();
            var incident = new DataNormalizer.DataEntity.Incident(incidentTable);
            int successCount = 0;
            //var queryText = $"INSERT into {this.tableInfo.tableName} {this.tableInfo.queryItemPattern} VALUES {this.tableInfo.queryValuePattern}";
            using (var transaction = this._connection.BeginTransaction())
            {
                foreach (Match match in collections)
                {
                    var cmd = new SqlCommand(queryText, this._connection, transaction);
                    incident.registerSqlCommand(match, ref cmd);
                    try
                    {
                        cmd.ExecuteNonQuery();
                        Console.WriteLine($"Insert: {match.Groups[1].Value}");
                        successCount += 1;
                    }
                    catch
                    {
                        var incidentString = match.Groups[1].Value;
                        duplicateHash.Add(incidentString);
                        Console.WriteLine($"Duplicate Incident: {incidentString}");
                    }
                }
                transaction.Commit();
            }
            return successCount;
        }
Exemplo n.º 2
0
 public void InsertIncidentLevel(ConfigInitializer.LevelTableEntity levelTable, MatchCollection collections, int incidentId)
 {
     string qText = levelTable.ToString();
     var cmd = new SqlCommand(qText, this._connection);
     for (int i = 0; i < 5; i++)
     {
         string tag = collections[i].Groups[1].Value;
         cmd.Parameters.AddWithValue($"@{i + 1}", tag);
     }
     cmd.Parameters.AddWithValue($"@6", incidentId);
     try
     {
         cmd.ExecuteNonQuery();
         Console.WriteLine($" @InsertIncidentLevel : insert {incidentId}");
     }
     catch
     {
         Console.WriteLine("Error happend at @InsertIncidentLevel");
     }
 }