Please start using our more robust New Forum, we have put this old forum in archive mode. Thanks.


Welcome Guest Search | Active Topics | Log In

Tag as favorite
Issue in printing the Gantt table & chart
pvenugopal
#1 Posted : Saturday, February 08, 2014 6:36:15 AM

Posts: 6

Hello,

Good day!,

What we are currently facing is , we are getting an exception when we try to expand all nodes of gantt table (by default we are showing the gantt table in collapsed form) and try to print it

the exception is as follows

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)
Timestamp: Sat, 8 Feb 2014 10:51:11 UTC


Message: Unhandled Error in Silverlight Application Dialogs must be user-initiated. at System.Windows.Printing.PrintDocument.PrintInternal(String documentName, PrinterFallbackSettings printerFallbackSettings, Boolean useDefaultPrinter)
at System.Windows.Printing.PrintDocument.Print(String documentName)
at System.Windows.Printing.Reporting.Report.Print()
at PPLGanttProj.MainPage.Print_Closed(Object sender, EventArgs e)
at System.Windows.Controls.ChildWindow.OnClosed(EventArgs e)
at System.Windows.Controls.ChildWindow.Close()
at System.Windows.Controls.ChildWindow.set_DialogResult(Nullable`1 value)
at PPLGanttProj.PrintWindow.OKButton_Click(Object sender, RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName, UInt32 flags)
Line: 1
Char: 1
Code: 0
URI: http://localhost/EwQMS_Inst1/common/ProjectPlanner/EwQMS4.0/PPL/GanttTaskGrid.aspx?ProjId=25&UsrId=123&ClsId=2&Mode=tracking&RespType=0&languageId=1&ProductId=10&SiteId=1&IsTemplate=0



Below is our code for printing



private void btnPrint_Click(object sender, RoutedEventArgs e)
{
this.gcTaskGrid.ExpandAll();



PrintWindow Print = new PrintWindow();
Print.Show();
Print.Closed += new EventHandler(Print_Closed);


}


void Print_Closed(object sender, EventArgs e)
{

if (gintPrintOption == 6) return;
busyIndicator.IsBusy = true;
PrintOptions prtopt = PrintOptions.WYSIWYG;
//PrintOptions is enum type
this.OnBeforeGanttPrint(this.gcTaskGrid);
switch (gintPrintOption)
{
case 0:
PrintAllTasksInProjectGantt();
prtopt = PrintOptions.Chart;
break;
case 1: prtopt = PrintOptions.VisibleChart;
break;
case 2: prtopt = PrintOptions.WYSIWYG;
break;
case 3:
PrintAllTasksInProjectGantt();
prtopt = PrintOptions.Full;
break;
case 4: prtopt = PrintOptions.Full2;
break;
case 5: prtopt = PrintOptions.Grid;
break;
}

double width = 800;
double height = 900;


GanttPrintVisuals visuals = new GanttPrintVisuals(this.gcTaskGrid, prtopt, Size.Empty);


List<UIElement> list = new List<UIElement>();

int i = 0;
while (visuals.IsPageCountValid == false)
{
UIElement pageVisual = visuals.GetVisual(i++, width, height);

// Convert the UIElement to an Image immediately and add it to a Canvas:
WriteableBitmap w = new WriteableBitmap(pageVisual, new TranslateTransform());


Canvas c = new Canvas();

c.Children.Add(new Image() { Source = w, MaxWidth = width, MaxHeight = height, Stretch = Stretch.None });


list.Add(c);
}

Report.ItemsSource = list;

Report.Print();
}



DateTime ComputedStartTime = DateTime.MinValue;
DateTime ComputedEndTime = DateTime.MinValue;
private void PrintAllTasksInProjectGantt()
{

ComputedStartTime = this.gcTaskGrid.GanttChart.ComputedStartTime;
ComputedEndTime = this.gcTaskGrid.GanttChart.ComputedEndTime;
// First compute the earliest start and the latest end in all the tasks.
DateTime startTimes = ((ActivitiesCollection)this.gcTaskGrid.Model.Activities).StartTime;
DateTime endTimes = ((ActivitiesCollection)this.gcTaskGrid.Model.Activities).EndTime;
// Set the end time.
SetEndTime(endTimes, this.gcTaskGrid);
// Set the start time.
this.gcTaskGrid.GanttChart.SetStartTime(startTimes);
// this.gcTaskGrid.Print(PrintOptions.Chart);
}
private void SetEndTime(DateTime selEnd, GanttBase gantt)
{
DateTime curStart = gantt.GanttChart.ComputedStartTime;
DateTime curEnd = gantt.GanttChart.ComputedEndTime;

if (selEnd == gantt.GanttChart.ComputedEndTime)
return;

if (selEnd > curStart)
{
// We zoom the time-range when the end-time changes.

TimeScaleType baseTimeScaleType = gantt.GanttChart.BaseTimeScaleType;
double curTimeUnits = TimeComputingUtils.ConvertTimeSpanToTimeUnits(baseTimeScaleType, curEnd - curStart);
double newTimeUnits = TimeComputingUtils.ConvertTimeSpanToTimeUnits(baseTimeScaleType, selEnd - curStart);
double curBaseUnitWidth = gantt.GanttChart.BaseTimeUnitWidth;
// Calcluate the new BaseTimeUnitWidth based on the current time units shown in the view and the current BaseTimeUnitWidth
double newBaseUnitWidth = (curTimeUnits * curBaseUnitWidth) / newTimeUnits;

// Make sure to ensure that the new value falls within the minimum and maximum.
// Note that the minimum and maximum are settable. Set values for minimum and maximum based on the time-scale headers you choose to include in the
// chart's headers and the zoom range you want to allow your end-users to zoom to.
if (newBaseUnitWidth < gantt.BaseTimeUnitWidthMinimum)
newBaseUnitWidth = gantt.BaseTimeUnitWidthMinimum;
if (newBaseUnitWidth > gantt.BaseTimeUnitWidthMaximum)
newBaseUnitWidth = gantt.BaseTimeUnitWidthMaximum;

gantt.BaseTimeUnitWidth = newBaseUnitWidth;

// The above would change the StartTime, so let us apply the starttime again:
gantt.GanttChart.SetStartTime(curStart);
}

}

--------------------
Below is the xaml code

--------------------
<reporting:Report x:Name="Report"
Title="PPL Document">

<reporting:Report.PageHeaderTemplate>
<DataTemplate>
<Grid Margin="1 1 1 20">
<Rectangle Stroke="Gray" />

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<TextBlock Text=""
Grid.RowSpan="2"
FontSize="16"
FontWeight="Bold"
Margin="5,6,5,5"
HorizontalAlignment="Left"
VerticalAlignment="Top" />

<TextBlock Text="{Binding CurrentPageNumber, StringFormat='Page No: {0}'}"
Grid.Row="1"
Margin="5"
HorizontalAlignment="Right"
VerticalAlignment="Top" />


<TextBlock Grid.Row="1" VerticalAlignment="Top"
HorizontalAlignment="Right"
Margin="5"
DataContext="{StaticResource info}"
Text="{Binding Now, StringFormat='DateTime: {0}'}"></TextBlock>
</Grid>
</Grid>
</DataTemplate>
</reporting:Report.PageHeaderTemplate>

<reporting:Report.ItemTemplate>
<DataTemplate>
<!-- The DataContext for this Grid will be a gantt visual.-->
<local:PrintPageContainerGrid HorizontalAlignment="Stretch" Margin="5" Width="850" Height="900">
</local:PrintPageContainerGrid>
</DataTemplate>
</reporting:Report.ItemTemplate>

<reporting:Report.PageFooterTemplate>
<DataTemplate>
<Grid Margin="1 20 1 1">
<Rectangle Stroke="Black" />
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Margin="5">
<TextBlock Text="{Binding CurrentPageNumber, StringFormat='Page {0}'}" />
<TextBlock Text="{Binding TotalPageCount, StringFormat=' of {0}'}" />

</StackPanel>

</Grid>
</DataTemplate>
</reporting:Report.PageFooterTemplate>

<reporting:Report.ReportFooterTemplate>
<DataTemplate>
<Grid Margin="1 20 1 1">
<Rectangle Stroke="Gray" />

<TextBlock Grid.Column="1"
FontSize="10"
Foreground="Black"
Text="Copyright © 2009-2011 Omnex | All Rights Reserved"
TextAlignment="Left" />

</Grid>
</DataTemplate>
</reporting:Report.ReportFooterTemplate>
</reporting:Report>



Kindly help me to resolve this issue!,



Thank you,

Praveen Chandar Venugopal
support
#2 Posted : Monday, February 10, 2014 11:47:45 AM

Posts: 469

Praveen,

Silverlight enforces that the Print dialog is shown only from a user initiated action like Button_Click. See this thread for example:
http://stackoverflow.com...ser-initiated-exception

Apparently, SL doesn't allow you to invoke Print from inside a Print_Closed handler either.

So, you will have to let your users first customize Print settings in your PPLGanttProject.PrintWindow and then again click on another "Print" button to initiate a Print.

Thanks
Support
pvenugopal
#3 Posted : Monday, February 10, 2014 11:23:15 PM

Posts: 6

Hello ,

Good day!,

Yes i understood what you had said.But how come the printing is working when we use the same code but not trying to expand the grid ? and how come it is not working when we try to expand the grid?


Thank you,

Praveen Chandar Venugopal
Bala - RadiantQ
#4 Posted : Tuesday, February 11, 2014 10:25:16 PM

Posts: 393

Praveen,
Silverlight also uses an internal timer to check how long it takes to initiate a Print after the user initiated action (like button click), so when you expand, it probably takes some time (?) and that trips this internal SL timer, preventing the Print.
Bala,
RadiantQ
Tag as favorite
Forum Jump  
Please Email support@radiantq.com for any issues

ugg boots outlet cheap ugg sale ugg boots clearance ugg boots sale ugg boots cheap ugg boots for women uggs for cheap ugg shops cheap ugg boots cheap uggs Official Ugg Outlet ugg Store Buy Cheap UGGs ugg boots uk ugg boots usa ugg Online uggs on sale ugg outlets cheap ugg boot Discount UGG Boots discount uggs