我正在尝试实现像Outlook这样的离线功能。如果脱机,则应将 EditForm1 中的值放置到本地集合(发件箱(。是否可以根据 Connection.Connected 变量将编辑表单提交到不同的源?然后,我将创建一个计时器,该计时器在每x秒连接一次时提交其背面。
如果我理解正确,您希望将当前在 EditForm1 中的内容保存到本地集合中,并且在再次收到互联网连接后,您想再次提交表单。
如果您已连接到 Internet,则需要使用条件来保存当前在表单中的数据,否则将其收集到临时集合中。
If(ToggleIsConnected.Value,
//If you are connected to the internet, then write the data to the database.
SubmitForm(Form1),
//If you are NOT connected to the internet, then write the data to a temporary collection to be written later.
Collect(temporary,
{id: Max(temporary,id)+1,
column1: InputColumn1.Text,
column2: InputColumn2.Text
}
);
SaveData(temporary,"temporary")
)
您可以使用切换来检查互联网连接。如果您失去连接、在本地保存数据并重新获得连接,切换开关将触发并自动执行 OnCheck 操作:
If(!IsEmpty(temporary),
// If the connection returns and there are records to be written,
// then perform these actions:
ForAll(temporary,
// For each of the records in the temporary collection,
// save their data to a new row in the connected datasource.
// If writing was successful, copy it to a collection called 'success'
// to identify it.
Collect(success,
{id: id,
Record:
Patch(datasource,Defaults(datasource),
{column1: column1,
column2: column2
}
)
}
)
);
If(IsEmpty(Errors(datasource)),
// If there are no errors with the datasource,
// go ahead and clear the entire temporary collection since you're writing.
Clear(temporary),
// Otherwise if there is an error, remove only the records that were successful.
// Then clear the successful records.
// Keep records that had an error so they could be attempted later.
Remove(temporary,Filter(temporary,id exactin Filter(success,!IsBlank(Record)).id));
Clear(success)
)
)
请注意,在这里,我使用 Patch(( 来保存临时集合中的内容。除非我填充表单,否则我无法使用提交表单。
进一步实现这一点还涉及更多步骤。有关更多详细信息,请参阅我关于此主题的视频: https://www.youtube.com/watch?v=j30xOM5OmRE