Есть колонка Online, которая создается путем запроса со значениями: 1 - если онлайн и 0 - если оффлайн. Я создал дополнительную колонку с иконками. Как мне подставить вместо значений 1 и 0 соответствующие иконки?
private void GetData()
{
try
{
var loadData = cs.LoadFile("DataConnection.xml");
string connString = String.Format("Data Source={0};Initial Catalog={1};User Id={2};Password={3}", loadData.Host, loadData.Database, loadData.UserId, loadData.PWD);
SqlConnection connection = new SqlConnection(connString);
// Create a DataSet.
DataSet data = new DataSet();
data.Locale = System.Globalization.CultureInfo.InvariantCulture;
// Add data from the BTA_USERS table to the DataSet.
//string strUsersData = String.Format("select * from BTA_USERS where \"ID\" != {0} and \"isDelUser\" is null", loadData.LastId);
string strUsersData = String.Format("select BTA_USERS.\"ID\", \"NAME\", case when BTA_USERS_ENTEREXIT.\"id\" is not null then '1' else '0' end as Online from BTA_USERS " +
"left join BTA_USERS_ENTEREXIT on BTA_USERS.\"ID\" = BTA_USERS_ENTEREXIT.\"user_id\" " +
"and cast(convert(char(8), BTA_USERS_ENTEREXIT.\"date_enter\", 112) as datetime) = cast(convert(char(8), GETDATE(), 112) as datetime) " +
"and BTA_USERS_ENTEREXIT.\"date_exit\" = null " +
"where BTA_USERS.\"ID\" != {0} and BTA_USERS.\"isDelUser\" is null " +
"order by Online asc, \"NAME\" asc", loadData.LastId);
SqlDataAdapter usersDataAdapter = new SqlDataAdapter(strUsersData, connection);
usersDataAdapter.Fill(data, "BTA_USERS");
// Add data from the sta_Messages table to the DataSet.
string strPostData = String.Format("select \"GetText\", case when \"SetUser_id\" = {0} then \"GetUser_id\" else \"SetUser_id\" end as Sender, case when \"SetUser_id\" = {0} then 'outgoing' else 'incoming' end as Stream from sta_Messages where \"SetUser_id\" = {0} or \"GetUser_id\" = {0}", loadData.LastId);
SqlDataAdapter postsDataAdapter = new SqlDataAdapter(strPostData, connection);
postsDataAdapter.Fill(data, "sta_Messages");
//// Establish a relationship between the two tables.
DataRelation relation = new DataRelation("UsersMessages",
data.Tables["BTA_USERS"].Columns["ID"],
data.Tables["sta_Messages"].Columns["Sender"]);
data.Relations.Add(relation);
// Bind the master data connector to the BTA_USERS table.
BindingSource usersBindingSource = new BindingSource();
BindingSource postsBindingSource = new BindingSource();
usersBindingSource.DataSource = data;
usersBindingSource.DataMember = "BTA_USERS";
postsBindingSource.DataSource = usersBindingSource;
postsBindingSource.DataMember = "UsersMessages";
usersDataGridView.DataSource = usersBindingSource;
postsDataGridView.DataSource = postsBindingSource;
usersDataGridView.Columns[0].Visible = false;
Image i = new Bitmap(@"D:\greenround.ico");
Image i2 = new Bitmap(@"D:\redround.ico");
for (int n = 0; n < usersDataGridView.RowCount; n++)
{
if (Convert.ToChar(usersDataGridView.Rows[n].Cells[2].Value) == '1')
{
usersDataGridView.Rows[n].Cells[2].Value = i;
}
else if (Convert.ToChar(usersDataGridView.Rows[n].Cells[2].Value) == '0')
{
usersDataGridView.Rows[n].Cells[2].Value = i2;
}
}
}
catch (SqlException)
{
MessageBox.Show("Помилка!");
}
}