CHTMLVBFeli
Mitglied
Hier ist der Code für die Form
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ADOX;
namespace m_erstellen
{
public partial class newtable : Form
{
public newtable(string txt)
{
InitializeComponent();
fieldanz.SelectedItem = "1";
fieldtype1.SelectedIndex = 0;
fieldtype2.SelectedIndex = 0;
}
public newtable()
{
// TODO: Complete member initialization
}
private void button1_Click(object sender, EventArgs e)
{
string strSQL;
object obj = new object();
ADOX.Catalog catPeople = new ADOX.Catalog();
ADODB.Connection conPeople = new ADODB.Connection();
string tblname = new_tblnam.Text;
string oldpath = label1.Text;
string newfilename = oldpath.Replace("\\", "\\\\");
string tblnam = new_tblnam.ToString();
try
{
conPeople.Open("Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source='" + newfilename + "'",
"", "", 0);
if (new_tblnam.Text == "")
{
}
else
{
if (fieldanz.Text == "1")
{
if (field1.Text==""){
MessageBox.Show("Feld1 ist leer! Bitte befüllen sie dieses Feld.", "Feld 1 ist leer!",MessageBoxButtons.OK, MessageBoxIcon.Warning);
field1.Focus();
}
else{
strSQL = "CREATE TABLE " + tblname + "("+field1.Text+" INTEGER CONSTRAINT PKeyMyId PRIMARY KEY);";
conPeople.Execute(strSQL, out obj, 0);
}
}
if (fieldanz.Text == "2")
{
if (field1.Text == "")
{
MessageBox.Show("Feld1 ist leer! Bitte befüllen sie dieses Feld.", "Feld 1 ist leer!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
field1.Focus();
}
else if (field2.Text == "")
{
MessageBox.Show("maiu");
}
else
{
if (fieldtype2.Text == "CheckBox (Bool)")
{
ADODB.Connection con = new ADODB.Connection();
ADOX.Catalog cat = new ADOX.Catalog();
ADOX.Table tbl = new ADOX.Table();
con.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + newfilename);
cat.ActiveConnection= con;
tbl.ParentCatalog = cat;
tbl.Name = "Tabelle";
cat.Tables.Append(tbl);
tbl.Columns.Append("Serial", DataTypeEnum.adVarWChar, 100);
tbl.Columns.Append("Name", DataTypeEnum.adBoolean, 250);
tbl.Columns.Append("Name2", DataTypeEnum.adVarWChar, 250);
tbl.Columns.Append("Phone", DataTypeEnum.adVarWChar, 200);
tbl.Keys.Append("PrimaryKey", KeyTypeEnum.adKeyPrimary, "Serial", null);
tbl.Keys["PrimaryKey"].Columns.Append("Name2", DataTypeEnum.adVarWChar, 250);
con.Close();
}
}
}
}
Console.WriteLine("A table named Persons has been " +
"created in the People.mdb database");
}
finally
{
conPeople.Close();
}
}
private void fieldanz_SelectedItemChanged(object sender, EventArgs e)
{
if (fieldanz.Text == "1")
{
field2label.Visible = false;
field2.Visible = false;
field3label.Visible = false;
field3.Visible = false;
field4label.Visible = false;
field4.Visible = false;
field5label.Visible = false;
field5.Visible = false;
field6label.Visible = false;
field6.Visible = false;
field7label.Visible = false;
field7.Visible = false;
field8label.Visible = false;
field8.Visible = false;
field9label.Visible = false;
field9.Visible = false;
field10label.Visible = false;
field10.Visible = false;
field11label.Visible = false;
field11.Visible = false;
field12label.Visible = false;
field12.Visible = false;
}
if (fieldanz.Text == "2")
{
field3label.Visible = false;
field3.Visible = false;
field4label.Visible = false;
field4.Visible = false;
field5label.Visible = false;
field5.Visible = false;
field6label.Visible = false;
field6.Visible = false;
field7label.Visible = false;
field7.Visible = false;
field8label.Visible = false;
field8.Visible = false;
field9label.Visible = false;
field9.Visible = false;
field10label.Visible = false;
field10.Visible = false;
field11label.Visible = false;
field11.Visible = false;
field12label.Visible = false;
field12.Visible = false;
field2.Visible = true;
field2label.Visible = true;
}
if (fieldanz.Text == "3")
{
field4label.Visible = false;
field4.Visible = false;
field5label.Visible = false;
field5.Visible = false;
field6label.Visible = false;
field6.Visible = false;
field7label.Visible = false;
field7.Visible = false;
field8label.Visible = false;
field8.Visible = false;
field9label.Visible = false;
field9.Visible = false;
field10label.Visible = false;
field10.Visible = false;
field11label.Visible = false;
field11.Visible = false;
field12label.Visible = false;
field12.Visible = false;
field3.Visible = true;
field3label.Visible = true;
field2.Visible = true;
field2label.Visible = true;
}
if (fieldanz.Text == "4")
{
field5label.Visible = false;
field5.Visible = false;
field6label.Visible = false;
field6.Visible = false;
field7label.Visible = false;
field7.Visible = false;
field8label.Visible = false;
field8.Visible = false;
field9label.Visible = false;
field9.Visible = false;
field10label.Visible = false;
field10.Visible = false;
field11label.Visible = false;
field11.Visible = false;
field12label.Visible = false;
field12.Visible = false;
field3.Visible = true;
field3label.Visible = true;
field2.Visible = true;
field2label.Visible = true;
field4label.Visible = true;
field4.Visible = true;
}
if (fieldanz.Text == "5")
{
field6label.Visible = false;
field6.Visible = false;
field7label.Visible = false;
field7.Visible = false;
field8label.Visible = false;
field8.Visible = false;
field9label.Visible = false;
field9.Visible = false;
field10label.Visible = false;
field10.Visible = false;
field11label.Visible = false;
field11.Visible = false;
field12label.Visible = false;
field12.Visible = false;
field3.Visible = true;
field3label.Visible = true;
field2.Visible = true;
field2label.Visible = true;
field4label.Visible = true;
field4.Visible = true;
field5label.Visible = true;
field5.Visible = true;
}
if (fieldanz.Text == "6")
{
field7label.Visible = false;
field7.Visible = false;
field8label.Visible = false;
field8.Visible = false;
field9label.Visible = false;
field9.Visible = false;
field10label.Visible = false;
field10.Visible = false;
field11label.Visible = false;
field11.Visible = false;
field12label.Visible = false;
field12.Visible = false;
field3.Visible = true;
field3label.Visible = true;
field2.Visible = true;
field2label.Visible = true;
field4label.Visible = true;
field4.Visible = true;
field5label.Visible = true;
field5.Visible = true;
field6label.Visible = true;
field6.Visible = true;
}
if (fieldanz.Text == "7")
{
field8label.Visible = false;
field8.Visible = false;
field9label.Visible = false;
field9.Visible = false;
field10label.Visible = false;
field10.Visible = false;
field11label.Visible = false;
field11.Visible = false;
field12label.Visible = false;
field12.Visible = false;
field3.Visible = true;
field3label.Visible = true;
field2.Visible = true;
field2label.Visible = true;
field4label.Visible = true;
field4.Visible = true;
field5label.Visible = true;
field5.Visible = true;
field6label.Visible = true;
field6.Visible = true;
field7label.Visible = true;
field7.Visible = true;
}
if (fieldanz.Text == "8")
{
field9label.Visible = false;
field9.Visible = false;
field10label.Visible = false;
field10.Visible = false;
field11label.Visible = false;
field11.Visible = false;
field12label.Visible = false;
field12.Visible = false;
field3.Visible = true;
field3label.Visible = true;
field2.Visible = true;
field2label.Visible = true;
field4label.Visible = true;
field4.Visible = true;
field5label.Visible = true;
field5.Visible = true;
field6label.Visible = true;
field6.Visible = true;
field7label.Visible = true;
field7.Visible = true;
field8label.Visible = true;
field8.Visible = true;
}
if (fieldanz.Text == "9")
{
field10label.Visible = false;
field10.Visible = false;
field11label.Visible = false;
field11.Visible = false;
field12label.Visible = false;
field12.Visible = false;
field3.Visible = true;
field3label.Visible = true;
field2.Visible = true;
field2label.Visible = true;
field4label.Visible = true;
field4.Visible = true;
field5label.Visible = true;
field5.Visible = true;
field6label.Visible = true;
field6.Visible = true;
field7label.Visible = true;
field7.Visible = true;
field8label.Visible = true;
field8.Visible = true;
field9label.Visible = true;
field9.Visible = true;
}
if (fieldanz.Text == "10")
{
field11label.Visible = false;
field11.Visible = false;
field12label.Visible = false;
field12.Visible = false;
field3.Visible = true;
field3label.Visible = true;
field2.Visible = true;
field2label.Visible = true;
field4label.Visible = true;
field4.Visible = true;
field5label.Visible = true;
field5.Visible = true;
field6label.Visible = true;
field6.Visible = true;
field7label.Visible = true;
field7.Visible = true;
field8label.Visible = true;
field8.Visible = true;
field9label.Visible = true;
field9.Visible = true;
field10label.Visible = true;
field10.Visible = true;
}
if (fieldanz.Text == "11")
{
field12label.Visible = false;
field12.Visible = false;
field3.Visible = true;
field3label.Visible = true;
field2.Visible = true;
field2label.Visible = true;
field4label.Visible = true;
field4.Visible = true;
field5label.Visible = true;
field5.Visible = true;
field6label.Visible = true;
field6.Visible = true;
field7label.Visible = true;
field7.Visible = true;
field8label.Visible = true;
field8.Visible = true;
field9label.Visible = true;
field9.Visible = true;
field10label.Visible = true;
field10.Visible = true;
field11label.Visible = true;
field11.Visible = true;
} if (fieldanz.Text == "12")
{
field3.Visible = true;
field3label.Visible = true;
field2.Visible = true;
field2label.Visible = true;
field4label.Visible = true;
field4.Visible = true;
field5label.Visible = true;
field5.Visible = true;
field6label.Visible = true;
field6.Visible = true;
field7label.Visible = true;
field7.Visible = true;
field8label.Visible = true;
field8.Visible = true;
field9label.Visible = true;
field9.Visible = true;
field10label.Visible = true;
field10.Visible = true;
field11label.Visible = true;
field11.Visible = true;
field12label.Visible = true;
field12.Visible = true;
}
}
private void newtable_FormClosed(object sender, FormClosedEventArgs e)
{
System.Windows.Forms.Application.Exit();
}
private void newtable_Load(object sender, EventArgs e)
{
}
}
}