{"id":229419,"date":"2021-11-06T10:32:31","date_gmt":"2021-11-06T02:32:31","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=229419"},"modified":"2021-10-30T13:33:56","modified_gmt":"2021-10-30T05:33:56","slug":"farm-linux-control","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/farm-linux-control.html","title":{"rendered":"\u6559\u4f60\u5982\u4f55\u5b9e\u73b0c#\u6587\u4ef6\u4e0a\u4f20\u4e0b\u8f7d\u529f\u80fd"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u7b80\u5355\u4ecb\u7ecd\u4e00\u4e0bc#\u6587\u4ef6\u4e0a\u4f20\u4e0b\u8f7d\u529f\u80fd\u5b9e\u73b0\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
NuGet \u5b89\u88c5SqlSugar<\/strong><\/div>\n

Model\u6587\u4ef6\u4e0b\u65b0\u5efa DbContext \u7c7b<\/p>\n

public class DbContext \r\n{\r\n\tpublic DbContext() \r\n\t{\r\n\t\tDb = new SqlSugarClient(new ConnectionConfig() \r\n\t\t{\r\n\t\t\tConnectionString = \"server=localhost;uid=root;pwd=woshishui;database=test\",\r\n\t\t\t                DbType = DbType.MySql,\r\n\t\t\t                InitKeyType = InitKeyType.Attribute,\/\/\u4ece\u7279\u6027\u8bfb\u53d6\u4e3b\u952e\u548c\u81ea\u589e\u5217\u4fe1\u606f\r\n\t\t\tIsAutoCloseConnection = true,\/\/\u5f00\u542f\u81ea\u52a8\u91ca\u653e\u6a21\u5f0f\u548cEF\u539f\u7406\u4e00\u6837\u6211\u5c31\u4e0d\u591a\u89e3\u91ca\u4e86\r\n\t\t\t});\r\n\t\t\t\/\/\u8c03\u5f0f\u4ee3\u7801 \u7528\u6765\u6253\u5370SQL \r\n\t\t\tDb.Aop.OnLogExecuting = (sql, pars) =>\r\n\t\t\t            {\r\n\t\t\t                Console.WriteLine(sql + \"rn\" +\r\n                                  Db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));\r\n                Console.WriteLine();\r\n            };\r\n        }\r\n        \/\/\u6ce8\u610f\uff1a\u4e0d\u80fd\u5199\u6210\u9759\u6001\u7684\uff0c\u4e0d\u80fd\u5199\u6210\u9759\u6001\u7684\r\n        public SqlSugarClient Db;\/\/\u7528\u6765\u5904\u7406\u4e8b\u52a1\u591a\u8868\u67e5\u8be2\u548c\u590d\u6742\u7684\u64cd\u4f5c\r\n        public SimpleClient uploadingdb { get { return new SimpleClient<\/uploading>(Db); } }\/\/\u7528\u6765\u5904\u7406Student\u8868\u7684\u5e38\u7528\u64cd\u4f5c\r\n    }<\/uploading><\/pre>\n

uploading\u5b9e\u4f53\u7c7b<\/p>\n

[SugarTable(\"uploading\")]\r\n   public class uploading\r\n    {\r\n        \/\/\u6307\u5b9a\u4e3b\u952e\u548c\u81ea\u589e\u5217\uff0c\u5f53\u7136\u6570\u636e\u5e93\u4e2d\u4e5f\u8981\u8bbe\u7f6e\u4e3b\u952e\u548c\u81ea\u589e\u5217\u624d\u4f1a\u6709\u6548\r\n        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]\r\n        public int id { get; set; }\r\n        public string name { get; set; }\r\n        public string path { get; set; }\r\n    }<\/pre>\n
UploadingManager<\/strong><\/div>\n
class UploadingManager : DbContext\r\n    {\r\n        public List Query()\r\n        {\r\n            try\r\n            {\r\n                List<\/uploading> data = Db.Queryable<\/uploading>()\r\n                    .Select(f => new uploading\r\n                    {\r\n                        name = f.name,\r\n                        path = f.path\r\n                    })\r\n                    .ToList();\r\n                return data;\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                Console.WriteLine(e);\r\n                throw;\r\n            }\r\n        }\r\n\r\n        public List GetName(string name)\r\n        {\r\n            List<\/string> data = Db.Queryable()\r\n                .Where(w=>w.name== name)\r\n                .Select(f => f.path)\r\n                .ToList();\r\n            return data;\r\n        }\r\n    }<\/uploading><\/string><\/uploading><\/pre>\n
\u7a97\u4f53\u52a0\u8f7d<\/strong><\/div>\n

\u8bfb\u53d6\u5230\u6570\u636e\u5e93\u5b57\u6bb5name\u5e76\u8d4b\u503c<\/p>\n

private void Form1_Load(object sender, EventArgs e)\r\n        {\r\n            List data = uploading.Query();\r\n            foreach (var data1 in data)\r\n            {\r\n                comboBox1.Items.Add(data1.name);\r\n            }\r\n            comboBox1.SelectedIndex = 0;\r\n\r\n        }<\/uploading><\/pre>\n
comboBox\u4e8b\u4ef6\u89e6\u53d1\u6761\u4ef6\u67e5\u8be2\u5230\u4e0a\u4f20\u7684path<\/strong><\/div>\n
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)\r\n        {\r\n            List data = uploading.GetName(comboBox1.Text);\r\n\r\n            for (int i = 0; i < data.Count; i++)\r\n            {\r\n                textBox1.Text = data[0];\r\n            }\r\n        }<\/string><\/pre>\n
\u4e0a\u4f20\u4e8b\u4ef6\u89e6\u53d1<\/strong><\/div>\n
private void Button1_Click(object sender, EventArgs e)\r\n        {\r\n             string path = textBox1.Text;\r\n            CopyDirs(textBox3.Text,\r\n                path);\r\n        }<\/pre>\n

.<\/p>\n

private void CopyDirs(string srcPath, string aimPath)\r\n        {\r\n            try\r\n            {\r\n                \/\/ \u68c0\u67e5\u76ee\u6807\u76ee\u5f55\u662f\u5426\u4ee5\u76ee\u5f55\u5206\u5272\u5b57\u7b26\u7ed3\u675f\u5982\u679c\u4e0d\u662f\u5219\u6dfb\u52a0\r\n                if (aimPath[aimPath.Length - 1] != System.IO.Path.DirectorySeparatorChar)\r\n                {\r\n                    aimPath += System.IO.Path.DirectorySeparatorChar;\r\n                }\r\n                \/\/ \u5224\u65ad\u76ee\u6807\u76ee\u5f55\u662f\u5426\u5b58\u5728\u5982\u679c\u4e0d\u5b58\u5728\u5219\u65b0\u5efa\r\n                if (!System.IO.Directory.Exists(aimPath))\r\n                {\r\n                    System.IO.Directory.CreateDirectory(aimPath);\r\n                }\r\n                \/\/ \u5f97\u5230\u6e90\u76ee\u5f55\u7684\u6587\u4ef6\u5217\u8868\uff0c\u8be5\u91cc\u9762\u662f\u5305\u542b\u6587\u4ef6\u4ee5\u53ca\u76ee\u5f55\u8def\u5f84\u7684\u4e00\u4e2a\u6570\u7ec4\r\n                \/\/ \u5982\u679c\u4f60\u6307\u5411copy\u76ee\u6807\u6587\u4ef6\u4e0b\u9762\u7684\u6587\u4ef6\u800c\u4e0d\u5305\u542b\u76ee\u5f55\u8bf7\u4f7f\u7528\u4e0b\u9762\u7684\u65b9\u6cd5\r\n                \/\/ string[] fileList = Directory.GetFiles\uff08srcPath\uff09\uff1b\r\n                string[] fileList = System.IO.Directory.GetFileSystemEntries(srcPath);\r\n                \/\/ \u904d\u5386\u6240\u6709\u7684\u6587\u4ef6\u548c\u76ee\u5f55\r\n                foreach (string file in fileList)\r\n                {\r\n                    \/\/ \u5148\u5f53\u4f5c\u76ee\u5f55\u5904\u7406\u5982\u679c\u5b58\u5728\u8fd9\u4e2a\u76ee\u5f55\u5c31\u9012\u5f52Copy\u8be5\u76ee\u5f55\u4e0b\u9762\u7684\u6587\u4ef6\r\n                    if (System.IO.Directory.Exists(file))\r\n                    {\r\n                        CopyDir(file, aimPath + System.IO.Path.GetFileName(file));\r\n                        DisplaylistboxMsg(\"\u4e0a\u4f20\u6210\u529f\");\r\n                    }\r\n                    \/\/ \u5426\u5219\u76f4\u63a5Copy\u6587\u4ef6\r\n                    else\r\n                    {\r\n                        System.IO.File.Copy(file, aimPath + System.IO.Path.GetFileName(file), true);\r\n                        DisplaylistboxMsg(\"\u4e0a\u4f20\u6210\u529f\");\r\n                    }\r\n                }\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                DisplaylistboxMsg(\"\u4e0a\u4f20\u5931\u8d25\" + e.Message);\r\n            }\r\n        }<\/pre>\n
\u4e0b\u8f7d\u4e8b\u4ef6\u89e6\u53d1<\/strong><\/div>\n
private void Button2_Click(object sender, EventArgs e)\r\n        {\r\n            CopyDir(@\"\\\\10.55.2.3\\mech_production_line_sharing\\Test\\\" + textBox2.Text, textBox4.Text);\r\n        }\r\n\r\nprivate void CopyDir(string srcPath, string aimPath)\r\n        {\r\n            \/\/ \u68c0\u67e5\u76ee\u6807\u76ee\u5f55\u662f\u5426\u4ee5\u76ee\u5f55\u5206\u5272\u5b57\u7b26\u7ed3\u675f\u5982\u679c\u4e0d\u662f\u5219\u6dfb\u52a0\r\n            if (aimPath[aimPath.Length - 1] != System.IO.Path.DirectorySeparatorChar)\r\n            {\r\n                aimPath += System.IO.Path.DirectorySeparatorChar;\r\n            }\r\n\r\n            \/\/ \u5224\u65ad\u76ee\u6807\u76ee\u5f55\u662f\u5426\u5b58\u5728\u5982\u679c\u4e0d\u5b58\u5728\u5219\u65b0\u5efa\r\n            if (!System.IO.Directory.Exists(aimPath))\r\n            {\r\n                System.IO.Directory.CreateDirectory(aimPath);\r\n            }\r\n\r\n            \/\/ \u5f97\u5230\u6e90\u76ee\u5f55\u7684\u6587\u4ef6\u5217\u8868\uff0c\u8be5\u91cc\u9762\u662f\u5305\u542b\u6587\u4ef6\u4ee5\u53ca\u76ee\u5f55\u8def\u5f84\u7684\u4e00\u4e2a\u6570\u7ec4\r\n            \/\/ \u5982\u679c\u4f60\u6307\u5411copy\u76ee\u6807\u6587\u4ef6\u4e0b\u9762\u7684\u6587\u4ef6\u800c\u4e0d\u5305\u542b\u76ee\u5f55\u8bf7\u4f7f\u7528\u4e0b\u9762\u7684\u65b9\u6cd5\r\n            \/\/ string[] fileList = Directory.GetFiles\uff08srcPath\uff09\uff1b\r\n            string[] fileList = System.IO.Directory.GetFileSystemEntries(srcPath);\r\n            \/\/ \u904d\u5386\u6240\u6709\u7684\u6587\u4ef6\u548c\u76ee\u5f55\r\n            foreach (string file in fileList)\r\n            {\r\n                \/\/ \u5148\u5f53\u4f5c\u76ee\u5f55\u5904\u7406\u5982\u679c\u5b58\u5728\u8fd9\u4e2a\u76ee\u5f55\u5c31\u9012\u5f52Copy\u8be5\u76ee\u5f55\u4e0b\u9762\u7684\u6587\u4ef6\r\n                if (System.IO.Directory.Exists(file))\r\n                {\r\n                    CopyDir(file, aimPath + System.IO.Path.GetFileName(file));\r\n                    DisplaylistboxMsg(\"\u4e0b\u8f7d\u6210\u529f\");\r\n                }\r\n                \/\/ \u5426\u5219\u76f4\u63a5Copy\u6587\u4ef6\r\n                else\r\n                {\r\n                    System.IO.File.Copy(file, aimPath + System.IO.Path.GetFileName(file), true);\r\n                    DisplaylistboxMsg(\"\u4e0b\u8f7d\u6210\u529f\");\r\n                }\r\n            }\r\n        }<\/pre>\n","protected":false},"excerpt":{"rendered":"

Model\u6587\u4ef6\u4e0b\u65b0\u5efa DbContext \u7c7b public class DbContext { public […]<\/p>\n","protected":false},"author":1482,"featured_media":229221,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-229419","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/229419","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1482"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=229419"}],"version-history":[{"count":7,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/229419\/revisions"}],"predecessor-version":[{"id":229426,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/229419\/revisions\/229426"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/229221"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=229419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=229419"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=229419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}