65 lines
1.7 KiB
C#
65 lines
1.7 KiB
C#
using System;
|
|
using System.Windows.Forms;
|
|
using GenesisCordonelInterface.API;
|
|
|
|
namespace GenesisCordonelInterface.UI.StaraTuraAPI_GenesisCordonelInterface
|
|
{
|
|
public partial class MeterInitView : UserControl
|
|
{
|
|
private readonly InterfaceOutsideToGCI _api;
|
|
private readonly Action _addSlotAction;
|
|
private readonly Action _saveAction;
|
|
|
|
public MeterInitView(InterfaceOutsideToGCI api, Action addSlotAction, Action saveAction)
|
|
{
|
|
_api = api;
|
|
_addSlotAction = addSlotAction;
|
|
_saveAction = saveAction;
|
|
|
|
InitializeComponent();
|
|
}
|
|
|
|
#region BUTTONS
|
|
// ----------------------------------------------------
|
|
|
|
|
|
private void btnSaveSetup_Click(object sender, EventArgs e)
|
|
{
|
|
_saveAction?.Invoke();
|
|
}
|
|
|
|
private void btnAddSlot_Click(object sender, EventArgs e)
|
|
{
|
|
_addSlotAction?.Invoke();
|
|
}
|
|
|
|
// ----------------------------------------------------
|
|
#endregion
|
|
|
|
private void ExecuteApiAction(Action action)
|
|
{
|
|
try
|
|
{
|
|
SetBusy(true);
|
|
action();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "API call failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
finally
|
|
{
|
|
SetBusy(false);
|
|
}
|
|
}
|
|
|
|
private void SetBusy(bool busy)
|
|
{
|
|
Cursor = busy ? Cursors.WaitCursor : Cursors.Default;
|
|
|
|
btnReloadSetup.Enabled = !busy;
|
|
btnSaveSetup.Enabled = !busy;
|
|
btnAddSlot.Enabled = !busy;
|
|
}
|
|
}
|
|
} |