Sunteți pe pagina 1din 4

using using using using

System; System.Collections.Generic; System.Linq; System.Text;

namespace Forms1demo { class DataStore { public static List<Customer> CustDB; static DataStore() { CustDB=new List<Customer>(); } } } --------------------------------------------------------------using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Forms1demo { class Customer { List<string> Hobbies= new List<string>(); public Customer(string _id, string _name,string _Address,string _gender, string _DOB,string _type, List<strin g>hob ) { Name = _name; Id = _id; Address = _Address; gender = _gender; DOB=_DOB; type=_type; hob = Hobbies; } public string Name{set;get;} public public public public public string string string string string Id { set; get; } Address { set; get; } gender { set; get; } DOB { set; get; } type { set; get; }

} }

------------------------------------------------------------------------------------------------------------using using using using using using using using using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms; System.Collections;

namespace Forms1demo { public partial class Form1 : Form { List<string> hby = new List<string>(); public Form1() { InitializeComponent(); } private void label1_Click(object sender, EventArgs e) { } private void Form1_Load(object sender, EventArgs e) { } private void radioButton2_CheckedChanged(object sender, EventArgs e) { } private void checkBox6_CheckedChanged(object sender, EventArgs e) { CheckBox c = (CheckBox)sender;

if (c.Checked) { hby.Add(c.Text); } else { hby.Remove(c.Text); }

} private void button1_Click(object sender, EventArgs e) { string gnd = "", types = ""; if (radioButton1.Checked) { gnd = radioButton1.Text; } else { gnd = radioButton2.Text; } if (radioButton3.Checked) { types = radioButton3.Text; } else if (radioButton4.Checked) { types = radioButton4.Text; } else { types = radioButton5.Text; } Customer c = new Customer(textBox1.Text, textBox2.Text, textBox3.Text, gnd, maskedTextBox1.Text,typ es, hby); DataStore.CustDB.Add(c); RefershData(textBox4.Text); } public void RefershData(string cname) { DataTable dt = new DataTable(); DataColumn dc1 = new DataColumn("CUSTOMER Id"); dt.Columns.Add(dc1); DataColumn dc2 = new DataColumn("CUSTOMER NAME"); dt.Columns.Add(dc2); DataColumn dc3 = new DataColumn("GENDER"); dt.Columns.Add(dc3); DataColumn dc4 = new DataColumn("BIRTH DATE"); dt.Columns.Add(dc4); DataColumn dc5 = new DataColumn("TYPE"); dt.Columns.Add(dc5);

IEnumerable enu = from cst in DataStore.CustDB where cst.Name.Starts With(cname) select cst; foreach (Customer c in enu) { DataRow dr = dt.NewRow(); dr[0] = c.Id; dr[1] = c.Name; dr[2] = c.gender; dr[3] = c.DOB; dr[4] = c.type; dt.Rows.Add(dr); } dataGridView1.DataSource = dt; } private void dataGridView1_CellContentClick(object sender, DataGridViewC ellEventArgs e) { string cid=(string)(dataGridView1.Rows[e.RowIndex].Cells[0].Value); Customer cst=(from c in DataStore.CustDB where c.Id==cid select c).F irstOrDefault(); textBox1.Text = cst.Id.ToString(); textBox2.Text = cst.Address; textBox3.Text = cst.Name; } private void textBox4_TextChanged(object sender, EventArgs e) { RefershData(textBox4.Text); }

} }

S-ar putea să vă placă și