C#机房重构之简单功能代码

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xyf13920745534/article/details/82825778

判断文本框是否为空

foreach (Control c in this.Controls)
{
	if (c is TextBox)
	{
		if (string.IsNullOrEmpty((c as TextBox).Text))
		{
			MessageBox.Show("输入框不能为空,请核对您的输入信息!","温馨提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
			break;
		}
	}
}

密码实现明密文转换

private void pic3_MouseDown(object sender, MouseEventArgs e)
        {
            txtOldPassword.PasswordChar = '\0';
        }

        private void pic3_MouseUp(object sender, MouseEventArgs e)
        {
            txtOldPassword.PasswordChar = '*';
        }

在这里插入图片描述
限制文本框只能输入数字

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
	if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)13 && e.KeyChar != (char)8)
	{
		e.Handled = true;
	}
}
三个条件:第一个是可以输入数字,第二个是可以输入回车,第三个是可以退格。

加载时去除重复的卡号

for (int i = 0; i < table.Rows.Count ; i++)
{
     if (comboRechargeCardNo.Items.Cast<object>().All(x => x.ToString () != table.Rows[i][0].ToString ()))//去除重复的卡号
     comboRechargeCardNo.Items .Add (table.Rows[i][0]);   
 }

数据库中充值记录
在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/xyf13920745534/article/details/82825778