Promotic

Example: Creates PmForm window configured for entering date and time

In a single script (e.g. after pressing the button in the onButtonUp event) a user window for date and time entry is created. The preset time can be set in the script after the comment "Initial time". The time value is processed by the function "onViewClose".
JavaScriptSelect and copy to clipboard

//#pragma variable sTxtDate=Macro("$.text('sys','date')");
//#pragma variable sTxtTime=Macro("$.text('sys','time')");
//#pragma variable sTxtSec=Macro("$.text('sys','second')");
//#pragma variable sTxtMin=Macro("$.text('sys','minute')");
//#pragma variable sTxtHour=Macro("$.text('sys','hour')");
//#pragma variable sTxtDay=Macro("$.text('sys','day')");
//#pragma variable sTxtMonth=Macro("$.text('sys','month')");
//#pragma variable sTxtYear=Macro("$.text('sys','year')");
var oFrom, oYear, oMonth, oDay, oHour, oMinut, oSec;
function onViewLoad(ev)
{
// Initial Time
var InitTime = Pm.CreatePmDateObject();
var oForm = ev.Form;
oForm.Title = sTxtDate + "/" + sTxtTime;

// string DateTime and button for setting
oFrom = oForm.CreateItem("string", "Dt", sTxtDate + " " + sTxtTime, "BodyWidthIni:10;BodyWidthMode:const;ValueHorzAlign:right;");
oFrom.Value = InitTime.Format("%Y.%m.%d %H:%M:%S");
oFrom.AddEvent("onEditAccept", "FromChange", onChangeDt);

oForm.CreateItem("separ", "", null, "Subtype:line;");

// TitleDate
var oLay1 = oForm.CreateItem("layout", "iTDate", null, "Subtype:horz;");
var oIt = oLay1.CreateItem("string", "s1", "", "Subtype:static;BodyWidthIni:5;TitlePos:no;Value:" + sTxtYear + ";");
oIt = oLay1.CreateItem("string", "s2", "", "Subtype:static;BodyWidthIni:5;TitlePos:no;Value:" + sTxtMonth + ";");
oIt = oLay1.CreateItem("string", "s3", "", "Subtype:static;BodyWidthIni:5;TitlePos:no;Value:" + sTxtDay + ";");

// Date
var oLay2 = oForm.CreateItem("layout", "iFr", null, "Subtype:horz;");
oYear = oLay2.CreateItem("number", "yearF", null, "BodyWidthIni:5;");
oYear.AddEvent("onEditAccept", "ChangeYear", onChange);
oMonth = oLay2.CreateItem("number", "monthF", null, "BodyWidthIni:5;Min:1;Max:12;");
oMonth.AddEvent("onEditAccept", "ChangeMonth", onChangeMonth);
oDay = oLay2.CreateItem("number", "dayF", null, "BodyWidthIni:5;Min:1;Max:31;");
oDay.AddEvent("onEditAccept", "ChangeDay", onChange);

// TitleTime
var oLay3 = oForm.CreateItem("layout", "iTTime", null, "Subtype:horz;");
oIt = oLay3.CreateItem("string", "s4", "", "Subtype:static;BodyWidthIni:5;TitlePos:no;Value:" + sTxtHour + ";");
oIt = oLay3.CreateItem("string", "s5", "", "Subtype:static;BodyWidthIni:5;TitlePos:no;Value:" + sTxtMin + ";");
oIt = oLay3.CreateItem("string", "s6", "", "Subtype:static;BodyWidthIni:5;TitlePos:no;Value:" + sTxtSec + ";");

// Time
var oLay4 = oForm.CreateItem("layout", "iFr2", null, "Subtype:horz;");
oHour = oLay4.CreateItem("number", "hourF", null, "BodyWidthIni:5;Min:0;Max:23;");
oHour.AddEvent("onEditAccept", "ChangeHour", onChange);
oMinut = oLay4.CreateItem("number", "minF", null, "BodyWidthIni:5;Min:0;Max:59;");
oMinut.AddEvent("onEditAccept", "ChangeMinute", onChange);
oSec = oLay4.CreateItem("number", "secF", null, "BodyWidthIni:5;Min:0;Max:59;");
oSec.AddEvent("onEditAccept", "ChangeSec", onChange);

onChangeDt();
onChangeMonth();
}


function onChangeMonth(ev)
{
var nMonth = oMonth.Value;
switch (nMonth)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
oDay.Max = 31;
break;
case 2:
oDay.Max = 29;
break;
case 4:
case 6:
case 9:
case 11:
oDay.Max = 30;
break;
}
}

function onChange(ev)
{
var tDateTime = Pm.CreateDate(oYear.Value, oMonth.Value, oDay.Value, oHour.Value, oMinut.Value, oSec.Value, 0);
var sDateTime = Pm.CreatePmDateObject(tDateTime).Format("%Y.%m.%d %H:%M:%S");
oFrom.Value = sDateTime;
}

function onChangeDt(ev)
{
var nTime = Pm.ScanDate(oFrom.Value, 1);
var oTime = Pm.CreatePmDateObject(nTime);
oYear.Value = oTime.GetYear();
oMonth.Value = oTime.GetMonth();
oDay.Value = oTime.GetDay();
oHour.Value = oTime.GetHour();
oMinut.Value = oTime.GetMinute();
oSec.Value = oTime.GetSecond();
}

function onViewClose(ev)
{
if (ev.CloseReason == "ok")
{
var tTime = Pm.ScanDate(oFrom.Value, 1);
Pm.Debug(tTime);
}
}

// Creates PmViewCreator - The object allows opening the various viewers
var oCreator = Pm.CreateView(null, "/#glob/form", "", "target:_blank;modal:1;");
oCreator.View.onLoad = onViewLoad;
oCreator.View.onClose = onViewClose;

// Opens form in a modal window:
oCreator.Open();
PROMOTIC 9.0.27 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r.o.