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_Strings
        private void EnableGroup_Strings (bool bEnable)
        {
            if (bEnable == false)
            {
                groupStrings .Title = "Strings";
                ClearGroup_Strings ();
            }
            List<Control> ctrls = groupStrings .Controls;
            foreach (Control control in ctrls)
            {
                control .Enabled = bEnable;
            }
        }
        // -------------------------------------------------        ClearGroup_Strings
        private void ClearGroup_Strings ()
        {
            textString_Name .Text = "";
            textString_Value .Text = "";
            textString_Comment .Text = "";
            listStrings .Items .Clear ();
        }
        // -------------------------------------------------        FillStringsList
        private void FillStringsList ()
        {
            ListView list = listStrings;
            list .Items .Clear ();
            if (PageAndSetSelected)
            {
                Data_Set set = SelectedSet;
                if (set .SetType == SetType .Strings)
                {
                    for (int i = 0; i < set .Strings .Count; i++)
                    {
                        Data_String data = set .Strings [i];
                        string [] strs = new string [4];
                        strs [0] = data .Name;
                        strs [1] = data .Value;
                        strs [2] = data .Comment;     
                        strs [3] = data .ShowToUser ? "Yes" : "No";
                        ListViewItem lvi = new ListViewItem (strs);
                        list .Items .Add (lvi);
                    }
                }
            }
        }
        // -------------------------------------------------        SelectedIndexChanged_listStrings
        private void SelectedIndexChanged_listStrings (object sender, EventArgs e)
        {
            ListView list = sender as ListView;

            textString_Name .Text = "";
            textString_Value .Text = "";
            textString_Comment .Text = "";
            if (PageAndSetSelected)
            {
                if (list .SelectedIndices .Count > 0)
                {
                    Data_Set set = SelectedSet;
                    Data_String data = set .Strings [list .SelectedIndices [0]];
                    textString_Name .Text = data .Name;
                    textString_Value .Text = data .Value .ToString ();
                    textString_Comment .Text = data .Comment;

                    btnDeleteString .Enabled = true;
                    btnShowHideString .Enabled = true;
                    btnStringUp .Enabled = list .SelectedIndices [0] > 0;
                    btnStringDown .Enabled = list .SelectedIndices [0] < list .Items .Count - 1;
                }
                else
                {
                    DisableFourButtons_Strings ();
                }
            }
        }
        // -------------------------------------------------        DisableFourButtons_Strings
        private void DisableFourButtons_Strings ()
        {
            btnDeleteString .Enabled = false;
            btnShowHideString .Enabled = false;
            btnStringUp .Enabled = false;
            btnStringDown .Enabled = false;
        }
        // -------------------------------------------------        AfterLabelEdit_listStrings
        private void AfterLabelEdit_listStrings (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 .Strings [i] .Name)
                    {
                        e .CancelEdit = true;
                        MessageBox .Show ("String with such name already exists; select another name", "Rename string",
                                          MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                        return;
                    }
                }
            }
            set .Strings [iSelLine] .Name = str;
            list .Items [iSelLine] .Selected = true;
            textString_Name .Text = str;
        }
        // -------------------------------------------------        Click_btnDeleteString
        private void Click_btnDeleteString (object sender, EventArgs e)
        {
            if (PageAndSetSelected)
            {
                ListView list = listStrings;
                if (list .SelectedIndices .Count > 0)
                {
                    if (DialogResult .Yes == MessageBox .Show ("Do you want to delete the selected string?", "Delete string",
                                                   MessageBoxButtons .YesNo, MessageBoxIcon .Question, MessageBoxDefaultButton .Button1))
                    {
                        int iSetSelected = listSets .SelectedIndices [0];
                        Data_Set set = SelectedSet;                   
                        int iStrSelected = list .SelectedIndices [0];
                        set .DeleteString (iStrSelected);

                        SetsList_RefreshSelectShow (iSetSelected);
                        FillStringsList ();
                        if (set .Strings .Count > 0)
                        {
                            Auxi_Common .ListView_LineSelectAndShow (list, Math .Min (iStrSelected, set .Strings .Count - 1));
                        }
                    }
                }
                else
                {
                    MessageBox .Show ("String to delete is not selected", "Delete string", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                }
            }
        }
        // -------------------------------------------------        Click_btnAddString
        private void Click_btnAddString (object sender, EventArgs e)
        {
            if (listSets .SelectedIndices .Count <= 0)
            {
                MessageBox .Show ("The set for the new string is not selected", "Add string",
                                  MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                return;
            }
            Data_Page page = SelectedPage;
            int iSetSelected = listSets .SelectedIndices [0];
            Data_Set set = page .Sets [iSetSelected];
            if (set .SetType != SetType .Strings)
            {
                MessageBox .Show ("The selected set is not for strings", "Add string", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                return;
            }
            string strName = textString_Name .Text .Trim ();
            if (string .IsNullOrEmpty (strName))
            {
                MessageBox .Show ("No name for the new String", "Add string", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                return;
            }
            for (int i = 0; i < set .Strings .Count; i++)
            {
                if (strName == set .Strings [i] .Name)
                {
                    MessageBox .Show ("String with such name already exists in this Set; select another name", "Add string",
                                      MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                    return;
                }
            }
            string strVal = textString_Value .Text .Trim ();
            if (string .IsNullOrEmpty (strVal))
            {
                MessageBox .Show ("The string is empty", "Add String", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                return;
            }
            string strCmnt = textString_Comment .Text .Trim ();
            Data_String data = new Data_String (strName, set .ShowToUser, strVal, strCmnt);
            set .AddString (data);
            SetsList_RefreshSelectShow (iSetSelected);
            FillStringsList ();
            Auxi_Common .ListView_LineSelectAndShow (listStrings, listStrings .Items .Count - 1);
        }
        // -------------------------------------------------        Click_btnChangeString
        private void Click_btnChangeString (object sender, EventArgs e)
        {
            if (listStrings .SelectedIndices .Count <= 0)
            {
                MessageBox .Show ("The string to change is not selected", "Change string", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                return;
            }
            Data_Set set = SelectedSet;
            string strName = textString_Name .Text .Trim ();
            if (string .IsNullOrEmpty (strName))
            {
                MessageBox .Show ("Name must be not empty", "Change string", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                return;
            }
            int iString = listStrings .SelectedIndices [0];
            for (int i = 0; i < set .Strings .Count; i++)
            {
                if (i != iString)
                {
                    if (strName == set .Strings [i] .Name)
                    {
                        MessageBox .Show ("The same name is used for another string", "Change string",
                                          MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                        return;
                    }
                }
            }
            string strVal = textString_Value .Text .Trim ();
            if (string .IsNullOrEmpty (strVal))
            {
                MessageBox .Show ("The string is empty", "Change string", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                return;
            }
            string strCmnt = textString_Comment .Text .Trim ();
            Data_String data = new Data_String (strName, set .Strings [iString] .ShowToUser, strVal, strCmnt);
            set .DeleteString (iString);
            set .InsertString (iString, data);
            FillStringsList ();
            Auxi_Common .ListView_LineSelectAndShow (listStrings, iString);
        }
        // -------------------------------------------------        Click_btnShowHideString
        private void Click_btnShowHideString (object sender, EventArgs e)
        {
            if (PageAndSetSelected)
            {
                ListView list = listStrings;
                if (list .SelectedIndices .Count > 0)
                {
                    Data_Page page = SelectedPage;
                    int iSetSelected = listSets .SelectedIndices [0];
                    Data_Set set = SelectedSet;
                    int iStrSelected = list .SelectedIndices [0];
                    Data_String data = set .Strings [iStrSelected];
                    data .ShowToUser = !data .ShowToUser;

                    SetsList_RefreshSelectShow (iSetSelected);
                    Auxi_Common .ListView_LineSelectAndShow (list, iStrSelected);
                }
                else
                {
                    MessageBox .Show ("String is not selected", "Strings", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                }
            }
        }
        // -------------------------------------------------        Click_btnStringUp
        private void Click_btnStringUp (object sender, EventArgs e)
        {
            if (PageAndSetSelected)
            {
                ListView list = listStrings;
                if (list .SelectedIndices .Count > 0)
                {
                    int iStrSelected = list .SelectedIndices [0];
                    if (iStrSelected > 0)
                    {
                        SelectedSet .Strings .Reverse (iStrSelected - 1, 2);
                        iStrSelected--;
                        FillStringsList ();
                        Auxi_Common .ListView_LineSelectAndShow (list, iStrSelected);
                    }
                }
                else
                {
                    MessageBox .Show ("String is not selected", "Strings", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
                }
            }
        }
        // -------------------------------------------------        Click_btnStringDown
        private void Click_btnStringDown (object sender, EventArgs e)
        {
            if (PageAndSetSelected)
            {
                ListView list = listStrings;
                if (list .SelectedIndices .Count > 0)
                {
                    Data_Set set = SelectedSet;
                    int iStrSelected = list .SelectedIndices [0];
                    if (iStrSelected < set .Strings .Count - 1)
                    {
                        set .Strings .Reverse (iStrSelected, 2);
                        iStrSelected++;
                        FillStringsList ();
                        Auxi_Common .ListView_LineSelectAndShow (list, iStrSelected);
                    }
                }
                else
                {
                    MessageBox .Show ("String is not selected", "Strings", 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)

About the Author

SergeyAndreyev

United States United States
No Biography provided

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