Gantt chart in vb.net windows application - vb.net

I am looking for developing Gantt chart application in vb.net windows application.
I wants to know is there any free third party tool or some demo application so that I can learn about it.

You can use System.Windows.Forms.DataVisualization.Charting to do so. Here is some sample code.
Dim newSeries As New Series
openConn()'opens the connection
openRS("SELECT * FROM Data")'pull data from database
Do Until rs.EOF
newSeries = New Series'create a new dataSeries
yPlot1 = CDbl(rs.Fields("Start Date").Value.ToOADate())'set beginning of bar
yPlot2 = CDbl(DateAdd(DateInterval.Day, rs.Fields("Duration").Value, rs.Fields("Start Date").Value).ToOADate())'set end of bar
newSeries.ChartType = SeriesChartType.RangeBar
newSeries.YValuesPerPoint = 2
newSeries.CustomProperties = "DrawSideBySide=false"
xOrdinal = rs.Fields("Ordinal").Value
newSeries.Points.AddXY(xOrdinal, yPlot1, yPlot2)
newSeries.Points(0).ToolTip = rs.Fields("Task Name").Value.ToString
newSeries.Name = rs.Fields("Task Name").Value.ToString
newSeries.Points(0).Color = Color.FromKnownColor(DirectCast([Enum].Parse(GetType(KnownColor), CStr(rs.Fields("Color").Value.ToString)), KnownColor))
newSeries.Points(0).AxisLabel = rs.Fields("Ordinal Name").Value.ToString
seriesList.Add(newSeries)
rs.MoveNext()
Loop
rs = Nothing
cn.Close()
cn = Nothing
Chart1.Series.Clear()
For Each plotSeries As Series In seriesList
Chart1.Series.Add(plotSeries)
Next
Chart1.ChartAreas(0).AxisX.Interval = 1
Chart1.ChartAreas(0).AxisY.Interval = 7
Chart1.ChartAreas(0).AxisX.IsReversed = True
Chart1.ChartAreas(0).AxisY.IsStartedFromZero = False
Chart1.ChartAreas(0).AxisY.IsMarginVisible = False
Chart1.ChartAreas(0).AxisY.IntervalType = DateTimeIntervalType.Days
Chart1.ChartAreas(0).AxisY.Minimum = CDbl(#4/1/2012#.ToOADate())
Chart1.ChartAreas(0).AxisY.Maximum = CDbl(#6/30/2012#.ToOADate())
Chart1.ChartAreas(0).AxisY.LabelStyle.Format = "ddd M/d"
Chart1.Update()
You will need a Chart control on your form (Chart1). And of course, your data may be different, but this may give you the step you are missing. You can also check out the following document for further details.
http://wiki.visualwebgui.com/pages/images/6/6a/MSChartsGanttChartAndPrinting.pdf

You can easily draw GANTT chart using GDI API in VB.NET. Take a look at codeproject article.

Related

OpenXML: Losing Custom Document Property After Editing Word Document

Using DocumentFormat.OpenXML, I am trying to add a custom property to a Word document and then later read the property. The following code "appears" to do just that:
Dim os As OpenSettings = New OpenSettings() With {
.AutoSave = False
}
Dim propVal As String = "Test Value"
Using doc As WordprocessingDocument = WordprocessingDocument.Open(filename, True, os)
Dim cPart As CustomFilePropertiesPart = doc.CustomFilePropertiesPart
If cPart Is Nothing Then
cPart = doc.AddCustomFilePropertiesPart
cPart.Properties = New DocumentFormat.OpenXml.CustomProperties.Properties()
End If
Dim cPart As CustomFilePropertiesPart = doc.CustomFilePropertiesPart
Dim cProps As Properties = cPart.Properties
For Each prop As CustomDocumentProperty In cProps
If prop.Name = "TranscriptID" Then
prop.Remove()
Exit For
End If
Next
Dim newProp As CustomDocumentProperty = New CustomDocumentProperty() With {
.Name = "TranscriptID"
}
newProp.VTBString = New VTBString(propVal)
newProp.FormatId = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"
cProps.AppendChild(newProp)
Dim pid As Integer = 2
For Each item As CustomDocumentProperty In cProps
item.PropertyId = pid
pid += 1
Next
cProps.Save()
End Using
This code is modeled after code found here:
https://learn.microsoft.com/en-us/office/open-xml/how-to-set-a-custom-property-in-a-word-processing-document
It appears to work in this scenario:
Execute code from above.
Execute code from above again.
At #2 I expect to find the CustomFilePropertiesPart and the property value and my expectation is met.
The problem appears in this scenario:
Execute code from above.
Open document using Microsoft Word, save and close.
Execute code from above again.
What happens in this scenario is that the CustomFilePropertiesPart is missing, whereas it should be found. It is as if Microsoft Word does not successfully read this object, so when the document is save, the object is lost. This suggests to me that there is something that there is something wrong with my code. If you can see what it is, or if you have a comparable working example that I could compare it with, I would appreciate hearing from you. I feel like I correctly followed the Microsoft example, but obviously I did not and I am having trouble seeing where I departed. Thanks.
OK, I found this wonderful tool called the Office Productivity Tool. It has a code generation feature, so I was able to compare what I was doing with what Word does. Basically the problem was with setting the property value. This snippet does the trick:
Dim cProps As Properties = cPart.Properties
Dim val As DocumentFormat.OpenXml.VariantTypes.VTLPWSTR = New DocumentFormat.OpenXml.VariantTypes.VTLPWSTR
val.Text = tr.ID.ToString
Dim newProp As CustomDocumentProperty = New CustomDocumentProperty() With {
.Name = "TranscriptID",
.FormatId = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"
}
newProp.Append(val)
cProps.AppendChild(newProp)

How to select a tray on a printer thorugh code when printing from a word document in VB (VS2019)

Hi I'm trying to create a word document and then print it with VB in visual studio 2019.
Creation works ok, the document saves fine, and prints fine to the general tray but I cannot get the application to send the print job to a specified tray. the prints will just come out of the default paper try
the customers have an array of different printer makes and models
ive tried printing the document through word, ive also tried changing the printer itself on the computer to set the tray then change it back after
TRY 1
Dim intTray As Integer = varibleNumber
If intTray = 1 Then
oWord.ActiveDocument.PageSetup.FirstPageTray = Word.WdPaperTray.wdPrinterUpperBin
oWord.ActiveDocument.PageSetup.OtherPagesTray = Word.WdPaperTray.wdPrinterUpperBin
ElseIf intTray = 2 Then
oWord.ActiveDocument.PageSetup.FirstPageTray = Word.WdPaperTray.wdPrinterMiddleBin
oWord.ActiveDocument.PageSetup.OtherPagesTray = Word.WdPaperTray.wdPrinterMiddleBin
ElseIf intTray = 3 Then
oWord.ActiveDocument.PageSetup.FirstPageTray = Word.WdPaperTray.wdPrinterLowerBin
oWord.ActiveDocument.PageSetup.OtherPagesTray = Word.WdPaperTray.wdPrinterLowerBin
Else
'else print default tray
oWord.ActiveDocument.p.PageSetup.FirstPageTray = Word.WdPaperTray.wdPrinterDefaultBin
oWord.ActiveDocument.PageSetup.OtherPagesTray = Word.WdPaperTray.wdPrinterDefaultBin
End If
TRY 2
Dim intTray As Integer = varibleNumber
Dim oPS As New System.Drawing.Printing.PrinterSettings
If intTray = 1 Then
oPS.DefaultPageSettings.PaperSource = oPS.DefaultPageSettings.PrinterSettings.PaperSources.Item("Tray 1")
oWord.ActiveDocument.PageSetup.FirstPageTray = "Tray 1"
oWord.ActiveDocument.PageSetup.OtherPagesTray = "Tray 1"
ElseIf intTray = 2 Then
oPS.DefaultPageSettings.PaperSource = oPS.DefaultPageSettings.PrinterSettings.PaperSources.Item("Tray 2")
oWord.ActiveDocument.PageSetup.FirstPageTray = "Tray 2"
oWord.ActiveDocument.PageSetup.OtherPagesTray = "Tray 2"
ElseIf intTray = 3 Then
oPS.DefaultPageSettings.PaperSource = oPS.DefaultPageSettings.PrinterSettings.PaperSources.Item("Tray 3")
oWord.ActiveDocument.PageSetup.FirstPageTray = "Tray 3"
oWord.ActiveDocument.PageSetup.OtherPagesTray = "Tray 3"
Else
'else print default tray
oPS.DefaultPageSettings.PaperSource = oPS.DefaultPageSettings.PrinterSettings.PaperSources.Item("Automatically Select")
End If
modPrint.printWordDoc(oWord)
Pages just come out of the main printer tray.
Any help much appreciated
One quick solution that pops to my mind is to use VBA Printer Setup Dialog to change the Tray on your printer settings. Try executing this line of code and change the options on the printer you're using:
Application.Dialogs(xlDialogPrinterSetup).Show
Edit:
Try using this code specific to VB framework. It's a valid starting point, since it allows you to select which print to use:
Public Sub Printing(printer As String)
Try
streamToPrint = New StreamReader(filePath)
Try
printFont = New Font("Arial", 10)
Dim pd As New PrintDocument()
AddHandler pd.PrintPage, AddressOf pd_PrintPage
' Specify the printer to use.
pd.PrinterSettings.PrinterName = printer
If pd.PrinterSettings.IsValid then
pd.Print()
Else
MessageBox.Show("Printer is invalid.")
End If
Finally
streamToPrint.Close()
End Try
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
You can find more info here on Microsoft Documentation.
Hope this helps.
Managed to resolve the issue finally :) each printer has its own tray numbers for every tray, even if they are labelled Tray1 Tray2 etc.
so had to look through the papersources find when the source name equalled the tray number I wanted then grab the rawkind value of that source and use that as the tray number when allocating to the word firstpagetray
Dim intTray As Integer = <tray number i'm looking for>
Dim oPS As New System.Drawing.Printing.PrinterSettings
Dim paper_Source As PaperSource = New PaperSource
Dim i As Integer = 0
For Each ps As PaperSource In oPS.PaperSources
If ps.SourceName.Contains(intTray.ToString) Then
i = ps.RawKind
Exit For
End If
Next
oWord.ActiveDocument.PageSetup.FirstPageTray = i
Hope this helps others with the same issue

Set font size when creating text box programatically in vb.net

I am programming in vb.net with Visual Studio 2015 Community. I am using the code below to programmatically create a text box. My question is - How can I set the text font size when the box is created. I looked around and found the code between the asterisks below, but I'm getting a compile error saying that Font is ambiguous. This is occurring for the first Font in the using f as Font statement and also the Font after the New in the following line. I'm very new to programming in vb and would appreciate any help you could give. Thanks.
tbnum.Location = New System.Drawing.Point(30, tvposition)
tbnum.Size = New Size(45, 20)
'********************
Using f As Font = tbnum.Font
tbnum.Font = New Font(f.FontFamily, f.Size + 2, f.Style)
End Using
'********************
tbnum.Text = panposition.ToString
tbnum.Name = "tbnum" + panposition.ToString
tbnum.AllowDrop = True
tbnum.TabStop = False
tbnum.TextAlign = HorizontalAlignment.Right
tbnum.BackColor = ColorTranslator.FromHtml(myYellow)
tbnum.ReadOnly = True
tbnum.Enabled = False
Controls.Add(tbnum)
The error you are getting means that you have two classes named Font. Do you use any libraries that contain a class called Font?
In all cases, to disambiguate, use the full class name, i.e., System.Drawing.Font like this:
Using f As System.Drawing.Font = tbnum.Font
tbnum.Font = New System.Drawing.Font(f.FontFamily, f.Size + 2, f.Style)
End Using

OTA - ALM 11.52 - Building Graphs through OTA

I am trying to create reports in the 'Analysis View' using OTA and HP ALM 11.52.
I've searched the OTA Reference Documentation and looked for samples online and I've found a few samples, but none seem to work.
There seem to be three methods utilised:
TDConnection.GraphBuilder.BuildGraph(GraphDefinition)
TDConnection.testFactory.BuildSummaryGraph("TS_STATUS", "TS_STATUS", "", 0, myFilter, False, False)
and a third method involving an AnalysisItemFactory object that I can't find anywhere in the OTA documentation.
I've tried the first two and they seem to run without triggering an error, however, no graph appears in ALM.
Is there a difference between these methods and which is the cleanest method?
Here are my attempts so far:
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Method 1: GraphBuilder
'Set GB = QCConnection.GraphBuilder
'Set G1 = GB.CreateGraphDefinition(2, 0)
'G1.Property(0) = "TS_NAME"
'G1.Property(1) = "TC_STATUS"
'Set tsf = QCConnection.TestSetFactory
'Set myFilter = tsf.Filter
'myFilter.Filter ("TC_STATUS") = "Not(N/A)"
'G1.Filter = "Filter: Status[Not N/A]"
'Set g = GB.BuildGraph(G1)
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Method 2: BuildSummaryGraph
'Dim testF
'Dim graph1
'Dim Filter
'Set testF = QCConnection.testFactory
'Set myFilter = testF.Filter
'myFilter.Filter("TS_STATUS") = "Not(N/A)"
'Set graph1 = _
'testF.BuildSummaryGraph("TC_NAME", "TS_STATUS", "", 0, myFilter, False, False)
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Method 3: AnalysisItemsFactory? I can't find any documentation on this object, yet I've seen it referenced in other code samples.
'Set aiFolderFact = QCConnection.AnalysisItemFolderFactory
'Set aiFact = QCConnection.AnalysisItemFactory ~~~ This line actually runs fine so I know it at least exists. But I am definitely not using the proper methods below.
'Set G1 = aiFact.AddItem("")
'G1.Field("AI_PARENT_ID") = 1001 'Public
'G1.Field("AI_TYPE") = "Graph"
'G1.Field("AI_SUB_TYPE") = "Progress Graph"
'G1.Field("AI_OWNER") = qcUserName.Value
'G1.Field("AI_MODULE") = "requirement"
'G1.Field("AI_NAME") = "test graph"
'G1.Post
As I mentioned previously, all of these scripts run error free, but I see no graph in the Analysis View. I've also noticed that there seem to be no "Name" or "Path" fields.
I've taken a look at the tables, and there seems to be 'Analysis_Item_Folder' and 'Analysis Items' tables so It's know it's possible to do this through the OTA client. Is there an AnalysisItemFactory and could someone please kindly provide a sample script of what I'm looking for?
I was able to generate a report with the help of this HP ALM forum entry.
As in the forum mentioned it is not an official documented feature of HP ALM. Therefore it can be that in the future it won't work without replacement. Please keep that in mind.
In case the forum entry may get deleted I copied the answer by a user called "delarosa62" here (date of copy 2015/9/8):
Hi MichaelMotes and the rest of the community members.
I developed a VBA code to generate dashboard standard reports automatically. I get the "successful exception" you have mentioned. However my report does not get generated in my hard disk.
I don't get any errors.
I have adapted your Visial Basic Code to VBA using OTA. I have the otareport 1.0 Type Library and otaxml type lib registered in the tools/reference option in the VBA module window.
I am pasting my code below hoping you guys can give me some insight on this. I am not getting any errors. Just the exception which includes a successful completion message.
Sub externalSTDReports()
Dim reqFact
Dim reqFilter
Dim reqList
Dim gTDConn As Object
Set gTDConn = CreateObject("TDApiOle80.TDConnection")
'QC Connection data
login_id = ActiveWorkbook.Sheets("CONFIG").Cells(9, 3).value
login_passwd = ActiveWorkbook.Sheets("CONFIG").Cells(10, 3).value
domain_name = ActiveWorkbook.Sheets("CONFIG").Cells(11, 3).value
project_name = ActiveWorkbook.Sheets("CONFIG").Cells(12, 3).value
server_name = ActiveWorkbook.Sheets("CONFIG").Cells(13, 3).value
gTDConn.InitConnectionEx server_name
gTDConn.login login_id, login_passwd
gTDConn.Connect domain_name, project_name
Set Rep = New OTAREPORTLib.Reporter
Call Rep.SetConnection(gTDConn, 0) ' This line doesn´t return errors. But I don´t know if it is correct
Set RepConf = Rep.ReportConfig
Rep.File = "C:\Users\cris\AppData\Local\Temp\TD_80\4c223b57\Reports\std.html"
Rep.Template = "C:\Users\cris\AppData\Local\Temp\TD_80\4c223b57\Reports\default.xsl"
'******************************************************** filter Reports
Set aiFact = gTDConn.AnalysisItemFolderFactory
Set reportFact = gTDConn.AnalysisItemFactory
Set aiFilter = aiFact.Filter
Set aiList = aiFilter.NewList
Set anf = reportFact.Filter
Dim FilterStr As String
For Each ai In anf.NewList
reportName = ai.Name
reportID = ai.id
If reportName = "tmp" Then
FilterStr = ai.Field("AI_FILTER_DATA")
RepConf.Filter = FilterStr
On Error Resume Next
'i is empty. Don´t know why
i = Rep.Generate(0, 0) MsgBox i & " --- " & Rep.File Debug.Print Rep.File '-------------------- Exit For
End If
Next
Set gTDConn = Nothing
Set aiFact = Nothing
Set reportFact = Nothing
Set aiFilter = Nothing
Set aiList = Nothing Set anf = Nothing
Set RepConfig = Nothing
Set Rep = Nothing
MsgBox "END "
End Sub 'Pls HELP!!
Graphs can be generated under analysis folder, its a bit of a process because you need a sound understanding of the database, XML and OTA API. There is no direct API available for building graphs, I have created the code samples below
https://github.com/sumeet-kushwah/ALM_OTA_Wrapper/blob/master/ALM_Wrapper/Analysis.cs
Check the following functions
CreateDefectAgeGraph
CreateExcelReport
CreateDefectSummaryGraph
CreateSummaryGraph
These functions are called from the tests available below
https://github.com/sumeet-kushwah/ALM_OTA_Wrapper/blob/master/ALM_Wrapper_Tests/ALM_Wrapper_Test.cs
Look for test function
Test_AnalysisAndDashboardScripts
If you have any questions regarding the process, please let me know.

DevExpress SpreadSheetControl Chart set line color /style

DevExpress website is unable to tell me. How can I influence the line color, thickness, etc. of created graphs?
Dim chart As Chart = myworb.Worksheets(1).Charts.Add(Charts.ChartType.ScatterLine)
chart.TopLeftCell = myworb.Worksheets(1).Cells("A83")
chart.BottomRightCell = myworb.Worksheets(1).Cells("F112")
chart.PlotArea.Fill.SetNoFill()
chart.Series.Add(myworb.Worksheets(1)("A1:A71"), myworb.Worksheets(1)("B1:B71"))
chart.Series.Add(myworb.Worksheets(1)("D1:D81"), myworb.Worksheets(1)("E1:E81"))
chart.Series.Add(myworb.Worksheets(1)("G1:G81"), myworb.Worksheets(1)("H1:H81"))
chart.Series.Add(myworb.Worksheets(1)("J1:J71"), myworb.Worksheets(1)("K1:K71"))
chart.Series.Add(myworb.Worksheets(1)("M1:M66"), myworb.Worksheets(1)("N1:N66"))
chart.Title.Visible = False
Dim axisX = chart.PrimaryAxes(0)
axisX.MajorTickMarks = AxisTickMarks.None
axisX.Scaling.AutoMax = False
axisX.Scaling.AutoMin = False
axisX.Scaling.Max = maxX1
axisX.Scaling.Min = minX1
Dim axisY = chart.PrimaryAxes(1)
axisY.MajorTickMarks = AxisTickMarks.None
axisY.Scaling.AutoMax = False
axisY.Scaling.AutoMin = False
axisY.Scaling.Max = maxY1
axisY.Scaling.Min = minY1
Normally I would just create an Excelfile as a template, load it into the control an just fill the values the chart is using as a series. But as I have to scale it manually because Excel autoscale is NOT WORKING, I have to create the whole chart from scratch. I am unable to find information about how I can set colors etc in the chart programatically. Any help is greatly apreciated.
You can set the color and thickness by using ShapeFormat.Outline property of your series objects. Call to ShapeOutlineFill.SetSolidFill method to set the color of your line and use the ShapeOutline.Width property to set the line width.
Here is example:
chart.Series(5).Outline.SetSolidFill(Color.Magenta)
chart.Series(5).Outline.Width = 20
The "lines" are the chart series and can be accessed in the Series property. From there you can change various things about the series including the color. Alternatively you can custom draw series yourself using the CustomDrawSeries event.