更新标准库UDP等
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using Ramitta;
|
||||
using System;
|
||||
using System.Collections;
|
||||
@@ -12,7 +10,7 @@ using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using static Ramitta.Excel;
|
||||
using static Ramitta.lib.Excel;
|
||||
using static Ramitta.lib.Basic;
|
||||
|
||||
|
||||
@@ -20,323 +18,6 @@ namespace template
|
||||
{
|
||||
public partial class MainWindow
|
||||
{
|
||||
Ramitta.Neo4jtool neo4jService = new Ramitta.Neo4jtool("bolt://localhost:7687", "neo4j", "AE1BC6D3");
|
||||
|
||||
public async void 数据升天计划neo4j()
|
||||
{
|
||||
await neo4jService.DeleteAllNodesAndRelationshipsAsync();
|
||||
|
||||
var 文件夹名单 = GetFilesAndDirectories(inputPath(null,null), true,
|
||||
outputFormat: dir => Path.GetFileNameWithoutExtension(dir));
|
||||
|
||||
|
||||
foreach (var 文件夹 in 文件夹名单)
|
||||
{
|
||||
var 文件名单 = GetFilesAndDirectories(inputPath(null, null) + 文件夹, false,
|
||||
outputFormat: dir => System.IO.Path.GetFileNameWithoutExtension(dir));
|
||||
|
||||
await neo4jService.CreateNodeAsync("文件夹", new Dictionary<string, string>() { { "name", 文件夹 } },alway_create:true);
|
||||
|
||||
foreach (var 文件 in 文件名单)
|
||||
{
|
||||
var name = Guid.NewGuid().ToString();
|
||||
var pair = new Dictionary<string, string>() {
|
||||
{ "name", name },{ "文件夹",文件夹} };
|
||||
|
||||
if (文件夹.Contains("边墙沉重管") ||
|
||||
文件夹.Contains("边墙基座固定") ||
|
||||
文件夹.Contains("杂件"))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
pair.Add("类型", Regex.Match(文件, @"([^-]+)").Groups[1].Value);
|
||||
}
|
||||
|
||||
if (
|
||||
文件夹.Contains("边墙沉重管") ||
|
||||
文件夹.Contains("承重柱") ||
|
||||
文件夹.Contains("弧形拉伸杆") ||
|
||||
文件夹.Contains("山墙侧柱套件") ||
|
||||
文件夹.Contains("山墙沉重管") ||
|
||||
文件夹.Contains("屋脊连接角") ||
|
||||
文件夹.Contains("屋面方管") ||
|
||||
文件夹.Contains("屋檐方管") ||
|
||||
文件夹.Contains("斜梁") ||
|
||||
文件夹.Contains("右悬挂管") ||
|
||||
文件夹.Contains("左悬挂管"))
|
||||
{
|
||||
pair.Add("型号", Regex.Match(文件, @"^(?:[^-]+-){2}([^-\r\n]+)").Groups[1].Value);
|
||||
}
|
||||
|
||||
if (文件.Contains("跨度"))
|
||||
{
|
||||
pair.Add("跨度", Regex.Match(文件, @"跨度(\d+)").Groups[1].Value);
|
||||
}
|
||||
|
||||
if (文件.Contains("长度"))
|
||||
{
|
||||
pair.Add("长度", Regex.Match(文件, @"长度(\d+)").Groups[1].Value);
|
||||
}
|
||||
|
||||
if (文件.Contains("宽度"))
|
||||
{
|
||||
pair.Add("宽度", Regex.Match(文件, @"宽度(\d+)").Groups[1].Value);
|
||||
}
|
||||
|
||||
await neo4jService.CreateNodeAsync("文件", pair, alway_create: true);
|
||||
await neo4jService.CreateRelationshipAsync("拥有",
|
||||
"文件夹", new Dictionary<string, string> { { "name", 文件夹 } },
|
||||
"文件", new Dictionary<string, string> { { "name", name } });
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Func<string?, string?, string> inputPath = (n, f) =>
|
||||
{
|
||||
// 如果 n 和 f 都为空,返回文件路径的根目录
|
||||
if (string.IsNullOrEmpty(n) && string.IsNullOrEmpty(f))
|
||||
return @"C:\Users\Xeroly\Desktop\组件库\";
|
||||
|
||||
// 如果 n 为空,返回路径不包含文件夹
|
||||
if (string.IsNullOrEmpty(n))
|
||||
return @"C:\Users\Xeroly\Desktop\组件库\" + f + ".xlsx";
|
||||
|
||||
// 如果 f 为空,返回路径不包含文件名
|
||||
if (string.IsNullOrEmpty(f))
|
||||
return @"C:\Users\Xeroly\Desktop\组件库\" + n + @"\";
|
||||
|
||||
// 如果 n 和 f 都不为空,返回完整路径
|
||||
return @"C:\Users\Xeroly\Desktop\组件库\" + n + @"\" + f + ".xlsx";
|
||||
};
|
||||
Func<string, string> outPath = (n) => @"C:\Users\Xeroly\Desktop\Outnm\" + n +".xlsx";
|
||||
|
||||
public void CreateXlsxMember(
|
||||
Dictionary<string, object> pair,
|
||||
string? fileUUID = null,
|
||||
Dictionary<string, List<string>>? dict = null)
|
||||
{
|
||||
// 如果没有传入 fileUUID,使用pair中的"name"作为文件名
|
||||
if (fileUUID == null)
|
||||
fileUUID = pair["name"].ToString();
|
||||
|
||||
// 创建一个新的工作簿
|
||||
var workbook = new XSSFWorkbook();
|
||||
var sheet1 = workbook.CreateSheet("data");
|
||||
var sheet2 = workbook.CreateSheet("info");
|
||||
var sheet3 = workbook.CreateSheet("link");
|
||||
|
||||
// 将字典pair内容竖着写入sheet2(即键在第一行,值在第二行)
|
||||
int columnIndex = 0;
|
||||
var headerRow = sheet2.CreateRow(0); // 第一行用作标题行(键)
|
||||
var valueRow = sheet2.CreateRow(1); // 第二行用作数据行(值)
|
||||
|
||||
foreach (var entry in pair)
|
||||
{
|
||||
// 将键写入第一行的相应单元格
|
||||
headerRow.CreateCell(columnIndex).SetCellValue(entry.Key);
|
||||
|
||||
// 将值写入第二行的相应单元格
|
||||
valueRow.CreateCell(columnIndex).SetCellValue(entry.Value?.ToString() ?? ""); // 防止null值导致异常
|
||||
|
||||
columnIndex++;
|
||||
}
|
||||
|
||||
// 如果dict不为空,将其内容竖着写入sheet1
|
||||
if (dict != null && dict.Any())
|
||||
{
|
||||
int rowIndex = 0;
|
||||
|
||||
// 先写入表头(字典的键)
|
||||
var dictHeaderRow = sheet1.CreateRow(rowIndex++);
|
||||
int dictColumnIndex = 0;
|
||||
foreach (var key in dict.Keys)
|
||||
{
|
||||
dictHeaderRow.CreateCell(dictColumnIndex++).SetCellValue(key); // 写入字典的键作为列名
|
||||
}
|
||||
|
||||
// 写入每一列数据(将List<string>的数据填充到各自的列)
|
||||
int maxRows = dict.Values.Max(list => list.Count); // 获取最多的行数
|
||||
|
||||
for (int i = 0; i < maxRows; i++)
|
||||
{
|
||||
var row = sheet1.CreateRow(rowIndex++);
|
||||
|
||||
int colIndex = 0;
|
||||
foreach (var key in dict.Keys)
|
||||
{
|
||||
var list = dict[key];
|
||||
|
||||
// 如果list中有对应的项,写入,否则写入空字符串
|
||||
row.CreateCell(colIndex++).SetCellValue(i < list.Count ? list[i] : string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 将数据写入到文件
|
||||
using (var fs = new FileStream(outPath(fileUUID), FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
workbook.Write(fs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async void 表原核生物化() {
|
||||
|
||||
var 文件夹名单 = GetFilesAndDirectories(inputPath(null, null), true,
|
||||
outputFormat: dir => Path.GetFileNameWithoutExtension(dir));
|
||||
|
||||
foreach (var 文件夹 in 文件夹名单)
|
||||
{
|
||||
var 文件名单 = GetFilesAndDirectories(inputPath(null, null) + 文件夹, false,
|
||||
outputFormat: dir => Path.GetFileNameWithoutExtension(dir));
|
||||
|
||||
foreach (var 文件 in 文件名单)
|
||||
{
|
||||
var name = Guid.NewGuid().ToString();
|
||||
var pair = new Dictionary<string, object>() {
|
||||
{"name", name },{"文件夹", 文件夹 } };
|
||||
|
||||
if (文件夹.Contains("边墙沉重管") ||
|
||||
文件夹.Contains("边墙基座固定") ||
|
||||
文件夹.Contains("杂件"))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
pair.Add("类型", Regex.Match(文件, @"([^-]+)").Groups[1].Value);
|
||||
}
|
||||
|
||||
if (
|
||||
文件夹.Contains("边墙沉重管") ||
|
||||
文件夹.Contains("承重柱") ||
|
||||
文件夹.Contains("弧形拉伸杆") ||
|
||||
文件夹.Contains("山墙侧柱套件") ||
|
||||
文件夹.Contains("山墙沉重管") ||
|
||||
文件夹.Contains("屋脊连接角") ||
|
||||
文件夹.Contains("屋面方管") ||
|
||||
文件夹.Contains("屋檐方管") ||
|
||||
文件夹.Contains("斜梁") ||
|
||||
文件夹.Contains("右悬挂管") ||
|
||||
文件夹.Contains("左悬挂管"))
|
||||
{
|
||||
pair.Add("型号", Regex.Match(文件, @"^(?:[^-]+-){2}([^-\r\n]+)").Groups[1].Value);
|
||||
}
|
||||
|
||||
if (文件.Contains("跨度"))
|
||||
{
|
||||
pair.Add("跨度", Regex.Match(文件, @"跨度(\d+)").Groups[1].Value);
|
||||
}
|
||||
|
||||
if (文件.Contains("长度"))
|
||||
{
|
||||
pair.Add("长度", Regex.Match(文件, @"长度(\d+)").Groups[1].Value);
|
||||
}
|
||||
|
||||
if (文件.Contains("宽度"))
|
||||
{
|
||||
pair.Add("宽度", Regex.Match(文件, @"宽度(\d+)").Groups[1].Value);
|
||||
}
|
||||
if (文件.Contains("边高"))
|
||||
{
|
||||
pair.Add("边高", Regex.Match(文件, @"边高(\d+)").Groups[1].Value);
|
||||
}
|
||||
|
||||
Dictionary<string, List<string>> dict =
|
||||
ReadExcelAsDictCol(inputPath(文件夹, 文件),headerInit:new List<string>() {
|
||||
"料号","名称","数量","标志","备注" });
|
||||
|
||||
// 删除每个列表中第一个元素(如果列表不为空)
|
||||
foreach (var key in dict.Keys.ToList()) // 使用ToList()来避免修改集合时的枚举问题
|
||||
{
|
||||
if (dict[key].Any())
|
||||
{
|
||||
dict[key].RemoveAt(0); // 删除列表中的第一个元素
|
||||
}
|
||||
}
|
||||
|
||||
CreateXlsxMember(pair,
|
||||
dict:dict);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async void 新建关系(Dictionary<string, string> pair, Dictionary<string, List<string>> dict,string tap,string rela="属于") {
|
||||
if (pair.ContainsKey(tap))
|
||||
{
|
||||
await neo4jService.CreateNodeAsync(tap, new Dictionary<string, string>() {
|
||||
{ "name", tap} });
|
||||
|
||||
await neo4jService.CreateRelationshipAsync(rela,
|
||||
tap, new Dictionary<string, string> { { "name", tap } },
|
||||
"文件", new Dictionary<string, string> { { "name", dict["name"][0] } },
|
||||
relationshipProperties:
|
||||
new Dictionary<string, string>{ { "value", dict[tap][0] } });
|
||||
}
|
||||
}
|
||||
|
||||
public async void 库表升天() {
|
||||
await neo4jService.DeleteAllNodesAndRelationshipsAsync();
|
||||
var 文件夹路径 = @"C:\Users\Xeroly\Desktop\Outnm\";
|
||||
|
||||
var 文件名单 = GetFilesAndDirectories(
|
||||
文件夹路径,false,
|
||||
outputFormat: dir => Path.GetFileNameWithoutExtension(dir));
|
||||
|
||||
foreach (var 文件 in 文件名单) {
|
||||
var dict = ReadExcelAsDictCol(文件夹路径+文件+".xlsx",sheetName:"info");
|
||||
|
||||
// 创建新的字典pair
|
||||
var pair = new Dictionary<string, string>();
|
||||
|
||||
// 遍历dict,将每个key对应的第一个value添加到新的pair字典中
|
||||
foreach (var entry in dict)
|
||||
{
|
||||
if (entry.Value.Any()) // 确保每个列表至少有一个元素
|
||||
{
|
||||
pair.Add(entry.Key, entry.Value[0]); // 只取第一个元素
|
||||
}
|
||||
}
|
||||
|
||||
await neo4jService.CreateNodeAsync("文件夹", new Dictionary<string, string>() {
|
||||
{ "name", dict["文件夹"][0] } });
|
||||
|
||||
await neo4jService.CreateNodeAsync("文件", pair);
|
||||
|
||||
|
||||
|
||||
await neo4jService.CreateRelationshipAsync("拥有",
|
||||
"文件夹", new Dictionary<string, string> { { "name", dict["文件夹"][0] } },
|
||||
"文件", new Dictionary<string, string> { { "name", dict["name"][0] } });
|
||||
|
||||
|
||||
新建关系(pair, dict, "跨度", "跨度");
|
||||
新建关系(pair, dict, "宽度","宽度");
|
||||
新建关系(pair, dict, "长度","长度");
|
||||
新建关系(pair, dict, "型号","型号");
|
||||
新建关系(pair, dict, "边高", "边高");
|
||||
|
||||
var dictdata = ReadExcelAsDictRow(文件夹路径 + 文件 + ".xlsx", sheetName: "data",headerInit:
|
||||
new List<string>() { "料号","名称","数量","标志","备注"});
|
||||
|
||||
dictdata.RemoveAt(0); // 移除列表中的第一个字典
|
||||
|
||||
foreach (var row in dictdata) {
|
||||
await neo4jService.CreateNodeAsync("品物", new Dictionary<string, string>() {
|
||||
{ "name", row["料号"] },{"名称",row["名称"] } });
|
||||
|
||||
await neo4jService.CreateRelationshipAsync("数量",
|
||||
"文件", new Dictionary<string, string> { { "name", dict["name"][0] } },
|
||||
"品物", new Dictionary<string, string> { { "name", row["料号"] } },
|
||||
relationshipProperties:
|
||||
new Dictionary<string, string> { { "数量", row["数量"] } });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public async void 数据升天计划sqlite() {
|
||||
string filename = @"C:\Users\Xeroly\Desktop\琦亚\Kia.db";
|
||||
SQLite db = new SQLite($"Data Source={filename};Version=3;");
|
||||
@@ -456,79 +137,5 @@ namespace template
|
||||
}
|
||||
}
|
||||
|
||||
public async void 数据升天计划mongodb()
|
||||
{
|
||||
var 文件夹名单 = GetFilesAndDirectories(inputPath(null, null), true,
|
||||
outputFormat: dir => Path.GetFileNameWithoutExtension(dir));
|
||||
|
||||
foreach (var 文件夹 in 文件夹名单)
|
||||
{
|
||||
var 文件名单 = GetFilesAndDirectories(inputPath(null, null) + 文件夹, false,
|
||||
outputFormat: dir => System.IO.Path.GetFileNameWithoutExtension(dir));
|
||||
/*
|
||||
// 使用示例
|
||||
var mongoDB = new MongoDB_interface(
|
||||
"mongodb://localhost:27017",
|
||||
"XerolySkinner",
|
||||
文件夹);
|
||||
*/
|
||||
foreach (var 文件 in 文件名单)
|
||||
{
|
||||
var name = Guid.NewGuid().ToString();
|
||||
var pair = new Dictionary<string, string>() {
|
||||
{ "name", name },{ "文件夹",文件夹} };
|
||||
|
||||
if (文件夹.Contains("边墙沉重管") ||
|
||||
文件夹.Contains("边墙基座固定") ||
|
||||
文件夹.Contains("杂件"))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
pair.Add("类型", Regex.Match(文件, @"([^-]+)").Groups[1].Value);
|
||||
}
|
||||
|
||||
if (
|
||||
文件夹.Contains("边墙沉重管") ||
|
||||
文件夹.Contains("承重柱") ||
|
||||
文件夹.Contains("弧形拉伸杆") ||
|
||||
文件夹.Contains("山墙侧柱套件") ||
|
||||
文件夹.Contains("山墙沉重管") ||
|
||||
文件夹.Contains("屋脊连接角") ||
|
||||
文件夹.Contains("屋面方管") ||
|
||||
文件夹.Contains("屋檐方管") ||
|
||||
文件夹.Contains("斜梁") ||
|
||||
文件夹.Contains("右悬挂管") ||
|
||||
文件夹.Contains("左悬挂管"))
|
||||
{
|
||||
pair.Add("型号", Regex.Match(文件, @"^(?:[^-]+-){2}([^-\r\n]+)").Groups[1].Value);
|
||||
}
|
||||
|
||||
if (文件.Contains("跨度"))
|
||||
{
|
||||
pair.Add("跨度", Regex.Match(文件, @"跨度(\d+)").Groups[1].Value);
|
||||
}
|
||||
|
||||
if (文件.Contains("长度"))
|
||||
{
|
||||
pair.Add("长度", Regex.Match(文件, @"长度(\d+)").Groups[1].Value);
|
||||
}
|
||||
|
||||
if (文件.Contains("宽度"))
|
||||
{
|
||||
pair.Add("宽度", Regex.Match(文件, @"宽度(\d+)").Groups[1].Value);
|
||||
}
|
||||
|
||||
/*
|
||||
await neo4jService.CreateNodeAsync("文件", pair, alway_create: true);
|
||||
await neo4jService.CreateRelationshipAsync("拥有",
|
||||
"文件夹", new Dictionary<string, string> { { "name", 文件夹 } },
|
||||
"文件", new Dictionary<string, string> { { "name", name } });
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user