Ejemplo n.º 1
0
        /// <summary>
        /// Updates data of body user values based on selected date
        /// </summary>
        public static bool UpdateRecord(ProgressModel progressModel, DateTime calendarDate)
        {
            try
            {
                // get connection string from Connections Helper Class
                SqlConnection conn = new SqlConnection(Connections.ConnectionString);

                string sql = "UPDATE dbo.UserBodyValues " +
                             "SET Weight=@Weight,Neck=@Neck, Chest=@Chest, Stomach=@Stomach, Waist=@Waist, Hips=@Hips, Thigh=@Thigh, Calf=@Calf, Biceps=@Biceps" +
                             " WHERE UserId=@UserId AND DateAdded=@DateAdded";

                conn.Open();

                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.Add("@UserId", SqlDbType.Int).Value         = progressModel.UserId;
                cmd.Parameters.Add("@Weight", SqlDbType.Decimal).Value     = progressModel.Weight;
                cmd.Parameters.Add("@Neck", SqlDbType.Decimal).Value       = progressModel.Neck;
                cmd.Parameters.Add("@Chest", SqlDbType.Decimal).Value      = progressModel.Chest;
                cmd.Parameters.Add("@Stomach", SqlDbType.Decimal).Value    = progressModel.Stomach;
                cmd.Parameters.Add("@Waist", SqlDbType.Decimal).Value      = progressModel.Waist;
                cmd.Parameters.Add("@Hips", SqlDbType.Decimal).Value       = progressModel.Hips;
                cmd.Parameters.Add("@Thigh", SqlDbType.Decimal).Value      = progressModel.Thigh;
                cmd.Parameters.Add("@Calf", SqlDbType.Decimal).Value       = progressModel.Calf;
                cmd.Parameters.Add("@Biceps", SqlDbType.Decimal).Value     = progressModel.Biceps;
                cmd.Parameters.Add("@DateAdded", SqlDbType.DateTime).Value = calendarDate;

                int result = cmd.ExecuteNonQuery();

                if (result > 0)
                {
                    MessageBox.Show("Data Updated!");
                    return(true);
                }

                else
                {
                    return(false);
                }
            }

            catch (SqlException ex)
            {
                string errorMessage = $"Error: {ex}";
                MessageBox.Show(errorMessage);
                return(true);
            }
        }
Ejemplo n.º 2
0
        public static ProgressModel GetUserProgress(int userId, DateTime calendarDate)
        {
            var progress = new ProgressModel();

            try
            {
                SqlConnection conn = new SqlConnection(Connections.ConnectionString);
                string        sql  = "SELECT * FROM dbo.UserBodyValues WHERE UserId=@UserId AND DateAdded=@DateAdded";

                conn.Open();

                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.Add("@UserId", SqlDbType.Int).Value         = userId;
                cmd.Parameters.Add("@DateAdded", SqlDbType.DateTime).Value = calendarDate;

                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    // if the result set is not NULL
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            progress.Weight  = reader.GetDecimal(4);
                            progress.Neck    = reader.GetDecimal(5);
                            progress.Chest   = reader.GetDecimal(6);
                            progress.Stomach = reader.GetDecimal(7);
                            progress.Waist   = reader.GetDecimal(8);
                            progress.Hips    = reader.GetDecimal(9);
                            progress.Thigh   = reader.GetDecimal(10);
                            progress.Calf    = reader.GetDecimal(11);
                            progress.Biceps  = reader.GetDecimal(12);
                        }
                    }
                }

                conn.Close();
            }

            catch (SqlException ex)
            {
                string errorMessage = $"Error: {ex}";
                MessageBox.Show(errorMessage);
            }

            return(progress);
        }
Ejemplo n.º 3
0
        public static bool AddNewRecord(ProgressModel progress)
        {
            try
            {
                // get connection string from Connections Helper Class
                SqlConnection conn = new SqlConnection(Connections.ConnectionString);

                string sql = "INSERT INTO dbo.UserBodyValues (UserId,DateAdded,Weight,Neck,Chest,Stomach,Waist,Hips,Thigh,Calf,Biceps) values (@UserId,@DateAdded,@Weight,@Neck,@Chest,@Stomach,@Waist,@Hips,@Thigh,@Calf,@Biceps)";


                conn.Open();

                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.Add("@UserId", SqlDbType.Int).Value         = progress.UserId;
                cmd.Parameters.Add("@Weight", SqlDbType.Decimal).Value     = progress.Weight;
                cmd.Parameters.Add("@Neck", SqlDbType.Decimal).Value       = progress.Neck;
                cmd.Parameters.Add("@Chest", SqlDbType.Decimal).Value      = progress.Chest;
                cmd.Parameters.Add("@Stomach", SqlDbType.Decimal).Value    = progress.Stomach;
                cmd.Parameters.Add("@Waist", SqlDbType.Decimal).Value      = progress.Waist;
                cmd.Parameters.Add("@Hips", SqlDbType.Decimal).Value       = progress.Hips;
                cmd.Parameters.Add("@Thigh", SqlDbType.Decimal).Value      = progress.Thigh;
                cmd.Parameters.Add("@Calf", SqlDbType.Decimal).Value       = progress.Calf;
                cmd.Parameters.Add("@Biceps", SqlDbType.Decimal).Value     = progress.Biceps;
                cmd.Parameters.Add("@DateAdded", SqlDbType.DateTime).Value = progress.DateAdded;


                int result = cmd.ExecuteNonQuery();

                if (result > 0)
                {
                    return(true);
                }
            }

            catch (SqlException ex)
            {
                string errorMessage = $"Error: {ex}";
                MessageBox.Show(errorMessage);
                return(false);
            }

            return(false);
        }
Ejemplo n.º 4
0
 public ProgressViewModel()
 {
     ComboBoxChoices = new ObservableCollection <ComboBoxHistory>();
     ComboBoxChoices.Add(new ComboBoxHistory()
     {
         Symbol = "-----"
     });
     ComboBoxChoices.Add(new ComboBoxHistory()
     {
         Symbol = "Add new record"
     });
     ComboBoxChoices.Add(new ComboBoxHistory()
     {
         Symbol = "Edit Record"
     });
     ComboBoxChoices.Add(new ComboBoxHistory()
     {
         Symbol = "View Values"
     });
     SelectedItem    = ComboBoxChoices[0];
     CurrentProgress = new ProgressModel();
 }
Ejemplo n.º 5
0
        public void AddRecord()
        {
            var progress = new ProgressModel();

            progress           = CurrentProgress;
            progress.UserId    = UserId;
            progress.DateAdded = CalendarDate;

            bool isAdded = Queries.AddNewRecord(progress);

            if (isAdded)
            {
                MessageBox.Show("Record Added!");

                TextBlockVisibility = Visibility.Visible;
                EditBoxVisibility   = Visibility.Hidden;
                AddButtonVisibility = Visibility.Hidden;
            }

            else
            {
                MessageBox.Show("Record Not Added!");
            }
        }