127 lines
2.8 KiB
C#
127 lines
2.8 KiB
C#
///
|
|
/// Copyright (c) 2017 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Net;
|
|
using System.Windows.Forms;
|
|
using Common;
|
|
using Config.Entities;
|
|
using TBF.Rig.Generic;
|
|
|
|
namespace TBF.Rig.Network.AdapterFTP
|
|
{
|
|
public partial class NetadapterCfgCtrl : UserControl, IComponentCfgCtrl
|
|
{
|
|
public bool ShowMore { get { return false; } }
|
|
|
|
NetFtpadapterCfg config;
|
|
public IComponentCfg Config
|
|
{
|
|
get { return config as IComponentCfg; }
|
|
set
|
|
{
|
|
config = value as NetFtpadapterCfg;
|
|
Redraw();
|
|
}
|
|
}
|
|
|
|
public NetadapterCfgCtrl()
|
|
{
|
|
InitializeComponent();
|
|
nameTextBox.Enabled = false;
|
|
textBoxFtpDir.Enabled = false;
|
|
btnDirSelect.Enabled = false;
|
|
button1.Enabled = false;
|
|
}
|
|
|
|
private void EntryFormCfgCtrl_Load(object sender, EventArgs e)
|
|
{
|
|
if (ParentForm == null) return; /// Return is executed when tab page is open in Designer
|
|
if (config == null) return; /// Control was not loaded, settings were not changed
|
|
|
|
Localize();
|
|
|
|
Redraw();
|
|
}
|
|
|
|
void Redraw()
|
|
{
|
|
classNameLabel.Text = config.Factory.ClassName;
|
|
nameTextBox.Text = config.Name;
|
|
textBoxFtpDir.Text = config.Path;
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
}
|
|
|
|
public void Closing()
|
|
{
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
textBoxFtpDir.Enabled = true;
|
|
btnDirSelect.Enabled = true;
|
|
button1.Enabled = true;
|
|
}
|
|
|
|
public CfgUpdateFlags VerifyCfg(ref string message)
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
if (!Directory.Exists(textBoxFtpDir.Text))
|
|
{
|
|
flags = CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'Dir path'";
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateCfg()
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.RestartRqrd;
|
|
|
|
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
|
|
|
|
config.Name = nameTextBox.Text;
|
|
|
|
/// Network adapter
|
|
string strAdapter = textBoxFtpDir.Text;
|
|
int iDash = strAdapter.IndexOf(" - ");
|
|
config.Description = iDash < 0 ? "" : strAdapter.Substring(iDash + 3);
|
|
|
|
config.Path = textBoxFtpDir.Text;
|
|
|
|
return flags;
|
|
}
|
|
|
|
private void btnDirSelect_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
// Create FolderBrowserDialog
|
|
FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
|
|
|
|
// Set initial directory
|
|
folderBrowserDialog.SelectedPath = textBoxFtpDir.Text; // Set your predefined path here
|
|
// Show the dialog and capture the result
|
|
DialogResult result = folderBrowserDialog.ShowDialog();
|
|
|
|
// Process the result
|
|
if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(folderBrowserDialog.SelectedPath))
|
|
{
|
|
textBoxFtpDir.Text = folderBrowserDialog.SelectedPath;
|
|
}
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
textBoxFtpDir.Text = @"C:\TBF\camera";
|
|
}
|
|
}
|
|
}
|