Convert UDF that is a Boolean type

From AutoCount Resource Center
Jump to navigation Jump to search

Introduction

Boolean type in AutoCount Accounting is a custom type that contains value of "T" or "F", which is also a single letter of string type.
It can be null when the custom boolean type is not assigned.

Boolean Type in Record or Entity

  • Custom boolean type in Record or Entity of a class has been converted to bool type, programmer does not have to do the conversion.
  • Example of below shows that, programmer can direct access to the bool type in Invoice class without having to convert it from original type (custom boolean type).
string docNo = "I-000001";

BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceCommand cmd = BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceCommand.Create(e.DBSetting);
BCE.AutoCount.Invoicing.Sales.Invoice.Invoice doc = cmd.Edit(docNo);

if (doc == null)
    return;

if (doc.Cancelled)
{
    BCE.Application.AppMessage.ShowMessage($"Document {docNo} is cancelled.");
}

if (doc.Transferable)
{
    BCE.Application.AppMessage.ShowMessage($"Document {docNo} can be transferred to C/N.");
}

UDF of Boolean Type

When an UDF that is boolean type, conversion may be necessary.
  • UDF is accessed via an object of UDFRecord class in Record or Entity, the value that it returns is an object.
  • The value of a UDF that is bool type has not been converted to bool type.
  • In order to apply the value of a boolean type UDF in condition, programmer needs to convert the type to bool type or string type.
  • The value of the object is either "T" or "F".
  • The value can be null if it has not been initialized. By default, AutoCount Accounting will initialize the value.

Convert "UDF Boolean Type" to "bool Type"

string docNo = "I-000001";

BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceCommand cmd = BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceCommand.Create(e.DBSetting);
BCE.AutoCount.Invoicing.Sales.Invoice.Invoice doc = cmd.Edit(docNo);

if (doc == null)
    return;

bool isBool = BCE.Data.Convert.TextToBoolean(doc.UDF["IsBool"]);

if (isBool)
{
    BCE.Application.AppMessage.ShowMessage("UDF_IsBool is true.");
}
else
{
    BCE.Application.AppMessage.ShowMessage("UDF_IsBool is false.");
}
  • TextToBoolean can convert "T", "true", true to bool type of true;
  • all other value and null are converted to bool type of false.


Assign value to UDF of boolean type

  • During assignment of true or false to UDF of boolean type, the value has to be converted to "T" or "F".
  • Below example will throw exception when assign true direct to UDF["IsBool"] which is UDF of boolean type.
e.MasterRecord.UDF["IsBool"] = true;
Warning-icon.png An exception of type 'System.ArgumentException' occurred in System.Data.dll but was not handled in user code
Additional information: Cannot set column 'UDF_IsBool'. The value violates the MaxLength limit of this column.


  • Convert to "T" or "F" before assign the value to UDF of boolean type.
e.MasterRecord.UDF["IsBool"] = BCE.Data.Convert.BooleanToText(true);
  • The value of e.MasterRecord.UDF["IsBool"] is "T"


e.MasterRecord.UDF["IsBool"] = BCE.Data.Convert.BooleanToText(false);
  • The value of e.MasterRecord.UDF["IsBool"] is "F"


Go to menu

IconAC81.png Go to top
ProgrammerGo.jpg Resources For AutoCount Software Developers