コード例 #1
0
        public void CreateWLC(WLCDAO _WLCCreate)
        {
            WLCDAO _CreateUser = new WLCDAO();

            try
            {
                using (SqlConnection _connection = new SqlConnection(connectionstring))
                {
                    using (SqlCommand _command = new SqlCommand("sp_CreateWLC", _connection))
                    {
                        _command.CommandType = CommandType.StoredProcedure;
                        _command.Parameters.AddWithValue("@Gender", _WLCCreate.Gender);
                        _command.Parameters.AddWithValue("@Age", _WLCCreate.Age);
                        _command.Parameters.AddWithValue("@Height", _WLCCreate.Height);
                        _command.Parameters.AddWithValue("@Weight", _WLCCreate.Weight);
                        _command.Parameters.AddWithValue("@Goal", _WLCCreate.Goal);
                        _command.Parameters.AddWithValue("@GoalTime", _WLCCreate.GoalTime);
                        _command.Parameters.AddWithValue("@User_ID", _WLCCreate.User_ID);
                        _command.Parameters.AddWithValue("@Result", _WLCCreate.Result);

                        _connection.Open();
                        _command.ExecuteNonQuery();


                        _connection.Close();
                        _connection.Dispose();
                    }
                }
            }
            catch (Exception error)
            {
                Error_Logger log = new Error_Logger();
                log.LogError(error);
            }
        }
コード例 #2
0
        public WLCDAO GetWLCByUser_ID(int User_ID)
        {
            WLCDAO _WLCToGet = new WLCDAO();

            try
            {  //esablishing the connection for the database
                using (SqlConnection _connection = new SqlConnection(connectionstring))

                {   //establishing the command to pass to the database and defining the command
                    using (SqlCommand _command = new SqlCommand("sp_GetWLCByUser_ID", _connection))
                    {
                        //this specifies what type of command is being used
                        _command.CommandType = CommandType.StoredProcedure;
                        //here is where values are going to be passed to the command
                        _command.Parameters.AddWithValue("@User_ID", User_ID);
                        //here is where the connection is open
                        _connection.Open();
                        //this executes the command
                        _command.ExecuteNonQuery();



                        using (SqlDataReader _reader = _command.ExecuteReader())
                        {
                            //loop through the dataset or command and write each element to the _playerToList using the player object class
                            while (_reader.Read())
                            {
                                _WLCToGet.Gender   = _reader.GetString(0);
                                _WLCToGet.Age      = _reader.GetInt32(1);
                                _WLCToGet.Height   = _reader.GetDecimal(2);
                                _WLCToGet.Weight   = _reader.GetDecimal(3);
                                _WLCToGet.Goal     = _reader.GetDecimal(4);
                                _WLCToGet.GoalTime = _reader.GetDecimal(5);
                                _WLCToGet.User_ID  = _reader.GetInt32(6);
                                _WLCToGet.ID       = _reader.GetInt32(7);
                            }
                        }
                    }
                }
            }
            catch (Exception error)
            {
                Error_Logger log = new Error_Logger();
                log.LogError(error);
            }
            return(_WLCToGet);
        }
コード例 #3
0
ファイル: Mapper.cs プロジェクト: aravinda-kumar/HealthStats
        public WLC Map(WLCDAO _CreateListToMap)
        {
            WLC _WLCToCreate = new WLC()
            {
                Gender   = _CreateListToMap.Gender,
                Age      = _CreateListToMap.Age,
                Height   = _CreateListToMap.Height,
                Weight   = _CreateListToMap.Weight,
                Goal     = _CreateListToMap.Goal,
                GoalTime = _CreateListToMap.GoalTime,
                User_ID  = _CreateListToMap.User_ID,
                ID       = _CreateListToMap.ID,
                Result   = _CreateListToMap.Result,
            };

            return(_WLCToCreate);
        }
コード例 #4
0
        public List <WLCDAO> ViewWLC()
        {
            List <WLCDAO> _WLCList = new List <WLCDAO>();

            try
            {  //esablishing the connection for the database
                using (SqlConnection _connection = new SqlConnection(connectionstring))

                {   //establishing the command to pass to the database and defining the command
                    using (SqlCommand _command = new SqlCommand("sp_ViewWLC", _connection))
                    {
                        _command.CommandType = CommandType.StoredProcedure;
                        //connect to the database
                        _connection.Open();
                        //open the SQL data reader
                        using (SqlDataReader _reader = _command.ExecuteReader())
                        {
                            //loop through the dataset or command and write each element to the _playerToList using the player object class
                            while (_reader.Read())
                            {
                                WLCDAO _userToList = new WLCDAO()
                                {
                                    Gender   = _reader.GetString(0),
                                    Age      = _reader.GetInt32(1),
                                    Height   = _reader.GetDecimal(2),
                                    Weight   = _reader.GetDecimal(3),
                                    Goal     = _reader.GetDecimal(4),
                                    GoalTime = _reader.GetDecimal(5),
                                    User_ID  = _reader.GetInt32(6),
                                    ID       = _reader.GetInt32(7),
                                    Result   = _reader.GetDecimal(8),
                                };
                                _WLCList.Add(_userToList);
                            }
                        }
                    }
                }
            }
            catch (Exception error)
            {
                Error_Logger log = new Error_Logger();
                log.LogError(error);
            }
            return(_WLCList);
        }
コード例 #5
0
        public bool UpdateWLC(WLCDAO WLCToUpdate)
        {
            bool success = false;

            try
            {
                using (SqlConnection _connection = new SqlConnection(connectionstring))
                {
                    using (SqlCommand _command = new SqlCommand("sp_UpdateWLC", _connection))
                    {
                        //this specifies what type of command is being used
                        _command.CommandType = CommandType.StoredProcedure;
                        //here is where values are going to be passed to the command
                        _command.Parameters.AddWithValue("@Gender", WLCToUpdate.Gender);
                        _command.Parameters.AddWithValue("@Age", WLCToUpdate.Age);
                        _command.Parameters.AddWithValue("@Height", WLCToUpdate.Height);
                        _command.Parameters.AddWithValue("@Weight", WLCToUpdate.Weight);
                        _command.Parameters.AddWithValue("@Goal", WLCToUpdate.Goal);
                        _command.Parameters.AddWithValue("GoalTime", WLCToUpdate.GoalTime);
                        _command.Parameters.AddWithValue("@Result", WLCToUpdate.Result);

                        //here is where the connection is open
                        _connection.Open();
                        //this executes the command
                        _command.ExecuteNonQuery();
                        success = true;
                        _connection.Close();
                    }
                }
            }
            catch (Exception error)
            {
                Error_Logger log = new Error_Logger();
                log.LogError(error);
            }

            return(success);
        }
コード例 #6
0
ファイル: Mapper.cs プロジェクト: aravinda-kumar/HealthStats
        public List <WLCDAO> Map(List <WLC> _WLCListToMap)
        {
            List <WLCDAO> _WLCListToReturn = new List <WLCDAO>();

            foreach (WLC _WLCToMap in _WLCListToMap)
            {
                WLCDAO _WLCToView = new WLCDAO()
                {
                    Gender   = _WLCToMap.Gender,
                    Age      = _WLCToMap.Age,
                    Height   = _WLCToMap.Height,
                    Weight   = _WLCToMap.Weight,
                    Goal     = _WLCToMap.Goal,
                    GoalTime = _WLCToMap.GoalTime,
                    User_ID  = _WLCToMap.User_ID,
                    ID       = _WLCToMap.ID,
                    Result   = _WLCToMap.Result,
                };

                _WLCListToReturn.Add(_WLCToView);
            }
            return(_WLCListToReturn);
        }