/// <summary> /// 更新一个引脚 /// </summary> /// <param name="pin"></param> /// <returns></returns> public static int UpdatOneExPin(ExcelPin pin) { string query = "Update ExcelPin Set PinSX=@PinSX,PinSY=@PinSY,PhysicalChannel=@PhysicalChannel,DrawColor=@DrawColor,Radius=@Radius WHERE PinNO = @PinNO and FixtureType=@FixtureType"; using (IDbConnection cnn = new SQLiteConnection(LoadConnectString())) { cnn.Open(); return(cnn.Execute(query, pin)); } }
/// <summary> /// 增加一个pin /// </summary> /// <param name="pin"></param> /// <returns></returns> public static int AddExPin(ExcelPin pin) { using (IDbConnection cnn = new SQLiteConnection(LoadConnectString())) { cnn.Open(); string sql = "Insert into ExcelPin(FixtureType,PinNO,physicalChannel,DrawColor,PinSX,PinSY,PinEX,PinEY,Radius)" + "Values(@FixtureType,@PinNO,@physicalChannel,@DrawColor,@PinSX,@PinSY,@PinEX,@PinEY,@Radius)"; return(cnn.Execute(sql, pin)); } }
private void MenuItem_Click_Delete(object sender, RoutedEventArgs e) { if (tempEp.Name != null && tempEp.Name != "") { canvas.UnregisterName(tempEp.Name); this.canvas.Children.Remove(tempEp); SQliteDbContext.DeleteOneExPin(tempEp.Name.Substring(1, tempEp.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 == tempEp.Name.Substring(1, tempEp.Name.Length - 1)); (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Pins.Remove(p); } }
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 Button_Click(object sender, RoutedEventArgs e) { if (!IsModify) { ExcelPin p = (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Pin; p.PinNO = this.codepart.Text; if (QualityCheck()) { int rs = SQliteDbContext.AddExPin(p); if (rs > 0) { MessageBox.Show("添加成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information); (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Pins.Add(p); IsAdd = true; this.Close(); } } } else { ExcelPin p = (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Pin; p.PinNO = this.codepart.Text; if (QualityCheck()) { int rs = SQliteDbContext.UpdatOneExPin(p); if (rs > 0) { MessageBox.Show("修改成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } } (App.Current.Resources["Locator"] as ViewModelLocator).ExcelPaper.Pins = new ObservableCollection <ExcelPin>(SQliteDbContext. GetOneFixtureExcelPins((App.Current.Resources["Locator"] as ViewModelLocator). ExcelPaper.Fixture.FixtureType)); }
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; } } }