09. oktober 2003 - 13:28
#4
Her er kode til den form hvor jeg anvender mit dataset
håber det kan hjælpe
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Prototype2.BankService;
namespace Prototype2
{
/// <summary>
/// Summary description for UpdateCustForm.
/// </summary>
public class UpdateCustForm : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox9;
private System.Windows.Forms.TextBox textBox10;
private System.Windows.Forms.TextBox textBox11;
private System.Windows.Forms.TextBox textBox12;
private System.Windows.Forms.TextBox textBox13;
private System.Windows.Forms.TextBox textBox14;
private System.Windows.Forms.TextBox textBox15;
private System.Windows.Forms.TextBox textBox16;
private System.Windows.Forms.TextBox textBox17;
private System.Windows.Forms.TextBox textBox18;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox textBox5;
private System.Windows.Forms.TextBox textBox8;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox7;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.TextBox textBox6;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.Label label12;
private System.Windows.Forms.Label label13;
private System.Windows.Forms.Label label14;
private System.Windows.Forms.Label label15;
private System.Windows.Forms.Label label16;
private System.Windows.Forms.Label label17;
private System.Windows.Forms.Label label18;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.DataGrid dataGrid1;
private DataSet dSet = null;
private Service1 s = null;
private System.Windows.Forms.Label label19;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Label hiddenLbl;
private System.ComponentModel.Container components = null;
public UpdateCustForm()
{
InitializeComponent();
s = new Service1();
GetAllCustomers();
}
/// <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.textBox9 = new System.Windows.Forms.TextBox();
this.textBox10 = new System.Windows.Forms.TextBox();
this.textBox11 = new System.Windows.Forms.TextBox();
this.textBox12 = new System.Windows.Forms.TextBox();
this.textBox13 = new System.Windows.Forms.TextBox();
this.textBox14 = new System.Windows.Forms.TextBox();
this.textBox15 = new System.Windows.Forms.TextBox();
this.textBox16 = new System.Windows.Forms.TextBox();
this.textBox17 = new System.Windows.Forms.TextBox();
this.textBox18 = new System.Windows.Forms.TextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label8 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.textBox5 = new System.Windows.Forms.TextBox();
this.textBox8 = new System.Windows.Forms.TextBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox7 = new System.Windows.Forms.TextBox();
this.textBox4 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.textBox6 = new System.Windows.Forms.TextBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.label16 = new System.Windows.Forms.Label();
this.label15 = new System.Windows.Forms.Label();
this.label14 = new System.Windows.Forms.Label();
this.label13 = new System.Windows.Forms.Label();
this.label12 = new System.Windows.Forms.Label();
this.label11 = new System.Windows.Forms.Label();
this.label10 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.label18 = new System.Windows.Forms.Label();
this.label17 = new System.Windows.Forms.Label();
this.label19 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.button5 = new System.Windows.Forms.Button();
this.hiddenLbl = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// textBox9
//
this.textBox9.Location = new System.Drawing.Point(144, 32);
this.textBox9.Name = "textBox9";
this.textBox9.TabIndex = 8;
this.textBox9.Text = "";
//
// textBox10
//
this.textBox10.Location = new System.Drawing.Point(144, 64);
this.textBox10.Name = "textBox10";
this.textBox10.TabIndex = 9;
this.textBox10.Text = "";
//
// textBox11
//
this.textBox11.Location = new System.Drawing.Point(144, 96);
this.textBox11.Name = "textBox11";
this.textBox11.TabIndex = 10;
this.textBox11.Text = "";
//
// textBox12
//
this.textBox12.Location = new System.Drawing.Point(144, 128);
this.textBox12.Name = "textBox12";
this.textBox12.TabIndex = 11;
this.textBox12.Text = "";
//
// textBox13
//
this.textBox13.Location = new System.Drawing.Point(408, 32);
this.textBox13.Name = "textBox13";
this.textBox13.TabIndex = 12;
this.textBox13.Text = "";
//
// textBox14
//
this.textBox14.Location = new System.Drawing.Point(408, 64);
this.textBox14.Name = "textBox14";
this.textBox14.TabIndex = 13;
this.textBox14.Text = "textBox14";
//
// textBox15
//
this.textBox15.Location = new System.Drawing.Point(408, 96);
this.textBox15.Name = "textBox15";
this.textBox15.TabIndex = 14;
this.textBox15.Text = "textBox15";
//
// textBox16
//
this.textBox16.Location = new System.Drawing.Point(408, 128);
this.textBox16.Name = "textBox16";
this.textBox16.TabIndex = 15;
this.textBox16.Text = "textBox16";
//
// textBox17
//
this.textBox17.Location = new System.Drawing.Point(144, 32);
this.textBox17.Name = "textBox17";
this.textBox17.TabIndex = 16;
this.textBox17.Text = "";
//
// textBox18
//
this.textBox18.Location = new System.Drawing.Point(408, 32);
this.textBox18.Name = "textBox18";
this.textBox18.TabIndex = 17;
this.textBox18.Text = "";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.label8);
this.groupBox1.Controls.Add(this.label7);
this.groupBox1.Controls.Add(this.label6);
this.groupBox1.Controls.Add(this.label5);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.textBox5);
this.groupBox1.Controls.Add(this.textBox8);
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Controls.Add(this.textBox7);
this.groupBox1.Controls.Add(this.textBox4);
this.groupBox1.Controls.Add(this.textBox2);
this.groupBox1.Controls.Add(this.textBox3);
this.groupBox1.Controls.Add(this.textBox6);
this.groupBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.groupBox1.Location = new System.Drawing.Point(16, 16);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(544, 200);
this.groupBox1.TabIndex = 18;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Kunde Information";
//
// label8
//
this.label8.Location = new System.Drawing.Point(304, 136);
this.label8.Name = "label8";
this.label8.TabIndex = 15;
this.label8.Text = "Email";
//
// label7
//
this.label7.Location = new System.Drawing.Point(304, 104);
this.label7.Name = "label7";
this.label7.TabIndex = 14;
this.label7.Text = "Tlf";
//
// label6
//
this.label6.Location = new System.Drawing.Point(304, 72);
this.label6.Name = "label6";
this.label6.TabIndex = 13;
this.label6.Text = "By";
//
// label5
//
this.label5.Location = new System.Drawing.Point(304, 40);
this.label5.Name = "label5";
this.label5.TabIndex = 12;
this.label5.Text = "Postnr";
//
// label4
//
this.label4.Location = new System.Drawing.Point(40, 136);
this.label4.Name = "label4";
this.label4.TabIndex = 11;
this.label4.Text = "Adresse";
//
// label3
//
this.label3.Location = new System.Drawing.Point(40, 104);
this.label3.Name = "label3";
this.label3.TabIndex = 10;
this.label3.Text = "EfterNavn";
//
// label2
//
this.label2.Location = new System.Drawing.Point(40, 72);
this.label2.Name = "label2";
this.label2.TabIndex = 9;
this.label2.Text = "Fornavn";
//
// label1
//
this.label1.Location = new System.Drawing.Point(40, 40);
this.label1.Name = "label1";
this.label1.TabIndex = 8;
this.label1.Text = "Kunde Nr";
//
// textBox5
//
this.textBox5.Location = new System.Drawing.Point(408, 40);
this.textBox5.Name = "textBox5";
this.textBox5.TabIndex = 4;
this.textBox5.Text = "";
//
// textBox8
//
this.textBox8.Location = new System.Drawing.Point(408, 136);
this.textBox8.Name = "textBox8";
this.textBox8.TabIndex = 7;
this.textBox8.Text = "";
//
// textBox1
//
this.textBox1.Enabled = false;
this.textBox1.Location = new System.Drawing.Point(144, 40);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// textBox7
//
this.textBox7.Location = new System.Drawing.Point(408, 104);
this.textBox7.Name = "textBox7";
this.textBox7.TabIndex = 6;
this.textBox7.Text = "";
//
// textBox4
//
this.textBox4.Location = new System.Drawing.Point(144, 136);
this.textBox4.Name = "textBox4";
this.textBox4.TabIndex = 3;
this.textBox4.Text = "";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(144, 72);
this.textBox2.Name = "textBox2";
this.textBox2.TabIndex = 1;
this.textBox2.Text = "";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(144, 104);
this.textBox3.Name = "textBox3";
this.textBox3.TabIndex = 2;
this.textBox3.Text = "";
//
// textBox6
//
this.textBox6.Location = new System.Drawing.Point(408, 72);
this.textBox6.Name = "textBox6";
this.textBox6.TabIndex = 5;
this.textBox6.Text = "";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.label16);
this.groupBox2.Controls.Add(this.label15);
this.groupBox2.Controls.Add(this.textBox10);
this.groupBox2.Controls.Add(this.textBox12);
this.groupBox2.Controls.Add(this.textBox11);
this.groupBox2.Controls.Add(this.textBox13);
this.groupBox2.Controls.Add(this.textBox16);
this.groupBox2.Controls.Add(this.textBox14);
this.groupBox2.Controls.Add(this.textBox15);
this.groupBox2.Controls.Add(this.textBox9);
this.groupBox2.Controls.Add(this.label14);
this.groupBox2.Controls.Add(this.label13);
this.groupBox2.Controls.Add(this.label12);
this.groupBox2.Controls.Add(this.label11);
this.groupBox2.Controls.Add(this.label10);
this.groupBox2.Controls.Add(this.label9);
this.groupBox2.Location = new System.Drawing.Point(16, 256);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(544, 176);
this.groupBox2.TabIndex = 19;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Rådgiver Information";
//
// label16
//
this.label16.Location = new System.Drawing.Point(304, 128);
this.label16.Name = "label16";
this.label16.TabIndex = 23;
this.label16.Text = "label16";
this.label16.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label15
//
this.label15.Location = new System.Drawing.Point(304, 96);
this.label15.Name = "label15";
this.label15.TabIndex = 22;
this.label15.Text = "label15";
this.label15.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label14
//
this.label14.Location = new System.Drawing.Point(304, 64);
this.label14.Name = "label14";
this.label14.TabIndex = 21;
this.label14.Text = "Afdeling";
this.label14.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label13
//
this.label13.Location = new System.Drawing.Point(304, 32);
this.label13.Name = "label13";
this.label13.TabIndex = 20;
this.label13.Text = "Email";
this.label13.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label12
//
this.label12.Location = new System.Drawing.Point(40, 128);
this.label12.Name = "label12";
this.label12.TabIndex = 19;
this.label12.Text = "Tlf.";
this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label11
//
this.label11.Location = new System.Drawing.Point(40, 96);
this.label11.Name = "label11";
this.label11.TabIndex = 18;
this.label11.Text = "Efternavn";
this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label10
//
this.label10.Location = new System.Drawing.Point(40, 64);
this.label10.Name = "label10";
this.label10.TabIndex = 17;
this.label10.Text = "Fornavn";
this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label9
//
this.label9.Location = new System.Drawing.Point(40, 32);
this.label9.Name = "label9";
this.label9.TabIndex = 16;
this.label9.Text = "Titel";
this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// groupBox3
//
this.groupBox3.Controls.Add(this.label18);
this.groupBox3.Controls.Add(this.label17);
this.groupBox3.Controls.Add(this.textBox18);
this.groupBox3.Controls.Add(this.textBox17);
this.groupBox3.Controls.Add(this.label19);
this.groupBox3.Location = new System.Drawing.Point(16, 472);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(544, 72);
this.groupBox3.TabIndex = 20;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Konto Information";
//
// label18
//
this.label18.Location = new System.Drawing.Point(304, 32);
this.label18.Name = "label18";
this.label18.TabIndex = 19;
this.label18.Text = "Saldo";
this.label18.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label17
//
this.label17.Location = new System.Drawing.Point(40, 32);
this.label17.Name = "label17";
this.label17.TabIndex = 18;
this.label17.Text = "Kontonr";
this.label17.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label19
//
this.label19.Location = new System.Drawing.Point(512, 32);
this.label19.Name = "label19";
this.label19.Size = new System.Drawing.Size(24, 24);
this.label19.TabIndex = 26;
this.label19.Text = "kr.";
this.label19.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// button1
//
this.button1.Location = new System.Drawing.Point(96, 560);
this.button1.Name = "button1";
this.button1.TabIndex = 21;
this.button1.Text = "Opret";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(176, 560);
this.button2.Name = "button2";
this.button2.TabIndex = 22;
this.button2.Text = "Rediger";
//
// button3
//
this.button3.Location = new System.Drawing.Point(256, 560);
this.button3.Name = "button3";
this.button3.TabIndex = 23;
this.button3.Text = "Slet";
//
// button4
//
this.button4.Location = new System.Drawing.Point(336, 560);
this.button4.Name = "button4";
this.button4.TabIndex = 24;
this.button4.Text = "Fortryd ";
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(584, 24);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.ReadOnly = true;
this.dataGrid1.Size = new System.Drawing.Size(408, 520);
this.dataGrid1.TabIndex = 25;
//
// button5
//
this.button5.Location = new System.Drawing.Point(16, 560);
this.button5.Name = "button5";
this.button5.TabIndex = 26;
this.button5.Text = "Ny";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// hiddenLbl
//
this.hiddenLbl.Location = new System.Drawing.Point(288, 224);
this.hiddenLbl.Name = "hiddenLbl";
this.hiddenLbl.TabIndex = 27;
//
// UpdateCustForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(1016, 741);
this.Controls.Add(this.hiddenLbl);
this.Controls.Add(this.button5);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Name = "UpdateCustForm";
this.Text = "Konto Information";
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void GetAllCustomers()
{
dSet = s.GetAllCustomers();
dataGrid1.DataSource = dSet.Tables["Customers"];
BindData(dSet);
}
private void BindData(DataSet ds)
{
textBox1.DataBindings.Add(new Binding("Text", ds.Tables["Customers"],"customerNo"));
textBox2.DataBindings.Add(new Binding("Text", ds.Tables["Customers"], "firstName"));
textBox3.DataBindings.Add(new Binding("Text", ds.Tables["Customers"], "lastName"));
textBox4.DataBindings.Add(new Binding("Text", ds.Tables["Customers"], "address"));
textBox5.DataBindings.Add(new Binding("Text", ds.Tables["Customers"], "zipcode"));
textBox6.DataBindings.Add(new Binding("Text", ds.Tables["Customers"], "city"));
textBox7.DataBindings.Add(new Binding("Text", ds.Tables["Customers"], "phone"));
textBox8.DataBindings.Add(new Binding("Text", ds.Tables["Customers"], "email"));
textBox9.DataBindings.Add(new Binding("Text", ds.Tables["Customers"], "Titel"));
textBox10.DataBindings.Add(new Binding("Text", ds.Tables["Customers"], "empFirstName"));
textBox11.DataBindings.Add(new Binding("Text", ds.Tables["Customers"], "empLastName"));
textBox12.DataBindings.Add(new Binding("Text", ds.Tables["Customers"], "empPhone"));
textBox13.DataBindings.Add(new Binding("Text", ds.Tables["Customers"], "empEmail"));
textBox14.DataBindings.Add(new Binding("Text", ds.Tables["Customers"], "address"));
textBox15.DataBindings.Add(new Binding("Text", ds.Tables["Customers"], "address"));
textBox16.DataBindings.Add(new Binding("Text", ds.Tables["Customers"], "address"));
textBox17.DataBindings.Add(new Binding("Text", ds.Tables["Customers"], "accountNo"));
textBox18.DataBindings.Add(new Binding("Text", ds.Tables["Customers"], "ballance"));
}
private void ResetTextBoxes()
{
textBox1.ResetText();
textBox2.ResetText();
textBox3.ResetText();
textBox4.ResetText();
textBox5.ResetText();
textBox6.ResetText();
textBox7.ResetText();
textBox8.ResetText();
textBox9.ResetText();
textBox10.ResetText();
textBox11.ResetText();
textBox12.ResetText();
textBox13.ResetText();
textBox14.ResetText();
textBox15.ResetText();
textBox16.ResetText();
textBox17.ResetText();
textBox18.ResetText();
}
private void button5_Click(object sender, System.EventArgs e)
{
ResetTextBoxes();
string kNo = s.GetNextCustomerNo();
textBox1.Text = kNo;
}
private void button1_Click(object sender, System.EventArgs e)
{
object[] items = new object[4];
items[0] = textBox1.Text;
items[1] = textBox2.Text;
items[2] = textBox3.Text;
items[3] = textBox4.Text;
// items[4] = Convert.ToInt32(textBox5.Text);
// items[5] = textBox6.Text;
// items[6] = textBox7.Text;
// items[7] = textBox8.Text;
// items[8] = textBox9.Text;
// items[9] = textBox10.Text;
// items[10] = textBox11.Text;
// items[11] = textBox12.Text;
// items[12] = textBox13.Text;
// items[13] = textBox14.Text;
// items[14] = textBox15.Text;
// items[15] = textBox16.Text;
// items[16] = textBox17.Text;
// items[17] = Convert.ToDouble( textBox18.Text);
DataRow row = dSet.Tables["Customers"].NewRow();
row.ItemArray = items;
dSet.Tables["Customers"].Rows.InsertAt(row, dSet.Tables["Customers"].Rows.Count+1);
}
}
}