Click here to Skip to main content
15,896,269 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_String
    {
        string name;
        bool bShowToUser;
        string text;       // this is the string itself
        string comment = "";

        // -------------------------------------------------
        public Data_String (string strName, bool bShow, string txt, string cmnt) 
        {
            string trimmedtext = txt .Trim ();
            if (!string .IsNullOrEmpty (trimmedtext))
            {
                name = strName;
                bShowToUser = bShow;
                text = trimmedtext;
                if (!string .IsNullOrEmpty (cmnt))
                {
                    comment = cmnt;
                }
            }
        }
        public Data_String (string strName, bool bShow, string txt)
            : this (strName, bShow, txt, null)
        {
        }
        public Data_String (string strName, string txt, string cmnt) 
            : this (strName, true, txt, cmnt)  
        {
        }
        public Data_String (string strName, string txt)
            : this (strName, true, txt, 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; }
        }
        // -------------------------------------------------        HasData
        public bool HasData
        {
            get { return (!string .IsNullOrEmpty (text)); }
        }
        // -------------------------------------------------        Value
        public string Value
        {
            get { return (text); }
            set
            {
                if (!string .IsNullOrEmpty (value))
                {
                    text = value;
                }
            }
        }
        // -------------------------------------------------        Comment
        public string Comment
        {
            get { return (comment); }
            set
            {
                if (value != null)
                {
                    comment = value;
                }
            }
        }
        // -------------------------------------------------        IntoFile
        public void IntoFile (BinaryWriter bw)
        {
            try
            {
                if (HasData)
                {
                    bw .Write (name);           // 0
                    bw .Write (bShowToUser);    // 1
                    bw .Write (text);           // 2
                    bw .Write (comment);        // 3
                }
            }
            catch
            {
            }
            finally
            {
            }
        }
        // -------------------------------------------------        FromFile
        public static void FromFile (BinaryReader br, out Data_String data)
        {
            try
            {
                data = new Data_String (br .ReadString (), br .ReadBoolean (), br .ReadString (), br .ReadString ());
            }
            catch
            {
                data = null;
                string strText = "Can't read Data_String";
                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