private void button1_Click(object sender, EventArgs e) { if (Number.Text == "") { MessageBox.Show("客户编码不能为空!"); } else if (Name1.Text == "") { MessageBox.Show("客户名称不能为空!"); } else if (Phone.Text == "") { MessageBox.Show("手机号不能为空!"); } else if (Encoding.Default.GetByteCount(Phone.Text) != 11) { MessageBox.Show("手机号长度不为11!"); } else if (Address.Text == "") { MessageBox.Show("地址不能为空!"); } else { string number = Number.Text; string name = Name1.Text; string phone = Phone.Text; string address = Address.Text; model.kehu r = new model.kehu(); r.Phone = phone; r.Address = address; r.Customer_name = name; r.Customer_number = number; customerDaoz c = new customerDaoz(); c.addCustomer(number, name, phone, address); Console.Write(c.kehu + "!!"); if (c.kehu == 0) { } else { int node = k.dataGridView1.Rows.Count; k.dt.Rows.Add(node + 1, number, name, phone, address); k.dataGridView1.DataSource = k.dt; this.Close(); } } }
private void button1_Click(object sender, EventArgs e) { try { if (Phone.Text == "") { MessageBox.Show("电话不能为空!"); } else if (Encoding.Default.GetByteCount(Phone.Text) != 11) { MessageBox.Show("电话格式不正确!"); } else if (Address.Text == "") { MessageBox.Show("住址不能为空!"); } else { string msg = "确定修改吗?"; if ((int)MessageBox.Show(msg, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) != 1) { return; } customerDaoz c = new customerDaoz(); c.update_customer(number, Phone.Text, Address.Text); n.dataGridView1.Rows[j].Cells[5].Value = Phone.Text; n.dataGridView1.Rows[j].Cells[6].Value = Address.Text; MessageBox.Show("已修改!"); this.Close(); } } catch (Exception) { MessageBox.Show("操作有误!"); } finally { } }