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
        //Delete canvas from overview
        public void DeleteCanvas(string name)
        {
            SQLServer_DrawAppDataContext ctx = new SQLServer_DrawAppDataContext();
            var deleteCanvas = (from o in ctx.TblOverviews
                                where o.Name == name
                                select o).FirstOrDefault();

            ctx.TblOverviews.DeleteOnSubmit(deleteCanvas);
            ctx.SubmitChanges();
            LoadCanvasses();
        }
Exemplo n.º 3
0
        private void OnCanvasCreatedHandler(object sender, NewCanvasEventArgs e)
        {
            TblOverview newCanvas = new TblOverview
            {
                Name        = e.CanvasName,
                DateCreated = e.CreationDate,
                DateUpdated = e.CreationDate
            };

            ctx.TblOverviews.InsertOnSubmit(newCanvas);
            ctx.SubmitChanges();
            cm.LoadCanvasses();
        }
Exemplo n.º 4
0
        private void CanvasWindow1_Closed(object sender, EventArgs e)
        {
            TblOverview tblOverview = new TblOverview()
            {
                DateUpdated = DateTime.Now,
                Name        = this.Title
            };

            var t = ctx.TblOverviews.Where(n => n.Name == tblOverview.Name).FirstOrDefault();

            if (t != null)
            {
                t.DateUpdated = tblOverview.DateUpdated;
                ctx.SubmitChanges();
                CanvasManager.LoadCanvasses();
            }
        }
Exemplo n.º 5
0
        //Method to write color to database
        public void WriteColorToDB(byte r, byte g, byte b)
        {
            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();
            }
            else
            {
                MessageBox.Show("This color already exists.");
            }
        }
Exemplo n.º 6
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);
            }
        }