private void button1_Click(object sender, EventArgs e) { if (Number.Text == "") { MessageBox.Show("供应商编号不能为空!"); } else if (Name1.Text == "") { MessageBox.Show("供应商姓名不能为空!"); } else if (Name2.Text == "") { MessageBox.Show("负责人姓名不能为空!"); } else if (Telephone.Text == "") { MessageBox.Show("电话不能为空!"); } else if (Encoding.Default.GetByteCount(Telephone.Text) != 11) { MessageBox.Show("电话号码长度不为11!"); } else if (Address.Text == "") { MessageBox.Show("地址不能为空!"); } else if (Type.Text == "") { MessageBox.Show("类型不能为空!"); } else { string number = Number.Text; string name1 = Name1.Text; string name2 = Name2.Text; string telephone = Telephone.Text; string address = Address.Text; string type = Type.Text; supplierDaoz c = new supplierDaoz(); c.addSupplier(number, name1, name2, telephone, address, type); Console.Write(c.su + "!!!!"); if (c.su == 0) { } else { int node = k.dataGridView1.Rows.Count; Console.Write("行数:" + node); k.dt.Rows.Add(node + 1, number, name1, name2, telephone, address, type); k.dataGridView1.DataSource = k.dt; this.Close(); } } }
private void button1_Click(object sender, EventArgs e) { try { if (Name2.Text == "") { MessageBox.Show("负责人不能为空!"); } else if (Telephone.Text == "") { MessageBox.Show("电话不能为空!"); } else if (Address.Text == "") { MessageBox.Show("地址不能为空!"); } else if (Type.Text == "") { MessageBox.Show("类型不能为空!"); } else { string msg = "确定修改吗?"; if ((int)MessageBox.Show(msg, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) != 1) { return; } supplierDaoz c = new supplierDaoz(); c.update_supplier(number, Name2.Text, Telephone.Text, Address.Text, Type.Text); g.dataGridView1.Rows[j].Cells[5].Value = Name2.Text; g.dataGridView1.Rows[j].Cells[6].Value = Telephone.Text; g.dataGridView1.Rows[j].Cells[7].Value = Address.Text; g.dataGridView1.Rows[j].Cells[8].Value = Type.Text; MessageBox.Show("已修改!"); this.Close(); } } catch (Exception) { MessageBox.Show("操作有误!"); } finally { } }