Timing in Ticket System - c#

I have nearly finished a project I've been working on for over three months. This is my first program I've ever made, so it may not be the cleanest code but for the most part works. The only issue I'm having now is getting the times to line up between specific times (In this instance 8am and 3pm). I am getting times outside of these times instead of inside. My current code is
if (DateTime.Now.AddMinutes(timetoadd).Hour < 8)
{
MessageBox.Show("Too early_Button Pressed");
var now = DateTime.Now;
var today8am = now.AddDays(0).Date.AddHours(8);
double totalHours = (today8am - now).TotalHours;
MessageBox.Show("totalHours=" + totalHours);
double hourstoadd = 0;// = timetoadd / 60;
MessageBox.Show("TTA = " + timetoadd.ToString());
do
{
hourstoadd++;
if (DateTime.Now.AddHours(hourstoadd).Hour == 15)
{
hourstoadd = hourstoadd + 17;
}
timetoadd = timetoadd - 60;
System.Diagnostics.Debug.WriteLine(hourstoadd.ToString());
}
while (timetoadd >= 60);
MessageBox.Show("TTA2 = " + timetoadd.ToString());
do
{
hourstoadd = hourstoadd - 8;
daystoadd++;
if (DateTime.Now.DayOfWeek.ToString() == "Saturday")
{
daystoadd = daystoadd + 2;
}
else if (DateTime.Now.DayOfWeek.ToString() == "Sunday")
{
daystoadd = daystoadd + 1;
}
}
while (hourstoadd > 8);
if (DateTime.Now.AddDays(daystoadd).AddHours(hourstoadd).Date.AddHours(hourstoadd + now.Hour).AddMinutes(timetoadd + now.Minute).DayOfWeek.ToString() == "Saturday")
{
daystoadd = daystoadd + 2;
}
else if (DateTime.Now.AddDays(daystoadd).AddHours(hourstoadd).Date.AddHours(hourstoadd + now.Hour).AddMinutes(timetoadd + now.Minute).DayOfWeek.ToString() == "Sunday")
{
daystoadd = daystoadd + 1;
}
EstimatedCompleteDate = DateTime.Now.AddDays(daystoadd).AddHours(hourstoadd).Date.AddHours(hourstoadd + now.Hour).AddMinutes(timetoadd + now.Minute).ToString();
MessageBox.Show("ETA = " + EstimatedCompleteDate);
}
else if (DateTime.Now.AddMinutes(timetoadd).Hour > 15)
{
MessageBox.Show("Too Late_Button Pressed");
var now = DateTime.Now;
var tomorrow8am = now.AddDays(1).Date.AddHours(8);
double totalHours = (tomorrow8am - now).TotalHours;
MessageBox.Show("totalHours=" + totalHours);
double hourstoadd = 0;// = timetoadd / 60;
MessageBox.Show("TTA = " + timetoadd.ToString());
do
{
hourstoadd++;
if (DateTime.Now.AddHours(hourstoadd).Hour == 15)
{
hourstoadd = hourstoadd + 17;
}
timetoadd = timetoadd - 60;
System.Diagnostics.Debug.WriteLine(hourstoadd.ToString());
}
while (timetoadd >= 60);
MessageBox.Show("TTA2 = " + timetoadd.ToString());
do
{
hourstoadd = hourstoadd - 8;
daystoadd++;
if (DateTime.Now.DayOfWeek.ToString() == "Saturday")
{
daystoadd = daystoadd + 2;
}
else if (DateTime.Now.DayOfWeek.ToString() == "Sunday")
{
daystoadd = daystoadd + 1;
}
}
while (hourstoadd > 8);
if (DateTime.Now.AddDays(daystoadd).AddHours(hourstoadd).Date.AddHours(hourstoadd + now.Hour).AddMinutes(timetoadd + now.Minute).DayOfWeek.ToString() == "Saturday")
{
daystoadd = daystoadd + 2;
}
else if (DateTime.Now.AddDays(daystoadd).AddHours(hourstoadd).Date.AddHours(hourstoadd + now.Hour).AddMinutes(timetoadd + now.Minute).DayOfWeek.ToString() == "Sunday")
{
daystoadd = daystoadd + 1;
}
EstimatedCompleteDate = DateTime.Now.AddDays(daystoadd).AddHours(hourstoadd).Date.AddHours(hourstoadd + now.Hour).AddMinutes(timetoadd + now.Minute).ToString();
MessageBox.Show("ETA = " + EstimatedCompleteDate);
}
else if (DateTime.Now.AddMinutes(timetoadd).Hour <= 15 && DateTime.Now.AddMinutes(timetoadd).Hour >= 8)
{
MessageBox.Show("Regular hours");
var now = DateTime.Now;
var tomorrow8am = now.AddDays(1).Date.AddHours(8);
double totalHours = 0;
MessageBox.Show("totalHours=" + totalHours);
double hourstoadd = 0 + now.Minute;// = timetoadd / 60;
MessageBox.Show("TTA = " + timetoadd.ToString());
do
{
hourstoadd++;
if (DateTime.Now.AddHours(hourstoadd).Hour == 15)
{
hourstoadd = hourstoadd + 17;
}
timetoadd = timetoadd - 60;
System.Diagnostics.Debug.WriteLine(hourstoadd.ToString());
}
while (timetoadd >= 60);
MessageBox.Show("TTA2 = " + timetoadd.ToString());
do
{
hourstoadd = hourstoadd - 8;
daystoadd++;
if (DateTime.Now.DayOfWeek.ToString() == "Saturday")
{
daystoadd = daystoadd + 2;
}
else if (DateTime.Now.DayOfWeek.ToString() == "Sunday")
{
daystoadd = daystoadd + 1;
}
}
while (hourstoadd > 8);
if (DateTime.Now.AddDays(daystoadd).AddHours(hourstoadd).Date.AddHours(hourstoadd + now.Hour).AddMinutes(timetoadd + now.Minute).DayOfWeek.ToString() == "Saturday")
{
daystoadd = daystoadd + 2;
}
else if (DateTime.Now.AddDays(daystoadd).AddHours(hourstoadd).Date.AddHours(hourstoadd + now.Hour).AddMinutes(timetoadd + now.Minute).DayOfWeek.ToString() == "Sunday")
{
daystoadd = daystoadd + 1;
}
EstimatedCompleteDate = DateTime.Now.AddDays(daystoadd).AddHours(hourstoadd).Date.AddHours(hourstoadd + now.Hour).AddMinutes(timetoadd + now.Minute).ToString();
MessageBox.Show("ETA = " + EstimatedCompleteDate);
}
timetoadd = sum + current_ticket_time in minutes.
sum = all previous ticket times.
I am using Messagebox's to provide me a form of immediate feedback.

The other night I was able to get a script that works for exactly what's needed.
var soonh = 0;
var now = DateTime.Now;
var soonm = 0;
double minutestoadd = timetoadd;
int hourstoadd = 0;
if (minutestoadd >= 60)
{
do
{
minutestoadd = minutestoadd - 60;
hourstoadd++;
}
while (minutestoadd > 60);
}
soonh = 6 - (Convert.ToInt32(now.Hour));
soonm = 60 - ((Convert.ToInt32(now.Minute)));
if (soonm < 0)
{
var temp = soonm;
soonm = 0;
soonh = soonh - 1;
soonm = 60 + temp;
Console.WriteLine("Sample");
}
double totalmin = soonm + now.Minute + minutestoadd;
if (totalmin >= 60)
{
do
{
if (totalmin >= 60)
{
totalmin = totalmin - 60;
hourstoadd = hourstoadd + 1;
}
}
while (totalmin >= 60);
if (soonh < 0)
{
soonh = 0;
}
int totalhour = soonh + now.Hour + hourstoadd;
int totalday = 0;
bool sample = false;
do
{
if (totalhour >= 8)
{
totalhour = totalhour - 7;
totalday = totalday + 1;
sample = true;
}
}
while (totalhour >= 8);
if (sample == true)
{
totalday = totalday - 1;
}
totalhour = totalhour + 7;
if (totalhour + DateTime.Today.Hour >= 15)
{
totalhour = totalhour - 7;
}
if (DateTime.Today.Date.AddDays(totalday) == DateTime.Today)
{
totalday++;
}
EstimatedCompleteDate = (DateTime.Today.Date.AddDays(totalday).AddHours(totalhour).AddMinutes(totalmin).ToString());
}

Related

C# - Copying Excel to Word using Interop

I want to copy excel to word as a picture without using the clipboard.
The clipboard is too easy for the user to manipulate while the program is running and it sometimes misses items.
How do I do this?
Heres How I handle it now
foreach (Worksheet WS in WB.Worksheets)
{
progresspercent += steps;
worker.ReportProgress(progresspercent);
if (WS.UsedRange.Count > 1 && WS != null)
{
Thread.Sleep(1000);
var height = WS.UsedRange.Height;
var width = WS.UsedRange.Width;
var MaxHeight = ((double)width * 8.5) / 6.5;
var heightRatio= (double)height/MaxHeight;
double TotalHeight = 0;
int RowsSoFar = 0;
int TotalRows = WS.UsedRange.Rows.Count;
int RowStart = 1;
int RowEnd = RowStart + (int)Math.Floor(TotalRows/heightRatio);
if (RowEnd > TotalRows + 1) { RowEnd = TotalRows + 1; }
///Calculate Image sizes and size copy for page
while (TotalRows > RowsSoFar)
{
Range CopyRange = WS.Range["A" + RowStart.ToString() + ":F" + RowEnd.ToString()];
double SelectionHeight = (double)CopyRange.Height;
while (SelectionHeight > MaxHeight )
{
//***************************************//
RowEnd = RowEnd - 1;
CopyRange = WS.Range["A" + RowStart.ToString() + ":F" + RowEnd.ToString()];
SelectionHeight = (double)CopyRange.Height;
}
FullWordDoc.Words.Last.InsertBreak(Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak);
string ContinuedPrompt = "";
if (RowStart!=1) { ContinuedPrompt = " (Continued)"; }
FullWordDoc.Words.Last.InsertAfter(WS.Name + ContinuedPrompt + "\r");
CopyRange.CopyPicture();
FullWordDoc.Words.Last.Paste();
Console.WriteLine(WS.Name);
RowsSoFar = RowsSoFar + RowEnd - RowStart + 1;
RowStart = RowEnd + 1;
RowEnd = RowStart + (int)Math.Floor(TotalRows / heightRatio);
if (RowEnd > TotalRows + 1) { RowEnd = TotalRows + 1; }
}
}
}

How use progress bar for a project that it's calculations is in another project

I have two project: a class library and a winform and all of the calculations is in the class library. now I want to use a progress bar for one of my forms when the user click on Run botton. I tried the below code but the progress bar filled as soon as loading data (about 6000 or more) in datagridview.
Code in Winform project:
private void BtnRun_Click(object sender, EventArgs e)
{
progressBar1.Maximum = TTools.Depth.Count;
progressBar1.Step = 1;
foreach (double doub in TLitho.CalcPercent().Item3)
{
progressBar1.PerformStep();
}
if (TTools.Depth != null)
{
dataGridView1.AllowUserToAddRows = false;
List<double> DolomitePer = TLitho.CalcPercent().Item3;
List<double> Depth = TTools.Depth;
var sourceD = new BindingSource
{
DataSource = Depth
};
for (int i = 0; i < (sourceD.Count); i++)
{
dataGridView1.Rows.Add();
dataGridView1.Rows[i].Cells[0].Value = sourceD[i];
}
var sourcePD = new BindingSource
{
DataSource = DolomitePer
};
for (int i = 0; i < (sourcePD.Count); i++)
{
dataGridView1.Rows.Add();
dataGridView1.Rows[i].Cells[1].Value = sourcePD[i];
}
}
}
code in class library project:
public static Tuple<List<double>, List<double>, List<double>> CalcPercent()
{
for (int j = 0; j < TTools.Depth.Count; j++)
{
MinimumIndexQC.Add(80000);
MinimumIndexQC[j] = lQC[j].IndexOf(lQC[j].Min());
MinimumIndexCD.Add(80000);
MinimumIndexCD[j] = lCD[j].IndexOf(lCD[j].Min());
MinimumIndexQD.Add(80000);
MinimumIndexQD[j] = lQD[j].IndexOf(lQD[j].Min());
CDandND.Add(Math.Abs(lCD[j][MinimumIndexCD[j]] - TPorosity.CalculateNDPorosity()[j]));
QCandND.Add(Math.Abs(lQC[j][MinimumIndexQC[j]] - TPorosity.CalculateNDPorosity()[j]));
QDandND.Add(Math.Abs(lQD[j][MinimumIndexQD[j]] - TPorosity.CalculateNDPorosity()[j]));
if (CDandND[j] < QCandND[j] && CDandND[j] < QDandND[j])
{
DistanceCD.Add((Math.Abs(TPorosity.BulkDensity[j] + (0.0173 * TPorosity.Neutron[j]) - 2.9162) / Math.Sqrt(Math.Pow(0.0173, 2) + 1))
+ (Math.Abs(TPorosity.BulkDensity[j] + (0.0173 * TPorosity.Neutron[j]) - 2.7031) / Math.Sqrt(Math.Pow(0.0173, 2) + 1)));
DolomitePercent.Add((Math.Abs(TPorosity.BulkDensity[j] + (0.0173 * TPorosity.Neutron[j]) - 2.7031) / Math.Sqrt(Math.Pow(0.0173, 2) + 1)) / DistanceCD[j]);
CalcitePercent.Add((Math.Abs(TPorosity.BulkDensity[j] + (0.0173 * TPorosity.Neutron[j]) - 2.9162) / Math.Sqrt(Math.Pow(0.0173, 2) + 1)) / DistanceCD[j]);
QuartzPercent.Add(0);
DistanceQC.Add(0);
DistanceQD.Add(0);
}
else if (QCandND[j] < CDandND[j] && QCandND[j] < QDandND[j])
{
DistanceQC.Add((Math.Abs(TPorosity.BulkDensity[j] + (0.0192 * TPorosity.Neutron[j]) - 2.5818) / Math.Sqrt(Math.Pow(0.0192, 2) + 1))
+ (Math.Abs(TPorosity.BulkDensity[j] + (0.0173 * TPorosity.Neutron[j]) - 2.7031) / Math.Sqrt(Math.Pow(0.0173, 2) + 1)));
QuartzPercent.Add((Math.Abs(TPorosity.BulkDensity[j] + (0.0173 * TPorosity.Neutron[j]) - 2.7031) / Math.Sqrt(Math.Pow(0.0173, 2) + 1)) / DistanceQC[j]);
CalcitePercent.Add((Math.Abs(TPorosity.BulkDensity[j] + (0.0192 * TPorosity.Neutron[j]) - 2.5818) / Math.Sqrt(Math.Pow(0.0192, 2) + 1)) / DistanceQC[j]);
DolomitePercent.Add(0);
DistanceCD.Add(0);
DistanceQD.Add(0);
}
else if (QDandND[j] < CDandND[j] && QDandND[j] < QCandND[j])
{
DistanceQD.Add((Math.Abs(TPorosity.BulkDensity[j] + (0.0192 * TPorosity.Neutron[j]) - 2.5818) / Math.Sqrt(Math.Pow(0.0192, 2) + 1))
+ (Math.Abs(TPorosity.BulkDensity[j] + (0.0173 * TPorosity.Neutron[j]) - 2.9162) / Math.Sqrt(Math.Pow(0.0173, 2) + 1)));
QuartzPercent.Add((Math.Abs(TPorosity.BulkDensity[j] + (0.0173 * TPorosity.Neutron[j]) - 2.9162) / Math.Sqrt(Math.Pow(0.0173, 2) + 1)) / DistanceQD[j]);
DolomitePercent.Add((Math.Abs(TPorosity.BulkDensity[j] + (0.0192 * TPorosity.Neutron[j]) - 2.5818) / Math.Sqrt(Math.Pow(0.0192, 2) + 1)) / DistanceQD[j]);
CalcitePercent.Add(0);
DistanceCD.Add(0);
DistanceQC.Add(0);
}
else
{
DistanceCD.Add(0);
DistanceQC.Add(0);
DistanceQD.Add(0);
DolomitePercent.Add(0);
CalcitePercent.Add(0);
QuartzPercent.Add(0);
}
if (DolomitePercent[j]==0 && CalcitePercent[j]==0 && QuartzPercent[j]==0 && TPorosity.BulkDensity[j] < (-0.0173 * TPorosity.Neutron[j]) + 2.9162)
{
DolomitePercent[j] = 100;
}
if (DolomitePercent[j] == 0 && CalcitePercent[j] == 0 && QuartzPercent[j] == 0 && TPorosity.BulkDensity[j]> 2.5943 * Math.Pow(Math.E, (-0.009 * TPorosity.Neutron[j])))
{
QuartzPercent[j] = 100;
}
}
return Tuple.Create(DolomitePercent, CalcitePercent, QuartzPercent);
}
}
Hope anyone help me.
thank you

TimeTable creation using graph colouring in ASP.net

I am working on an ASP application which is about creating time table (scheduling of classes) for my final semester project. I have used the logic from a basic console application program of graph colouring and incorporated into my project. Though the logic for a console application works as required, I am unable to do the same for my asp project.
try
{
int n = 10, i, j, max = 0, col, ct = 0, rt = 0, m, count = 2, g = 0;
int[][] a = new int[20][];
int[] c = new int[20];
int[] arr = new int[20];
for (int k = 0; k < 20; k++)
{
c[k] = 0;
arr[k] = 0;
a[k] = new int[20];
for (int l = 0; l < 20; l++)
{
a[k][l] = 0;
}
}
string num = null, num1 = "";
string display = "SELECT * FROM tbl_Subjects WHERE USN IN(SELECT USN FROM tbl_Student WHERE Semester='" + DropDownList1.Text + "')";
con.Open();
SqlCommand cmdSql = new SqlCommand(display, con);
SqlDataReader rs;
rs = cmdSql.ExecuteReader();
while (rs.Read())
{
//count1++;
for (int k = 1; k <= n; k++)
{
g = k - 1;
num = rs[k].ToString();
arr[g] = Convert.ToInt32(num);
num1 += arr[g] + " ";
}
num1 += "\n";
for (int k = 0; k < n; k++)
{
for (int l = (k + 1); l < n; l++)
{
if (arr[k] == 1 && arr[l] == 1)
{
a[k][l] = 1;
//a[l][k] = 1;
}
}
}
}
rs.Close();
TextBox3.Text = num1;
num1 = "";
for (int k = 0; k < n; k++)
{
for (int l = 0; l < n; l++)
{
num1 += a[k][l] + " ";
}
num1 += "\n";
}
for (i = 0; i < n; i++)
{
c[i] = 0;
//for(j=0;j<n;j++)
//scanf("%d",&a[i][j]);
}
c[0] = 1; c[1] = 2;
for (i = 2; i < n; i++)
{
for (j = 0; j < n; j++)
if (a[i][j] > 0)
{
m = 0;
for (col = 0; col < n; col++)
{ if (a[i][col] > 0)rt++; if (a[col][i] > 0)ct++; }
m = rt; if (ct > rt) m = ct;
if (m < 2) { if (a[0][i] > 0)c[i] = 2; else c[i] = 1; } else { c[i] = count; if (m > max) { max = m; count++; } }
rt = 0; ct = 0;
} if (c[i] < 1) if (c[i - 1] > 1) c[i] = 1; else c[i] = 2;
}
string result = "";
for (i = 0; i < n; i++)
{
result += "Subject[" + (i + 1) + "] = " + c[i] + "\n";
if (c[i]==1)
{
TextBox4.Text += "Subject 1 = 8:15 to 9:15 \n";
}
if (c[i] == 2)
{
TextBox4.Text += "Subject 2 = 9:15 to 10:15 \n";
}
if (c[i] == 3)
{
TextBox4.Text += "Subject 3 = 10:45 to 11:45 \n";
}
if (c[i] == 4)
{
TextBox4.Text += "Subject 4 = 11:45 to 12:45 \n";
}
if (c[i] == 5)
{
TextBox4.Text += "Subject 5 = 1:30 to 2:30 \n";
}
if (c[i] == 6)
{
TextBox4.Text += "Subject 6 = 2:30 to 3:30 \n";
}
if (c[i] == 7)
{
TextBox4.Text += "Lab 1 = 8-15 to 10:15 \n";
}
if (c[i] == 8)
{
TextBox4.Text += "Lab 2 = 10:45 to 12:45 \n";
}
if (c[i] == 9)
{
TextBox4.Text += "Lab 3 = 1:30 to 3:30 \n";
}
if (c[i] == 10)
{
TextBox4.Text += "Lab 4 = 8-15 to 9:15 \n";
}
}
con.Close();
TextBox2.Text = result;
}
catch (Exception ex)
{
Label2.Text = ex.Message;
}
In the above code, I'm reading the data i.e 0's and 1's of the adjacency matrix from the database onto which the graph colouring algorithm is applied. Once the colouring has been performed, results are printed on a textbox for time being.
The problem I am facing is, the colors are not being assigned and not able to generate the time table.

Required a spacing while merging two identical column values

I have a requirement to merge 2 column values - It's working good. But, there is no space between 2 values. Below is my code. Please let me know where i have to correct:
DataGridViewTextBoxColumn dgvctime = new DataGridViewTextBoxColumn();
dgvctime.Name = cmbColumn1.Text;
dgvctime.HeaderText = cmbColumn1.Text;
dataGridView1.Columns.Add(dgvctime);
//dataGridView1.Rows.Add(dgvctime);
int rowadded = 0;
for (int RowCount = 1; RowCount <= strfile.Length - 1; RowCount++)
{
if (strfile[RowCount].ToString() != "")
{
if (RowCount != 0)
{
//dataGridView1.Rows.Add();
string[] column = strfile[RowCount].Split('รพ');
rowadded = 0;
for (int i = 1; i < column.Length - 1; i++)
{
//dataGridView1.Rows.Add();
if ((cmbColumn1.SelectedIndex == ((i - 1) / 2)) || (cmbColumn2.SelectedIndex == ((i - 1) / 2)))
{
if (rowadded == 0)
{
rowadded = 1;
dataGridView1.Rows.Add();
}
if (column[i].ToString() != "\u0014")
{
//dataGridView1.Rows[RowCount - 1].Cells[cmbColumn1.Text].Value += column[i].ToString();
dataGridView1.Rows[RowCount - 1].Cells[cmbColumn1.Text].Value += column[i].ToString();
` }
}
}
}
}
Change this line ...
dataGridView1.Rows[RowCount - 1].Cells[cmbColumn1.Text].Value += " " + column[i].ToString();
Just add a short update
dataGridView1.Rows[RowCount - 1].Cells[cmbColumn1.Text].Value += " " + column[i].ToString();

How to validate a generic collection of Data in window Form

I have the method that does a calculation and adds the data to a collection list. Below is my code
IterateDtColl iterateDataList = new IterateDtColl();
double answer;
//Array to hold the previous initail tempreture
double[] TempArray = new double[9];
for (int tVal = 0; tVal < exdatalist.count(); tVal++)
{
ValidateDataColl validatelist = new ValidateDataColl();
//Assign my initial tempreture
if (iterateDataList.count() > 0)
{
TempArray[0] = iterateDataList.getexceldata(tVal - 1).Pi1;
TempArray[1] = iterateDataList.getexceldata(tVal - 1).Pi2;
TempArray[2] = iterateDataList.getexceldata(tVal - 1).Pi3;
TempArray[3] = iterateDataList.getexceldata(tVal - 1).Pi4;
TempArray[4] = iterateDataList.getexceldata(tVal - 1).Pi5;
TempArray[5] = iterateDataList.getexceldata(tVal - 1).Pi6;
TempArray[6] = iterateDataList.getexceldata(tVal - 1).Pi7;
TempArray[7] = iterateDataList.getexceldata(tVal - 1).Pi8;
TempArray[8] = iterateDataList.getexceldata(tVal - 1).Pi9;
}
else
{
TempArray[0] = Convert.ToDouble(initProbTxtBx.Text);
TempArray[1] = TempArray[0];
TempArray[2] = TempArray[0];
TempArray[3] = TempArray[0];
TempArray[4] = TempArray[0];
TempArray[5] = TempArray[0];
TempArray[6] = TempArray[0];
TempArray[7] = TempArray[0];
TempArray[8] = TempArray[0];
}
//Holds Value for last calculated values..
double[] LastCalValue = new double[9];
for (int iVal = 0; iVal < 9; iVal++)
{
answer = 0.0;
if (iVal == 0)
{
answer = (TempArray[iVal] + (r_val(dxval(lval, nval)) * (exdatalist.getexceldata(tVal).CentreTemp + initVal))) / (1 + (2 * r_val(dxval(lval, nval))));
}
else if (iVal == 8)
{
answer = (TempArray[iVal] + (r_val(dxval(lval, nval)) * (LastCalValue[iVal - 1] + exdatalist.getexceldata(tVal).SurfaceTemp))) / (1 + (2 * r_val(dxval(lval, nval))));
}
else
{
answer = (TempArray[iVal] + (r_val(dxval(lval, nval)) * (LastCalValue[iVal - 1] + initVal))) / (1 + (2 * r_val(dxval(lval, nval))));
}
//Hold the values at the present index so it can be used at the next index
LastCalValue[iVal] = answer;
//Adds the data to be validated to my collection list
validatelist.addvaliddt(new ValidateDataCl(initVal, LastCalValue[iVal], TempArray[iVal]));
}
I want to check that the difference between the initVal and LastCalValue[index] in the validatelist is less than 0.0001, if it is not, then do the calculation below till the condition is met.
for (int check = 0; check < validate.count(); check++)
{
double newAnswer;
double NewVal = 0.0;
if (check == 0)
{
//Set my new value to the value at the next index(Which then becomes my guess)
NewVal = validate.getvaliddata(check + 1).NewValue;
newAnswer = (validate.getvaliddata(check).InitTemp + (r_val(dxval(lval, nval)) * (CentreTemp + NewVal))) / (1 + (2 * r_val(dxval(lval, nval))));
}
else if (check == 8)
{
NewVal = OldVal[check - 1];
newAnswer = (validate.getvaliddata(check).InitTemp + (r_val(dxval(lval, nval)) * (NewVal + SurfaceTemp))) / (1 + (2 * r_val(dxval(lval, nval))));
}
else
{
NewVal = validate.getvaliddata(check + 1).NewValue;
newAnswer = (validate.getvaliddata(check).InitTemp + (r_val(dxval(lval, nval)) * (OldVal[check - 1] + NewVal))) / (1 + (2 * r_val(dxval(lval, nval))));
}
validate.getvaliddata(check).InitGuess = NewVal;
validate.getvaliddata(check).NewValue = newAnswer;
OldVal[check] = newAnswer;
}
//ValidateDataColl ValidatedList = CalNewData(validatelist, exdatalist.getexceldata(tVal).CentreTemp, exdatalist.getexceldata(tVal).SurfaceTemp);
iterateDataList.additerdt(new IterateClass(exdatalist.getexceldata(tVal).CentreTemp, ValidatedList.getvaliddata(0).NewValue, ValidatedList.getvaliddata(1).NewValue, ValidatedList.getvaliddata(2).NewValue, ValidatedList.getvaliddata(3).NewValue, ValidatedList.getvaliddata(4).NewValue, ValidatedList.getvaliddata(5).NewValue, ValidatedList.getvaliddata(6).NewValue, ValidatedList.getvaliddata(7).NewValue, ValidatedList.getvaliddata(8).NewValue, exdatalist.getexceldata(tVal).SurfaceTemp));
}
return iterateDataList;
How can I do that?

Categories

Resources