Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version
Go to top

User-driven applications

, 10 Apr 2010
User-driven applications are the programs in which full control is given to the users. Designers of such programs are responsible only for developing an instrument for solving some task, but they do not enforce users to work with this instrument according with a predefined scenario.
TheoryOfUserDrivenApplications.zip
TheoryOfUserDrivenApplications
TheoryOfUserDrivenApplications
bin
Debug
TheoryOfUserDrivenApplications.vshost.exe
Release
MoveGraphLibrary.dll
TheoryOfUserDrivenApplications.bin
TheoryOfUserDrivenApplications.exe
TheoryOfUserDrivenApplications.vshost.exe
Properties
Settings.settings
Resources
ArrowDown.bmp
ArrowUp.bmp
DELETE.BMP
Hangar.bmp
Lock.bmp
palette_.bmp
RuralHouse.bmp
RuralLeftPlus.bmp
RuralRightPlus.bmp
SimpleHouse.bmp
User_driven_applications.doc
User_driven_applications.pdf
using System;
using System .Collections .Generic;
using System .IO;
using System .Windows .Forms;

using MoveGraphLibrary;

namespace UserDrivenApplications
{
    public class Data_Set
    {
        string name;
        bool bShowToUser;
        SetType typeSet;
        List<Data_Number> datNumbers = new List<Data_Number> ();
        List<Data_String> datStrings = new List<Data_String> ();
        List<Data_ABArray> datABArrays = new List<Data_ABArray> ();
        string comment = "";

        // -------------------------------------------------
        public Data_Set (string strName, bool bShow, SetType type, string cmnt) 
        {
            name = strName;
            bShowToUser = bShow;
            typeSet = type;
            if (!string .IsNullOrEmpty (cmnt))
            {
                comment = cmnt;
            }
        }
        public Data_Set (string strName, bool bShow, SetType type)
            : this (strName, bShow, type, null)
        {
        }
        // -------------------------------------------------
        public Data_Set (string strName, bool bShow, Data_Number datnum, string cmnt)   // [] strsCmnts)
        {
            name = strName;
            bShowToUser = bShow;
            typeSet = SetType .Numbers;
            datNumbers .Add (datnum);
            if (!string .IsNullOrEmpty (cmnt))
            {
                comment = cmnt;
            }
        }
        public Data_Set (string strName, bool bShow, Data_Number datnum)
            : this (strName, bShow, datnum, null)
        {
        }
        public Data_Set (string strName, Data_Number datnum)
            : this (strName, true, datnum, null)
        {
        }
        // -------------------------------------------------
        public Data_Set (string strName, bool bShow, Data_String datstr, string cmnt)   // [] strsCmnts)
        {
            name = strName;
            bShowToUser = bShow;
            typeSet = SetType .Strings;
            datStrings .Add (datstr);
            if (!string .IsNullOrEmpty (cmnt))
            {
                comment = cmnt;
            }
        }
        public Data_Set (string strName, bool bShow, Data_String datstr)
            : this (strName, bShow, datstr, null)
        {
        }
        public Data_Set (string strName, Data_String datstr)
            : this (strName, true, datstr, null)
        {
        }
        // -------------------------------------------------
        public Data_Set (string strName, bool bShow, Data_ABArray datar, string cmnt)  
        {
            name = strName;
            bShowToUser = bShow;
            typeSet = SetType .ABArrays;
            datABArrays .Add (datar);
            if (!string .IsNullOrEmpty (cmnt))
            {
                comment = cmnt;
            }
        }
        public Data_Set (string strName, bool bShow, Data_ABArray datar)
            : this (strName, bShow, datar, null)
        {
        }
        public Data_Set (string strName, Data_ABArray datar)
            : this (strName, true, datar, null)
        {
        }
        // -------------------------------------------------        Name
        public string Name
        {
            get { return (name); }
            set
            {
                if (!string .IsNullOrEmpty (value))
                {
                    name = value;
                }
            }
        }
        // -------------------------------------------------        ShowToUser
        public bool ShowToUser
        {
            get { return (bShowToUser); }
            set { bShowToUser = value; }
        }
        // -------------------------------------------------        CheckData
        public void CheckData ()
        {
            if (typeSet == SetType .ABArrays)
            {
                for (int i = datABArrays .Count - 1; i >= 0; i--)
                {
                    if (!datABArrays [i] .HasData)
                    {
                        datABArrays .RemoveAt (i);
                    }
                }
            }
        }
        // -------------------------------------------------        HasData
        public bool HasData
        {
            get { return (datNumbers .Count > 0 || datStrings .Count > 0 || datABArrays .Count > 0); }
        }
        // -------------------------------------------------       SetType
        public SetType SetType
        {
            get { return (typeSet); }
        }
        // -------------------------------------------------        Comment
        public string Comment
        {
            get { return (comment); }
            set
            {
                if (value != null)
                {
                    comment = value;
                }
            }
        }
        // -------------------------------------------------        Statistics
        public void Statistics (out int elems, out int elemsShow)
        {
            int nShow = 0;
            switch (typeSet)
            {
                case SetType .Numbers:
                default:
                    elems = datNumbers .Count;
                    for (int i = 0; i < elems; i++)
                    {
                        if (datNumbers [i] .ShowToUser)
                        {
                            nShow++;
                        }
                    }
                    break;
                case SetType .Strings:
                    elems = datStrings .Count;
                    for (int i = 0; i < elems; i++)
                    {
                        if (datStrings [i] .ShowToUser)
                        {
                            nShow++;
                        }
                    }
                    break;
                case SetType .ABArrays:
                    elems = datABArrays .Count;
                    for (int i = 0; i < elems; i++)
                    {
                        if (datABArrays [i] .ShowToUser)
                        {
                            nShow++;
                        }
                    }
                    break;
            }
            elemsShow = nShow;
        }
        // -------------------------------------------------        Numbers
        public List<Data_Number> Numbers
        {
            get { return (datNumbers); }
        }
        // -------------------------------------------------        Strings
        public List<Data_String> Strings
        {
            get { return (datStrings); }
        }
        // -------------------------------------------------        ABArrays
        public List<Data_ABArray> ABArrays
        {
            get { return (datABArrays); }
        }
        // -------------------------------------------------        AddNumber
        public bool AddNumber (Data_Number dataNew)
        {
            bool bRet = false;
            if (typeSet == SetType .Numbers)
            {
                for (int i = 0; i < datNumbers .Count; i++)
                {
                    if (dataNew .Name == datNumbers [i] .Name)
                    {
                        return (false);
                    }
                }
                datNumbers .Add (dataNew);
                bRet = true;
            }
            return (bRet);
        }
        // -------------------------------------------------        AddString
        public bool AddString (Data_String dataNew)
        {
            bool bRet = false;
            if (typeSet == SetType .Strings)
            {
                for (int i = 0; i < datStrings .Count; i++)
                {
                    if (dataNew .Name == datStrings [i] .Name)
                    {
                        return (false);
                    }
                }
                datStrings .Add (dataNew);
                bRet = true;
            }
            return (bRet);
        }
        // -------------------------------------------------        AddABArray
        public bool AddABArray (Data_ABArray arAB)
        {
            bool bRet = false;
            if (typeSet == SetType .ABArrays)
            {
                for (int i = 0; i < datABArrays .Count; i++)
                {
                    if (arAB .Name == datABArrays [i] .Name)
                    {
                        return (false);
                    }
                }
                datABArrays .Add (arAB);
                bRet = true;
            }
            return (bRet);
        }
        // -------------------------------------------------        DeleteNumber
        public bool DeleteNumber (int iDel)
        {
            bool bRet = false;
            if (typeSet == SetType .Numbers)
            {
                if (0 <= iDel && iDel < datNumbers .Count)
                {
                    datNumbers .RemoveAt (iDel);
                }
                bRet = true;
            }
            return (bRet);
        }
        // -------------------------------------------------        DeleteNumber
        public bool DeleteNumber (string datName)
        {
            bool bRet = false;
            if (typeSet == SetType .Numbers)
            {
                for (int i = 0; i < datNumbers .Count; i++)
                {
                    if (datName == datNumbers [i] .Name)
                    {
                        datNumbers .RemoveAt (i);
                        break;
                    }
                }
                bRet = true;
            }
            return (bRet);
        }
        // -------------------------------------------------        DeleteString
        public bool DeleteString (int iDel)
        {
            bool bRet = false;
            if (typeSet == SetType .Strings)
            {
                if (0 <= iDel && iDel < datStrings .Count)
                {
                    datStrings .RemoveAt (iDel);
                }
                bRet = true;
            }
            return (bRet);
        }
        // -------------------------------------------------        DeleteString
        public bool DeleteString (string datName)
        {
            bool bRet = false;
            if (typeSet == SetType .Numbers)
            {
                for (int i = 0; i < datStrings .Count; i++)
                {
                    if (datName == datStrings [i] .Name)
                    {
                        datStrings .RemoveAt (i);
                        break;
                    }
                }
                bRet = true;
            }
            return (bRet);
        }
        // -------------------------------------------------        DeleteABArray
        public bool DeleteABArray (int iDel)
        {
            bool bRet = false;
            if (typeSet == SetType .ABArrays)
            {
                if (0 <= iDel && iDel < datABArrays .Count)
                {
                    datABArrays .RemoveAt (iDel);
                }
                bRet = true;
            }
            return (bRet);
        }
        // -------------------------------------------------        DeleteABArray
        public bool DeleteABArray (string datName)
        {
            bool bRet = false;
            if (typeSet == SetType .ABArrays)
            {
                for (int i = 0; i < datABArrays .Count; i++)
                {
                    if (datName == datABArrays [i] .Name)
                    {
                        datABArrays .RemoveAt (i);
                        break;
                    }
                }
                bRet = true;
            }
            return (bRet);
        }
        // -------------------------------------------------        InsertNumber
        public bool InsertNumber (int iPos, Data_Number dataNew)
        {
            bool bRet = false;
            if (typeSet == SetType .Numbers)
            {
                for (int i = 0; i < datNumbers .Count; i++)
                {
                    if (dataNew .Name == datNumbers [i] .Name)
                    {
                        return (false);
                    }
                }
                iPos = Math .Min (Math .Max (0, iPos), datNumbers .Count);
                datNumbers .Insert (iPos, dataNew);
                bRet = true;
            }
            return (bRet);
        }
        // -------------------------------------------------        InsertString
        public bool InsertString (int iPos, Data_String dataNew)
        {
            bool bRet = false;
            if (typeSet == SetType .Strings)
            {
                for (int i = 0; i < datStrings .Count; i++)
                {
                    if (dataNew .Name == datStrings [i] .Name)
                    {
                        return (false);
                    }
                }
                iPos = Math .Min (Math .Max (0, iPos), datStrings .Count);
                datStrings .Insert (iPos, dataNew);
                bRet = true;
            }
            return (bRet);
        }
        // -------------------------------------------------        InsertABArray
        public bool InsertABArray (int iPos, Data_ABArray dataNew)
        {
            bool bRet = false;
            if (typeSet == SetType .ABArrays)
            {
                for (int i = 0; i < datABArrays .Count; i++)
                {
                    if (dataNew .Name == datABArrays [i] .Name)
                    {
                        return (false);
                    }
                }
                iPos = Math .Min (Math .Max (0, iPos), datABArrays .Count);
                datABArrays .Insert (iPos, dataNew);
                bRet = true;
            }
            return (bRet);
        }
        // -------------------------------------------------        IntoFile
        public void IntoFile (BinaryWriter bw)
        {
            try
            {
                if (HasData)
                {
                    bw .Write (name);               // 0
                    bw .Write (bShowToUser);        // 1
                    bw .Write ((int) typeSet);      // 2
                    bw .Write (comment);            // 3
                    switch (typeSet)
                    {
                        case SetType .Numbers:
                            bw .Write (datNumbers .Count);          // 4
                            for (int i = 0; i < datNumbers .Count; i++)
                            {
                                datNumbers [i] .IntoFile (bw);
                            }
                            break;
                        case SetType .Strings:
                            bw .Write (datStrings .Count);          // 4
                            for (int i = 0; i < datStrings .Count; i++)
                            {
                                datStrings [i] .IntoFile (bw);
                            }
                            break;
                        case SetType .ABArrays:
                            bw .Write (datABArrays .Count);         // 4
                            for (int i = 0; i < datABArrays .Count; i++)
                            {
                                datABArrays [i] .IntoFile (bw);
                            }
                            break;
                    }
                }
            }
            catch
            {
            }
            finally
            {
            }
        }
        // -------------------------------------------------        FromFile
        public static void FromFile (Form form, BinaryReader br, out Data_Set data)
        {
            try
            {
                string strName = br .ReadString ();             // 0
                bool bShow = br .ReadBoolean ();                // 1
                SetType type = (SetType) br .ReadInt32 ();      // 2
                string cmnt = br .ReadString ();                // 3
                Data_Set setNew = new Data_Set (strName, bShow, type, cmnt);
                int nElems = br .ReadInt32 ();                  // 4
                switch (type)
                {
                    case SetType .Numbers:
                        for (int i = 0; i < nElems; i++)
                        {
                            Data_Number numNew = null;
                            Data_Number .FromFile (br, out numNew);
                            if (numNew != null)
                            {
                                setNew .AddNumber (numNew);
                            }
                        }
                        break;

                    case SetType .Strings:
                        for (int i = 0; i < nElems; i++)
                        {
                            Data_String stringNew;
                            Data_String .FromFile (br, out stringNew);
                            if (stringNew != null)
                            {
                                setNew .AddString (stringNew);
                            }
                        }
                        break;

                    case SetType .ABArrays:
                        for (int i = 0; i < nElems; i++)
                        {
                            Data_ABArray arrayNew;
                            Data_ABArray .FromFile (form, br, out arrayNew);
                            if (arrayNew != null)
                            {
                                setNew .AddABArray (arrayNew);
                            }
                        }
                        break;
                }
                data = setNew;
            }
            catch
            {
                data = null;
                string strText = "Can't read Data_Set";
                MessageBox .Show (strText, "Problem on Reading", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
            }
            finally
            {
            }
        }
    }
}

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)

Share

About the Author

SergeyAndreyev

United States United States
No Biography provided

| Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 10 Apr 2010
Article Copyright 2010 by SergeyAndreyev
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid