private void MenuItem_Click_Modify(object sender, RoutedEventArgs e)
        {
            ExcelPin p = SQliteDbContext.GetOneExPin((App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Fixture.FixtureType, tempEp.Name.Substring(1, tempEp.Name.Length - 1));

            if (p == null)
            {
                return;
            }
            p.PinEX  = canvas.RenderSize.Width;
            p.PinEY  = canvas.RenderSize.Height;
            p.PinSX  = Canvas.GetLeft(tempEp);
            p.PinSY  = Canvas.GetTop(tempEp);
            p.Radius = tempEp.ActualHeight;
            (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Pin = p;


            ExcelPinWindow codeWindow = new ExcelPinWindow(true);

            //  SQliteDbContext.UpdatOneExPin(p);
            codeWindow.ShowDialog();
            tempEp.Name = "P" + p.PinNO;
        }
        private void Ellipse_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Ellipse ep = sender as Ellipse;

            mousedown = true;
            if (Operator != Operation.Create)
            {
                if (tempEp != null)
                {
                    tempEp.Fill = TempBruhes;
                }
                tempEp     = ep;
                TempBruhes = ep.Fill;
                ep.Fill    = Brushes.LawnGreen;

                ep.CaptureMouse();
            }
            if (Operator == Operation.Delete)
            {
                ep.ReleaseMouseCapture();
                canvas.UnregisterName(ep.Name);
                canvas.Children.Remove(ep);

                if (ep.Name != null && ep.Name != "")
                {
                    SQliteDbContext.DeleteOneExPin(ep.Name.Substring(1, ep.Name.Length - 1), (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Fixture.FixtureType);
                    ExcelPin p = (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Pins.ToList().Find(x => x.PinNO == ep.Name.Substring(1, ep.Name.Length - 1));
                    (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Pins.Remove(p);
                }
            }
            if (Operator == Operation.Modify)
            {
                if (tempEp != null)
                {
                    int value = 0;
                    int.TryParse(txtDia.Text, out value);
                    if (cbDia.IsChecked.HasValue && cbDia.IsChecked.Value)
                    {
                        tempEp.Height = value;
                        tempEp.Width  = value;
                    }
                    if (cbDia.IsChecked.HasValue && cbColor.IsChecked.Value)
                    {
                        tempEp.Fill = clpk.SelectedBrush;
                    }
                }
                if (tempEp.Name == "")
                {
                    ExcelPin p = new ExcelPin();
                    p.PinEX  = canvas.RenderSize.Width;
                    p.PinEY  = canvas.RenderSize.Height;
                    p.PinSX  = Canvas.GetLeft(tempEp);
                    p.PinSY  = Canvas.GetTop(tempEp);
                    p.Radius = tempEp.ActualHeight;
                    if (tempEp.Fill.ToString().Trim().Length > 0 && tempEp.Fill.ToString() != "0")
                    {
                        p.DrawColor = tempEp.Fill.ToString();
                    }
                    else
                    {
                        p.DrawColor = "#FF0000";
                    }

                    if ((App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Fixture == null)
                    {
                        MessageBox.Show("请选择一个治具型号后再创建!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                        return;
                    }
                    p.FixtureType = (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Fixture.FixtureType;
                    (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Pin = p;
                    ExcelPinWindow codeWindow = new ExcelPinWindow(false);
                    codeWindow.ShowDialog();
                    // tempEp.Name = "P" + p.PinNO;
                    //canvas.RegisterName(tempEp.Name, tempEp);
                    tempEp.Fill = TempBruhes;
                }
                else
                {
                    ExcelPin p = SQliteDbContext.GetOneExPin((App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Fixture.FixtureType, tempEp.Name.Substring(1, tempEp.Name.Length - 1));
                    if (p == null)
                    {
                        return;
                    }
                    p.PinEX  = canvas.RenderSize.Width;
                    p.PinEY  = canvas.RenderSize.Height;
                    p.PinSX  = Canvas.GetLeft(tempEp);
                    p.PinSY  = Canvas.GetTop(tempEp);
                    p.Radius = tempEp.ActualHeight;
                    (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Pin = p;


                    ExcelPinWindow codeWindow = new ExcelPinWindow(true);

                    //  SQliteDbContext.UpdatOneExPin(p);
                    codeWindow.ShowDialog();
                    tempEp.Name = "P" + p.PinNO;
                }
            }
        }
        private void Ellipse_MouseUp(object sender, MouseButtonEventArgs e)
        {
            Ellipse ep = sender as Ellipse;

            mousedown = false;

            ep.ReleaseMouseCapture();
            if (tempEp != null && (Operator == Operation.Move))
            {
                tempEp.Fill = TempBruhes;
                Operator    = Operation.None;
            }
            if (ep.Name != null && ep.Name.Trim().Length > 0)
            {
                string name = ep.Name.Remove(0, 1);

                ExcelPin p = (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Pins.ToList().Find(x => x.PinNO == name);
                if (p == null)
                {
                    return;
                }
                p.PinSX = Canvas.GetLeft(ep);
                p.PinSY = Canvas.GetTop(ep);
                SQliteDbContext.UpdatOneExPin(p);
            }
            if (ep.Name == "" && Operator == Operation.Create)
            {
                ExcelPin p = new ExcelPin();
                p.PinEX  = canvas.RenderSize.Width;
                p.PinEY  = canvas.RenderSize.Height;
                p.PinSX  = Canvas.GetLeft(ep);
                p.PinSY  = Canvas.GetTop(ep);
                p.Radius = ep.ActualHeight;

                if (ep.Fill.ToString().Trim().Length > 0 && ep.Fill.ToString() != "0")
                {
                    p.DrawColor = ep.Fill.ToString();
                }
                else
                {
                    p.DrawColor = "#FF0000";
                }

                if ((App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Fixture == null)
                {
                    MessageBox.Show("请选择一个治具型号后再创建!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
                p.FixtureType = (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Fixture.FixtureType;
                var pnm = (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Pins.OrderBy(x => Convert.ToInt16(x.PinNO)).LastOrDefault();
                int pn  = 0;
                if (pnm != null)
                {
                    string pno = pnm.PinNO;
                    int.TryParse(pno, out pn);
                }


                p.PinNO           = (pn + 1).ToString();
                p.PhysicalChannel = (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Channels.FirstOrDefault();
                (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Pin = p;
                ExcelPinWindow codeWindow = new ExcelPinWindow(false);
                codeWindow.ShowDialog();
                // tempEp.Name = "P" + p.PinNO;
                //canvas.RegisterName(tempEp.Name, tempEp);
                if (codeWindow.IsAdd)
                {
                    tempEp  = ep;
                    ep.Name = "P" + p.PinNO;

                    canvas.RegisterName(ep.Name, ep);
                }
                else
                {
                    ep.Fill = null;
                }
            }
        }