C# - Copying Excel to Word using Interop - c#

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; }
}
}
}

Related

Implementing Transvoxel algorithm, Gaps and Odd Mesh formations

I am trying to implement the Transvoxel algorithm for a game I am working on but I'm noticing some weird issues in the mesh generated:
Not sure why there are gaps and why the sphere has fins behind it.
For some reason, the mesh has gaps between chunks, and it has these strange fins extending out behind it. I haven't been able to figure out why this is happening but I have an inkling it may have to do with either the function that generates the density values for each Chunk (16x16x16 Block of cells):
private float SampleDensity(float3 _point)
{
var _worldPos = (_point / (m_WorldRadius - 1.0f) - 0.5f) * m_VolumeFieldSize;
var _halfS = m_VolumeFieldSize / 2;
var _maxD= Magnitude(new float3(_halfS, _halfS, _halfS));
var _fudge = 1f;
var _density = Magnitude(_worldPos) / (_maxD + _fudge) - 0.5f;
var _noise = CalculateNoise(_worldPos);
_density += _noise;
return _density;
}
public void Execute()
{
for (int _z = 0; _z < m_ChunkSize; _z++)
{
for (int _y = 0; _y < m_ChunkSize; _y++)
{
for (int _x = 0; _x < m_ChunkSize; _x++)
{
var _point = (new float3(_x, _y, _z) + (m_GPosition)); // Multiplying or dividing this value adjusts the final mesh's scale.
var _valueAtPoint = SampleDensity(_point);
m_Cells[_z * m_ChunkSize * m_ChunkSize + _y * m_ChunkSize + _x] = _valueAtPoint;
}
}
}
}
, or the mesh generating code itself:
for (int _z = 0; _z < _chunk.m_ChunkSize; _z++)
{
for (int _y = 0; _y < _chunk.m_ChunkSize; _y++)
{
for (int _x = 0; _x < _chunk.m_ChunkSize; _x++)
{
var _cubeConfiguration = 0;
for (int _i = 0; _i < 8; _i++)
{
_cornerPos = CornerIndex[_i];
_densityValues[_i] = _chunk.GetCell(_x + _cornerPos.x, _y + _cornerPos.y, _z + _cornerPos.z);
if (_densityValues[_i] < _chunk.m_World.m_ISOLevel) _cubeConfiguration |= (1 << _i);
}
var _caseCode = (byte) _cubeConfiguration;
if (_caseCode == 0) continue;
for (int _i = 0; _i < _cornerNormals.Length; _i++)
{
_cornerPos = CornerIndex[_i];
_cornerNormals[_i] = new Vector3(
_chunk.GetCell(_x + _cornerPos.x - 1, _y + _cornerPos.y, _z + _cornerPos.z) - _chunk.GetCell(_x + _cornerPos.x + 1, _y + _cornerPos.y, _z + _cornerPos.z),
_chunk.GetCell(_x + _cornerPos.x, _y + _cornerPos.y - 1, _z + _cornerPos.z) - _chunk.GetCell(_x + _cornerPos.x, _y + _cornerPos.y + 1, _z + _cornerPos.z),
_chunk.GetCell(_x + _cornerPos.x, _y + _cornerPos.y, _z + _cornerPos.z - 1) - _chunk.GetCell(_x + _cornerPos.x, _y + _cornerPos.y, _z + _cornerPos.z + 1)
);
}
var _cellClass = Transvoxel.regularCellClass[_caseCode];
Debug.Log($"Cell Class {_cellClass}");
var _vertexLocations = Transvoxel.RegularVertexData[_caseCode];
var _cellData = Transvoxel.RegularCellDatas[_cellClass];
var _vertexCount = _cellData.GetVertexCount();
var _triangleCount = _cellData.GetTriangleCount();
var _indexOffset = _cellData.vertexIndex;
for (int _i = 0; _i < _vertexCount; _i++)
{
ushort _edge = (ushort)(_vertexLocations[_i] & 255);
byte _v0 = (byte)((_edge >> 4) & 0x0F); //First Corner Index
byte _v1 = (byte)(_edge & 0x0F); //Second Corner Index
float _t = (_densityValues[_v1]) / (_densityValues[_v1] - _densityValues[_v0]);
Vector3 _p0 = new Vector3((_x + CornerIndex[_v0].x), (_y + CornerIndex[_v0].y), (_z + CornerIndex[_v0].z));
Vector3 _p1 = new Vector3((_x + CornerIndex[_v1].x), (_y + CornerIndex[_v1].y), (_z + CornerIndex[_v1].z));
var _position = (_p0 * _t) + ((1 - _t) * _p1);
var _n0 = CalculateNormal(_chunk, new Vector3Int((int) _p0.x, (int) _p0.y, (int) _p0.z));
var _n1 = CalculateNormal(_chunk, new Vector3Int((int) _p1.x, (int) _p1.y, (int) _p1.z));
var _normal = (_n0 + _t * (_n1 - _n0)).normalized;
m_Normals.Add(_normal);
m_Vertices.Add(_position);
m_UVs.Add(UvOffset[m_VCase]);
m_VCase = (byte)(m_VCase == 3 ? 0 : m_VCase + 1);
m_LocalVertexMapping[_i] = (ushort)(m_Vertices.Count - 1);
}
for (int _t = 0; _t < _triangleCount; _t++)
{
int _tm = _t * 3;
m_Triangles.Add(m_LocalVertexMapping[_indexOffset[_tm]]);
m_Triangles.Add(m_LocalVertexMapping[_indexOffset[_tm + 1]]);
m_Triangles.Add(m_LocalVertexMapping[_indexOffset[_tm + 2]]);
}
}
}
}
I am at a complete loss and would really appreciate some help as I've been racking my brains for close to 2 months on this, along with reading several papers on different MC Algorithms (Lengyel's included) for potential inspiration. Thank You.

Way too slow C# Console application. Any way to speed it up?

I am currently developing a little program that goes through an excel file and escalate things by e-mail, and shows the progress of the materials in a "progress bar" inside the excel.
The program runs just fine, does all the things it intended to do but its way too slow.
For about 11 rows it takes like 3 minutes.
The file will have more and more (couple hunderd) lines eventually and it will take forever to update.
Do you guys know any way to speed this up?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using System.IO;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace Prod_Tracking
{
class Program
{
static void Main(string[] args)
{
Outlook.Application app = new Outlook.Application();
Outlook.MailItem mailItem = app.CreateItem(Outlook.OlItemType.olMailItem);
string rootPath = Directory.GetCurrentDirectory();
string path = rootPath + "\\ProdTracking.xlsx";
string email1 = "email#email.com";
string email2 = "email#email.com";
string body;
string subject;
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook wb = excel.Workbooks.Open(path);
Microsoft.Office.Interop.Excel.Worksheet tracking = excel.Sheets["Tracking"] as Microsoft.Office.Interop.Excel.Worksheet;
Microsoft.Office.Interop.Excel.Worksheet coois = excel.Sheets["COOIS"] as Microsoft.Office.Interop.Excel.Worksheet;
Microsoft.Office.Interop.Excel.Worksheet line = excel.Sheets["Line"] as Microsoft.Office.Interop.Excel.Worksheet;
Microsoft.Office.Interop.Excel.Worksheet stat = excel.Sheets["Stat"] as Microsoft.Office.Interop.Excel.Worksheet;
Excel.Range trackingRange = tracking.UsedRange;
int mainRows = trackingRange.Rows.Count; //row number of main sheet
coois.Select(true);
Excel.Range cooisRange = coois.UsedRange;
int cooisRows =cooisRange.Rows.Count; //row number of coois sheet
line.Select(true);
Excel.Range lineRange = line.UsedRange;
int lineRows = lineRange.Rows.Count; //row number of line sheet
line.Select(true);
Excel.Range statRange = stat.UsedRange;
int statRows = statRange.Rows.Count; //row number of stat sheet
DateTime thisDay = DateTime.Today;
int days = 0;
int daysofescalation = 0;
for (int i = 3; i <= mainRows; i++)
{
double percent = (i - 2) * 100 / (mainRows - 1); //progress percentage
Console.Clear();
Console.Write("Update in progress! Please wait..." + '\n' + percent + "%" );
for(int j = 2; j <= cooisRows; j++)
{
//get data from COOIS
if (coois.Cells[j,1].Value == tracking.Cells[i, 1].Value)
{
tracking.Cells[i, 2].Value = coois.Cells[j, 2].Value;
tracking.Cells[i, 5].Value = coois.Cells[j, 11].Value;
tracking.Cells[i, 7].Value = coois.Cells[j, 8].Value;
tracking.Cells[i, 8].Value = coois.Cells[j, 9].Value;
if ((thisDay - Convert.ToDateTime(tracking.Cells[i, 5].Value)).TotalDays > 0)
{
tracking.Cells[i, 38].Value = (thisDay - Convert.ToDateTime(tracking.Cells[i, 5].Value)).TotalDays; //calculate passed time in days format
days = Convert.ToInt32(tracking.Cells[i, 38].Value);
}
else
{
tracking.Cells[i, 38].Value = "Prod not yet started";
}
//A/B/C
if (Convert.ToString(tracking.Cells[i,2].Value).Length > 12)
{
tracking.Cells[i, 3].Value = "A";
tracking.Cells[i, 6].Value = Convert.ToDateTime(tracking.Cells[i, 5].Value).AddDays(21);
tracking.Range["J" + i + ":" + "AK" + i].Interior.ColorIndex = 0; //clear progress bar/line
tracking.Range["AF" + i + ":" + "AK" + i].Interior.ColorIndex = 1; //insert black part
//fill up progress bar
if (Convert.ToString(tracking.Cells[i, 38].Value) != "Prod not yet started")
{
if (days > 21)
{
tracking.Range["J" + i + ":" + "AE" + i].Interior.ColorIndex = 3;
}
else
{
tracking.Range[tracking.Cells[i, 10], tracking.Cells[i, (10 + days)]].Interior.ColorIndex = 4;
}
}
}
if(Convert.ToString(tracking.Cells[i, 2].Value).Length == 12)
{
tracking.Cells[i, 3].Value = "B";
tracking.Cells[i, 6].Value = Convert.ToDateTime(tracking.Cells[i, 5].Value).AddDays(13);
tracking.Range["J" + i + ":" + "AK" + i].Interior.ColorIndex = 0; //clear progress bar/line
tracking.Range["W" + i + ":" + "AK" + i].Interior.ColorIndex = 1; //insert black part
//fill up progress bar
if (Convert.ToString(tracking.Cells[i, 38].Value) != "Prod not yet started")
{
if (days >= 13)
{
tracking.Range["J" + i + ":" + "V" + i].Interior.ColorIndex = 3;
}
else
{
tracking.Range[tracking.Cells[i, 10], tracking.Cells[i, (10 + days)]].Interior.ColorIndex = 4;
}
}
}
if (Convert.ToString(tracking.Cells[i, 2].Value)[0] == '5')
{
tracking.Cells[i, 3].Value = "C";
tracking.Range["J" + i + ":" + "AK" + i].Interior.ColorIndex = 0; //clear progress bar/line
tracking.Cells[i, 6].Value = Convert.ToDateTime(tracking.Cells[i, 5].Value).AddDays(28);
//fill up progress bar
if (Convert.ToString(tracking.Cells[i, 38].Value) != "Prod not yet started")
{
if (days > 28)
{
tracking.Range["J" + i + ":" + "AK" + i].Interior.ColorIndex = 3;
}
else
{
tracking.Range[tracking.Cells[i, 10], tracking.Cells[i, (10 + days)]].Interior.ColorIndex = 4;
}
}
}
//get current production status
for (int l = 2; l <= statRows; l++)
{
if(tracking.Cells[i,1].Value == stat.Cells[l,1].Value && stat.Cells[l, 7].Value != null)
{
tracking.Cells[i, 9].value = Convert.ToString(stat.Cells[l, 4].Value);
l = statRows + 1;
}
}
//Get lines (way too slow, need to be optimised, maybe import it to a list?)
for (int k = 2; k <= lineRows; k++)
{
if (tracking.Cells[i, 2].Value == line.Cells[k, 1].Value)
{
tracking.Cells[i, 4].Value = line.Cells[k, 2].Value;
k = lineRows + 1;
}
}
if (tracking.Cells[i, 4].Value == null)
{
tracking.Cells[i, 4].Value = "NA";
}
//overdue status "YES" or "NO"
if(tracking.Cells[i, 10].Interior.ColorIndex == 3)
{
tracking.Cells[i, 39].Value = "Yes";
}
else
{
tracking.Cells[i, 39].Value = "No";
}
//escalation level one, making the body into a string, sending email and writing in the date of the escalation
if(tracking.Cells[i, 39].Value == "Yes" && tracking.Cells[i, 40].Value == null && tracking.Cells[i, 42].Value != "x")
{
body = "Dear Recipient," + "\n\nThe production order: " + Convert.ToString(tracking.Cells[i, 1].Value) + " for the material " + Convert.ToString(tracking.Cells[i, 2].Value) + " is overdue." + "\nOrdered quantity: " + Convert.ToString(tracking.Cells[i, 7].Value) + "\nConfirmed quantity: " + Convert.ToString(tracking.Cells[i, 8].Value) + "\nPlease take some actions." + "\n\n\n\nThis is an automatically generated message by the production tracking tool";
subject = Convert.ToString(tracking.Cells[i, 1].Value) + " production order is overdue - Escalalation I.";
Program.SendEMail(email1, subject, body);
tracking.Cells[i, 40].Value = thisDay;
}
//escalation level2
if (tracking.Cells[i, 40].Value != null)
{
daysofescalation = Convert.ToInt32((thisDay - Convert.ToDateTime(tracking.Cells[i, 40].Value)).TotalDays);
if(daysofescalation > 8 && tracking.Cells[i, 42].Value != "x" && tracking.Cells[i, 41].Value != null)
{
body = "Dear Recipient," + "\n\nThe production order: " + Convert.ToString(tracking.Cells[i, 1].Value) + " for the material " + Convert.ToString(tracking.Cells[i, 2].Value) + " is overdue." + "\nOrdered quantity: " + Convert.ToString(tracking.Cells[i, 7].Value) + "\nConfirmed quantity: " + Convert.ToString(tracking.Cells[i, 8].Value) + "\nPlease take some actions." + "\n\n\n\nThis is an automatically generated message by the production tracking tool";
subject = Convert.ToString(tracking.Cells[i, 1].Value) + " production order is overdue - Escalalation II.";
Program.SendEMail(email2, subject, body);
tracking.Cells[i, 41].Value = thisDay;
}
}
j = cooisRows + 1;
}
}
}
wb.Close(true);
excel.Quit();
Console.Clear();
Console.WriteLine("Update in progress!Please wait..." + '\n' + "100" + " % " + "\nExcel updated!");
Console.ReadLine();
}
static void SendEMail(string email, string subject, string body)
{
Outlook.Application app = new Outlook.Application();
Outlook.MailItem mailItem = app.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.Subject = subject;
mailItem.To = email;
mailItem.Body = body;
mailItem.Importance = Outlook.OlImportance.olImportanceHigh;
mailItem.Display(false);
((Outlook._MailItem)mailItem).Send();
}
}
}
Thank you so much for the help in advance,
-B

Timing in Ticket System

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());
}

Adding Images in Row and Column in Grid

I have a problem where I am trying to add images to a grid, but the images are being added oddly. (See Picture). I am trying to add the images in a straight row, yet they are being added in the first spot then in the next row. I am a noob, so I am very confused. Thank you for your help.
(The TUtils are just grabbing values from an .ini file)
Code:
private void PopulateGrid()
{
Image img = CreateImage();
ImageSize = TUtils.GetIniInt(Moleini, "ImageSize", "imageSize", 10);
NumofImages= TUtils.GetIniInt(Moleini, "NumPictures", "pictures", 8);
int ImageBorderSize = TUtils.GetIniInt(Moleini, "ImageBorder", "imageBorder", 2);
double NumberOfColumns = TUtils.GetIniInt(Moleini, "NumRowsColumns", "columnNum", 4);
// More Columns than Rows \\
if (NumberOfColumns > NumofImages)
{
MessageBox.Show("There is something wrong with the .ini file.");
MainWin.Close();
}
// Math - Get Necessary Variables \\
int ColumnSize = (ImageSize + (2 * ImageBorderSize));
int RowSize = (ImageSize + (2 * ImageBorderSize));
int NumberofRows = (int)Math.Ceiling(NumofImages / NumberOfColumns);
int MainWindowWidth = (TUtils.ToInt(NumberOfColumns.ToString(), 2) * ColumnSize) + 15;
int MainWindowHeight = (NumberofRows * RowSize) + 35;
// Set Window Size \\
MainWin.Width = MainWindowWidth;
MainWin.Height = MainWindowHeight;
// Create Grid \\
MainWin.Content = grid_Main;
grid_Main.Height = MainWindowHeight;
grid_Main.Width = MainWindowWidth;
grid_Main.Background = Brushes.Transparent;
// Grid Properties \\
for (int i = 0; i < NumberOfColumns; i++)
{
ColumnDefinition newColumn = new ColumnDefinition();
newColumn.Width = new GridLength(ColumnSize, GridUnitType.Pixel);
grid_Main.ColumnDefinitions.Add(newColumn);
}
for (int i = 0; i < NumberofRows; i++)
{
RowDefinition Row = new RowDefinition();
Row.Height = new GridLength(RowSize, GridUnitType.Pixel);
grid_Main.RowDefinitions.Add(Row);
}
// Fill Grid \\
int RowCount = 0;
int ColumnCount = 0;
for (int i = 0; i <= NumofImages; i++)
{
Image newImage = CreateImage();
if (RowCount < NumberofRows)
{
if (ColumnCount < NumberOfColumns)
{
Console.WriteLine("ColumnCount: " + ColumnCount.ToString());
Grid.SetRow(newImage, ColumnCount);
Grid.SetColumn(newImage, ColumnCount);
grid_Main.Children.Add(newImage);
ColumnCount++;
}
else
{
RowCount++;
ColumnCount = 0;
Grid.SetRow(newImage, ColumnCount);
Grid.SetColumn(newImage, ColumnCount);
grid_Main.Children.Add(newImage);
ColumnCount++;
Console.WriteLine("RowCount: " + RowCount.ToString());
}
}
else
{
break;
}
}
}
Discovers problem, I used "ColumnCount" when I should have used "RowCount"

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