Ejemplo n.º 1
0
        /// <summary>
        /// When the local directory is updated with .csv files, we are using the date in the filename, to find newest edition with sort.
        /// </summary>
        public void ImportNewestFile()
        {
            ServerAccessLayer.DownloadFiles();
            List <DateTime> fileDate = new List <DateTime>();

            string localDirectory = Directory.GetCurrentDirectory() + @"\DownloadedCSVFiles\";

            string[] fileArray = Directory.GetFiles(localDirectory, "*.csv");

            foreach (var file in fileArray)
            {
                fileDate.Add(DateTime.ParseExact(file.Substring(file.Length - 12, 8), "ddMMyyyy", CultureInfo.InvariantCulture));
            }
            fileDate.Sort();
            NewFile = "ApEngros_PriCat_" + fileDate[fileDate.Count - 1].ToString("ddMMyyyy");
        }
Ejemplo n.º 2
0
        public async void CreateCSV()
        {
            while (true)
            {
                List <Agreement> agreements = new List <Agreement>();
                agreements = DataAccessLayer.CreateAgreementList();  //Hemter liste af aggreements fra db.

                List <Product> linesFromDB = new List <Product>();
                string         header      = "CompanyID;InterchangeId;ProductID;ProductName1;ProductName2;ItemUnit;ProductDesreptionLong;Synonyms;ProductGroup;Weight;MinQuantity;Price;Discount;NetPrice;Pcode;DistCode;";

                foreach (Agreement agree in agreements)
                {
                    linesFromDB = DataAccessLayer.CreateList(agree.ProductGroup);       //Henter liste af produkter fra DB, ved hjælp af ProductGroup fra agreements.
                    char pad = '0';

                    string custID         = Convert.ToString(agree.CustomerID).PadLeft(5, pad);
                    string localDirectory = Directory.GetCurrentDirectory() + @"\CSVFilesToUpload\";

                    Directory.CreateDirectory(localDirectory);

                    //string filePath = @"C:\Test\";
                    string fileName = "ApEngros_" + custID + "_" + DateTime.Now.ToString("ddMMyyyy") + ".txt";
                    bool   exists   = File.Exists(localDirectory + fileName);

                    using (StreamWriter write = new StreamWriter(localDirectory + fileName, true))
                    {
                        if (!exists)
                        {
                            write.WriteLine(header);
                        }

                        foreach (Product prod in linesFromDB)
                        {
                            write.Write(custID + ";" + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss") + ";" + prod.ProductID + ";" + prod.ProductName1 + ";" + prod.ProductName2 + ";" + prod.ItemUnit + ";" + prod.ProductDescription + ";" + prod.Synonyms + ";" +
                                        prod.ProductGroup + ";" + prod.Weight + ";" + prod.MinQuantity + ";" + prod.Price + ";" + prod.Discount + ";" + prod.NetPrice + ";" + prod.PCode + ";" + prod.DistCode + ";" + Environment.NewLine);
                        }
                    }
                }
                ServerAccessLayer.UploadFiles();
                await PutTaskDelay(7);
            }
        }