Esempio n. 1
0
        public static List <FormMaster> FillList(TaxFormCatalogContext context, string SQLCommand)
        {
            var list = new List <FormMaster>();

            //Load the data into the SqlDataReader
            using (var dataCommand = context.Database.GetDbConnection().CreateCommand())
            {
                dataCommand.CommandType = System.Data.CommandType.Text;
                dataCommand.CommandText = SQLCommand;

                if (dataCommand.Connection.State != System.Data.ConnectionState.Open)
                {
                    dataCommand.Connection.Open();
                }

                var dataReader = dataCommand.ExecuteReader();

                //Fill the list with the contents of the reader
                while (dataReader.Read())
                {
                    var obj = new FormMaster();

                    //Get the property information
                    var properties = typeof(FormMaster).GetProperties();
                    int i          = 0;

                    foreach (var property in properties)
                    {
                        property.SetValue(obj, dataReader[i], null); // set the fields of T to the reader's value
                        i++;
                    }

                    list.Add(obj);
                }

                dataReader.Close();
            }

            return(list);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Beginning Processing");
            int recordsUpdated = 0;
            int recordsErrored = 0;

            // Exclude users that have not logged in within the last 120 days
            string sql = @"SELECT *
                            FROM FormMaster fm
                            WHERE (fm.DORAddress1 is NULL or fm.DORAddress1 = '') 
                            AND (fm.DORAddress2 is NOT NULL or fm.DORAddress2 != '')";

            using (TaxFormCatalogContext context = new TaxFormCatalogContext())
            {
                List <FormMaster> formMasters = FillList(context, sql);

                foreach (FormMaster formMaster in formMasters)
                {
                    formMaster.DORAddress1 = formMaster.DORAddress2;
                    formMaster.DORAddress2 = null;
                    bool success = UpdateFormMasterDORAddress(formMaster, args[0], args[1], args[2]);
                    if (success)
                    {
                        Console.WriteLine(string.Format("3: UpdateFormMasterAddress: TaxFormCode [{0}] was successfully updated.", formMaster.TaxFormCode));
                        recordsUpdated++;
                    }
                    else
                    {
                        Console.WriteLine(string.Format("4: UpdateFormMasterAddress: TaxFormCode [{0}] was not updated.", formMaster.TaxFormCode));
                        recordsErrored++;
                    }
                }

                Console.WriteLine(string.Format("7: UpdateFormMasterDORAddresses: {0} records updated out of {1} total records.  There were {2} records that resulted in an error.", recordsUpdated.ToString(), formMasters.Count.ToString(), recordsErrored.ToString()));
                Console.WriteLine("Complete");
            }
            Console.ReadKey();
        }