public static int Insert(MediaData m) { int result = -1; //p_insert_media try { using (MySqlConnection conn = new MySqlConnection(App.setting.connectString)) { conn.Open(); string query = "`p_insert_media`"; using (MySqlCommand cmd = new MySqlCommand(query, conn)) { cmd.Parameters.Add(new MySqlParameter("@_media_name", MySqlDbType.VarChar, 255) { Direction = System.Data.ParameterDirection.Input, Value = m.Name }); cmd.Parameters.Add(new MySqlParameter("@_media_url", MySqlDbType.VarChar, 255) { Direction = System.Data.ParameterDirection.Input, Value = m.Url }); cmd.Parameters.Add(new MySqlParameter("@_media_type", MySqlDbType.Int32) { Direction = System.Data.ParameterDirection.Input, Value = m.Type }); cmd.Parameters.Add(new MySqlParameter("@_media_comment", MySqlDbType.Text) { Direction = System.Data.ParameterDirection.Input, Value = m.Comment }); cmd.Parameters.Add(new MySqlParameter("@_media_size", MySqlDbType.VarChar,100) { Direction = System.Data.ParameterDirection.Input, Value = m.FileSize }); cmd.Parameters.Add(new MySqlParameter("@_media_duration", MySqlDbType.VarChar, 100) { Direction = System.Data.ParameterDirection.Input, Value = m.Duration }); cmd.Parameters.Add(new MySqlParameter("@_media_user", MySqlDbType.Int32) { Direction = System.Data.ParameterDirection.Input, Value = m.User_ID }); cmd.Parameters.Add(new MySqlParameter("@_media_id", MySqlDbType.Int32) { Direction = System.Data.ParameterDirection.Output, Value = 0 }); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.ExecuteScalar(); result = Convert.ToInt32(cmd.Parameters["@_media_id"].Value); }; conn.Close(); }; } catch (Exception) { } return result; }
public static void Delete(MediaData m) { //p_delete_media try { using (MySqlConnection conn = new MySqlConnection(App.setting.connectString)) { conn.Open(); string query = "`p_delete_media`"; using (MySqlCommand cmd = new MySqlCommand(query, conn)) { cmd.Parameters.Add(new MySqlParameter("@_media_id", MySqlDbType.Int32) { Direction = System.Data.ParameterDirection.Input, Value = m.ID }); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.ExecuteScalar(); }; conn.Close(); }; } catch (Exception) { } }
public static MediaData Info(int id) { MediaData m = null; //p_info_media try { using (MySqlConnection conn = new MySqlConnection(App.setting.connectString)) { conn.Open(); string query = "`p_info_media`"; using (MySqlCommand cmd = new MySqlCommand(query, conn)) { cmd.Parameters.Add(new MySqlParameter("@_media_id", MySqlDbType.Int32, 100) { Direction = System.Data.ParameterDirection.Input, Value = id }); cmd.CommandType = System.Data.CommandType.StoredProcedure; var tmp = cmd.ExecuteScalar(); if (Convert.ToInt32(tmp) > 0) { using (MySqlDataReader reader = cmd.ExecuteReader()) { m = reader.toMedia(); } } }; conn.Close(); }; } catch (Exception) { } return(m); }
public static int Insert(MediaData m) { int result = -1; //p_insert_media try { using (MySqlConnection conn = new MySqlConnection(App.setting.connectString)) { conn.Open(); string query = "`p_insert_media`"; using (MySqlCommand cmd = new MySqlCommand(query, conn)) { cmd.Parameters.Add(new MySqlParameter("@_media_name", MySqlDbType.VarChar, 255) { Direction = System.Data.ParameterDirection.Input, Value = m.Name }); cmd.Parameters.Add(new MySqlParameter("@_media_url", MySqlDbType.VarChar, 255) { Direction = System.Data.ParameterDirection.Input, Value = m.Url }); cmd.Parameters.Add(new MySqlParameter("@_media_type", MySqlDbType.Int32) { Direction = System.Data.ParameterDirection.Input, Value = m.Type }); cmd.Parameters.Add(new MySqlParameter("@_media_comment", MySqlDbType.Text) { Direction = System.Data.ParameterDirection.Input, Value = m.Comment }); cmd.Parameters.Add(new MySqlParameter("@_media_size", MySqlDbType.VarChar, 100) { Direction = System.Data.ParameterDirection.Input, Value = m.FileSize }); cmd.Parameters.Add(new MySqlParameter("@_media_duration", MySqlDbType.VarChar, 100) { Direction = System.Data.ParameterDirection.Input, Value = m.Duration }); cmd.Parameters.Add(new MySqlParameter("@_media_user", MySqlDbType.Int32) { Direction = System.Data.ParameterDirection.Input, Value = m.User_ID }); cmd.Parameters.Add(new MySqlParameter("@_media_id", MySqlDbType.Int32) { Direction = System.Data.ParameterDirection.Output, Value = 0 }); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.ExecuteScalar(); result = Convert.ToInt32(cmd.Parameters["@_media_id"].Value); }; conn.Close(); }; } catch (Exception) { } return(result); }
private bool? checkFile(MediaData m) { if (m == null) return null; if (m.LocalFile != null && m.TypeMedia.Code.ToUpper() == "FILE" && (!m.LocalFile.Exists || m.LocalFile.toMD5() != m.MD5)) return false; return true; }
public static MediaData toMedia(this MySqlDataReader reader) { if (reader.HasRows) { MediaData m = new MediaData(); while (reader.Read()) { if (!reader.IsDBNull(0)) { m.ID = reader.GetInt32(Define.media_id); m.Name = reader.GetString(Define.media_name); m.Url = reader.GetString(Define.media_url); m.Type = reader.GetInt32(Define.media_type); m.FileSize = reader.GetString(Define.media_size); try { m.MD5 = reader.GetString(Define.media_md5); } catch (Exception) { } try { m.FileSize = reader.GetString(Define.media_size); } catch (Exception) { } try { m.Duration = reader.GetString(Define.media_duration); } catch (Exception) { } try { m.Comment = reader.GetString(Define.media_comment); } catch (Exception) { } m.Status = reader.GetBoolean(Define.media_status); m.User_ID = reader.GetInt32(Define.media_user); m.Time = reader.GetDateTime(Define.media_time); } } return m; } return null; }