using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace AdapterDemo
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
        private GBS.Data.GBasedbt.IfxDataAdapter ifxDataAdapter1;
        private GBS.Data.GBasedbt.IfxConnection IfxConnection1;
        private GBS.Data.GBasedbt.IfxCommand IfxSelectCommand1;
        private GBS.Data.GBasedbt.IfxCommand IfxInsertCommand1;
        private GBS.Data.GBasedbt.IfxCommand IfxUpdateCommand1;
        private GBS.Data.GBasedbt.IfxCommand IfxDeleteCommand1;
        private System.Windows.Forms.DataGrid dataGrid1;
        private System.Data.DataSet ds;
        private System.Windows.Forms.Button BtnUpdate;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// 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.ifxDataAdapter1 = new GBS.Data.GBasedbt.IfxDataAdapter();
            this.IfxConnection1 = new GBS.Data.GBasedbt.IfxConnection();
            this.IfxSelectCommand1 = new GBS.Data.GBasedbt.IfxCommand();
            this.IfxInsertCommand1 = new GBS.Data.GBasedbt.IfxCommand();
            this.IfxUpdateCommand1 = new GBS.Data.GBasedbt.IfxCommand();
            this.IfxDeleteCommand1 = new GBS.Data.GBasedbt.IfxCommand();
            this.dataGrid1 = new System.Windows.Forms.DataGrid();
            this.BtnUpdate = new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
            this.SuspendLayout();
            // 
            // ifxDataAdapter1
            // 
            this.ifxDataAdapter1.DeleteCommand = this.IfxDeleteCommand1;
            this.ifxDataAdapter1.InsertCommand = this.IfxInsertCommand1;
            this.ifxDataAdapter1.SelectCommand = this.IfxSelectCommand1;
            this.ifxDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
                                                                                                      new System.Data.Common.DataTableMapping("Table", "customer", new System.Data.Common.DataColumnMapping[] {
                                                                                                                                                                                                                  new System.Data.Common.DataColumnMapping("customer_num", "customer_num"),
                                                                                                                                                                                                                  new System.Data.Common.DataColumnMapping("fname", "fname"),
                                                                                                                                                                                                                  new System.Data.Common.DataColumnMapping("lname", "lname")})});
            this.ifxDataAdapter1.UpdateCommand = this.IfxUpdateCommand1;
            // 
            // IfxConnection1
            // 
            this.IfxConnection1.ClientLocale = "en_us.CP1252";
            this.IfxConnection1.ConnectionString = "Server=ids940uc2;DataBase=dbl;";
            this.IfxConnection1.DatabaseLocale = "";
            this.IfxConnection1.FetchBufferSize = 32767;
            this.IfxConnection1.PacketSize = 32767;
            // 
            // IfxSelectCommand1
            // 
            this.IfxSelectCommand1.CommandText = "SELECT customer_num, fname, lname FROM customer";
            this.IfxSelectCommand1.Connection = this.IfxConnection1;
            // 
            // IfxInsertCommand1
            // 
            this.IfxInsertCommand1.CommandText = "INSERT INTO customer ( customer_num, fname, lname ) VALUES ( ?, ?, ? )\n";
            this.IfxInsertCommand1.Connection = this.IfxConnection1;
            this.IfxInsertCommand1.Parameters.Add(new GBS.Data.GBasedbt.IfxParameter("CustomerNum", GBS.Data.GBasedbt.IfxType.Integer, 0, "customer_num"));
            this.IfxInsertCommand1.Parameters.Add(new GBS.Data.GBasedbt.IfxParameter("Fname", GBS.Data.GBasedbt.IfxType.Char, 30, "fname"));
            this.IfxInsertCommand1.Parameters.Add(new GBS.Data.GBasedbt.IfxParameter("Lname", GBS.Data.GBasedbt.IfxType.Char, 30, "lname"));
            // 
            // IfxUpdateCommand1
            // 
            this.IfxUpdateCommand1.CommandText = "UPDATE customer SET  fname =?, lname = ? WHERE customer_num = ?";
            this.IfxUpdateCommand1.Connection = this.IfxConnection1;
            this.IfxUpdateCommand1.Parameters.Add(new GBS.Data.GBasedbt.IfxParameter("Fname", GBS.Data.GBasedbt.IfxType.Char, 30, "fname"));
            this.IfxUpdateCommand1.Parameters.Add(new GBS.Data.GBasedbt.IfxParameter("Lname", GBS.Data.GBasedbt.IfxType.Char, 30, "lname"));
            this.IfxUpdateCommand1.Parameters.Add(new GBS.Data.GBasedbt.IfxParameter("CustomerNum", GBS.Data.GBasedbt.IfxType.Integer, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "customer_num", System.Data.DataRowVersion.Original, null));
            // 
            // IfxDeleteCommand1
            // 
            this.IfxDeleteCommand1.CommandText = "DELETE FROM customer WHERE customer_num = ?";
            this.IfxDeleteCommand1.Connection = this.IfxConnection1;
            this.IfxDeleteCommand1.Parameters.Add(new GBS.Data.GBasedbt.IfxParameter("CustomerNum", GBS.Data.GBasedbt.IfxType.Integer, 0, "customer_num"));
            // 
            // dataGrid1
            // 
            this.dataGrid1.DataMember = "";
            this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
            this.dataGrid1.Location = new System.Drawing.Point(24, 24);
            this.dataGrid1.Name = "dataGrid1";
            this.dataGrid1.Size = new System.Drawing.Size(392, 216);
            this.dataGrid1.TabIndex = 0;
            // 
            // BtnUpdate
            // 
            this.BtnUpdate.Location = new System.Drawing.Point(440, 64);
            this.BtnUpdate.Name = "BtnUpdate";
            this.BtnUpdate.Size = new System.Drawing.Size(88, 32);
            this.BtnUpdate.TabIndex = 1;
            this.BtnUpdate.Text = "Update Data";
            this.BtnUpdate.Click += new System.EventHandler(this.BtnUpdate_Click);
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(552, 273);
            this.Controls.Add(this.BtnUpdate);
            this.Controls.Add(this.dataGrid1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
            this.ResumeLayout(false);

        }
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

        private void Form1_Load(object sender, System.EventArgs e)
        {
            ds = new DataSet();
            ifxDataAdapter1.Fill( ds, "customer" );
            dataGrid1.SetDataBinding( ds, "customer" );
        }

        private void BtnUpdate_Click(object sender, System.EventArgs e)
        {
            try
            {
                ifxDataAdapter1.Update( ds.Tables["customer"] );
                MessageBox.Show( "Successfully updated to the Database" );
            }
            catch (Exception ex)
            {
                MessageBox.Show( ex.Message );
            }        
        }

 	}
}
