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
{
}
}
}
}