private void CommanOk_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            var DbText        = new DbTextModel();
            var DbTextContent = new TextBlock();
            var Dc            = new NewTextViewModel();

            var fixName = DateTime.Now.ToString("yyyyMMddHHmmss");

            DbTextContent.Text = Dc.LabelContent = NewDbTextVM.SelectedElem.wartosc;
            DbText.Name        = Dc.Name = $"DBT_{fixName}";
            DbText.Width       = Dc.LabelContent.Count() * 8;
            DbText.Height      = 30;
            DbText.Id_Pole     = NewDbTextVM.SelectedElem.id_pole;
            DbText.Content     = DbTextContent;
            DbText.DataContext = Dc;

            NewDbTextEvent?.Invoke(DbText, 5, 5);

            WindowResult = true;
            Close();
        }
Esempio n. 2
0
        private static void ParseLabel(XElement lbl, Dictionary <UIElement, CanvasPosition> list, string type)
        {
            Label newLabel;

            switch (type)
            {
            case "Margin":
                newLabel = new Label();
                break;

            case "Own":
                newLabel = new OwnTextModel();
                break;

            case "Db":
                newLabel = new DbTextModel();
                break;

            default:
                throw new Exception("Nie rozpoznany typ komponentu tekstowego.");
            }

            TextBlock        newTextBlock     = new TextBlock();
            NewTextViewModel newTextViewModel = new NewTextViewModel();

            var textBlock = lbl.Descendants(ns + "TextBlock").FirstOrDefault();

            if (textBlock != null)
            {
                var text       = textBlock.Attribute("Text").Value;
                var fontFamily = textBlock.Attribute("FontFamily")?.Value;
                var fontStyle  = textBlock.Attribute("FontStyle")?.Value;
                var fontWeight = textBlock.Attribute("FontWeight")?.Value;
                var fontSize   = textBlock.Attribute("FontSize")?.Value;
                var fontColor  = textBlock.Attribute("Foreground")?.Value;
                var hca        = lbl.Attribute("HorizontalContentAlignment")?.Value;
                var vca        = lbl.Attribute("VerticalContentAlignment")?.Value;

                newTextViewModel.LabelContent = text;
                newTextViewModel.TbFontFamily = fontFamily != null ? new FontFamily(fontFamily) : new FontFamily("Verdana");
                newTextViewModel.TbFontStyle  = fontStyle == "Italic" ? FontStyles.Italic : FontStyles.Normal;
                newTextViewModel.TbFontWeight = fontWeight == "Bold" ? FontWeights.Bold : FontWeights.Regular;
                newTextViewModel.TbFontSize   = fontSize != null ? (float)Convert.ToDouble(StrToDouble(fontSize)) : 10;
                newTextViewModel.FontColor    = fontColor != null ? new BrushConverter().ConvertFromString(fontColor) as SolidColorBrush : Brushes.Black;
                newTextViewModel.TbHorizontalContentAligment = hca != null?GetHorizontalAligment(hca) : HorizontalAlignment.Left;

                newTextViewModel.TbVerticalContentAligment = vca != null?GetVerticalAligment(vca) : VerticalAlignment.Top;

                // UTWORZENIE OKNA DIALOGOWEGO DO WYBIERANIA CZCIONKI
                System.Drawing.FontStyle fs1 = System.Drawing.FontStyle.Regular;
                System.Drawing.FontStyle fs2 = System.Drawing.FontStyle.Regular;
                System.Drawing.FontStyle fs3 = System.Drawing.FontStyle.Regular;
                System.Drawing.FontStyle fs4 = System.Drawing.FontStyle.Regular;
                if (fontStyle == "Italic")
                {
                    fs1 = System.Drawing.FontStyle.Italic;
                }

                if (fontWeight == "Bold")
                {
                    fs2 = System.Drawing.FontStyle.Bold;
                }

                var textDecoration = textBlock.Descendants(ns + "TextDecoration").ToList();

                if (textDecoration != null)
                {
                    TextDecorationCollection tdc = new TextDecorationCollection();

                    foreach (var decoration in textDecoration)
                    {
                        var d = decoration.Attribute("Location").Value;

                        if (d == "Underline")
                        {
                            tdc.Add(TextDecorations.Underline);
                            fs3 = System.Drawing.FontStyle.Underline;
                        }

                        if (d == "Strikethrough")
                        {
                            tdc.Add(TextDecorations.Strikethrough);
                            fs4 = System.Drawing.FontStyle.Strikeout;
                        }
                    }

                    newTextViewModel.TbTextDecorations = tdc;
                }

                newTextViewModel.FontDialog       = new System.Windows.Forms.FontDialog();
                newTextViewModel.FontDialog.Color = System.Drawing.ColorTranslator.FromHtml(fontColor);
                newTextViewModel.FontDialog.Font  = new System.Drawing.Font(newTextViewModel.TbFontFamily.Source.ToString(), (float)Convert.ToDouble(StrToDouble(newTextViewModel.TbFontSize.ToString())), fs1 | fs2 | fs3 | fs4);

                newLabel.Content = newTextBlock;
            }

            var name = lbl.Attribute("Name").Value;

            newLabel.Name         = name;
            newTextViewModel.Name = name;

            // POBRANIE WŁAŚCIWOŚCI MARGINESÓW
            if (!name.Contains("Margin"))
            {
                var borderBrush = lbl.Attribute("BorderBrush")?.Value;
                var borderThick = lbl.Attribute("BorderThickness")?.Value;
                var thickness   = borderThick != null?Convert.ToInt32(borderThick.Split(',')[0]) : 0;

                newTextViewModel.BorderColor     = borderBrush != null ? new BrushConverter().ConvertFromString(borderBrush) as SolidColorBrush : null;
                newTextViewModel.BorderThickness = thickness;
                if (thickness > 0)
                {
                    newTextViewModel.Border = true;
                }
            }

            var width  = lbl.Attribute("Width")?.Value;
            var height = lbl.Attribute("Height")?.Value;

            newTextViewModel.TbWidth  = Convert.ToDouble(StrToDouble(width));
            newTextViewModel.TbHeight = Convert.ToDouble(StrToDouble(height));

            var left = lbl.Attribute(ns + "Canvas.Left").Value;
            var top  = lbl.Attribute(ns + "Canvas.Top").Value;

            var canvasLeft = Convert.ToDouble(StrToDouble(left));
            var canvasTop  = Convert.ToDouble(StrToDouble(top));

            newLabel.DataContext = newTextViewModel;

            AppHandler.BindData(newLabel, newTextBlock);

            list.Add(newLabel, new CanvasPosition(canvasLeft, canvasTop));
        }