okey I dont know how much to shorten this so I post the whole
function:
public void afterstart()
{
DateTime startdatum = new DateTime(myForm.Start.Year, 1,
1);
check = DayCheck(startdatum.DayOfWeek.ToString());
check2 = DayCheck2(myForm.Start.DayOfWeek.ToString());
check3 = DayCheck2(myForm.End.DayOfWeek.ToString());
int preweek = (myForm.Start.DayOfYear - check + check2) /
7;
afterweek = ((myForm.End.DayOfYear - check + check3) / 7)
- preweek + 1;
MessageBox.Show(afterweek.ToString());
//get the start and end date from form1
Sjuk = 0;
Ledig = 0;
VAB = 0;
Kurs = 0;
Debiterbar = 0;
Presale = 0;
ws = new List<Excel.Worksheet>();
// ws = (;
//declare outlook objects
Microsoft.Office.Interop.Outlook.Application App = new
Microsoft.Office.Interop.Outlook.Application();
NameSpace MAPI = App.GetNamespace("MAPI");
AppointmentItem newAPP =
(AppointmentItem)App.CreateItem(OlItemType.olAppointmentItem);
//get the names from the specified txtfile
StreamReader Re = File.OpenText(@"C:\Names.txt");
int slutvecka;
for (int i = 0; i <= afterweek; i++)
{
ws.Add((Excel.Worksheet)Globals.ThisWorkbook.Worksheets.Add(missing,
missing, missing, missing));
slutvecka = i + preweek;
// du ska säkert på nåt sätt lägga till worksheeten i
workbooken
// typ
ThisApplication.ActiveWorkbook.Worksheets.Add(ws);
ws.Name = slutvecka.ToString();
datum = myForm.Start.ToString("dd MMM-");
datum += myForm.End.ToString("dd MMM");
ws.Cells[2, 2] = datum;
int cell = 3;
ws.Cells[5, cell++] = "Måndag";
ws.Cells[5, cell++] = "Tisdag";
ws.Cells[5, cell++] = "Onsdag";
ws.Cells[5, cell++] = "Torsdag";
ws.Cells[5, cell++] = "Fredag";
//start the nameloop
//try
//{
while ((input = Re.ReadLine()) != null)
{
namn++;
Recipient rec = newAPP.Recipients.Add(input);
MAPIFolder MAPIF =
MAPI.GetSharedDefaultFolder(rec, OlDefaultFolders.olFolderCalendar);
r = ws.get_Range(ws.Cells[y, 1],
ws.Cells[y + 9, 1]);
ws.Cells[y, 1] = input;
date = new DateTime(myForm.Start.Year,
myForm.Start.Month, myForm.Start.Day);
date = date.AddHours(8);
for (int k = 0; k < 10; i++)
{
ws.Cells[y + k, 2] =
date.ToString("HH:mm");
date = date.AddHours(1);
}
y += 10;
r.MergeCells = true;
//start the appointmentloop
foreach (object obj in MAPIF.Items)
{
AppointmentItem item = obj as
AppointmentItem;
if (item != null)
{
//check if the dates is correct, and
nonprivate
if (DateTime.Compare(item.Start,
myForm.Start) > 0 &&
DateTime.Compare(item.Start,
myForm.End) <= 0
&& item.Sensitivity !=
OlSensitivity.olPrivate)
{
finaldate = new
DateTime(myForm.Start.Year, myForm.Start.Month, myForm.Start.Day);
finaldate = finaldate.AddHours(8);
itemstart =
item.Start.AddHours(-1);
itemend = item.End.AddHours(-1);
for (int j = 0; j < 5; j++)
{
for (int k = 0; k < 10; k++)
{
if
(DateTime.Compare(itemstart, finaldate) <= 0
&&
DateTime.Compare(itemend, finaldate) >= 0)
{
subject =
item.Location;
if (subject == null)
{
subject = " ";
}
if
(subject.EndsWith("[Sjuk]", false, CultureInfo.CurrentCulture))
{
item.Subject =
"Sjuk";
Sjuk++;
}
else if
(subject.EndsWith("[Kurs]", false, CultureInfo.CurrentCulture))
{
item.Subject =
"Kurs";
Kurs++;
}
else if
(subject.EndsWith("[VAB]", false, CultureInfo.CurrentCulture))
{
item.Subject =
"VAB";
VAB++;
}
else if
(subject.EndsWith("[Ledig]", false, CultureInfo.CurrentCulture))
{
item.Subject =
"Ledig";
Ledig++;
}
else if
(subject.EndsWith("[Debiterbar]", false, CultureInfo.CurrentCulture))
{
Debiterbar++;
}
else if
(subject.EndsWith("[Presale]", false, CultureInfo.CurrentCulture))
{
Presale++;
}
ws.Cells[yy + k, x
+ j] = item.Subject;
}
finaldate =
finaldate.AddHours(1);
}
finaldate =
finaldate.AddDays(1);
finaldate =
finaldate.AddHours(-10);
}
}
}
}
}/*
}
Thought that would be pretty much but there you have it ; )