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.

128 lines
3.8 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;
namespace ClientTest
{
/*
*MeterAddrForm
*
*2010-10-30
*
*/
public partial class MeterAddrForm : Form
{
public CheckedListBox checkedListBox;
public TextBox [] arrTextBox = new TextBox[16];
public MeterAddrForm()
{
InitializeComponent();
checkedListBox = clbMeterAdd;
arrTextBox[0] = textBox1;
arrTextBox[1] = textBox2;
arrTextBox[2] = textBox3;
arrTextBox[3] = textBox4;
arrTextBox[4] = textBox5;
arrTextBox[5] = textBox6;
arrTextBox[6] = textBox7;
arrTextBox[7] = textBox8;
arrTextBox[8] = textBox9;
arrTextBox[9] = textBox10;
arrTextBox[10] = textBox11;
arrTextBox[11] = textBox12;
arrTextBox[12] = textBox13;
arrTextBox[13] = textBox14;
arrTextBox[14] = textBox15;
arrTextBox[15] = textBox16;
}
/*
*btnOK_Click
*
*2010-10-30
*object sender , EventArgs e
*void
*
*/
private void tbCheck_KeyPress(object sender, KeyPressEventArgs e)
{
if ((int)e.KeyChar <= 32) // 特殊键(含空格), 不处理
{
return;
}
if (!char.IsDigit(e.KeyChar)) // 非数字键, 放弃该输入
{
e.Handled = true;
return;
}
}
/*
*btnApply_Click
*
*2010-10-30
*object sender , EventArgs e
*void
*
*/
private void btnApply_Click(object sender, EventArgs e)
{
if (CheckAddrs() == true)
{
this.DialogResult = DialogResult.OK;
}
}
/*
*CheckAddrs
*
*2010-10-30
*void
*bool true false
*
*/
private bool CheckAddrs()
{
bool res = true;
int nAcceptCount = 0;
while (nAcceptCount < 16)
{
if (arrTextBox[nAcceptCount].Text.Trim() != "")
{
for (int i = 0; i < nAcceptCount; i++)
{
if (Convert.ToInt32(arrTextBox[nAcceptCount].Text) == Convert.ToInt32(arrTextBox[i].Text))
{
MessageBox.Show(this, "存在重复地址!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
res = false;
break;
}
}
if (res == false)
{
break;
}
}
else
{
MessageBox.Show(this, "地址不可为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
res = false;
break;
}
nAcceptCount++;
}
return res;
}
}
}