Click here to Skip to main content
15,888,521 members
Articles / Programming Languages / C#

DBLayer Wizard V 1.0

,
Rate me:
Please Sign up or sign in to vote.
3.42/5 (22 votes)
8 Nov 20052 min read 75.1K   1.5K   51  
DBLayer Wizard is a code generator that generates Data Layer classes in C# using ADO.NET and SQL Server 2000.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace SampleApp
{
	/// <summary>
	/// Summary description for TableInsert.
	/// </summary>
	public class TableOperations : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button btnInsert;
		private System.Windows.Forms.Button btnInsertDR;
		private System.Windows.Forms.Button btnInsertTable;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.TextBox txtPK;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Button btnDeleteAll;
		private System.Windows.Forms.Button btnDeleteByPK;
		private System.Windows.Forms.TextBox txtFK;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Button btnSeleteByFK;
		private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button btnUpdateDR;
		private System.Windows.Forms.Button btnUpdateDataTable;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public TableOperations()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.btnInsert = new System.Windows.Forms.Button();
			this.btnInsertDR = new System.Windows.Forms.Button();
			this.btnInsertTable = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.txtPK = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.btnDeleteAll = new System.Windows.Forms.Button();
			this.btnDeleteByPK = new System.Windows.Forms.Button();
			this.txtFK = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.btnSeleteByFK = new System.Windows.Forms.Button();
			this.groupBox3 = new System.Windows.Forms.GroupBox();
			this.button1 = new System.Windows.Forms.Button();
			this.btnUpdateDR = new System.Windows.Forms.Button();
			this.btnUpdateDataTable = new System.Windows.Forms.Button();
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.groupBox3.SuspendLayout();
			this.SuspendLayout();
			// 
			// btnInsert
			// 
			this.btnInsert.Location = new System.Drawing.Point(16, 24);
			this.btnInsert.Name = "btnInsert";
			this.btnInsert.Size = new System.Drawing.Size(104, 40);
			this.btnInsert.TabIndex = 4;
			this.btnInsert.Text = "Insert";
			this.btnInsert.Click += new System.EventHandler(this.button1_Click);
			// 
			// btnInsertDR
			// 
			this.btnInsertDR.Location = new System.Drawing.Point(16, 80);
			this.btnInsertDR.Name = "btnInsertDR";
			this.btnInsertDR.Size = new System.Drawing.Size(104, 40);
			this.btnInsertDR.TabIndex = 4;
			this.btnInsertDR.Text = "Insert DataRow";
			this.btnInsertDR.Click += new System.EventHandler(this.btnInsertDR_Click);
			// 
			// btnInsertTable
			// 
			this.btnInsertTable.Location = new System.Drawing.Point(16, 136);
			this.btnInsertTable.Name = "btnInsertTable";
			this.btnInsertTable.Size = new System.Drawing.Size(104, 40);
			this.btnInsertTable.TabIndex = 4;
			this.btnInsertTable.Text = "Insert DataTable";
			this.btnInsertTable.Click += new System.EventHandler(this.btnInsertTable_Click);
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.btnInsertDR);
			this.groupBox1.Controls.Add(this.btnInsertTable);
			this.groupBox1.Controls.Add(this.btnInsert);
			this.groupBox1.Location = new System.Drawing.Point(16, 16);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(136, 184);
			this.groupBox1.TabIndex = 5;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Insert [ Shippers ]";
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.Add(this.txtPK);
			this.groupBox2.Controls.Add(this.label1);
			this.groupBox2.Controls.Add(this.btnDeleteAll);
			this.groupBox2.Controls.Add(this.btnDeleteByPK);
			this.groupBox2.Controls.Add(this.txtFK);
			this.groupBox2.Controls.Add(this.label2);
			this.groupBox2.Controls.Add(this.btnSeleteByFK);
			this.groupBox2.Location = new System.Drawing.Point(168, 16);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(216, 184);
			this.groupBox2.TabIndex = 6;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "Delete [ Orders ] ";
			// 
			// txtPK
			// 
			this.txtPK.Location = new System.Drawing.Point(88, 88);
			this.txtPK.Name = "txtPK";
			this.txtPK.TabIndex = 13;
			this.txtPK.Text = "10334";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 88);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(56, 23);
			this.label1.TabIndex = 12;
			this.label1.Text = "Order ID";
			// 
			// btnDeleteAll
			// 
			this.btnDeleteAll.Location = new System.Drawing.Point(16, 24);
			this.btnDeleteAll.Name = "btnDeleteAll";
			this.btnDeleteAll.Size = new System.Drawing.Size(96, 23);
			this.btnDeleteAll.TabIndex = 10;
			this.btnDeleteAll.Text = "Delete All";
			this.btnDeleteAll.Click += new System.EventHandler(this.btnDeleteAll_Click);
			// 
			// btnDeleteByPK
			// 
			this.btnDeleteByPK.Location = new System.Drawing.Point(16, 56);
			this.btnDeleteByPK.Name = "btnDeleteByPK";
			this.btnDeleteByPK.Size = new System.Drawing.Size(96, 23);
			this.btnDeleteByPK.TabIndex = 8;
			this.btnDeleteByPK.Text = "Delete By PK";
			this.btnDeleteByPK.Click += new System.EventHandler(this.btnDeleteByPK_Click);
			// 
			// txtFK
			// 
			this.txtFK.Location = new System.Drawing.Point(88, 152);
			this.txtFK.Name = "txtFK";
			this.txtFK.Size = new System.Drawing.Size(96, 20);
			this.txtFK.TabIndex = 14;
			this.txtFK.Text = "10334";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 152);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(72, 23);
			this.label2.TabIndex = 11;
			this.label2.Text = "Customer ID";
			// 
			// btnSeleteByFK
			// 
			this.btnSeleteByFK.Location = new System.Drawing.Point(16, 120);
			this.btnSeleteByFK.Name = "btnSeleteByFK";
			this.btnSeleteByFK.Size = new System.Drawing.Size(96, 23);
			this.btnSeleteByFK.TabIndex = 9;
			this.btnSeleteByFK.Text = "Delete By FK";
			this.btnSeleteByFK.Click += new System.EventHandler(this.btnSeleteByFK_Click);
			// 
			// groupBox3
			// 
			this.groupBox3.Controls.Add(this.button1);
			this.groupBox3.Controls.Add(this.btnUpdateDR);
			this.groupBox3.Controls.Add(this.btnUpdateDataTable);
			this.groupBox3.Location = new System.Drawing.Point(16, 216);
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new System.Drawing.Size(184, 176);
			this.groupBox3.TabIndex = 7;
			this.groupBox3.TabStop = false;
			this.groupBox3.Text = "Update [ Shippers ]";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(16, 24);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(104, 40);
			this.button1.TabIndex = 4;
			this.button1.Text = "Update";
			this.button1.Click += new System.EventHandler(this.button1_Click_1);
			// 
			// btnUpdateDR
			// 
			this.btnUpdateDR.Location = new System.Drawing.Point(16, 72);
			this.btnUpdateDR.Name = "btnUpdateDR";
			this.btnUpdateDR.Size = new System.Drawing.Size(104, 40);
			this.btnUpdateDR.TabIndex = 4;
			this.btnUpdateDR.Text = "Insert DataRow";
			this.btnUpdateDR.Click += new System.EventHandler(this.btnUpdateDR_Click);
			// 
			// btnUpdateDataTable
			// 
			this.btnUpdateDataTable.Location = new System.Drawing.Point(16, 128);
			this.btnUpdateDataTable.Name = "btnUpdateDataTable";
			this.btnUpdateDataTable.Size = new System.Drawing.Size(104, 40);
			this.btnUpdateDataTable.TabIndex = 4;
			this.btnUpdateDataTable.Text = "Insert DataTable";
			this.btnUpdateDataTable.Click += new System.EventHandler(this.btnUpdateDataTable_Click);
			// 
			// TableInsert
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(528, 406);
			this.Controls.Add(this.groupBox3);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.groupBox1);
			this.Name = "TableInsert";
			this.Text = "TableOperations";
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void button1_Click(object sender, System.EventArgs e)
		{
			bool result=DBLayer.DBTableShippers.Insert("New Tech","123456");
			if(result)
				MessageBox.Show("Row Inserted Successfully");
			
		}

		private void btnInsertDR_Click(object sender, System.EventArgs e)
		{
			DataRow row=DBLayer.DBTableShippers.GetSchema();
			row["CompanyName"]="New Tech";
			row["Phone"]="123456";
			bool result=DBLayer.DBTableShippers.Insert(row);
			if(result)
				MessageBox.Show("Row Inserted Successfully");
		}

		private void btnInsertTable_Click(object sender, System.EventArgs e)
		{
			DataTable table=DBLayer.DBTableShippers.GetSchemaTable();
			DataRow row1=table.NewRow();
			row1["CompanyName"]="New Tech";
			row1["Phone"]="123456";
			table.Rows.Add(row1);

			DataRow row2=table.NewRow();
			row2["CompanyName"]="New Tech";
			row2["Phone"]="123456";
			table.Rows.Add(row2);

			bool result=DBLayer.DBTableShippers.Insert(table);
			if(result)
				MessageBox.Show("Row Inserted Successfully");
		}

		private void btnDeleteAll_Click(object sender, System.EventArgs e)
		{
			if(DialogResult.OK==MessageBox.Show(this,"Are you sure you want to Delete All Rows","DBLayer Sample",MessageBoxButtons.OKCancel))
			{
				int DeletedRows=DBLayer.DBTableOrders.DeleteAll();
				MessageBox.Show("Number Of Deleted Rows= "+DeletedRows);
			}
		}

		private void btnDeleteByPK_Click(object sender, System.EventArgs e)
		{
			bool result=DBLayer.DBTableOrders.DeleteByPK(int.Parse(txtPK.Text));
			if(result)
				MessageBox.Show(this,"Row Deleted Successfully");
		}

		private void btnSeleteByFK_Click(object sender, System.EventArgs e)
		{
			bool result=DBLayer.DBTableOrders.DeleteByFK(txtFK.Text);
			if(result)
				MessageBox.Show(this,"Row Deleted Successfully");
		}

		private void button1_Click_1(object sender, System.EventArgs e)
		{
			bool result=DBLayer.DBTableShippers.Update(1,"Home","12365");
			if(result)
				MessageBox.Show(this,"Row Updated Successfully");
		}

		private void btnUpdateDR_Click(object sender, System.EventArgs e)
		{
			DataRow row=DBLayer.DBTableShippers.GetSchema();
			row["ShipperID"]=1;
			row["CompanyName"]="New Tech";
			row["Phone"]="123456";
			bool result=DBLayer.DBTableShippers.Update(row);
			if(result)
				MessageBox.Show("Row Updated Successfully");
		}

		private void btnUpdateDataTable_Click(object sender, System.EventArgs e)
		{
			DataTable table=DBLayer.DBTableShippers.GetSchemaTable();
			DataRow row1=table.NewRow();
			row1["ShipperID"]=1;
			row1["CompanyName"]="New Tech";
			row1["Phone"]="123456";
			table.Rows.Add(row1);

			DataRow row2=table.NewRow();
			row2["ShipperID"]=2;
			row2["CompanyName"]="Ok";
			row2["Phone"]="123456";
			table.Rows.Add(row2);

			bool result=DBLayer.DBTableShippers.Update(table);
			if(result)
				MessageBox.Show("Row Updated Successfully");
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Austria Austria
Egyption ,B.Sc in computer science Department from faculty of computer science and information system Egypt-Helwan Univeristy ,
my master in progress in intelligent systems in Vienna Technology university ,
Microsoft Certified Professional science 2003 experience with
Turbo Pascal ,C++,VC++,C#,VB.NET,J# ,asp,ASP.Net,COM+ & XML , sql server 2000,action script 2

Written By
Web Developer
Egypt Egypt
I have B.Sc in Computer Science , Microsoft Certified Solution Developer and experienced with C/C++,MFC,C#,VB.NET,ASP.NET,XML,SQL Server 2000 & Crystal Reports.I like challenge and enjoy working with new technologies.

Comments and Discussions