Ejemplo n.º 1
0
        public override FrameworkElement CreateCellEditElement(Telerik.Windows.Controls.GridView.GridViewCell cell, object dataItem)
        {
            DataRow dr             = (DataRow)dataItem;
            string  sHienThiDKhien = dr["HTHI_DIEU_KHIEN"].ToString();
            string  sGiaTri        = dr["GTRI_TTIN"].ToString();
            TextBox ctrCommon      = new TextBox();
            Binding valueBinding   = CreateValueBinding();

            if (sHienThiDKhien.Equals("Combobox"))
            {
                RadComboBox cmbCommon = new RadComboBox();
                List <AutoCompleteEntry> lstComboBox = new List <AutoCompleteEntry>();
                string maTruyVan = dr["HTHI_SQL"].ToString();
                if (dr["HTHI_SDUNG_TVAN"].Equals("CO"))
                {
                    KhoiTaoGiaTriComboBox(ref lstComboBox, ref cmbCommon, maTruyVan);
                    cmbCommon.SetBinding(DataContextProperty, valueBinding);
                    if (!sGiaTri.IsNullOrEmptyOrSpace())
                    {
                        cmbCommon.SelectedIndex = lstComboBox.IndexOf(lstComboBox.FirstOrDefault(i => i.KeywordStrings.First().Equals(sGiaTri)));
                    }
                    else
                    {
                        cmbCommon.SelectedIndex = 0;
                    }
                }
                return(cmbCommon as FrameworkElement);
            }
            else if (sHienThiDKhien.Equals("Datetime"))
            {
                RadMaskedDateTimeInput radMaskDate = new RadMaskedDateTimeInput();
                radMaskDate.SetBinding(DataContextProperty, valueBinding);
                if (!sGiaTri.IsNullOrEmptyOrSpace())
                {
                    radMaskDate.Value = LDateTime.StringToDate(sGiaTri);
                }
                else
                {
                    radMaskDate.Value = LDateTime.StringToDate(ApplicationConstant.defaultDateTimeFormat);
                }
                return(radMaskDate as FrameworkElement);
            }
            else
            {
                ctrCommon.SetBinding(DataContextProperty, valueBinding);
                if (!sGiaTri.IsNullOrEmptyOrSpace())
                {
                    ctrCommon.Text = sGiaTri;
                }
                else
                {
                    ctrCommon.Text = "";
                }
                return(ctrCommon as FrameworkElement);
            }
        }
Ejemplo n.º 2
0
        public override FrameworkElement CreateCellEditElement(Telerik.Windows.Controls.GridView.GridViewCell cell, object dataItem)
        {
            DataRow dr = null;

            if (dataItem.GetType().Equals(typeof(DataRow)))
            {
                dr = (DataRow)dataItem;
            }
            else
            {
                dr = ((DataRowView)dataItem).Row;
            }
            string  sHienThiDKhien = dr["HTHI_DIEU_KHIEN"].ToString();
            string  sHienThiTVan   = dr["HTHI_SDUNG_TVAN"].ToString();
            string  sGiaTriTVan    = dr["HTHI_SQL"].ToString();
            string  sGiaTri        = dr["GTRI_TTIN"].ToString();
            string  sKieuDuLieu    = dr["KIEU_DU_LIEU"].ToString();
            TextBox ctrCommon      = new TextBox();
            Binding valueBinding   = CreateValueBinding();

            if (sHienThiDKhien.Equals("Combobox"))
            {
                lstComboBox = new List <AutoCompleteEntry>();
                cmbCommon   = new RadComboBox();
                KhoiTaoGiaTriComboBox(ref lstComboBox, ref cmbCommon, sGiaTriTVan);
                if (!sGiaTri.IsNullOrEmptyOrSpace())
                {
                    cmbCommon.SelectedIndex = lstComboBox.IndexOf(lstComboBox.FirstOrDefault(i => i.KeywordStrings.First().Equals(sGiaTri)));
                }
                else
                {
                    cmbCommon.SelectedIndex = 0;
                }
                cmbCommon.Tag = lstComboBox;
                cmbCommon.SetBinding(DisplayIndexProperty, valueBinding);
                cmbCommon.IsEnabled = true;
                return(cmbCommon as FrameworkElement);
            }
            else if (sHienThiDKhien.Equals("Datetimebox"))
            {
                var ControlRad = grdControl.FindChildByType <RadMaskedDateTimeInput>();
                if (ControlRad != null)
                {
                    grdControl.Children.Remove(ControlRad);
                }
                var ControlDTP = grdControl.FindChildByType <DatePicker>();
                if (ControlDTP != null)
                {
                    grdControl.Children.Remove(ControlDTP);
                }
                radMaskDate = new RadMaskedDateTimeInput();

                if (!sGiaTri.IsNullOrEmptyOrSpace())
                {
                    radMaskDate.Value = LDateTime.StringToDate(sGiaTri, ApplicationConstant.defaultDateTimeFormat);
                }
                else
                {
                    radMaskDate.Value = LDateTime.StringToDate(ClientInformation.NgayLamViecHienTai, ApplicationConstant.defaultDateTimeFormat);
                }
                radMaskDate.SetBinding(DisplayIndexProperty, valueBinding);
                radMaskDate.IsEnabled           = true;
                radMaskDate.HorizontalAlignment = HorizontalAlignment.Stretch;
                radMaskDate.Margin            = new Thickness(0, 0, 40, 0);
                dtpPicker.HorizontalAlignment = HorizontalAlignment.Right;
                dtpPicker.Width = 30;
                dtpPicker.SelectedDateChanged += new EventHandler <SelectionChangedEventArgs>(dtpPicker_SelectedDateChanged);
                grdControl.Children.Add(dtpPicker);
                grdControl.Children.Add(radMaskDate);
                return(grdControl as FrameworkElement);
            }
            else
            {
                if (sKieuDuLieu.Equals("Number"))
                {
                    ctrMaskText      = new RadMaskedNumericInput();
                    ctrMaskText.Mask = "#18";
                    if (!sGiaTri.IsNullOrEmptyOrSpace())
                    {
                        ctrMaskText.Value = Convert.ToDouble(sGiaTri);
                    }
                    else
                    {
                        ctrMaskText.Value = null;
                    }
                    ctrMaskText.SetBinding(DisplayIndexProperty, valueBinding);
                    ctrMaskText.HorizontalAlignment = HorizontalAlignment.Stretch;
                    return(ctrMaskText as FrameworkElement);
                }
                else
                {
                    ctrCommon = new TextBox();
                    if (!sGiaTri.IsNullOrEmptyOrSpace())
                    {
                        ctrCommon.Text = sGiaTri;
                    }
                    else
                    {
                        ctrCommon.Text = "";
                    }
                    ctrCommon.SetBinding(DisplayIndexProperty, valueBinding);
                    return(ctrCommon as FrameworkElement);
                }
            }
        }
Ejemplo n.º 3
0
        public Grid CreateChartOptionsPanel()
        {
            Grid chartOptionsPanel = new Grid();

            if (!optionsType.Equals(ChartOptionsType.CandleStick))
            {
                if (optionsType.Equals(ChartOptionsType.Scenario))
                {
                    ColumnDefinition column1 = new ColumnDefinition();
                    column1.Width = new GridLength(4.5, GridUnitType.Star);
                    ColumnDefinition column2 = new ColumnDefinition();
                    column2.Width = new GridLength(4.5, GridUnitType.Star);
                    ColumnDefinition column3 = new ColumnDefinition();
                    column3.Width = new GridLength(1, GridUnitType.Star);
                    chartOptionsPanel.ColumnDefinitions.Add(column1);
                    chartOptionsPanel.ColumnDefinitions.Add(column2);
                    chartOptionsPanel.ColumnDefinitions.Add(column3);
                }
                else
                {
                    ColumnDefinition column1 = new ColumnDefinition();
                    column1.Width = new GridLength(2.5, GridUnitType.Star);
                    ColumnDefinition column2 = new ColumnDefinition();
                    column2.Width = new GridLength(2, GridUnitType.Star);
                    ColumnDefinition column3 = new ColumnDefinition();
                    column3.Width = new GridLength(1, GridUnitType.Star);
                    ColumnDefinition column4 = new ColumnDefinition();
                    column4.Width = new GridLength(2, GridUnitType.Star);
                    ColumnDefinition column5 = new ColumnDefinition();
                    column5.Width = new GridLength(2.5, GridUnitType.Star);
                    chartOptionsPanel.ColumnDefinitions.Add(column1);
                    chartOptionsPanel.ColumnDefinitions.Add(column2);
                    chartOptionsPanel.ColumnDefinitions.Add(column3);
                    chartOptionsPanel.ColumnDefinitions.Add(column4);
                    chartOptionsPanel.ColumnDefinitions.Add(column5);
                }

                TextBlock scenarioTextBlock = new TextBlock();
                scenarioTextBlock.VerticalAlignment   = VerticalAlignment.Center;
                scenarioTextBlock.HorizontalAlignment = HorizontalAlignment.Right;


                SetRow(scenarioTextBlock, 0);
                SetColumn(scenarioTextBlock, 0);
                chartOptionsPanel.Children.Add(scenarioTextBlock);

                RadComboBox scenarioComboBox = new RadComboBox();

                bool b = chartTitle.Contains("COSTO MARGINAL POR ESCENARIOS");

                if (b)
                {
                    ////  if (chartTitle == "COSTO MARGINAL POR BLOQUES")
                    //{
                    //    //    scenarioTextBlock.Text = "BLOQUES";
                    scenarioTextBlock.Visibility = Visibility.Hidden;
                    scenarioComboBox.Visibility  = Visibility.Hidden;
                }
                //else
                scenarioTextBlock.Text = "ESCENARIO";

                Binding binding = new Binding("ActiveScenarios");
                binding.Source = entitiesCollections;
                scenarioComboBox.SetBinding(RadComboBox.ItemsSourceProperty, binding);


                binding = new Binding("Scenario");

                binding.Source = entitiesCollections.DHOGCaseViewModel;

                scenarioComboBox.SetBinding(RadComboBox.SelectedItemProperty, binding);
                scenarioComboBox.Width  = 100;
                scenarioComboBox.Height = 20;
                scenarioComboBox.Margin = new Thickness(10, 0, 0, 0);
                scenarioComboBox.HorizontalAlignment = HorizontalAlignment.Left;
                scenarioComboBox.Focusable           = true;
                SetRow(scenarioComboBox, 0);
                //MessageBox.Show("valor", scenarioComboBox.ToString());

                SetColumn(scenarioComboBox, 1);


                //MessageBox.Show("valor", scenarioComboBox.ToString());
                //scenarioComboBox.SelectedIndex = 0;
                chartOptionsPanel.Children.Add(scenarioComboBox);


                if (!optionsType.Equals(ChartOptionsType.Scenario))
                {
                    TextBlock optionTextBlock = new TextBlock();
                    optionTextBlock.VerticalAlignment   = VerticalAlignment.Center;
                    optionTextBlock.HorizontalAlignment = HorizontalAlignment.Right;
                    switch (optionsType)
                    {
                    case ChartOptionsType.Reservoir:
                        optionTextBlock.Text = "EMBALSE";
                        break;

                    case ChartOptionsType.Company:
                        optionTextBlock.Text = "EMPRESA";
                        break;
                    }
                    SetRow(optionTextBlock, 0);
                    SetColumn(optionTextBlock, 2);
                    chartOptionsPanel.Children.Add(optionTextBlock);

                    RadComboBox optionComboBox = new RadComboBox();
                    switch (optionsType)
                    {
                    case ChartOptionsType.Reservoir:
                        binding = new Binding("ReservoirsScenario1");
                        break;

                    case ChartOptionsType.Company:
                        binding = new Binding("CompaniesScenario1");
                        break;
                    }
                    binding.Source = entitiesCollections;
                    optionComboBox.SetBinding(RadComboBox.ItemsSourceProperty, binding);

                    switch (optionsType)
                    {
                    case ChartOptionsType.Reservoir:
                        binding = new Binding("SelectedReservoir");
                        break;

                    case ChartOptionsType.Company:
                        binding = new Binding("SelectedCompany");
                        break;
                    }
                    binding.Source = entitiesCollections.DHOGCaseViewModel;
                    optionComboBox.SetBinding(RadComboBox.SelectedItemProperty, binding);

                    optionComboBox.SelectedIndex       = 0;
                    optionComboBox.Width               = 150;
                    optionComboBox.Height              = 20;
                    optionComboBox.Margin              = new Thickness(10, 0, 0, 0);
                    optionComboBox.HorizontalAlignment = HorizontalAlignment.Left;
                    optionComboBox.Focusable           = false;
                    SetRow(optionComboBox, 0);
                    SetColumn(optionComboBox, 3);
                    chartOptionsPanel.Children.Add(optionComboBox);

                    //if (String.IsNullOrEmpty(scenarioComboBox.SelectedValue.ToString()))
                    //{
                    //  MessageBox.Show("Valor escenario","Valor vacio");
                    //}
                    //else
                    //{
                    //    MessageBox.Show("Valor escenario", scenarioComboBox.SelectedValue.ToString());
                    //}
                }
            }

            RadButton saveAsImageButton = new RadButton
            {
                BorderThickness = new Thickness(0, 0, 0, 0),
                Content         = new Image()
                {
                    Source = new BitmapImage(new Uri(@"Images/download_image_icon.png", UriKind.Relative)),
                    Width  = 40,
                    Height = 40,
                },
                Background          = Brushes.Transparent,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
                Margin  = new Thickness(0, 25, 30, 0),
                ToolTip = "Guardar Imagen"
            };

            saveAsImageButton.Click += SaveAsImageButton_Click;
            SetRow(saveAsImageButton, 0);
            if (optionsType.Equals(ChartOptionsType.Scenario))
            {
                SetColumn(saveAsImageButton, 2);
            }
            else
            {
                SetColumn(saveAsImageButton, 5);
            }
            chartOptionsPanel.Children.Add(saveAsImageButton);

            return(chartOptionsPanel);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// When overridden in a derived class, is invoked whenever application code or internal processes (such as a rebuilding layout pass) call <see cref="M:System.Windows.Controls.Control.ApplyTemplate"/>. In simplest terms, this means the method is called just before a UI element displays in an application. For more information, see Remarks.
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (_comboBox != null)
            {
                _comboBox.ClearValue(TagProperty);
                _comboBox.SelectionChanged -= OnSelectedFilterChanged;
                _comboBox = null;
            }

            if (_udpItemsControl != null)
            {
                _udpItemsControl.ItemsSource = null;
            }

            _comboBox = GetTemplateChild("FiltersComboBox") as RadComboBox;
            if (_comboBox != null)
            {
                _comboBox.DisplayMemberPath = ReflectionHelper.GetPropertyName<IFilter>(f => f.Name);
                _comboBox.SelectedValuePath = ReflectionHelper.GetPropertyName<IFilter>(f => f.FilterGuid);
                _comboBox.ItemsSource = FilterList;
                _comboBox.SelectedValue = FilterGuid;

                var expression = GetBindingExpression(FilterGuidProperty);
                if (expression != null && expression.ParentBinding != null)
                {
                    _comboBox.SetBinding(TagProperty, expression.ParentBinding);
                }

                _comboBox.SelectionChanged += OnSelectedFilterChanged;
            }

            _udpItemsControl = GetTemplateChild("UdpList") as ItemsControl;
            if (_udpItemsControl != null)
            {
                _udpItemsControl.ItemsSource = UdpList;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates the ImportDataGrid's import column.
        /// </summary>
        /// <param name="importColumn">The import column to setup a DataGridColumn for.</param>
        /// <param name="columnDisplayName">Display name of the column.</param>
        /// <returns></returns>
        private GridViewDataColumn CreateColumn(ImportColumn importColumn, string columnDisplayName)
        {
            #region Setup the import column header

            var columnHeaderColumnStackPanel = new StackPanel();

            var importColumnTypeComboBox = new RadComboBox { Width = 100, DisplayMemberPath = "DisplayName" };

            //TODO: Setup ComboBox's ItemTemplate to work with Multiplicity

            //Bind the ImportColumnTypeComboBox's itemsource to the import destination's column types
            importColumnTypeComboBox.SetBinding(ItemsControl.ItemsSourceProperty, new Binding("DestinationColumnTypes") { Source = VM.ImportData });

            //Bind the selected item of the ImportColumnTypeComboBox to the ImportColumn.ImportColumnType
            importColumnTypeComboBox.SetBinding(Selector.SelectedItemProperty, new Binding("ImportColumnType") { Mode = BindingMode.TwoWay, Source = importColumn });

            columnHeaderColumnStackPanel.Children.Add(importColumnTypeComboBox);
            columnHeaderColumnStackPanel.Children.Add(new TextBlock
            {
                Text = columnDisplayName,
                Foreground = new SolidColorBrush(Colors.White),
                HorizontalAlignment = HorizontalAlignment.Center
            });

            var columnHeaderStackPanel = new StackPanel { Orientation = Orientation.Horizontal };
            columnHeaderStackPanel.Children.Add(columnHeaderColumnStackPanel);
            var removeColumnButton = new Button
            {
                Content = "x",
                VerticalAlignment = VerticalAlignment.Center
            };

            columnHeaderStackPanel.Children.Add(removeColumnButton);

            #endregion

            var gridViewColumn = new GridViewDataColumn
            {
                UniqueName = importColumn.ColumnName,
                DataMemberBinding = new Binding(importColumn.ColumnName),
                //CellTemplate = (DataTemplate)this.Resources["DefaultCellTemplate"],
                //CellEditTemplate = (DataTemplate)this.Resources["DefaultEditTemplate"],
                Header = columnHeaderStackPanel
            };

            //When the remove column button is pressed, remove this column from the DataGrid.
            removeColumnButton.Click += (sender, args) => this.ImportRadGridView.Columns.Remove(gridViewColumn);

            //TODO: Dynamically add columns when all are selected. Wait on response from 
            //importColumnTypeComboBox.SelectionChanged += (sender, e) =>
            //{
            //    //Check if every column is selected
            //    var allAreSelected = true;
            //    foreach (var column in ImportRadGridView.Columns)
            //    {
            //        if (((StackPanel)column.Header).FindChildByType<RadComboBox>().SelectedItem == null)
            //            allAreSelected = false;
            //    }

            //    //Create another column if all columns are selected
            //    if (allAreSelected)
            //    {
            //        var newColumnUniqueName = String.Format("CustomColumn{0}", _customColumnIndex);
            //        var newColumn = VM.ImportData.AddColumn(newColumnUniqueName);
            //        ImportRadGridView.Columns.Add(CreateColumn(newColumn, ""));
            //        _customColumnIndex++;
            //    }
            //};

            return gridViewColumn;
        }