示例#1
0
        /// <summary>
        /// 向数据库插入单条数据
        /// </summary>
        /// <param name="connection">数据库连接标识符</param>
        /// <param name="folderinfo">要插入的字段信息</param>
        public void FolderInfoInser(SqlConnection connection, Folderinfo folderinfo)
        {
            Random r   = new Random(int.Parse(DateTime.Now.ToString("HHmmssfff")));
            int    num = r.Next(10000, 99999);//随机生成一个5位整数

            Console.WriteLine("num 的值是:" + num);
            string cmdconten = String.Format($"insert into FolderTable (netpath,folderName,ftid,CreateDate,ProjectName) values('{folderinfo.NetPath}','{folderinfo.FolderName}',{num},'{folderinfo.Createtime}','{folderinfo.ProjectName}')");

            using (SqlCommand insertcmd = new SqlCommand(cmdconten, connection))
            {
                int result = insertcmd.ExecuteNonQuery();
                Console.WriteLine("受影响行数" + result + "数据写入数据库成功");
            }
            connection.Close();
        }
示例#2
0
        /// <summary>
        /// 收集主文件夹目录下子文件夹的信息
        /// </summary>
        /// <param name="folderPath">要查询文件的路径</param>
        /// <returns>子文件夹名称列表</returns>
        public List <Folderinfo> CheckFolder(string folderPath)
        {
            List <Folderinfo> folderinfolist = new List <Folderinfo>();
            DirectoryInfo     directoryInfo  = new DirectoryInfo(folderPath);

            foreach (var folder in directoryInfo.GetDirectories())
            {
                Folderinfo folderinfo = new Folderinfo();
                folderinfo.FolderName = folder.Name;
                folderinfo.NetPath    = "10.12.2.19";
                folderinfo.Createtime = folder.CreationTime;
                folderinfolist.Add(folderinfo);
                Console.WriteLine("当前文件夹下的子文件夹:{0}", folder.FullName);
                Console.WriteLine(folder.CreationTime);
            }
            return(folderinfolist);
        }
示例#3
0
        /// <summary>
        /// 创建文件夹的方法
        /// </summary>
        /// <param name="path">路径地址 如E:\</param>
        /// <param name="proName">文件夹名称</param>
        public Folderinfo CreateAction(string path, string proName, string localfolderName)
        {
            Folderinfo folderinfo = new Folderinfo();

            folderinfo.FolderName  = localfolderName;
            folderinfo.ProjectName = proName;
            folderinfo.NetPath     = "10.12.2.19";               //插入数据库的IP
            folderinfo.Createtime  = DateTime.Now.ToLocalTime(); //获取当前时间
            string pathStr = Path.Combine(path, localfolderName);

            Console.WriteLine(pathStr);
            try
            {
                Directory.CreateDirectory(pathStr);
                Console.WriteLine($"文件创建成功:{pathStr}");
            }
            catch (IOException ioe)
            {
                Console.WriteLine($"文件创建失败,返回的异常是:\n{ioe.Message}");
            }
            return(folderinfo);
        }