示例#1
0
        /// <summary>
        /// Denne metode henter alt dataen fra Databasens table "Customer" plus lidt fra tablet
        /// "ArtTrade" og laver det om til en liste af ClassCustomer's
        /// </summary>
        /// <param name="inCurrency"></param>
        /// <returns></returns>
        public List <ClassCustomer> GetAllCustomerFromDB(ClassCurrency inCurrency)
        {
            List <ClassCustomer> listCCres = new List <ClassCustomer>();

            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = con;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "spGetAllCustomerFromDB";

            DataTable dataTable = MakeCallToStoredProcedure(cmd);

            foreach (DataRow row in dataTable.Rows)
            {
                ClassCustomer customer = new ClassCustomer();

                customer.customerID             = Convert.ToInt32(row["id"]);
                customer.name                   = row["name"].ToString();
                customer.address                = row["address"].ToString();
                customer.zipCity                = row["zipCity"].ToString();
                customer.country                = row["country"].ToString();
                customer.email                  = row["email"].ToString();
                customer.phoneNo                = row["phone"].ToString();
                customer.classSalesValue.bidUSD = row["maximumBid"].ToString();
                customer.customerCurrencyID     = row["preferredCurrency"].ToString();
                customer.isActive               = Convert.ToBoolean(row["isActive"]);

                listCCres.Add(customer);
            }

            return(listCCres);
        }
示例#2
0
        public ClassBiz()
        {
            classCurrency = new ClassCurrency();
            GetAllCurrencyIdAndNames();

            classCustomer = new ClassCustomer();
            classCustomer.classCurrency = classCurrency;

            listCustomer = classWorldArtSaleDB.GetAllCustomerFromDB(classCurrency);
            listClassArt = classWorldArtSaleDB.GetAllArtFromDB();
        }
示例#3
0
        public async Task StartCurrencyApiCall()
        {
            while (runUpdate)
            {
                // GetURLContents returns the contents of url as a byte array.
                byte[] urlContents = await classCallWebAPI.GetURLContentsAsync("https://openexchangerates.org/api/latest.json?app_id=09e34d204d7e4b998d7f178033b742ca");

                string strJson = System.Text.Encoding.UTF8.GetString(urlContents);
                classCurrency = JsonConvert.DeserializeObject <ClassCurrency>(strJson);
                await Task.Delay(60000);
            }
        }
示例#4
0
        public ClassBIZ()
        {
            selectedCurrency = new ClassCurrency();
            selectedCustomer = new ClassCustomer();
            selectedArt      = new ClassArt();
            listClassArt     = new List <ClassArt>();
            listCustomer     = new List <ClassCustomer>();

            Task.Run(async() => await StartCurrencyApiCall());
            classFile.ReadDataFromCurrencyFile();
            listCustomer = classDB.GetAllCustomerFromDB(selectedCurrency);
            listClassArt = classDB.GetAllArtFromDB();
        }
示例#5
0
        /// <summary>
        /// Kalder Api'en og smider dataen ind i en ClassCurrency.
        /// Gentager sig selv vært 5 minut (hvært 10 sek for testing)
        /// </summary>
        /// <returns></returns>
        public async Task StartCurrencyApiCall()
        {
            while (true)
            {
                byte[] urlContents = await classAPI.GetURLContentsAsync("https://openexchangerates.org/api/latest.json?app_id=5c02031ed690400cb11fe0224a861ad8&base=USD");

                string strJason = System.Text.Encoding.UTF8.GetString(urlContents);
                selectedCurrency = JsonConvert.DeserializeObject <ClassCurrency>(strJason);

                //await Task.Delay(300000);
                await Task.Delay(10000);
            }
        }
示例#6
0
        /// <summary>
        /// This method calls our webapi.
        /// The method is async to avoid any delays if the data from the api is delayed.
        /// </summary>
        /// <returns>List</returns>
        public async Task <ClassCurrency> GetAllCurrenciesWebAPI()
        {
            ClassCurrency res = new ClassCurrency();

            try
            {
                res = await classCallWebAPI.GetURLContentsAsync();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(res);
        }
示例#7
0
        public ClassBiz()
        {
            classCurrency = new ClassCurrency();
            GetAllCurrencyIdAndNames();



            ClassSalesValues csv = new ClassSalesValues();

            csv.classCurrency = classCurrency;

            classCustomer        = new ClassCustomer();
            listClassArt         = new List <ClassArt>(getdata.classArt.ToList() as List <ClassArt>);
            classArt             = new ClassArt();
            listCustomer         = new List <ClassCustomer>(getdata.classCustomer.ToList() as List <ClassCustomer>);
            ClassSalesValues     = new ClassSalesValues();
            listclassSalesValues = new List <ClassSalesValues>(getdata.classSalesValues.ToList() as List <ClassSalesValues>);
        }
示例#8
0
 public ClassBIZ()
 {
     textLock              = "true";
     comboLock             = "false";
     classCallWebAPI       = new ClassCallWebAPI();
     classLuxYachtDieselDB = new ClassLuxYachtDieselDB();
     currency              = new ClassCurrency();
     selectedCustomer      = new ClassCustomer();
     selectedSupplier      = new ClassSupplier();
     fallbackCustomer      = new ClassCustomer();
     fallbackSupplier      = new ClassSupplier();
     listCountry           = GetAllCountries();
     listDieselPrice       = GetAllDieselPricesForListFromDB();
     //country = new List<ClassCountry>();
     listCustomers = GetAllCustomersForListFromDB();
     listSupplier  = GetAllSuplliersForListFromDB();
     dieselPrice   = GetDieselPriceFromDB();
     order         = new ClassOrder();
 }
示例#9
0
        /// <summary>
        /// This method creates the connection the webApi.
        ///  We make an instance of MemoryStream,
        ///  this is the object which contains the return of our request as a collection of bytes.
        ///  Create an abstract variable webReq which holds the actual request.
        ///  The request has to be made as a WebRequest which has to be casted to a HTTPWebRequest, this means we by force transform.
        ///  We do this as we can't make a HTTPWebRequest with the parameters that are available,
        ///  but as there is a overloaded constructor in the class which can convert a WebRequest into a HTTPWebRequest instance
        ///  we obtain that the communication between the application and the WEB API is via the HTTP protocol
        ///  The actual communication with the WEB API is wrapped in a "using",
        ///  as we want the actual connection to be closed properly after use without having to write to much code,
        ///  as using and GarbageCollector will do this for us.
        ///  In the first using we start the request, as we are communicating with and external device
        ///  we use await to imply that this part can be executed asynchronized.
        ///  This means that if the WEB API doesnt answer at once, the application will give the right to execute new actions,
        ///  to a new thread and as soon as the WEB API begins to answer,
        ///  this method will once again recieve the highed priority to execute actions.
        ///  the instance webReq has to be translated to a WebResponse, which is the object that holds the connection to the WEB API.
        ///  The instance response has to be translated to a Stream which,
        ///  handles the data packages which are recieved via the HTTP protocol.
        ///  The instance of our Stream(responseStream) also uses await as there can't be transfered data to our content
        ///  of datatype MemoryStream before all packages have been received from the WEB API
        ///  because content is not completely build until all packages are recieved. This is why we use async,
        ///  so the program doesnt freeze trying to deliver content to the gui, when not all data has been recieved.
        ///  When all packages are recieved we convert them to a MemoryStream.
        ///  Now we have to ensure that the text we recieve as answer is readable by our application.
        ///  Therefore we make an encoding to UTF8 which ensures all nordical characters are recognized and showable.
        ///  Now we have a dataset which can be be converted to our own simple datatype classCityWeather via JsonConvert,
        ///  here we imply which class we want to convert to and a indication of the source to the data which
        ///  have to be implemented in the datatype.
        ///  Then we return an instance of ClassCityWeather which now contains all the data we have recieved from the Web API.
        /// </summary>
        /// <returns>Task<ClassCurrency></returns>
        public async Task <ClassCurrency> GetURLContentsAsync()
        {
            ClassCurrency CC      = new ClassCurrency();
            var           content = new MemoryStream();
            var           webReq  = (HttpWebRequest)WebRequest.Create($"https://openexchangerates.org/api/latest.json?app_id=02ce56841b244b9ebd18d47a7d8c40e7");

            using (WebResponse response = await webReq.GetResponseAsync())
            {
                using (Stream responseStream = response.GetResponseStream())
                {
                    await responseStream.CopyToAsync(content);
                }
            }

            string strRes = System.Text.Encoding.UTF8.GetString(content.ToArray()); // content is byte, if we make them into an array we can use encoding to make a readable string

            CC = JsonConvert.DeserializeObject <ClassCurrency>(strRes);             // JsonConvert class has a method called Deserialze object,
            // the method needs an indication of the object it needs to build(ClassCityWeather)
            // and a parameter which here is a string that contains the data recieved fromt the api as a string in Json format
            return(CC);
        }