示例#1
0
        private void ButtonAddWidgetDataModel_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                LogicalLibrary.DataModelClasses.Table table = comboBoxDataModels.SelectedItem as LogicalLibrary.DataModelClasses.Table;
                if (table != null)
                {
                    DataSourceWpf dataSourceWPF = new DataSourceWpf(table);
                    dataSourceWPF.MakeCanvas();

                    document.AddWidget(dataSourceWPF);

                    comboBoxDataModels.Items.RemoveAt(comboBoxDataModels.SelectedIndex);
                    comboBoxDataModels.SelectedIndex = 0;
                }
            }
            catch (FileNotFoundException)
            {
                Util.ShowErrorDialog(UtnEmall.ServerManager.Properties.Resources.InternalError);
                this.Close();
            }
            catch (ArgumentNullException)
            {
                Util.ShowErrorDialog(UtnEmall.ServerManager.Properties.Resources.InternalError);
                this.Close();
            }
            catch (Exception error)
            {
                Util.ShowErrorDialog(UtnEmall.ServerManager.Properties.Resources.UnhandledError +
                                     ": " + error.Message);
            }
        }
        /// <summary>
        /// Convierte un ComponentEntity guardado en la base de datos que representa un DataSource en un DataSourceWpf para ser usado en un proyecto wpf
        /// </summary>
        /// <param name="componentEntity"></param>
        /// <param name="dataModel">modelo de datos</param>
        /// <returns></returns>
        public static DataSourceWpf ConvertEntityToDataSource(ComponentEntity componentEntity, DataModel dataModel)
        {
            DataSourceWpf dataSourceWpf = new DataSourceWpf(new Table("Stub"));

            // dataSource.AssociateTable(ConvertEntityToTable(componentEntity.RelatedTable));
            dataSourceWpf.RelatedTable                      = dataModel.GetTable(componentEntity.RelatedTable.Name);
            dataSourceWpf.Height                            = componentEntity.Height;
            dataSourceWpf.Width                             = componentEntity.Width;
            dataSourceWpf.InputConnectionPoint              = ConvertEntityToConnectionPoint(componentEntity.InputConnectionPoint, dataSourceWpf);
            dataSourceWpf.InputDataContext                  = ConvertEntityToTable(componentEntity.InputDataContext);
            dataSourceWpf.OutputConnectionPoint             = ConvertEntityToConnectionPoint(componentEntity.OutputConnectionPoint, dataSourceWpf);
            dataSourceWpf.OutputDataContext                 = ConvertEntityToTable(componentEntity.OutputDataContext);
            dataSourceWpf.XCoordinateRelativeToParent       = componentEntity.XCoordinateRelativeToParent;
            dataSourceWpf.XFactorCoordinateRelativeToParent = componentEntity.XFactorCoordinateRelativeToParent;
            dataSourceWpf.YCoordinateRelativeToParent       = componentEntity.YCoordinateRelativeToParent;
            dataSourceWpf.YFactorCoordinateRelativeToParent = componentEntity.YFactorCoordinateRelativeToParent;

            if (componentEntity.RelatedTable.IsStorage == false)
            {
                dataSourceWpf.FieldToOrder = dataSourceWpf.RelatedTable.GetField(componentEntity.FieldToOrder.Name);
                // dataSource.IsListGiver = componentEntity.IsListGiver;
                //dataSource.IsRegisterGiver = componentEntity.IsRegisterGiver;
                dataSourceWpf.TypeOrder = (OrderType)componentEntity.TypeOrder;
            }


            return(dataSourceWpf);
        }
        /// <summary>
        ///Adjunta eventos a un componente
        /// </summary>
        /// <param name="widget">Componente al que se le agregara los eventos</param>
        private void AttachWidgetEvents(Widget widget)
        {
            String widgetName = widget.GetType().Name;

            if (String.CompareOrdinal(widgetName, typeof(ShowDataFormWpf).Name) == 0)
            {
                ShowDataFormWpf myWidget = widget as ShowDataFormWpf;
                myWidget.WidgetPreviewMouseDown       += new MouseButtonEventHandler(myWidget_PreviewMouseDown);
                myWidget.WidgetPreviewMouseUp         += new MouseButtonEventHandler(myWidget_PreviewMouseUp);
                myWidget.WidgetClick                  += new MouseButtonEventHandler(myWidget_WidgetClick);
                myWidget.WidgetContextMenuEditClick   += new RoutedEventHandler(myWidget_WidgetContextMenuEditClick);
                myWidget.WidgetContextMenuDeleteClick += new RoutedEventHandler(myWidget_WidgetContextMenuDeleteClick);
                myWidget.ConnectionClick              += new EventHandler <ConnectionPointClickEventArgs>(myWidget_ConnectionClick);
            }
            if (String.CompareOrdinal(widgetName, typeof(EnterSingleDataFormWpf).Name) == 0)
            {
                EnterSingleDataFormWpf myWidget = widget as EnterSingleDataFormWpf;
                myWidget.WidgetPreviewMouseDown       += new MouseButtonEventHandler(myWidget_PreviewMouseDown);
                myWidget.WidgetPreviewMouseUp         += new MouseButtonEventHandler(myWidget_PreviewMouseUp);
                myWidget.WidgetClick                  += new MouseButtonEventHandler(myWidget_WidgetClick);
                myWidget.WidgetContextMenuEditClick   += new RoutedEventHandler(myWidget_WidgetContextMenuEditClick);
                myWidget.WidgetContextMenuDeleteClick += new RoutedEventHandler(myWidget_WidgetContextMenuDeleteClick);
                myWidget.ConnectionClick              += new EventHandler <ConnectionPointClickEventArgs>(myWidget_ConnectionClick);
            }
            if (String.CompareOrdinal(widgetName, typeof(MenuFormWpf).Name) == 0)
            {
                MenuFormWpf myWidget = widget as MenuFormWpf;
                myWidget.WidgetPreviewMouseDown       += new MouseButtonEventHandler(myWidget_PreviewMouseDown);
                myWidget.WidgetPreviewMouseUp         += new MouseButtonEventHandler(myWidget_PreviewMouseUp);
                myWidget.WidgetClick                  += new MouseButtonEventHandler(myWidget_WidgetClick);
                myWidget.WidgetContextMenuEditClick   += new RoutedEventHandler(myWidget_WidgetContextMenuEditClick);
                myWidget.WidgetContextMenuDeleteClick += new RoutedEventHandler(myWidget_WidgetContextMenuDeleteClick);

                myWidget.ConnectionClick += new EventHandler <ConnectionPointClickEventArgs>(myWidget_ConnectionClick);
            }
            if (String.CompareOrdinal(widgetName, typeof(ListFormWpf).Name) == 0)
            {
                ListFormWpf myWidget = widget as ListFormWpf;
                myWidget.WidgetPreviewMouseDown       += new MouseButtonEventHandler(myWidget_PreviewMouseDown);
                myWidget.WidgetPreviewMouseUp         += new MouseButtonEventHandler(myWidget_PreviewMouseUp);
                myWidget.WidgetClick                  += new MouseButtonEventHandler(myWidget_WidgetClick);
                myWidget.WidgetContextMenuEditClick   += new RoutedEventHandler(myWidget_WidgetContextMenuEditClick);
                myWidget.WidgetContextMenuDeleteClick += new RoutedEventHandler(myWidget_WidgetContextMenuDeleteClick);

                myWidget.ConnectionClick += new EventHandler <ConnectionPointClickEventArgs>(myWidget_ConnectionClick);
            }
            if (String.CompareOrdinal(widgetName, typeof(DataSourceWpf).Name) == 0)
            {
                DataSourceWpf myWidget = widget as DataSourceWpf;
                myWidget.WidgetPreviewMouseDown       += new MouseButtonEventHandler(myWidget_PreviewMouseDown);
                myWidget.WidgetPreviewMouseUp         += new MouseButtonEventHandler(myWidget_PreviewMouseUp);
                myWidget.WidgetClick                  += new MouseButtonEventHandler(myWidget_WidgetClick);
                myWidget.WidgetContextMenuDeleteClick += new RoutedEventHandler(myWidget_WidgetContextMenuDeleteClick);
                myWidget.ConnectionClick              += new EventHandler <ConnectionPointClickEventArgs>(myWidget_ConnectionClick);
            }
        }
        private void myWidget_WidgetContextMenuDeleteClick(object sender, RoutedEventArgs e)
        {
            Widget        widget        = sender as Widget;
            DataSourceWpf dataSourceWpf = widget as DataSourceWpf;

            if (dataSourceWpf != null && DataSourceDeleted != null)
            {
                DataSourceDeleted(dataSourceWpf, e);
            }

            this.RemoveWidget(widget);
            this.RedrawDocument();

            if ((widget is ListFormWpf || widget is MenuFormWpf) && FormDeleted != null)
            {
                FormDeleted(widget, e);
            }
        }
        public static ConnectionWpf ConvertEntityToConnection(Dictionary <Component, ComponentEntity> connectableComponents,
                                                              ConnectionWidgetEntity connectionWidgetEntity, ServiceDocumentWpf serviceDocumentWpf)
        {
            Component relatedSourceWpf = null;
            Component relatedTargetWpf = null;

            ConnectionPointWpf source = null;
            ConnectionPointWpf target = null;

            // Busca por el componente origen
            relatedSourceWpf = SearchForSourceComponent(connectableComponents, connectionWidgetEntity, serviceDocumentWpf);

            // Busca el componente destino
            relatedTargetWpf = SearchForTargetComponent(connectableComponents, connectionWidgetEntity, serviceDocumentWpf);


            DataSourceWpf          dataSourceWpf          = relatedSourceWpf as DataSourceWpf;
            ListFormWpf            listFormWpf            = relatedSourceWpf as ListFormWpf;
            MenuFormWpf            menuFormWpf            = relatedSourceWpf as MenuFormWpf;
            EnterSingleDataFormWpf enterSingleDataFormWpf = relatedSourceWpf as EnterSingleDataFormWpf;
            ShowDataFormWpf        showDataFormWpf        = relatedSourceWpf as ShowDataFormWpf;

            // Si el Source es de entrada
            //obtengo y guardo el connectionpoint del widget correspondiente
            if (connectionWidgetEntity.Source.ConnectionType == (int)ConnectionPointType.Input)
            {
                if (dataSourceWpf != null)
                {
                    source = dataSourceWpf.InputConnectionPoint as ConnectionPointWpf;
                }
                if (listFormWpf != null)
                {
                    source = listFormWpf.InputConnectionPoint as ConnectionPointWpf;
                }
                if (menuFormWpf != null)
                {
                    source = menuFormWpf.InputConnectionPoint as ConnectionPointWpf;
                }
                if (enterSingleDataFormWpf != null)
                {
                    source = enterSingleDataFormWpf.InputConnectionPoint as ConnectionPointWpf;
                }
                if (showDataFormWpf != null)
                {
                    source = showDataFormWpf.InputConnectionPoint as ConnectionPointWpf;
                }
            }
            // El Source es de Output obtengo y guardo el Widget correpondiente
            else
            {
                if (dataSourceWpf != null)
                {
                    source = dataSourceWpf.OutputConnectionPoint as ConnectionPointWpf;
                }
                if (listFormWpf != null)
                {
                    source = listFormWpf.OutputConnectionPoint as ConnectionPointWpf;
                }
                if (menuFormWpf != null)
                {
                    foreach (FormMenuItemWpf menuItem in menuFormWpf.MenuItems)
                    {
                        if (String.CompareOrdinal(menuItem.Text, connectionWidgetEntity.Source.ParentComponent.Text) == 0)
                        {
                            source = menuItem.OutputConnectionPoint as ConnectionPointWpf;
                        }
                    }
                }
                if (enterSingleDataFormWpf != null)
                {
                    source = enterSingleDataFormWpf.OutputConnectionPoint as ConnectionPointWpf;
                }
                if (showDataFormWpf != null)
                {
                    source = showDataFormWpf.OutputConnectionPoint as ConnectionPointWpf;
                }
            }

            dataSourceWpf          = relatedTargetWpf as DataSourceWpf;
            listFormWpf            = relatedTargetWpf as ListFormWpf;
            menuFormWpf            = relatedTargetWpf as MenuFormWpf;
            enterSingleDataFormWpf = relatedTargetWpf as EnterSingleDataFormWpf;
            showDataFormWpf        = relatedTargetWpf as ShowDataFormWpf;

            // Si el Target es input
            if (connectionWidgetEntity.Target.ConnectionType == (int)ConnectionPointType.Input)
            {
                if (dataSourceWpf != null)
                {
                    target = dataSourceWpf.InputConnectionPoint as ConnectionPointWpf;
                }
                if (listFormWpf != null)
                {
                    target = listFormWpf.InputConnectionPoint as ConnectionPointWpf;
                }
                if (menuFormWpf != null)
                {
                    target = menuFormWpf.InputConnectionPoint as ConnectionPointWpf;
                }
                if (enterSingleDataFormWpf != null)
                {
                    target = enterSingleDataFormWpf.InputConnectionPoint as ConnectionPointWpf;
                }
                if (showDataFormWpf != null)
                {
                    target = showDataFormWpf.InputConnectionPoint as ConnectionPointWpf;
                }
            }
            // El Target es de Output obtengo y guardo el Widget correpondiente
            else
            {
                if (dataSourceWpf != null)
                {
                    target = dataSourceWpf.OutputConnectionPoint as ConnectionPointWpf;
                }

                if (listFormWpf != null)
                {
                    target = listFormWpf.OutputConnectionPoint as ConnectionPointWpf;
                }
                if (menuFormWpf != null)
                {
                    target = menuFormWpf.OutputConnectionPoint as ConnectionPointWpf;
                }

                if (enterSingleDataFormWpf != null)
                {
                    target = enterSingleDataFormWpf.OutputConnectionPoint as ConnectionPointWpf;
                }
                if (showDataFormWpf != null)
                {
                    target = showDataFormWpf.OutputConnectionPoint as ConnectionPointWpf;
                }
            }

            ConnectionWpf connectionWpf = new ConnectionWpf(source, target);

            return(connectionWpf);
        }
        /// <summary>
        /// Convierte un CustomerServiceDataEntity guardado en la base de datos en un ServiceDocumentWpf para ser usado en un proyecto wpf.
        /// </summary>
        /// <param name="documentEntity"></param>
        /// <param name="serviceDocumentWpf"></param>
        /// <param name="session"></param>
        public static void ConvertEntityToServiceModelWithStatistics(CustomerServiceDataEntity documentEntity, ServiceDocumentWpf serviceDocumentWpf, string session)
        {
            Dictionary <Component, ComponentEntity> connectableComponents = new Dictionary <Component, ComponentEntity>();

            foreach (ComponentEntity componentEntity in documentEntity.Components)
            {
                StatisticsWpf statisticsCanvas;

                switch (componentEntity.ComponentType)
                {
                case (int)ComponentType.DataSource:

                    // Genera e inserta un componente de origen de dato en un documento de servicio.
                    DataSourceWpf dataSource = Utilities.ConvertEntityToDataSource(componentEntity, serviceDocumentWpf.DataModel);
                    dataSource.MakeCanvas();
                    serviceDocumentWpf.Components.Add(dataSource);
                    connectableComponents.Add(dataSource, componentEntity);
                    break;

                case (int)ComponentType.EnterSingleDataFrom:

                    // Genera e inserta el componente de entrada de datos en el documento del servicio.
                    EnterSingleDataFormWpf enterSingleData = Utilities.ConvertEntityToEnterSingleData(componentEntity);
                    enterSingleData.MakeCanvas();
                    serviceDocumentWpf.Components.Add(enterSingleData);
                    connectableComponents.Add(enterSingleData, componentEntity);

                    // Genera el componente de estadistica para el formulario y lo agrega
                    statisticsCanvas = new StatisticsWpf(enterSingleData, serviceDocumentWpf.DrawArea, StatisticsWpf.GenerateStatisticSummary(componentEntity, session));
                    serviceDocumentWpf.Components.Add(statisticsCanvas);
                    break;

                case (int)ComponentType.ListForm:

                    // Genera e inserta el componente de origen de datos en el documento del servicio
                    ListFormWpf listFormWpf = Utilities.ConvertEntityToListForm(componentEntity);
                    listFormWpf.MakeCanvas();
                    serviceDocumentWpf.Components.Add(listFormWpf);
                    connectableComponents.Add(listFormWpf, componentEntity);

                    // Asigna el formulario de listas como el componente de inicio si lo es.
                    if (documentEntity.InitComponent != null && documentEntity.InitComponent.Id == componentEntity.Id)
                    {
                        serviceDocumentWpf.StartWidget = listFormWpf;
                    }

                    // Genera el componente de estadistica y lo agrega
                    statisticsCanvas = new StatisticsWpf(listFormWpf, serviceDocumentWpf.DrawArea, StatisticsWpf.GenerateStatisticSummary(componentEntity, session));
                    serviceDocumentWpf.Components.Add(statisticsCanvas);
                    break;

                case (int)ComponentType.MenuForm:

                    // Genera e inserta el componetne de origen de datos en el documento del servicio
                    MenuFormWpf menuForm = Utilities.ConvertEntityToMenuForm(componentEntity);
                    menuForm.MakeCanvas();
                    serviceDocumentWpf.Components.Add(menuForm);

                    // Agrega el formulario de menu y todos los items del menu
                    connectableComponents.Add(menuForm, componentEntity);
                    for (int i = 0; i < menuForm.MenuItems.Count; i++)
                    {
                        connectableComponents.Add(menuForm.MenuItems[i], componentEntity.MenuItems[i]);
                    }

                    // Asigna el formulario de menu como componente de inicio
                    if (documentEntity.InitComponent != null && documentEntity.InitComponent.Id == componentEntity.Id)
                    {
                        serviceDocumentWpf.StartWidget = menuForm;
                    }

                    // Genera el componente de estadistica y lo agrega
                    statisticsCanvas = new StatisticsWpf(menuForm, serviceDocumentWpf.DrawArea, StatisticsWpf.GenerateStatisticSummary(componentEntity, session));
                    serviceDocumentWpf.Components.Add(statisticsCanvas);
                    break;

                case (int)ComponentType.ShowDataForm:

                    // Genera e inserta el componente de origen de datos en el documento de servicio.
                    ShowDataFormWpf showDataFormWpf = Utilities.ConvertEntityToShowDataForm(componentEntity);
                    showDataFormWpf.MakeCanvas();
                    serviceDocumentWpf.Components.Add(showDataFormWpf);
                    connectableComponents.Add(showDataFormWpf, componentEntity);

                    // Genera el componente de estadistica y lo agrega
                    statisticsCanvas = new StatisticsWpf(showDataFormWpf, serviceDocumentWpf.DrawArea, StatisticsWpf.GenerateStatisticSummary(componentEntity, session));
                    serviceDocumentWpf.Components.Add(statisticsCanvas);
                    break;
                }
            }

            // Convierte cada una de las conexiones
            foreach (ConnectionWidgetEntity connectionWidgetEntity in documentEntity.Connections)
            {
                try
                {
                    ConnectionWpf connectionWpf = ConvertEntityToConnection(connectableComponents, connectionWidgetEntity, serviceDocumentWpf);
                    serviceDocumentWpf.AddConnection(connectionWpf);
                }
                catch (ArgumentNullException)
                {
                    Util.ShowErrorDialog(UtnEmall.ServerManager.Properties.Resources.NonFatalErrorLoadingConnection);
                }
            }
        }
        /// <summary>
        /// Convierte un CustomerServiceDataEntity almacenado en la base de datos en un ServiceDocumentWpf para ser usado en un proyecto wpf
        /// </summary>
        /// <param name="documentEntity"></param>
        /// <param name="serviceDocumentWpf"></param>
        public static void ConvertEntityToServiceModel(CustomerServiceDataEntity documentEntity, ServiceDocumentWpf serviceDocumentWpf)
        {
            Dictionary <Component, ComponentEntity> connectableComponents = new Dictionary <Component, ComponentEntity>();

            foreach (ComponentEntity componentEntity in documentEntity.Components)
            {
                switch (componentEntity.ComponentType)
                {
                // Convierte un DataSourceEntity en un DataSourceWpf
                case (int)ComponentType.DataSource:
                    DataSourceWpf dataSource = Utilities.ConvertEntityToDataSource(componentEntity, serviceDocumentWpf.DataModel);
                    dataSource.MakeCanvas();
                    serviceDocumentWpf.Components.Add(dataSource);
                    connectableComponents.Add(dataSource, componentEntity);
                    break;

                // Convierte un EnterSingleDataFormEntity en un EnterSingleDataFormWpf
                case (int)ComponentType.EnterSingleDataFrom:
                    EnterSingleDataFormWpf enterSingleData = Utilities.ConvertEntityToEnterSingleData(componentEntity);
                    enterSingleData.MakeCanvas();
                    serviceDocumentWpf.Components.Add(enterSingleData);
                    connectableComponents.Add(enterSingleData, componentEntity);
                    break;

                // Convierte un ListFormEntity en un ListFormWpf
                case (int)ComponentType.ListForm:
                    ListFormWpf listFormWpf = Utilities.ConvertEntityToListForm(componentEntity);
                    listFormWpf.MakeCanvas();
                    serviceDocumentWpf.Components.Add(listFormWpf);
                    connectableComponents.Add(listFormWpf, componentEntity);

                    if (documentEntity.InitComponent != null && documentEntity.InitComponent.Id == componentEntity.Id)
                    {
                        serviceDocumentWpf.StartWidget = listFormWpf;
                    }
                    break;

                // Convierte un MenuFormEntity en un MenuFormWpf
                case (int)ComponentType.MenuForm:
                    MenuFormWpf menuForm = Utilities.ConvertEntityToMenuForm(componentEntity);
                    menuForm.MakeCanvas();
                    serviceDocumentWpf.Components.Add(menuForm);

                    connectableComponents.Add(menuForm, componentEntity);
                    for (int i = 0; i < menuForm.MenuItems.Count; i++)
                    {
                        connectableComponents.Add(menuForm.MenuItems[i], componentEntity.MenuItems[i]);
                    }

                    if (documentEntity.InitComponent != null && documentEntity.InitComponent.Id == componentEntity.Id)
                    {
                        serviceDocumentWpf.StartWidget = menuForm;
                    }
                    break;

                // Convierte un ShowDataFormEntity en un ShowDataFormWpf
                case (int)ComponentType.ShowDataForm:
                    ShowDataFormWpf showDataFormWpf = Utilities.ConvertEntityToShowDataForm(componentEntity);
                    showDataFormWpf.MakeCanvas();
                    serviceDocumentWpf.Components.Add(showDataFormWpf);
                    connectableComponents.Add(showDataFormWpf, componentEntity);
                    break;

                default:
                    break;
                }
            }

            // Convierte cada una de las conexiones
            foreach (ConnectionWidgetEntity connectionWidgetEntity in documentEntity.Connections)
            {
                ConnectionWpf connectionWpf = ConvertEntityToConnection(connectableComponents, connectionWidgetEntity, serviceDocumentWpf);
                serviceDocumentWpf.AddConnection(connectionWpf);
            }
        }