Click here to Skip to main content
15,892,199 members
Articles / Programming Languages / C#

Universal Framework for Science and Engineering - Part 6: Determination of Orbits of Artificial Satellites

Rate me:
Please Sign up or sign in to vote.
4.88/5 (28 votes)
8 Jul 2011CPOL19 min read 82.5K   6.6K   82  
An article on framework applications to determine the orbits of artificial satellites
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Serialization;


using CategoryTheory;
using DiagramUI;
using Diagram.UI.Interfaces;
using DiagramUI.Labels;
using DiagramUI.Interfaces;

using DataSetService;


using Database.UI.Forms;


namespace Database.UI.Labels
{
    [Serializable()]
    public partial class QueryLabel : UserControl, ISerializable,
        IObjectLabel, INonstandardLabel
    {
        #region Fields

        protected IDataSetProvider provider;

        bool showTable = false;

        protected Form form;

        private IDesktop desktop;

        #endregion

        #region Ctor

        public QueryLabel()
        {
            InitializeComponent();
        }


        protected QueryLabel(SerializationInfo info, StreamingContext context)
            : this()
        {
            ResourceService.Resources.LoadControlResources(this, Database.UI.Utils.ControlUtilites.Resources);
            showTable = (bool)info.GetValue("ShowTable", typeof(bool));
            checkBoxShowData.Checked = showTable;
        }

        #endregion

        #region ISerializable Members

        void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("ShowTable", showTable, typeof(bool));
        }

        #endregion


        #region IObjectLabel Members

        public virtual ICategoryObject Object
        {
            get
            {
                return provider as ICategoryObject;
            }
            set
            {
                if (!(value is StatementWrapper))
                {
                    CategoryException.ThrowIllegalSourceException();
                }
                provider = value as StatementWrapper;
                value.Object = this;
            }
        }

        #endregion

        #region INamedComponent Members

        string INamedComponent.Name
        {
            get { return this.GetRootLabel().Name; }
        }

        string INamedComponent.Kind
        {
            get { return ""; }
        }

        public virtual string Type
        {
            get { return typeof(StatementWrapper).FullName; }
        }

        void INamedComponent.Remove()
        {
        }

        int INamedComponent.X
        {
            get
            {
                return 0;
            }
            set
            {
            }
        }

        int INamedComponent.Y
        {
            get
            {
                return 0;
            }
            set
            {
            }
        }

        IDesktop INamedComponent.Desktop
        {
            get
            {
                if (desktop == null)
                {
                    desktop = this.GetRootLabel().Desktop;
                }
                return desktop;
            }
            set
            {
            }
        }

        int INamedComponent.Ord
        {
            get
            {
                INamedComponent nc = this;
                Control c = nc.Desktop as Control;
                return c.Controls.GetChildIndex(this);
            }
        }


        INamedComponent INamedComponent.Parent
        {
            get
            {
                return null;
            }
            set
            {
                throw new Exception("You should not set parent to UI component");
            }
        }

        public INamedComponent GetRoot(IDesktop desktop)
        {
            return PureObjectLabel.GetRoot(this, desktop);
        }

        string INamedComponent.GetName(IDesktop desktop)
        {
            return PureObjectLabel.GetName(this, desktop);
        }

        string INamedComponent.RootName
        {
            get
            {
                INamedComponent nc = this;
                return nc.GetName(nc.Desktop.Root);
            }
        }

        INamedComponent INamedComponent.Root
        {
            get { return PureObjectLabel.GetRoot(this); }
        }


        INamedComponent INamedComponent.GetRoot(IDesktop desktop)
        {
            return PureObjectLabel.GetRoot(this, desktop);
        }


        #endregion

        #region INonstandardLabel Members

        void INonstandardLabel.Initialize()
        {
        }

        void INonstandardLabel.Post()
        {
            ShowNumber();
            ShowTable();
            checkBoxShowData.CheckedChanged += checkBoxShowData_CheckedChanged;
        }

        void INonstandardLabel.Resize()
        {
        }

        public virtual void CreateForm()
        {
            form = new FormStatementWrapper(this.GetRootLabel(), checkBoxShowData.Checked,
                ShowNumber, ShowTable);
        }

        object INonstandardLabel.Form
        {
            get { return form; }
        }

        public virtual object Image
        {
            get { return ResourceImage.Query; }
        }

        #endregion

        #region Event Handlers

        private void checkBoxShowData_CheckedChanged(object sender, EventArgs e)
        {
            showTable = checkBoxShowData.Checked;
            ShowTable();
        }

        #endregion

        #region Members

        private void Check(bool b)
        {
            checkBoxShowData.Checked = b;
        }

        private DataTable Table
        {
            get
            {
                DataSet ds = provider.DataSet;
                if (ds == null)
                {
                    return null;
                }
                if (ds.Tables.Count == 0)
                {
                    return null;
                }
                return ds.Tables[0];
            }
        }

        protected void ShowNumber()
        {
            DataTable t = Table;
            if (t == null)
            {
                return;
            }
            labelNumber.Text = 
                ResourceService.Resources.GetControlResource("Number of rows: ",
    Database.UI.Utils.ControlUtilites.Resources) + t.Rows.Count;

        }

        private void ShowTable()
        {
            if (showTable)
            {
                DataTable t = Table;
                if (t == null)
                {
                    dataGridViewTable.DataMember = null;
                    return;
                }
                dataGridViewTable.DataSource = provider.DataSet;
                dataGridViewTable.DataMember = t.TableName;
                return;
            }
            dataGridViewTable.DataMember = null;
        }


        protected void ShowTable(bool show)
        {
            checkBoxShowData.Checked = show;
        }
        #endregion

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Russian Federation Russian Federation
Ph. D. Petr Ivankov worked as scientific researcher at Russian Mission Control Centre since 1978 up to 2000. Now he is engaged by Aviation training simulators http://dinamika-avia.com/ . His additional interests are:

1) Noncommutative geometry

http://front.math.ucdavis.edu/author/P.Ivankov

2) Literary work (Russian only)

http://zhurnal.lib.ru/editors/3/3d_m/

3) Scientific articles
http://arxiv.org/find/all/1/au:+Ivankov_Petr/0/1/0/all/0/1

Comments and Discussions