Beispiel #1
0
        /// <summary>
        /// Get list of address from database
        /// </summary>
        /// <param name="whereString">sql string contain 'where' params. Ex: "name LIKE '%name%'"</param>
        /// <returns>List of Address objects</returns>
        public List <IAdress> GetAddress(string whereString = "")
        {
            List <IAdress>  list    = new List <IAdress>();
            DBAdapter       adapter = new DBAdapter();
            MySqlDataReader products;

            try
            {
                adapter.OpenConnection();
                if (whereString == "")
                {
                    products = adapter.GetSelectReader("oc_address",
                                                       columns: "oc_customer.firstname,oc_customer.lastname,company,address_1,address_2,city,postcode,oc_country.name as country,oc_zone.name as zone ",
                                                       join:
                                                       String.Concat(
                                                           GetJoinedTableString("oc_customer", "LEFT", "customer_id"),
                                                           GetJoinedTableString("oc_country", "LEFT", "country_id"),
                                                           GetJoinedTableString("oc_zone", "LEFT", "zone_id")
                                                           )
                                                       );
                }
                else
                {
                    products = adapter.GetSelectReader("oc_address",
                                                       columns: "oc_customer.firstname,oc_customer.lastname,company,address_1,address_2,city,postcode,oc_country.name as country,oc_zone.name as zone ",
                                                       where : whereString,
                                                       join:
                                                       String.Concat(
                                                           GetJoinedTableString("oc_customer", "LEFT", "customer_id"),
                                                           GetJoinedTableString("oc_country", "LEFT", "country_id"),
                                                           GetJoinedTableString("oc_zone", "LEFT", "zone_id")
                                                           )
                                                       );
                }
                while (products.Read())
                {
                    list.Add(Adress.Get()
                             .SetFirstName(products["firstname"].ToString())
                             .SetLastName(products["lastname"].ToString())
                             .SetAddress1(products["address_1"].ToString())
                             .SetCity(products["city"].ToString())
                             .SetPostCode(products["postcode"].ToString())
                             .SetCountry(products["country"].ToString())
                             .SetRegion(products["zone"].ToString())
                             .SetAddress2(products["address_2"].ToString())
                             .SetCompany(products["company"].ToString())
                             .Build()
                             );
                }
            }
            catch
            {
                throw new Exception();
            }
            finally
            {
                adapter.CloseConnection();
            }
            return(list);
        }
Beispiel #2
0
        /// <summary>
        /// Read file with address input data
        /// </summary>
        /// <returns>Object IAddress class</returns>
        public IAdress GetInputAddress(string addressFileName = ADDRESS_FILE_NAME)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(XML_PATH + addressFileName);
            XmlElement node = doc.DocumentElement;

            return(Adress.Get()
                   .SetFirstName(node.GetElementsByTagName("firstname")[0].InnerText)
                   .SetLastName(node.GetElementsByTagName("lastname")[0].InnerText)
                   .SetAddress1(node.GetElementsByTagName("address1")[0].InnerText)
                   .SetCity(node.GetElementsByTagName("city")[0].InnerText)
                   .SetPostCode(node.GetElementsByTagName("postcode")[0].InnerText)
                   .SetCountry(node.GetElementsByTagName("country")[0].InnerText)
                   .SetRegion(node.GetElementsByTagName("region")[0].InnerText)
                   .SetAddress2(node.GetElementsByTagName("address2")[0].InnerText)
                   .SetCompany(node.GetElementsByTagName("company")[0].InnerText)
                   .Build());
        }