public static InspectionPlanPartDto GetOrCreatePart(DataServiceRestClient client, string name)
        {
            var parts        = client.GetParts(PathInformationDto.Root, null, 1).Result;
            var existingPart = parts.FirstOrDefault(p => string.Equals(p.Path.Name, name));

            if (existingPart == null)
            {
                existingPart = new InspectionPlanPartDto
                {
                    Path = PathHelper.String2PartPathInformation(name),
                    Uuid = Guid.NewGuid()
                };

                client.CreateParts(new[]
                {
                    existingPart
                }).Wait();
            }

            return(existingPart);
        }
示例#2
0
        private async void creatNewDemo(string demoType)
        {
            try
            {
                creatSuccessed = true;
                var partPath = PathHelper.String2PartPathInformation("/Demo/");
                var parts    = await _RestDataServiceClient.GetParts(partPath);

                if (parts.Count() != 0)
                {
                    var Part       = (InspectionPlanPart)parts.ToList()[0];
                    var attributes = new List <Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute>();
                    //demo type
                    attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20043, demoType + "_Demo"));
                    //serial number
                    string date = DateTime.Now.ToString("yyyyMMddHHmmss");
                    attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)14, CC_Data["CC"] + date));
                    //CC
                    attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)801, CC_Data["CC"]));
                    //owner
                    if (comboBox1.Text != "")
                    {
                        attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20028, comboBox1.Text.Trim()));
                    }
                    else
                    {
                        MessageBox.Show("专案负责人未填写!");
                        creatSuccessed = false;
                    }
                    //sales
                    if (comboBox2.Text != "")
                    {
                        attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20004, comboBox2.Text.Trim()));
                    }
                    else
                    {
                        MessageBox.Show("销售联系人未填写!");
                        creatSuccessed = false;
                    }
                    //application engineer
                    if (comboBox3.Text != "")
                    {
                        attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20003, comboBox3.Text.Trim()));
                    }
                    else
                    {
                        MessageBox.Show("Demo工程师未填写!");
                        creatSuccessed = false;
                    }
                    //customer
                    if (comboBox4.Text != "")
                    {
                        attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)1062, comboBox4.Text.Trim()));
                    }
                    else
                    {
                        MessageBox.Show("客户名称未填写!");
                        creatSuccessed = false;
                    }
                    //province
                    if (comboBox5.Text != "")
                    {
                        attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20001, comboBox5.Text.Trim()));
                    }
                    else
                    {
                        MessageBox.Show("客户所在省份未填写!");
                        creatSuccessed = false;
                    }
                    //city
                    if (comboBox6.Text != "")
                    {
                        attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20002, comboBox6.Text.Trim()));
                    }
                    else
                    {
                        MessageBox.Show("客户所在城市未填写!");
                        creatSuccessed = false;
                    }
                    //customer Contact person
                    attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20053, textBox1.Text.Trim()));
                    //customer phone number
                    attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20054, textBox2.Text.Trim()));
                    //customer address
                    attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20055, textBox3.Text.Trim()));
                    //customer person count
                    attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20056, textBox4.Text.Trim()));
                    //cmm info
                    if (comboBox7.Text != "")
                    {
                        attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20051, comboBox7.Text.Trim()));
                    }
                    else
                    {
                        MessageBox.Show("三坐标信息未填写!");
                        creatSuccessed = false;
                    }
                    //sensor info
                    if (comboBox8.Text != "")
                    {
                        attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20052, comboBox8.Text.Trim()));
                    }
                    else
                    {
                        MessageBox.Show("传感器信息未填写!");
                        creatSuccessed = false;
                    }
                    //time K4
                    attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)4, DateTime.Now));
                    //check report
                    if (checkBox1.Checked)
                    {
                        attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20048, "已完成"));
                    }
                    //check handover
                    attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20029, textBox5.Text));
                    //part number
                    attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20041, 1));
                    //process status
                    if (checkBox2.Checked)
                    {
                        attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20027, "技术交接完成"));
                    }
                    else
                    {
                        attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20027, "创建完成"));
                    }
                    var Measurement = new DataMeasurement
                    {
                        Uuid       = Guid.NewGuid(),
                        PartUuid   = Part.Uuid,
                        Time       = DateTime.Now,
                        Attributes = attributes.ToArray()
                    };
                    if (creatSuccessed)
                    {
                        //Create measurement on the server
                        await _RestDataServiceClient.CreateMeasurementValues(new[] { Measurement });
                    }
                    else
                    {
                        creatSuccessed = false;
                    }
                }
                else
                {
                    creatSuccessed = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                creatSuccessed = false;
            }
            finally
            {
                if (creatSuccessed)
                {
                    DirectoryInfo path_exe = new DirectoryInfo(Application.StartupPath); //exe目录
                    RealAction(path_exe + @"\PiWebInterface.exe", " 主界面");
                    //写入完成
                    DialogResult dr = MessageBox.Show("创建Demo完成,是否继续创建Demo?", "创建Demo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dr == DialogResult.Yes)
                    {
                        //询问是否清空界面内容
                        comboBox2.Text    = "";
                        comboBox3.Text    = "";
                        comboBox4.Text    = "";
                        comboBox5.Text    = "";
                        comboBox6.Text    = "";
                        comboBox7.Text    = "";
                        comboBox8.Text    = "";
                        textBox1.Text     = "";
                        textBox2.Text     = "";
                        textBox3.Text     = "";
                        textBox4.Text     = "";
                        checkBox1.Checked = false;
                        checkBox2.Checked = false;
                        textBox5.Text     = "";
                    }
                    else
                    {
                        Application.Exit();
                    }
                }
            }
        }