├── .gitignore ├── CommonLib ├── .gitignore ├── IZhy │ ├── ConsoleTest │ │ ├── ConsoleTest.csproj │ │ ├── DbTestEntity.cs │ │ └── Program.cs │ ├── IZhy.Common │ │ ├── AopProxy │ │ │ ├── GeneralDecorator.cs │ │ │ └── IgnoreDecoratorAttribute.cs │ │ ├── BasicTools │ │ │ ├── CommonConfigTool.cs │ │ │ ├── EncodingTool.cs │ │ │ ├── GcProcessor.cs │ │ │ ├── JsonTool.cs │ │ │ └── LogsTool.cs │ │ ├── CommonConfig │ │ │ ├── CommonConfig.json │ │ │ └── DbConnInfo.json │ │ ├── Const │ │ │ ├── AppsettingsJsonFieldsConst.cs │ │ │ ├── CommonConfigFieldsConst.cs │ │ │ ├── FileNameConst.cs │ │ │ └── FolderNameConst.cs │ │ ├── DbTools │ │ │ ├── DbConnFactory.cs │ │ │ ├── DbOperToolDecorator.cs │ │ │ ├── DbOperationTool.cs │ │ │ ├── IDbOperation.cs │ │ │ ├── InvokeDbOperTool.cs │ │ │ └── SqlStringExtension.cs │ │ ├── IZhy.Common.csproj │ │ ├── Redis │ │ │ └── RedisTool.cs │ │ ├── SimpleTools │ │ │ ├── ArrayTool.cs │ │ │ ├── AutoActionControl.cs │ │ │ ├── DateTimeTool.cs │ │ │ ├── ExcelTool.cs │ │ │ ├── FilesTool.cs │ │ │ ├── JavaScriptUtil.cs │ │ │ ├── RandomNumTool.cs │ │ │ ├── StringEncryptionTool.cs │ │ │ ├── StringOperationTool.cs │ │ │ ├── TimedFixedTask.cs │ │ │ └── TimedIntervalTask.cs │ │ └── SysEntities │ │ │ ├── PagingDataEntity.cs │ │ │ └── ServiceResultEntity.cs │ └── IZhy.sln └── README.md ├── README.md ├── Word模板文件的替换并生成新的Word文件 └── WordTestDemo │ ├── WordFileDemo │ ├── App.config │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── SimpleFilesTool.cs │ ├── TestImages │ │ └── test.jpg │ ├── WordFileDemo.csproj │ ├── WordFiles │ │ └── Templates │ │ │ ├── 新模板1.docx │ │ │ └── 测试模板-0.docx │ ├── WordTool.cs │ └── packages.config │ └── WordTestDemo.sln ├── js-a标签下载文件 └── aTagDownloadFile.js ├── js异步等待毫秒数 └── waitMillisecond.js ├── js数据合并 └── mergeData.js ├── 录屏 └── ScreenRecording │ ├── ScreenRecording.sln │ └── ScreenRecording │ ├── App.config │ ├── Common │ ├── GcProcessor.cs │ └── TimedIntervalTask.cs │ ├── FormMain.Designer.cs │ ├── FormMain.cs │ ├── FormMain.resx │ ├── Program.cs │ ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ ├── Settings.settings │ └── app.manifest │ ├── Resources │ ├── Logo.ico │ ├── MouseLeftImg.ico │ ├── MousePointerImg.ico │ ├── MouseRightImg.ico │ └── MouseWheelImg.ico │ ├── ScreenRecording.csproj │ └── packages.config ├── 汉字笔顺图 ├── ChineseWords.gif.sln └── ChineseWords.gif │ ├── App.config │ ├── CheckInternetTool.cs │ ├── ChineseWords.gif.csproj │ ├── FormMain.Designer.cs │ ├── FormMain.cs │ ├── FormMain.resx │ ├── Program.cs │ ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings │ └── Resources │ ├── Logo.ico │ └── Logo.png ├── 自动爬行者工具 └── AutoCrawlerTool │ ├── AutoCrawlerTool.sln │ ├── AutoCrawlerTool │ ├── App.config │ ├── AutoCrawlerTool.csproj │ ├── Common │ │ ├── AutoActionControl.cs │ │ ├── CheckInternetTool.cs │ │ ├── FilesTool.cs │ │ └── JsonTool.cs │ ├── M3U8Video │ │ ├── VideoCollectorForm.Designer.cs │ │ ├── VideoCollectorForm.cs │ │ ├── VideoCollectorForm.resx │ │ ├── VideoCollectorParams.cs │ │ └── VideoCollectorTool.cs │ ├── MainForm.Designer.cs │ ├── MainForm.cs │ ├── MainForm.resx │ ├── Program.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings │ ├── logo │ │ ├── 暗影蜘蛛侠.ico │ │ └── 视频.ico │ └── packages.config │ └── BrowserCrawler │ ├── BrowserCrawler.csproj │ ├── ChromiumBrowser.cs │ └── OSHelper.cs ├── 节日倒计时 └── ChineseNewYear │ ├── ChineseNewYear.Countdown │ ├── App.config │ ├── ChineseNewYear.Countdown.csproj │ ├── Countdown.cs │ ├── DateTimeTool.cs │ ├── FilesTool.cs │ ├── FrmMain.cs │ ├── FrmMain.designer.cs │ ├── FrmMain.resx │ ├── FrmUpdateDate.cs │ ├── FrmUpdateDate.designer.cs │ ├── FrmUpdateDate.resx │ ├── Program.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings │ ├── logo.ico │ └── packages.config │ └── ChineseNewYear.sln └── 节点找出最短的路 └── ConsoleDemo ├── ConsoleDemo.sln ├── ConsoleDemo ├── ConsoleDemo.csproj ├── Node.cs ├── NodePath.cs └── Program.cs └── 节点示例图.jpg /CommonLib/IZhy/ConsoleTest/ConsoleTest.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /CommonLib/IZhy/ConsoleTest/DbTestEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace ConsoleTest 6 | { 7 | internal class DbTestEntity 8 | { 9 | public int? ID { get; set; } 10 | 11 | public string Name { get; set; } 12 | 13 | public string Sex { get; set; } 14 | 15 | public int? Age { get; set; } 16 | 17 | public string Remark { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /CommonLib/IZhy/ConsoleTest/Program.cs: -------------------------------------------------------------------------------- 1 | using IZhy.Common.BasicTools; 2 | using IZhy.Common.DbTools; 3 | using IZhy.Common.SysEntities; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace ConsoleTest 10 | { 11 | class Program 12 | { 13 | static void Main(string[] args) 14 | { 15 | Console.WriteLine($"Hello World!{Environment.NewLine}"); 16 | 17 | Console.WriteLine(Environment.CurrentDirectory); 18 | 19 | // 日志测试 20 | { 21 | //LogsTool.LogWritingExe = logInfo => 22 | //{ 23 | // Console.WriteLine($"日志写入时执行 | {DateTime.Now.ToString("HH:mm:ss.ffff")}"); 24 | // Console.WriteLine($"{JsonTool.ObjectToJson(logInfo, true)} | {DateTime.Now.ToString("HH:mm:ss.ffff")}"); 25 | //}; 26 | 27 | //LogsTool.ClearBeforeSpecifiedDaysLog = saveDays => 28 | //{ 29 | // Console.WriteLine($"清除指定天数前的日志 => 天数: {saveDays} | {DateTime.Now.ToString("HH:mm:ss.ffff")}"); 30 | //}; 31 | 32 | //for (int i = 0; i < 100; i++) 33 | //{ 34 | // Task.Factory.StartNew(num => 35 | // { 36 | // LogsTool.ConsoleLog($"日志测试 {num} | {DateTime.Now.ToString("HH:mm:ss.ffff")}"); 37 | // }, i + 1); 38 | 39 | // Task.Run(() => 40 | // { 41 | // LogsTool.ConsoleLog($"日志测试 {i} | {DateTime.Now.ToString("HH:mm:ss.ffff")}"); 42 | // }); 43 | //} 44 | } 45 | 46 | // 数据库操作测试 47 | { 48 | string sql = " sql ".SqlWhere(true); 49 | sql += " test1 ".SqlWhere(false); 50 | sql += " test2 ".SqlWhere(true); 51 | Console.WriteLine(sql); 52 | 53 | //try 54 | //{ 55 | // using (var db = InvokeDbOperTool.DbOperTool()) 56 | // { 57 | // StringBuilder sql = new StringBuilder(); 58 | // sql.AppendLine("SELECT * FROM test WHERE `Name` LIKE '%1';"); 59 | // sql.AppendLine("SELECT * FROM test WHERE Sex = '女';"); 60 | // sql.AppendLine("SELECT * FROM test WHERE Age > 23;"); 61 | 62 | // var dbConnInfo = db.GetConnStringInfo(); 63 | // Console.WriteLine(JsonTool.ObjectToJson(dbConnInfo, true)); 64 | 65 | // Console.WriteLine(); 66 | 67 | // var data = db.QueryMultiple(sql.ToString()); 68 | // Console.WriteLine(JsonTool.ObjectToJson(data, true)); 69 | // } 70 | //} 71 | //catch (Exception ex) 72 | //{ 73 | // Console.WriteLine(ex.Message); 74 | //} 75 | 76 | //try 77 | //{ 78 | // sql = $" SELECT * FROM test " 79 | // + $" WHERE `Name` LIKE @Name " 80 | // + $" AND Sex = @Sex ".SqlWhere(true); 81 | 82 | // using (var db = InvokeDbOperTool.DbOperTool()) 83 | // { 84 | // var res = db.QueryBySql(sql, new { Name = "%1", Sex = "女" }); 85 | // Console.WriteLine(JsonTool.ObjectToJson(res, true)); 86 | // } 87 | //} 88 | //catch (Exception ex) 89 | //{ 90 | // Console.WriteLine(ex.Message); 91 | //} 92 | 93 | //try 94 | //{ 95 | // sql = "CALL p_test_user_info( @userName );"; 96 | 97 | // using (var db = InvokeDbOperTool.DbOperTool()) 98 | // { 99 | // Console.WriteLine(db.ToString()); 100 | 101 | // var res = db.QueryBySql(sql, new { userName = "李." }); 102 | // Console.WriteLine(JsonTool.ObjectToJson(res, true)); 103 | 104 | // Console.WriteLine(); 105 | 106 | // res = db.QueryProcedure("p_test_user_info", new { userName = "李" }); 107 | // Console.WriteLine(JsonTool.ObjectToJson(res, true)); 108 | // } 109 | //} 110 | //catch (Exception ex) 111 | //{ 112 | // Console.WriteLine(ex.Message); 113 | //} 114 | } 115 | 116 | 117 | Console.WriteLine(); 118 | Console.ReadKey(); 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /CommonLib/IZhy/IZhy.Common/AopProxy/IgnoreDecoratorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IZhy.Common.AopProxy 4 | { 5 | /// 6 | /// 忽略 装饰者 特性类 ( 只作用于方法 ) 7 | /// 8 | [AttributeUsage(AttributeTargets.Method)] 9 | public sealed class IgnoreDecoratorAttribute : Attribute { } 10 | } 11 | -------------------------------------------------------------------------------- /CommonLib/IZhy/IZhy.Common/BasicTools/CommonConfigTool.cs: -------------------------------------------------------------------------------- 1 | using IZhy.Common.Const; 2 | using IZhy.Common.SimpleTools; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | 7 | namespace IZhy.Common.BasicTools 8 | { 9 | /// 10 | /// 公共配置文件 读取工具类 11 | /// 12 | public static class CommonConfigTool 13 | { 14 | /// 15 | /// 配置文件路径 16 | /// 17 | private static readonly string _configPath = $"{FilesTool.ProgramRootDirectoryCommonConfig}{FileNameConst.CommonConfigJson}"; 18 | 19 | /// 20 | /// 用来存放 CommonConfig.json 配置文件 的 最后修改时间 21 | /// 22 | public static DateTime CommonConfigLastChangeTime { get; private set; } 23 | 24 | /// 25 | /// 获取一个 bool 值,表示 CommonConfig.json 配置文件 是否已被重新修改;true/false 是/否 26 | /// 27 | public static bool IsChangeConfigFile() 28 | { 29 | if (!File.Exists(_configPath)) 30 | { 31 | throw new Exception($"【CommonConfigTool】 数据库连接信息的配置文件不存在,请检查 => [ {_configPath} ]"); 32 | } 33 | 34 | try 35 | { 36 | FileInfo fileInfo = new FileInfo(_configPath); 37 | if (fileInfo.LastWriteTime != CommonConfigLastChangeTime) 38 | { 39 | CommonConfigLastChangeTime = fileInfo.LastWriteTime; 40 | return true; 41 | } 42 | } 43 | catch (Exception ex) 44 | { 45 | LogsTool.WriteEXLog("【CommonConfigTool】 获取一个 bool 值,表示 CommonConfig.json 配置文件 是否已被重新修改,发生异常", ex.ToString()); 46 | return true; 47 | } 48 | return false; 49 | } 50 | 51 | 52 | private static Dictionary _allConfigKeyValues = new Dictionary(); 53 | 54 | /// 55 | /// 获取 CommonConfig.json 配置文件里的所有配置信息 56 | /// 57 | public static Dictionary AllConfigKeyValues() 58 | { 59 | try 60 | { 61 | if (_allConfigKeyValues == null || _allConfigKeyValues.Count < 1 || IsChangeConfigFile()) 62 | { 63 | _allConfigKeyValues = JsonTool.JsonFileToObject>(_configPath); 64 | } 65 | } 66 | catch (Exception ex) 67 | { 68 | LogsTool.WriteEXLog("【CommonConfigTool】 获取 CommonConfig.json 配置文件里的配置信息,发生异常", ex); 69 | _allConfigKeyValues = new Dictionary(); 70 | } 71 | return _allConfigKeyValues; 72 | } 73 | 74 | 75 | /// 76 | /// 根据键获取 CommonConfig.json 配置文件里的信息 77 | /// 78 | /// 79 | /// 80 | public static object GetConfig(string key) 81 | { 82 | Dictionary dic = AllConfigKeyValues(); 83 | if (dic.ContainsKey(key)) 84 | { 85 | return dic[key]; 86 | } 87 | return null; 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /CommonLib/IZhy/IZhy.Common/BasicTools/EncodingTool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace IZhy.Common.BasicTools 5 | { 6 | /// 7 | /// Encoding 工具类 8 | /// 9 | public static class EncodingTool 10 | { 11 | static EncodingTool() 12 | { 13 | Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); 14 | } 15 | 16 | /// 17 | /// Encoding 初始化 18 | /// 19 | public static void EncodingInit() { } 20 | 21 | /// 22 | /// 获取一个指定的字符编码 23 | /// 24 | /// 编码名称;例如 GBK 、 GB2312 25 | /// 26 | public static Encoding GetEncoding(string name) 27 | { 28 | try 29 | { 30 | return Encoding.GetEncoding(name); 31 | } 32 | catch (Exception) 33 | { 34 | return Encoding.Default; 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /CommonLib/IZhy/IZhy.Common/BasicTools/GcProcessor.cs: -------------------------------------------------------------------------------- 1 | using IZhy.Common.SimpleTools; 2 | using System; 3 | 4 | namespace IZhy.Common.BasicTools 5 | { 6 | /// 7 | /// GC 回收处理器 初始化类;用在程序启动处 8 | /// 9 | public static class GcProcessor 10 | { 11 | private static bool _isRunning = false; 12 | 13 | private static readonly object _lock = new object(); 14 | 15 | /// 16 | /// GC 回收器 初始化; 默认 每 100 秒 执行一次 GC.Collect(); 17 | /// 18 | /// 间隔时间,单位秒;默认 100 s 19 | public static void Init(int intervalTime = 100) 20 | { 21 | lock (_lock) 22 | { 23 | if (_isRunning) 24 | { 25 | return; 26 | } 27 | else 28 | { 29 | _isRunning = true; 30 | new TimedIntervalTask(() => 31 | { 32 | GC.Collect(); 33 | }, 1000 * intervalTime, false).Startup(); 34 | } 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /CommonLib/IZhy/IZhy.Common/CommonConfig/CommonConfig.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/A-Grass-Code/OpenDemo/3d73ac75a1df53019b888933c9243c5d24425970/CommonLib/IZhy/IZhy.Common/CommonConfig/CommonConfig.json -------------------------------------------------------------------------------- /CommonLib/IZhy/IZhy.Common/CommonConfig/DbConnInfo.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/A-Grass-Code/OpenDemo/3d73ac75a1df53019b888933c9243c5d24425970/CommonLib/IZhy/IZhy.Common/CommonConfig/DbConnInfo.json -------------------------------------------------------------------------------- /CommonLib/IZhy/IZhy.Common/Const/AppsettingsJsonFieldsConst.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IZhy.Common.Const 6 | { 7 | /// 8 | /// appsettings.json 文件里的 字段名 常量 抽象类 ( 提供继承支持 ) 9 | /// 10 | public abstract class AppsettingsJsonFieldsConst 11 | { 12 | /// 13 | /// 文件上传的根目录 14 | /// 15 | public const string FilesUploadRootDirectory = "FilesUploadRootDirectory"; 16 | 17 | /// 18 | /// 上传文件的大小限制 19 | /// 20 | public const string UploadFileSizeLimit = "UploadFileSizeLimit"; 21 | 22 | /// 23 | /// 文件服务的 URL 根地址 24 | /// 25 | public const string FilesServiceUrlRoot = "FilesServiceUrlRoot"; 26 | 27 | /// 28 | /// 是否启用数据库日志记录器 29 | /// 30 | public const string IsEnableDbLogRecorder = "IsEnableDbLogRecorder"; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /CommonLib/IZhy/IZhy.Common/Const/CommonConfigFieldsConst.cs: -------------------------------------------------------------------------------- 1 | namespace IZhy.Common.Const 2 | { 3 | /// 4 | /// CommonConfig.json 公共配置文件里的字段名 常量 抽象类 ( 提供继承支持 ) 5 | /// 6 | public abstract class CommonConfigFieldsConst 7 | { 8 | /// 9 | /// 日志记录保存的天数 10 | /// 11 | public const string LogSaveDays = "LogSaveDays"; 12 | 13 | /// 14 | /// 单个日志文件可允许的最大大小 15 | /// 16 | public const string LogFileMaxSize = "LogFileMaxSize"; 17 | 18 | /// 19 | /// 日志保存的根目录 20 | /// 21 | public const string LogSaveRootDirectory = "LogSaveRootDirectory"; 22 | 23 | /// 24 | /// 是否启用 Redis 25 | /// 26 | public const string IsEnableRedis = "IsEnableRedis"; 27 | 28 | /// 29 | /// Redis 连接字符串 30 | /// 31 | public const string RedisConnString = "RedisConnString"; 32 | 33 | /// 34 | /// 是否启用数据库连接 35 | /// 36 | public const string IsEnableDbConn = "IsEnableDbConn"; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /CommonLib/IZhy/IZhy.Common/Const/FileNameConst.cs: -------------------------------------------------------------------------------- 1 | namespace IZhy.Common.Const 2 | { 3 | /// 4 | /// 文件名 常量 抽象类 ( 提供继承支持 ) 5 | /// 6 | public abstract class FileNameConst 7 | { 8 | /// 9 | /// 数据库连接信息配置 文件名 // DbConnInfo.json 10 | /// 11 | public const string DbConnInfoJson = "DbConnInfo.json"; 12 | 13 | /// 14 | /// 通用的配置文件 文件名 // CommonConfig.json 15 | /// 16 | public const string CommonConfigJson = "CommonConfig.json"; 17 | 18 | /// 19 | /// 用户头像 文件名 20 | /// 21 | public const string UserHeadPortrait = "UserHeadPortrait.jpg"; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /CommonLib/IZhy/IZhy.Common/Const/FolderNameConst.cs: -------------------------------------------------------------------------------- 1 | namespace IZhy.Common.Const 2 | { 3 | /// 4 | /// 文件夹名 常量 抽象类 ( 提供继承支持 ) 5 | /// 6 | public abstract class FolderNameConst 7 | { 8 | /// 9 | /// 日志 文件夹名 10 | /// 11 | public const string Logs = "Logs"; 12 | 13 | /// 14 | /// 必要配置 文件夹名 15 | /// 16 | public const string NecessaryConfig = "NecessaryConfig"; 17 | 18 | /// 19 | /// 运行时配置 文件夹名 20 | /// 21 | public const string RunningConfig = "RunningConfig"; 22 | 23 | /// 24 | /// 公共配置 文件夹名 25 | /// 26 | public const string CommonConfig = "CommonConfig"; 27 | 28 | /// 29 | /// 文件上传的根目录 文件夹名 30 | /// 31 | public const string FilesUploadRoot = "FilesUploadRoot"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /CommonLib/IZhy/IZhy.Common/DbTools/DbConnFactory.cs: -------------------------------------------------------------------------------- 1 | using IZhy.Common.BasicTools; 2 | using IZhy.Common.Const; 3 | using IZhy.Common.SimpleTools; 4 | using Microsoft.Data.SqlClient; 5 | using MySql.Data.MySqlClient; 6 | using Npgsql; 7 | using Oracle.ManagedDataAccess.Client; 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Data.Common; 11 | using System.IO; 12 | 13 | namespace IZhy.Common.DbTools 14 | { 15 | /// 16 | /// 数据库连接工厂 17 | /// 18 | public static class DbConnFactory 19 | { 20 | /// 21 | /// 默认的 DB连接配置 的 唯一别名 22 | /// 23 | public const string DefaultConnUniqueAlias = "default"; 24 | 25 | /// 26 | /// 获取或设置 数据库连接信息 配置文件 的 绝对路径 27 | /// 28 | public static string DbConnConfigPath { get; set; } = $"{FilesTool.ProgramRootDirectoryCommonConfig}{FileNameConst.DbConnInfoJson}"; 29 | 30 | /// 31 | /// 用来存放 DbConnInfo.json 配置文件 的 最后修改时间 32 | /// 33 | public static DateTime DbConnInfoLastChangeTime { get; private set; } 34 | 35 | /// 36 | /// 获取一个 bool 值,表示 DbConnInfo.json 配置文件 是否已被重新修改;true/false 是/否 37 | /// 38 | public static bool IsChangeConfigFile() 39 | { 40 | if (!File.Exists(DbConnConfigPath)) 41 | { 42 | throw new Exception($"【DbConnFactory】 数据库连接信息的配置文件不存在,请检查 => [ {DbConnConfigPath} ]"); 43 | } 44 | 45 | try 46 | { 47 | FileInfo fileInfo = new FileInfo(DbConnConfigPath); 48 | if (fileInfo.LastWriteTime != DbConnInfoLastChangeTime) 49 | { 50 | DbConnInfoLastChangeTime = fileInfo.LastWriteTime; 51 | return true; 52 | } 53 | } 54 | catch (Exception ex) 55 | { 56 | LogsTool.WriteEXLog("【DbConnFactory】 获取一个 bool 值,表示 DbConnInfo.json 配置文件 是否已被重新修改,发生异常", ex.ToString()); 57 | return true; 58 | } 59 | return false; 60 | } 61 | 62 | 63 | private static Dictionary _dbConnInfo = new Dictionary(); 64 | 65 | /// 66 | /// 获取 DbConnInfo.json 配置文件里的数据库连接信息 67 | /// 68 | public static Dictionary GetDbConnInfo() 69 | { 70 | try 71 | { 72 | if (_dbConnInfo == null || _dbConnInfo.Count < 1 || IsChangeConfigFile()) 73 | { 74 | _dbConnInfo = JsonTool.JsonFileToObject>(DbConnConfigPath); 75 | } 76 | } 77 | catch (Exception ex) 78 | { 79 | LogsTool.WriteEXLog("【DbConnFactory】 获取 DbConnInfo.json 配置文件里的配置信息,发生异常", ex); 80 | _dbConnInfo = new Dictionary(); 81 | } 82 | return _dbConnInfo; 83 | } 84 | 85 | 86 | /// 87 | /// 依据 唯一别名 获取 数据库连接对象 88 | /// 默认值 : "default" 89 | /// 90 | /// 连接配置的唯一别名 91 | /// 92 | internal static DbConnection GetDbConnection(string uniqueAlias = null) 93 | { 94 | if (string.IsNullOrWhiteSpace(uniqueAlias)) 95 | { 96 | uniqueAlias = DefaultConnUniqueAlias; 97 | } 98 | 99 | Dictionary dicConn = GetDbConnInfo(); 100 | 101 | if (dicConn.ContainsKey(uniqueAlias)) 102 | { 103 | var dbConnInfo = dicConn[uniqueAlias]; 104 | 105 | switch (dbConnInfo.DbType) 106 | { 107 | case DbTypeConst.MySQL: 108 | return new MySqlConnection(dbConnInfo.ConnString); 109 | 110 | case DbTypeConst.MSSqlServer: 111 | return new SqlConnection(dbConnInfo.ConnString); 112 | 113 | case DbTypeConst.PostgreSQL: 114 | return new NpgsqlConnection(dbConnInfo.ConnString); 115 | 116 | case DbTypeConst.Oracle: 117 | return new OracleConnection(dbConnInfo.ConnString); 118 | 119 | default: 120 | throw new Exception($"暂不支持【 {dbConnInfo.DbType} 】数据库"); 121 | } 122 | } 123 | else 124 | throw new Exception($"未找到唯一别名【 {uniqueAlias} 】下的数据库连接信息"); 125 | } 126 | } 127 | 128 | 129 | /// 130 | /// 数据库连接信息 实体类 131 | /// 132 | public sealed class DbConnInfo 133 | { 134 | private string _dbType = string.Empty; 135 | 136 | /// 137 | /// 数据库类型;参照 DbTypeConst 数据库类型常量类 138 | /// 139 | public string DbType 140 | { 141 | get => _dbType?.ToLower() ?? string.Empty; 142 | set => _dbType = value ?? string.Empty; 143 | } 144 | 145 | /// 146 | /// 连接字符串 147 | /// 148 | public string ConnString { get; set; } 149 | } 150 | 151 | /// 152 | /// 数据库类型常量类;常量值必须设置为小写字母,以便做等值比较 153 | /// 154 | public static class DbTypeConst 155 | { 156 | /// 157 | /// 代表 MySQL 数据库 158 | /// 159 | public const string MySQL = "mysql"; 160 | 161 | /// 162 | /// 代表 MS SqlServer 数据库 163 | /// 164 | public const string MSSqlServer = "mssqlserver"; 165 | 166 | /// 167 | /// 代表 PostgreSQL 数据库 168 | /// 169 | public const string PostgreSQL = "postgresql"; 170 | 171 | /// 172 | /// 代表 Oracle 数据库 173 | /// 174 | public const string Oracle = "oracle"; 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /CommonLib/IZhy/IZhy.Common/DbTools/DbOperToolDecorator.cs: -------------------------------------------------------------------------------- 1 | using IZhy.Common.AopProxy; 2 | using IZhy.Common.BasicTools; 3 | using System; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace IZhy.Common.DbTools 9 | { 10 | /// 11 | /// 数据库操作工具类 的 装饰器 12 | /// 13 | public class DbOperToolDecorator : GeneralDecorator 14 | { 15 | protected override void Before(MethodInfo method, object[] paramArr, string exeIdNum) 16 | { 17 | if (paramArr != null && paramArr.Length >= 3) 18 | { 19 | _ = Task.Run(() => 20 | { 21 | StringBuilder paramSb = new StringBuilder(); 22 | for (int i = 1; i < paramArr.Length - 1; i++) 23 | { 24 | object temp = paramArr[i]; 25 | if (temp == null) 26 | { 27 | continue; 28 | } 29 | paramSb.AppendLine(JsonTool.ObjectToJson(temp, true)); 30 | } 31 | paramSb.AppendLine($"sqlExeTimeout = {paramArr[paramArr.Length - 1]}"); 32 | 33 | LogsTool.WriteSQLLog(Convert.ToString(paramArr[0]), 34 | paramSb.ToString(), 35 | $"{TargetImpClassFullName}.{method.Name}()", 36 | exeIdNum); 37 | }); 38 | } 39 | } 40 | 41 | protected override void WhenException(MethodInfo method, object[] paramArr, Exception ex, string exeIdNum) 42 | { 43 | _ = Task.Run(() => 44 | { 45 | LogsTool.WriteEXLog("数据库操作时发生异常", 46 | ex.ToString(), 47 | null, 48 | $"{TargetImpClassFullName}.{method.Name}()", 49 | exeIdNum); 50 | }); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /CommonLib/IZhy/IZhy.Common/DbTools/InvokeDbOperTool.cs: -------------------------------------------------------------------------------- 1 | using IZhy.Common.AopProxy; 2 | using IZhy.Common.BasicTools; 3 | using IZhy.Common.Const; 4 | using System; 5 | 6 | namespace IZhy.Common.DbTools 7 | { 8 | /// 9 | /// 调用数据库操作工具类 10 | /// 11 | public static class InvokeDbOperTool 12 | { 13 | /// 14 | /// 是否启用数据库连接;若为 false 则不再执行与数据库的操作,适用于不依赖数据库的项目 15 | /// 16 | public static bool IsEnableDbConn() 17 | { 18 | try 19 | { 20 | return Convert.ToBoolean(CommonConfigTool.GetConfig(CommonConfigFieldsConst.IsEnableDbConn) ?? false); 21 | } 22 | catch (Exception) 23 | { 24 | return false; 25 | } 26 | } 27 | 28 | 29 | /// 30 | /// 获取一个 DbOperationTool 的新实例 31 | /// 属性 ConnUniqueAlias 连接信息的唯一别名是默认值 : "default" 32 | /// 33 | /// 34 | public static IDbOperation DbOperTool() 35 | { 36 | if (!IsEnableDbConn()) 37 | { 38 | return null; 39 | } 40 | var db = GeneralDecorator.CreateDecorator(new DbOperationTool()); 41 | db.OpenConn(); 42 | return db; 43 | } 44 | 45 | /// 46 | /// 获取一个 DbOperationTool 类的新实例 47 | /// 并设置 属性 ConnUniqueAlias 连接信息的唯一别名 48 | /// 49 | /// 设置 属性 ConnUniqueAlias 连接信息的唯一别名 50 | /// 51 | public static IDbOperation DbOperTool(string connUniqueAlias) 52 | { 53 | if (!IsEnableDbConn()) 54 | { 55 | return null; 56 | } 57 | var db = GeneralDecorator.CreateDecorator(new DbOperationTool(connUniqueAlias)); 58 | db.OpenConn(); 59 | return db; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /CommonLib/IZhy/IZhy.Common/DbTools/SqlStringExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IZhy.Common.DbTools 6 | { 7 | /// 8 | /// sql 字符串 扩展方法 工具类 9 | /// 10 | public static class SqlStringExtension 11 | { 12 | /// 13 | /// 用于 sql 字符串 条件拼接 14 | /// 15 | /// 16 | /// 17 | /// 18 | public static string SqlWhere(this string sql, bool isJoin) 19 | { 20 | return isJoin ? sql : string.Empty; 21 | } 22 | 23 | /// 24 | /// 用于 sql 字符串 条件拼接 25 | /// 26 | /// 27 | /// 28 | /// 成功拼接后需要执行的东西 29 | /// 30 | public static string SqlWhere(this string sql, bool isJoin, Action trueExe) 31 | { 32 | if (isJoin) 33 | { 34 | trueExe(); 35 | } 36 | return isJoin ? sql : string.Empty; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /CommonLib/IZhy/IZhy.Common/IZhy.Common.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | PreserveNewest 15 | 16 | 17 | PreserveNewest 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /CommonLib/IZhy/IZhy.Common/Redis/RedisTool.cs: -------------------------------------------------------------------------------- 1 | using IZhy.Common.BasicTools; 2 | using IZhy.Common.Const; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace IZhy.Common.Redis 9 | { 10 | /// 11 | /// Redis 操作 工具类 12 | /// 13 | public static class RedisTool 14 | { 15 | private static string _redisConn; 16 | 17 | static RedisTool() 18 | { 19 | if (!IsEnableRedis()) 20 | { 21 | return; 22 | } 23 | } 24 | 25 | 26 | /// 27 | /// 是否启用 Redis 28 | /// 29 | public static bool IsEnableRedis() 30 | { 31 | try 32 | { 33 | bool isEnable = Convert.ToBoolean(CommonConfigTool.GetConfig(CommonConfigFieldsConst.IsEnableRedis) ?? false); 34 | 35 | string redisConn = Convert.ToString(CommonConfigTool.GetConfig(CommonConfigFieldsConst.RedisConnString)); 36 | if (isEnable && _redisConn != redisConn) 37 | { 38 | _redisConn = redisConn; 39 | RedisHelper.Initialization(new CSRedis.CSRedisClient(_redisConn)); 40 | } 41 | 42 | return isEnable; 43 | } 44 | catch (Exception) 45 | { 46 | return false; 47 | } 48 | } 49 | 50 | 51 | /// 52 | /// 向 redis 里设置键值 53 | /// 54 | /// 键值 55 | /// 键对应的值 56 | /// 过期时间(单位 s 秒),默认 -1,永不过期 57 | /// 58 | public static bool Set(string key, object value, int expireSeconds = -1) 59 | { 60 | if (!IsEnableRedis()) 61 | { 62 | return false; 63 | } 64 | return RedisHelper.Set(key, value, expireSeconds); 65 | } 66 | 67 | /// 68 | /// 向 redis 里设置键值 69 | /// 70 | /// 键值 71 | /// 键对应的值 72 | /// 过期时间(单位 s 秒),默认 -1,永不过期 73 | /// 74 | public static Task SetAsync(string key, object value, int expireSeconds = -1) 75 | { 76 | if (!IsEnableRedis()) 77 | { 78 | return Task.FromResult(false); 79 | } 80 | return RedisHelper.SetAsync(key, value, expireSeconds); 81 | } 82 | 83 | 84 | /// 85 | /// 获取 redis 里键对应的值 86 | /// 87 | /// 泛型对象 88 | /// 键值 89 | /// 90 | public static T Get(string key) 91 | { 92 | if (!IsEnableRedis()) 93 | { 94 | return default; 95 | } 96 | return RedisHelper.Get(key); 97 | } 98 | 99 | /// 100 | /// 获取 redis 里键对应的值 101 | /// 102 | /// 泛型对象 103 | /// 键值 104 | /// 105 | public static Task GetAsync(string key) 106 | { 107 | if (!IsEnableRedis()) 108 | { 109 | return Task.FromResult(default); 110 | } 111 | return RedisHelper.GetAsync(key); 112 | } 113 | 114 | /// 115 | /// 获取 redis 里键对应的值 116 | /// 117 | /// 键值 118 | /// 119 | public static string Get(string key) 120 | { 121 | if (!IsEnableRedis()) 122 | { 123 | return null; 124 | } 125 | return RedisHelper.Get(key); 126 | } 127 | 128 | /// 129 | /// 获取 redis 里键对应的值 130 | /// 131 | /// 键值 132 | /// 133 | public static Task GetAsync(string key) 134 | { 135 | if (!IsEnableRedis()) 136 | { 137 | return Task.FromResult(null); 138 | } 139 | return RedisHelper.GetAsync(key); 140 | } 141 | 142 | 143 | private static TimeSpan KeyTimeSpan(long milliseconds) 144 | { 145 | // -1 表示 key 永不过期 146 | // -2 表示 key 不存在 147 | if (milliseconds == -2) 148 | { 149 | return new TimeSpan(0); 150 | } 151 | TimeSpan span = TimeSpan.FromMilliseconds(milliseconds); 152 | return span; 153 | } 154 | 155 | /// 156 | /// 获取 Key 的有效时间 157 | /// 158 | /// 159 | /// 160 | public static async Task KeyValidTimeAsync(string key) 161 | { 162 | if (!IsEnableRedis()) 163 | { 164 | return new TimeSpan(0); 165 | } 166 | long ms = await RedisHelper.PTtlAsync(key); 167 | return KeyTimeSpan(ms); 168 | } 169 | 170 | /// 171 | /// 获取 Key 的有效时间 172 | /// 173 | /// 174 | /// 175 | public static TimeSpan KeyValidTime(string key) 176 | { 177 | if (!IsEnableRedis()) 178 | { 179 | return new TimeSpan(0); 180 | } 181 | long ms = RedisHelper.PTtl(key); 182 | return KeyTimeSpan(ms); 183 | } 184 | 185 | 186 | /// 187 | /// 更新 Key 的过期时间,单位 秒 188 | /// 189 | /// 190 | /// 191 | /// 192 | public static bool Expire(string key, int seconds) 193 | { 194 | if (!IsEnableRedis()) 195 | { 196 | return false; 197 | } 198 | return RedisHelper.Expire(key, seconds); 199 | } 200 | 201 | /// 202 | /// 更新 Key 的过期时间,单位 秒 203 | /// 204 | /// 205 | /// 206 | /// 207 | public static async Task ExpireAsync(string key, int seconds) 208 | { 209 | if (!IsEnableRedis()) 210 | { 211 | return false; 212 | } 213 | return await RedisHelper.ExpireAsync(key, seconds); 214 | } 215 | } 216 | } 217 | -------------------------------------------------------------------------------- /CommonLib/IZhy/IZhy.Common/SimpleTools/DateTimeTool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Dynamic; 3 | 4 | namespace IZhy.Common.SimpleTools 5 | { 6 | /// 7 | /// 一个简单的日期时间工具类 8 | /// 9 | public static class DateTimeTool 10 | { 11 | /// 计算两个日期时间的间隔(返回一个动态对象,包含 年、月、日、时、分、秒 的间隔) 12 | /// 13 | /// 开始时间 14 | /// 结束时间(必须大于开始时间) 15 | /// 16 | public static dynamic ComputeHowLong(DateTime beginTime, DateTime endTime) 17 | { 18 | //创建匿名对象 19 | dynamic HowLong = new ExpandoObject(); 20 | 21 | if (endTime <= beginTime) 22 | { 23 | HowLong.cYear = 0; 24 | HowLong.cMonth = 0; 25 | HowLong.cDay = 0; 26 | HowLong.cHour = 0; 27 | HowLong.cMinute = 0; 28 | HowLong.cSecond = 0; 29 | 30 | HowLong.Days = 0; 31 | HowLong.Hours = 0; 32 | HowLong.Minutes = 0; 33 | HowLong.Seconds = 0; 34 | 35 | return HowLong; 36 | } 37 | 38 | #region 算法 39 | 40 | //// 结束日期时间 41 | int n_y = endTime.Year; 42 | int n_M = endTime.Month; 43 | int n_d = endTime.Day; 44 | int n_H = endTime.Hour; 45 | int n_m = endTime.Minute; 46 | int n_s = endTime.Second; 47 | 48 | //// 开始日期时间 49 | int b_y = beginTime.Year; 50 | int b_M = beginTime.Month; 51 | int b_d = beginTime.Day; 52 | int b_H = beginTime.Hour; 53 | int b_m = beginTime.Minute; 54 | int b_s = beginTime.Second; 55 | 56 | //// 相差日期时间 57 | int c_y; 58 | int c_M; 59 | int c_d; 60 | int c_H; 61 | int c_m; 62 | int c_s; 63 | 64 | //// 计算秒 65 | if (n_s < b_s) 66 | { 67 | c_s = n_s + 60 - b_s; 68 | n_m--; 69 | } 70 | else 71 | { 72 | c_s = n_s - b_s; 73 | } 74 | //// 计算分 75 | if (n_m < b_m) 76 | { 77 | c_m = n_m + 60 - b_m; 78 | n_H--; 79 | } 80 | else 81 | { 82 | c_m = n_m - b_m; 83 | } 84 | //// 计算时 85 | if (n_H < b_H) 86 | { 87 | c_H = n_H + 24 - b_H; 88 | n_d--; 89 | } 90 | else 91 | { 92 | c_H = n_H - b_H; 93 | } 94 | //// 计算天 95 | if (n_d < b_d) 96 | { 97 | switch (n_M - 1) 98 | { 99 | case 0: 100 | case 1: 101 | case 3: 102 | case 5: 103 | case 7: 104 | case 8: 105 | case 10: 106 | case 12: 107 | c_d = n_d + 31 - b_d; 108 | break; 109 | case 2: 110 | if ((n_y % 4 == 0 && n_y % 100 != 0) || n_y % 400 == 0) 111 | { 112 | c_d = n_d + 29 - b_d; 113 | } 114 | else 115 | { 116 | c_d = n_d + 28 - b_d; 117 | } 118 | break; 119 | default: 120 | c_d = n_d + 30 - b_d; 121 | break; 122 | }; 123 | n_M--; 124 | } 125 | else 126 | { 127 | c_d = n_d - b_d; 128 | } 129 | //// 计算月 130 | if (n_M < b_M) 131 | { 132 | c_M = n_M + 12 - b_M; 133 | n_y--; 134 | } 135 | else 136 | { 137 | c_M = n_M - b_M; 138 | } 139 | //// 计算年 140 | c_y = n_y - b_y; 141 | 142 | if (c_d >= 30) 143 | { 144 | c_d = 0; 145 | c_M++; 146 | } 147 | 148 | if (c_M >= 12) 149 | { 150 | c_M = 0; 151 | c_y++; 152 | } 153 | 154 | #endregion 155 | 156 | HowLong.cYear = c_y; 157 | HowLong.cMonth = c_M; 158 | HowLong.cDay = c_d; 159 | HowLong.cHour = c_H; 160 | HowLong.cMinute = c_m; 161 | HowLong.cSecond = c_s; 162 | 163 | TimeSpan ts = endTime - beginTime; 164 | HowLong.Days = ts.Days; 165 | HowLong.Hours = ts.Hours; 166 | HowLong.Minutes = ts.Minutes; 167 | HowLong.Seconds = ts.Seconds; 168 | 169 | return HowLong; 170 | } 171 | 172 | 173 | /// 174 | /// DateTime 格式化为精确到毫秒6位数 ( 字符长度 26 ) 175 | /// 格式: "yyyy-MM-dd HH:mm:ss.ffffff" 176 | /// 177 | /// 178 | /// 179 | public static string FormatCorrectToMs6(this DateTime dateTime) 180 | { 181 | return dateTime.ToString("yyyy-MM-dd HH:mm:ss.ffffff"); 182 | } 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /CommonLib/IZhy/IZhy.Common/SimpleTools/JavaScriptUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace IZhy.Common.SimpleTools 5 | { 6 | /// 7 | /// 一个 JavaScript 的工具类 8 | /// 9 | public static class JavaScriptUtil 10 | { 11 | /// 12 | /// 计算机起始时间 【 1970, 1, 1, 0, 0, 0, 0 】 13 | /// 14 | private static readonly DateTime ComputerStartTime = TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1, 0, 0, 0, 0), TimeZoneInfo.Local); 15 | 16 | 17 | /// 18 | /// 获取 js 的时间戳( 13 位 长度 ) 19 | /// 20 | /// 21 | /// 22 | public static long JsTimestamp13(this DateTime dateTime) 23 | { 24 | long t = (long)(dateTime - ComputerStartTime).TotalMilliseconds; 25 | return t; 26 | } 27 | 28 | /// 29 | /// 获取 js 的时间戳( 10 位 长度 ) 30 | /// 31 | /// 32 | /// 33 | public static long JsTimestamp10(this DateTime dateTime) 34 | { 35 | long t = (long)(dateTime - ComputerStartTime).TotalSeconds; 36 | return t; 37 | } 38 | 39 | 40 | /// 41 | /// 对正常的字符串转换为 Unicode 的字符串 42 | /// 43 | /// 正常的字符串 44 | /// 是否大写U字母 ‘\U’;默认 false ‘\u’ 45 | /// 46 | public static string ToUnicode(this string normalStr, bool isUpperCaseU = false) 47 | { 48 | if (string.IsNullOrWhiteSpace(normalStr)) 49 | { 50 | return string.Empty; 51 | } 52 | 53 | StringBuilder strResult = new StringBuilder(); 54 | for (int i = 0; i < normalStr.Length; i++) 55 | { 56 | if (isUpperCaseU) 57 | { 58 | strResult.Append("\\U"); 59 | } 60 | else 61 | { 62 | strResult.Append("\\u"); 63 | } 64 | strResult.Append(((int)normalStr[i]).ToString("x")); 65 | } 66 | return strResult.ToString(); 67 | } 68 | 69 | /// 70 | /// 对 Unicode 的字符串解码 71 | /// 72 | /// Unicode 字符串 73 | /// 74 | public static string UnicodeDecode(this string unicodeStr) 75 | { 76 | if (string.IsNullOrWhiteSpace(unicodeStr) || !unicodeStr.Contains("\\u") || !unicodeStr.Contains("\\U")) 77 | { 78 | return unicodeStr; 79 | } 80 | 81 | StringBuilder strResult = new StringBuilder(); 82 | string[] strArr = unicodeStr.Split('\\'); 83 | for (int i = 0; i < strArr.Length; i++) 84 | { 85 | if (strArr[i].Length < 5) 86 | { 87 | continue; 88 | } 89 | int code = Convert.ToInt32(strArr[i].Remove(0, 1), 16); 90 | strResult.Append((char)code); 91 | } 92 | return strResult.ToString(); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /CommonLib/IZhy/IZhy.Common/SimpleTools/StringOperationTool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace IZhy.Common.SimpleTools 5 | { 6 | /// 7 | /// 一个简单的字符串操作工具类 8 | /// 9 | public static class StringOperationTool 10 | { 11 | /// 12 | /// 每固定长度截取字符串转换为字符串数组 13 | /// 14 | /// 源字符串 15 | /// 固定长度(不可小于2,小于2无意义) 16 | /// 17 | public static string[] PerFixedLengthSplit(string sourceStr, int fixLength) 18 | { 19 | if (string.IsNullOrWhiteSpace(sourceStr) || fixLength < 2) 20 | { 21 | return null; 22 | } 23 | int length = sourceStr.Length % fixLength == 0 ? sourceStr.Length / fixLength : sourceStr.Length / fixLength + 1; 24 | string[] strArr = new string[length]; 25 | for (int i = 0; i < strArr.Length; i++) 26 | { 27 | if (i == strArr.Length - 1) 28 | { 29 | strArr[i] = sourceStr.Substring(i * fixLength); 30 | } 31 | else 32 | { 33 | strArr[i] = sourceStr.Substring(i * fixLength, fixLength); 34 | } 35 | } 36 | return strArr; 37 | } 38 | 39 | /// 40 | /// 用一个字符数组 char[],从中产生一个指定长度的随机字符串 41 | /// 42 | /// char[] 字符数组 43 | /// 指定返回字符串的长度(length 要 大于 0,小于 charArr.Length) 44 | /// 45 | public static string RandomStrFromCharArr(char[] charArr, int length) 46 | { 47 | if (charArr == null || charArr.Length < 1) 48 | { 49 | return null; 50 | } 51 | if (length < 1 || length > charArr.Length) 52 | { 53 | return null; 54 | } 55 | 56 | StringBuilder sb_randomStr = new StringBuilder(); 57 | 58 | int lastIndex = -1; //上一个index数 59 | do 60 | { 61 | Random rd = new Random(RandomNumTool.CreateSeed()); //随机数对象 62 | //int index = rd.Next(0, 10); //产生[0~10]之间的随机数,包含0,不包含10 63 | int index = rd.Next(0, charArr.Length); 64 | if (index == lastIndex) 65 | { 66 | continue; 67 | } 68 | else 69 | { 70 | if (charArr[index] == ' ' || charArr[index] == '\0') 71 | { 72 | sb_randomStr.Append('K'); 73 | } 74 | else 75 | { 76 | sb_randomStr.Append(charArr[index]); 77 | } 78 | lastIndex = index; 79 | } 80 | } while (sb_randomStr.Length < length); 81 | 82 | return sb_randomStr.ToString(); 83 | } 84 | 85 | /// 86 | /// 对一个字符串截取指定两个字符之间的内容 87 | /// 88 | /// 源字符串 89 | /// 开始字符 90 | /// 结束字符 91 | /// 是否去除后结果字符串的前后空格。true:是去除;false:不去除。默认值:false 92 | /// 93 | public static string StrCutOutBetweenTwoChar(string sourceStr, char beginChar, char endChar, bool isTrim = false) 94 | { 95 | if (string.IsNullOrWhiteSpace(sourceStr)) 96 | { 97 | return string.Empty; 98 | } 99 | 100 | int strLength = sourceStr.Length; 101 | int index = sourceStr.IndexOf(beginChar); //取得“开始字符”在“源字符串”中的索引位置 102 | int end = sourceStr.IndexOf(endChar); //取得“结束字符”在“源字符串”中的索引位置 103 | 104 | string newStr; 105 | int length; 106 | if (index < 0 && end < 0) 107 | { 108 | newStr = sourceStr; 109 | } 110 | else if (index < 0 && end >= 0) 111 | { 112 | index = 0; 113 | length = strLength - 1 - end; 114 | if (length < 1) 115 | { 116 | newStr = string.Empty; 117 | } 118 | else 119 | { 120 | newStr = sourceStr.Substring(index, length); 121 | } 122 | } 123 | else if (index >= 0 && end < 0) 124 | { 125 | index++; //开始索引值加1,用于忽略截取“开始字符” 126 | length = strLength - index; 127 | if (length < 1) 128 | { 129 | newStr = string.Empty; 130 | } 131 | else 132 | { 133 | newStr = sourceStr.Substring(index, length); 134 | } 135 | } 136 | else 137 | { 138 | index++; //开始索引值加1,用于忽略截取“开始字符” 139 | length = end - index; 140 | if (length < 1) 141 | { 142 | newStr = string.Empty; 143 | } 144 | else 145 | { 146 | newStr = sourceStr.Substring(index, length); 147 | } 148 | } 149 | 150 | if (isTrim) 151 | { 152 | newStr = newStr.Trim(); 153 | return newStr; 154 | } 155 | else 156 | { 157 | return newStr; 158 | } 159 | } 160 | 161 | 162 | /// 163 | /// 字符串脱敏处理; 164 | /// 把源字符串,从 [index] 索引处开始,向后 [length] 长度,替换为 [newChar] 新字符 165 | /// 166 | /// 源字符串 167 | /// 开始处索引 168 | /// 向后替换的长度 169 | /// 替换的新字符 170 | /// 171 | public static string StrDesensitization(string sourceStr, int index = 0, int length = 3, char newChar = '*') 172 | { 173 | if (string.IsNullOrWhiteSpace(sourceStr)) 174 | { 175 | return string.Empty; 176 | } 177 | char[] sourceStrArr = sourceStr.Trim().ToCharArray(); 178 | for (int i = index; i < length; i++) 179 | { 180 | sourceStrArr[i] = newChar; 181 | } 182 | return new string(sourceStrArr); 183 | } 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /CommonLib/IZhy/IZhy.Common/SimpleTools/TimedIntervalTask.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace IZhy.Common.SimpleTools 5 | { 6 | /// 7 | /// 时间间隔模式的定时任务类 8 | /// 9 | public sealed class TimedIntervalTask 10 | { 11 | /// 12 | /// 初始化 时间间隔模式的定时任务类;须给定一些必要参数 13 | /// 14 | /// 15 | /// 定时任务的方法行为,不可为 null;此方法里须加入 try {} catch {} 异常处理,以保证其稳定运行 16 | /// 17 | /// 定时任务的间隔时间,单位:毫秒 18 | /// 19 | /// 是否先运行行为;默认为 true,先运行行为,再等待时间间隔;若设为 false,则先等待时间间隔,再运行行为 20 | /// 21 | public TimedIntervalTask(Action action, int intervalTime, bool whetherToRunFirst = true) 22 | { 23 | TimedAction = action; 24 | IntervalTime = intervalTime; 25 | WhetherToRunFirst = whetherToRunFirst; 26 | Restore(); 27 | } 28 | 29 | /// 30 | /// 还原 31 | /// 32 | private void Restore() 33 | { 34 | IsPause = false; 35 | IsStop = false; 36 | IsRunning = false; 37 | IsStarted = false; 38 | } 39 | 40 | /// 41 | /// 定时的行为 42 | /// 43 | private Action TimedAction { get; set; } 44 | 45 | /// 46 | /// 行为运行的间隔时间,单位:毫秒 47 | /// 48 | public int IntervalTime { get; set; } 49 | 50 | /// 51 | /// 是否先运行 行为,默认 true 52 | /// 53 | /// 若为 true,则先运行行为,再等待时间间隔;若设为 false,则先等待时间间隔,再运行行为 54 | /// 55 | /// 56 | public bool WhetherToRunFirst { get; set; } 57 | 58 | /// 59 | /// 是否已经启动,true 已启动,false 未启动;默认 false 60 | /// 61 | public bool IsStarted { get; private set; } = false; 62 | 63 | /// 64 | /// 是否暂停行为,默认 false 65 | /// 66 | /// 若为 true,则暂停定时行为的运行;若再设为 false,则继续定时行为的运行 67 | /// 68 | /// 69 | public bool IsPause { get; private set; } = false; 70 | 71 | /// 72 | /// 是否终止定时任务,默认 false 73 | /// 74 | public bool IsStop { get; private set; } = false; 75 | 76 | /// 77 | /// 定时任务是否在运行中;true 是,false 否;默认 false 78 | /// 79 | public bool IsRunning { get; private set; } = false; 80 | 81 | /// 82 | /// 启动任务运行 83 | /// 注意:再次调用此方法需要先执行 Stop() 终止定时任务 84 | /// 85 | public void Startup() 86 | { 87 | if (TimedAction == null || IsStarted) 88 | { 89 | return; 90 | } 91 | 92 | Task.Run(async () => 93 | { 94 | IsStarted = true; 95 | 96 | while (!IsStop) 97 | { 98 | IntervalTime = IntervalTime < 1 ? 1 : IntervalTime; 99 | if (IsPause) 100 | { 101 | IsRunning = false; 102 | await Task.Delay(IntervalTime); 103 | continue; 104 | } 105 | else 106 | { 107 | IsRunning = true; 108 | } 109 | 110 | if (WhetherToRunFirst) 111 | { 112 | _ = Task.Run(() => 113 | { 114 | try 115 | { 116 | TimedAction(); 117 | } 118 | catch (Exception) 119 | { 120 | // 不做处理 121 | } 122 | }); 123 | await Task.Delay(IntervalTime); 124 | } 125 | else 126 | { 127 | await Task.Delay(IntervalTime); 128 | _ = Task.Run(() => 129 | { 130 | try 131 | { 132 | TimedAction(); 133 | } 134 | catch (Exception) 135 | { 136 | // 不做处理 137 | } 138 | }); 139 | } 140 | } 141 | 142 | Restore(); 143 | }); 144 | } 145 | 146 | /// 147 | /// 终止定时任务 148 | /// 注意:调用该方法后,定时任务会在下一个运行周期终止定时任务,这可能会产生一个等待期; 149 | /// 可通过 IsStarted 属性判断,当值为 false 时(未启动),则表示已终止定时任务,可通过 Startup() 重新启动运行 150 | /// 151 | public void Stop() 152 | { 153 | IsStop = true; 154 | } 155 | 156 | /// 157 | /// 终止定时任务 158 | /// 159 | /// 160 | public async Task StopAsync() 161 | { 162 | IsStop = true; 163 | 164 | await Task.Run(async () => 165 | { 166 | while (true) 167 | { 168 | await Task.Delay(100); 169 | if (!IsStarted) 170 | { 171 | break; 172 | } 173 | } 174 | }); 175 | } 176 | 177 | /// 178 | /// 暂停定时任务 179 | /// 180 | public void Pause() 181 | { 182 | IsPause = true; 183 | } 184 | 185 | /// 186 | /// 暂停定时任务 187 | /// 188 | public async Task PauseAsync() 189 | { 190 | IsPause = true; 191 | 192 | await Task.Run(async () => 193 | { 194 | while (true) 195 | { 196 | await Task.Delay(100); 197 | if (!IsRunning) 198 | { 199 | break; 200 | } 201 | } 202 | }); 203 | } 204 | 205 | /// 206 | /// 继续定时任务 207 | /// 208 | public void GoOn() 209 | { 210 | IsPause = false; 211 | } 212 | 213 | /// 214 | /// 继续定时任务 215 | /// 216 | public async Task GoOnAsync() 217 | { 218 | IsPause = false; 219 | 220 | await Task.Run(async () => 221 | { 222 | while (true) 223 | { 224 | await Task.Delay(100); 225 | if (IsRunning) 226 | { 227 | break; 228 | } 229 | } 230 | }); 231 | } 232 | } 233 | } 234 | -------------------------------------------------------------------------------- /CommonLib/IZhy/IZhy.Common/SysEntities/PagingDataEntity.cs: -------------------------------------------------------------------------------- 1 | using IZhy.Common.BasicTools; 2 | using System.Collections; 3 | using System.Data; 4 | 5 | namespace IZhy.Common.SysEntities 6 | { 7 | /// 8 | /// 分页数据 实体类 9 | /// 必须设置基础数据: 10 | /// AllDataCount,数据总条数 11 | /// PageSize,每页数据量 12 | /// PageNum,当前页码号 13 | /// 14 | public class PagingDataEntity 15 | { 16 | /// 17 | /// 分页实体类初始化基础数据 18 | /// 参数: 19 | /// allDataCount 数据总条数;pageSize 每页数据量;pageNum 当前页码号 20 | /// 21 | /// 数据总条数 22 | /// 每页数据量 23 | /// 当前页码号 24 | public PagingDataEntity(int allDataCount, int pageSize, int pageNum) 25 | { 26 | AllDataCount = allDataCount; 27 | PageSize = pageSize; 28 | PageNum = pageNum; 29 | } 30 | 31 | 32 | /// 33 | /// 每页的数据量,默认数量值 10 34 | /// 35 | public const int DefaultPageSize = 10; 36 | 37 | 38 | /// 39 | /// 数据总页数 40 | /// 41 | private int _allPageCount = 0; 42 | 43 | /// 44 | /// 当前页码号 45 | /// 46 | private int _pageNum = 1; 47 | 48 | /// 49 | /// 每页数据量 50 | /// 51 | private int _pageSize = DefaultPageSize; 52 | 53 | /// 54 | /// 发起分页查询的开始序号 55 | /// 56 | private int _startNum = 0; 57 | 58 | 59 | /// 60 | /// 数据总条数 61 | /// 62 | public int AllDataCount { get; set; } = 0; 63 | 64 | /// 65 | /// 数据总页数 66 | /// 67 | public int AllPageCount 68 | { 69 | get 70 | { 71 | _allPageCount = AllDataCount % PageSize == 0 ? AllDataCount / PageSize : (AllDataCount / PageSize) + 1; 72 | return _allPageCount; 73 | } 74 | } 75 | 76 | /// 77 | /// 当前页码号 78 | /// 79 | public int PageNum 80 | { 81 | get 82 | { 83 | if (_pageNum < 1) 84 | { 85 | _pageNum = 1; 86 | } 87 | else if (_pageNum > AllPageCount) 88 | { 89 | _pageNum = AllPageCount; 90 | } 91 | return _pageNum; 92 | } 93 | set { _pageNum = value; } 94 | } 95 | 96 | /// 97 | /// 每页数据量;1 ~ 1000 98 | /// 99 | public int PageSize 100 | { 101 | get 102 | { 103 | if (_pageSize < 1) 104 | { 105 | _pageSize = DefaultPageSize; 106 | } 107 | 108 | if (_pageSize > 1000) 109 | { 110 | _pageSize = 1000; 111 | } 112 | 113 | return _pageSize; 114 | } 115 | set 116 | { 117 | _pageSize = value; 118 | } 119 | } 120 | 121 | /// 122 | /// 发起分页查询的开始序号 123 | /// 124 | public int StartNum 125 | { 126 | get 127 | { 128 | if (PageNum < 2) 129 | { 130 | _startNum = 0; 131 | } 132 | else 133 | { 134 | _startNum = (PageNum - 1) * PageSize; 135 | } 136 | return _startNum; 137 | } 138 | } 139 | 140 | /// 141 | /// 结果数据的数据量 142 | /// 结果值:= -1 则表示结果数据可能不是有效的集合数据,需要检查程序代码 143 | /// 144 | public int ResultDataCount 145 | { 146 | get 147 | { 148 | if (ResultData == null) 149 | { 150 | return 0; 151 | } 152 | else 153 | { 154 | if (ResultData is DataTable) 155 | { 156 | return (ResultData as DataTable).Rows.Count; 157 | } 158 | else if (ResultData is ICollection) 159 | { 160 | return (ResultData as ICollection).Count; 161 | } 162 | else 163 | { 164 | return -1; 165 | } 166 | } 167 | } 168 | } 169 | 170 | /// 171 | /// 分页查询的结果数据 172 | /// 173 | public object ResultData { get; set; } = null; 174 | 175 | 176 | public override string ToString() 177 | { 178 | return JsonTool.ObjectToJson(this); 179 | } 180 | } 181 | } 182 | -------------------------------------------------------------------------------- /CommonLib/IZhy/IZhy.Common/SysEntities/ServiceResultEntity.cs: -------------------------------------------------------------------------------- 1 | using IZhy.Common.BasicTools; 2 | using System.Text; 3 | 4 | namespace IZhy.Common.SysEntities 5 | { 6 | /// 7 | /// 服务接口 结果 实体类 8 | /// 9 | public class ServiceResultEntity 10 | { 11 | /// 12 | /// 是否成功 13 | /// 14 | public bool IsSucceed { get; set; } = false; 15 | 16 | /// 17 | /// 消息 18 | /// 19 | public string Message { get; set; } = "无消息"; 20 | 21 | /// 22 | /// 结果对象 23 | /// 24 | public object Result { get; set; } = null; 25 | 26 | 27 | public ServiceResultEntity() { } 28 | 29 | public ServiceResultEntity(bool isSucc, object result = null) 30 | { 31 | IsSucceed = isSucc; 32 | if (isSucc) 33 | { 34 | Message = "成功的"; 35 | } 36 | else 37 | { 38 | Message = "失败的"; 39 | } 40 | Result = result; 41 | } 42 | 43 | public ServiceResultEntity(string msg, bool isSucc = false) 44 | { 45 | Message = msg; 46 | IsSucceed = isSucc; 47 | } 48 | 49 | public ServiceResultEntity(bool isSucc, string msg, object result) 50 | { 51 | IsSucceed = isSucc; 52 | Message = msg; 53 | Result = result; 54 | } 55 | 56 | 57 | public override string ToString() 58 | { 59 | return JsonTool.ObjectToJson(this); 60 | } 61 | 62 | /// 63 | /// 把 ToString() 字符串中的特殊字符转换成 HTML 可识别的字符 64 | /// 65 | /// 66 | public string ToHtml() 67 | { 68 | StringBuilder sbHtml = new StringBuilder(this.ToString()); 69 | 70 | sbHtml.Replace("<", "<"); 71 | sbHtml.Replace(">", ">"); 72 | 73 | sbHtml.Replace(@"\r\n", "
"); 74 | sbHtml.Replace(@"\n\r", "
"); 75 | sbHtml.Replace(@"\n", "
"); 76 | 77 | //   字符:不断行的空白格,该空格占据的宽度受字体影响(一个字符宽度)。 78 | //   字符:相当全角状态键入半个“空格”键(半个汉字的宽度,一个字符宽度)。 79 | //   字符:相当全角状态键入“空格”键(1个汉字的宽度,两个字符宽度)。 80 | 81 | sbHtml.Replace(" ", " "); 82 | 83 | return sbHtml.ToString(); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /CommonLib/IZhy/IZhy.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31105.61 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IZhy.Common", "IZhy.Common\IZhy.Common.csproj", "{F8A27B11-8796-405C-9635-1316BB9ACF25}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleTest", "ConsoleTest\ConsoleTest.csproj", "{3302D5C0-9BAB-4E96-B56E-753A2EDDBC80}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {F8A27B11-8796-405C-9635-1316BB9ACF25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {F8A27B11-8796-405C-9635-1316BB9ACF25}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {F8A27B11-8796-405C-9635-1316BB9ACF25}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {F8A27B11-8796-405C-9635-1316BB9ACF25}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {3302D5C0-9BAB-4E96-B56E-753A2EDDBC80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {3302D5C0-9BAB-4E96-B56E-753A2EDDBC80}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {3302D5C0-9BAB-4E96-B56E-753A2EDDBC80}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {3302D5C0-9BAB-4E96-B56E-753A2EDDBC80}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {2071DE76-24E9-47DB-92E0-283DC85F31D0} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /CommonLib/README.md: -------------------------------------------------------------------------------- 1 | # IZhy 2 | iZhy自己的代码通用库 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenDemo 2 | 公开的例子 3 | -------------------------------------------------------------------------------- /Word模板文件的替换并生成新的Word文件/WordTestDemo/WordFileDemo/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Word模板文件的替换并生成新的Word文件/WordTestDemo/WordFileDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace WordFileDemo 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | Console.WriteLine("程序开始..."); 14 | 15 | Task.Run(() => 16 | { 17 | WordTool.WordTemplateReplace($"{WordTool.WordTemplateDirectory}测试模板-0.docx", 18 | $"{WordTool.WordOutputDirectory}模板输出-{DateTime.Now.ToString("HH_mm_ss_ffff")}.docx", 19 | new Dictionary() 20 | { 21 | ["name"] = "张三", 22 | ["sex"] = "23", 23 | ["age"] = "男", 24 | }, 25 | new Dictionary() 26 | { 27 | ["picture"] = new WordImg(WordTool.TestImagePath, 70, 30), 28 | ["picture2"] = new WordImg(WordTool.TestImagePath, 70, 30), 29 | ["picture3"] = new WordImg(WordTool.TestImagePath, 70, 30), 30 | }); 31 | 32 | WordTool.WordTemplateReplace($"{WordTool.WordTemplateDirectory}新模板1.docx", 33 | $"{WordTool.WordOutputDirectory}模板输出--{DateTime.Now.ToString("HH_mm_ss_ffff")}.docx", 34 | new Dictionary() 35 | { 36 | ["nd"] = "2021", 37 | ["yd"] = "01", 38 | ["rd"] = "28", 39 | }, 40 | new Dictionary() 41 | { 42 | ["picture"] = new WordImg(WordTool.TestImagePath, 70, 30), 43 | }); 44 | 45 | }).ContinueWith(t => 46 | { 47 | Console.WriteLine("程序运行完毕!"); 48 | Console.WriteLine("\n按任意键退出!"); 49 | }); 50 | 51 | Console.ReadKey(); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Word模板文件的替换并生成新的Word文件/WordTestDemo/WordFileDemo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("WordFileDemo")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("WordFileDemo")] 13 | [assembly: AssemblyCopyright("Copyright © 2021")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("dc0f0567-caae-4cd5-846d-c252bb9464ec")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 33 | //通过使用 "*",如下所示: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Word模板文件的替换并生成新的Word文件/WordTestDemo/WordFileDemo/SimpleFilesTool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace WordFileDemo 9 | { 10 | /// 11 | /// 一个简单的文件工具类 12 | /// 13 | public static class SimpleFilesTool 14 | { 15 | 16 | /// 17 | /// 获取程序根目录( ..\ ) 18 | /// 19 | public static string ProgramRootDirectory 20 | { 21 | get 22 | { 23 | string root = AppDomain.CurrentDomain.BaseDirectory; 24 | if (root.Last() != '\\') 25 | { 26 | root += '\\'; 27 | } 28 | return root; 29 | } 30 | } 31 | 32 | /// 33 | /// 获取当前桌面目录( ..\ ) 34 | /// 35 | public static string CurrentDesktopDirectory 36 | { 37 | get 38 | { 39 | string path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); 40 | if (path.Last() != '\\') 41 | { 42 | path += '\\'; 43 | } 44 | return path; 45 | } 46 | } 47 | 48 | /// 49 | /// 创建文件路径的目录 50 | /// 给一个绝对路径,如果该路径的目录不存在,该方法会自动创建这个路径的目录 51 | /// 52 | /// 53 | /// 54 | public static string CreateFilePathDirectory(string path) 55 | { 56 | if (!Directory.Exists(Path.GetDirectoryName(path))) 57 | { 58 | Directory.CreateDirectory(Path.GetDirectoryName(path)); 59 | } 60 | return path; 61 | } 62 | 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Word模板文件的替换并生成新的Word文件/WordTestDemo/WordFileDemo/TestImages/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/A-Grass-Code/OpenDemo/3d73ac75a1df53019b888933c9243c5d24425970/Word模板文件的替换并生成新的Word文件/WordTestDemo/WordFileDemo/TestImages/test.jpg -------------------------------------------------------------------------------- /Word模板文件的替换并生成新的Word文件/WordTestDemo/WordFileDemo/WordFileDemo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {DC0F0567-CAAE-4CD5-846D-C252BB9464EC} 8 | Exe 9 | WordFileDemo 10 | WordFileDemo 11 | v4.5 12 | 512 13 | true 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | ..\packages\DocX.1.7.1\lib\net40\Xceed.Document.NET.dll 45 | 46 | 47 | ..\packages\DocX.1.7.1\lib\net40\Xceed.Words.NET.dll 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | Always 61 | 62 | 63 | Always 64 | 65 | 66 | Always 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /Word模板文件的替换并生成新的Word文件/WordTestDemo/WordFileDemo/WordFiles/Templates/新模板1.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/A-Grass-Code/OpenDemo/3d73ac75a1df53019b888933c9243c5d24425970/Word模板文件的替换并生成新的Word文件/WordTestDemo/WordFileDemo/WordFiles/Templates/新模板1.docx -------------------------------------------------------------------------------- /Word模板文件的替换并生成新的Word文件/WordTestDemo/WordFileDemo/WordFiles/Templates/测试模板-0.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/A-Grass-Code/OpenDemo/3d73ac75a1df53019b888933c9243c5d24425970/Word模板文件的替换并生成新的Word文件/WordTestDemo/WordFileDemo/WordFiles/Templates/测试模板-0.docx -------------------------------------------------------------------------------- /Word模板文件的替换并生成新的Word文件/WordTestDemo/WordFileDemo/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Word模板文件的替换并生成新的Word文件/WordTestDemo/WordTestDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30907.101 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WordFileDemo", "WordFileDemo\WordFileDemo.csproj", "{DC0F0567-CAAE-4CD5-846D-C252BB9464EC}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {DC0F0567-CAAE-4CD5-846D-C252BB9464EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {DC0F0567-CAAE-4CD5-846D-C252BB9464EC}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {DC0F0567-CAAE-4CD5-846D-C252BB9464EC}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {DC0F0567-CAAE-4CD5-846D-C252BB9464EC}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {D22BC69B-67A8-49B5-AD2B-B83D870AFC6F} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /js-a标签下载文件/aTagDownloadFile.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 用 a 标签下载文件 3 | * @param {*} downloadUrl 下载 URL 4 | * @param {*} fileName 文件名 5 | */ 6 | const aTagDownloadFile = (downloadUrl, fileName) => { 7 | const link = document.createElement('a'); 8 | link.setAttribute('visibility', 'hidden'); 9 | link.download = fileName; 10 | link.href = downloadUrl; 11 | document.body.appendChild(link); 12 | link.click(); 13 | document.body.removeChild(link); 14 | } 15 | 16 | export default aTagDownloadFile; -------------------------------------------------------------------------------- /js异步等待毫秒数/waitMillisecond.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 等待毫秒数,示例: await waitMillisecond(2000) 3 | * @param {*} ms 等待的毫秒数值 4 | * @returns 返回一个 Promise 对象 5 | */ 6 | const waitMillisecond = (ms = 1000) => { 7 | return new Promise((resolve) => { 8 | setTimeout(() => { 9 | resolve(1); 10 | }, ms); 11 | }); 12 | } 13 | 14 | export default waitMillisecond; -------------------------------------------------------------------------------- /js数据合并/mergeData.js: -------------------------------------------------------------------------------- 1 | export default class MergeData { 2 | static test() { 3 | const a = { 4 | a: 1, 5 | b: { 6 | b1: 10, 7 | b2: [2, 21, 23] 8 | }, 9 | c: [ 10 | { 11 | c1: 3, 12 | c2: [44, 45], 13 | c3: '', 14 | c4: 0 15 | } 16 | ] 17 | } 18 | console.log('a --', a); 19 | 20 | const b = { 21 | a: 19, 22 | b: { 23 | b1: 190, 24 | b2: [291, 293] 25 | }, 26 | c: [ 27 | { 28 | c4: 39, 29 | c2: [495] 30 | }, 31 | { 32 | c4: 393, 33 | c2: [4945] 34 | }, 35 | ] 36 | } 37 | console.log('b --', b); 38 | 39 | console.log('源数据(b) 合并到 目标数据(a) 上 --', MergeData.setDataMerge(a, b)); 40 | } 41 | 42 | /** 43 | * 设置数据合并,把 源数据 合并到 目标数据 上 44 | * @param {*} target 目标数据 45 | * @param {*} sources 源数据 46 | * @returns 返回新的目标数据 47 | */ 48 | static setDataMerge(target, sources) { 49 | const targetDeep = JSON.parse(JSON.stringify(target)); 50 | const sourcesDeep = JSON.parse(JSON.stringify(sources)); 51 | let res = JSON.parse(JSON.stringify(target)); 52 | if (targetDeep.constructor === Object && sourcesDeep.constructor === Object) { 53 | for (let key in targetDeep) { 54 | if (sourcesDeep.hasOwnProperty(key)) { 55 | res[key] = MergeData.setDataMerge(targetDeep[key], sourcesDeep[key]); 56 | } 57 | } 58 | } 59 | else if (targetDeep.constructor === Array && sourcesDeep.constructor === Array) { 60 | if (targetDeep.length > 0) { 61 | const targetModel = targetDeep.slice(0, 1)[0]; 62 | if (sourcesDeep.length > 0) { 63 | const n = targetDeep.length >= sourcesDeep.length ? targetDeep.length : sourcesDeep.length; 64 | for (let i = 0; i < n; i++) { 65 | if (targetDeep.length >= sourcesDeep.length) { 66 | if (i < sourcesDeep.length) { 67 | res[i] = MergeData.setDataMerge(targetDeep[i], sourcesDeep[i]); 68 | } 69 | } 70 | else { 71 | if (i < targetDeep.length) { 72 | res[i] = MergeData.setDataMerge(targetDeep[i], sourcesDeep[i]); 73 | } 74 | else { 75 | res.push(MergeData.setDataMerge(targetModel, sourcesDeep[i])); 76 | } 77 | } 78 | } 79 | } 80 | } 81 | else { 82 | res = [...sourcesDeep]; 83 | } 84 | } 85 | else { 86 | res = sourcesDeep; 87 | } 88 | return res; 89 | } 90 | } -------------------------------------------------------------------------------- /录屏/ScreenRecording/ScreenRecording.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31605.320 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScreenRecording", "ScreenRecording\ScreenRecording.csproj", "{24AC21EC-ACF0-4723-A103-BAB52BA99F5E}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {24AC21EC-ACF0-4723-A103-BAB52BA99F5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {24AC21EC-ACF0-4723-A103-BAB52BA99F5E}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {24AC21EC-ACF0-4723-A103-BAB52BA99F5E}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {24AC21EC-ACF0-4723-A103-BAB52BA99F5E}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {C69243BA-C445-41D2-97CD-CA300489B389} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /录屏/ScreenRecording/ScreenRecording/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /录屏/ScreenRecording/ScreenRecording/Common/GcProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ScreenRecording.Common 4 | { 5 | /// 6 | /// GC 回收处理器 初始化类;用在程序启动处 7 | /// 8 | public static class GcProcessor 9 | { 10 | private static bool _isRunning = false; 11 | 12 | private static readonly object _lock = new object(); 13 | 14 | /// 15 | /// GC 回收器 初始化; 默认 每 100 秒 执行一次 GC.Collect(); 16 | /// 17 | /// 间隔时间,单位秒;默认 100 s 18 | public static void Init(int intervalTime = 100) 19 | { 20 | lock (_lock) 21 | { 22 | if (_isRunning) 23 | { 24 | return; 25 | } 26 | else 27 | { 28 | _isRunning = true; 29 | new TimedIntervalTask(() => 30 | { 31 | GC.Collect(); 32 | }, 1000 * intervalTime, false).Startup(); 33 | } 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /录屏/ScreenRecording/ScreenRecording/Common/TimedIntervalTask.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace ScreenRecording.Common 5 | { 6 | /// 7 | /// 时间间隔模式的定时任务类 8 | /// 9 | public sealed class TimedIntervalTask 10 | { 11 | /// 12 | /// 初始化 时间间隔模式的定时任务类;须给定一些必要参数 13 | /// 14 | /// 15 | /// 定时任务的方法行为,不可为 null;此方法里须加入 try {} catch {} 异常处理,以保证其稳定运行 16 | /// 17 | /// 定时任务的间隔时间,单位:毫秒 18 | /// 19 | /// 是否先运行行为;默认为 true,先运行行为,再等待时间间隔;若设为 false,则先等待时间间隔,再运行行为 20 | /// 21 | public TimedIntervalTask(Action action, int intervalTime, bool whetherToRunFirst = true) 22 | { 23 | TimedAction = action; 24 | IntervalTime = intervalTime; 25 | WhetherToRunFirst = whetherToRunFirst; 26 | Restore(); 27 | } 28 | 29 | /// 30 | /// 还原 31 | /// 32 | private void Restore() 33 | { 34 | IsPause = false; 35 | IsStop = false; 36 | IsRunning = false; 37 | IsStarted = false; 38 | } 39 | 40 | /// 41 | /// 定时的行为 42 | /// 43 | private Action TimedAction { get; set; } 44 | 45 | /// 46 | /// 行为运行的间隔时间,单位:毫秒 47 | /// 48 | public int IntervalTime { get; set; } 49 | 50 | /// 51 | /// 是否先运行 行为,默认 true 52 | /// 53 | /// 若为 true,则先运行行为,再等待时间间隔;若设为 false,则先等待时间间隔,再运行行为 54 | /// 55 | /// 56 | public bool WhetherToRunFirst { get; set; } 57 | 58 | /// 59 | /// 是否已经启动,true 已启动,false 未启动;默认 false 60 | /// 61 | public bool IsStarted { get; private set; } = false; 62 | 63 | /// 64 | /// 是否暂停行为,默认 false 65 | /// 66 | /// 若为 true,则暂停定时行为的运行;若再设为 false,则继续定时行为的运行 67 | /// 68 | /// 69 | public bool IsPause { get; private set; } = false; 70 | 71 | /// 72 | /// 是否终止定时任务,默认 false 73 | /// 74 | public bool IsStop { get; private set; } = false; 75 | 76 | /// 77 | /// 定时任务是否在运行中;true 是,false 否;默认 false 78 | /// 79 | public bool IsRunning { get; private set; } = false; 80 | 81 | /// 82 | /// 启动任务运行 83 | /// 注意:再次调用此方法需要先执行 Stop() 终止定时任务 84 | /// 85 | public void Startup() 86 | { 87 | if (TimedAction == null || IsStarted) 88 | { 89 | return; 90 | } 91 | 92 | Task.Run(async () => 93 | { 94 | IsStarted = true; 95 | 96 | while (!IsStop) 97 | { 98 | IntervalTime = IntervalTime < 1 ? 1 : IntervalTime; 99 | if (IsPause) 100 | { 101 | IsRunning = false; 102 | await Task.Delay(IntervalTime); 103 | continue; 104 | } 105 | else 106 | { 107 | IsRunning = true; 108 | } 109 | 110 | if (WhetherToRunFirst) 111 | { 112 | _ = Task.Run(() => 113 | { 114 | try 115 | { 116 | TimedAction(); 117 | } 118 | catch (Exception) 119 | { 120 | // 不做处理 121 | } 122 | }); 123 | await Task.Delay(IntervalTime); 124 | } 125 | else 126 | { 127 | await Task.Delay(IntervalTime); 128 | _ = Task.Run(() => 129 | { 130 | try 131 | { 132 | TimedAction(); 133 | } 134 | catch (Exception) 135 | { 136 | // 不做处理 137 | } 138 | }); 139 | } 140 | } 141 | 142 | Restore(); 143 | }); 144 | } 145 | 146 | /// 147 | /// 终止定时任务 148 | /// 注意:调用该方法后,定时任务会在下一个运行周期终止定时任务,这可能会产生一个等待期; 149 | /// 可通过 IsStarted 属性判断,当值为 false 时(未启动),则表示已终止定时任务,可通过 Startup() 重新启动运行 150 | /// 151 | public void Stop() 152 | { 153 | IsStop = true; 154 | } 155 | 156 | /// 157 | /// 暂停定时任务 158 | /// 159 | public void Pause() 160 | { 161 | IsPause = true; 162 | } 163 | 164 | /// 165 | /// 继续定时任务 166 | /// 167 | public void GoOn() 168 | { 169 | IsPause = false; 170 | } 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /录屏/ScreenRecording/ScreenRecording/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace ScreenRecording 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// 应用程序的主入口点。 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new FormMain()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /录屏/ScreenRecording/ScreenRecording/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("ScreenRecording")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ScreenRecording")] 13 | [assembly: AssemblyCopyright("Copyright © 2021")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("24ac21ec-acf0-4723-a103-bab52ba99f5e")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 33 | //通过使用 "*",如下所示: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.2.1.1")] 36 | [assembly: AssemblyFileVersion("1.2.1.1")] 37 | -------------------------------------------------------------------------------- /录屏/ScreenRecording/ScreenRecording/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace ScreenRecording.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// 一个强类型的资源类,用于查找本地化的字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// 返回此类使用的缓存的 ResourceManager 实例。 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ScreenRecording.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 重写当前线程的 CurrentUICulture 属性,对 51 | /// 使用此强类型资源类的所有资源查找执行重写。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。 65 | /// 66 | internal static System.Drawing.Icon Logo { 67 | get { 68 | object obj = ResourceManager.GetObject("Logo", resourceCulture); 69 | return ((System.Drawing.Icon)(obj)); 70 | } 71 | } 72 | 73 | /// 74 | /// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。 75 | /// 76 | internal static System.Drawing.Icon MouseLeftImg { 77 | get { 78 | object obj = ResourceManager.GetObject("MouseLeftImg", resourceCulture); 79 | return ((System.Drawing.Icon)(obj)); 80 | } 81 | } 82 | 83 | /// 84 | /// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。 85 | /// 86 | internal static System.Drawing.Icon MousePointerImg { 87 | get { 88 | object obj = ResourceManager.GetObject("MousePointerImg", resourceCulture); 89 | return ((System.Drawing.Icon)(obj)); 90 | } 91 | } 92 | 93 | /// 94 | /// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。 95 | /// 96 | internal static System.Drawing.Icon MouseRightImg { 97 | get { 98 | object obj = ResourceManager.GetObject("MouseRightImg", resourceCulture); 99 | return ((System.Drawing.Icon)(obj)); 100 | } 101 | } 102 | 103 | /// 104 | /// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。 105 | /// 106 | internal static System.Drawing.Icon MouseWheelImg { 107 | get { 108 | object obj = ResourceManager.GetObject("MouseWheelImg", resourceCulture); 109 | return ((System.Drawing.Icon)(obj)); 110 | } 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /录屏/ScreenRecording/ScreenRecording/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace ScreenRecording.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.2.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /录屏/ScreenRecording/ScreenRecording/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /录屏/ScreenRecording/ScreenRecording/Properties/app.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 49 | 57 | 58 | 72 | -------------------------------------------------------------------------------- /录屏/ScreenRecording/ScreenRecording/Resources/Logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/A-Grass-Code/OpenDemo/3d73ac75a1df53019b888933c9243c5d24425970/录屏/ScreenRecording/ScreenRecording/Resources/Logo.ico -------------------------------------------------------------------------------- /录屏/ScreenRecording/ScreenRecording/Resources/MouseLeftImg.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/A-Grass-Code/OpenDemo/3d73ac75a1df53019b888933c9243c5d24425970/录屏/ScreenRecording/ScreenRecording/Resources/MouseLeftImg.ico -------------------------------------------------------------------------------- /录屏/ScreenRecording/ScreenRecording/Resources/MousePointerImg.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/A-Grass-Code/OpenDemo/3d73ac75a1df53019b888933c9243c5d24425970/录屏/ScreenRecording/ScreenRecording/Resources/MousePointerImg.ico -------------------------------------------------------------------------------- /录屏/ScreenRecording/ScreenRecording/Resources/MouseRightImg.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/A-Grass-Code/OpenDemo/3d73ac75a1df53019b888933c9243c5d24425970/录屏/ScreenRecording/ScreenRecording/Resources/MouseRightImg.ico -------------------------------------------------------------------------------- /录屏/ScreenRecording/ScreenRecording/Resources/MouseWheelImg.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/A-Grass-Code/OpenDemo/3d73ac75a1df53019b888933c9243c5d24425970/录屏/ScreenRecording/ScreenRecording/Resources/MouseWheelImg.ico -------------------------------------------------------------------------------- /录屏/ScreenRecording/ScreenRecording/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /汉字笔顺图/ChineseWords.gif.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31911.196 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChineseWords.gif", "ChineseWords.gif\ChineseWords.gif.csproj", "{66281B66-1A78-4014-BFA8-1E80F4E09A97}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {66281B66-1A78-4014-BFA8-1E80F4E09A97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {66281B66-1A78-4014-BFA8-1E80F4E09A97}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {66281B66-1A78-4014-BFA8-1E80F4E09A97}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {66281B66-1A78-4014-BFA8-1E80F4E09A97}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {880F31AE-B9B5-4CD3-98F8-EF6379EBFADB} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /汉字笔顺图/ChineseWords.gif/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /汉字笔顺图/ChineseWords.gif/CheckInternetTool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.Http; 3 | using System.Threading.Tasks; 4 | 5 | namespace ChineseWords.gif 6 | { 7 | /// 8 | /// 检查互联网 工具类 9 | /// 10 | public static class CheckInternetTool 11 | { 12 | private static readonly HttpClient _httpClient = new HttpClient(); 13 | 14 | /// 15 | /// 检查互联网是否可用 16 | /// 17 | /// 18 | public static async Task InternetIsUseableAsync() 19 | { 20 | try 21 | { 22 | var response = await _httpClient.GetAsync("https://www.baidu.com/"); 23 | return response.IsSuccessStatusCode; 24 | } 25 | catch (Exception) 26 | { 27 | return false; 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /汉字笔顺图/ChineseWords.gif/ChineseWords.gif.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {66281B66-1A78-4014-BFA8-1E80F4E09A97} 8 | WinExe 9 | ChineseWords.gif 10 | 汉字笔顺图 11 | v4.8 12 | 512 13 | true 14 | 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | Resources\Logo.ico 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | Form 55 | 56 | 57 | FormMain.cs 58 | 59 | 60 | 61 | 62 | FormMain.cs 63 | 64 | 65 | ResXFileCodeGenerator 66 | Resources.Designer.cs 67 | Designer 68 | 69 | 70 | True 71 | Resources.resx 72 | True 73 | 74 | 75 | SettingsSingleFileGenerator 76 | Settings.Designer.cs 77 | 78 | 79 | True 80 | Settings.settings 81 | True 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /汉字笔顺图/ChineseWords.gif/FormMain.Designer.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace ChineseWords.gif 3 | { 4 | partial class FormMain 5 | { 6 | /// 7 | /// 必需的设计器变量。 8 | /// 9 | private System.ComponentModel.IContainer components = null; 10 | 11 | /// 12 | /// 清理所有正在使用的资源。 13 | /// 14 | /// 如果应释放托管资源,为 true;否则为 false。 15 | protected override void Dispose(bool disposing) 16 | { 17 | if (disposing && (components != null)) 18 | { 19 | components.Dispose(); 20 | } 21 | base.Dispose(disposing); 22 | } 23 | 24 | #region Windows 窗体设计器生成的代码 25 | 26 | /// 27 | /// 设计器支持所需的方法 - 不要修改 28 | /// 使用代码编辑器修改此方法的内容。 29 | /// 30 | private void InitializeComponent() 31 | { 32 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMain)); 33 | this.label1 = new System.Windows.Forms.Label(); 34 | this.Txt_hanzi = new System.Windows.Forms.TextBox(); 35 | this.Btn_get = new System.Windows.Forms.Button(); 36 | this.Pic_Hanzi_gif = new System.Windows.Forms.PictureBox(); 37 | this.label2 = new System.Windows.Forms.Label(); 38 | this.statusStrip1 = new System.Windows.Forms.StatusStrip(); 39 | this.ToolStatus_msg = new System.Windows.Forms.ToolStripStatusLabel(); 40 | ((System.ComponentModel.ISupportInitialize)(this.Pic_Hanzi_gif)).BeginInit(); 41 | this.statusStrip1.SuspendLayout(); 42 | this.SuspendLayout(); 43 | // 44 | // label1 45 | // 46 | this.label1.AutoSize = true; 47 | this.label1.ForeColor = System.Drawing.Color.Blue; 48 | this.label1.Location = new System.Drawing.Point(12, 18); 49 | this.label1.Name = "label1"; 50 | this.label1.Size = new System.Drawing.Size(89, 20); 51 | this.label1.TabIndex = 0; 52 | this.label1.Text = "输入汉字"; 53 | // 54 | // Txt_hanzi 55 | // 56 | this.Txt_hanzi.Font = new System.Drawing.Font("楷体", 20F); 57 | this.Txt_hanzi.ForeColor = System.Drawing.Color.Red; 58 | this.Txt_hanzi.Location = new System.Drawing.Point(12, 51); 59 | this.Txt_hanzi.MaxLength = 10; 60 | this.Txt_hanzi.Name = "Txt_hanzi"; 61 | this.Txt_hanzi.Size = new System.Drawing.Size(125, 38); 62 | this.Txt_hanzi.TabIndex = 1; 63 | // 64 | // Btn_get 65 | // 66 | this.Btn_get.Enabled = false; 67 | this.Btn_get.ForeColor = System.Drawing.Color.Green; 68 | this.Btn_get.Location = new System.Drawing.Point(160, 51); 69 | this.Btn_get.Name = "Btn_get"; 70 | this.Btn_get.Size = new System.Drawing.Size(82, 38); 71 | this.Btn_get.TabIndex = 2; 72 | this.Btn_get.Text = "获 取"; 73 | this.Btn_get.UseVisualStyleBackColor = true; 74 | this.Btn_get.Click += new System.EventHandler(this.Btn_get_Click); 75 | // 76 | // Pic_Hanzi_gif 77 | // 78 | this.Pic_Hanzi_gif.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; 79 | this.Pic_Hanzi_gif.ImageLocation = ""; 80 | this.Pic_Hanzi_gif.Location = new System.Drawing.Point(12, 104); 81 | this.Pic_Hanzi_gif.Name = "Pic_Hanzi_gif"; 82 | this.Pic_Hanzi_gif.Size = new System.Drawing.Size(230, 230); 83 | this.Pic_Hanzi_gif.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; 84 | this.Pic_Hanzi_gif.TabIndex = 3; 85 | this.Pic_Hanzi_gif.TabStop = false; 86 | // 87 | // label2 88 | // 89 | this.label2.AutoSize = true; 90 | this.label2.Font = new System.Drawing.Font("楷体", 10F); 91 | this.label2.ForeColor = System.Drawing.Color.Olive; 92 | this.label2.Location = new System.Drawing.Point(107, 22); 93 | this.label2.Name = "label2"; 94 | this.label2.Size = new System.Drawing.Size(133, 14); 95 | this.label2.TabIndex = 4; 96 | this.label2.Text = "(只取第一个汉字)"; 97 | // 98 | // statusStrip1 99 | // 100 | this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 101 | this.ToolStatus_msg}); 102 | this.statusStrip1.Location = new System.Drawing.Point(0, 345); 103 | this.statusStrip1.Name = "statusStrip1"; 104 | this.statusStrip1.Size = new System.Drawing.Size(254, 22); 105 | this.statusStrip1.TabIndex = 5; 106 | this.statusStrip1.Text = "statusStrip1"; 107 | // 108 | // ToolStatus_msg 109 | // 110 | this.ToolStatus_msg.Name = "ToolStatus_msg"; 111 | this.ToolStatus_msg.Size = new System.Drawing.Size(56, 17); 112 | this.ToolStatus_msg.Text = "消息提示"; 113 | // 114 | // FormMain 115 | // 116 | this.AcceptButton = this.Btn_get; 117 | this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 20F); 118 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 119 | this.ClientSize = new System.Drawing.Size(254, 367); 120 | this.Controls.Add(this.statusStrip1); 121 | this.Controls.Add(this.label2); 122 | this.Controls.Add(this.Pic_Hanzi_gif); 123 | this.Controls.Add(this.Btn_get); 124 | this.Controls.Add(this.Txt_hanzi); 125 | this.Controls.Add(this.label1); 126 | this.Font = new System.Drawing.Font("楷体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 127 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; 128 | this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); 129 | this.Margin = new System.Windows.Forms.Padding(4); 130 | this.MaximizeBox = false; 131 | this.Name = "FormMain"; 132 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 133 | this.Text = "汉字笔顺图"; 134 | this.Load += new System.EventHandler(this.FormMain_Load); 135 | ((System.ComponentModel.ISupportInitialize)(this.Pic_Hanzi_gif)).EndInit(); 136 | this.statusStrip1.ResumeLayout(false); 137 | this.statusStrip1.PerformLayout(); 138 | this.ResumeLayout(false); 139 | this.PerformLayout(); 140 | 141 | } 142 | 143 | #endregion 144 | 145 | private System.Windows.Forms.Label label1; 146 | private System.Windows.Forms.TextBox Txt_hanzi; 147 | private System.Windows.Forms.Button Btn_get; 148 | private System.Windows.Forms.PictureBox Pic_Hanzi_gif; 149 | private System.Windows.Forms.Label label2; 150 | private System.Windows.Forms.StatusStrip statusStrip1; 151 | private System.Windows.Forms.ToolStripStatusLabel ToolStatus_msg; 152 | } 153 | } 154 | 155 | -------------------------------------------------------------------------------- /汉字笔顺图/ChineseWords.gif/FormMain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Net.Http; 8 | using System.Text; 9 | using System.Text.RegularExpressions; 10 | using System.Threading.Tasks; 11 | using System.Windows.Forms; 12 | 13 | namespace ChineseWords.gif 14 | { 15 | public partial class FormMain : Form 16 | { 17 | private HttpClient _httpClient = new HttpClient(); 18 | 19 | private string _currentHanzi = string.Empty; 20 | 21 | public FormMain() 22 | { 23 | InitializeComponent(); 24 | } 25 | 26 | private void FormMain_Load(object sender, EventArgs e) 27 | { 28 | this.ToolStatus_msg.Text = "正在检查网络..."; 29 | Task.Run(async () => 30 | { 31 | if (await CheckInternetTool.InternetIsUseableAsync()) 32 | { 33 | this.Invoke(new Action(() => 34 | { 35 | this.ToolStatus_msg.Text = "网络正常"; 36 | this.Btn_get.Enabled = true; 37 | })); 38 | } 39 | else 40 | { 41 | this.Invoke(new Action(() => 42 | { 43 | this.ToolStatus_msg.Text = "网络不可用"; 44 | this.Btn_get.Enabled = false; 45 | })); 46 | } 47 | }); 48 | } 49 | 50 | private void Btn_get_Click(object sender, EventArgs e) 51 | { 52 | this.Btn_get.Enabled = false; 53 | 54 | string hanzi = this.Txt_hanzi.Text.Trim(); 55 | if (string.IsNullOrWhiteSpace(hanzi) || hanzi.Length < 1) 56 | { 57 | MessageBox.Show("请输入一个有效汉字", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 58 | this.Btn_get.Enabled = true; 59 | return; 60 | } 61 | hanzi = hanzi.Substring(0, 1); 62 | 63 | if (hanzi == _currentHanzi) 64 | { 65 | this.Btn_get.Enabled = true; 66 | return; 67 | } 68 | else 69 | { 70 | _currentHanzi = hanzi; 71 | } 72 | 73 | Task.Run(async () => 74 | { 75 | string res = await _httpClient.GetStringAsync($"https://hanyu.baidu.com/s?wd={ hanzi }&ptype=zici&tn=sug_click"); 76 | res = Regex.Match(res, "id=\"word_bishun\".*?data-gif=\"(.*?)\"", RegexOptions.Singleline).Groups[1].Value.Trim(); 77 | return res; 78 | }).ContinueWith(t => 79 | { 80 | if (string.IsNullOrWhiteSpace(t.Result)) 81 | { 82 | this.Invoke(new Action(() => 83 | { 84 | MessageBox.Show("未能获取到汉字笔顺图,请检查", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 85 | this.Btn_get.Enabled = true; 86 | })); 87 | return; 88 | } 89 | 90 | this.BeginInvoke(new Action(s => 91 | { 92 | this.Btn_get.Enabled = true; 93 | this.Pic_Hanzi_gif.ImageLocation = s; 94 | }), t.Result); 95 | }); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /汉字笔顺图/ChineseWords.gif/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace ChineseWords.gif 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// 应用程序的主入口点。 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new FormMain()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /汉字笔顺图/ChineseWords.gif/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("ChineseWords.gif")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ChineseWords.gif")] 13 | [assembly: AssemblyCopyright("Copyright © 2021")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("66281b66-1a78-4014-bfa8-1e80f4e09a97")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 33 | //通过使用 "*",如下所示: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /汉字笔顺图/ChineseWords.gif/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace ChineseWords.gif.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// 一个强类型的资源类,用于查找本地化的字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// 返回此类使用的缓存的 ResourceManager 实例。 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ChineseWords.gif.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 重写当前线程的 CurrentUICulture 属性,对 51 | /// 使用此强类型资源类的所有资源查找执行重写。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// 查找 System.Drawing.Bitmap 类型的本地化资源。 65 | /// 66 | internal static System.Drawing.Bitmap Logo { 67 | get { 68 | object obj = ResourceManager.GetObject("Logo", resourceCulture); 69 | return ((System.Drawing.Bitmap)(obj)); 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /汉字笔顺图/ChineseWords.gif/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 122 | ..\Resources\Logo.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 123 | 124 | -------------------------------------------------------------------------------- /汉字笔顺图/ChineseWords.gif/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace ChineseWords.gif.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.2.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /汉字笔顺图/ChineseWords.gif/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /汉字笔顺图/ChineseWords.gif/Resources/Logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/A-Grass-Code/OpenDemo/3d73ac75a1df53019b888933c9243c5d24425970/汉字笔顺图/ChineseWords.gif/Resources/Logo.ico -------------------------------------------------------------------------------- /汉字笔顺图/ChineseWords.gif/Resources/Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/A-Grass-Code/OpenDemo/3d73ac75a1df53019b888933c9243c5d24425970/汉字笔顺图/ChineseWords.gif/Resources/Logo.png -------------------------------------------------------------------------------- /自动爬行者工具/AutoCrawlerTool/AutoCrawlerTool.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.2.32630.192 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BrowserCrawler", "BrowserCrawler\BrowserCrawler.csproj", "{2F329349-4295-40FD-9B6F-372E556C0877}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoCrawlerTool", "AutoCrawlerTool\AutoCrawlerTool.csproj", "{F6DD381C-970B-4602-9CDB-6225A06E5791}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {2F329349-4295-40FD-9B6F-372E556C0877}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {2F329349-4295-40FD-9B6F-372E556C0877}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {2F329349-4295-40FD-9B6F-372E556C0877}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {2F329349-4295-40FD-9B6F-372E556C0877}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {F6DD381C-970B-4602-9CDB-6225A06E5791}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {F6DD381C-970B-4602-9CDB-6225A06E5791}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {F6DD381C-970B-4602-9CDB-6225A06E5791}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {F6DD381C-970B-4602-9CDB-6225A06E5791}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {6540AE5B-5871-470F-9FDD-1A12C32AB24B} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /自动爬行者工具/AutoCrawlerTool/AutoCrawlerTool/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /自动爬行者工具/AutoCrawlerTool/AutoCrawlerTool/Common/CheckInternetTool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.Http; 3 | using System.Threading.Tasks; 4 | 5 | namespace AutoCrawlerTool.Common 6 | { 7 | /// 8 | /// 检查互联网 工具类 9 | /// 10 | public static class CheckInternetTool 11 | { 12 | private static readonly HttpClient _http = new HttpClient(); 13 | 14 | /// 15 | /// 检查互联网是否可用 16 | /// 17 | /// 18 | public static async Task InternetIsUseableAsync() 19 | { 20 | try 21 | { 22 | var response = await _http.GetAsync("https://www.baidu.com/"); 23 | return response.IsSuccessStatusCode; 24 | } 25 | catch (Exception) 26 | { 27 | return false; 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /自动爬行者工具/AutoCrawlerTool/AutoCrawlerTool/M3U8Video/VideoCollectorParams.cs: -------------------------------------------------------------------------------- 1 | using AutoCrawlerTool.Common; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Text; 6 | 7 | namespace AutoCrawlerTool.M3U8Video 8 | { 9 | internal class VideoCollectorParams 10 | { 11 | private static readonly string _videoCollectorParamsFilePath = 12 | $"{FilesTool.ProgramRootDirectoryOther("CollectorParamsConfig")}videoCollectorParams.json"; 13 | 14 | private static VideoCollectorParams _this = null; 15 | 16 | 17 | public static VideoCollectorParams GetParams() 18 | { 19 | if (_this == null) 20 | { 21 | if (File.Exists(_videoCollectorParamsFilePath)) 22 | { 23 | _this = JsonTool.JsonFileToObject(_videoCollectorParamsFilePath); 24 | } 25 | else 26 | { 27 | _this = new VideoCollectorParams(); 28 | } 29 | } 30 | return _this; 31 | } 32 | 33 | public static void SetParams(VideoCollectorParams collectorParams) 34 | { 35 | _this = collectorParams; 36 | JsonTool.ObjectToJsonFile(_this, _videoCollectorParamsFilePath); 37 | } 38 | 39 | 40 | public string ResourceUrl { get; set; } = string.Empty; 41 | 42 | public string ResourceDirectoryUrl { get; set; } = string.Empty; 43 | 44 | public string SaveDirectory { get; set; } = string.Empty; 45 | 46 | public string SaveName { get; set; } = string.Empty; 47 | 48 | public string M3u8UrlMatchReg { get; set; } = string.Empty; 49 | 50 | public int DownSpeedIndex { get; set; } = 2; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /自动爬行者工具/AutoCrawlerTool/AutoCrawlerTool/MainForm.Designer.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AutoCrawlerTool 3 | { 4 | partial class MainForm 5 | { 6 | /// 7 | /// Required designer variable. 8 | /// 9 | private System.ComponentModel.IContainer components = null; 10 | 11 | /// 12 | /// Clean up any resources being used. 13 | /// 14 | /// true if managed resources should be disposed; otherwise, false. 15 | protected override void Dispose(bool disposing) 16 | { 17 | if (disposing && (components != null)) 18 | { 19 | components.Dispose(); 20 | } 21 | base.Dispose(disposing); 22 | } 23 | 24 | #region Windows Form Designer generated code 25 | 26 | /// 27 | /// Required method for Designer support - do not modify 28 | /// the contents of this method with the code editor. 29 | /// 30 | private void InitializeComponent() 31 | { 32 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); 33 | this.toolStrip1 = new System.Windows.Forms.ToolStrip(); 34 | this.toolStripDropDownButton1 = new System.Windows.Forms.ToolStripButton(); 35 | this.toolStrip1.SuspendLayout(); 36 | this.SuspendLayout(); 37 | // 38 | // toolStrip1 39 | // 40 | this.toolStrip1.BackColor = System.Drawing.Color.White; 41 | this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 42 | this.toolStripDropDownButton1}); 43 | this.toolStrip1.Location = new System.Drawing.Point(0, 0); 44 | this.toolStrip1.Name = "toolStrip1"; 45 | this.toolStrip1.Size = new System.Drawing.Size(284, 25); 46 | this.toolStrip1.TabIndex = 0; 47 | this.toolStrip1.Text = "toolStrip1"; 48 | // 49 | // toolStripDropDownButton1 50 | // 51 | this.toolStripDropDownButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; 52 | this.toolStripDropDownButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripDropDownButton1.Image"))); 53 | this.toolStripDropDownButton1.ImageTransparentColor = System.Drawing.Color.Magenta; 54 | this.toolStripDropDownButton1.Name = "toolStripDropDownButton1"; 55 | this.toolStripDropDownButton1.Size = new System.Drawing.Size(72, 22); 56 | this.toolStripDropDownButton1.Text = "m3u8 视频"; 57 | this.toolStripDropDownButton1.Click += new System.EventHandler(this.ToolStripDropDownButton1_Click); 58 | // 59 | // MainForm 60 | // 61 | this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); 62 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 63 | this.BackColor = System.Drawing.SystemColors.Control; 64 | this.ClientSize = new System.Drawing.Size(284, 61); 65 | this.Controls.Add(this.toolStrip1); 66 | this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 67 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; 68 | this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); 69 | this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); 70 | this.MaximizeBox = false; 71 | this.MinimumSize = new System.Drawing.Size(300, 100); 72 | this.Name = "MainForm"; 73 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 74 | this.Text = "自动爬行者工具"; 75 | this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing); 76 | this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.MainForm_FormClosed); 77 | this.Load += new System.EventHandler(this.MainForm_Load); 78 | this.toolStrip1.ResumeLayout(false); 79 | this.toolStrip1.PerformLayout(); 80 | this.ResumeLayout(false); 81 | this.PerformLayout(); 82 | 83 | } 84 | 85 | #endregion 86 | 87 | private System.Windows.Forms.ToolStrip toolStrip1; 88 | private System.Windows.Forms.ToolStripButton toolStripDropDownButton1; 89 | } 90 | } 91 | 92 | -------------------------------------------------------------------------------- /自动爬行者工具/AutoCrawlerTool/AutoCrawlerTool/MainForm.cs: -------------------------------------------------------------------------------- 1 | using AutoCrawlerTool.Common; 2 | using AutoCrawlerTool.M3U8Video; 3 | using BrowserCrawler; 4 | using PuppeteerSharp; 5 | using System; 6 | using System.Drawing; 7 | using System.Threading.Tasks; 8 | using System.Windows.Forms; 9 | 10 | namespace AutoCrawlerTool 11 | { 12 | public partial class MainForm : Form 13 | { 14 | public MainForm() 15 | { 16 | InitializeComponent(); 17 | } 18 | 19 | 20 | private static LaunchOptions _launchOptions; 21 | 22 | private static Browser _browser; 23 | 24 | private static Page _page; 25 | 26 | private static LaunchOptions ChromiumOptions 27 | { 28 | get 29 | { 30 | if (_launchOptions == null) 31 | { 32 | _launchOptions = ChromiumBrowser.GetNativeChromiumBrowser(); 33 | #if DEBUG 34 | _launchOptions = ChromiumBrowser.GetNativeChromiumBrowser(ChromiumBrowser.NativeEdgePath, true); 35 | #endif 36 | } 37 | return _launchOptions; 38 | } 39 | } 40 | 41 | public static int CollectorFormCount = 0; 42 | 43 | public static async Task ChromiumAsync() 44 | { 45 | if (_browser == null || _browser.IsClosed) 46 | { 47 | _browser = await Puppeteer.LaunchAsync(ChromiumOptions); 48 | _page = await ChromiumBrowser.NewPageAndInitAsync(_browser); 49 | await _page.GoToAsync("https://www.baidu.com/"); 50 | } 51 | return _browser; 52 | } 53 | 54 | 55 | private void MainForm_Load(object sender, EventArgs e) 56 | { 57 | var p = this.Location; 58 | this.Location = new Point(p.X, 20); 59 | 60 | _ = Task.Run(async () => 61 | { 62 | bool isSucc = await CheckInternetTool.InternetIsUseableAsync(); 63 | if (!isSucc) 64 | { 65 | this.BeginInvoke(new Action(() => 66 | { 67 | MessageBox.Show("请检查网络", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 68 | })); 69 | } 70 | }); 71 | 72 | _ = Task.Run(async () => 73 | { 74 | while (true) 75 | { 76 | await Task.Delay(1000 * 60); 77 | GC.Collect(); 78 | } 79 | }); 80 | } 81 | 82 | private void MainForm_FormClosed(object sender, FormClosedEventArgs e) 83 | { 84 | this.Invoke(new Action(async () => 85 | { 86 | await ((_page?.CloseAsync()) ?? Task.CompletedTask); 87 | _page?.Dispose(); 88 | 89 | await ((_browser?.CloseAsync()) ?? Task.CompletedTask); 90 | _browser?.Dispose(); 91 | })); 92 | Environment.Exit(0); 93 | } 94 | 95 | 96 | private void ToolStripDropDownButton1_Click(object sender, EventArgs e) 97 | { 98 | VideoCollectorForm form = new VideoCollectorForm(); 99 | form.Show(); 100 | CollectorFormCount++; 101 | } 102 | 103 | private void MainForm_FormClosing(object sender, FormClosingEventArgs e) 104 | { 105 | if (CollectorFormCount > 0) 106 | { 107 | if (MessageBox.Show("存在未关闭的采集器窗口,可能采集任务尚未完成!\n确定要强制关闭吗?", 108 | "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes) 109 | { 110 | e.Cancel = true; 111 | } 112 | } 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /自动爬行者工具/AutoCrawlerTool/AutoCrawlerTool/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace AutoCrawlerTool 8 | { 9 | internal static class Program 10 | { 11 | /// 12 | /// 应用程序的主入口点。 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new MainForm()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /自动爬行者工具/AutoCrawlerTool/AutoCrawlerTool/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("AutoCrawlerTool")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("AutoCrawlerTool")] 13 | [assembly: AssemblyCopyright("Copyright © 2022")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("f6dd381c-970b-4602-9cdb-6225a06e5791")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 33 | //通过使用 "*",如下所示: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /自动爬行者工具/AutoCrawlerTool/AutoCrawlerTool/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本: 4.0.30319.42000 5 | // 6 | // 对此文件的更改可能导致不正确的行为,如果 7 | // 重新生成代码,则所做更改将丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace AutoCrawlerTool.Properties 12 | { 13 | 14 | 15 | /// 16 | /// 强类型资源类,用于查找本地化字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// 返回此类使用的缓存 ResourceManager 实例。 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AutoCrawlerTool.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// 重写当前线程的 CurrentUICulture 属性,对 56 | /// 使用此强类型资源类的所有资源查找执行重写。 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /自动爬行者工具/AutoCrawlerTool/AutoCrawlerTool/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /自动爬行者工具/AutoCrawlerTool/AutoCrawlerTool/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace AutoCrawlerTool.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /自动爬行者工具/AutoCrawlerTool/AutoCrawlerTool/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /自动爬行者工具/AutoCrawlerTool/AutoCrawlerTool/logo/暗影蜘蛛侠.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/A-Grass-Code/OpenDemo/3d73ac75a1df53019b888933c9243c5d24425970/自动爬行者工具/AutoCrawlerTool/AutoCrawlerTool/logo/暗影蜘蛛侠.ico -------------------------------------------------------------------------------- /自动爬行者工具/AutoCrawlerTool/AutoCrawlerTool/logo/视频.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/A-Grass-Code/OpenDemo/3d73ac75a1df53019b888933c9243c5d24425970/自动爬行者工具/AutoCrawlerTool/AutoCrawlerTool/logo/视频.ico -------------------------------------------------------------------------------- /自动爬行者工具/AutoCrawlerTool/AutoCrawlerTool/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /自动爬行者工具/AutoCrawlerTool/BrowserCrawler/BrowserCrawler.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /自动爬行者工具/AutoCrawlerTool/BrowserCrawler/OSHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BrowserCrawler 6 | { 7 | static class OSHelper 8 | { 9 | /// 10 | /// 判断当前系统是否是 Win7 以下(包含 Win7) 11 | /// 参考: 12 | /// 1. https://www.cnblogs.com/yinghualuowu/p/9703266.html 13 | /// 2. https://docs.microsoft.com/zh-cn/windows/desktop/SysInfo/operating-system-version 14 | /// 15 | /// 16 | public static bool IsWin7Under() 17 | { 18 | var p = Environment.OSVersion.Platform; 19 | var a = Environment.OSVersion.Version.Major; 20 | var i = Environment.OSVersion.Version.Minor; 21 | if ((p == PlatformID.Win32NT) && (Convert.ToDouble($"{a}.{i}") <= 6.1)) 22 | { 23 | return true; 24 | } 25 | else 26 | { 27 | return false; 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /节日倒计时/ChineseNewYear/ChineseNewYear.Countdown/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /节日倒计时/ChineseNewYear/ChineseNewYear.Countdown/ChineseNewYear.Countdown.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {0B9AD579-2C0E-4C34-80D5-04A3FB6B6F79} 8 | WinExe 9 | ChineseNewYear.Countdown 10 | 节日倒计时 11 | v4.8 12 | 512 13 | true 14 | 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | logo.ico 37 | 38 | 39 | 40 | 41 | 42 | ..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | Form 60 | 61 | 62 | FrmMain.cs 63 | 64 | 65 | Form 66 | 67 | 68 | FrmUpdateDate.cs 69 | 70 | 71 | 72 | 73 | FrmMain.cs 74 | 75 | 76 | FrmUpdateDate.cs 77 | 78 | 79 | ResXFileCodeGenerator 80 | Resources.Designer.cs 81 | Designer 82 | 83 | 84 | True 85 | Resources.resx 86 | True 87 | 88 | 89 | 90 | SettingsSingleFileGenerator 91 | Settings.Designer.cs 92 | 93 | 94 | True 95 | Settings.settings 96 | True 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /节日倒计时/ChineseNewYear/ChineseNewYear.Countdown/Countdown.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace ChineseNewYear.Countdown 9 | { 10 | /// 11 | /// 倒计时 类 12 | /// 13 | internal static class Countdown 14 | { 15 | /// 16 | /// FestivalInfo.dat 节日信息 文件绝对路径 17 | /// 18 | public static readonly string ConfigPath = $"{FilesTool.ProgramRootDirectory}FestivalInfo.dat"; 19 | 20 | /// 21 | /// 获取节日信息( 节日名称 ,日期时间 ) 22 | /// 23 | /// 24 | public static (string FestivalName, DateTime FestivalDate) GetFestivalInfo() 25 | { 26 | try 27 | { 28 | var festivalInfo = FilesTool.ReadFileToAll(ConfigPath).Split(new string[] { Environment.NewLine }, 29 | StringSplitOptions.RemoveEmptyEntries); 30 | return (festivalInfo[0].Trim(), Convert.ToDateTime(festivalInfo[1].Trim())); 31 | } 32 | catch (Exception) 33 | { 34 | return (string.Empty, default(DateTime)); 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /节日倒计时/ChineseNewYear/ChineseNewYear.Countdown/DateTimeTool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ChineseNewYear.Countdown 8 | { 9 | /// 10 | /// 一个简单的日期时间工具类 11 | /// 12 | public static class DateTimeTool 13 | { 14 | /// 计算两个日期时间的间隔(返回一个动态对象,包含 年、月、日、时、分、秒 的间隔) 15 | /// 16 | /// 开始时间 17 | /// 结束时间(必须大于开始时间) 18 | /// 19 | public static dynamic ComputeHowLong(DateTime beginTime, DateTime endTime) 20 | { 21 | //创建匿名对象 22 | dynamic HowLong = new System.Dynamic.ExpandoObject(); 23 | 24 | if (endTime <= beginTime) 25 | { 26 | HowLong.cYear = 0; 27 | HowLong.cMonth = 0; 28 | HowLong.cDay = 0; 29 | HowLong.cHour = 0; 30 | HowLong.cMinute = 0; 31 | HowLong.cSecond = 0; 32 | 33 | HowLong.Days = 0; 34 | HowLong.Hours = 0; 35 | HowLong.Minutes = 0; 36 | HowLong.Seconds = 0; 37 | 38 | return HowLong; 39 | } 40 | 41 | #region 算法 42 | 43 | //// 结束日期时间 44 | int n_y = endTime.Year; 45 | int n_M = endTime.Month; 46 | int n_d = endTime.Day; 47 | int n_H = endTime.Hour; 48 | int n_m = endTime.Minute; 49 | int n_s = endTime.Second; 50 | 51 | //// 开始日期时间 52 | int b_y = beginTime.Year; 53 | int b_M = beginTime.Month; 54 | int b_d = beginTime.Day; 55 | int b_H = beginTime.Hour; 56 | int b_m = beginTime.Minute; 57 | int b_s = beginTime.Second; 58 | 59 | //// 相差日期时间 60 | int c_y; 61 | int c_M; 62 | int c_d; 63 | int c_H; 64 | int c_m; 65 | int c_s; 66 | 67 | //// 计算秒 68 | if (n_s < b_s) 69 | { 70 | c_s = n_s + 60 - b_s; 71 | n_m--; 72 | } 73 | else 74 | { 75 | c_s = n_s - b_s; 76 | } 77 | //// 计算分 78 | if (n_m < b_m) 79 | { 80 | c_m = n_m + 60 - b_m; 81 | n_H--; 82 | } 83 | else 84 | { 85 | c_m = n_m - b_m; 86 | } 87 | //// 计算时 88 | if (n_H < b_H) 89 | { 90 | c_H = n_H + 24 - b_H; 91 | n_d--; 92 | } 93 | else 94 | { 95 | c_H = n_H - b_H; 96 | } 97 | //// 计算天 98 | if (n_d < b_d) 99 | { 100 | switch (n_M - 1) 101 | { 102 | case 0: 103 | case 1: 104 | case 3: 105 | case 5: 106 | case 7: 107 | case 8: 108 | case 10: 109 | case 12: 110 | c_d = n_d + 31 - b_d; 111 | break; 112 | case 2: 113 | if ((n_y % 4 == 0 && n_y % 100 != 0) || n_y % 400 == 0) 114 | { 115 | c_d = n_d + 29 - b_d; 116 | } 117 | else 118 | { 119 | c_d = n_d + 28 - b_d; 120 | } 121 | break; 122 | default: 123 | c_d = n_d + 30 - b_d; 124 | break; 125 | }; 126 | n_M--; 127 | } 128 | else 129 | { 130 | c_d = n_d - b_d; 131 | } 132 | //// 计算月 133 | if (n_M < b_M) 134 | { 135 | c_M = n_M + 12 - b_M; 136 | n_y--; 137 | } 138 | else 139 | { 140 | c_M = n_M - b_M; 141 | } 142 | //// 计算年 143 | c_y = n_y - b_y; 144 | 145 | if (c_d >= 30) 146 | { 147 | c_d = 0; 148 | c_M++; 149 | } 150 | 151 | if (c_M >= 12) 152 | { 153 | c_M = 0; 154 | c_y++; 155 | } 156 | 157 | #endregion 158 | 159 | HowLong.cYear = c_y; 160 | HowLong.cMonth = c_M; 161 | HowLong.cDay = c_d; 162 | HowLong.cHour = c_H; 163 | HowLong.cMinute = c_m; 164 | HowLong.cSecond = c_s; 165 | 166 | TimeSpan ts = endTime - beginTime; 167 | HowLong.Days = ts.Days; 168 | HowLong.Hours = ts.Hours; 169 | HowLong.Minutes = ts.Minutes; 170 | HowLong.Seconds = ts.Seconds; 171 | 172 | return HowLong; 173 | } 174 | 175 | 176 | /// 177 | /// DateTime 格式化为精确到毫秒6位数 178 | /// 格式: "yyyy-MM-dd HH:mm:ss.ffffff" 179 | /// 180 | /// 181 | /// 182 | public static string FormatCorrectToMs6(this DateTime dateTime) 183 | { 184 | return dateTime.ToString("yyyy-MM-dd HH:mm:ss.ffffff"); 185 | } 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /节日倒计时/ChineseNewYear/ChineseNewYear.Countdown/FrmMain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using System.Windows.Forms; 11 | 12 | namespace ChineseNewYear.Countdown 13 | { 14 | public partial class FrmMain : Form 15 | { 16 | #region 单例模式 17 | 18 | private FrmMain() 19 | { 20 | InitializeComponent(); 21 | } 22 | 23 | private static readonly object _lockCreateInstrance = new object(); 24 | 25 | private static FrmMain _thisForm = null; 26 | 27 | public static FrmMain CreateInstrance() 28 | { 29 | if (_thisForm == null || _thisForm.IsDisposed) 30 | { 31 | lock (_lockCreateInstrance) 32 | { 33 | if (_thisForm == null || _thisForm.IsDisposed) 34 | { 35 | _thisForm = new FrmMain(); 36 | } 37 | } 38 | } 39 | return _thisForm; 40 | } 41 | 42 | #endregion 43 | 44 | 45 | /// 46 | /// 是否正在运行倒计时 47 | /// 48 | private bool IsRunningCountdown { get; set; } = false; 49 | 50 | /// 51 | /// 节日信息 52 | /// 53 | internal (string FestivalName, DateTime FestivalDate) FestivalInfo { get; set; } 54 | 55 | 56 | /// 57 | /// 启动倒计时 58 | /// 59 | internal void StartCountdown() 60 | { 61 | if (IsRunningCountdown) 62 | { 63 | return; 64 | } 65 | 66 | Task.Run(async () => 67 | { 68 | IsRunningCountdown = true; 69 | FestivalInfo = Countdown.GetFestivalInfo(); 70 | while (true) 71 | { 72 | try 73 | { 74 | this.BeginInvoke(new Action(() => 75 | { 76 | if (FestivalInfo.FestivalDate.Year < DateTime.Now.Year || string.IsNullOrWhiteSpace(FestivalInfo.FestivalName)) 77 | { 78 | this.lab_year.Text = $"距离 ... 年"; 79 | this.lab_festivalName.Text = "... 节日"; 80 | this.lab_countdown.Text = $"{0}天 {0}时 {0}分 {0}秒"; 81 | } 82 | else 83 | { 84 | dynamic dyData = DateTimeTool.ComputeHowLong(DateTime.Now, FestivalInfo.FestivalDate); 85 | this.lab_year.Text = $"距离 {FestivalInfo.FestivalDate.Year} 年"; 86 | this.lab_festivalName.Text = FestivalInfo.FestivalName; 87 | this.lab_festivalDate.Text = FestivalInfo.FestivalDate.ToString("yyyy年M月d日"); 88 | this.lab_countdown.Text = $"{dyData.Days}天 {dyData.Hours}时 {dyData.Minutes}分 {dyData.Seconds}秒"; 89 | } 90 | })); 91 | } 92 | catch (Exception) 93 | { 94 | IsRunningCountdown = false; 95 | this.BeginInvoke(new Action(() => 96 | { 97 | MessageBox.Show("请更新春节日期!", "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 98 | this.toolStripButton2.Enabled = !IsRunningCountdown; 99 | })); 100 | break; 101 | } 102 | finally 103 | { 104 | this.BeginInvoke(new Action(() => 105 | { 106 | this.toolStripButton2.Enabled = !IsRunningCountdown; 107 | })); 108 | } 109 | await Task.Delay(100); 110 | } 111 | }); 112 | } 113 | 114 | 115 | private void Form1_Load(object sender, EventArgs e) 116 | { 117 | StartCountdown(); 118 | } 119 | 120 | private void Form1_FormClosed(object sender, FormClosedEventArgs e) 121 | { 122 | Environment.Exit(0); 123 | } 124 | 125 | private void toolStripButton1_Click(object sender, EventArgs e) 126 | { 127 | FrmUpdateDate frm = FrmUpdateDate.CreateInstrance(); 128 | frm.MainLocation = this.Location; 129 | frm.MainSize = this.Size; 130 | frm.ShowDialog(); 131 | } 132 | 133 | private void toolStripButton2_Click(object sender, EventArgs e) 134 | { 135 | StartCountdown(); 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /节日倒计时/ChineseNewYear/ChineseNewYear.Countdown/FrmUpdateDate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows.Forms; 10 | 11 | namespace ChineseNewYear.Countdown 12 | { 13 | public partial class FrmUpdateDate : Form 14 | { 15 | #region 单例模式 16 | 17 | private FrmUpdateDate() 18 | { 19 | InitializeComponent(); 20 | } 21 | 22 | private static readonly object _lockCreateInstrance = new object(); 23 | 24 | private static FrmUpdateDate _thisForm = null; 25 | 26 | public static FrmUpdateDate CreateInstrance() 27 | { 28 | if (_thisForm == null || _thisForm.IsDisposed) 29 | { 30 | lock (_lockCreateInstrance) 31 | { 32 | if (_thisForm == null || _thisForm.IsDisposed) 33 | { 34 | _thisForm = new FrmUpdateDate(); 35 | } 36 | } 37 | } 38 | return _thisForm; 39 | } 40 | 41 | #endregion 42 | 43 | 44 | internal Point MainLocation { get; set; } 45 | 46 | internal Size MainSize { get; set; } 47 | 48 | 49 | private void FrmUpdateDate_Load(object sender, EventArgs e) 50 | { 51 | this.Location = new Point(MainLocation.X + MainSize.Width + 20, MainLocation.Y); 52 | try 53 | { 54 | (string FestivalName, DateTime FestivalDate) festivalInfo = Countdown.GetFestivalInfo(); 55 | this.txt_festivalName.Text = festivalInfo.FestivalName; 56 | this.date_festivalDate.Value = festivalInfo.FestivalDate; 57 | } 58 | catch (Exception) 59 | { 60 | this.txt_festivalName.Text = string.Empty; 61 | this.date_festivalDate.Value = DateTime.Now; 62 | } 63 | } 64 | 65 | private void button1_Click(object sender, EventArgs e) 66 | { 67 | if (string.IsNullOrWhiteSpace(this.txt_festivalName.Text)) 68 | { 69 | MessageBox.Show("请输入“节日名称”!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 70 | return; 71 | } 72 | 73 | try 74 | { 75 | FilesTool.WriteFileCreate(Countdown.ConfigPath, 76 | $"{this.txt_festivalName.Text.Trim()}{Environment.NewLine}{this.date_festivalDate.Value:yyyy-MM-dd}"); 77 | this.Close(); 78 | 79 | var frm = FrmMain.CreateInstrance(); 80 | frm.FestivalInfo = Countdown.GetFestivalInfo(); 81 | frm.StartCountdown(); 82 | } 83 | catch (Exception) 84 | { 85 | MessageBox.Show("保存失败,请重新操作!", "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 86 | } 87 | } 88 | 89 | private void button2_Click(object sender, EventArgs e) 90 | { 91 | this.Close(); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /节日倒计时/ChineseNewYear/ChineseNewYear.Countdown/FrmUpdateDate.designer.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace ChineseNewYear.Countdown 3 | { 4 | partial class FrmUpdateDate 5 | { 6 | /// 7 | /// Required designer variable. 8 | /// 9 | private System.ComponentModel.IContainer components = null; 10 | 11 | /// 12 | /// Clean up any resources being used. 13 | /// 14 | /// true if managed resources should be disposed; otherwise, false. 15 | protected override void Dispose(bool disposing) 16 | { 17 | if (disposing && (components != null)) 18 | { 19 | components.Dispose(); 20 | } 21 | base.Dispose(disposing); 22 | } 23 | 24 | #region Windows Form Designer generated code 25 | 26 | /// 27 | /// Required method for Designer support - do not modify 28 | /// the contents of this method with the code editor. 29 | /// 30 | private void InitializeComponent() 31 | { 32 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmUpdateDate)); 33 | this.date_festivalDate = new System.Windows.Forms.DateTimePicker(); 34 | this.label1 = new System.Windows.Forms.Label(); 35 | this.button1 = new System.Windows.Forms.Button(); 36 | this.button2 = new System.Windows.Forms.Button(); 37 | this.label2 = new System.Windows.Forms.Label(); 38 | this.txt_festivalName = new System.Windows.Forms.TextBox(); 39 | this.SuspendLayout(); 40 | // 41 | // date_festivalDate 42 | // 43 | this.date_festivalDate.CustomFormat = ""; 44 | this.date_festivalDate.Location = new System.Drawing.Point(16, 73); 45 | this.date_festivalDate.Margin = new System.Windows.Forms.Padding(2, 3, 2, 3); 46 | this.date_festivalDate.Name = "date_festivalDate"; 47 | this.date_festivalDate.Size = new System.Drawing.Size(213, 25); 48 | this.date_festivalDate.TabIndex = 3; 49 | // 50 | // label1 51 | // 52 | this.label1.AutoSize = true; 53 | this.label1.Location = new System.Drawing.Point(12, 42); 54 | this.label1.Name = "label1"; 55 | this.label1.Size = new System.Drawing.Size(230, 19); 56 | this.label1.TabIndex = 2; 57 | this.label1.Text = "选择日期(农历春节对应的公历日期)"; 58 | // 59 | // button1 60 | // 61 | this.button1.ForeColor = System.Drawing.Color.Blue; 62 | this.button1.Location = new System.Drawing.Point(16, 107); 63 | this.button1.Name = "button1"; 64 | this.button1.Size = new System.Drawing.Size(75, 30); 65 | this.button1.TabIndex = 4; 66 | this.button1.Text = "保 存"; 67 | this.button1.UseVisualStyleBackColor = true; 68 | this.button1.Click += new System.EventHandler(this.button1_Click); 69 | // 70 | // button2 71 | // 72 | this.button2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); 73 | this.button2.Location = new System.Drawing.Point(154, 107); 74 | this.button2.Name = "button2"; 75 | this.button2.Size = new System.Drawing.Size(75, 30); 76 | this.button2.TabIndex = 5; 77 | this.button2.Text = "取 消"; 78 | this.button2.UseVisualStyleBackColor = true; 79 | this.button2.Click += new System.EventHandler(this.button2_Click); 80 | // 81 | // label2 82 | // 83 | this.label2.AutoSize = true; 84 | this.label2.Location = new System.Drawing.Point(12, 9); 85 | this.label2.Name = "label2"; 86 | this.label2.Size = new System.Drawing.Size(61, 19); 87 | this.label2.TabIndex = 0; 88 | this.label2.Text = "节日名称"; 89 | // 90 | // txt_festivalName 91 | // 92 | this.txt_festivalName.Location = new System.Drawing.Point(79, 6); 93 | this.txt_festivalName.MaxLength = 5; 94 | this.txt_festivalName.Name = "txt_festivalName"; 95 | this.txt_festivalName.Size = new System.Drawing.Size(150, 25); 96 | this.txt_festivalName.TabIndex = 1; 97 | // 98 | // FrmUpdateDate 99 | // 100 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 19F); 101 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 102 | this.ClientSize = new System.Drawing.Size(246, 146); 103 | this.Controls.Add(this.txt_festivalName); 104 | this.Controls.Add(this.label2); 105 | this.Controls.Add(this.button2); 106 | this.Controls.Add(this.button1); 107 | this.Controls.Add(this.label1); 108 | this.Controls.Add(this.date_festivalDate); 109 | this.Font = new System.Drawing.Font("微软雅黑", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 110 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; 111 | this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); 112 | this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); 113 | this.MaximizeBox = false; 114 | this.Name = "FrmUpdateDate"; 115 | this.Text = "更新节日"; 116 | this.Load += new System.EventHandler(this.FrmUpdateDate_Load); 117 | this.ResumeLayout(false); 118 | this.PerformLayout(); 119 | 120 | } 121 | 122 | #endregion 123 | 124 | private System.Windows.Forms.DateTimePicker date_festivalDate; 125 | private System.Windows.Forms.Label label1; 126 | private System.Windows.Forms.Button button1; 127 | private System.Windows.Forms.Button button2; 128 | private System.Windows.Forms.Label label2; 129 | private System.Windows.Forms.TextBox txt_festivalName; 130 | } 131 | } -------------------------------------------------------------------------------- /节日倒计时/ChineseNewYear/ChineseNewYear.Countdown/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace ChineseNewYear.Countdown 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// 应用程序的主入口点。 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(FrmMain.CreateInstrance()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /节日倒计时/ChineseNewYear/ChineseNewYear.Countdown/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("ChineseNewYear.Countdown")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ChineseNewYear.Countdown")] 13 | [assembly: AssemblyCopyright("Copyright © 2021")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("0b9ad579-2c0e-4c34-80d5-04a3fb6b6f79")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 33 | //通过使用 "*",如下所示: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /节日倒计时/ChineseNewYear/ChineseNewYear.Countdown/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace ChineseNewYear.Countdown.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// 一个强类型的资源类,用于查找本地化的字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// 返回此类使用的缓存的 ResourceManager 实例。 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ChineseNewYear.Countdown.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 重写当前线程的 CurrentUICulture 属性,对 51 | /// 使用此强类型资源类的所有资源查找执行重写。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /节日倒计时/ChineseNewYear/ChineseNewYear.Countdown/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /节日倒计时/ChineseNewYear/ChineseNewYear.Countdown/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace ChineseNewYear.Countdown.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.2.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /节日倒计时/ChineseNewYear/ChineseNewYear.Countdown/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /节日倒计时/ChineseNewYear/ChineseNewYear.Countdown/logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/A-Grass-Code/OpenDemo/3d73ac75a1df53019b888933c9243c5d24425970/节日倒计时/ChineseNewYear/ChineseNewYear.Countdown/logo.ico -------------------------------------------------------------------------------- /节日倒计时/ChineseNewYear/ChineseNewYear.Countdown/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /节日倒计时/ChineseNewYear/ChineseNewYear.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30804.86 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChineseNewYear.Countdown", "ChineseNewYear.Countdown\ChineseNewYear.Countdown.csproj", "{0B9AD579-2C0E-4C34-80D5-04A3FB6B6F79}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {0B9AD579-2C0E-4C34-80D5-04A3FB6B6F79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {0B9AD579-2C0E-4C34-80D5-04A3FB6B6F79}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {0B9AD579-2C0E-4C34-80D5-04A3FB6B6F79}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {0B9AD579-2C0E-4C34-80D5-04A3FB6B6F79}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {E7942638-8DED-4888-825B-4FE0E6174572} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /节点找出最短的路/ConsoleDemo/ConsoleDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31424.327 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleDemo", "ConsoleDemo\ConsoleDemo.csproj", "{E564B73C-10F1-4FF7-BA1D-CBEF87C4063D}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {E564B73C-10F1-4FF7-BA1D-CBEF87C4063D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {E564B73C-10F1-4FF7-BA1D-CBEF87C4063D}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {E564B73C-10F1-4FF7-BA1D-CBEF87C4063D}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {E564B73C-10F1-4FF7-BA1D-CBEF87C4063D}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {1DE2AB08-8895-4A5F-916D-99EE2FB37D23} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /节点找出最短的路/ConsoleDemo/ConsoleDemo/ConsoleDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /节点找出最短的路/ConsoleDemo/ConsoleDemo/Node.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace ConsoleDemo 4 | { 5 | /// 6 | /// 节点 7 | /// 8 | public class Node 9 | { 10 | public Node(string nodeName) 11 | { 12 | this.NodeName = nodeName; 13 | } 14 | 15 | public Node(string nodeName, Dictionary everyPath) 16 | { 17 | this.NodeName = nodeName; 18 | this.EveryPath = everyPath; 19 | } 20 | 21 | 22 | /// 23 | /// 节点名 24 | /// 25 | public string NodeName { get; set; } 26 | 27 | /// 28 | /// 当前节点的每一条路径 29 | /// 字典集合中的 key 是当前节点所指向的下一个节点名 30 | /// 字典集合中的 value 是两个节点之间的距离 31 | /// 32 | public Dictionary EveryPath { get; set; } = new Dictionary(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /节点找出最短的路/ConsoleDemo/ConsoleDemo/NodePath.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace ConsoleDemo 7 | { 8 | /// 9 | /// 节点路径 10 | /// 11 | public class NodePath 12 | { 13 | public NodePath(Dictionary nodes) 14 | { 15 | this.Nodes = nodes; 16 | } 17 | 18 | 19 | private readonly StringBuilder _sbPath = new StringBuilder(); 20 | 21 | private readonly List _pathList = new List(); 22 | 23 | private readonly Dictionary _pathLengthDic = new Dictionary(); 24 | 25 | /// 26 | /// 用来存放所有的节点 27 | /// 28 | public Dictionary Nodes { get; set; } 29 | 30 | 31 | /// 32 | /// 找出 路 33 | /// 34 | /// 35 | /// 36 | private void FindoutPath(string startNode, string endNode) 37 | { 38 | if (!Nodes.ContainsKey(startNode)) 39 | { 40 | return; 41 | } 42 | 43 | if (startNode == endNode) 44 | { 45 | _sbPath.Append($"-{endNode}"); 46 | _sbPath.AppendLine(); 47 | return; 48 | } 49 | 50 | var nodePath = Nodes[startNode].EveryPath; 51 | if (nodePath == null || nodePath.Count < 1) 52 | { 53 | _sbPath.AppendLine(); 54 | return; 55 | } 56 | else 57 | { 58 | foreach (var item in nodePath) 59 | { 60 | _sbPath.Append($"-{startNode}"); 61 | FindoutPath(item.Key, endNode); 62 | } 63 | } 64 | } 65 | 66 | /// 67 | /// 获取两节点之间的所有路径 68 | /// 69 | /// 70 | /// 71 | /// 72 | private bool GetAllPath(string startNode, string endNode) 73 | { 74 | _sbPath.Clear(); 75 | _pathList.Clear(); 76 | _pathLengthDic.Clear(); 77 | 78 | FindoutPath(startNode, endNode); 79 | 80 | var pathArr = _sbPath.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); 81 | foreach (var item in pathArr) 82 | { 83 | if (!item.Contains($"-{startNode}")) 84 | { 85 | _pathList.Add($"-{startNode}{item}"); 86 | } 87 | else 88 | { 89 | _pathList.Add(item); 90 | } 91 | } 92 | 93 | for (int i = 0; i < _pathList.Count; i++) 94 | { 95 | string path = _pathList[i].Remove(0, 1); 96 | if (path.Contains($"{startNode}-") && path.Contains($"-{endNode}")) 97 | { 98 | _pathList[i] = path; 99 | } 100 | else 101 | { 102 | _pathList[i] = null; 103 | } 104 | } 105 | 106 | _pathList.RemoveAll(x => 107 | { 108 | return string.IsNullOrWhiteSpace(x); 109 | }); 110 | 111 | return _pathList.Count > 0; 112 | } 113 | 114 | 115 | /// 116 | /// 计算最短路径 117 | /// 118 | /// 119 | /// 120 | /// 121 | public (string Path, double Length, List> AllPath) ComputeShortestPath(string startNode, string endNode) 122 | { 123 | if (!GetAllPath(startNode, endNode)) 124 | { 125 | return (string.Empty, -1, null); 126 | } 127 | 128 | foreach (var item in _pathList) 129 | { 130 | var nodeIds = item.Split("-", StringSplitOptions.RemoveEmptyEntries); 131 | string tempNodeId = startNode; 132 | double length = 0.0; 133 | foreach (var nodeId in nodeIds) 134 | { 135 | if (nodeId == startNode) 136 | { 137 | continue; 138 | } 139 | 140 | length += Nodes[tempNodeId].EveryPath[nodeId]; 141 | 142 | tempNodeId = nodeId; 143 | } 144 | _pathLengthDic.Add(item, length); 145 | } 146 | 147 | var temp = _pathLengthDic.OrderBy(x => x.Value).ToList(); 148 | 149 | return (temp[0].Key, temp[0].Value, temp); 150 | } 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /节点找出最短的路/ConsoleDemo/ConsoleDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace ConsoleDemo 5 | { 6 | class Program 7 | { 8 | [STAThread] 9 | static void Main(string[] args) 10 | { 11 | Console.WriteLine("Hello World!"); 12 | Console.WriteLine(); 13 | Console.WriteLine(); 14 | 15 | #region 初始化一些节点数据 16 | Node a = new Node("a"); 17 | a.EveryPath.Add("b", 2); 18 | a.EveryPath.Add("c", 6); 19 | 20 | Node b = new Node("b"); 21 | b.EveryPath.Add("e", 5); 22 | b.EveryPath.Add("d", 5); 23 | 24 | Node c = new Node("c"); 25 | c.EveryPath.Add("e", 3); 26 | c.EveryPath.Add("f", 7); 27 | c.EveryPath.Add("d", 8); 28 | 29 | Node d = new Node("d"); 30 | d.EveryPath.Add("f", 10); 31 | 32 | Node e = new Node("e"); 33 | e.EveryPath.Add("f", 7); 34 | 35 | Node f = new Node("f"); 36 | #endregion 37 | 38 | Dictionary nodes = new Dictionary() 39 | { 40 | { nameof(a), a }, 41 | { nameof(b), b }, 42 | { nameof(c), c }, 43 | { nameof(d), d }, 44 | { nameof(e), e }, 45 | { nameof(f), f } 46 | }; 47 | 48 | NodePath nodesPath = new NodePath(nodes); 49 | 50 | string startNode = "c"; 51 | string endNode = "f"; 52 | var shortestPath = nodesPath.ComputeShortestPath(startNode, endNode); 53 | 54 | Console.WriteLine($"节点 {startNode} --> 节点 {endNode}"); 55 | Console.WriteLine(); 56 | Console.WriteLine("路长\t路径"); 57 | Console.WriteLine("---------------------------------------------"); 58 | Console.WriteLine(); 59 | 60 | if (shortestPath.AllPath == null) 61 | { 62 | Console.WriteLine($"此路不通"); 63 | } 64 | else 65 | { 66 | Console.WriteLine("最短路径:"); 67 | Console.WriteLine($"{shortestPath.Length}\t{shortestPath.Path}"); 68 | Console.WriteLine(); 69 | Console.WriteLine("所有路径:"); 70 | foreach (var item in shortestPath.AllPath) 71 | { 72 | Console.WriteLine($"{item.Value}\t{item.Key}"); 73 | } 74 | } 75 | 76 | Console.WriteLine(); 77 | Console.WriteLine("---------------------------------------------"); 78 | 79 | Console.ReadKey(); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /节点找出最短的路/ConsoleDemo/节点示例图.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/A-Grass-Code/OpenDemo/3d73ac75a1df53019b888933c9243c5d24425970/节点找出最短的路/ConsoleDemo/节点示例图.jpg --------------------------------------------------------------------------------