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

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_Number
    {
        string name;
        bool bShowToUser;
        NumberType typeNum;
        int nVal, nMin, nMax;
        double fVal, fMin, fMax;
        string comment = "";

        // -------------------------------------------------
        public Data_Number (string strName, bool bShow, int minValue, int maxValue, int val, string cmnt) 
        {
            name = strName;
            bShowToUser = bShow;
            typeNum = NumberType .INT;
            nMin = Math .Min (minValue, maxValue);
            nMax = Math .Max (minValue, maxValue);
            nVal = Math .Min (Math .Max (nMin, val), nMax);
            if (!string .IsNullOrEmpty (cmnt))
            {
                comment = cmnt;
            }
        }
        public Data_Number (string strName, bool bShow, int minValue, int maxValue, int val)
            : this (strName, bShow, minValue, maxValue, val, null)
        {
        }
        public Data_Number (string strName, bool bShow, int minValue, int maxValue, string cmnt) 
            : this (strName, bShow, minValue, maxValue, Math .Min (minValue, maxValue), cmnt) 
        {
        }
        public Data_Number (string strName, bool bShow, int minValue, int maxValue)
            : this (strName, bShow, minValue, maxValue, Math .Min (minValue, maxValue), null)
        {
        }
        public Data_Number (string strName, int minValue, int maxValue, int val, string cmnt) 
            : this (strName, true, minValue, maxValue, val, cmnt)
        {
        }
        public Data_Number (string strName, int minValue, int maxValue, int val)
            : this (strName, true, minValue, maxValue, val, null)
        {
        }
        public Data_Number (string strName, int minValue, int maxValue)
            : this (strName, true, minValue, maxValue, Math .Min (minValue, maxValue), null)
        {
        }
        // -------------------------------------------------
        public Data_Number (string strName, bool bShow, double minValue, double maxValue, double val, string cmnt) 
        {
            name = strName;
            bShowToUser = bShow;
            typeNum = NumberType .DOUBLE;
            fMin = Math .Min (minValue, maxValue);
            fMax = Math .Max (minValue, maxValue);
            fVal = Math .Min (Math .Max (fMin, val), fMax);
            if (!string .IsNullOrEmpty (cmnt))
            {
                comment = cmnt;
            }
        }
        public Data_Number (string strName, bool bShow, double minValue, double maxValue, double val)
            : this (strName, bShow, minValue, maxValue, val, null)
        {
        }
        public Data_Number (string strName, bool bShow, double minValue, double maxValue, string cmnt) 
            : this (strName, bShow, minValue, maxValue, Math .Min (minValue, maxValue), cmnt) 
        {
        }
        public Data_Number (string strName, bool bShow, double minValue, double maxValue)
            : this (strName, bShow, minValue, maxValue, Math .Min (minValue, maxValue), null)
        {
        }
        public Data_Number (string strName, double minValue, double maxValue, double val, string cmnt) 
            : this (strName, true, minValue, maxValue, val, cmnt) 
        {
        }
        public Data_Number (string strName, double minValue, double maxValue, double val)
            : this (strName, true, minValue, maxValue, val, null)
        {
        }
        public Data_Number (string strName, double minValue, double maxValue)
            : this (strName, true, minValue, maxValue, Math .Min (minValue, maxValue), 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; }
        }
        // -------------------------------------------------        NumberType
        public NumberType NumberType
        {
            get { return (typeNum); }
        }
        // -------------------------------------------------        Minimum
        public double Minimum
        {
            get
            {
                if (typeNum == NumberType .DOUBLE)
                {
                    return (fMin);
                }
                else
                {
                    return (nMin);
                }
            }
        }
        // -------------------------------------------------        Maximum
        public double Maximum
        {
            get
            {
                if (typeNum == NumberType .DOUBLE)
                {
                    return (fMax);
                }
                else
                {
                    return (nMax);
                }
            }
        }
        // -------------------------------------------------        Value
        public double Value
        {
            get
            {
                if (typeNum == NumberType .DOUBLE)
                {
                    return (fVal);
                }
                else
                {
                    return (nVal);
                }
            }
            set
            {
                if (typeNum == NumberType .DOUBLE)
                {
                    if (fMin <= value && value <= fMax)
                    {
                        fVal = value;
                    }
                }
                else
                {
                    if (nMin <= value && value <= nMax)
                    {
                        nVal = Convert .ToInt32 (value);
                    }
                }
            }
        }
        // -------------------------------------------------        Comment
        public string Comment
        {
            get { return (comment); }
            set
            {
                if (value != null)
                {
                    comment = value;
                }
            }
        }
        // -------------------------------------------------        IntoFile
        public void IntoFile (BinaryWriter bw)
        {
            try
            {
                bw .Write (name);                   // 0
                bw .Write (bShowToUser);            // 1
                bw .Write ((int) typeNum);          // 2
                if (typeNum == NumberType .INT)
                {
                    bw .Write (nMin);          // 3
                    bw .Write (nMax);          // 4
                    bw .Write (nVal);          // 5
                }
                else
                {
                    bw .Write (fMin);          // 3
                    bw .Write (fMax);          // 4
                    bw .Write (fVal);          // 5
                }
                bw .Write (comment);        // 6
            }
            catch
            {
            }
            finally
            {
            }
        }
        // -------------------------------------------------        FromFile
        public static void FromFile (BinaryReader br, out Data_Number data)
        {
            try
            {
                Data_Number numberNew;
                string str = br .ReadString ();     // 0
                bool bShow = br .ReadBoolean ();    // 1
                NumberType type = (NumberType) br .ReadInt32 ();    // 2
                if (type == NumberType .INT)
                {
                    numberNew = new Data_Number (str, bShow, br .ReadInt32 (), br .ReadInt32 (), br .ReadInt32 (), br .ReadString ());
                }
                else
                {
                    numberNew = new Data_Number (str, bShow, br .ReadDouble (), br .ReadDouble (), br .ReadDouble (), br .ReadString ());
                }
                data = numberNew;
            }
            catch
            {
                data = null;
                string strText = "Can't read Data_Number";
                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)

About the Author

SergeyAndreyev

United States United States
No Biography provided

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