protected void bManualCalc_Click(object sender, EventArgs e) { Sample s = new Sample(); s.PopulationMean = double.Parse(tbPopMean.Text); double total = 0.0; double variance = 0.0; int sampsize = 0; List <double> calcVar = new List <double>(); // Build the sample from user input foreach (string sNum in tbEnterObs.Text.Split(new char[] { ',' })) { double num = double.Parse(sNum); calcVar.Add(num); total += num; sampsize++; } s.SampleSize = sampsize; s.SampleMean = total / sampsize; for (int i = 0; i < calcVar.Count; i++) { variance += (calcVar[i] - s.SampleMean) * (calcVar[i] - s.PopulationMean); } s.SampleStDev = Math.Sqrt(variance); // Calculate the Z score for this sample ZStat z = new ZStat(); z.Alpha = double.Parse(rbAlphaLevel.SelectedValue.ToString()); z.TwoTailed = bool.Parse(rbTwoTailed.SelectedValue.ToString()); if (z.Alpha == 0.05 && z.TwoTailed == true) { z.CriticalZ = 1.960; } else if (z.Alpha == 0.05 && z.TwoTailed == false) { z.CriticalZ = 1.645; } else if (z.Alpha == 0.01) { z.CriticalZ = 2.326; } z.ObservedZ = (s.SampleMean - s.PopulationMean) / s.SampleStDev; }
// A function that inserts a User into the database. public void InsertZ(ZStat newZStat) { // Declare a new variable. Variable name is ‘sSQL’. Datatype is ‘string’. string sSQL = ""; // Define the value for the ‘sSQL’ string variable. // Notice that this text is a SQL Query. sSQL += " INSERT INTO [ZStat] "; // More columns will need to be added, depending on how many columns you have in your User table. // In this line, you need ALL the columns from your User table. // The word ‘Password’ is in brackets because it is a reserved word in SQL. // We are hijacking that word and using it for our own purposes, so we need to put it in brackets. // Normally, SQL would try to interpret the word 'Password' differently than how we're using it. sSQL += " (CriticalZ, ObservedZ, Alpha, TwoTailed) "; sSQL += " Values "; // The ‘@’ sign is a SQL Variable. It is connected to a SqlParameter (below). // This line needs to exactly match the list of columns in the User table. sSQL += " (@CriticalZ, @ObservedZ, @Alpha, @TwoTailed) "; // Declare a new variable. Variable name is ‘sqlcomm’. Datatype is ‘SqlCommand’. SqlCommand sqlcomm = new SqlCommand(); // Assign a value to the CommandText property. sqlcomm.CommandText = sSQL; // This SqlParameter constructor takes two arguments as input values. // Argument One: SQL Variable Name // Argument Two: Variable Value // The SqlParameter handles the declaration of the actual SQL Parameter in the T-SQL. SqlParameter sqlparam = new SqlParameter("CriticalZ", newZStat.CriticalZ); sqlcomm.Parameters.Add(sqlparam); // Notice that there is one ‘SqlParameter’ variable for each variable used in the SQL Query // More SqlParameter variables will need to be added for additional SQL variables. sqlparam = new SqlParameter("ObservedZ", newZStat.ObservedZ); sqlcomm.Parameters.Add(sqlparam); sqlparam = new SqlParameter("Alpha", newZStat.Alpha); sqlcomm.Parameters.Add(sqlparam); sqlparam = new SqlParameter("TwoTailed", newZStat.TwoTailed); sqlcomm.Parameters.Add(sqlparam); // Execute the query. ExecNonQuery(sqlcomm); }
// User enters sample size, population mean, sample mean, sample stdev protected void bAutoCalc_Click(object sender, EventArgs e) { Sample s = new Sample(); s.SampleSize = int.Parse(tbSampleSizeA.Text); s.PopulationMean = double.Parse(tbPopMean.Text); s.SampleMean = double.Parse(tbMean.Text); s.SampleStDev = double.Parse(tbStdDev.Text); ZStat z = new ZStat(); z.Alpha = double.Parse(rbAlphaLevel.SelectedValue.ToString()); z.TwoTailed = bool.Parse(rbTwoTailed.SelectedValue.ToString()); if (z.Alpha == 0.05 && z.TwoTailed == true) { z.CriticalZ = 1.960; } else if (z.Alpha == 0.05 && z.TwoTailed == false) { z.CriticalZ = 1.645; } else if (z.Alpha == 0.01) { z.CriticalZ = 2.326; } z.ObservedZ = (s.SampleMean - s.PopulationMean) / s.SampleStDev; autoAlpha.Text = z.Alpha.ToString(); autoTwoTailed.Text = z.TwoTailed.ToString(); autoCriticalZ.Text = z.CriticalZ.ToString(); autoObservedZ.Text = z.ObservedZ.ToString(); panAutoZ.Visible = true; ZStatisticController con = new ZStatisticController(ConfigurationManager.ConnectionStrings["DBInformation"].ToString()); con.InsertSample(s); con.InsertZ(z); }
public void InsertZ(ZStat z) { ZStatDataAccess zda = new ZStatDataAccess(SqlConConnectionString); zda.InsertZ(z); }