private void Messagerie_Load(object sender, EventArgs e) { try { subjnme_lbl.Text = project_selection_form.subject; subj_id_lbl.Text = project_selection_form.subject_ID; MySqlConnection connection = new MySqlConnection(Connec); connection.Open(); string query3 = @"SELECT message_content, user_name FROM internal_communication_4.messages AS m1 JOIN internal_communication_4.subjects AS s1 ON m1.subjects_subject_id = s1.subject_id JOIN user AS u1 ON m1.user_user_id = u1.user_id WHERE (subject_selection = 1)"; MySqlDataAdapter adapte = new MySqlDataAdapter(query3, connection); adapte.Fill(table2); while (row < table2.Rows.Count) { Message_class mes = new Message_class(); mes.User_name = (string)table2.Rows[row]["message_content"]; mes.Message_content = (string)table2.Rows[row]["user_name"]; message_lstbx.Items.Add(mes.Showmessage()); row += 1; } subjnme_lbl.Text = (string)table2.Rows[0]["subject_name"]; subj_id_lbl.Text = table2.Rows[0]["subject_id"].ToString(); connection.Close(); row = 0; } catch { } }
public void Generator(string Nick, string message, DateTime date, int photo = Resource.Drawable.acceptsmall) { Message_class new_message = new Message_class(Nick, message, Convert.ToString(date.Day) + ":" + Convert.ToString(date.Month) + ":" + Convert.ToString(date.Year) + " " + Convert.ToString(date.Hour) + ":" + Convert.ToString(date.Minute)); new_message.uri = photo; new_message.id = messageHistory_list.Count; message_list.Add(new_message); messageHistory_list.Add(new_message); mAdapter.NotifyDataSetChanged(); mLayoutManager.ScrollToPosition(0); historia.SaveObject(messageHistory_list); }
public void Load_History(List <Message_class> history_list) { //System.Threading.Thread.Sleep(2000); for (int a = 0; a <= 5; a++) { if (message_list[0].id > 0) { Message_class mes = history_list[message_list[0].id - 1]; message_list.Insert(0, mes); } } int numberOfChild = mRecyclerView.ChildCount; mAdapter.NotifyDataSetChanged(); mLayoutManager.ScrollToPosition(numberOfChild); }
private void send_btn_Click(object sender, EventArgs e) { try { MySqlConnection connection = new MySqlConnection(Connec); connection.Open(); string query = @"SELECT user_id FROM internal_communication_4.users WHERE user_name = " + login_form.user_name + " "; MySqlCommand command = new MySqlCommand(query, connection); MySqlDataReader MyReader2; MyReader2 = command.ExecuteReader(); while (MyReader2.Read()) { user_id_messages = Convert.ToInt32(MyReader2.GetString(0)); } connection.Close(); MySqlConnection connection3 = new MySqlConnection(Connec); connection3.Open(); string query3 = @"SELECT Project_project_id FROM internal_communication_4.subjects WHERE subject_id = " + subj_id_lbl.Text + " "; MySqlCommand command3 = new MySqlCommand(query3, connection3); MySqlDataReader MyReader4; MyReader4 = command3.ExecuteReader(); while (MyReader4.Read()) { project_id = Convert.ToInt32(MyReader4.GetString(0)); } connection3.Close(); } catch { MessageBox.Show("error in data integrity"); } try { Message_class mes = new Message_class(); mes.Message_content = input_txtbx.Text; mes.Subject_id = Convert.ToInt32(subj_id_lbl.Text); mes.User_id = user_id_messages; mes.Project_id = project_id; mes.Message_posting = DateTime.Now; MySqlConnection connection2 = new MySqlConnection(Connec); connection2.Open(); MySqlCommand command2 = connection2.CreateCommand(); command2.CommandText = @"INSERT INTO internal_communication_4.messages (user_user_id,subjects_subject_id,subjects_Project_project_id,message_content, message_posting) VALUES( @user_user_id, @subjects_subject_id, @subjects_Project_project_id, @message_content, @message_posting)"; command2.Parameters.AddWithValue("@user_user_id", mes.User_id); command2.Parameters.AddWithValue("@subjects_subject_id", mes.Subject_id); command2.Parameters.AddWithValue("@subjects_Project_project_id", mes.Project_id); command2.Parameters.AddWithValue("@message_content", mes.Message_content); command2.Parameters.AddWithValue("@message_posting", mes.Message_posting); command2.ExecuteNonQuery(); connection2.Close(); message_lstbx.Items.Add(mes.Showmessage()); } catch { MessageBox.Show("could not add message"); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Chat); SupportToolbar toolBar = FindViewById <SupportToolbar>(Resource.Id.toolbar); SetSupportActionBar(toolBar); SupportActionBar.SetDisplayHomeAsUpEnabled(true); string friend = Intent.GetStringExtra("Name"); SupportActionBar.Title = friend; ImageView imagev = FindViewById <ImageView>(Resource.Id.sendImage); //imagev.SetOnClickListener(SendClickListener); imagev.Click += delegate { SendClickListener(); }; mRecyclerView = FindViewById <RecyclerView>(Resource.Id.recyclerview); mLayoutManager = new LinearLayoutManager(mRecyclerView.Context); mAdapter = new RecyclerAdapter(message_list); mLayoutManager.StackFromEnd = false; mLayoutManager.ReverseLayout = true; var onScrollListener = new RecyclerViewOnScrollListener(mLayoutManager); mRecyclerView.AddOnScrollListener(onScrollListener); mRecyclerView.SetLayoutManager(mLayoutManager); mRecyclerView.SetAdapter(mAdapter); historia = new ReadWriteAppFile(friend); try { var restoredOject = historia.RestoreObject(); messageHistory_list = (List <Message_class>)restoredOject; int k = 0; for (int i = 0; i <= 10; i++) { if (messageHistory_list.Count >= k + 1) { DateTime date = DateTime.Now; Message_class mes = messageHistory_list[messageHistory_list.Count - (k + 1)]; message_list.Insert(0, mes); k++; } } mAdapter.NotifyDataSetChanged(); mLayoutManager.ScrollToPosition(0); } catch { } onScrollListener.LoadMoreEvent += (object sender, EventArgs e) => { if (message_list[0].id > 0) { Load_History(messageHistory_list); } else { mRecyclerView.RemoveOnScrollListener(onScrollListener); } }; }