public noteForm(Config.Noty _noty, bool iscreatinganewnote) { noty = _noty; _iscreatinganewnote = iscreatinganewnote; InitializeComponent(); StdConfig.MYSQLCONNECTION = new MySql.Data.MySqlClient.MySqlConnection(Config.Cfg.MYSQLCONNECTIONSTRING); }
public async Task SET(Config.Noty noty, MySql.Data.MySqlClient.MySqlConnection conn) { try { MySqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "insert into noty(title,content,autor,encr_alg) values('" + noty.Title + "','" + noty.Content + "','" + noty.Autor + "','" + noty.EncrAlg + "');"; cmd.Connection = conn; await conn.OpenAsync(); var result = Convert.ToString(await cmd.ExecuteNonQueryAsync()); if (Convert.ToInt16(result) == 1) { MessageBox.Show(@"Noty Created!", @"Saved", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show( @"Error, we can not Create the Noty! " + Environment.NewLine + "For more informations please contact the developers.", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (MySqlException ex) { MessageBox.Show("Error: " + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { conn.Close(); } }
private void button1_Click(object sender, EventArgs e) { Config.Noty noty = new Config.Noty(); noty.Autor = Config.Cfg.UID; noty.EncrAlg = "RijndaelManaged"; noteForm noteF = new noteForm(noty, true); this.Hide(); noteF.ShowDialog(); }
public async Task <List <Config.Noty> > Notys(int ID, MySql.Data.MySqlClient.MySqlConnection conn) { try { MySqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "Select * from noty where autor=@user"; cmd.Parameters.AddWithValue("@user", ID); cmd.Connection = conn; await conn.OpenAsync(); MySqlDataReader uid = cmd.ExecuteReader(); List <Config.Noty> notylist = new List <Config.Noty>(); while (await uid.ReadAsync()) { Config.Noty noty = new Config.Noty(); noty.ID = Convert.ToInt16(uid["id"].ToString()); noty.Title = uid["title"].ToString(); noty.Autor = Convert.ToInt16(uid["autor"].ToString()); noty.Content = null; //uid["content"].ToString(); noty.EncrAlg = uid["encr_alg"].ToString(); noty.LastEdit = Convert.ToDateTime(uid["last_edit"]); noty.CreationDate = Convert.ToDateTime(uid["creation_date"]); notylist.Add(noty); } return(notylist); } catch (MySqlException ex) { MessageBox.Show("Error: " + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } finally { conn.Close(); } }
public async Task POST(Config.Noty noty, MySql.Data.MySqlClient.MySqlConnection conn) { try { MySqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "UPDATE noty SET title=@title, content=@content, encr_alg=@encr_alg WHERE id=@id"; cmd.Connection = conn; cmd.Parameters.AddWithValue("@title", noty.Title); cmd.Parameters.AddWithValue("@content", noty.Content); cmd.Parameters.AddWithValue("@encr_alg", noty.EncrAlg); cmd.Parameters.AddWithValue("@id", noty.ID); await conn.OpenAsync(); var result = Convert.ToString(await cmd.ExecuteNonQueryAsync()); if (Convert.ToInt16(result) == 1) { MessageBox.Show(@"Noty Updated!", @"Saved", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show( @"Error, we can not update! Try with another username. " + Environment.NewLine + "For more informations please contact the developers.", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (MySqlException ex) { MessageBox.Show("Error: " + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { conn.Close(); } }