Convert UDF that is a Boolean type: Difference between revisions

From AutoCount Resource Center
Content added Content deleted
(Created page with " ==Introduction== Boolean type in AutoCount Accounting is a custom type that contains value of "T" or "F", which is also a string type. It can also be null when the custom b...")
 
No edit summary
Line 1: Line 1:


==Introduction==
==Introduction==
Boolean type in AutoCount Accounting is a custom type that contains value of "T" or "F", which is also a string type.
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 also be null when the custom boolean type is not assigned.
It can also be null when the custom boolean type is not assigned.



Revision as of 03:34, 19 March 2018

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 also 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 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) to a 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;

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(e.MasterRecord.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 an exception when assign true to UDF["IsBool"].
e.MasterRecord.UDF["IsBool"] = true;
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

Go to top
Resources For AutoCount Software Developers