CutTaskInfoVM.cs 30.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654
using HHECS.Application.Enums;
using HHECS.Application.Service;
using HHECS.BLL.Services;
using HHECS.BllModel;
using HHECS.Dal;
using HHECS.Dal.Repository;
using HHECS.Infrastructure.CommonHelper;
using HHECS.Model.Entities;
using HHECS.Model.Enums.Warehouse;
using HHECS.WinClient.View.EquipmentInfo;
using HHECS.WinCommon.ViewModel;
using Microsoft.Win32;
using Newtonsoft.Json;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.Metrics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Net.NetworkInformation;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Shell;
using MessageBox = HandyControl.Controls.MessageBox;

namespace HHECS.WinClient.View.TaskInfo
{
    public class CutTaskInfoVM : VMBase
    {
        public PageInfo PageInfo { get; set; } = new PageInfo();
        public string Id { get; set; }
        public string Length { get; set; }
        public string Diameter { get; set; }
        public string ExcelDate { get; set; } = "line3";
        public string ExcelDate1 { get; set; }
        public string FirstStatus { get; set; }
        public string lastStatus;
        public string LastStatus
        {
            get { return lastStatus; }
            set { lastStatus = value; OnPropertyChanged(nameof(LastStatus)); }
        }
        public string LineCode { get; set; }
        public string NowStation { get; set; }
        public string NextStation { get; set; }

        public DateTime? StartTime { get; set; } = DateTime.Now.Date.AddDays(-7);

        public DateTime? EndTime { get; set; } = DateTime.Now.Date.AddDays(2).AddSeconds(-1);

        public Dictionary<string, object> Stations { get; set; }

        public Dictionary<string, string> LineCodes { get; set; }

        public Dictionary<string, object> Statuss { get; set; }

        List<DictDetail> ProcessRouteDetails { get; set; } = new List<DictDetail>();

        List<Equipment> WorkStations { get; set; } = new List<Equipment>();

        public List<CutPlanDetail> CutPlanTasks { get; set; } = new List<CutPlanDetail>();
        List<Line> Lines { get; set; } = new List<Line>();

        public CutTaskInfoVM()
        {
            //    ProcessRouteDetails.Add(new DictDetail { Id = 0, Value = "", Name = "全部" });
            //    string str1 = DictConst.TaskStatus.ToString();
            //    ProcessRouteDetails.AddRange(App.SystemService.GetDictWithDetails(a => a.Code == str1).Data?.DictDetails ?? new List<DictDetail>());
            //var result1 = App.TaskService.GetEquipments(t => true);
            //if (result1.Success)
            //{
            //    Stations = new Dictionary<string, object>();
            //    if (!Stations.ContainsKey("全部"))
            //    {
            //        Stations.Add("全部", "");
            //    }

            // WorkStations = result1.Data.Where(t => t.LineCode == App.LineCode && t.EquipmentTypeId != 68).ToList();
            // //Stations=result1.Data.ToDictionary(t => t.WorkStationName, x => (object)x.Id);
            // WorkStations.ForEach(t => { Stations.Add(t.Name, t.Id); });
            //    //Stations.Add("全部", 0);
            //}

            //var result = App.TaskService.GetLines(t => true);
            //if (result.Success)
            //{
            //    LineCodes = new Dictionary<string, string>();
            //    var nowLine = result.Data.Find(t => t.lineCode == App.LineCode);
            //    LineCodes.Add(nowLine.lineName, nowLine.lineCode);
            //    result.Data.Remove(nowLine);
            //    result.Data.ForEach(t => { LineCodes.Add(t.lineName, t.lineCode); });
            //    LineCodes.Add("全部", "");
            //}
            //LineCode = App.LineCode;
            var statu = EnumHelper.EnumListDic<CutPlanDetailState>("全部", "");
            Statuss = statu;

            LastStatus = CutPlanDetailState.初始.GetIndexString();
            //ProcessRouteDetails = DALHelper.GetFreeSql().GetRepository<BaseProcessRouteDetail>().Where(x => true).ToList();
        }

        public Expression<Func<CutPlanDetail, bool>> GetStepTraceExpression()
        {
            Expression<Func<CutPlanDetail, bool>> filter = a => true;
            if (!string.IsNullOrWhiteSpace(Id))
            {
                filter = filter.And(a => a.Id.ToString() == Id);
            }
            if (!string.IsNullOrWhiteSpace(Length))
            {
                filter = filter.And(a => a.IwpNo.ToString() == Length);
            }
            if (!string.IsNullOrWhiteSpace(Diameter))
            {
                filter = filter.And(a => a.BarCode.ToString() == Diameter);
            }
            if (!string.IsNullOrWhiteSpace(ExcelDate))
            {
                filter = filter.And(a => a.Extend4.ToString() == ExcelDate);
            }
            if (!string.IsNullOrWhiteSpace(ExcelDate1))
            {
                filter = filter.And(a => a.Extend1.Contains(ExcelDate1));
            }
            //if (!string.IsNullOrWhiteSpace(FirstStatus))
            //{
            //    filter = filter.And(a => a.CutState >= Convert.ToInt16(FirstStatus));
            //}
            if (!string.IsNullOrWhiteSpace(LastStatus))
            {
                if (LastStatus == "0")
                {
                    filter = filter.And(a => a.CutState < 100);
                }
                else
                {
                    filter = filter.And(a => a.CutState == Convert.ToInt32(LastStatus));
                }
            }
            //if (!string.IsNullOrWhiteSpace(LineCode))
            //{
            //    filter = filter.And(a => a..ToString() == LineCode);
            //}
            //if (StartTime != null)
            //{
            //    //filter = filter.And(a => a.CreateTime >= StartTime);
            //}
            //if (EndTime != null)
            //{
            //    //filter = filter.And(a => a.CreateTime <= EndTime);
            //}
            return filter;
        }

        public void Query()
        {
            Expression<Func<CutPlanDetail, bool>> filter = GetStepTraceExpression();
            var result = App.TaskService.GetAllCutPlanTasks(filter, PageInfo.PageIndex, PageInfo.PageSize, out long totalCount);
            if (result.Success)
            {
                PageInfo.TotalCount = totalCount;
                CutPlanTasks = result.Data;
                // CutPlanTasks = cutPlanTasks.OrderBy(pet => pet.Id).ToList();
            }
            else
            {
                MessageBox.Show($"查询失败:{result.Msg}", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }


        public void Complete(List<CutPlanDetail> stepTraces)
        {
            if (stepTraces == null || stepTraces.Count() < 1)
            {
                MessageBox.Show("请选中一条任务后继续", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else
            {
                var stepTrace = stepTraces[0];
                if (MessageBox.Show($"是否要重新套料任务;这可能导致未知异常发生!", "警告", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                {
                    var result = App.TaskService.CutTaskExceptionOver(stepTraces, App.User.UserCode);
                    if (result.Success)
                    {
                        MessageBox.Show($"重新套料任务成功");
                        Query();
                    }
                    else
                    {
                        MessageBox.Show($"重新套料任务失败:{result.Msg}");
                    }
                }
            }
        }


        /// <summary>
        /// 任务维护
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void Maintain(List<CutPlanDetail> stepTraces)
        {
            if (stepTraces == null || stepTraces.Count() != 1)
            {
                MessageBox.Show("请选中一条任务后继续", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else
            {
                WinStepTraceMaintain winStepTraceMaintain = new WinStepTraceMaintain(stepTraces[0].Id);
                winStepTraceMaintain.ShowDialog();
                Query();
            }
        }


        //public void Import()
        //{
        //    // 创建文件选择对话框
        //    OpenFileDialog openFileDialog = new OpenFileDialog
        //    {
        //        Filter = "Excel Files|*.xls;*.xlsx", // 只显示 Excel 文件
        //        Title = "选择 Excel 文件"
        //    };
        //    try
        //    {
        //        if (openFileDialog.ShowDialog() == true)
        //        {
        //            string filePath = openFileDialog.FileName;

        //            // 调用读取方法
        //            var dataTable = ParseExcel(filePath);
        //            CutPlanTaskRepository cutPlanTaskRepository = new CutPlanTaskRepository();
        //            var uw = DALHelper.GetFreeSql().CreateUnitOfWork();
        //            cutPlanTaskRepository.UnitOfWork = uw;
        //            var result = cutPlanTaskRepository.Insert(dataTable);
        //            uw?.Commit();
        //            uw?.Dispose();
        //            if (result.Count > 0)
        //            {
        //                MessageBox.Show($"导入成功");
        //            }

        //            Query();
        //            //var dataTable11 = ImportExcelToDataTable(filePath);
        //            // 将数据绑定到 DataGridView
        //            // dataGridView1.DataSource = dataTable;
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show($"导入 Excel 文件时发生错误:{ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
        //    }
        //}

        //public List<CutPlanTask> ParseExcel(string filePath)
        //{
        //    var materials = new List<CutPlanTask>();
        //    ConfigRepository configRepository = new ConfigRepository();
        //    var isAutoLength = configRepository.Where(t => t.Code == "IsAutoLength").ToList().First();
        //    if (isAutoLength == null)
        //    {
        //        MessageBox.Show("系统配置中没有配置自动生产长度");
        //    }
        //    var autoLength = Convert.ToInt16(isAutoLength.Value);

        //    var loss = configRepository.Where(t => t.Code == "Loss").ToList().First();
        //    if (loss == null)
        //    {
        //        MessageBox.Show("系统配置中没有配置单次切割损耗长度");
        //    }
        //    var lossLength = Convert.ToDouble(loss.Value);

        //    var bigLineMinDiameter = configRepository.Where(t => t.Code == "BigLineMinDiameter").ToList().First();
        //    if (bigLineMinDiameter == null)
        //    {
        //        MessageBox.Show("系统配置中没有配置大管径线最小管径");
        //    }
        //    var BigLineMinDiameter = Convert.ToInt16(bigLineMinDiameter.Value);

        //    var parentMetal = configRepository.Where(t => t.Code == "ParentMetalNo").ToList().First();
        //    if (parentMetal == null)
        //    {
        //        MessageBox.Show("系统配置中没有配置当前母材编码");
        //    }
        //    var parentMetalNo = Convert.ToInt64(parentMetal.Value);

        //    BllService bllService = new BllService();
        //    var pipeTypeList = bllService.GetDictWithDetails(a => a.Code == "PipeType").Data.DictDetails.Select(t => t.Value).ToList(); ;


        //    SystemService systemService = new SystemService();
        //    //var pipeTypeList = systemService.GetDictDetails(t => t.Code == "PipeType").Data.Select(t => t.Value).ToList();
        //    if (!pipeTypeList.Any())
        //    {
        //        MessageBox.Show("系统字典中没有配置管种");
        //    }

        //    using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
        //    {
        //        IWorkbook workbook;

        //        // 判断文件类型
        //        if (Path.GetExtension(filePath).ToLower() == ".xls")
        //        {
        //            workbook = new HSSFWorkbook(fs);  // .xls 格式
        //        }
        //        else if (Path.GetExtension(filePath).ToLower() == ".xlsx")
        //        {
        //            workbook = new XSSFWorkbook(fs);  // .xlsx 格式
        //        }
        //        else
        //        {
        //            throw new Exception("Unsupported file format!");
        //        }

        //        var sheet = workbook.GetSheetAt(0);  // 获取第一个工作表

        //        // 跳过标题行,从第二行开始读取数据
        //        decimal currentOuterDiameter = 0;
        //        decimal currentThickness = 0;
        //        int currentRow = 0;
        //        string pipeType = "";
        //        decimal length = 0;
        //        //string residualLength = "";
        //        var excelCreateTime = sheet.GetRow(0).GetCell(55).ToString();
        //        var pipeDiameterStandard = sheet.GetRow(0).GetCell(6).ToString();
        //        for (int rowIndex = 3; rowIndex <= sheet.LastRowNum; rowIndex++) // 从第二行开始(假设第一行是标题)
        //        {
        //            var row = sheet.GetRow(rowIndex);
        //            if (row == null)
        //            {
        //                continue; // 跳过空行
        //            }
        //            var topRow = sheet.GetRow(rowIndex - 1);
        //            if (topRow == null)
        //            {
        //                continue; // 跳过空行
        //            }

        //            // 读取外径和壁厚(假设外径在第1列,壁厚在第2列)
        //            if (row.GetCell(7).ToString().Contains("D=") && row.GetCell(12).ToString().Contains("T="))
        //            {
        //                currentOuterDiameter = Convert.ToDecimal(GetNum(row.GetCell(7)?.ToString())); // 外径
        //                currentThickness = Convert.ToDecimal(GetNum(row.GetCell(12)?.ToString())); // 壁厚
        //                pipeType = row.GetCell(0)?.ToString();//管种
        //                currentRow = rowIndex + 1;// 母材空行
        //                //residualLength = "";//清空
        //                continue; // 跳过母材行
        //            }
        //            if (currentRow == rowIndex)
        //            {
        //                continue; // 跳过母材空行
        //            }

        //            // 处理该行数据(可能存在多个切断长)
        //            if (rowIndex % 2 != 0)
        //            {
        //                if (!string.IsNullOrEmpty(row.GetCell(7)?.ToString()))
        //                {
        //                    length = Convert.ToDecimal(row.GetCell(7)?.ToString());
        //                }
        //                continue;   // 跳过奇数行
        //            }
        //            decimal cuttingLength1 = string.IsNullOrEmpty(row.GetCell(24)?.ToString()) ? 0 : Convert.ToDecimal(row.GetCell(24).ToString());// 第一个切断长
        //            decimal cuttingLength2 = string.IsNullOrEmpty(row.GetCell(50)?.ToString()) ? 0 : Convert.ToDecimal(row.GetCell(50).ToString()); // 第二个切断长度


        //            CutPlanTask material1;
        //            // 拆分数据,确保每个切断长都有一条记录
        //            if (cuttingLength1 != 0)
        //            {

        //                material1 = new CutPlanTask
        //                {
        //                    //这里不能根据64列(余料数据)去判断是否是另外一根管子了
        //                    ParentMetalNo = string.IsNullOrEmpty(topRow.GetCell(64)?.ToString()) ? "" : (parentMetalNo + 1).ToString(), // 母材编号
        //                    //ParentMetalNo = string.IsNullOrEmpty(topRow.GetCell(7)?.ToString()) ? "" : (parentMetalNo + 1).ToString(), // 母材编号
        //                    Status = 0,
        //                    NowStation = "",// 当前工位
        //                    NextStation = "", // 下个工位
        //                    NowStationAddress = "",//当前工位Address
        //                    NextStationAddress = "",//下个工位Address
        //                    BevelCount = 0, // 坡口次数
        //                    IsAuto = (int)(cuttingLength1 * 1000) > autoLength ? true : false,//是否自动在切割完成之后判断写入,默认为false
        //                    //LineCode = currentOuterDiameter > BigLineMinDiameter ? "MaxPipeLine" : "MinPipeLine", // 大小管线
        //                    LineCode = App.LineCode,



        //                    PipeType = pipeType,           // 管种
        //                    OuterDiameter = currentOuterDiameter,            // 外径
        //                    Thickness = currentThickness,                    // 厚度
        //                    TotalLength = length,        // 总长度
        //                    PNo = topRow.GetCell(12)?.ToString(),                // PNo.
        //                    OnePassNo = topRow.GetCell(15)?.ToString(),          // 一贯No
        //                    ProcessSeries = row.GetCell(15)?.ToString(),      // 加工系列
        //                    CodeNo = topRow.GetCell(20)?.ToString(),            // 代码No
        //                    System = row.GetCell(20)?.ToString(),            // 系统
        //                    EndFitting = topRow.GetCell(24)?.ToString(),         // 管端金物
        //                    CuttingLength = (int)(cuttingLength1 * 1000),                  // 切断长
        //                    PostProcessing = topRow.GetCell(29)?.ToString(),    // 后处理
        //                    PipeEnd = row.GetCell(29)?.ToString(),          // 管端
        //                    BendType = row.GetCell(32)?.ToString(),         // 弯曲类型
        //                    ShipCode = topRow.GetCell(35)?.ToString(),          // 船别代码
        //                    ShipCode1 = row.GetCell(35)?.ToString(),       // 船别代码1
        //                    ResidualLength = topRow.GetCell(64)?.ToString(), // 余料长度
        //                    ResidualCode = topRow.GetCell(37)?.ToString(),  // 余料编码
        //                    ResidualCode1 = row.GetCell(37)?.ToString(),  // 余料编码1
        //                    Letter = topRow.GetCell(69)?.ToString(),
        //                    CreateTime = DateTime.Now,
        //                    CreateBy = App.User.UserCode,
        //                    ExcelCreateTime = excelCreateTime,
        //                    PipeStandards = Regex.Replace(pipeDiameterStandard, @"[^a-zA-Z]", ""),
        //                    ExcelRow = row.RowNum.ToString(),


        //                };
        //                material1.BevelCount = material1.PipeEnd.Count(c => c == 'V');
        //                materials.Add(material1);
        //                //更新母材编码
        //                if (!string.IsNullOrEmpty(material1.ParentMetalNo))
        //                {
        //                    parentMetal.Value = material1.ParentMetalNo;
        //                    parentMetalNo = Convert.ToInt64(material1.ParentMetalNo);
        //                }
        //            }

        //            if (cuttingLength2 != 0)
        //            {
        //                CutPlanTask material2 = new CutPlanTask
        //                {
        //                    ParentMetalNo = string.IsNullOrEmpty(topRow.GetCell(64)?.ToString()) ? "" : parentMetal.Value, // 母材编号
        //                    Status = 0,
        //                    NowStation = "",// 当前工位
        //                    NextStation = "", // 下个工位
        //                    NowStationAddress = "",//当前工位Address
        //                    NextStationAddress = "",//下个工位Address
        //                    BevelCount = 0, // 坡口次数
        //                    IsAuto = (int)(cuttingLength2 * 1000) > autoLength ? true : false,//是否自动在切割完成之后判断写入,默认为false
        //                    //LineCode = currentOuterDiameter > BigLineMinDiameter ? "MaxPipeLine" : "MinPipeLine", // 大小管线
        //                    LineCode = App.LineCode,

        //                    PipeType = pipeType,           // 管种
        //                    OuterDiameter = currentOuterDiameter,            // 外径
        //                    Thickness = currentThickness,                    // 厚度
        //                    TotalLength = length,        // 总长度
        //                    PNo = topRow.GetCell(38)?.ToString(),                // PNo.
        //                    OnePassNo = topRow.GetCell(41)?.ToString(),          // 一贯No
        //                    ProcessSeries = row.GetCell(41)?.ToString(),      // 加工系列
        //                    CodeNo = topRow.GetCell(46)?.ToString(),            // 代码No
        //                    System = row.GetCell(46)?.ToString(),            // 系统
        //                    EndFitting = topRow.GetCell(50)?.ToString(),         // 管端金物
        //                    CuttingLength = (int)(cuttingLength2 * 1000),                  // 切断长
        //                    PostProcessing = topRow.GetCell(55)?.ToString(),    // 后处理
        //                    PipeEnd = row.GetCell(55)?.ToString(),          // 管端
        //                    BendType = row.GetCell(58)?.ToString(),         // 弯曲类型
        //                    ShipCode = topRow.GetCell(61)?.ToString(),       // 船别代码
        //                    ShipCode1 = row.GetCell(61)?.ToString(),       // 船别代码1
        //                    ResidualLength = topRow.GetCell(64)?.ToString(), // 余料长度
        //                    ResidualCode = topRow.GetCell(63)?.ToString(),  // 余料编码
        //                    ResidualCode1 = row.GetCell(63)?.ToString(),  // 余料编码1
        //                    Letter = topRow.GetCell(69)?.ToString(),
        //                    CreateTime = DateTime.Now,
        //                    CreateBy = App.User.UserCode,
        //                    ExcelCreateTime = excelCreateTime,
        //                    PipeStandards = Regex.Replace(pipeDiameterStandard, @"[^a-zA-Z]", ""),
        //                    ExcelRow = row.RowNum.ToString(),
        //                };
        //                material2.BevelCount = material2.PipeEnd.Count(c => c == 'V');
        //                materials.Add(material2);
        //            }
        //        }
        //    }
        //    var temp = "";
        //    var temp1 = "";
        //    var tempParentMetalNo = "";
        //    //补充所有数据的余料长度
        //    for (int i = materials.Count - 1; i >= 0; i--)
        //    {
        //        if (!string.IsNullOrEmpty(materials[i].ResidualLength))
        //        {
        //            tempParentMetalNo = materials[i].ParentMetalNo;
        //            temp = materials[i].ResidualLength; // 跳过空余料长度
        //            temp1 = materials[i].Letter;
        //        }
        //        else
        //        {
        //            materials[i].ParentMetalNo = tempParentMetalNo;
        //            materials[i].ResidualLength = temp;
        //            materials[i].Letter = temp1;
        //        }

        //        //管种取字典中存在的

        //        //生成打码数据
        //        var PipeDiameterStandard = materials[i].PipeStandards;
        //        var PipeType = GetMatchingPipeType(materials[i].PipeType, pipeTypeList);
        //        var date = materials[i].ExcelCreateTime.Substring(materials[i].ExcelCreateTime.Length - 4);
        //        var OnePassNo = materials[i].OnePassNo ?? "    ";
        //        var CodeNo = materials[i].CodeNo ?? "    ";
        //        var ProcessSeries = materials[i].ProcessSeries ?? "    ";
        //        var PNo = materials[i].PNo ?? "    ";
        //        var CuttingLength = materials[i].CuttingLength == 0 ? "    " : materials[i].CuttingLength.ToString();
        //        var ShipCode = materials[i].ShipCode ?? "    ";
        //        var ShipCode1 = materials[i].ShipCode1 ?? "    ";
        //        var ResidualCode1 = materials[i].ResidualCode1 ?? "    ";
        //        var ResidualCode = materials[i].ResidualCode ?? "    ";
        //        var Letter = materials[i].Letter ?? "\u0020";
        //        var Bevel = materials[i].PipeEnd;
        //        var OuterDiameter = materials[i].OuterDiameter;
        //        var Thickness = materials[i].Thickness;

        //        var total = "";
        //        string part1 = $"{PipeDiameterStandard}-{PipeType}-{OuterDiameter}-{Thickness}-{OnePassNo}-{CodeNo}-{PNo}-{ProcessSeries}-{CuttingLength}-{Bevel}";
        //        string part2 = $"-{ShipCode}({ResidualCode})";
        //        string part3 = $"-{ShipCode1}({ResidualCode1})"; ;
        //        string part4 = $"-{date}";
        //        // 判断part3是否为空,如果为空,则不包含part3
        //        if (string.IsNullOrEmpty(ShipCode1))
        //        {
        //            total = part1 + part2 + part4; // 不拼接part3
        //        }
        //        else
        //        {
        //            total = part1 + part2 + part3 + part4; // 拼接part3
        //        }

        //        materials[i].PrintCode = total;
        //        materials[i].QRCodeContent = $"{OnePassNo}-{CodeNo}";
        //    }

        //    configRepository.Update(parentMetal);
        //    //对相同母材中的长度从小到大排序
        //    var tempList = new List<CutPlanTask>();
        //    var sortedData = materials.GroupBy(x => x.ParentMetalNo).ToList();
        //    var rows = "";
        //    foreach (var group in sortedData)
        //    {
        //        var sortedGroup = group.OrderBy(x => x.CuttingLength).ToList();

        //        //计算母材中所有管段长度加上每刀损耗长度之和是否大于母材总长
        //        var user = sortedGroup.Select(t => t.CuttingLength).ToList().Sum();
        //        if ((lossLength * sortedGroup.Count) + user > (double)sortedGroup[0].TotalLength * 1000)
        //        {
        //            rows += $"第[{sortedGroup[0].ExcelRow}]行-";

        //        }

        //        // 对每个分组按cuttingLength排序
        //        foreach (var entry in sortedGroup)
        //        {
        //            tempList.Add(entry);
        //        }
        //    }
        //    if (!string.IsNullOrEmpty(rows))
        //    {
        //        MessageBox.Show($"{rows}数据切割长度和损耗长度大于管材总和,请修改数据之后重新导入!");
        //        return new List<CutPlanTask>();
        //    }
        //    return tempList;
        //}

        //static string GetMatchingPipeType(string pipeType, List<string> pipeTypes)
        //{
        //    // 遍历pipeTypes,检查pipeType中是否包含对应的数字
        //    foreach (var pipe in pipeTypes)
        //    {
        //        if (pipeType.Contains(pipe))
        //        {
        //            return pipe; // 如果找到匹配的数字,返回
        //        }
        //    }


        //        // 使用正则表达式提取数字和字母(例如:316L, 316等)
        //        var regex = new Regex(@"(\d+L?)"); // 匹配数字并可选择性包含L
        //        var match = regex.Match(pipeType);

        //        if (match.Success)
        //        {
        //            string foundPipe = match.Value; // 提取到的数字或字母部分
        //            // 遍历pipeTypes,检查是否包含这个数字
        //            foreach (var pipe in pipeTypes)
        //            {
        //                if (pipe.Contains(foundPipe))
        //                {
        //                    return pipe; // 找到匹配项
        //                }
        //}
        //        }
        //    return "No match"; // 如果没有找到匹配项,返回"No match"
        //}
        //public static string GetMatchingPipeType(string pipeType, List<string> pipeTypes)
        //{
        //    // 使用正则表达式提取括号前的部分和括号中的数字(例如:5H和316L)
        //    var regex = new Regex(@"([^\(]+)\(([^)]+)\)"); // 匹配括号前的部分和括号内的内容
        //    var match = regex.Match(pipeType);

        //    if (match.Success)
        //    {
        //        string prefix = match.Groups[1].Value;  // 括号前的部分(例如 5H)
        //        string innerContent = match.Groups[2].Value; // 括号内的内容(例如 SUS316LTPS)

        //        // 使用正则表达式提取数字和字母(例如:316L, 316等)
        //        // var numberRegex = new Regex(@"(\d+L?)"); // 匹配数字和字母(例如 316L)
        //        var numberRegex = new Regex(@"\d{3,}L?");
        //        //var innerMatch1 = numberRegex.Match(innerContent);
        //        var matches = numberRegex.Matches(innerContent);
        //        var innerMatch = matches[matches.Count - 1].Value; // 这将得到"316L"

        //        if (!string.IsNullOrEmpty(innerMatch))
        //        {
        //            string foundPipe = innerMatch; // 提取到的数字或字母部分
        //                                           // 遍历pipeTypes,检查是否包含这个数字
        //            foreach (var pipe in pipeTypes)
        //            {
        //                if (pipe.Contains(foundPipe))
        //                {
        //                    return $"{prefix}{foundPipe}"; // 返回匹配的完整部分(例如 5H316L)
        //                }
        //            }
        //        }
        //    }

        //    return "No match"; // 如果没有找到匹配项
        //}

        public static decimal GetNum(string b)
        {

            // 使用 Split 方法拆分字符串,获取等号后面的部分
            string[] parts = b.Split('=');

            // 取等号后面的部分并去除空格
            string numberPart = parts[1].Trim();

            // 转换为数字(decimal 类型)
            if (decimal.TryParse(numberPart, out decimal result))
            {
                return result;
            }
            else
            {
                return 0;//Console.WriteLine("转换失败,输入的不是有效的数字。");
            }
        }
    }
}