private void WindowList(string username) { if (TempClass.usernameList.Contains(username)) { ((SendMessage)TempClass.usernameList[username]).Focus(); } else { SendMessage frmMessage = new SendMessage(username); frmMessage.contact = username; frmMessage.Text = username + " - Instant Message"; TempClass.usernameList.Add(username, frmMessage); frmMessage.Show(); } }
private void tmrMessageReceive_Tick(object sender, EventArgs e) { try { string sql = "SELECT * FROM tbOnlineUsersMessage WHERE ToLoginName=@tologinname"; SqlCommand SqlCommand1 = con.CreateCommand(); SqlCommand1.CommandText = sql; int res; SqlCommand1.Parameters.Add("@tologinname", SqlDbType.VarChar, 100); SqlCommand1.Parameters[0].Value = TempClass.username; da = new SqlDataAdapter(); da.SelectCommand = SqlCommand1; myDataSet = new System.Data.DataSet(); res = da.Fill(myDataSet, "tbOnlineUsersMessage"); if (res >= 1) { string from = myDataSet.Tables["tbOnlineUsersMessage"].Rows[0]["FromLoginName"].ToString(); if (TempClass.usernameList.Contains(from)) { ((SendMessage)TempClass.usernameList[from]).Focus(); ((SendMessage)TempClass.usernameList[from]).tmrMessageComing.Enabled = true; TempClass.i = 1; } else { SendMessage frmMessage = new SendMessage(from); frmMessage.contact = from; frmMessage.Text = from + " - Instant Message"; TempClass.usernameList.Add(from, frmMessage); frmMessage.Show(); frmMessage.tmrMessageComing.Enabled = true; TempClass.i = 1; } } } catch (Exception ex) { MessageBox.Show("Error"); } }