ランダム値を挿入するための NetLogic を開発する

ランダム値を挿入するための 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