private void btnSave_Click(object sender, EventArgs e)
        {
            DrawingDateBO drawingDateToSave = new DrawingDateBO();
            drawingDateToSave.DrawingDate = Convert.ToDateTime(txtDrawingDate.Text);
            int returnedDrawingDateId = DrawingDateManager.Save(_DrawingDateId, _GameId, drawingDateToSave);

            int i = 0;
            foreach(Control ctrl in panelWinningNumbers.Controls)
            {
                if (ctrl is TextBox)
                {
                    if (_WinningNumbersId == 0)
                    {
                        WinningNumbers winningNumberToSave = new WinningNumbers();
                        winningNumberToSave.NumberValue = Convert.ToInt32(ctrl.Text);
                        WinningNumbersManager.Save(_WinningNumbersId, returnedDrawingDateId, winningNumberToSave);
                    }
                    else
                    {
                        WinningNumbers winningNumberToSave = new WinningNumbers();
                        winningNumberToSave.NumberValue = Convert.ToInt32(ctrl.Text);
                        int winningNumbersId = Convert.ToInt32(ctrl.Name);
                        WinningNumbersManager.Save(winningNumbersId, returnedDrawingDateId, winningNumberToSave);
                    }
                }
                i++;
            }

            base.Close();
        }
        /// <summary>
        /// Initializes a new instance of the WinningNumbers class and fills it with the data from the IDataRecord
        /// </summary>
        /// <param name="myDataRecord"></param>
        /// <returns></returns>
        private static WinningNumbers FillDataRecord(IDataRecord myDataRecord)
        {
            WinningNumbers myWinningNumsObject = new WinningNumbers();

            //myWinningNumsObject.DrawingDateId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("DrawingDateId"));
            //myWinningNumsObject.GameId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("GameId"));
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("WinningNumbersId")))
            {
                myWinningNumsObject.WinningNumbersId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("WinningNumbersId"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("NumberValue")))
            {
                myWinningNumsObject.NumberValue = myDataRecord.GetInt32(myDataRecord.GetOrdinal("NumberValue"));
            }
            return myWinningNumsObject;
        }
 public static int Save(int winningNumbersId, int drawingDateId, WinningNumbers winningNumberToSave)
 {
     int returnedValue = WinningNumbersDAL.SaveNewNumber(winningNumbersId, drawingDateId, winningNumberToSave);
     return returnedValue;
 }
        public static int SaveNewNumber(int winningNumbersId, int drawingDateId, WinningNumbers winningNumbersToSave)
        {
            ExecuteTypeEnum queryId = ExecuteTypeEnum.InsertItem;
            int result = 0;

            if (winningNumbersId > 0)
            {
                queryId = ExecuteTypeEnum.UpdateItem;
            }

            using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("usp_ExecuteWinningNumbers", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

                    myCommand.Parameters.AddWithValue("@QueryId", queryId);
                    myCommand.Parameters.AddWithValue("@DrawingDateId", drawingDateId);
                    myCommand.Parameters.AddWithValue("@WinningNumbersId", winningNumbersId);

                    if (winningNumbersToSave.NumberValue != null)
                    {
                        myCommand.Parameters.AddWithValue("@NumberValue", winningNumbersToSave.NumberValue);
                    }

                    //add return output parameter to command object
                    myCommand.Parameters.Add(HelperDAL.GetReturnParameterInt("ReturnValue"));

                    myConnection.Open();
                    myCommand.ExecuteNonQuery();

                    //Get return value from stored procedure and return Id
                    result = (int)myCommand.Parameters["@ReturnValue"].Value;
                }
                myConnection.Close();
            }
            return result;
        }