|
|
|
|
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 Mesnac.Equips.BaseInfo;
|
|
|
|
|
|
|
|
|
|
namespace Mesnac.Equips.SetConfig.DataConfig
|
|
|
|
|
{
|
|
|
|
|
public partial class NewGroupForm : Form
|
|
|
|
|
{
|
|
|
|
|
private bool isNew = true;
|
|
|
|
|
private ConfigEquipFactory configEquipFactory = null;
|
|
|
|
|
public NewGroupForm(ConfigEquipFactory configEquipFactory, bool isNew)
|
|
|
|
|
{
|
|
|
|
|
this.isNew = isNew;
|
|
|
|
|
this.configEquipFactory = configEquipFactory;
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
private void NewGroupForm_Shown(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
IniDefault();
|
|
|
|
|
}
|
|
|
|
|
private void IniDefault()
|
|
|
|
|
{
|
|
|
|
|
if (isNew || configEquipFactory.CurrentGroup == null)
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
i++;
|
|
|
|
|
this.textBox1.Text = "B" + i.ToString();
|
|
|
|
|
if (!SameGroupName(this.textBox1.Text))
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.textBox2.Text = string.Empty;
|
|
|
|
|
this.textBox3.Text = "0";
|
|
|
|
|
this.textBox4.Text = "10";
|
|
|
|
|
this.comboBox1.Text = "ReadWrite";
|
|
|
|
|
this.textBox6.Text = string.Empty;
|
|
|
|
|
this.checkBox1.Checked = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.textBox1.Text = configEquipFactory.CurrentGroup.Name.ToString();
|
|
|
|
|
this.textBox2.Text = configEquipFactory.CurrentGroup.Block.ToString();
|
|
|
|
|
this.textBox3.Text = configEquipFactory.CurrentGroup.Start.ToString();
|
|
|
|
|
this.textBox4.Text = configEquipFactory.CurrentGroup.Len.ToString();
|
|
|
|
|
this.comboBox1.Text = configEquipFactory.CurrentGroup.Access.ToString();
|
|
|
|
|
this.textBox6.Text = configEquipFactory.CurrentGroup.Remark.ToString();
|
|
|
|
|
this.checkBox1.Checked = configEquipFactory.CurrentGroup.IsAutoRead;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 数据保存
|
|
|
|
|
private bool SameGroupName(string name)
|
|
|
|
|
{
|
|
|
|
|
foreach (Group group in this.configEquipFactory.CurrentEquip.Group.Values)
|
|
|
|
|
{
|
|
|
|
|
if (group.Name.Equals(name))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (isNew)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (group.Name != this.configEquipFactory.CurrentGroup.Name)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
int int_start = 0;
|
|
|
|
|
if (!int.TryParse(this.textBox3.Text, out int_start))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("请设置正确的起始位!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (int_start < 0)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("起始位必须大于等于0!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int int_len = 0;
|
|
|
|
|
if (!int.TryParse(this.textBox4.Text, out int_len))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("请设置正确的长度!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (int_len <= 0)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("长度必须大于0!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (SameGroupName(this.textBox1.Text))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("设备名称重复!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (this.isNew)
|
|
|
|
|
{
|
|
|
|
|
configEquipFactory.CurrentGroup = new Group();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
configEquipFactory.CurrentEquip.Group.Remove(configEquipFactory.CurrentGroup.Name);
|
|
|
|
|
}
|
|
|
|
|
configEquipFactory.CurrentGroup.Name = this.textBox1.Text;
|
|
|
|
|
configEquipFactory.CurrentGroup.Block = this.textBox2.Text;
|
|
|
|
|
configEquipFactory.CurrentGroup.Start = int_start;
|
|
|
|
|
configEquipFactory.CurrentGroup.Len = int_len;
|
|
|
|
|
configEquipFactory.CurrentGroup.IsAutoRead = this.checkBox1.Checked;
|
|
|
|
|
configEquipFactory.CurrentGroup.Access = (System.IO.FileAccess)(this.comboBox1.SelectedIndex + 1);
|
|
|
|
|
configEquipFactory.CurrentGroup.Remark = this.textBox6.Text;
|
|
|
|
|
configEquipFactory.CurrentEquip.Group.Add(configEquipFactory.CurrentGroup.Name, configEquipFactory.CurrentGroup);
|
|
|
|
|
this.DialogResult = System.Windows.Forms.DialogResult.OK;
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void textBox_Int_KeyPress(object sender, KeyPressEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
//判断按键是不是要输入的类型。
|
|
|
|
|
if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
|
|
|
|
|
{
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|