public static void NewRecord(int id, int txtQuantity, string type) { try { var insertRecord = "INSERT INTO [FlemidraDB].[dbo].[Records] ([FlemidraDB].[dbo].[Records].[type], [FlemidraDB].[dbo].[Records].[time], [FlemidraDB].[dbo].[Records].[id_Product], [FlemidraDB].[dbo].[Records].[quantity], [FlemidraDB].[dbo].[Records].[id_Users]) VALUES (@type, @time, @id_Prod, @quantity, @id_User )"; var con = new SqlConnection(GlobalVariables.GetConString()); con.Open(); SqlCommand sqlCommand = new SqlCommand(); sqlCommand.Parameters.AddWithValue("@type", type); sqlCommand.Parameters.AddWithValue("@time", DateTime.Now.ToString("yyyy-MM-dd")); sqlCommand.Parameters.AddWithValue("@id_Prod", id); sqlCommand.Parameters.AddWithValue("@quantity", txtQuantity); sqlCommand.Parameters.AddWithValue("@id_User", GlobalVariables.GetActualUser()); sqlCommand.CommandText = insertRecord; sqlCommand.CommandType = CommandType.Text; sqlCommand.Connection = con; sqlCommand.ExecuteNonQuery(); //MessageBox.Show("Record exitoso."); con.Close(); } catch (Exception e) { MessageBox.Show("Error 08: al agregar una entrada al registro de la base de datos. " + e); } }
public static string UserLevel() { try { var select = "SELECT [FlemidraDB].[dbo].[Users].type FROM [FlemidraDB].[dbo].[Users] WHERE [FlemidraDB].[dbo].[Users].[id] =@id"; var con = new SqlConnection(GlobalVariables.GetConString()); con.Open(); SqlCommand sqlCommand = new SqlCommand(); sqlCommand.Parameters.AddWithValue("@id", GlobalVariables.GetActualUser()); sqlCommand.CommandText = select; sqlCommand.Connection = con; sqlCommand.CommandType = CommandType.Text; var resultQueryId = sqlCommand.ExecuteScalar(); con.Close(); return(resultQueryId.ToString()); } catch (Exception e) { MessageBox.Show("Error 10: al identificador tipo de usuario. " + e); return(null); } }