You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.0 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
namespace Mesnac.Equips.Connection.Default
{
public partial class SetConfigForm : Form, Mesnac.Equips.Connection.ConnConfig
{
#region 单例模式
private static SetConfigForm _this;
public static SetConfigForm Instance
{
get
{
if (null == _this)
_this = new SetConfigForm();
return _this;
}
}
#endregion
public SetConfigForm()
{
InitializeComponent();
}
ConnType thisConnType = new ConnType();
private void button1_Click(object sender, EventArgs e)
{
thisConnType.IP = this.textBox1.Text;
this.Close();
}
#region SetConfig GetConfig
public Connection.ConnType SetConfig(Connection.ConnType connType)
{
ConnType Result = new ConnType();
if (connType != null)
{
Result = (ConnType)connType;
}
this.textBox1.Text = Result.IP;
this.ShowDialog();
return thisConnType;
}
private bool GetFirstNodeValue(XmlNode node, string path, string attribute, bool throwException, out string value)
{
value = string.Empty;
try
{
value = node.SelectNodes(path)[0].Attributes[attribute.ToLower()].Value.ToString();
}
catch (Exception ex)
{
if (throwException)
{
throw (ex);
}
return false;
}
return true;
}
private bool GetNodeAttributeValue(XmlNode node, string attribute, bool throwException, out string value)
{
value = string.Empty;
try
{
value = node.Attributes[attribute.ToLower()].Value.ToString();
}
catch (Exception ex)
{
if (throwException)
{
throw (ex);
}
return false;
}
return true;
}
//public Connection.ConnType GetConfig(XmlNode node)
//{
// ConnType Result = new ConnType();
// return Result;
//}
public Connection.ConnType GetConfig(XmlNode node)
{
ConnType Result = new ConnType();
string ss = string.Empty;
GetFirstNodeValue(node, ".//IP[@value]", "value", true, out ss);
Result.IP = ss;
return Result;
}
#endregion
}
public class ConnType : Mesnac.Equips.Connection.ConnType
{
public ConnType()
{
this.IP = string.Empty;
}
public string IP { get; set; }
}
}