SHARE
TWEET

Untitled

a guest Jul 23rd, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5.  
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. using System.Configuration;
  9.  
  10. /// <summary>
  11. /// Summary description for Form
  12. /// </summary>
  13. public class Form
  14. {
  15.     string _connStr = ConfigurationManager.ConnectionStrings["formContext"].ConnectionString;
  16.     private string _Iden_Form_ID;
  17.     private string _Age;
  18.     private string _CurrentHeight;
  19.     private string _CurrentWeight;
  20.     private string _WorkoutGoals;
  21.     public Form()
  22.     {
  23.         this.Iden_Form_ID = null;
  24.         this.Age = null;
  25.         this.Current_Height = null;
  26.         this.Current_Weight = null;
  27.         this.Workout_Goals = null;
  28.     }
  29.  
  30.     public Form(string p_Age, string p_CurrentHeight, string p_CurrentWeight, string p_WorkoutGoals)
  31.     {
  32.         this.Age = p_Age;
  33.         this.Current_Height = p_CurrentHeight;
  34.         this.Current_Weight = p_CurrentWeight;
  35.         this.Workout_Goals = p_WorkoutGoals;
  36.     }
  37.  
  38.     public string Iden_Form_ID
  39.     {
  40.         get { return _Iden_Form_ID; }
  41.         set { _Iden_Form_ID = value; }
  42.     }
  43.     public string Age
  44.     {
  45.         get { return _Age; }
  46.         set { _Age = value; }
  47.     }
  48.     public string Current_Height
  49.     {
  50.         get { return _CurrentHeight; }
  51.         set { _CurrentHeight = value;  }
  52.     }
  53.     public string Current_Weight
  54.     {
  55.         get { return _CurrentWeight; }
  56.         set { _CurrentWeight = value; }
  57.     }
  58.     public string Workout_Goals
  59.     {
  60.         get { return _WorkoutGoals; }
  61.         set { _WorkoutGoals = value; }
  62.     }
  63.  
  64.     public List<Form> getallData()
  65.     {
  66.         List<Form> formlist = new List<Form>();
  67.         string age, currentHeight, currentWeight, workoutGoals;
  68.  
  69.         string queryStr = "Select * FROM [Forms] Order By Iden_Form_ID";
  70.  
  71.         SqlConnection conn = new SqlConnection(_connStr);
  72.         SqlCommand cmd = new SqlCommand(queryStr, conn);
  73.         conn.Open();
  74.         SqlDataReader dr = cmd.ExecuteReader();
  75.  
  76.         while (dr.Read())
  77.         {
  78.             age = dr["Age"].ToString();
  79.             currentHeight = dr["Current_Height"].ToString();
  80.             currentWeight = dr["Current_Weight"].ToString();
  81.             workoutGoals = dr["Workout_Goals"].ToString();
  82.  
  83.             Form form = new Form(age, currentHeight, currentWeight, workoutGoals);
  84.             formlist.Add(form);
  85.         }
  86.         conn.Close();
  87.         dr.Close();
  88.         dr.Dispose();
  89.  
  90.         return formlist;
  91.     }
  92.     public int FormInsert()
  93.     {
  94.         int result = 0;
  95.         string formStr = "INSERT INTO [Forms](Age, Current_Height, Current_Weight, Workout_Goals)" +
  96.             "values(@Age, @Current_Height, @Current_Weight, @Workout_Goals)";
  97.  
  98.         SqlConnection conn = new SqlConnection(_connStr);
  99.         SqlCommand cmd = new SqlCommand(formStr, conn);
  100.         cmd.Parameters.AddWithValue("@Age", this.Age);
  101.         cmd.Parameters.AddWithValue("@Current_Height", this.Current_Height);
  102.         cmd.Parameters.AddWithValue("@Current_Weight", this.Current_Weight);
  103.         cmd.Parameters.AddWithValue("@Workout_Goals", this.Workout_Goals);
  104.        
  105.         conn.Open();
  106.         result += cmd.ExecuteNonQuery();
  107.         conn.Close();
  108.        
  109.         //result += 1;
  110.         return result;
  111.     }
  112. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top