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 .ComponentModel;
using System .Drawing;
using System .IO;
using System .Windows .Forms;
using Microsoft .Win32;

using MoveGraphLibrary;

namespace UserDrivenApplications
{
    public partial class Form_DataWorld : Form
    {
        // -------------------------------------------------        EnableGroup_Numbers
        private void EnableGroup_Numbers (bool bEnable)
        {
            if (bEnable == false)
            {
                groupNumbers .Title = "Numbers";
                ClearGroup_Numbers ();
            }
            List<Control> ctrls = groupNumbers .Controls;
            foreach (Control control in ctrls)
            {
                control .Enabled = bEnable;
            }
        }
        // -------------------------------------------------        ClearGroup_Numbers
        private void ClearGroup_Numbers ()
        {
            textNum_Value .Text = "";
            textNum_MinValue .Text = "";
            textNum_MaxValue .Text = "";
            textNum_Name .Text = "";
            textNum_Comment .Text = "";
            listNumbers .Items .Clear ();
        }
        // -------------------------------------------------        FillNumbersList
        private void FillNumbersList ()
        {
            ListView list = listNumbers;
            list .Items .Clear ();
            if (PageAndSetSelected)
            {
                Data_Set set = SelectedSet;
                if (set .SetType == SetType .Numbers)
                {
                    for (int i = 0; i < set .Numbers .Count; i++)
                    {
                        Data_Number data = set .Numbers [i];
                        string [] strs = new string [6];
                        strs [0] = data .Name;
                        strs [1] = data .Value .ToString ();
                        strs [2] = data .Minimum .ToString ();
                        strs [3] = data .Maximum .ToString ();
                        strs [4] = data .Comment;        
                        strs [5] = data .ShowToUser ? "Yes" : "No";
                        ListViewItem lvi = new ListViewItem (strs);
                        list .Items .Add (lvi);
                    }
                }
            }
        }
        // -------------------------------------------------        SelectedIndexChanged_listNumbers
        private void SelectedIndexChanged_listNumbers (object sender, EventArgs e)
        {
            ListView list = sender as ListView;

            textNum_Value .Text = "";
            textNum_MinValue .Text = "";
            textNum_MaxValue .Text = "";
            textNum_Name .Text = "";
            textNum_Comment .Text = "";
            if (PageAndSetSelected)
            {
                if (list .SelectedIndices .Count > 0)
                {
                    Data_Set set = SelectedSet;
                    Data_Number data = set .Numbers [list .SelectedIndices [0]];
                    textNum_Value .Text = data .Value .ToString ();
                    textNum_MinValue .Text = data .Minimum .ToString ();
                    textNum_MaxValue .Text = data .Maximum .ToString ();
                    domainUD_NumType .SelectedIndex = Convert .ToInt32 (data .NumberType);
                    textNum_Name .Text = data .Name;
                    textNum_Comment .Text = data .Comment;

                    btnDeleteNumber .Enabled = true;
                    btnShowHideNumber .Enabled = true;
                    btnNumberUp .Enabled = list .SelectedIndices [0] > 0;
                    btnNumberDown .Enabled = list .SelectedIndices [0] < list .Items .Count - 1;
                }
                else
                {
                    DisableFourButtons_Numbers ();
                }
            }
        }
        // -------------------------------------------------        DisableFourButtons_Numbers
        private void DisableFourButtons_Numbers ()
        {
            btnDeleteNumber .Enabled = false;
            btnShowHideNumber .Enabled = false;
            btnNumberUp .Enabled = false;
            btnNumberDown .Enabled = false;
        }
        // -------------------------------------------------        AfterLabelEdit_listNumbers
        private void AfterLabelEdit_listNumbers (object sender, LabelEditEventArgs e)
        {
            if (string .IsNullOrEmpty (e .Label) || string .IsNullOrEmpty (e .Label .Trim ()))
            {
                e .CancelEdit = true;
                return;
            }
            string str = e .Label .Trim ();
            ListView list = sender as ListView;
            int iSelLine = list .SelectedIndices [0];
            Data_Set set = SelectedSet;
            for (int i = 0; i < list .Items .Count; i++)
            {
                if (i != iSelLine)
                {
                    if (str == set .Numbers [i] .Name)
                    {
                        e .CancelEdit = true;
                        MessageBox .Show ("Number with such name already exists; select another name", "Rename number",
                                          MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                        return;
                    }
                }
            }
            set .Numbers [iSelLine] .Name = str;
            list .Items [iSelLine] .Selected = true;
            textNum_Name .Text = str;
        }
        // -------------------------------------------------        Click_btnDeleteNumber
        private void Click_btnDeleteNumber (object sender, EventArgs e)
        {
            if (PageAndSetSelected)
            {
                ListView list = listNumbers;
                if (list .SelectedIndices .Count > 0)
                {
                    if (DialogResult .Yes == MessageBox .Show ("Do you want to delete the selected number?", "Delete number",
                                                               MessageBoxButtons .YesNo, MessageBoxIcon .Question, MessageBoxDefaultButton .Button1))
                    {
                        int iSetSelected = listSets .SelectedIndices [0];
                        Data_Set set = SelectedSet;              
                        int iNumSelected = list .SelectedIndices [0];
                        set .DeleteNumber (iNumSelected);

                        SetsList_RefreshSelectShow (iSetSelected);
                        FillNumbersList ();
                        if (set .Numbers .Count > 0)
                        {
                            Auxi_Common .ListView_LineSelectAndShow (list, Math .Min (iNumSelected, set .Numbers .Count - 1));
                        }
                    }
                }
                else
                {
                    MessageBox .Show ("Number to delete is not selected", "Delete number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                }
            }
        }
        // -------------------------------------------------        Click_btnAddNumber
        private void Click_btnAddNumber (object sender, EventArgs e)
        {
            if (listSets .SelectedIndices .Count <= 0)
            {
                MessageBox .Show ("The set for the new number is not selected", "Add number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                return;
            }
            Data_Page page = SelectedPage;
            int iSetSelected = listSets .SelectedIndices [0];
            Data_Set set = page .Sets [iSetSelected];
            if (set .SetType != SetType .Numbers)
            {
                MessageBox .Show ("The selected set is not for numbers", "Add number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                return;
            }
            string strName = textNum_Name .Text .Trim ();
            if (string .IsNullOrEmpty (strName))
            {
                MessageBox .Show ("No name for the new Number", "Add number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                return;
            }
            for (int i = 0; i < set .Numbers .Count; i++)
            {
                if (strName == set .Numbers [i] .Name)
                {
                    MessageBox .Show ("Number with such name already exists in this Set; select another name", "Add number",
                                      MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                    return;
                }
            }
            string strMin = textNum_MinValue .Text .Trim ();
            string strMax = textNum_MaxValue .Text .Trim ();
            if (string .IsNullOrEmpty (strMin) || string .IsNullOrEmpty (strMax))
            {
                MessageBox .Show ("Range for the new Number is not defined", "Add number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                return;
            }
            double fVal, fMin, fMax;
            int nVal, nMin, nMax;
            string strVal = textNum_Value .Text .Trim ();
            string strCmnt = textNum_Comment .Text .Trim ();
            Data_Number data;
            if ((NumberType) domainUD_NumType .SelectedIndex == NumberType .DOUBLE)
            {
                if (!double .TryParse (strMin, out fMin))
                {
                    MessageBox .Show ("Wrong expression for minimum value", "Add number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                    return;
                }
                if (!double .TryParse (strMax, out fMax))
                {
                    MessageBox .Show ("Wrong expression for maximum value", "Add number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                    return;
                }
                if (!string .IsNullOrEmpty (strVal))
                {
                    if (!double .TryParse (strVal, out fVal))
                    {
                        MessageBox .Show ("Wrong expression for value", "Add number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                        return;
                    }
                    if (fVal < fMin || fMax < fVal)
                    {
                        MessageBox .Show ("Value is out of the range", "Add number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                        return;
                    }
                }
                else
                {
                    fVal = (fMin + fMax) / 2;
                }
                data = new Data_Number (strName, set .ShowToUser, fMin, fMax, fVal, strCmnt);
            }
            else
            {
                if (!int .TryParse (strMin, out nMin))
                {
                    MessageBox .Show ("Wrong expression for minimum value", "Add number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                    return;
                }
                if (!int .TryParse (strMax, out nMax))
                {
                    MessageBox .Show ("Wrong expression for maximum value", "Add number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                    return;
                }
                if (!string .IsNullOrEmpty (strVal))
                {
                    if (!int .TryParse (strVal, out nVal))
                    {
                        MessageBox .Show ("Wrong expression for value", "Add number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                        return;
                    }
                    if (nVal < nMin || nMax < nVal)
                    {
                        MessageBox .Show ("Value is out of the range", "Add number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                        return;
                    }
                }
                else
                {
                    nVal = (nMin + nMax) / 2;
                }
                data = new Data_Number (strName, set .ShowToUser, nMin, nMax, nVal, strCmnt);
            }
            set .AddNumber (data);
            SetsList_RefreshSelectShow (iSetSelected);
            FillNumbersList ();
            Auxi_Common .ListView_LineSelectAndShow (listNumbers, listNumbers .Items .Count - 1);
        }
        // -------------------------------------------------        Click_btnChangeNumber
        private void Click_btnChangeNumber (object sender, EventArgs e)
        {
            if (listNumbers .SelectedIndices .Count <= 0)
            {
                MessageBox .Show ("The number to change is not selected", "Change number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                return;
            }
            if (listSets .SelectedIndices .Count <= 0)
            {
                MessageBox .Show ("The set with the numbers is not selected", "Change number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                return;
            }
            Data_Set set = SelectedSet;
            if (set .SetType != SetType .Numbers)
            {
                MessageBox .Show ("The selected set is not for numbers", "Change number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                return;
            }
            string strName = textNum_Name .Text .Trim ();
            if (string .IsNullOrEmpty (strName))
            {
                MessageBox .Show ("Name must be not empty", "Change number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                return;
            }
            int iNumber = listNumbers .SelectedIndices [0];
            for (int i = 0; i < set .Numbers .Count; i++)
            {
                if (i != iNumber)
                {
                    if (strName == set .Numbers [i] .Name)
                    {
                        MessageBox .Show ("The same name is used for another number", "Change number",
                                          MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                        return;
                    }
                }
            }
            string strMin = textNum_MinValue .Text .Trim ();
            string strMax = textNum_MaxValue .Text .Trim ();
            if (string .IsNullOrEmpty (strMin) || string .IsNullOrEmpty (strMax))
            {
                MessageBox .Show ("Range for the Number is not defined", "Change number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                return;
            }
            double fVal, fMin, fMax;
            int nVal, nMin, nMax;
            string strVal = textNum_Value .Text .Trim ();
            string strCmnt = textNum_Comment .Text .Trim ();
            Data_Number data;
            bool bShow = set .Numbers [iNumber] .ShowToUser;
            if ((NumberType) domainUD_NumType .SelectedIndex == NumberType .DOUBLE)
            {
                if (!double .TryParse (strMin, out fMin))
                {
                    MessageBox .Show ("Wrong expression for minimum value", "Change number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                    return;
                }
                if (!double .TryParse (strMax, out fMax))
                {
                    MessageBox .Show ("Wrong expression for maximum value", "Change number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                    return;
                }
                if (!string .IsNullOrEmpty (strVal))
                {
                    if (!double .TryParse (strVal, out fVal))
                    {
                        MessageBox .Show ("Wrong expression for value", "Change number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                        return;
                    }
                    if (fVal < fMin || fMax < fVal)
                    {
                        MessageBox .Show ("Value is out of the range", "Change number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                        return;
                    }
                }
                else
                {
                    fVal = (fMin + fMax) / 2;
                }
                data = new Data_Number (strName, bShow, fMin, fMax, fVal, strCmnt);
            }
            else
            {
                if (!int .TryParse (strMin, out nMin))
                {
                    MessageBox .Show ("Wrong expression for minimum value", "Change number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                    return;
                }
                if (!int .TryParse (strMax, out nMax))
                {
                    MessageBox .Show ("Wrong expression for maximum value", "Change number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                    return;
                }
                if (!string .IsNullOrEmpty (strVal))
                {
                    if (!int .TryParse (strVal, out nVal))
                    {
                        MessageBox .Show ("Wrong expression for value", "Change number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                        return;
                    }
                    if (nVal < nMin || nMax < nVal)
                    {
                        MessageBox .Show ("Value is out of the range", "Change number", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                        return;
                    }
                }
                else
                {
                    nVal = (nMin + nMax) / 2;
                }
                data = new Data_Number (strName, bShow, nMin, nMax, nVal, strCmnt);
            }
            set .DeleteNumber (iNumber);
            set .InsertNumber (iNumber, data);
            FillNumbersList ();
            Auxi_Common .ListView_LineSelectAndShow (listNumbers, iNumber);
        }
        // -------------------------------------------------        Click_btnShowHideNumber
        private void Click_btnShowHideNumber (object sender, EventArgs e)
        {
            if (PageAndSetSelected)
            {
                ListView list = listNumbers;
                if (list .SelectedIndices .Count > 0)
                {
                    Data_Page page = SelectedPage;
                    int iSetSelected = listSets .SelectedIndices [0];
                    Data_Set set = SelectedSet;
                    int iNumSelected = list .SelectedIndices [0];
                    Data_Number data = set .Numbers [iNumSelected];
                    data .ShowToUser = !data .ShowToUser;

                    SetsList_RefreshSelectShow (iSetSelected);
                    Auxi_Common .ListView_LineSelectAndShow (list, iNumSelected);
                }
                else
                {
                    MessageBox .Show ("Number is not selected", "Numbers", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                }
            }
        }
        // -------------------------------------------------        Click_btnNumberUp
        private void Click_btnNumberUp (object sender, EventArgs e)
        {
            if (PageAndSetSelected)
            {
                ListView list = listNumbers;
                if (list .SelectedIndices .Count > 0)
                {
                    int iNumSelected = list .SelectedIndices [0];
                    if (iNumSelected > 0)
                    {
                        SelectedSet .Numbers .Reverse (iNumSelected - 1, 2);
                        iNumSelected--;
                        FillNumbersList ();
                        Auxi_Common .ListView_LineSelectAndShow (list, iNumSelected);
                    }
                }
                else
                {
                    MessageBox .Show ("Number is not selected", "Numbers", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                }
            }
        }
        // -------------------------------------------------        Click_btnNumberDown
        private void Click_btnNumberDown (object sender, EventArgs e)
        {
            if (PageAndSetSelected)
            {
                ListView list = listNumbers;
                if (list .SelectedIndices .Count > 0)
                {
                    Data_Set set = SelectedSet;
                    int iNumSelected = list .SelectedIndices [0];
                    if (iNumSelected < set .Numbers .Count - 1)
                    {
                        set .Numbers .Reverse (iNumSelected, 2);
                        iNumSelected++;
                        FillNumbersList ();
                        Auxi_Common .ListView_LineSelectAndShow (list, iNumSelected);
                    }
                }
                else
                {
                    MessageBox .Show ("Number is not selected", "Numbers", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                }
            }
        }
    }
}

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.140827.1 | Last Updated 10 Apr 2010
Article Copyright 2010 by SergeyAndreyev
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid