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 System.Data.SqlClient;
using System.Data.SqlServerCe;
namespace HDRDataEntryForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
BindDataToGrid();
}
private string _textFilters;
private DataSet _ds;
frmSearch _frmSearch = null;
DataTable dt;
DataRow dr;
private void Form1_Load(object sender, EventArgs e)
{
loadEmployee();
this.mainformTableAdapter.Fill(this.databaseDataSet.Mainform);
}
public void BindDataToGrid()
{
try
{
dataGridView1.DataSource = databaseDataSet.Tables[0].DefaultView;
dataGridView2.DataSource = databaseDataSet.Tables[0].DefaultView;
}
catch (Exception ex)
{
MessageBox.Show(string.Format("Seems like the database file is not where it should... \n\nError details: {0}", ex.Message), "Error loading sample data", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
public void searchgrid_TextChanged(List<field> fields)
{
System.Data.DataView dv = ((System.Data.DataView)dataGridView2.DataSource);
_textFilters = "";
bool first = true;
foreach (field f in fields)
{
if (f.Value.Length > 0)
{
if (!first) _textFilters += " and ";
_textFilters += f.Field + " like '%" + f.Value + "%'";
first = false;
}
}
dv.RowFilter = _textFilters;
}
private void button2_Click(object sender, EventArgs e)
{
if (_frmSearch == null)
{
List<field> fields = new List<field>();
field f = new field();
f.FriendlyName = "UserID";
f.Field = "UserID";
fields.Add(f);
f = new field();
f.FriendlyName = "Name";
f.Field = "Name";
fields.Add(f);
f = new field();
f.FriendlyName = "Age";
f.Field = "Age";
fields.Add(f);
f = new field();
f.FriendlyName = "Gender";
f.Field = "Gender";
fields.Add(f);
f = new field();
f.FriendlyName = "Family_Member_Relation";
f.Field = "Family_Member_Relation";
fields.Add(f);
f = new field();
f.FriendlyName = "Family_Member_Name";
f.Field = "Family_Member_Name";
fields.Add(f);
f = new field();
f.FriendlyName = "Shnong";
f.Field = "Shnong";
fields.Add(f);
f = new field();
f.FriendlyName = "Dong";
f.Field = "Dong";
fields.Add(f);
f = new field();
f.FriendlyName = "Grand";
f.Field = "Grand";
fields.Add(f);
f = new field();
f.FriendlyName = "Amount";
f.Field = "Amount";
fields.Add(f);
f = new field();
f.FriendlyName = "Phone_Number";
f.Field = "Phone_Number";
fields.Add(f);
f = new field();
f.FriendlyName = "Date_Registered";
f.Field = "Date_Registered";
fields.Add(f);
f = new field();
f.FriendlyName = "Date_Recieved";
f.Field = "Date_Recieved";
fields.Add(f);
f = new field();
f.FriendlyName = "Status";
f.Field = "Status";
fields.Add(f);
_frmSearch = new frmSearch(fields);
_frmSearch.TextChanged += new SearchContextChangedHandler(searchgrid_TextChanged);
}
_frmSearch.ShowDialog();
this.btoReset.Visible = true;
}
private void btoReset_Click(object sender, EventArgs e)
{
{
_frmSearch = null;
_textFilters = "";
System.Data.DataView dv = ((System.Data.DataView)dataGridView1.DataSource);
dv.RowFilter = _textFilters;
this.btoReset.Visible = false;
}
}
public void loadEmployee()
{
SqlCeConnection con = new SqlCeConnection("Data Source=Database.sdf");
try
{
SqlCeDataAdapter ADAP = new SqlCeDataAdapter("Select UserID, Name, Age, Gender, Family_Member_Relation, Family_Member_Name, Shnong, Dong, Grand, Amount, Phone_Number, Date_Registered, Date_Recieved, Status from Mainform", con);
ADAP.Fill(databaseDataSet, "Mainform");
this.dataGridView2.DataSource = databaseDataSet.Tables["Mainform"];
databaseDataSet.GetChanges();
dataGridView1.RefreshEdit();
dataGridView2.RefreshEdit();
this.mainformTableAdapter.Fill(this.databaseDataSet.Mainform);
}
catch (Exception)
{
}
}
private void btoedit_Click(object sender, EventArgs e)
{
frmUpdate f2 = new frmUpdate(this);
f2.UserID = dataGridView2.CurrentRow.Cells[0].Value.ToString();
f2.Name = dataGridView2.CurrentRow.Cells[1].Value.ToString();
f2.Age = dataGridView2.CurrentRow.Cells[2].Value.ToString();
f2.Gender = dataGridView2.CurrentRow.Cells[3].Value.ToString();
f2.Family_Member_Relation = dataGridView2.CurrentRow.Cells[4].Value.ToString();
f2.Family_Member_Name = dataGridView2.CurrentRow.Cells[5].Value.ToString();
f2.Shnong = dataGridView2.CurrentRow.Cells[6].Value.ToString();
f2.Dong = dataGridView2.CurrentRow.Cells[7].Value.ToString();
f2.Grand = dataGridView2.CurrentRow.Cells[8].Value.ToString();
f2.Amount = dataGridView2.CurrentRow.Cells[9].Value.ToString();
f2.Phone_Number = dataGridView2.CurrentRow.Cells[10].Value.ToString();
f2.Date_Registered = dataGridView2.CurrentRow.Cells[11].Value.ToString();
f2.Date_Recieved = dataGridView2.CurrentRow.Cells[12].Value.ToString();
f2.Status = dataGridView2.CurrentRow.Cells[13].Value.ToString();
f2.passDgvValueToForm2();
f2.ShowDialog();
loadEmployee();
}