if (btnFindNext.Enabled)
Find();
}
void grid_CellEnter(object sender, DataGridViewCellEventArgs e)
{
activeGrid = sender as DataGridView;
sNotFound.Visible = false;
if (e.RowIndex != -1 && e.ColumnIndex != -1)
{
activeCell = (DataGridViewCell)activeGrid.Rows[e.RowIndex].Cells[e.ColumnIndex];
if (activeCell != foundCell)
bFindNext = false;
}
}
void gridNew_CellEnter(object sender, DataGridViewCellEventArgs e)
{
DataGridView grid = sender as DataGridView;
int row = e.RowIndex;
grid.Rows[row].Selected = true;
int id = (int)grid.Rows[row].Cells[0].Value;
if (grid.Tag == studsGrid)
ShowStud(id);
else
ShowExam(id);
}
bool FindNext(int row, int col)
{
// Здесь ваш код
}
void Find()
{
// Здесь ваш код
}
void FindAndShowList()
{
string criteria = GetSearchString("List");
if (criteria != null)
ShowList(criteria);
}
void FindAndShowGrid()
{
string criteria = GetSearchString("Grid");
if (criteria != null)
ShowGrid(criteria);
}
void FilterAverage()
{
float low, hi;
bool ok = float.TryParse(tAverageLow.Text, out low);
ok &= float.TryParse(tAverageHi.Text, out hi);
if (!ok)
return;
activeGrid = studsGrid;
activeTable = ds.Tables[0];
searchColumnName = "Average";
string criteria = "Average >= " + low + " AND Average <=" + hi;
DataRow[] rows = ds.Tables[0].Select(criteria);
if (rows.Length == 0)
{
sNotFound.Visible = true;
if (formFound != null)
formFound.Dispose();
return;
}
sNotFound.Visible = false;
FillList(rows, criteria);
}
string GetSearchString(string where)
{
activeTable = activeGrid == studsGrid ? ds.Tables[0] : ds.Tables[1];
int row = 0, col = 0;
if (activeCell != null)
{
row = activeCell.RowIndex;
col = activeCell.ColumnIndex;
}
string
colName = activeTable.Columns[col].ColumnName,
text = Trim(comboFind.Text.ToUpper()); // Искомый текст
bSearchChanged = formFound == null || !formFound.Visible
|| findWhat != text
|| searchGrid != activeGrid
|| searchControl != where
|| searchColumnName != colName;
if (bSearchChanged)
{
searchGrid = activeGrid;
searchColumnName = colName;
findWhat = text;
searchControl = where;
return GetSelectCriteia();
}
return null;
}
string GetSelectCriteia()
{
DataColumn dc = activeTable.Columns[activeCell.ColumnIndex];
string colName = dc.ColumnName;
if (colName != searchColumnName)
searchColumnName = colName;
Type type = dc.DataType;
string sel = "";
switch (type.Name)
{
case "String": sel = " LIKE '" + findWhat + "*'"; break;
case "Decimal": case "Byte": case "SByte":
case "Int16": case "UInt16": case "Int64":
case "UInt64": case "UInt32": case "Boolean":
case "Int32": sel = "=" + findWhat; break;
case "DateTime":
DateTime dt;
bool ok = DateTime.TryParse(findWhat, out dt);
if (ok)
sel = " = #" + dt.ToString() + "#"; // ToShortDateString
else
return null;
break;
}
return sel;
}
void ShowList(string criteria)
{
DataRow[] rows = null;
try
{
rows = activeTable.Select(
activeTable.Columns[activeCell.ColumnIndex].ColumnName + criteria);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
DisposeFormFound();
return;
}
if (rows.Length != 0)
{
if (!comboFind.Items.Contains(comboFind.Text))
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.