/// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public string GetFilesCount()
 {
     if (!string.IsNullOrEmpty(RootPath))
     {
         DirectoryInfo[] fldrs = di.GetDirectories("*.*");
         filesString = "";
         for (int i = fldrs.Length; i > 0; i--)
         {
             DirectoryInfo d = fldrs[i - 1];
             if (Finance_Tools.IsAddedToGallery(d))
             {
                 try
                 {
                     FileInfo[] myfile = d.GetFiles();
                     for (int j = myfile.Length; j > 0; j--)
                     {
                         FileInfo f = myfile[j - 1];
                         if (f.Extension == ".xls" || f.Extension == ".xlsx" || f.Extension == ".xlsm" || f.Extension == ".pdf")
                         {
                             string fileName = Path.GetFileNameWithoutExtension(f.Name);
                             if (!fileName.Contains("~"))
                             {
                                 filesString += fileName;
                             }
                         }
                     }
                 }
                 catch
                 { }
             }
         }
     }
     return(filesString);
 }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        private void initializeFolder()
        {
            var           path = Finance_Tools.RootPath;
            DirectoryInfo di   = new DirectoryInfo(path);

            DirectoryInfo[] fldrs = di.GetDirectories("*.*");
            foreach (DirectoryInfo d in fldrs)
            {
                if (Finance_Tools.IsAddedToGallery(d))
                {
                    cbFolders.Items.Add(new KeyValuePair <string, string>(d.Name, d.FullName));
                }
            }
            cbFolders.DisplayMember = "Key";
            cbFolders.ValueMember   = "Value";
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="cmd"></param>
        private void ImportTemplatesIntoDB(SqlConnection conn, SqlCommand cmd)
        {
            var path = string.Empty;

            getTemplateFolder(ref path);
            if (!string.IsNullOrEmpty(path))
            {
                try
                {
                    DirectoryInfo   di    = new DirectoryInfo(path);
                    DirectoryInfo[] fldrs = di.GetDirectories("*.*");
                    if (Finance_Tools.IsAddedToGallery(di))
                    {
                        try
                        {
                            FileInfo[] myfile = di.GetFiles();
                            foreach (FileInfo f in myfile)
                            {
                                int index = this.dataGridView1.Rows.Add();
                                Log("Importing " + f.Name + "...", index, "", "");
                                DirectoryInfo dir = new DirectoryInfo(di.FullName);
                                if (f.Extension == ".xls" || f.Extension == ".xlsx" || f.Extension == ".xlsm" || f.Extension == ".pdf")
                                {
                                    string Description = string.Empty;
                                    try
                                    {
                                        ShellLib.ShellLibClass sl = new ShellLib.ShellLibClass();
                                        Description = sl.getFileDetail(di.FullName, f.Name);
                                    }
                                    catch { }
                                    InsertIntoDB(f, Description, index, conn, cmd);
                                }
                                else
                                {
                                    Log("Importing " + f.Name + "...", index, "Fail!", "File format is not correct!File format must be xls , xlsx , xlsm or pdf ");
                                }
                            }
                        }
                        catch (Exception ex)
                        { MessageBox.Show(ex.Message, "Message - RSystems FinanceTools", MessageBoxButtons.OK, MessageBoxIcon.Information); }
                    }
                    foreach (DirectoryInfo d in fldrs)
                    {
                        if (Finance_Tools.IsAddedToGallery(d))
                        {
                            try
                            {
                                FileInfo[] myfile = d.GetFiles();
                                foreach (FileInfo f in myfile)
                                {
                                    int index = this.dataGridView1.Rows.Add();
                                    Log("Importing " + f.Name + "...", index, "", "");
                                    DirectoryInfo dir = new DirectoryInfo(d.FullName);
                                    if (f.Extension == ".xls" || f.Extension == ".xlsx" || f.Extension == ".xlsm" || f.Extension == ".pdf")
                                    {
                                        string Description = string.Empty;
                                        try
                                        {
                                            ShellLib.ShellLibClass sl = new ShellLib.ShellLibClass();
                                            Description = sl.getFileDetail(d.FullName, f.Name);
                                        }
                                        catch { }
                                        InsertIntoDB(f, Description, index, conn, cmd);
                                    }
                                    else
                                    {
                                        Log("Importing " + f.Name + "...", index, "Fail!", "File format is not correct!File format must be xls , xlsx , xlsm or pdf ");
                                    }
                                }
                            }
                            catch (Exception ex)
                            { MessageBox.Show(ex.Message, "Message - RSystems FinanceTools", MessageBoxButtons.OK, MessageBoxIcon.Information); }
                        }
                    }
                }
                catch (Exception ex)
                { MessageBox.Show(ex.Message, "Message - RSystems FinanceTools", MessageBoxButtons.OK, MessageBoxIcon.Information); }
            }
        }
 /// <summary>
 /// Initialize File Structure when initia folder path or file number changes
 /// </summary>
 public void InitializeFileXMLStructure()
 {
     if (!string.IsNullOrEmpty(RootPath))
     {
         string[] sArray = Finance_Tools.FileIds.Split(new char[3] {
             ',', ',', ','
         });
         DirectoryInfo[] fldrs = di.GetDirectories("*.*");
         XmlDocument     xdoc  = new XmlDocument();
         xdoc.Load(Finance_Tools.FolderFileXMLPath + Finance_Tools.simpleID + ".xml");
         XmlNode Nodes = xdoc.SelectSingleNode("Nodes");
         Nodes.RemoveAll();
         filesString = "";
         for (int i = fldrs.Length; i > 0; i--)
         {
             DirectoryInfo d = fldrs[i - 1];
             if (Finance_Tools.IsAddedToGallery(d))
             {
                 try
                 {                                                         //add folder nodes
                     XmlElement xmlElement = xdoc.CreateElement("Folder"); //add attributes
                     xmlElement.SetAttribute("Name", d.Name);              //The node is added to the specified node
                     XmlNode    xml    = Nodes.PrependChild(xmlElement);
                     FileInfo[] myfile = d.GetFiles();
                     for (int j = myfile.Length; j > 0; j--)
                     {
                         FileInfo f = myfile[j - 1];
                         if (f.Extension == ".xls" || f.Extension == ".xlsx" || f.Extension == ".xlsm" || f.Extension == ".pdf")
                         {
                             string fileName = Path.GetFileNameWithoutExtension(f.Name);
                             //using ShellLib project(framework2.0) for current project(framework3.5),because framework3.5 cannot using SHELL32(X64) directly.
                             string fileDesc = string.Empty;
                             try
                             {
                                 ShellLib.ShellLibClass sl = new ShellLib.ShellLibClass();
                                 fileDesc = sl.getFileDetail(d.FullName, f.Name);
                             }
                             catch { }//add folder nodes
                             XmlElement xmlElementSub = xdoc.CreateElement("File");//add attributes
                             xmlElementSub.SetAttribute("Name", fileName);
                             xmlElementSub.SetAttribute("Description", fileDesc);
                             for (int x = 0; x < sArray.Length; x++)
                             {
                                 if (!string.IsNullOrEmpty(sArray[x]) && sArray[x].ToLower().Contains(f.FullName.ToLower()))
                                 {
                                     xmlElementSub.SetAttribute("ID", sArray[x].Substring(sArray[x].LastIndexOf("-") + 1));
                                 }
                             }//The node is added to the specified node
                             xml.PrependChild(xmlElementSub);
                             if (!fileName.Contains("~"))
                             {
                                 filesString += fileName;
                             }
                         }
                     }
                 }
                 catch { }
             }
         }
         xdoc.Save(Finance_Tools.FolderFileXMLPath + Finance_Tools.simpleID + ".xml");
         Finance_Tools.TemplateCount = filesString;
     }
 }