//
// ImpExpSettPanel.cs
//
// Copyright(c) 2011 Actia (China) Co., Ltd. All Rights Reserved.
//
// Owner: Vincent BRIARD
// Created on: 2011/4/28
//
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AppCore.UI.Interface;
using Utils.Model;
using AppCore.UI.CustomComponents;
using Utils.App;
namespace AppCore.UI.Settings
{
/// <summary>
/// Class to represent the import and export settigns for the options
/// </summary>
public partial class ImpExpSettPanel : UserControl, ILocalizable, ISettings
{
#region attributes
//Import panel
private FileSelectionPanel importPanel;
//Export panel
private FileSelectionPanel exportPanel;
//table layout
private TableLayoutPanel tlp;
//從xml讀取的import的路徑的節點
private static String IMP_PATH = "ExportImport/Import/ImportFilePath";
//從xml讀取的export的路徑的節點
private static String EXP_PATH = "ExportImport/Export/ExportFilePath";
#endregion attributes
public void SetSettingsPtr(IntPtr ptr)
{
IntPtr _SettingsPtr = ptr;
if (_SettingsPtr != IntPtr.Zero)
{
importPanel.SetPtr(_SettingsPtr);
exportPanel.SetPtr(_SettingsPtr);
}
}
/// <summary>
/// 構造函數
/// </summary>
public ImpExpSettPanel()
{
InitializeComponent();
this.SuspendLayout();
this.Margin = new Padding(0, 0, 0, 0);
// create tlp
this.tlp = new TableLayoutPanel();
// Set the BorderStyle to Inset
this.tlp.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset;
this.tlp.ColumnCount = 2;
this.tlp.RowCount = 2;
// the table layout panel fill the whole main window
this.tlp.Dock = DockStyle.Fill;
// If grid is full do nothing
this.tlp.GrowStyle = TableLayoutPanelGrowStyle.FixedSize;
// Padding of the tlp (usefull?!)
this.tlp.Padding = new Padding(0, 0, 0, 0);
// Adding column style
this.tlp.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
this.tlp.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
// Adding row style
this.tlp.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
this.tlp.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
// adding import panel
this.importPanel = new FileSelectionPanel(FileSelType.Import);
this.importPanel.Dock = DockStyle.Fill;
this.tlp.Controls.Add(this.importPanel, 0, 0);
// adding export panel
this.exportPanel = new FileSelectionPanel(FileSelType.Export);
this.exportPanel.Dock = DockStyle.Fill;
this.tlp.Controls.Add(this.exportPanel, 0, 1);
// add tlp to the control
this.Controls.Add(this.tlp);
this.ResumeLayout(false);
}
#region ILocalizable Members
public bool CanBeValidated()
{
Boolean validated = true;
validated = validated && this.importPanel.CanBeValidated();
validated = validated && this.exportPanel.CanBeValidated();
return validated;
}
/// <summary>
/// Load localized Content for all children elements in the UI
/// </summary>
public void LoadLocalizedContent()
{
foreach (Control ctrl in this.tlp.Controls)
{
if (ctrl is ILocalizable)
{
((ILocalizable)ctrl).LoadLocalizedContent();
}
}
}
#endregion
/// <summary>
/// Method used to resize the content of a TabControl which font changed
/// </summary>
public void InitialFontSize()
{
this.exportPanel.InitialFontSize();
this.importPanel.InitialFontSize();
}
#region ISettings Members
public SettingValueList GetRequestedSettings()
{
// generate the setting request
SettingValue<String> impSett = new SettingValue<String>(IMP_PATH, "");
SettingValue<String> expSett = new SettingValue<String>(EXP_PATH, "");
// store the setting values in the list
SettingValueList svl = new SettingValueList();
svl.AddSettingValue(impSett);
svl.AddSettingValue(expSett);
return svl;
}
public SettingValueList GetSettingsFromUI()
{
// generate the setting request
SettingValue<String> impSett = new SettingValue<String>(IMP_PATH, this.importPanel.GetFilePath());
SettingValue<String> expSett = new SettingValue<String>(EXP_PATH, this.exportPanel.GetFilePath());
// store the setting values in the list
SettingValueList svl = new SettingValueList();
svl.AddSettingValue(impSett);
svl.AddSettingValue(expSett);
return svl;
}
public void SetSettingFromFile(SettingValueList pSvl)
{
SettingValue<String> importSett = (SettingValue<String>)pSvl.FindSettingByName(IMP_PATH)[0];
this.importPanel.SetFilePath((String)importSett.GetValue());
SettingValue<String> exportSett = (SettingValue<String>)pSvl.FindSettingByName(EXP_PATH)[0];
this.exportPanel.SetFilePath((String)exportSett.GetValue());
}
#endregion
}
}