private void button2_Click(object sender, EventArgs e) { int count = this.checkedListBox1.Items.Count; if (count == 0) { MessageBox.Show("表为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (this.checkedListBox1.CheckedItems.Count == 0) { MessageBox.Show("未选中任何表!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } string path = this.textBox4.Text.Trim(); if (path == "") { MessageBox.Show("路径不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (this.radioButton1.Checked) { for (int i = 0; i < count; i++) { if (this.checkedListBox1.GetItemChecked(i)) { string tableName = this.checkedListBox1.Items[i].ToString().Trim(); connectionStr += "database=" + this.comboBox1.SelectedItem.ToString().Trim() + ";"; List <TableStructure> structureList = ser.queryTableStructure(connectionStr, tableName); if (this.textBox5.Text.Trim() == "") { this.textBox5.Text = "命名空间"; } string fileContent = ser.createFileContent(structureList, this.textBox5.Text.Trim(), tableName); System.IO.File.WriteAllText(path + "\\" + tableName + ".cs", fileContent); this.textBox6.Text = this.textBox6.Text + "\n" + tableName + "生成成功!"; } } } else if (this.radioButton2.Checked) { for (int i = 0; i < count; i++) { if (this.checkedListBox1.GetItemChecked(i)) { string tableName = this.checkedListBox1.Items[i].ToString().Trim(); connectionStr += "database=" + this.comboBox1.SelectedItem.ToString().Trim() + ";"; List <TableStructure> structureList = ser.queryTableStructure(connectionStr, tableName); foreach (TableStructure item in structureList) { if (item.Type1.Equals("string")) { item.Type1 = "String"; } } if (this.textBox5.Text.Trim() == "") { this.textBox5.Text = "包名"; } string fileContent = ser.createJavaFileContent(structureList, this.textBox5.Text.Trim(), tableName); System.IO.File.WriteAllText(path + "\\" + tableName + ".java", fileContent); this.textBox6.Text = this.textBox6.Text + "\n" + tableName + "生成成功!"; } } } }