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...")
 
mNo edit summary
 
(4 intermediate revisions by the same user not shown)
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 be null when the custom boolean type is not assigned.


==Boolean Type in Record or Entity==
==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.
* 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.
* 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).
<syntaxhighlight lang="csharp" highlight="9,14">
<syntaxhighlight lang="csharp" highlight="9,14">
string docNo = "I-000001";
string docNo = "I-000001";
Line 36: Line 36:
* The value can be null if it has not been initialized. By default, AutoCount Accounting will initialize the value.
* 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===
===Convert '''"UDF Boolean Type"''' to '''"bool Type"'''===
<syntaxhighlight lang="csharp" highlight="9">
<syntaxhighlight lang="csharp" highlight="9">
string docNo = "I-000001";
string docNo = "I-000001";
Line 46: Line 46:
return;
return;


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


if (isBool)
if (isBool)
Line 60: Line 60:
*all other value and null are converted to bool type of false.
*all other value and null are converted to bool type of false.


<br />


<br /><br />
===Assign value to UDF of boolean type===
===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".
*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"].
*Below example will throw exception when assign true direct to UDF["IsBool"] which is '''UDF of boolean type'''.
<syntaxhighlight lang="csharp">
<syntaxhighlight lang="csharp">
e.MasterRecord.UDF["IsBool"] = true;
e.MasterRecord.UDF["IsBool"] = true;
Line 76: Line 74:
</syntaxhighlight>
</syntaxhighlight>
*The value of e.MasterRecord.UDF["IsBool"] is "T"
*The value of e.MasterRecord.UDF["IsBool"] is "T"
<br />
<syntaxhighlight lang="csharp">
<syntaxhighlight lang="csharp">
e.MasterRecord.UDF["IsBool"] = BCE.Data.Convert.BooleanToText(false);
e.MasterRecord.UDF["IsBool"] = BCE.Data.Convert.BooleanToText(false);

Latest revision as of 07:52, 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 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;
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