static void Main() { /* * FileStream filestream = new FileStream("output.txt", FileMode.Create); * var streamwriter = new StreamWriter(filestream); * streamwriter.AutoFlush = true; * Console.SetOut(streamwriter); * Console.SetError(streamwriter); * Globals.counter = 0;*/ //String contact_connectionString = "Data Source=EBAILEY;Initial Catalog=Contacts;Integrated Security=True"; List <EnerGovSource> contacts = new List <EnerGovSource>(); using (SqlConnection contact_connection = new SqlConnection(contact_connectionString)) { SqlCommand contact_command = new SqlCommand("GetContactCompanyBusiness", contact_connection); contact_command.CommandType = CommandType.StoredProcedure; contact_connection.Open(); SqlDataReader con_rdr = contact_command.ExecuteReader(); while (con_rdr.Read()) { EnerGovSource source = new EnerGovSource(); source.Contact_ID = con_rdr["contact_id"].ToString(); source.Company_Name = con_rdr["company_name"].ToString(); source.BTR_IDs = con_rdr["btr_ids"].ToString(); source.ENG_IDs = con_rdr["eng_ids"].ToString(); source.CODE_IDs = con_rdr["cont_ids"].ToString(); source.building_id = con_rdr["building_ids"].ToString(); contacts.Add(source); } contact_connection.Close(); } List <Business> businesses = new List <Business>(); List <Business_Address> business_addresses = new List <Business_Address>(); //List<Business_Parcel> business_parcels = new List<Business_Parcel>(); List <Business_Note> business_notes = new List <Business_Note>(); for (int i = 0; i < contacts.Count; i++) { ProcessBusiness(contacts[i]); /* * using (SqlConnection bus_con = new SqlConnection(contact_connectionString)) * { * SqlCommand bus_command = new SqlCommand("GetBusinessInfo", bus_con); * bus_command.CommandType = CommandType.StoredProcedure; * * bus_command.Parameters.AddWithValue("@refnum", split[0]); * * bus_con.Open(); * * SqlDataReader bus_rdr = bus_command.ExecuteReader(); * * while (bus_rdr.Read()) * { * Globals.counter = Globals.counter + 1; * Business business = new Business() * { * Business_ID = ReturnFormattedID(Globals.counter), * Contact_ID = contacts[i].Contact_ID, * Ownership_Type = bus_rdr["Ownership"].ToString(), * Location_Type = "Commercial", * Business_Status = "Active", * District = bus_rdr["district"].ToString(), * Open_Date = bus_rdr["open_date"].ToString(), * Business_Description = "", * Closed_Date = "", * Federal_ID_Number = bus_rdr["federal_id_number"].ToString(), * State_ID_Number = "", * DBA = "", * Legacy_Data_Source_Name = "BTR" * }; * businesses.Add(business); * Console.WriteLine("New Business Object created with ID: " + ReturnFormattedID(Globals.counter)); * * Business_Address business_address = new Business_Address() * { * Business_ID = ReturnFormattedID(Globals.counter), * Main_Address = true, * Address_Type = "Location", * Street_Number = bus_rdr["street_number"].ToString(), * Pre_Direction = bus_rdr["pre_direction"].ToString(), * Street_Name = bus_rdr["street_name"].ToString(), * Street_Type = bus_rdr["street_type"].ToString(), * Post_Direction = "", * Unit_Suite_Number = bus_rdr["unit_suite_number"].ToString(), * Address_Line_3 = "", * PO_Box = "", * City = bus_rdr["city"].ToString(), * State_Code = "FL", * Zip = bus_rdr["zip"].ToString(), * County_Code = "", * Country_Code = "", * Country_Type = "US", * Last_Update_Date = "", * Last_Update_User = "" * }; * * business_addresses.Add(business_address); * * Business_Note business_note = new Business_Note() * { * Business_ID = ReturnFormattedID(Globals.counter), * Note_Text = bus_rdr["note_text"].ToString(), * Note_User = "", * Note_Date = "" * }; * * business_notes.Add(business_note); * * Business_Parcel business_parcel = new Business_Parcel() * { * Business_ID = ReturnFormattedID(Globals.counter), * Parcel_Number = bus_rdr["note_text"].ToString(), * Main_Parcel = true * }; * * business_parcels.Add(business_parcel); * * * } * }*/ } }
static void ProcessBusiness(EnerGovSource source) { string[] split = source.BTR_IDs.Split(";"); Console.WriteLine("Processing Business Object with Contact ID of " + source.Contact_ID + " and " + split[0]); using (SqlConnection bus_con = new SqlConnection(contact_connectionString)) { SqlCommand bus_command = new SqlCommand("GetBusinessInfo", bus_con); bus_command.CommandType = CommandType.StoredProcedure; bus_command.Parameters.AddWithValue("@refnum", split[0]); bus_con.Open(); SqlDataReader bus_rdr = bus_command.ExecuteReader(); while (bus_rdr.Read()) { Globals.counter = Globals.counter + 1; Business business = new Business() { Business_ID = ReturnFormattedID(Globals.counter), Contact_ID = source.Contact_ID, Ownership_Type = bus_rdr["Ownership"].ToString(), Location_Type = "Commercial", Business_Status = "Active", District = bus_rdr["district"].ToString(), Open_Date = bus_rdr["open_date"].ToString(), Business_Description = "", Closed_Date = "", Federal_ID_Number = bus_rdr["federal_id_number"].ToString(), State_ID_Number = "", DBA = "", Legacy_Data_Source_Name = "BTR" }; Console.WriteLine("New Business Object created with ID: " + ReturnFormattedID(Globals.counter)); Business_Address business_address = new Business_Address() { Business_ID = ReturnFormattedID(Globals.counter), Main_Address = true, Address_Type = "Location", Street_Number = bus_rdr["street_number"].ToString(), Pre_Direction = bus_rdr["pre_direction"].ToString(), Street_Name = bus_rdr["street_name"].ToString(), Street_Type = bus_rdr["street_type"].ToString(), Post_Direction = "", Unit_Suite_Number = bus_rdr["unit_suite_number"].ToString(), Address_Line_3 = "", PO_Box = "", City = bus_rdr["city"].ToString(), State_Code = "FL", Zip = bus_rdr["zip"].ToString(), County_Code = "", Country_Code = "", Country_Type = "US", Last_Update_Date = "", Last_Update_User = "" }; Business_Note business_note = new Business_Note() { Business_ID = ReturnFormattedID(Globals.counter), Note_Text = bus_rdr["note_text"].ToString(), Note_User = "", Note_Date = "" }; /* * Business_Parcel business_parcel = new Business_Parcel() * { * Business_ID = ReturnFormattedID(Globals.counter), * Parcel_Number = bus_rdr["note_text"].ToString(), * Main_Parcel = true * };*/ /* * //Business Additional Fields * Business_Additional_Fields business_additional_fields = new Business_Additional_Fields * { * Business_ID = ReturnFormattedID(Globals.counter), * Exemptions = bus_rdr["Exemption"].ToString(), * NewHomeBasedBusiness = bus_rdr["NewHomeBasedBusiness"].ToString(), * NotForProfitBusiness = bus_rdr["NotForProfitBusiness"].ToString(), * OfAdditionalClassifications = Convert.ToDecimal(bus_rdr["OfAdditionalClassifications"]) * };*/ InsertBusiness(business); InsertBusinessAddress(business_address); // InsertBusinessParcel(business_parcels); InsertBusinessNote(business_note); // InsertBusinessAdditionalFields(business_additional_fields); } } }