Пример #1
0
        private void ContextMenuButtonClick(object sender, RoutedEventArgs e)
        {
            System.Windows.Controls.MenuItem menuItem = sender as System.Windows.Controls.MenuItem;
            if (menuItem == null)
            {
                return;
            }

            DependencyObject parent = menuItem.Parent;
            ToggleButton     button = menuItem.Tag as ToggleButton;

            while (parent != null)
            {
                if (parent is ContextMenu)
                {
                    parent = ((ContextMenu)parent).PlacementTarget;
                }
                if (parent is ToggleButton)
                {
                    button = parent as ToggleButton;
                    break;
                }
                if (parent is FrameworkElement)
                {
                    parent = ((FrameworkElement)parent).Parent;
                }
                else
                {
                    parent = null;
                }
            }
            if (button == null)
            {
                return;
            }

            DamageSector sector = button.Tag as DamageSector;

            if (sector == null)
            {
                return;
            }

            CommonEditorForm form = new CommonEditorForm(sector, sector.ItemId > 0);

            if (form.ShowDialog() == DialogResult.OK)
            {
                System.Windows.Controls.RichTextBox rtb = new System.Windows.Controls.RichTextBox()
                {
                    FontFamily = FontFamily, FontSize = FontSize
                };
                FlowDocumentScrollViewer flowDocument = new FlowDocumentScrollViewer();
                string tooltipTex = string.IsNullOrEmpty(sector.Remarks) ? "No Information" : sector.Remarks;
                try
                {
                    //TextRange tr = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd);
                    var documentBytes = Encoding.UTF8.GetBytes(tooltipTex);
                    using (var reader = new MemoryStream(documentBytes))
                    {
                        reader.Position = 0;
                        rtb.SelectAll();
                        rtb.Selection.Load(reader, System.Windows.DataFormats.Rtf);
                    }

                    //using (var reader = new MemoryStream(documentBytes))
                    //{
                    //    tr.Load(reader, System.Windows.DataFormats.Rtf);
                    //}
                    flowDocument.Document = rtb.Document;
                }
                catch (Exception)
                {
                }
                button.ToolTip = flowDocument;
            }
        }
Пример #2
0
        ///<summary>
        ///</summary>
        private void UpdateInformation()
        {
            if (_currentDirctive == null || _currentDirctive.DamageDocs == null ||
                _currentAircraft == null)
            {
                return;
            }

            _chartImages.Clear();
            _chartImages.AddRange(new[]
            {
                _b737300400500Bs46Leftside,
                _b737300400500Bs46Rightside,
                _b737300400500WingLowerSurface,
                _b737300400500WingUpperSurface,
                _b737500RearLeft,
                _b737500Side,
                _b737500Top,
                _selectDamageChartImage
            });

            ChartComboBox.Items.Clear();
            foreach (DamageChartImage t in _chartImages)
            {
                ChartComboBox.Items.Add(t);
            }

            DamageChartsListView.Items.Clear();

            if (_currentDirctive.DamageDocs.Count == 0)
            {
                //если у родителя нет ни одного Damage Doc-а, то ему добавляется в коллекцию Damage Doc-ов
                //пустой Damage Doc, ради того, что бы при появлении формы она не была пустой
                //если пользователь не изменит объект пустого Damage Doc-а, то данный Damage Doc при
                //закрытии формы не сохранится и произоидет удаление всех пустых Damage Doc-ов из
                //коллекции Damage Doc-ов родителя

                DamageDocument damageDoc = new DamageDocument(1, _currentDirctive.ItemId);
                _currentDirctive.DamageDocs.Add(damageDoc);

                DamageDocument imageDoc = new DamageDocument(2, _currentDirctive.ItemId);
                _currentDirctive.DamageDocs.Add(imageDoc);
            }

            int countCharts = 0, countImages = 0;

            foreach (DamageDocument document in _currentDirctive.DamageDocs)
            {
                if (document.DocumentTypeId == 1)
                {
                    DamageChartImage dci = _chartImages.FirstOrDefault(ci => ci.ChartName == document.DamageChart2DImageName);

                    if (dci != null)
                    {
                        document.DamageChart2DImageName = dci.ChartName;
                        document.DamageChartImage       = dci.Image;
                    }

                    DamageChartsListView.Items.Add(document);
                }
                if (document.DocumentTypeId == 2)
                {
                    //DamageChartImageControl docControl = new DamageChartImageControl(doc);
                    //if (countImages == 0) docControl.Extended = true;
                    //else docControl.Extended = false;
                    //countImages++;

                    //_damageImagesFileControls.Add(docControl);
                    //docControl.Deleted += ImageDeleted;
                    //flowLayoutPanelImages.Controls.Remove(panelButtonsImages);
                    //flowLayoutPanelImages.Controls.Add(docControl);
                    //flowLayoutPanelImages.Controls.Add(panelButtonsImages);
                }
            }

            DamageChartsListView.SelectedIndex = 0;

            DamageDocument doc = DamageChartsListView.SelectedItem as DamageDocument;

            if (doc == null)
            {
                return;
            }

            foreach (DamageSector damageSector in doc.DamageSectors)
            {
                if (damageSector.DamageChartColumn < 0 || (damageSector.DamageChartColumn + 1) > ChartGrid.ColumnDefinitions.Count ||
                    damageSector.DamageChartRow < 0 || (damageSector.DamageChartRow + 1) > ChartGrid.RowDefinitions.Count)
                {
                    continue;
                }

                UIElement uiElement = null;
                foreach (UIElement child in ChartGrid.Children)
                {
                    if (Grid.GetColumn(child) == damageSector.DamageChartColumn &&
                        Grid.GetRow(child) == damageSector.DamageChartRow)
                    {
                        uiElement = child;
                    }
                }

                if (uiElement == null)
                {
                    continue;
                }

                ToggleButton button = uiElement as ToggleButton;
                if (button == null)
                {
                    continue;
                }
                button.IsChecked = true;
                button.Tag       = damageSector;

                System.Windows.Controls.RichTextBox rtb = new System.Windows.Controls.RichTextBox {
                    FontFamily = FontFamily, FontSize = FontSize
                };
                FlowDocumentScrollViewer flowDocument = new FlowDocumentScrollViewer();
                string tooltipTex = string.IsNullOrEmpty(damageSector.Remarks) ? "No Information" : damageSector.Remarks;
                try
                {
                    //TextRange tr = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd);
                    var documentBytes = Encoding.UTF8.GetBytes(tooltipTex);
                    using (var reader = new MemoryStream(documentBytes))
                    {
                        reader.Position = 0;
                        rtb.SelectAll();
                        rtb.Selection.Load(reader, System.Windows.DataFormats.Rtf);
                    }
                    flowDocument.Document = rtb.Document;
                }
                catch (Exception)
                {
                }
                button.ToolTip = flowDocument;
            }
        }
Пример #3
0
        private void ChartComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ChartGrid.ColumnDefinitions.Clear();
            ChartGrid.RowDefinitions.Clear();
            foreach (UIElement uiElement in ChartGrid.Children)
            {
                if (uiElement is Button)
                {
                    ((Button)uiElement).Click -= DamageSectorButtonClick;
                }
            }
            ChartGrid.Children.Clear();

            DamageChartImage dci = ChartComboBox.SelectedItem as DamageChartImage ?? _selectDamageChartImage;

            if (dci == null || dci.Image == null)
            {
                return;
            }

            try
            {
                BitmapConverter converter   = new BitmapConverter();
                ImageSource     imageSource = (ImageSource)converter.Convert(dci.Image, null, null, null);

                ChartGrid.Width      = imageSource.Width;
                ChartGrid.Height     = imageSource.Height;
                ChartGrid.Background = new ImageBrush(imageSource);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            for (int i = 0; i < dci.CountColumns; i++)
            {
                ChartGrid.ColumnDefinitions.Add(new ColumnDefinition());
            }

            for (int i = 0; i < dci.CountRows; i++)
            {
                ChartGrid.RowDefinitions.Add(new RowDefinition());
            }

            for (int i = 0; i < ChartGrid.ColumnDefinitions.Count; i++)
            {
                for (int j = 0; j < ChartGrid.RowDefinitions.Count; j++)
                {
                    ToggleButton newButton = new ToggleButton
                    {
                        Content             = "X",
                        VerticalAlignment   = VerticalAlignment.Stretch,
                        HorizontalAlignment = HorizontalAlignment.Stretch,
                    };
                    newButton.Click += DamageSectorButtonClick;

                    Grid.SetColumn(newButton, i);
                    Grid.SetRow(newButton, j);
                    ChartGrid.Children.Add(newButton);
                }
            }

            DamageDocument doc = DamageChartsListView.SelectedItem as DamageDocument;

            if (doc == null)
            {
                return;
            }
            if (doc.DamageChart2DImageName == dci.ChartName)
            {
                foreach (DamageSector damageSector in doc.DamageSectors)
                {
                    if (damageSector.DamageChartColumn < 0 || (damageSector.DamageChartColumn + 1) > ChartGrid.ColumnDefinitions.Count ||
                        damageSector.DamageChartRow < 0 || (damageSector.DamageChartRow + 1) > ChartGrid.RowDefinitions.Count)
                    {
                        continue;
                    }

                    UIElement uiElement = null;
                    foreach (UIElement child in ChartGrid.Children)
                    {
                        if (Grid.GetColumn(child) == damageSector.DamageChartColumn &&
                            Grid.GetRow(child) == damageSector.DamageChartRow)
                        {
                            uiElement = child;
                        }
                    }

                    if (uiElement == null)
                    {
                        continue;
                    }

                    ToggleButton button = uiElement as ToggleButton;
                    if (button == null)
                    {
                        continue;
                    }
                    button.IsChecked = true;
                    button.Tag       = damageSector;

                    System.Windows.Controls.RichTextBox rtb = new System.Windows.Controls.RichTextBox()
                    {
                        FontFamily = FontFamily, FontSize = FontSize
                    };
                    FlowDocumentScrollViewer flowDocument = new FlowDocumentScrollViewer();
                    string tooltipTex = string.IsNullOrEmpty(damageSector.Remarks) ? "No Information" : damageSector.Remarks;
                    try
                    {
                        //TextRange tr = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd);
                        var documentBytes = Encoding.UTF8.GetBytes(tooltipTex);
                        using (var reader = new MemoryStream(documentBytes))
                        {
                            reader.Position = 0;
                            rtb.SelectAll();
                            rtb.Selection.Load(reader, System.Windows.DataFormats.Rtf);
                        }
                        flowDocument.Document = rtb.Document;
                    }
                    catch (Exception)
                    {
                    }
                    button.ToolTip = flowDocument;
                }
            }
            else
            {
                doc.DamageChartImage       = dci.Image;
                doc.DamageChart2DImageName = dci.ChartName;
            }
        }
Пример #4
0
	public void InsertRTFLayer (DataRow DescriptionRow, RichTextBox RTFDocument, DataRow ContentRow,
					double OriginalWidth, double OriginalHeight, double FontSizingBase)
		{
		String TextToWrite = CVM.CommonValues.ProcessCommonTextSubstitutions (DescriptionRow ["Text"].ToString ());
		if ((String.IsNullOrEmpty (TextToWrite))
			&& (!String.IsNullOrEmpty (DescriptionRow ["DataBaseItem"].ToString ())))
			TextToWrite = ContentRow [DescriptionRow ["DataBaseItem"].ToString ()].ToString ();

		double WidthPercentage = MaxPercentage;
		if ((!Convert.IsDBNull (DescriptionRow ["PositionRight"]))
			&& (!Convert.IsDBNull (DescriptionRow ["PositionLeft"])))
			WidthPercentage = Convert.ToDouble (DescriptionRow ["PositionRight"]) -
						 Convert.ToDouble (DescriptionRow ["PositionLeft"]);
		else
			{
			if (!Convert.IsDBNull (DescriptionRow ["PositionRight"]))
				WidthPercentage = Convert.ToDouble (DescriptionRow ["PositionRight"]);
			if (!Convert.IsDBNull (DescriptionRow ["PositionLeft"]))
				WidthPercentage = MaxPercentage - Convert.ToDouble (DescriptionRow ["PositionLeft"]);
			}

		double HeightPercentage = MaxPercentage;
		if ((!Convert.IsDBNull (DescriptionRow ["PositionBottom"]))
			&& (!Convert.IsDBNull (DescriptionRow ["PositionTop"])))
			HeightPercentage = Convert.ToDouble (DescriptionRow ["PositionBottom"]) -
						 Convert.ToDouble (DescriptionRow ["PositionTop"]);
		else
			{
			if (!Convert.IsDBNull (DescriptionRow ["PositionBottom"]))
				HeightPercentage = Convert.ToDouble (DescriptionRow ["PositionBottom"]);
			if (!Convert.IsDBNull (DescriptionRow ["PositionTop"]))
				HeightPercentage = MaxPercentage - Convert.ToDouble (DescriptionRow ["PositionTop"]);
			}
		double LeftPercentage = 0;
		if (!Convert.IsDBNull (DescriptionRow ["PositionLeft"]))
			LeftPercentage = Convert.ToDouble (DescriptionRow ["PositionLeft"]);
		double TopPercentage = 0;
		if (!Convert.IsDBNull (DescriptionRow ["PositionTop"]))
			TopPercentage = Convert.ToDouble (DescriptionRow ["PositionTop"]);


		double FontPercentage = 5;
		if (!Convert.IsDBNull (DescriptionRow ["FontSize"]))
			if (!String.IsNullOrEmpty (DescriptionRow ["FontSize"].ToString ()))
				FontPercentage = Convert.ToDouble (DescriptionRow ["FontSize"]);

		String FontDescription = "Arial";
		if (!Convert.IsDBNull (DescriptionRow ["FontDescription"]))
			if (!String.IsNullOrEmpty (DescriptionRow ["FontDescription"].ToString ()))
				FontDescription = DescriptionRow ["FontDescription"].ToString ();

		String FontWeight = "Normal";
		if (!Convert.IsDBNull (DescriptionRow ["FontStyle"]))
			if (!String.IsNullOrEmpty (DescriptionRow ["FontStyle"].ToString ()))
				FontWeight = DescriptionRow ["FontStyle"].ToString ();

		String FontColor = "Black";
		if (!Convert.IsDBNull (DescriptionRow ["FontColor"]))
			if (!String.IsNullOrEmpty (DescriptionRow ["FontColor"].ToString ()))
				FontColor = DescriptionRow ["FontColor"].ToString ();

		String ConvertContent = String.Empty;
		if (!Convert.IsDBNull (DescriptionRow ["ConvertContent"]))
			ConvertContent = DescriptionRow ["ConvertContent"].ToString ();
		String ConverterParameter = String.Empty;
		if (!Convert.IsDBNull (DescriptionRow ["ConverterParameter"]))
			ConverterParameter = DescriptionRow ["ConverterParameter"].ToString ();

		if (ConvertContent == "ToUpper")
			TextToWrite = TextToWrite.ToUpper ();
		if (ConvertContent == "FormatedDate")
			{
			try
				{
				DateTime WorkingDate = DateTime.Parse (TextToWrite);
				if (String.IsNullOrEmpty (ConverterParameter))
					TextToWrite = WorkingDate.ToString ();
				else
					TextToWrite = WorkingDate.ToString (ConverterParameter);
				}
			catch (Exception)
				{
				}
			}

		String ForceNewLine = String.Empty;
		if (!Convert.IsDBNull (DescriptionRow ["ForceNewLine"]))
			ForceNewLine = DescriptionRow ["ForceNewLine"].ToString ();

		String Alignment = String.Empty;
		if (!Convert.IsDBNull (DescriptionRow ["Alignment"]))
			Alignment = DescriptionRow ["Alignment"].ToString ();

		RTFDocument.SelectAll ();
		RTFDocument.Selection.Load(new MemoryStream (ASCIIEncoding.Default.GetBytes (TextToWrite)), DataFormats.Rtf);


		}
Пример #5
0
		public void Text ()
		{
			TextSelection ts = rtb.Selection;

			ts.Text = "Moon";
			Assert.AreEqual (String.Empty, ts.Text, "#0");

			rtb.SelectAll ();
			Assert.AreEqual ("Moon", rtb.Selection.Text, "#1");
			Assert.AreEqual ("Moon", ts.Text, "#2");
			rtb = new RichTextBox ();

			ts = rtb.Selection;
			CreateAsyncTest (rtb,
					 () => {
						 ts.Text = "Hello";
						 Assert.AreEqual (String.Empty, ts.Text, "#3");
					 },
					 () => {
						 Assert.AreEqual (String.Empty, ts.Text, "#4");
						 Assert.AreEqual (String.Empty, rtb.Selection.Text, "#5");
						 rtb.SelectAll ();
						 Assert.AreEqual ("Hello", rtb.Selection.Text, "#6");
					 });
		}
Пример #6
0
 public void DeleteString(RichTextBox rtb, FlowDocument fd)
 {
     rtb.SelectAll();
     rtb.Selection.Text = "";
     FlowDocSettings(fd);
 }
Пример #7
0
 private void PastePlainTextCommand(object sender, ExecutedRoutedEventArgs e)
 {
     RichTextBox rtb = new RichTextBox();
     rtb.Paste();
     rtb.SelectAll();
     rtb.Selection.ClearAllProperties();
     rtb.Copy();
     richTextBox_Main.Paste();
 }