diff --git a/SacsCoreWeb/Web/Components/SaController.cs b/SacsCoreWeb/Web/Components/SaController.cs
index 733c147..3822044 100644
--- a/SacsCoreWeb/Web/Components/SaController.cs
+++ b/SacsCoreWeb/Web/Components/SaController.cs
@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Routing;
using Microsoft.Net.Http.Headers;
using Newtonsoft.Json;
using Sarand.Net.Standard.Base.App;
+using Sarand.Net.Standard.Base.Bus;
using Sarand.Net.Standard.Base.Core;
using Sarand.Net.Standard.Base.Helpers;
using Sarand.Net.Standard.Base.Utils;
@@ -183,6 +184,39 @@ namespace Sacs.Web.Components
Response.Cookies.Append(key, value, options);
}
+ //-------------------------------------------------------------------
+ // Error State
+ //-------------------------------------------------------------------
+ private SacsErrorState errorState = null;
+ public bool HasErrorState()
+ {
+ return errorState != null;
+ }
+ public SacsErrorState ErrorState
+ {
+ get { return errorState; }
+ }
+ public String ErrorStateMessage
+ {
+ get { return (errorState != null ? errorState.Message : String.Empty); }
+ }
+ ///
+ /// Record the error state message.
+ /// Blank message does not set the error state - leaves previous state intact.
+ /// Return value is fale unless the message is blank.
+ ///
+ public bool SetErrorState(String message)
+ {
+ if (StringUtil.IsEmpty(message)) return true;
+ this.errorState = new SacsErrorState(message);
+ return false;
+ }
+ /// Clear the error state.
+ public void ClearErrorState()
+ {
+ errorState = null;
+ }
+
//-------------------------------------------------------------------
// Ajax actions.
//-------------------------------------------------------------------
@@ -240,6 +274,19 @@ namespace Sacs.Web.Components
Message = new MessageData() { Title = title, Text = text };
return this;
}
+ // Confirmation message - to query user.
+ public class ConfirmMessageData : MessageData
+ {
+ public SaConfirmActions Actions { get; set; }
+ }
+ public ConfirmMessageData ConfirmMessage { get; private set; }
+ public AjaxResponse_Base SetConfirmMessage(String title, String text, SaConfirmActions actions = SaConfirmActions.YesNo)
+ {
+ if (!StringUtil.IsBlank(text))
+ ConfirmMessage = new ConfirmMessageData() { Title = title, Text = text, Actions = actions };
+ return this;
+ }
+ public bool HasConfirmMessage { get { return ConfirmMessage != null; } }
}
//-------------------------------------------------------------------
@@ -316,6 +363,11 @@ namespace Sacs.Web.Components
/// Item code and desc values.
public class ItemCodeDesc
{
+ public ItemCodeDesc(String code, String desc)
+ {
+ this.Code = code;
+ this.Desc = desc;
+ }
public String Code { get; set; }
public String Desc { get; set; }
}
diff --git a/SacsStandardBase/Base/Core/DataValue.cs b/SacsStandardBase/Base/Core/DataValue.cs
index 9b3c8d8..2fb5507 100644
--- a/SacsStandardBase/Base/Core/DataValue.cs
+++ b/SacsStandardBase/Base/Core/DataValue.cs
@@ -20,8 +20,8 @@ namespace Sarand.Net.Standard.Base.Core
//-------------------------------------------------------------------
// Construction.
- public DataValue () { }
- public DataValue (DataValue dataValue)
+ public DataValue() { }
+ public DataValue(DataValue dataValue)
{
if (dataValue != null)
{
@@ -29,37 +29,37 @@ namespace Sarand.Net.Standard.Base.Core
value = dataValue.value;
}
}
- public DataValue (bool value)
+ public DataValue(bool value)
{
this.value = value;
this.dataType = DataType.Bool;
}
- public DataValue (TriStateType value)
+ public DataValue(TriStateType value)
{
this.value = value;
this.dataType = DataType.TriState;
}
- public DataValue (long value)
+ public DataValue(long value)
{
this.value = value;
this.dataType = DataType.Long;
}
- public DataValue (double value)
+ public DataValue(double value)
{
this.value = value;
this.dataType = DataType.Double;
}
- public DataValue (decimal value)
+ public DataValue(decimal value)
{
this.value = value;
this.dataType = DataType.Decimal;
}
- public DataValue (String value)
+ public DataValue(String value)
{
this.value = value;
this.dataType = DataType.String;
}
- public DataValue (DateTime value, DataType type = DataType.DateTime)
+ public DataValue(DateTime value, DataType type = DataType.DateTime)
{
this.value = value;
switch (type)
@@ -74,7 +74,7 @@ namespace Sarand.Net.Standard.Base.Core
break;
}
}
- public DataValue (Byte[] value)
+ public DataValue(Byte[] value)
{
this.value = value;
this.dataType = DataType.Blob;
@@ -83,11 +83,11 @@ namespace Sarand.Net.Standard.Base.Core
//-------------------------------------------------------------------
// Properties.
public static readonly DataValue NullValue = new DataValue();
- public DataType GetDataType ()
+ public DataType GetDataType()
{
return dataType;
}
- public static String GetTypeDesc (DataType type)
+ public static String GetTypeDesc(DataType type)
{
// Converts type to string.
switch (type)
@@ -105,38 +105,38 @@ namespace Sarand.Net.Standard.Base.Core
}
return "";
}
- public String GetTypeDesc ()
+ public String GetTypeDesc()
{
return GetTypeDesc(dataType);
}
- public bool IsValid ()
+ public bool IsValid()
{
return (dataType != DataType.Unknown);
}
- public bool IsNumeric ()
+ public bool IsNumeric()
{
return (dataType == DataType.Long || dataType == DataType.Double || dataType == DataType.Decimal);
}
- public bool IsDate ()
+ public bool IsDate()
{
return (dataType == DataType.Date || dataType == DataType.DateTime);
}
- public bool IsTime ()
+ public bool IsTime()
{
return (dataType == DataType.Time || dataType == DataType.DateTime);
}
- public bool IsDateTime ()
+ public bool IsDateTime()
{
return (dataType == DataType.Date || dataType == DataType.Time || dataType == DataType.DateTime);
}
- public bool IsBlob ()
+ public bool IsBlob()
{
return (dataType == DataType.Blob);
}
//-------------------------------------------------------------------
// Conversion.
- public override String ToString ()
+ public override String ToString()
{
if (value == null) return String.Empty;
// Forces any data type to string.
@@ -154,7 +154,7 @@ namespace Sarand.Net.Standard.Base.Core
}
return String.Empty;
}
- public double ToNumeric ()
+ public double ToNumeric()
{
if (value == null) return 0.0;
// Convert any type to double numeric.
@@ -172,8 +172,26 @@ namespace Sarand.Net.Standard.Base.Core
}
return 0.0;
}
+ public decimal ToDecimal()
+ {
+ if (value == null) return 0.0m;
+ // Convert any type to double numeric.
+ switch (dataType)
+ {
+ case DataType.Bool: return ((bool)value ? 1 : 0);
+ case DataType.TriState: return (int)(TriStateType)value;
+ case DataType.Long: return (long)value;
+ case DataType.Double: return (decimal)(double)value;
+ case DataType.Decimal: return (decimal)value;
+ case DataType.String: return StringUtil.ToDecimal((String)value);
+ case DataType.Date: return ((DateTime)value).Ticks;
+ case DataType.Time: return ((DateTime)value).Ticks;
+ case DataType.DateTime: return ((DateTime)value).Ticks;
+ }
+ return 0.0m;
+ }
/// Return value interpretted as boolean.
- public bool ToBool ()
+ public bool ToBool()
{
if (value == null) return false;
// Numeric <> 0, String: 'Yes', 'True', numeric value.
@@ -192,7 +210,7 @@ namespace Sarand.Net.Standard.Base.Core
return false;
}
/// Return explicit boolean value or false for other types.
- public bool AsBool ()
+ public bool AsBool()
{
// Convert to specific type of data - fails if type is not correct:
if (dataType == DataType.Bool) return (bool)value;
@@ -200,21 +218,21 @@ namespace Sarand.Net.Standard.Base.Core
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn} Incorrect data type: {dataType.ToString()}.");
return false;
}
- public TriStateType AsTriState ()
+ public TriStateType AsTriState()
{
if (dataType == DataType.TriState) return (TriStateType)value;
if (dataType == DataType.Unknown) return TriStateType.Unknown;
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn} Incorrect data type: {dataType.ToString()}.");
return TriStateType.Unknown;
}
- public long AsLong ()
+ public long AsLong()
{
if (dataType == DataType.Long) return (long)value;
if (dataType == DataType.Unknown) return 0;
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn} Incorrect data type: {dataType.ToString()}.");
return 0;
}
- public double AsDouble ()
+ public double AsDouble()
{
if (dataType == DataType.Double) return (double)value;
if (dataType == DataType.Unknown) return 0.0;
@@ -227,21 +245,21 @@ namespace Sarand.Net.Standard.Base.Core
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn} Incorrect data type: {dataType.ToString()}.");
return 0.0;
}
- public decimal AsDecimal ()
+ public decimal AsDecimal()
{
if (dataType == DataType.Decimal) return (decimal)value;
if (dataType == DataType.Unknown) return 0.00m;
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn} Incorrect data type: {dataType.ToString()}.");
return 0.00m;
}
- public String AsString ()
+ public String AsString()
{
if (dataType == DataType.String) return (String)value;
if (dataType == DataType.Unknown) return "";
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn} Incorrect data type: {dataType.ToString()}.");
return "";
}
- public DateTime AsDateTime ()
+ public DateTime AsDateTime()
{
// NB DateTime.Ticks is NotFiniteNumberException of 100-nanosecond intervals since beginning of 1st January 0001.
if (dataType == DataType.Date || dataType == DataType.Time || dataType == DataType.DateTime) return (DateTime)value;
@@ -249,21 +267,21 @@ namespace Sarand.Net.Standard.Base.Core
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn} Incorrect data type: {dataType.ToString()}.");
return DateTime.MinValue;
}
- public DateTime AsDate ()
+ public DateTime AsDate()
{
if (dataType == DataType.Date || dataType == DataType.DateTime) return ((DateTime)value).Date;
if (dataType == DataType.Unknown) return DateTime.MinValue;
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn} Incorrect data type: {dataType.ToString()}.");
return DateTime.MinValue;
}
- public DateTime AsTime ()
+ public DateTime AsTime()
{
if (dataType == DataType.Time || dataType == DataType.DateTime) return (DateTime)value;
if (dataType == DataType.Unknown) return DateTime.MinValue;
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn} Incorrect data type: {dataType.ToString()}.");
return DateTime.MinValue;
}
- public Byte[] AsBlob ()
+ public Byte[] AsBlob()
{
if (dataType == DataType.Blob) return (Byte[])value;
if (dataType == DataType.Unknown) return null;
@@ -273,18 +291,18 @@ namespace Sarand.Net.Standard.Base.Core
//-------------------------------------------------------------------
// Comparison.
- public bool Equals (DataValue value)
+ public bool Equals(DataValue value)
{
return false;
}
- public int CompareTo (DataValue value)
+ public int CompareTo(DataValue value)
{
return -1;
}
//-------------------------------------------------------------------
// Utilities.
- public void Clear ()
+ public void Clear()
{
dataType = DataType.Unknown;
value = null;
@@ -292,7 +310,7 @@ namespace Sarand.Net.Standard.Base.Core
//-------------------------------------------------------------------
// Arithmeic.
- public void Increment (DataValue value)
+ public void Increment(DataValue value)
{
if (dataType == value.GetDataType())
{
@@ -310,7 +328,7 @@ namespace Sarand.Net.Standard.Base.Core
}
}
}
- public void Decrement (DataValue value)
+ public void Decrement(DataValue value)
{
if (dataType == value.GetDataType())
{
@@ -328,7 +346,7 @@ namespace Sarand.Net.Standard.Base.Core
}
}
}
- public void MultiplyBy (DataValue value)
+ public void MultiplyBy(DataValue value)
{
if (dataType == value.GetDataType())
{
@@ -346,7 +364,7 @@ namespace Sarand.Net.Standard.Base.Core
}
}
}
- public void DivideBy (DataValue value)
+ public void DivideBy(DataValue value)
{
if (dataType == value.GetDataType())
{
@@ -422,7 +440,7 @@ namespace Sarand.Net.Standard.Base.Core
// Conversion.
/// Convert all data values to strings.
- public static List ToStringList (this List values)
+ public static List ToStringList(this List values)
{
List stringValues = new List();
foreach (var dataValue in values)
@@ -434,7 +452,7 @@ namespace Sarand.Net.Standard.Base.Core
/// Convert the data values to raw objects.
/// eg. For population to Excel spreadsheet cells.
///
- public static List