|
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace DNetLibrary
{
/// <summary>
/// Summary description for UC_DataWindow.
/// </summary>
public class UC_DataWindow : System.Windows.Forms.UserControl
{
protected DataHelper dm;
private System.Data.DataSet ds_Data;
public System.Windows.Forms.ContextMenu menContextMenue;
private System.Windows.Forms.MenuItem mRetrieve;
private System.Windows.Forms.MenuItem mFirst;
private System.Windows.Forms.MenuItem mNext;
private System.Windows.Forms.MenuItem mPrev;
private System.Windows.Forms.MenuItem mLast;
private System.Windows.Forms.MenuItem mInsert;
private System.Windows.Forms.MenuItem mUpdate;
private System.Windows.Forms.MenuItem mDelete;
private System.Windows.Forms.MenuItem mDuplicate;
private System.Windows.Forms.MenuItem mCancel;
private System.Windows.Forms.MenuItem mSep1;
private System.Windows.Forms.MenuItem mSep2;
private System.Windows.Forms.MenuItem mSep3;
private string sort="";
private string filter="";
bool applyFilter=false;
bool applySort=false;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public event EventHandler RowChanged;
public UC_DataWindow()
{
InitializeComponent();
dm=new DataHelper();
InitData();
}
/// <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 Component 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()
{
ds_Data = new System.Data.DataSet();
menContextMenue = new System.Windows.Forms.ContextMenu();
mRetrieve = new System.Windows.Forms.MenuItem();
mSep1 = new System.Windows.Forms.MenuItem();
mFirst = new System.Windows.Forms.MenuItem();
mNext = new System.Windows.Forms.MenuItem();
mPrev = new System.Windows.Forms.MenuItem();
mLast = new System.Windows.Forms.MenuItem();
mSep2 = new System.Windows.Forms.MenuItem();
mInsert = new System.Windows.Forms.MenuItem();
mUpdate = new System.Windows.Forms.MenuItem();
mDelete = new System.Windows.Forms.MenuItem();
mDuplicate = new System.Windows.Forms.MenuItem();
mSep3 = new System.Windows.Forms.MenuItem();
mCancel = new System.Windows.Forms.MenuItem();
((System.ComponentModel.ISupportInitialize)(ds_Data)).BeginInit();
//
// ds_Data
//
ds_Data.DataSetName = "DS_Data";
ds_Data.Locale = new System.Globalization.CultureInfo("en-US");
//
// menContextMenue
//
menContextMenue.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
mRetrieve,
mSep1,
mFirst,
mNext,
mPrev,
mLast,
mSep2,
mInsert,
mUpdate,
mDelete,
mDuplicate,
mSep3,
mCancel});
//
// mRetrieve
//
mRetrieve.Index = 0;
mRetrieve.Text = "R&etrieve";
mRetrieve.Click += new System.EventHandler(mRetrieve_Click);
//
// mSep1
//
mSep1.Index = 1;
mSep1.Text = "-";
//
// mFirst
//
mFirst.Index = 2;
mFirst.Text = "&First";
mFirst.Click += new System.EventHandler(mFirst_Click);
//
// mNext
//
mNext.Index = 3;
mNext.Text = "&Next";
mNext.Click += new System.EventHandler(mNext_Click);
//
// mPrev
//
mPrev.Index = 4;
mPrev.Text = "&Previous";
mPrev.Click += new System.EventHandler(mPrev_Click);
//
// mLast
//
mLast.Index = 5;
mLast.Text = "&Last";
mLast.Click += new System.EventHandler(mLast_Click);
//
// mSep2
//
mSep2.Index = 6;
mSep2.Text = "-";
//
// mInsert
//
mInsert.Index = 7;
mInsert.Text = "&Insert";
mInsert.Click += new System.EventHandler(mInsert_Click);
//
// mUpdate
//
mUpdate.Index = 8;
mUpdate.Text = "&Update";
//
// mDelete
//
mDelete.Index = 9;
mDelete.Text = "&Delete";
//
// mDuplicate
//
mDuplicate.Index = 10;
mDuplicate.Text = "D&uplicate";
//
// mSep3
//
mSep3.Index = 11;
mSep3.Text = "-";
//
// mCancel
//
mCancel.Index = 12;
mCancel.Text = "&Cancel";
//
// UC_DataWindow
//
BackColor = System.Drawing.Color.Silver;
ContextMenu = menContextMenue;
Name = "UC_DataWindow";
Size = new System.Drawing.Size(288, 224);
Load += new System.EventHandler(UC_DataWindow_Load);
((System.ComponentModel.ISupportInitialize)(ds_Data)).EndInit();
}
#endregion
DataTable table=new DataTable();
public DataTable Table
{
get
{
return table;
}
set
{
table=value;
}
}
private bool retrieveAtOpening;
public bool RetrieveAtOpening
{
get
{
return retrieveAtOpening;
}
set
{
retrieveAtOpening=value;
}
}
public int Retrieve()
{
int result=-1;
string whereCondition="";
string sort="";
try
{
if(ApplyFilter)whereCondition+=Filter;
if(ApplySort)sort=Sort;
table.Clear();
result=dm.Retreive(table,whereCondition,sort);
if(RowChanged!=null)RowChanged("Retrieve",new Args(RowNo));
RaiseRowChangeEvent(0);
}
catch(Exception ex){MessageBox.Show(UTIL.GetExceptionMessage(ex));}
return result;
}
public void MoveFirst()
{
BindingContext[ds_Data,table.TableName].Position=0;
RaiseRowChangeEvent(1);
}
public void MoveLast()
{
BindingContext[ds_Data,table.TableName].Position=BindingContext[ds_Data,table.TableName].Count-1;
RaiseRowChangeEvent(RowNo);
}
public void MoveNext()
{
if(BindingContext[ds_Data,table.TableName].Position==BindingContext[ds_Data,table.TableName].Count-1)
{
BindingContext[ds_Data,table.TableName].Position=0;
RaiseRowChangeEvent(RowNo);
}
BindingContext[ds_Data,table.TableName].Position++;
RaiseRowChangeEvent(RowNo);
}
public void MovePrevious()
{
if(BindingContext[ds_Data,table.TableName].Position==0)
{
BindingContext[ds_Data,table.TableName].Position=BindingContext[ds_Data,table.TableName].Count-1;
RaiseRowChangeEvent(RowNo);
}
BindingContext[ds_Data,table.TableName].Position--;
RaiseRowChangeEvent(RowNo);
}
public int InitData()
{
if(retrieveAtOpening)
{
return Retrieve();
}
return 0;
}
private void menuItem1_Click(object sender, System.EventArgs e)
{
Retrieve();
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
MoveFirst();
}
private void menuItem4_Click(object sender, System.EventArgs e)
{
MoveNext();
}
private void menuItem5_Click(object sender, System.EventArgs e)
{
MovePrevious();
}
private void menuItem6_Click(object sender, System.EventArgs e)
{
MoveLast();
}
public DataSet DS_Data
{
get
{
return ds_Data;
}
set
{
ds_Data=value;
}
}
public int Count
{
get
{
return BindingContext[ds_Data,table.TableName].Count;
}
}
public int RowNo
{
get
{
return BindingContext[ds_Data,table.TableName].Position+1;
}
}
public DataRow DataRowObject
{
get
{
return ds_Data.Tables[table.TableName].Rows[BindingContext[ds_Data,table.TableName].Position];
}
}
private void RaiseRowChangeEvent(int rowNo)
{
if(RowChanged!=null)RowChanged("Navigate",new Args(rowNo));
}
private void UC_DataWindow_Load(object sender, System.EventArgs e)
{
}
private void mRetrieve_Click(object sender, System.EventArgs e)
{
Retrieve();
}
private void mFirst_Click(object sender, System.EventArgs e)
{
MoveFirst();
}
private void mNext_Click(object sender, System.EventArgs e)
{
MoveNext();
}
private void mPrev_Click(object sender, System.EventArgs e)
{
MovePrevious();
}
private void mLast_Click(object sender, System.EventArgs e)
{
MoveLast();
}
private void mInsert_Click(object sender, System.EventArgs e)
{
}
public string Tag1
{
get
{
return null;
}
set
{
}
}
public string Sort
{
get
{
return sort;
}
set
{
sort=value;
}
}
public bool ApplySort
{
get
{
return applySort;
}
set
{
if(Sort==null||Sort.Trim()=="")
{
return;
}
applySort=value;
if(applySort)Retrieve();
}
}
public string Filter
{
get
{
return filter;
}
set
{
filter=value;
}
}
public bool ApplyFilter
{
get
{
return applyFilter;
}
set
{
if(Filter==null||Filter.Trim()=="")
{
return;
}
applyFilter=value;
if(applyFilter)Retrieve();
}
}
public void RemoveFilterSort()
{
Filter="";
ApplySort=false;
Sort="";
ApplyFilter=false;
}
/*class*/}
/*name space*/}
|
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.