Exemple #1
0
        private void buttonUpdatePosData_Click(object sender, EventArgs e)
        {
            var newPos = new List <IPlatformPos>();
            var data   = richTextBoxPosData.Lines;
            var line   = string.Empty;

            if (TestPos.Count > 0 && TestPos.First().GetType() == typeof(PosXYZ))
            {
                try
                {
                    foreach (var l in data)
                    {
                        if (string.IsNullOrEmpty(l))
                        {
                            continue;
                        }
                        line = l;
                        newPos.Add(PosXYZ.Create(l));
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"PosXYZ点位数据异常: {line} {ex.Message}");
                    return;
                }
            }
            else if (TestPos.Count > 0 && TestPos.First().GetType() == typeof(PosXYZU))
            {
                try
                {
                    foreach (var l in data)
                    {
                        if (string.IsNullOrEmpty(l))
                        {
                            continue;
                        }
                        line = l;
                        newPos.Add(PosXYZU.Create(l));
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"PosXYZU点位数据异常: {line} {ex.Message}");
                    return;
                }
            }
            else if (TestPos.Count > 0 && TestPos.First().GetType() == typeof(PosXYZUVW))
            {
                try
                {
                    foreach (var l in data)
                    {
                        if (string.IsNullOrEmpty(l))
                        {
                            continue;
                        }
                        line = l;
                        newPos.Add(PosXYZUVW.Create(l));
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"PosXYZUVW点位数据异常: {line} {ex.Message}");
                    return;
                }
            }
            else
            {
                return;
            }


            if (MessageBox.Show($"是否更新点位为:\r\n{string.Join("\r\n", newPos.Select(p => p.ToString()))} ", "更新点位数据", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }


            try
            {
                TestPos.Clear();
                TestPos.AddRange(newPos);

                LoadTestPos();
            }
            catch (Exception ex)
            {
                MessageBox.Show($"更新点位数据异常:{ex.Message}");
            }
        }