FrmReplace.cs
2.1 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ConveyorLine.EditPointCode
{
public partial class FrmReplace : Form
{
public FrmReplace()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
var oldVal = numOld.Value;
var newVal = numNew.Value;
var findOld = EditPointCodeHelper.pointCodes.Find(s => s.Id == oldVal);
var findNew = EditPointCodeHelper.pointCodes.Find(s => s.Id == newVal);
if(findOld==null)
{
MessageBox.Show($"替换失败,因旧地码【{oldVal}】不存在");
return;
}
if (findNew != null)
{
MessageBox.Show($"替换失败,因新地码【{newVal}】已存在");
return;
}
findOld.Id= (uint)newVal;
findOld.Name = findOld.Id.ToString();
var findLeft = EditPointCodeHelper.pointCodes.Find(s => s.Left!=null && s.Left.Id == oldVal);
if( findLeft!=null )
{
findLeft.Left.Id = (uint)newVal;
}
var findRight = EditPointCodeHelper.pointCodes.Find(s => s.Right != null && s.Right.Id == oldVal);
if (findRight != null)
{
findRight.Right.Id = (uint)newVal;
}
var findUp = EditPointCodeHelper.pointCodes.Find(s => s.Above != null && s.Above.Id == oldVal);
if (findUp != null)
{
findUp.Above.Id = (uint)newVal;
}
var findDwn = EditPointCodeHelper.pointCodes.Find(s => s.Below != null && s.Below.Id == oldVal);
if (findDwn != null)
{
findDwn.Below.Id = (uint)newVal;
}
MessageBox.Show($"【{oldVal}】=》【{newVal}】替换完成");
Close();
}
}
}