⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frm-switchadd.cs

📁 这是我个人写的一个实例用于登记公司的电脑信息
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 计算机及IP管理
{
    public partial class frm_switchAdd : Form
    {
        UserCls cls = new UserCls();
        public frm_switchAdd()
        {
            InitializeComponent();
            //给下拉列表赋值
            string strdepart = "select name from t_department";         
            bool isdepart;
            isdepart = cls.GetDataToComboBox(strdepart, comDepartment, "t_department", "name", "name");
            if (!isdepart)
            {
                MessageBox.Show("给部门赋值失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
         
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtName.Text.Trim()=="")
            {
                MessageBox.Show("交换机名称不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);               
                return;
            }
            if(txtModel.Text.Trim()=="")
            {
                MessageBox.Show("交换机型号不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);                 
                return;
            }
            StringBuilder strsql = new StringBuilder();
            strsql.Append("insert into t_switch(name,model,network,scope,department,charge,remarks)");
            strsql.Append("values('");
            strsql.Append(txtName.Text.ToString());
            strsql.Append("','");
            strsql.Append(txtModel.Text.ToString());
            strsql.Append("','");
            strsql.Append(txtNetwork.Text.ToString());
            strsql.Append("','");
            strsql.Append(txtScope.Text.ToString());
            strsql.Append("','");
            strsql.Append(comDepartment.Text.ToString());
            strsql.Append("','");
            strsql.Append(txtCharge.Text.ToString());
            strsql.Append("','");
            strsql.Append(txtRemark.Text.ToString());
            strsql.Append("')");          
            if (cls.ExecSqlString(strsql.ToString()))
            {
                MessageBox.Show("添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("添加失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        //页面载入,设置交换机名称
        private void frm_switchAdd_Load(object sender, EventArgs e)
        {
            txtName.Items.Add("一层交换机");            
            txtName.Items.Add("二层交换机");
            txtName.Items.Add("三层交换机");
            txtName.Items.Add("路由器");
            txtName.Items.Add("核心交换机");
            txtName.SelectedItem = "二层交换机";
            
        }       
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -