• c#导入二级树代码备份


    1. using log4net;
    2. using System;
    3. using System.Collections.Generic;
    4. using System.Diagnostics;
    5. using System.IO;
    6. using System.Linq;
    7. using System.Security.Cryptography;
    8. using System.Text;
    9. using System.Threading.Tasks;
    10. using YRUSServer.common;
    11. using YRUSServer.entity;
    12. using YRUSServer.model;
    13. using YRUSServer.util;
    14. namespace YRUSServer.service
    15. {
    16. public class ToolService
    17. {
    18. private static readonly ILog log = LogManager.GetLogger(typeof(ToolService));
    19. public static Result InsertData()
    20. {
    21. long pid = 0;
    22. string filePath = "D:\\ms_test\\临床诊断.txt";
    23. string root = "";
    24. // 使用StreamReader打开文件
    25. using (StreamReader sr = new StreamReader(filePath, Encoding.UTF8))
    26. {
    27. string line;
    28. // 逐行读取文件内容
    29. while ((line = sr.ReadLine()) != null)
    30. {
    31. if (!string.IsNullOrEmpty(line))
    32. {
    33. if(IsLevel1(line))
    34. {
    35. root = line;
    36. pid =InsertItem(line, 0);
    37. }
    38. if (IsLevel2(line))
    39. {
    40. line = line.Trim();
    41. InsertItem(line, pid);
    42. }
    43. }
    44. }
    45. }
    46. return Result.Ok("success");
    47. }
    48. public static bool IsLevel1(string line)
    49. {
    50. if (!line.StartsWith("\t") && !line.StartsWith("\t\t")) return true;
    51. else return false;
    52. }
    53. public static bool IsLevel2(string line)
    54. {
    55. if (line.StartsWith("\t") && !line.StartsWith("\t\t")) return true;
    56. else return false;
    57. }
    58. public static bool IsLevel3(string line)
    59. {
    60. if (line.StartsWith("\t\t")) return true;
    61. else return false;
    62. }
    63. public static long InsertItem(string name,long pid)
    64. {
    65. Word word = new Word();
    66. word.Pid = pid;
    67. word.Gid = 17;
    68. word.CreateTime =DateTime.Now;
    69. word.Name = name;
    70. long row = App.DB.Insert(word);
    71. return row;
    72. }
    73. }
    74. }

  • 相关阅读:
    案例:用户管理
    计算机网络-传输层:TCP协议
    VUE3学习
    ES对比两个索引的数据差
    Fiddler工具讲解
    RealEvo许可证协议
    Centos7安装kvm,配置虚拟机网络
    算法提高-AC自动机
    C++(day6)
    精选版:用Java扩展Nginx(nginx-clojure 入门)
  • 原文地址:https://blog.csdn.net/fanhenghui/article/details/133936823