Example #1
0
        private void btn_Add_Click(object sender, EventArgs e)
        {
            Agent model = new Agent();  // 本项目的 Service 文件夹内的 Agent 类(属于 Model 类)

            string _name = txt_Name.Text.Trim();

            if (string.IsNullOrEmpty(_name))
            {
                MessageBox.Show("客户名称不能为空!");
                txt_Name.Focus();
                return;
            }
            if (model.Exists(_name))
            {
                MessageBox.Show("该客户名称已存在!");
                txt_Name.Focus();
                return;
            }
            model.Name      = _name;
            model.LevelName = cbx_Level.SelectedValue.ToString();
            model.Contact   = txt_Contact.Text.Trim();
            model.Phone     = txt_Phone.Text.Trim();
            model.Address   = txt_Address.Text.Trim();
            model.Tel       = txt_Tel.Text.Trim();
            model.Fox       = txt_Fox.Text.Trim();
            int re = model.Add();

            if (re > 0)
            {
                MessageBox.Show("添加成功!");
                txt_Name.Text           = "";
                cbx_Level.SelectedIndex = 0;
                txt_Name.Focus();
                txt_Contact.Text = "";
                txt_Phone.Text   = "";
                txt_Address.Text = "";
                txt_Fox.Text     = "";
                txt_Tel.Text     = "";
                BindDGV("");
            }
            else
            {
                MessageBox.Show("添加失败!");
            }
        }