|
using System;
using System .Collections .Generic;
using System .IO;
using System .Windows .Forms;
using MoveGraphLibrary;
namespace UserDrivenApplications
{
public class Data_Page
{
bool bShowToUser;
string name;
List<Data_Set> sets = new List<Data_Set> ();
// -------------------------------------------------
public Data_Page (bool bShow, string strName)
{
bShowToUser = bShow;
name = strName;
}
// ------------------------------------------------- ShowToUser
public bool ShowToUser
{
get { return (bShowToUser); }
set { bShowToUser = value; }
}
// ------------------------------------------------- RemoveEmptySets
public void RemoveEmptySets ()
{
for (int i = sets .Count - 1; i >= 0; i--)
{
if (!sets [i] .HasData)
{
sets .RemoveAt (i);
}
}
}
// ------------------------------------------------- HasData
public bool HasData
{
get
{
for (int i = 0; i < sets .Count; i++)
{
if (sets [i] .HasData)
{
return (true);
}
}
return (false);
}
}
// ------------------------------------------------- Name
public string Name
{
get { return (name); }
set
{
if (!string .IsNullOrEmpty (value))
{
name = value;
}
}
}
// ------------------------------------------------- Sets
public List<Data_Set> Sets
{
get { return (sets); }
}
// ------------------------------------------------- AddSet
public bool AddSet (Data_Set setNew)
{
for (int i = 0; i < sets .Count; i++)
{
if (setNew .Name == sets [i] .Name)
{
return (false);
}
}
setNew .ShowToUser = bShowToUser;
sets .Add (setNew);
return (true);
}
// ------------------------------------------------- DeleteSet
public bool DeleteSet (int iSet)
{
bool bRet = false;
if (0 <= iSet && iSet < sets .Count)
{
sets .RemoveAt (iSet);
}
bRet = true;
return (bRet);
}
// ------------------------------------------------- InsertSet
public bool InsertSet (int iPos, Data_Set setNew)
{
for (int i = 0; i < sets .Count; i++)
{
if (setNew .Name == sets [i] .Name)
{
return (false);
}
}
iPos = Math .Min (Math .Max (0, iPos), sets .Count);
setNew .ShowToUser = bShowToUser;
sets .Insert (iPos, setNew);
return (true);
}
// ------------------------------------------------- IntoFile
public void IntoFile (BinaryWriter bw)
{
try
{
if (HasData)
{
for (int i = sets .Count - 1; i >= 0; i--)
{
if (!sets [i] .HasData)
{
sets .RemoveAt (i);
}
}
bw .Write (bShowToUser); // 0
bw .Write (name); // 1
bw .Write (sets .Count); // 2
for (int i = 0; i < sets .Count; i++)
{
sets [i] .IntoFile (bw);
}
}
}
catch
{
}
finally
{
}
}
// ------------------------------------------------- FromFile
public static void FromFile (Form form, BinaryReader br, out Data_Page data)
{
try
{
Data_Page pageNew = new Data_Page (br .ReadBoolean (), br .ReadString ());
int nSets = br .ReadInt32 ();
for (int i = 0; i < nSets; i++)
{
Data_Set setNew = null;
Data_Set .FromFile (form, br, out setNew);
if (setNew != null)
{
pageNew .AddSet (setNew);
}
}
data = pageNew;
}
catch
{
data = null;
string strText = "Can't read data from file";
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.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.