Exemplo n.º 1
0
        //Write a new shape to DB
        public void WriteShapeToDB(string name, byte r, byte g, byte b, int w, int h)
        {
            SQLServer_DrawAppDataContext ctx = new SQLServer_DrawAppDataContext();

            TblColor c = new TblColor()
            {
                Red   = r,
                Green = g,
                Blue  = b
            };

            TblColor savedColor = ctx.TblColors.Where(sc => sc.Red == c.Red && sc.Blue == c.Blue && sc.Green == c.Green).FirstOrDefault();

            if (savedColor == null)
            {
                ctx.TblColors.InsertOnSubmit(c);
                ctx.SubmitChanges();
                ColorManager.LoadColors();
            }
            else
            {
                c.Color_ID = savedColor.Color_ID;
            }

            TblShape s = new TblShape()
            {
                Width    = w,
                Height   = h,
                Shape    = name,
                Color_ID = c.Color_ID
            };

            TblShape savedShape = ctx.TblShapes.Where(ss => ss.Color_ID == s.Color_ID && ss.Width == s.Width && ss.Height == s.Height && ss.Shape == s.Shape).FirstOrDefault();

            if (savedShape == null)
            {
                ctx.TblShapes.InsertOnSubmit(s);
                ctx.SubmitChanges();
            }
            else
            {
                MessageBox.Show("This shape already exists");
            }
        }
Exemplo n.º 2
0
        //Click event to draw the chosen shape on canvas
        private void cvs_Drawing_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                Shape shapeDrawing = CanvasManager.ShapeManager.CreateNewShape();
                Point location     = e.GetPosition(cvs_Drawing);
                Canvas.SetTop(shapeDrawing, location.Y);
                Canvas.SetLeft(shapeDrawing, location.X);
                cvs_Drawing.Children.Add(shapeDrawing);

                SQLServer_DrawAppDataContext ctx = new SQLServer_DrawAppDataContext();

                TblColor c = new TblColor()
                {
                    Red   = ((SolidColorBrush)shapeDrawing.Fill).Color.R,
                    Green = ((SolidColorBrush)shapeDrawing.Fill).Color.G,
                    Blue  = ((SolidColorBrush)shapeDrawing.Fill).Color.B
                };

                var savedColor = ctx.TblColors.Where(sc => sc.Red == c.Red && sc.Blue == c.Blue && sc.Green == c.Green).FirstOrDefault();
                if (savedColor == null)
                {
                    ctx.TblColors.InsertOnSubmit(c);
                    ctx.SubmitChanges();
                }
                else
                {
                    c.Color_ID = savedColor.Color_ID;
                }

                TblShape s = new TblShape()
                {
                    Shape    = CanvasManager.ShapeManager.SetFinalShapeName(shapeDrawing, shapeDrawing.Width, shapeDrawing.Height),
                    Width    = (float)shapeDrawing.Width,
                    Height   = (float)shapeDrawing.Height,
                    Color_ID = c.Color_ID,
                };

                var savedShape = ctx.TblShapes.Where(ss => ss.Color_ID == s.Color_ID && ss.Width == s.Width && ss.Height == s.Height && ss.Shape == s.Shape).FirstOrDefault();
                if (savedShape == null)
                {
                    ctx.TblShapes.InsertOnSubmit(s);
                    ctx.SubmitChanges();
                }
                else
                {
                    s.Shape_ID = savedShape.Shape_ID;
                }

                var canvasID = ctx.TblOverviews.Where(canvas => canvas.Name == this.Title).FirstOrDefault();
                if (canvasID != null)
                {
                    TblPosition position = new TblPosition()
                    {
                        Shape_ID   = s.Shape_ID,
                        Drawing_ID = canvasID.Drawing_ID,
                        X          = Canvas.GetLeft(shapeDrawing),
                        Y          = Canvas.GetTop(shapeDrawing)
                    };

                    ctx.TblPositions.InsertOnSubmit(position);
                }

                ctx.SubmitChanges();
            }

            catch (FormatException)
            {
                MessageBox.Show("Please provide necessary values or select a shape from the selection window");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error occured - " + ex);
            }
        }
Exemplo n.º 3
0
 partial void DeleteTblShape(TblShape instance);
Exemplo n.º 4
0
 partial void UpdateTblShape(TblShape instance);
Exemplo n.º 5
0
 partial void InsertTblShape(TblShape instance);
Exemplo n.º 6
0
 private void detach_TblShapes(TblShape entity)
 {
     this.SendPropertyChanging();
     entity.TblColor = null;
 }
Exemplo n.º 7
0
 private void attach_TblShapes(TblShape entity)
 {
     this.SendPropertyChanging();
     entity.TblColor = this;
 }