|
hmm. right you are.
cool.
|
|
|
|
|
Thanks Chris!
This thread has really helped my human factors. I didn't really know I had an unresolved resentment againts this interviewer.
It also helped me to lear something new: Big O Notation. This was another factor which came up in the interview. I did not go to an ivy leage college to study Computer Science, in fact I never went to college to learn computer science. I did study engineering and electronics in college at a technical college. The interviewer told me this would not be a factor in his assessment of my skill. However he did give me a problem first year Computer Science engineers study.
I sometimes wonder if the interviewer was really trying to factor me out of the equation.
|
|
|
|
|
Big O is cool. i learned it in college, but it was a decade before i really found a practical use for it (when i got into graphics programming).
|
|
|
|
|
Well, I think this is really a great question for an interview, becouse you can get a lot of conclusions depending on the answer.
If the answer was:
int BadFib(int n)
{
if (n == 1 || n == 2)
return 1;
else
return BadFib(n - 1) + BadFib(n - 2);
}
This answer means that the guy knows what recursion is, but he has no idea about algorithm complexity, and he does not mind performance at all. So, my next question would be: Can you do it better?
But now, if somebody came up with this solution:
public int GoodFib(int n)
{
return Fib(n, 1, 1);
}
private int Fib(int n, int n1, int n2)
{
if (n == 1 || n == 2)
return 1;
else if (n == 3)
return n1 + n2;
else
return Fib(n - 1, n1 + n2, n1);
}
This means that the guy knows what recursion is, he knows what algorithm complexity is, and he is worried about the performance of his code. So, my next question would be: When would yo be able to start with the job?
I guess the interviewer just wanted to know how skilled you were about programming.
modified on Tuesday, July 7, 2009 11:30 AM
|
|
|
|
|
In one of my interviews, I was asked to code a function to convert an string (char *, it was as C interview) into an int.
Considering that there are already a lot of functions that do it already, it looks stupid. Considering it was an way to know if I know how to solve problems, I did it.
Later, the interviewer was surprised, because I was the only one of the candidates to answer such question.
|
|
|
|
|
Paulo Zemek wrote: Later, the interviewer was surprised, because I was the only one of the candidates to answer such question.
That's sad. I wrote the pascal equivalent after roughly half a year of programming in high school, and then wrote the equivalent to convert a string into a float.
I was writing custom numeric input handlers that rejected garbage keystrokes; offhand I don't recall why I didn't want to use the standard library validation/conversion functions.
The European Way of War: Blow your own continent up.
The American Way of War: Go over and help them.
|
|
|
|
|
That is exactly the point I wanted to reach.
|
|
|
|
|
Paulo Zemek wrote: In one of my interviews, I was asked to code a function to convert an string (char *, it was as C interview) into an int.
Considering that there are already a lot of functions that do it already, it looks stupid. Considering it was an way to know if I know how to solve problems, I did it.
Cool!
But how did you do it?
|
|
|
|
|
Initialized an int to zero.
Checked if the value started with a - (setting an isNegative boolean and, at the end, multiplying the value by -1).
At each char read, checked if it was an int (>= '0' && <='9'). If not, returned 0. (it was a requisite).
Multiplied the result by 10. If it was zero, nothing happened.
Got the real value of the char (c - '0'). Added this value to the integer result.
And thats it.
|
|
|
|
|
Okay after much testing I have a non recursive version:
using System;
namespace Test
{
class fib
{
double n = 0;
public double next
{
get
{
return n;
}
set
{
n = Math.Round(((Math.Pow(fib.golden(),value)) - Math.Pow((1-fib.golden()),value)) / Math.Sqrt(5));
}
}
private static double golden()
{
return (1 + Math.Sqrt(5)) / 2;
}
}
}
public static double MyFib(int n)
{
fib f = new fib();
f.next = n;
return f.next;
}
Like I said, 'recursive algroythms are a bad idea.'
GoodFib(6000)
-1142292160
MyFib(6000)
Infinity
GoodFib(1000)
1556111435
MyFib(1000)
4.3466557686938915E+208
If you change GoodFib to return a double:
GoodFib(6000)
Infinity
GoodFib(1000)
4.3466557686937428E+208
MyFib looses precision (I think):
public static double NotEqual()
{
double count;
double result1 = 0;
double result2 = 0;
for (count = 1;; count++)
{
result1 = GoodFib(count);
result2 = MyFib(count);
if (result1 != Math.Floor(result2))
break;
}
Console.WriteLine("Result1: [" + result1.ToString() + "]");
Console.WriteLine("Result2: [" + result2.ToString() + "]");
return count;
}
NotEqual()
71.0
Result1: [308061521170129]
Result2: [308061521170130] ?!?!
Not really sure which is correct. The online sources say GoodFib is right. If I was really to do something like this I would use Math Lab C# extensions. Guarinteed precision.
modified on Wednesday, July 8, 2009 2:42 AM
|
|
|
|
|
'Maybe the SS uses this formula...'
|
|
|
|
|
I think you have not got the point. What I mean is that when an intervewer asks you to solve a problem within some kind of restrictions, as "recursive way" to do "whatever", the really important thing here is not the problem itself, but the way you can solve it applying those restrictions.
That is why I have showed two possible ways to solve Fibonacci sequence in a recursive way. The first one is horrible because it has an exponential complexity, while the second one is linear. Sure, using golden proportion in this concrete case comes with a constant complexity algorithm, but you have not folowed the instructions. So, the problem here is not finding a Fibonacci number. The problem is to do it in a recursive way with a good performance. If the interviewer had asked you, for example, to find an iterative way to solve Hanoi's Tower problem, golden proportion would not be there to help you.
On the other hand, when you say recursion is bad, sorry, but you are absolutely wrong. Many abstract data types are recursive by definition, like trees or graphs. Just implement a non recursive way to find a file within a tree of folders. When you get it, do it recursive. When finished, analyze both of them, how they work and what they do under the covers. When you get finished, I think you will really appreciate the real value of recursion.
|
|
|
|
|
Yes I understand your point is valid. However, if the candidate tells the interviewer he understands recrusion and gives the text book definition and tells the interviewer that the problem is better solved using non-recrusive methods... If the interviewer does not trust the candidate it speaks bad for the company they represent.
Why are recursive algrythms bad:
IEEE Abstract - Recursive algorithms in computer science courses: Fibonacci numbersand binomial coefficients[^]
I did some BigO testing of the various algorithms, here are the results:
BadFib(40) LoopCount: [204668309] - SplitTimeMicro: [15042441.7069767]
GoodFib(40) LoopCount: [38] - SplitTimeMicro: [1171.09856140934]
MyFib(40) LoopCount: [1] - SplitTimeMicro: [6122.8452219486] - 'can be improved using the correct math lib.'
LinerFib(40) LoopCount: [41] - SplitTimeMicro: [652.317543151434]
Liner Fib:
public static double LinerFib(double n)
{
double previous = -1;
double result = 1;
double sum = 0;
for (double i = 0; i <= n; ++i)
{
sum = result + previous;
previous = result;
result = sum;
}
return result;
}
'Most solutions to problems which are inherintly recrusive in nature can be solved using liner proofs...'
|
|
|
|
|
|
Using infinite asymptotics...
MyFib(1477) Loops: [1477] Steps: [Approx:25109]
GoodFib(1477) Loops: [1088552] Steps: [6537220]
LinearFib(1477) Loops: [1092980] Steps: [8752702]
Even though Linerfib takes more steps, it out performs GoodFib in a clock test. In engineering we call this the 'Proof from the pudding...'
LinerFib(1477) LoopCount: [1478] - SplitTimeMicro: [44.6984183744023]
MyFib(1477) LoopCount: [1] - SplitTimeMicro: [48.8888950970026]
GoodFib(1477) LoopCount: [1475] - SplitTimeMicro: [507.047683434626]
modified on Wednesday, July 8, 2009 2:35 PM
|
|
|
|
|
Ok, guy. Which part of "the really important thing here is not the problem itself, but the way you can solve it applying those restrictions" is the one you have not understood?
|
|
|
|
|
_Erik_ wrote: Ok, guy. Which part of "the really important thing here is not the problem itself, but the way you can solve it applying those restrictions" is the one you have not understood?
I have all ready admited your point is valid! My problem with the interviewer was that I had expalined the problems with recrusion and how it causes bad things to happen like: heap pile up, stack overflow, huge thread stacks, and object over load due to the problem with not being able box objects for reuse. I also told the interviewer that I only had a basic understanding of the problem and that I knew it would be better solved with out using recursion. I did explain what recursion was and such. My biggest mistake was not asking the interviewer for a diffrent problem using the same constraints for which I completly undestood. We are human Eric, a knowlegable man learns from his own mistakes, a wise man learns from others. I was not trying to bash you in this thread, my honest appoligies if you though as much. My intent was to show how I arrived at my conclusions about the problem algroythm during the interview. Perhaps others reading this thread could gain wisdom from my mistake.
~TheArch
|
|
|
|
|
You don't know why you didn't get the job. It could have been for many reasons. I've been turned down for jobs even AFTER I passed the technical part. A lot of who gets hired has to do with the chemistry of the group you're interviewing with. Qualifications are overrated.
The second phrase is correct.
|
|
|
|
|
Well, I would have been thier Cheif Architect and Lead Developer.
I would have been the companies first hire besides the CTO which I was interviewing with.
He probibly didn't like me breaking the pencile into Four peices.
~TheArch
|
|
|
|
|
What would have been really funny; is if the interviewer actually hired me because I demonstrated recursion by repeatidly breaking the pencile in half. But he told me I didn't understand recursion. Hmm, strange how the subconcious mind works.
~TheArch
|
|
|
|
|
What I do is keep crib notes of basic algorithms in my notebook in case they ask you to do one. With the iPhone, you can keep electronic notes of the same things and review them while waiting for the interview to start.
|
|
|
|
|
This is just one method, but do not expect it to be short...
I spent my days debugging this kind of code...
Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
Dim i As Integer
Dim r As Integer
Dim sEmployeeID As String
Dim dDateFrom As DateTime = Convert.ToDateTime(DateFrom.Text)
Dim dDateTo As DateTime = Convert.ToDateTime(DateTo.Text)
Dim dDateCurrent As Date = dDateFrom
Dim sConsultantInfoDay As String = ""
Dim sProjectInfo1 As String = ""
Dim sProjectInfo2 As String = ""
Dim sProject As String = ""
Dim DateEnd As Object
Dim DaysNoticeExt As Object
Dim sColor1 As String = "#FFFFFF"
Dim sColor2 As String = "#FFFFFF"
Dim PreviousColor As String = "#FFFFFF"
Dim hl As New HyperLink
Dim lb As New Label
Dim lb2 As New Label
Dim iDayofWeek As Integer
Dim sDayName As String
Dim sExit As String
Dim bgColor As Drawing.Color
Dim sColorProject As String = "#FFFFFF"
Dim bTSClosed As Boolean
Dim Hours As Double
Dim HoursClientMonth As Double
Dim HoursMonth As Double
Dim HoursTBPMonth As Double
Dim HoursInternalMonth As Double
Dim DailyHoursTBP As Double
Dim TSID As Integer
Dim oEmpDateStart As Object
Dim oEmpDateEnd As Object
Dim bClientProject As Boolean = False
Dim bProjectFoundMonth As Boolean = False
Dim WorkPerc As Double
Dim sHoliday As String
Dim ProjectID As Integer
Dim TotalHoursMonth As Double
Dim dteRenewal, dteCurrentNotification, dteCurrentEndProj As DateTime
Dim intRenewalCpt As Integer = -1
Dim blnIsFirstTime As Boolean = True
Dim intRenewsEachNbMonths As Integer
Select Case e.Row.RowType
Case DataControlRowType.Header
Dim iMonth As Integer
e.Row.Cells(0).Visible = False
e.Row.Cells(1).Visible = False
e.Row.Cells(2).Visible = False
e.Row.Cells(3).Visible = False
e.Row.Cells(iColDaysStart - 1).Width = ConsultantColWidth
e.Row.Cells(iColDaysStart - 1).Text = sEmployeeHeader
e.Row.Cells(iColDaysStart - 1).Font.Size = iFontSizeEmployees
e.Row.Cells(iColDaysStart - 1).Font.Bold = True
e.Row.Cells(iColDaysStart - 1).ForeColor = Drawing.Color.White
e.Row.Cells(iColDaysStart - 1).BackColor = Drawing.Color.DarkBlue
i = iColDaysStart
Do While dDateCurrent <= dDateTo
iMonth = dDateCurrent.Month
sDayName = WeekdayName(DatePart("w", dDateCurrent), True, Microsoft.VisualBasic.FirstDayOfWeek.Sunday)
e.Row.Cells(i).Text = String.Concat(Left(sDayName, 2), String.Concat("<br /> ", Day(dDateCurrent).ToString))
e.Row.Cells(i).Font.Name = "Consolas, Courier New"
e.Row.Cells(i).Font.Size = iFontSizeHours
e.Row.Cells(i).BorderWidth = 1
e.Row.Cells(i).BorderColor = Drawing.Color.LightGray
e.Row.Cells(i).HorizontalAlign = HorizontalAlign.Center
iDayofWeek = Weekday(dDateCurrent)
sHoliday = sql.SQLValue("IsHoliday '" & dDateCurrent.Month.ToString & "/" & dDateCurrent.Day.ToString & "/" & dDateCurrent.Year.ToString & "'")
If sHoliday <> "N" Then
' Public Holiday
bgColor = Drawing.Color.Gray
Else
If iDayofWeek = 7 Or iDayofWeek = 1 Then
bgColor = Drawing.Color.Gray
Else
bgColor = Drawing.Color.DarkBlue
End If
End If
e.Row.Cells(i).ForeColor = Drawing.Color.White
e.Row.Cells(i).BackColor = bgColor
dDateCurrent = DateAdd(DateInterval.Day, 1, dDateCurrent)
If iMonth <> dDateCurrent.Month And Me.chkTotals.Checked Then
i = i + 1
e.Row.Cells(i).Text = "Total"
e.Row.Cells(i).Font.Size = iFontSizeHours
e.Row.Cells(i).ForeColor = Drawing.Color.White
e.Row.Cells(i).BackColor = Drawing.Color.DarkBlue
End If
i = i + 1
Loop
Case DataControlRowType.DataRow
Dim iMonth As Integer = 0
e.Row.Height = 25
e.Row.Cells(0).Visible = False ' EmployeeID
e.Row.Cells(1).Visible = False ' Customer
e.Row.Cells(2).Visible = False ' Department/Project
e.Row.Cells(3).Visible = False ' ProjectID
ProjectID = e.Row.Cells(3).Text
sEmployeeID = e.Row.Cells(0).Text
lb2.Text = " "
If sCustomerProject <> e.Row.Cells(1).Text & e.Row.Cells(2).Text And Me.optGroupBy.SelectedValue = 3 Then
' New Client/Project
e.Row.BackColor = Drawing.Color.White
e.Row.ForeColor = Drawing.Color.DarkBlue
e.Row.Cells(iColDaysStart - 1).Font.Size = iFontSizeEmployees ' Employees
e.Row.Cells(iColDaysStart - 1).Font.Bold = True
e.Row.Cells(iColDaysStart - 1).Text = e.Row.Cells(1).Text & " - " & e.Row.Cells(2).Text
e.Row.Style.Add("border-top-color", "Black")
e.Row.Style.Add("border-bottom-color", "White")
e.Row.Height = 25
sCustomerProject = e.Row.Cells(1).Text & e.Row.Cells(2).Text
e.Row.Cells(iColDaysStart - 1).Width = 210
e.Row.Cells(iColDaysStart - 1).Style.Add("cellspacing", "2")
e.Row.Cells(iColDaysStart - 1).Style.Add("background-color", "#FFFFCA")
e.Row.Cells(iColDaysStart - 1).Style.Add("color", "DarkBlue")
e.Row.Cells(iColDaysStart - 1).Style.Add("border-right-color", "#FFFFFD")
e.Row.Cells(iColDaysStart - 1).Style.Add("border-top-color", "#FFFFFD")
e.Row.Cells(iColDaysStart - 1).Style.Add("border-bottom-color", "#FFFFFD")
e.Row.Cells(iColDaysStart).Style.Add("border-left-color", "#FFFFFD")
i = iColDaysStart
Do While dDateCurrent <= dDateTo
iDayofWeek = Weekday(dDateCurrent)
e.Row.Cells(i).Style.Add("border-left-color", "White")
e.Row.Cells(i).Style.Add("border-right-color", "White")
dDateCurrent = DateAdd(DateInterval.Day, 1, dDateCurrent)
i = i + 1
Loop
Else
e.Row.Cells(iColDaysStart - 1).Font.Size = iFontSizeEmployees ' Employees
e.Row.Cells(iColDaysStart - 1).BackColor = Drawing.Color.Ivory
e.Row.Cells(iColDaysStart - 1).Width = ConsultantColWidth
Select Case Me.optGroupBy.SelectedValue
Case 1 ' Group By Department
lb.Text = " " & e.Row.Cells(2).Text & " - "
lb.ForeColor = Drawing.Color.Black
e.Row.Cells(iColDaysStart - 1).Controls.Add(lb)
hl.Text = e.Row.Cells(iColDaysStart - 1).Text ' Consultant
Case 2 ' Group By Consultant
hl.Text = Convert.ToString(cntConsultant) & ". " & e.Row.Cells(iColDaysStart - 1).Text ' Consultant
Case 3 ' Group By Client/Project
hl.Text = e.Row.Cells(iColDaysStart - 1).Text ' Consultant
lb.Text = " "
e.Row.Cells(iColDaysStart - 1).Controls.Add(lb)
End Select
hl.NavigateUrl = "EmployeeProjectsEdit.aspx?eid=" & e.Row.Cells(0).Text
e.Row.Cells(iColDaysStart - 1).Controls.Add(lb2)
e.Row.Cells(iColDaysStart - 1).Controls.Add(hl)
cntConsultant = cntConsultant + 1
i = iColDaysStart
sExit = ""
Dim dr() As DataRow
If Me.optGroupBy.SelectedValue = 3 Then
' Client/Project view
dr = dtProjectsTS.Select("EmployeeID = " & sEmployeeID) ' Get projects employee
Else
dr = dtProjectsTS.Select("EmployeeID = " & sEmployeeID) ' Get projects employee
End If
' Get Employee startdate / endate
If dr.GetUpperBound(0) > -1 Then
oEmpDateStart = dr(r)("EmpDateStart")
oEmpDateEnd = dr(r)("EmpDateEnd")
WorkPerc = dr(r)("WorkPerc")
Else
' No Projects assigned
oEmpDateStart = sql.SQLValue("SELECT DateStart FROM Employees WHERE EmployeeID = " & sEmployeeID)
oEmpDateEnd = sql.SQLValue("SELECT DateEnd FROM Employees WHERE EmployeeID = " & sEmployeeID)
End If
' Fake the dates to prevent Null error
If IsDBNull(oEmpDateStart) Then oEmpDateStart = Convert.ToDateTime("01/01/1950")
If IsDBNull(oEmpDateEnd) Then oEmpDateEnd = Convert.ToDateTime("01/01/2099")
HoursMonth = 0
HoursClientMonth = 0
HoursInternalMonth = 0
HoursTBPMonth = 0
bProjectFoundMonth = False
' Get days / Format days (colors, hours, 2 projects)
Do While dDateCurrent <= dDateTo
iMonth = dDateCurrent.Month
iDayofWeek = Weekday(dDateCurrent)
If oEmpDateStart > dDateCurrent Or oEmpDateEnd < dDateCurrent Then
' Unemployed / no project
e.Row.Cells(i).ToolTip = "Unemployed"
e.Row.Cells(i).BackColor = Drawing.ColorTranslator.FromHtml("#FFFFFF")
e.Row.Cells(i).Style.Add("border-left-color", "White")
e.Row.Cells(i).Style.Add("border-right-color", "White")
Else
sColor1 = "#FFFFFF"
sProject = "No Assignment"
Hours = 0
DailyHoursTBP = 8
DaysNoticeExt = 0
bClientProject = False
If dr.GetUpperBound(0) > -1 Then ' Loop through employee projects
' Check for client project = main
For r = 0 To dr.GetUpperBound(0)
If dr(r)("Month") = dDateCurrent.Month And dr(r)("Year") = dDateCurrent.Year Then
bTSClosed = dr(r)("Closed")
If Me.optGroupBy.SelectedValue = 3 Then ' Client/Project view
If Server.HtmlDecode(e.Row.Cells(2).Text) = dr(r)("ProjectName") And dr(r)("ProjectTypeID") < 4 Then
bClientProject = True
End If
Else
If dr(r)("ProjectTypeID") < 4 Then ' Client project
bClientProject = True
End If
End If
End If
Next
Dim sInfo As String = ""
For r = 0 To dr.GetUpperBound(0)
' Employee Projects / Months
If dr(r)("Month") = dDateCurrent.Month And dr(r)("Year") = dDateCurrent.Year Then
bProjectFoundMonth = True
If Me.optGroupBy.SelectedValue < 3 Then
' Department / Employee view
If Not IsDBNull(dr(r)("DateStart")) And Not IsDBNull(dr(r)("DateEnd")) Then
If dDateCurrent >= dr(r)("DateStart") And dDateCurrent <= dr(r)("DateEnd") Then
If bClientProject Then
If dr(r)("ProjectTypeID") <= 3 Then 'Client Project
sProject = GetProjectInfoToolTip(dr, r)
sColor1 = dr(r)("ColorHtml")
If Not IsDBNull(dr(r)("FirstRenewalDate")) Then
If Not dDateCurrent < dr(r)("FirstRenewalDate") Then
If dteCurrentNotification < DateTime.Today() Then
dteRenewal = DateTime.Parse(dr(r)("FirstRenewalDate").ToString())
Do Until dteCurrentNotification >= DateTime.Today()
intRenewalCpt += 1
dteCurrentNotification = dteRenewal.AddMonths(intRenewalCpt * dr(r)("RenewEachNbMonths")).AddDays(-1 * dr(r)("DaysNoticeExt"))
dteCurrentEndProj = dteRenewal.AddMonths(intRenewalCpt * dr(r)("RenewEachNbMonths"))
Loop
End If
If dDateCurrent = dteCurrentEndProj And blnIsFirstTime Then
intRenewalCpt += 1
dteCurrentNotification = dteRenewal.AddMonths(intRenewalCpt * dr(r)("RenewEachNbMonths")).AddDays(-1 * dr(r)("DaysNoticeExt"))
dteCurrentEndProj = dteRenewal.AddMonths(intRenewalCpt * dr(r)("RenewEachNbMonths"))
intRenewsEachNbMonths = Integer.Parse(dr(r)("RenewEachNbMonths"))
blnIsFirstTime = False
End If
If dDateCurrent < dteCurrentEndProj And Not blnIsFirstTime Then
sColor1 = dr(r)("ColorHtmlExt")
ElseIf Not blnIsFirstTime Then
sColor1 = "#FFFFFF"
sProject = "No Assignment"
End If
End If
End If
DailyHoursTBP = dr(r)("DailyHoursTBP")
DateEnd = dr(r)("DateEnd")
DaysNoticeExt = dr(r)("DaysNoticeExt")
TotalHoursMonth = dr(r)("TotalHoursMonth")
End If
Else
If dr(r)("ProjectTypeID") >= 4 Then ' Internal Project
sProject = dr(r)("ProjectName")
sColor1 = dr(r)("ColorHtml")
DailyHoursTBP = dr(r)("DailyHoursTBP")
DateEnd = dr(r)("DateEnd")
DaysNoticeExt = dr(r)("DaysNoticeExt")
TotalHoursMonth = dr(r)("TotalHoursMonth")
End If
End If
End If
End If
If dr(r)(14 + dDateCurrent.Day) > 4 Then
If dr(r)("ProjectTypeID") >= 4 Then ' Internal Project
sProject = dr(r)("ProjectName")
Else
sProject = GetProjectInfoToolTip(dr, r)
End If
sColor1 = dr(r)("ColorHtml")
If Not IsDBNull(dr(r)("FirstRenewalDate")) Then
If Not dDateCurrent < dr(r)("FirstRenewalDate") Then
If dteCurrentNotification < DateTime.Today() Then
dteRenewal = DateTime.Parse(dr(r)("FirstRenewalDate").ToString())
Do Until dteCurrentNotification >= DateTime.Today()
intRenewalCpt += 1
dteCurrentNotification = dteRenewal.AddMonths(intRenewalCpt * dr(r)("RenewEachNbMonths")).AddDays(-1 * dr(r)("DaysNoticeExt"))
dteCurrentEndProj = dteRenewal.AddMonths(intRenewalCpt * dr(r)("RenewEachNbMonths"))
Loop
End If
If dDateCurrent = dteCurrentEndProj And blnIsFirstTime Then
intRenewalCpt += 1
dteCurrentNotification = dteRenewal.AddMonths(intRenewalCpt * dr(r)("RenewEachNbMonths")).AddDays(-1 * dr(r)("DaysNoticeExt"))
dteCurrentEndProj = dteRenewal.AddMonths(intRenewalCpt * dr(r)("RenewEachNbMonths"))
intRenewsEachNbMonths = Integer.Parse(dr(r)("RenewEachNbMonths"))
blnIsFirstTime = False
End If
If dDateCurrent < dteCurrentEndProj And Not blnIsFirstTime Then
sColor1 = dr(r)("ColorHtmlExt")
ElseIf Not blnIsFirstTime Then
sColor1 = "#FFFFFF"
sProject = "No Assignment"
End If
End If
End If
DailyHoursTBP = dr(r)("DailyHoursTBP")
DateEnd = dr(r)("DateEnd")
DaysNoticeExt = dr(r)("DaysNoticeExt")
TotalHoursMonth = dr(r)("TotalHoursMonth")
TSID = dr(r)("TSID")
If Me.optMonths.SelectedValue = 1 Then ' One month view
Hours = Hours + Math.Round(dr(r)(14 + dDateCurrent.Day), 2, MidpointRounding.AwayFromZero)
Else
Hours = Hours + Math.Round(dr(r)(14 + dDateCurrent.Day), 1, MidpointRounding.AwayFromZero)
End If
HoursMonth = HoursMonth + dr(r)(14 + dDateCurrent.Day)
Exit For
End If
TSID = dr(r)("TSID")
If Me.optMonths.SelectedValue = 1 Then ' One month view
Hours = Hours + Math.Round(dr(r)(14 + dDateCurrent.Day), 2, MidpointRounding.AwayFromZero)
Else
Hours = Hours + Math.Round(dr(r)(14 + dDateCurrent.Day), 1, MidpointRounding.AwayFromZero)
End If
HoursMonth = HoursMonth + dr(r)(14 + dDateCurrent.Day)
Else
' Client / Project view
If Not IsDBNull(dr(r)("DateStart")) And Not IsDBNull(dr(r)("DateEnd")) Then
If dDateCurrent >= dr(r)("DateStart") And dDateCurrent <= dr(r)("DateEnd") Then
If bClientProject Then
If dr(r)("ProjectTypeID") <= 3 Then 'Client Project
' START someone's name changes
If Server.HtmlDecode(e.Row.Cells(2).Text) = dr(r)("ProjectName") AndAlso Server.HtmlDecode(e.Row.Cells(1).Text) = dr(r)("CustomerName") Then
' STOP someone's name changes
sProject = GetProjectInfoToolTip(dr, r)
sColor1 = dr(r)("ColorHtml")
If Not IsDBNull(dr(r)("FirstRenewalDate")) Then
If Not dDateCurrent < dr(r)("FirstRenewalDate") Then
If dteCurrentNotification < DateTime.Today() Then
dteRenewal = DateTime.Parse(dr(r)("FirstRenewalDate").ToString())
Do Until dteCurrentNotification >= DateTime.Today()
intRenewalCpt += 1
dteCurrentNotification = dteRenewal.AddMonths(intRenewalCpt * dr(r)("RenewEachNbMonths")).AddDays(-1 * dr(r)("DaysNoticeExt"))
dteCurrentEndProj = dteRenewal.AddMonths(intRenewalCpt * dr(r)("RenewEachNbMonths"))
Loop
End If
If dDateCurrent = dteCurrentEndProj And blnIsFirstTime Then
intRenewalCpt += 1
dteCurrentNotification = dteRenewal.AddMonths(intRenewalCpt * dr(r)("RenewEachNbMonths")).AddDays(-1 * dr(r)("DaysNoticeExt"))
dteCurrentEndProj = dteRenewal.AddMonths(intRenewalCpt * dr(r)("RenewEachNbMonths"))
intRenewsEachNbMonths = Integer.Parse(dr(r)("RenewEachNbMonths"))
blnIsFirstTime = False
End If
If dDateCurrent < dteCurrentEndProj And Not blnIsFirstTime Then
sColor1 = dr(r)("ColorHtmlExt")
ElseIf Not blnIsFirstTime Then
sColor1 = "#FFFFFF"
sProject = "No Assignment"
End If
End If
End If
DailyHoursTBP = dr(r)("DailyHoursTBP")
DateEnd = dr(r)("DateEnd")
DaysNoticeExt = dr(r)("DaysNoticeExt")
TotalHoursMonth = dr(r)("TotalHoursMonth")
End If
End If
Else
End If
End If
End If
If dr(r)(14 + dDateCurrent.Day) > 4 Then
If Server.HtmlDecode(e.Row.Cells(2).Text) = dr(r)("ProjectName") Or dr(r)("ProjectTypeID") = 6 Then
sColor1 = dr(r)("ColorHtml")
If Not IsDBNull(dr(r)("FirstRenewalDate")) Then
If Not dDateCurrent < dr(r)("FirstRenewalDate") Then
If dteCurrentNotification < DateTime.Today() Then
dteRenewal = DateTime.Parse(dr(r)("FirstRenewalDate").ToString())
Do Until dteCurrentNotification >= DateTime.Today()
intRenewalCpt += 1
dteCurrentNotification = dteRenewal.AddMonths(intRenewalCpt * dr(r)("RenewEachNbMonths")).AddDays(-1 * dr(r)("DaysNoticeExt"))
dteCurrentEndProj = dteRenewal.AddMonths(intRenewalCpt * dr(r)("RenewEachNbMonths"))
Loop
End If
If dDateCurrent = dteCurrentEndProj And blnIsFirstTime Then
intRenewalCpt += 1
dteCurrentNotification = dteRenewal.AddMonths(intRenewalCpt * dr(r)("RenewEachNbMonths")).AddDays(-1 * dr(r)("DaysNoticeExt"))
dteCurrentEndProj = dteRenewal.AddMonths(intRenewalCpt * dr(r)("RenewEachNbMonths"))
intRenewsEachNbMonths = Integer.Parse(dr(r)("RenewEachNbMonths"))
blnIsFirstTime = False
End If
If dDateCurrent < dteCurrentEndProj And Not blnIsFirstTime Then
sColor1 = dr(r)("ColorHtmlExt")
ElseIf Not blnIsFirstTime Then
sColor1 = "#FFFFFF"
sProject = "No Assignment"
End If
End If
End If
DailyHoursTBP = dr(r)("DailyHoursTBP")
DateEnd = dr(r)("DateEnd")
DaysNoticeExt = dr(r)("DaysNoticeExt")
TotalHoursMonth = dr(r)("TotalHoursMonth")
TSID = dr(r)("TSID")
If Me.optMonths.SelectedValue = 1 Then ' One month view
Hours = Hours + Math.Round(dr(r)(14 + dDateCurrent.Day), 2, MidpointRounding.AwayFromZero)
Else
Hours = Hours + Math.Round(dr(r)(14 + dDateCurrent.Day), 1, MidpointRounding.AwayFromZero)
End If
HoursMonth = HoursMonth + dr(r)(14 + dDateCurrent.Day)
Exit For
End If
End If
TSID = dr(r)("TSID")
If Server.HtmlDecode(e.Row.Cells(2).Text) = dr(r)("ProjectName") Then
If Me.optMonths.SelectedValue = 1 Then ' One month view
Hours = Hours + Math.Round(dr(r)(14 + dDateCurrent.Day), 2, MidpointRounding.AwayFromZero)
Else
Hours = Hours + Math.Round(dr(r)(14 + dDateCurrent.Day), 1, MidpointRounding.AwayFromZero)
End If
If dr(r)("ProjectTypeID") >= 4 Then ' Internal Project
HoursInternalMonth = HoursInternalMonth + dr(r)(14 + dDateCurrent.Day)
End If
HoursClientMonth = HoursClientMonth + dr(r)(14 + dDateCurrent.Day)
HoursMonth = HoursMonth + dr(r)(14 + dDateCurrent.Day)
End If
End If
End If
Next ' Next record in Timesheets/Projects Employee
bgColor = Drawing.ColorTranslator.FromHtml(sColor1)
e.Row.Cells(i).BackColor = bgColor
If Me.GridView1.HeaderRow.Cells(i).BackColor <> Drawing.Color.Gray Then
If dDateCurrent = dteCurrentNotification And Not blnIsFirstTime Then
e.Row.Cells(i).ToolTip = "Passed this deadline, the contract will be automatically prolonged for " & _
intRenewsEachNbMonths & " month(s)"
Else
e.Row.Cells(i).ToolTip = sProject
End If
HoursTBPMonth = HoursTBPMonth + DailyHoursTBP
End If
e.Row.Cells(i).Font.Size = iFontSizeHours
e.Row.Cells(i).ForeColor = Drawing.Color.White
e.Row.Cells(i).HorizontalAlign = HorizontalAlign.Center
If Me.chkHours.Checked Then
If dDateCurrent = dteCurrentNotification And Not blnIsFirstTime Then
e.Row.Cells(i).Text = IIf(Hours > 0, "<span style=""color: Black;"">* </style>" + Hours.ToString, "<span style=""color: Black;"">*</style>")
Else
e.Row.Cells(i).Text = IIf(Hours > 0, Hours.ToString, "")
End If
End If
Else
' No projects assigned
e.Row.Cells(i).ToolTip = sProject
e.Row.Cells(i).BackColor = Drawing.ColorTranslator.FromHtml("#FFFFFF")
End If
If iDayofWeek = 7 Or iDayofWeek = 1 Then
e.Row.Cells(i).ToolTip = "Weekend"
e.Row.Cells(i).BackColor = Drawing.Color.Gray
e.Row.Cells(i).Width = 20
Else
If Me.GridView1.HeaderRow.Cells(i).BackColor = Drawing.Color.Gray Then
'Public Holiday
bgColor = Drawing.Color.Gray
e.Row.Cells(i).ToolTip = "Public Holiday"
e.Row.Cells(i).BackColor = bgColor
End If
e.Row.Cells(i).Width = DayWidth
End If
End If
dDateCurrent = DateAdd(DateInterval.Day, 1, dDateCurrent)
If iMonth <> dDateCurrent.Month And Me.chkTotals.Checked Then
' TOTALS: Total column month
i = i + 1
If bProjectFoundMonth = True Then
e.Row.Cells(i).Attributes("onmouseover") = "this.style.cursor='hand';this.style.textDecoration='underline';this.style.color='blue'"
e.Row.Cells(i).Attributes("OnClick") = "javascript:location.href='Timesheet.aspx?t=e&tsid=" & TSID.ToString & "'"
Dim sTSClosedLabel As String = ""
If HoursMonth < ((WorkPerc / 100) * HoursTBPMonth) Then
' Timesheet not completed, i.e. not all hours performed
If bTSClosed Then
e.Row.Cells(i).ForeColor = Drawing.ColorTranslator.FromHtml("#006464")
sTSClosedLabel = "Timesheet closed" & vbCrLf
e.Row.Cells(i).Attributes("onmouseout") = "this.style.textDecoration='none';this.style.color='#006464'"
e.Row.Cells(i).ToolTip = sTSClosedLabel & sb("Remaining hours: ", Math.Round(((WorkPerc / 100) * HoursTBPMonth) - HoursMonth, 2, MidpointRounding.AwayFromZero).ToString, vbCrLf, "Click to open the Timesheet")
Else
If Me.optGroupBy.SelectedValue = 3 Then ' Client/Project view
If TotalHoursMonth < ((WorkPerc / 100) * HoursTBPMonth) Then
e.Row.Cells(i).ForeColor = Drawing.ColorTranslator.FromHtml("#E60000")
e.Row.Cells(i).Attributes("onmouseout") = "this.style.textDecoration='none';this.style.color='#E60000'"
Else
e.Row.Cells(i).ForeColor = Drawing.Color.Black
e.Row.Cells(i).Attributes("onmouseout") = "this.style.textDecoration='none';this.style.color='black'"
End If
e.Row.Cells(i).ToolTip = "Click to open the Timesheet"
Else
' Display in red
e.Row.Cells(i).ForeColor = Drawing.ColorTranslator.FromHtml("#E60000")
e.Row.Cells(i).Attributes("onmouseout") = "this.style.textDecoration='none';this.style.color='#E60000'"
e.Row.Cells(i).ToolTip = sb("Remaining hours: ", Math.Round(((WorkPerc / 100) * HoursTBPMonth) - HoursMonth, 2, MidpointRounding.AwayFromZero).ToString, vbCrLf, "Click to open the Timesheet")
End If
End If
Else
' Timesheet completed, i.e. hours performed
If bTSClosed Then
' Timesheet closed
e.Row.Cells(i).ForeColor = Drawing.ColorTranslator.FromHtml("#006464")
sTSClosedLabel = "Timesheet closed" & vbCrLf
e.Row.Cells(i).Attributes("onmouseout") = "this.style.textDecoration='none';this.style.color='#006464'"
Else
e.Row.Cells(i).ForeColor = Drawing.Color.Black
e.Row.Cells(i).Attributes("onmouseout") = "this.style.textDecoration='none';this.style.color='black'"
End If
If HoursMonth > ((WorkPerc / 100) * HoursTBPMonth) Then
e.Row.Cells(i).ToolTip = sb("Additional hours: ", Math.Round(Math.Abs(((WorkPerc / 100) * HoursTBPMonth) - HoursMonth), 2, MidpointRounding.AwayFromZero).ToString, vbCrLf, sb(sTSClosedLabel, "Click to open the Timesheet"))
Else
e.Row.Cells(i).ToolTip = sTSClosedLabel & "Click to open the Timesheet"
End If
End If
e.Row.Cells(i).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(i).Font.Size = iFontSizeHours
e.Row.Cells(i).Font.Bold = True
HoursMonth = HoursMonth - HoursInternalMonth ' Test
If Me.optMonths.SelectedValue = 1 Then ' One month view
HoursMonth = Math.Round(HoursMonth, 2, MidpointRounding.AwayFromZero)
If InStr(HoursMonth.ToString, ".") = 0 Then
e.Row.Cells(i).Text = IIf(HoursMonth >= 0, HoursMonth.ToString & ".00", "")
Else
e.Row.Cells(i).Text = IIf(HoursMonth >= 0, HoursMonth.ToString("#.00"), "")
End If
Else
HoursMonth = Math.Round(HoursMonth, 1, MidpointRounding.AwayFromZero)
If InStr(HoursMonth.ToString, ".") = 0 Then
e.Row.Cells(i).Text = IIf(HoursMonth >= 0, HoursMonth.ToString & ".0", "")
Else
e.Row.Cells(i).Text = IIf(HoursMonth >= 0, HoursMonth.ToString, "")
End If
End If
End If
e.Row.Cells(i).BackColor = Drawing.ColorTranslator.FromHtml("#8ECBDD")
HoursMonth = 0
HoursTBPMonth = 0
End If
i = i + 1
Loop
End If
End Select
End Sub
Well this is enough to keep the forum busy for few days I believe.
modified 21-Jun-23 3:47am.
|
|
|
|
|
That's terrible!
I mean...VB?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Wow, what a beast. My deepest condolences.
A dogged, arrogant belief in self and the childlike idealism that comes with not knowing my limits. This is my greatest blessing, my priceless attribute.
|
|
|
|
|
"Swiss made" implies elgance in design, using the least amount of parts in a well-thought out fashion.
This is more German made, where the engineering uses the most amount of parts possible to do the simplest of jobs.
The breech of a certain German artillery piece (can't remember which) was made with 192 parts. The equivilent artillery piece on the U.S. side used 48. The Swiss probably could have done it in 20.
|
|
|
|
|