Click here to Skip to main content
15,893,668 members
Articles / Programming Languages / C#

User-driven applications

Rate me:
Please Sign up or sign in to vote.
4.88/5 (24 votes)
10 Apr 2010CPOL136 min read 33.1K   5   78  
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.
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)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions