Search website

How to add UDF and UDL

Introduction

The following code sample shows how a developer could add both User Defined Fields (UDF) and User Defined Lists (UDL)

UDF

Code Snippet
  1. // The following code direct access to a local AutoCount database called AED_MOBILE_0, there is no login window to prompt out to allow users to select a database.
  2. BCE.Data.DBSetting dbSetting = new BCE.Data.DBSetting(BCE.Data.DBServerType.SQL2000, @”(local)\A2006″, “sa”, BCE.AutoCount.Const.AppConst.DefaultPassword, “AED_MOBILE_0″);
  3. BCE.AutoCount.MainEntry.Startup.Default.SubProjectStartup(dbSetting);
  4. if (BCE.AutoCount.Authentication.UserAuthentication.GetOrCreate(dbSetting).Login(“ADMIN”, “ADMIN”))
  5. {
  6.     BCE.AutoCount.UDF.UDFTable udfTable = new BCE.AutoCount.UDF.UDFTable(“SalesAgent”, dbSetting);
  7.     BCE.AutoCount.UDF.Field afield;
  8.     // If ServiceGrp UDF does not exists, then add it.
  9.     if (udfTable[“ServiceGrp”] == null)
  10.     {
  11.         afield = udfTable.Add(“ServiceGrp”, BCE.AutoCount.UDF.UDFType.Text, “Service Group”);
  12.         afield.TextProperties.Size = 20;
  13.         afield.TextProperties.ListName = “SGList”;
  14.     }
  15.     // If Location UDF does not exists, then add it.
  16.     if (udfTable[“Location”] == null)
  17.     {
  18.         afield = udfTable.Add(“Location”, BCE.AutoCount.UDF.UDFType.System, “Location”);
  19.         afield.SystemProperties.CustomDataType = BCE.AutoCount.UDF.SystemType.Location.ToString();
  20.     }
  21.     // If MaxAmount UDF does not exists, then add it.
  22.     if (udfTable[“MaxAmount”] == null)
  23.     {
  24.         afield = udfTable.Add(“MaxAmount”, BCE.AutoCount.UDF.UDFType.Decimal, “Maximum Amount”);
  25.         afield.DecimalProperties.Precision = 12;
  26.         afield.DecimalProperties.Scale = 2;
  27.     }
  28.     udfTable.Save();
  29.     AddOrUpdateUDFList(dbSetting, “SGList”, newstring[] { “Consultant”, “Service” });
  30. }

UDL

Code Snippet
  1. private static void AddOrUpdateUDFList(BCE.Data.DBSetting dbSetting, string listName, string[] values)
  2. {
  3.     BCE.AutoCount.UDF.UDFList udfList = new BCE.AutoCount.UDF.UDFList(dbSetting);
  4.     BCE.AutoCount.UDF.List list = udfList[listName];
  5.     if (list == null)
  6.     {
  7.         list = new BCE.AutoCount.UDF.List();
  8.         list.Name = listName;
  9.         udfList.Add(list);
  10.     }
  11.     list.SetItems(values);
  12.     udfList.Save();
  13. }

Creating a control for UDF

Code Snippet
  1. public static void CreateUDFControl(BCE.Data.DBSetting setting, DataTable table, DevExpress.XtraEditors.PanelControl panel)
  2. {
  3.     // The following code shows how to create a UDF control and add it to a panel.
  4.     // Assume the UDF must exist.
  5.     BCE.AutoCount.UDF.UDFUtil udfUtil = new BCE.AutoCount.UDF.UDFUtil(setting);
  6.     Control ctrl = udfUtil.CreateEditor(“IV”, “ICNo”, table);
  7.     if (ctrl != null)
  8.     {
  9.         ctrl.Top = 100;
  10.         ctrl.Left = 100;
  11.         panel.Controls.Add(ctrl);
  12.     }
  13. }