Groups > Databases > Access Databases and AccessDataSource Control > Re: Complex function to populate dates in a list




Complex function to populate dates in a list

Complex function to populate dates in a list
Tue, 1 Apr 2008 01:37:24 +0000
Hi All,

Depending on the selected product, I have a list of milestones that need to be
achieved during manufacture -- buy parts, assemble, test, etc.  Based on the due
date of the entire project, I would like to populate the deadlines to complete
each of these milestones.  Example.  Widget 'A' takes 10 days to build (2 days
to order parts, 4 for assembly, 2 to test, and 2 for paperwork).  If I say this
product is due on 4/20/08, then I should start to order parts on 4/10, begin
assembly on 4/12, etc.

I believe that I have the logic mostly correct -- I order my returned rows by
"order" (descending) and use a Do/Loop to go through each one.  Each
time I take days from the preceding deadline.  (please tell me if I have any
obvious errors here).  What I really need help with is taking this calculated
deadline and writing it into the table while I have it open.  Do I nest a
SqlString4 into the middle of my OleDbDataReader? 

Any help would be appreciated.  Here is my code (VB):Dim days AsInteger = 0

Dim Date AsDate = Convert.ToDateTime(duedate) 'where due date is pulled in from
a label on the page

Dim WorkOrderNumber AsInteger = Request.QueryString("ID")Dim
ConnString AsString = Utils.GetConnString()Dim SqlString3 AsString =
"SELECT MilestoneOffset FROM (tblWOMilestones) WHERE (WorkOrderNumber = ?)
ORDER BY [Order] DESC"            Using conn3 AsNew
OleDbConnection(ConnString)   Cmd3.CommandType = CommandType.Text  
Cmd3.Parameters.AddWithValue("WorkOrderNumber", WorkOrderNumber)  
Conn3.Open()   Using reader As OleDbDataReader = cmd3.ExecuteReader()      
DoWhile reader.Read()       days = reader("MilestoneOffset")

       Dim newdeadline As Date = Date.AddDays(-days)  

       <<<<<<write newdeadline to table as
“deadline”>>>>>>        date = newdeadline       Loop   

EndUsingEndUsing
Post Reply
Re: Complex function to populate dates in a list
Tue, 1 Apr 2008 17:40:59 +0000
Any help with this function would be greatly appreciated.  Thanks.

I've gone back twice to format my code better with line breaks.  Everytime I
save it reverts back to this jumbled mess.  Sorry for the unreadability.
Post Reply
Re: Complex function to populate dates in a list
Tue, 1 Apr 2008 23:58:50 +0000
Getting closer... Can anybody see why this doesn't work?  I don't get any
errors, but the function does not write anything to my table.  Thanks again.

1                Dim WorkOrderNumber As Integer =
Request.QueryString("ID")
2                Dim ConnString3 As String = Utils.GetConnString()
3                Dim SqlString3 As String = "SELECT * FROM
(tblWOMilestones) WHERE (WorkOrderNumber = ?) ORDER BY [Order] DESC"
4                Dim days As Integer = 0
5                Dim duedate As String =
CType(FormView1.FindControl("DueTextBox"), Label).Text
6                Dim Date1 As Date = Convert.ToDateTime(duedate)
7                Using conn3 As New OleDbConnection(ConnString3)
8                    Using cmd3 As New OleDbCommand(SqlString3, conn3)
9                        cmd3.CommandType = CommandType.Text
10                      
cmd3.Parameters.AddWithValue("WorkOrderNumber", WorkOrderNumber)
11                       conn3.Open()
12                       Using reader As OleDbDataReader = cmd3.ExecuteReader()
13                           Do While reader.Read()
14                               days = reader("MilestoneOffset")
15                               Dim WOMilestoneID As Integer =
reader("WOMilestoneID")
16                               Dim newdeadline As Date = Date1.AddDays(-days)
17                               
18                               '<<<<<update newdeadline into
table>>>>>>
19                               writedeadline(WOMilestoneID, newdeadline)
20   
21                               Date1 = newdeadline
22                           Loop
23                       End Using
24                   End Using
25   
26               End Using
27   
28           End If
29   
30           Dim url As String = Request.Url.ToString
31           Response.Redirect(url)
32       End Sub
33   
34       Private Function writedeadline(ByVal WOMilestoneID As Integer, ByVal
newdeadline As Date) As Object
35   
36           Dim ConnString4 As String = Utils.GetConnString()
37           Dim SqlString4 As String = "UPDATE tblWOMilestones SET
Deadline = @Deadline WHERE WOMilestoneID = @WOMilestoneID"
38           Using conn4 As New OleDbConnection(ConnString4)
39               Using cmd4 As New OleDbCommand(SqlString4, conn4)
40                   cmd4.CommandType = CommandType.Text
41                   cmd4.Parameters.AddWithValue("@WOMilestoneID",
WOMilestoneID)
42                   cmd4.Parameters.AddWithValue("@Deadline",
newdeadline.ToString())
43                   conn4.Open()
44                   cmd4.ExecuteNonQuery()
45               End Using
46           End Using
47   
48           Return Nothing
49       End Function
Post Reply
Re: Complex function to populate dates in a list
Wed, 2 Apr 2008 00:19:43 +0000
Got it!  Thanks for your replies, everyone.

PrivateFunction writedeadline(ByVal WOMilestoneID AsInteger, ByVal newdeadline
AsDate) AsObjectDim ConnString4 AsString = Utils.GetConnString()

Dim SqlString4 AsString = "UPDATE tblWOMilestones SET Deadline = @Deadline
WHERE WOMilestoneID = @WOMilestoneID"Using conn4 AsNew
OleDbConnection(ConnString4)Using cmd4 AsNew OleDbCommand(SqlString4, conn4)

cmd4.CommandType = CommandType.Text

cmd4.Parameters.AddWithValue("@Deadline",
newdeadline.ToString())cmd4.Parameters.AddWithValue("@WOMilestoneID",
WOMilestoneID)

conn4.Open()

cmd4.ExecuteNonQuery()

EndUsing

EndUsing

ReturnNothing

EndFunction
Post Reply
Re: Complex function to populate dates in a list
Wed, 2 Apr 2008 00:28:23 +0000
More internet searching led me to this.  Errors all over the place.  Has anyone
tackled this type of problem before?Dim workordernumber as integer =
Request.QueryString("ID")Dim Date AsDate =
Convert.ToDateTime(duedate)<<<<<<get WO due date 

Dim dv As DataView

dv = New DataView(SageDataSet.Tables("tblWOMilestones"))

dv.Sort = "Order" DESC

dv.RowFilter = "WorkOrderNumber = " & workordernumber 

Dim i As Integer

For i = 0 To dv.count – 1

        Dim days as integer = dv.Item(“MilestoneOffset”)

        Dim newdeadline As Date = Date.AddDays(-days)

        dv.BeginEdit()

        dv.Item(“Deadline”) = newdeadline

        dv.EndEdit()

        date = newdeadlineNext
Post Reply
<< Previous 1 2 Next >>
( Page 1 of 2 )
about | contact