Exemple #1
0
        public static void Import(string[] ofdFilenames)
        {
            int count = 0;

            using (SqlConnection connection =
                       new SqlConnection(new SmartDB().Connection.ConnectionString))
            {
                connection.Open();

                foreach (var filename in ofdFilenames)
                {
                    DataTable newMeter = MakeTable.Meter(filename);
                    //bool flag = getMeterList.Code == ErrorEnum.NoError;

                    DataTable fetchMeter = FetchTable.GetMeter();

                    var fMeter = new HashSet <string>(fetchMeter.AsEnumerable()
                                                      .Select(x => x.Field <string>("SerialNumber")));
                    DataTable dtUniqueGateway = newMeter.AsEnumerable()
                                                .Where(x => !fMeter.Contains(x.Field <string>("SerialNumber")))
                                                .CopyToDataTable();

                    InsertMeterBulkCopy(connection, dtUniqueGateway);
                }
            }
        }
Exemple #2
0
        public static void Import(string[] ofdFilenames)
        {
            int count = 0;

            using (SqlConnection connection =
                       new SqlConnection(new SmartDB().Connection.ConnectionString))
            {
                connection.Open();

                foreach (var filename in ofdFilenames)
                {
                    DataTable newGateway = MakeTable.Gateway(filename);

                    //TODO Create temptable
                    DataTable fetchGateway = FetchTable.GetGateway();

                    var fGateway = new HashSet <string>(fetchGateway.AsEnumerable()
                                                        .Select(x => x.Field <string>("MacAddress")));
                    DataTable dtUniqueGateway = newGateway.AsEnumerable()
                                                .Where(x => !fGateway.Contains(x.Field <string>("MacAddress")))
                                                .CopyToDataTable();

                    using (SqlBulkCopy s = new SqlBulkCopy(connection))
                    {
                        s.DestinationTableName = "Gateway";
                        s.ColumnMappings.Add("MacAddress", "MacAddress");
                        s.ColumnMappings.Add("SimCard", "SimCard");
                        s.ColumnMappings.Add("X", "X");
                        s.ColumnMappings.Add("Y", "Y");
                        s.ColumnMappings.Add("Description", "Description");
                        s.ColumnMappings.Add("InstallationDate", "InstallationDate");
                        s.ColumnMappings.Add("MaintenanceDate", "MaintenanceDate");
                        s.ColumnMappings.Add("IPAddress", "IPAddress");
                        s.ColumnMappings.Add("DMZId", "DMZId");
                        s.ColumnMappings.Add("CityId", "CityId");
                        s.ColumnMappings.Add("Createdby", "Createdby");
                        s.ColumnMappings.Add("Editedby", "Editedby");
                        s.ColumnMappings.Add("DocDate", "DocDate");
                        s.ColumnMappings.Add("Show", "Show");
                        s.ColumnMappings.Add("LockCount", "LockCount");
                        try
                        {
                            s.WriteToServer(dtUniqueGateway);
                            Console.WriteLine($"Importing was successful.");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine($"Contact Admin: {ex.Message}", "Import");
                        }
                    }
                }
            }
        }