Ejemplo n.º 1
0
        internal static void PrivateDownload(Documents doc)
        {
            try
            {
                string order = Storage.datasetKlient.Tables["ClientInfo"].Rows[0][6].ToString();
                GetInfoCorrectDownloadFolder();

                using (WebClient clientPDF = new WebClient())
                {
                    clientPDF.Credentials = new
                                            NetworkCredential(nameFTP, passwordFTP);
                    string ftpPath = pathFTP + "/" + order + "/" + "|" + doc.Name;
                    clientPDF.DownloadFile(ftpPath, downFolderName + doc.Name + ".PDF");

                    string exePath    = Directory.GetCurrentDirectory();
                    string openFolder = exePath + "Downloads";
                }
                Process.Start(@"Downloads");
            }
            catch (NullReferenceException)
            {
                // Срабатывает когда пользователь нажал не на ячейку с именем файла а пустое пространство
            }
            catch (Exception ex)
            {
                BOX.ShowError(ex.Message, ex.Source);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Получает ДЕЙСТВУЮЩУЮ цену на бумагу по отправленному ISIN и записывает в Storage.CurrentQuoteAll
 /// </summary>
 /// <param name="currentISIN"></param>
 internal static void StorageISINandQuoteSave(List <string> currentISIN)
 {
     try
     {
         int cells = -1;
         using (var reader = XmlReader.Create("http://castle-privatesolutions.sg/assets/quotes/book1.xml"))
         {
             while (reader.ReadToFollowing("Data"))
             {
                 if (reader.GetAttribute("Type", "urn:schemas-microsoft-com:office:spreadsheet") == "Number")
                 {
                     cells++;
                     if (cells % 2 == 0)
                     {
                         Qoute = reader.ReadElementContentAsDecimal();
                     }
                     if (cells % 2 != 0)
                     {
                         ISIN = reader.ReadElementContentAsString();
                         if (currentISIN.Contains(ISIN))
                         {
                             Storage.CurrentQuoteAll.Add(Qoute.ToString());
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         BOX.ShowError(ex.Message, ex.Source);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Получает ДЕЙСТВУЮЩУЮ цену на бумагу по отправленному ISIN и записывает в Storage.CurrentQuoteAll
        /// </summary>
        /// <param name="currentISIN"></param>
        internal static void StorageISINandQuoteSave(List <string> currentISIN)
        {
            int           i          = 0;
            List <object> AllXMLMass = new List <object>();

            try
            {
                WebRequest request = WebRequest.Create(XMLFTPFILE);
                request.Credentials = new NetworkCredential(userftp, passftp);
                using (WebResponse responce = request.GetResponse())
                {
                    using (var reader = XmlReader.Create(responce.GetResponseStream()))
                    {
                        while (reader.ReadToFollowing("Data"))
                        {
                            if (reader.GetAttribute("Type", "urn:schemas-microsoft-com:office:spreadsheet") == "String" || reader.GetAttribute("Type", "urn:schemas-microsoft-com:office:spreadsheet") == "Number")
                            {
                                i++;
                                if (i > 4)
                                {
                                    AllXMLMass.Add(reader.ReadElementContentAsString());
                                }
                            }
                        }
                    }
                }
                AddQuoteintoStorageCurrentQuoteAll(AllXMLMass, currentISIN);
            }
            catch (ArgumentOutOfRangeException) { }
            catch (FormatException) { BOX.ShowInformation("Failed to get topical values from XML"); }
            catch (Exception ex)
            {
                BOX.ShowError(ex.Message, ex.Source);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Поиск названия фирмы и текущей акции по ISIN компании
        /// </summary>
        /// <param name="getisin">ISIN</param>
        /// <returns></returns>
        internal static string[] TitleQuoteByISIN(string getisin)
        {
            try
            {
                int      cells  = 1;
                string[] counts = { "", "" };
                using (var reader = XmlReader.Create("http://castle-privatesolutions.sg/assets/quotes/book1.xml"))
                {
                    while (reader.ReadToFollowing("Data"))
                    {
                        while (!isin.Contains(getisin))
                        {
                            if (reader.GetAttribute("Type", "urn:schemas-microsoft-com:office:spreadsheet") == "Number")
                            {
                                cells++;
                                if (cells % 2 != 0)
                                {
                                    isin.Add((reader.ReadElementContentAsString()));
                                }
                                if (cells % 2 == 0)
                                {
                                    quoe.Add((reader.ReadElementContentAsDecimal()));
                                }
                            }
                            else if (reader.GetAttribute("Type", "urn:schemas-microsoft-com:office:spreadsheet") == "String")
                            {
                                names.Add(reader.ReadElementContentAsString().ToString());
                            }
                            break;
                        }
                    }
                    if (isin.Contains(getisin))
                    {
                        int index = isin.IndexOf(getisin);
                        counts[0] = quoe[index].ToString("0.00", System.Globalization.CultureInfo.GetCultureInfo("ru-RU"));
                        counts[1] = names[index].ToString();
                        isin.Clear();
                        names.Clear();
                        quoe.Clear();
                        return(counts);
                    }
                }
            }

            catch (Exception ex)
            {
                BOX.ShowError(ex.Message, ex.Source);
            }
            string[] notFound = { "isin Not found", "isin Not found" };
            return(notFound);
        }
 /// <summary>
 /// Проверяет существует ли папка Downloads для загружаемых документов,
 /// создает если нет.
 /// </summary>
 private static void GetInfoCorrectDownloadFolder()
 {
     try
     {
         string        exePath = Directory.GetCurrentDirectory();
         DirectoryInfo folder  = new DirectoryInfo(exePath + "Downloads");
         if (!folder.Exists)
         {
             Directory.CreateDirectory(exePath + @"\Downloads");
         }
     }
     catch (Exception ex)
     {
         BOX.ShowError(ex.Message, ex.Source);
     }
 }
 /// <summary>
 /// Создает папку на сервере через FTP.
 /// </summary>
 /// <param name="URLpath"></param>
 /// <param name="Pass"></param>
 /// <param name="username"></param>
 /// <param name="folder_order">Название папки должно соответствовать номеру договора</param>
 internal static void FolderCreate(string URLpath, string Pass, string username, string folder_order)
 {
     try
     {
         string        fullPath = URLpath + "/" + folder_order;
         FtpWebRequest zapros   = (FtpWebRequest)WebRequest.Create(fullPath);
         zapros.Credentials = new NetworkCredential(username, Pass);
         zapros.Method      = WebRequestMethods.Ftp.MakeDirectory;
         FtpWebResponse resp = (FtpWebResponse)zapros.GetResponse();
         resp.Dispose();
     }
     catch (Exception ex)
     {
         BOX.ShowError(ex.Message, ex.Source);
     }
 }
Ejemplo n.º 7
0
 internal static void downloadPrivate(string order, string filename)
 {
     try
     {
         using (WebClient client = new WebClient())
         {
             client.Credentials = new NetworkCredential(nameFTP, passwordFTP);
             string path = pathFTP + "\\" + order + "\\" + "|" + filename;
             client.DownloadFile(path, downFolderName + filename);
             Process.Start(@"Downloads");
         }
     }
     catch (WebException) { }
     catch (Exception ex)
     {
         BOX.ShowError(ex.Message, ex.StackTrace);
     }
 }
        /// <summary>
        /// Возвращает список приватных документов по указанному номеру договора
        /// Возвращает список публичных документов если на вход подан null
        /// </summary>
        /// <param name="folder">Номер договора или null</param>
        /// <returns></returns>
        internal List <string> GetListFromFTP(string folder)
        {
            folder = (folder == null) ? folder :  FTPServer += "//" + folder;
            List <string> FTPFiles = new List <string>();
            FtpWebRequest request  = (FtpWebRequest)WebRequest.Create(FTPServer);

            request.Credentials = new NetworkCredential(UserName, Password);
            request.Method      = WebRequestMethods.Ftp.ListDirectoryDetails;
            using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
            {
                try
                {
                    Stream responseStream = response.GetResponseStream();
                    using (StreamReader reader = new StreamReader(responseStream))
                    {
                        if (reader.EndOfStream)
                        {
                            FTPFiles.Add
                                ("This guy don't have private folder. \r\nCreate immediately! ");
                            return(FTPFiles);
                        }
                        while (!reader.EndOfStream)
                        {
                            fileName = reader.ReadLine();
                            if (fileName.Contains("|"))
                            {
                                fileName = fileName.Substring(fileName.IndexOf('|') + 1);
                                FTPFiles.Add(fileName);
                            }
                        }
                        if (FTPFiles.Count == 0)
                        {
                            FTPFiles.Add("Folder is Empty");
                        }
                        return(FTPFiles);
                    }
                }
                catch (Exception ex)
                {
                    BOX.ShowError(ex.Message, ex.Source);
                    return(null);
                }
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Создает папку на сервере через FTP.
 /// </summary>
 /// <param name="URLpath"></param>
 /// <param name="Pass"></param>
 /// <param name="username"></param>
 /// <param name="folder_order">Название папки должно соответствовать номеру договора</param>
 internal static void FolderCreate(string URLpath, string Pass, string username, string folder_order)
 {
     try
     {
         string        fullPath = URLpath + "//" + folder_order;
         FtpWebRequest zapros   = (FtpWebRequest)WebRequest.Create(fullPath);
         zapros.Method      = WebRequestMethods.Ftp.MakeDirectory;
         zapros.Credentials = new NetworkCredential(username, Pass);
         zapros.KeepAlive   = false;
         using (FtpWebResponse otvet = (FtpWebResponse)zapros.GetResponse())
         {
             BOX.ShowInformation(otvet.StatusCode.ToString());
         }
     }
     catch (Exception ex)
     {
         BOX.ShowError(ex.Message, ex.Source);
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Возвращает список приватных документов по указанному номеру договора
        /// Возвращает список публичных документов если на вход подан null
        /// </summary>
        /// <param name="folder">Номер договора или null</param>
        /// <returns></returns>
        internal List <string> GetListFromFTP(string folder)
        {
            List <string> FTPFiles = new List <string>();
            FtpWebRequest request  = (FtpWebRequest)WebRequest.Create(folder);

            request.Credentials = new NetworkCredential(UserName, Password);
            request.Method      = WebRequestMethods.Ftp.ListDirectoryDetails;
            using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
            {
                try
                {
                    Stream responseStream = response.GetResponseStream();
                    using (StreamReader reader = new StreamReader(responseStream))
                    {
                        if (reader.EndOfStream)
                        {
                            FTPFiles.Add
                                ("Documents Folder is Empty ");
                            return(FTPFiles);
                        }
                        while (!reader.EndOfStream)
                        {
                            fileName = reader.ReadLine();
                            if (fileName.Contains("|"))
                            {
                                fileName = fileName.Substring(fileName.IndexOf('|'));
                                FTPFiles.Add(fileName);
                            }
                        }
                        return(FTPFiles);
                    }
                }
                catch (Exception ex)
                {
                    BOX.ShowError(ex.Message, ex.Source);
                    return(null);
                }
            }
        }