/// <summary> /// Metoda pobierająca z bazy danych MySQL wszystkie rekordy z tabeli i przypisująca je do podanej tabeli (tableActions). /// </summary> /// <param name="dbClient"></param> /// <param name="tableActions"></param> /// <returns></returns> public static bool GetAll(Database.Client dbClient, /*ref*/ List <Database.Structure.Tables.Actions> tableActions) { if (dbClient == null || dbClient.Connection() == null) { return(false); } if (!dbClient.OpenConnection()) // próba nawiązania połączenia z bazą { return(false); } try { MySqlDataAdapter mySqlDa = new MySqlDataAdapter("ActionsGetAll", dbClient.Connection()); mySqlDa.SelectCommand.CommandType = System.Data.CommandType.StoredProcedure; System.Data.DataTable dtActions = new System.Data.DataTable(); mySqlDa.Fill(dtActions); tableActions.Clear(); for (int i = 0; i < dtActions.Rows.Count; i++) { Database.Structure.Tables.Actions tableItem = new Database.Structure.Tables.Actions(); int j = 0; tableItem.Idactions = (int)dtActions.Rows[i].ItemArray[j++]; tableItem.Idtype_of_event = (int)dtActions.Rows[i].ItemArray[j++]; tableItem.Idproduct = (int)dtActions.Rows[i].ItemArray[j++]; tableItem.Operator = (int)dtActions.Rows[i].ItemArray[j++]; tableItem.Client = (int)dtActions.Rows[i].ItemArray[j++]; tableItem.Quantity = OperationHelper.PrepareInt32Value(dtActions.Rows[i].ItemArray[j++].ToString()); tableItem.Suggest_date = OperationHelper.PrepareDateTimeValue(dtActions.Rows[i].ItemArray[j++].ToString()); tableItem.Idactionstart = OperationHelper.PrepareInt32Value(dtActions.Rows[i].ItemArray[j++].ToString()); tableItem.Date_added = OperationHelper.PrepareDateTimeValue(dtActions.Rows[i].ItemArray[j++].ToString()); tableItem.Actionscol = dtActions.Rows[i].ItemArray[j].ToString(); tableActions.Add(tableItem); } return(true); } catch (MySqlException ex) { Trace.WriteLine(ex.Message); return(false); } // pamiętać, aby zamykać połączenie }
/// <summary> /// Metoda pobierająca z bazy danych MySQL pojedynczy rekord o podanym identyfikatorze (IdActions) i przypisująca go do podanej strukturze tabeli (tableActionsItem). /// </summary> /// <param name="dbClient"></param> /// <param name="IdActions"></param> /// <param name="tableActionsItem"></param> /// <returns></returns> public static bool Get(Database.Client dbClient, int IdActions, Database.Structure.Tables.Actions tableActionsItem) { if (dbClient == null || dbClient.Connection() == null) { return(false); } if (!dbClient.OpenConnection()) // próba nawiązania połączenia z bazą { return(false); } try { MySqlCommand mySqlCmd = new MySqlCommand("ActionsGet", dbClient.Connection()); mySqlCmd.CommandType = System.Data.CommandType.StoredProcedure; mySqlCmd.Parameters.AddWithValue("_IdActions", IdActions); mySqlCmd.ExecuteNonQuery(); MySqlDataReader reader = mySqlCmd.ExecuteReader(); if (reader.Read()) { int i = 0; tableActionsItem.Idactions = (int)reader[i++]; tableActionsItem.Idtype_of_event = (int)reader[i++]; tableActionsItem.Idproduct = (int)reader[i++]; tableActionsItem.Operator = (int)reader[i++]; tableActionsItem.Client = (int)reader[i++]; tableActionsItem.Quantity = OperationHelper.PrepareInt32Value(reader[i++].ToString()); tableActionsItem.Suggest_date = OperationHelper.PrepareDateTimeValue(reader[i++].ToString()); tableActionsItem.Idactionstart = OperationHelper.PrepareInt32Value(reader[i++].ToString()); tableActionsItem.Date_added = OperationHelper.PrepareDateTimeValue(reader[i++].ToString()); tableActionsItem.Actionscol = reader[i].ToString(); reader.Close(); } return(true); } catch (MySqlException ex) { Trace.WriteLine(ex.Message); return(false); } // pamiętać, aby zamykać połączenie }