开发用于插入随机值的 NetLogic

此 NetLogic 脚本用于将随机值插入到数据库的
Table1
表中。
先决条件
设置默认外部代码编辑器。请参见设置默认代码编辑器。
  1. 开发 NetLogic
  2. 在
    项目视图
    中,展开
    数据存储
    文件夹。
  3. 右键单击数据库,然后选择
    新建
    运行时 NetLogic
    。
  4. 将光标悬停在 NetLogic 上,选择
    Edit
    并输入
    EmbeddedDatabase1NetLogic
  5. 双击 NetLogic。
    外部代码编辑器将打开。
  6. 在代码编辑器中,使用以下代码替换现有代码:
    #region Using directives using System; using FTOptix.HMIProject; using FTOptix.NetLogic; using FTOptix.Store; #endregion public class EmbeddedDatabase1NetLogic : BaseNetLogic { public override void Start() { // Insert code to be executed when the user-defined logic is started } public override void Stop() { // Insert code to be executed when the user-defined logic is stopped } [ExportMethod] public void InsertRandomValues (){ // Get the current project folder. var project = Project.Current; // Save the names of the columns of the table to an array string[] columns = { "Column1", "Column2", "Column3" }; // Create and populate a matrix with values to insert into the odbc table var rawValues = new object[1000, 3]; Random randomNumber = new Random (); for (UInt16 i = 0; i < 1000; ++i) { // Column1 rawValues[i, 0] = i; // Column2 rawValues[i, 1] = randomNumber.Next(0, 5000); // Column3 rawValues[i, 2] = randomNumber.NextDouble() * 5000; } var myStore = LogicObject.Owner as Store; // Get Table1 from myStore var table1 = myStore.Tables.Get<Table>("Table1"); // Insert values into table1 table1.Insert(columns, rawValues); } }
  7. 保存代码。
提供反馈
对本文档有问题或反馈吗? 请在这里提交您的反馈 。
Normal