Print a report without preview view and without preview browser view - vb.net

How can I print a report without the preview, and taking the default local printer?
I try to put this code lines, but does´nt work:
Dim rep As New XtraReport1()
rep.DataSource = DataSet
rep.CreateDocument()
rep.Print()
Thank you

I solve my problem with this code:
Imports DevExpress.XtraReports.UI
Imports System.IO
Imports DevExpress.XtraPrinting
Imports System.Data
Imports System.Drawing
Partial Class TPV_Tickets
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim Report As New TicketTPV
' THIS IS TO TAKE THE DEFAULT LOCAL PRINT
Dim instance As New Printing.PrinterSettings
Dim DefaultPrinter As String = instance.PrinterName
' THIS IS TO PRINT THE REPORT
Report.PrinterName = DefaultPrinter
Report.CreateDocument()
Report.PrintingSystem.ShowMarginsWarning = False
Report.Print()
End Sub
End Class

Related

Event 'Load' cannot be found

Getting the error "Event 'Load' cannot be found" referring to "Handles MyBase.Load" Please see attached code. Any help much appreciated!
I have many other applications set up the same way and they all work. However, these were in an older version of Visual Studio.
Option Explicit On
Option Strict On
Imports System, System.IO
Imports System.Text
Public Class Form1
Private Sub cleanXMLDialog_Load(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles MyBase.Load
Main()
End
End Sub
Public Sub Main()
Dim directories() As String = Directory.GetDirectories("C:\")
Dim files() As String = Directory.GetFiles("C:\", "*.dll")
DirSearch("c:\")
End Sub
Sub DirSearch(ByVal sDir As String)
Dim d As String
Dim f As String
Try
For Each d In Directory.GetDirectories(sDir)
For Each f In Directory.GetFiles(d, "*.xml")
'Dim Response As String = MsgBox(f)
Debug.Write(f)
Next
DirSearch(d)
Next
Catch excpt As System.Exception
Debug.WriteLine(excpt.Message)
End Try
End Sub
End Class
Load should happen without this error.
This is the class declaration:
Public Class Form1
It looks like you intend this to inherit from a windows Form type, but there's nothing here to make that happen.
You may want this:
Public Class Form1 Inherits System.Windows.Forms.Form
but even this is unlikely to really accomplish anything. It's not enough just to inherit from the Form type if you don't have any controls are properties set and don't ever show the form.
Did you accidentally create a Console or Class Library project when you mean to create a WinForms project?

vb.net 2017 unable to insert Calendar event

I have looked at all the examples I could find and hobbled together the code below. The first time I ran it a web page asked if I wanted to allow my user to update Google calendar and then it asked me to select an account. After that it just sat there and my windows application never finished painting the screen and displaying the simple button I had placed on a form from which to run the insert calendar event. Now when I run the code it comes up, a small gray window appears and it just sits there. What am I doing wrong?
Imports System.Collections.Generic
Imports System.IO
Imports System.Threading
Imports Google.Apis.Calendar.v3
Imports Google.Apis.Calendar.v3.Data
Imports Google.Apis.Calendar.v3.EventsResource
Imports Google.Apis.Services
Imports Google.Apis.Auth.OAuth2
Imports Google.Apis.Util.Store
Imports Google.Apis.Requests
Public Class Form1
Dim service As CalendarService
Dim GRPS As IList(Of String) = New List(Of String)()
Sub New()
Authenticate()
End Sub
Private Function Authenticate()
GRPS.Add(CalendarService.Scope.Calendar)
Dim credential As UserCredential
Using stream As New FileStream("client_secret.json", FileMode.Open,
FileAccess.Read)
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets, GRPS, "user",
CancellationToken.None, New
FileDataStore("Vanguard")).Result
End Using
' Create the calendar service using an initializer instance
Dim initializer As New BaseClientService.Initializer()
initializer.HttpClientInitializer = credential
initializer.ApplicationName = "Vanguard"
service = New CalendarService(initializer)
Return 0
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
InsertCalendar()
MessageBox.Show("Done")
Application.Exit()
End Sub
Public Sub InsertCalendar()
Dim CalendarEvent As New Data.Event
Dim SDT As New Data.EventDateTime
Dim A As Date = DateSerial(2017, 8, 11)
A = A.AddHours(10)
A = A.AddMinutes(30)
SDT.DateTime = A
Dim b As Date
b = A.AddHours(2)
Dim EDT As New Data.EventDateTime
EDT.DateTime = b
CalendarEvent.Start = SDT
CalendarEvent.End = EDT
CalendarEvent.Id = System.Guid.NewGuid.ToString
CalendarEvent.Description = "Test Event"
Dim list As IList(Of CalendarListEntry) =
service.CalendarList.List().Execute().Items()
service.Events.Insert(CalendarEvent, list(0).Id).Execute()
End Sub
End Class

Not Knowing How to Display Username After Login

I’m still stumbling with this page over and over again. Just couldn’t get the user’s Username (using email as the username) to display on mysupport.aspx page after she’s successfully logged in. The result should look like this with the email showing but it is not retrieving anything:
Email: barb#hotmail.com
Being an amateur, I know I’m missing a big piece of the puzzle but I don’t know what. Am I using the mailLBL.Text = User.Identity.Name.ToString() wrongly? Below are the code-behind:
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data.SqlClient
Partial Class mysupport
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim sConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("TrackTicketsConnectionString2").ConnectionString)
sConnection.Open()
Dim cmdS As String = "Select Email from Users Where Deleted='N'"
Dim cmdCheckmail As New SqlCommand(cmdS, sConnection)
If Session("Ticket") IsNot Nothing Then
mailLBL.Text = User.Identity.Name.ToString()
Else
Response.Redirect("SignIn.aspx")
End If
End Sub
Protected Sub signinBTN_Click(ByVal sender As Object, ByVal e As EventArgs)
Session("Ticket") = Nothing
Response.Redirect("SignIn.aspx")
End Sub
End Class
Any help and guidance is truly appreciated!
What you could do first is study these links:
How to: Implement Simple Forms Authentication
How to use Sessions
There are several things wrong with this code.
Old Code:
Dim cmdS As String = "Select Email from Users Where Deleted='N'"
Dim cmdCheckmail As New SqlCommand(cmdS, sConnection)
If Session("Ticket") IsNot Nothing Then
mailLBL.Text = User.Identity.Name.ToString()
Else
Response.Redirect("SignIn.aspx")
End If
Corrected Code:
If Session("Ticket") Is Nothing Then
Response.Redirect("SignIn.aspx")
Else
Dim cmdS As String = "Select Email from Users Where Deleted='N' AND Username=#Username"
Dim cmdCheckEmail as new SqlCommand(cmdS, sConnection)
cmd.AddParameters(new SqlParameter("#UserName", SqlDbType.VarChar).Value = Session("Ticket")
Dim obj as Object = cmd.ExecuteScalar()
If obj isNot Nothing
mailLBL.Text = Convert.ToString(obj)
End If
End
I hope that helps.

VB silverlight for windows phone

I am writing an application in VB for windows phone 7.5
but it has some bug
Imports System.IO
Imports System.IO.TextReader
Imports System.Xml
Imports System.Windows.RoutedEventArgs
Imports System.Windows.RoutedEvent
Imports System.ComponentModel
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
Imports Microsoft.Phone.Tasks
Imports System.Xml.Linq
Imports System.Net.NetworkInformation
Imports Microsoft.VisualBasic.CompilerService
Partial Public Class MainPage
Inherits PhoneApplicationPage
Public Sub New()
InitializeComponent()
End Sub
Private Sub MainPage_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
Final.Items.Clear()
If NetworkInterface.GetIsNetworkAvailable Then
Dim cl As New WebClient
AddHandler cl.DownloadStringCompleted, AddressOf cl_DownloadStringCompleted
cl.DownloadStringAsync(New Uri("http://web.com/xml.xml"))
Else
MessageBox.Show("check your internet connection")
End If
End Sub
Private Sub cl_DownloadStringCompleted(sender As Object, e As System.Net.DownloadStringCompletedEventArgs)
Dim doc = XDocument.Parse(e.Result)
Dim names = XDocument.Parse(e.Result)
Dim result_name = names.<Data>.<Entry>
For Each result In doc.<Data>.<Entry>.<tag>
Dim item As New ListBoxItem
item.Content = result.Value
AddHandler item.Tap, AddressOf ItemTap
Final.Items.Add(item)
Next
End Sub
Private Sub ItemTap(sender As Object, e As GestureEventArgs)
Dim lbi As New ListBoxItem
lbi = sender
Dim url As New Uri("/" & lbi.Content & ".xaml", UriKind.Relative)
Me.NavigationService.Navigate(url)
End Sub
End Class
it finds a bug at Dim url As New Uri("/" & lbi.Content & ".xaml", UriKind.Relative)
and it says on the report :
Requested operation is not available because the runtime library
function
'Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject'
is not defined.
NOTE :
when i am changing the ItemTap to this :
Private Sub ItemTap(ByRef sender As Object, e As GestureEventArgs)
this error is gone and appears another one :
Method 'Private Sub ItemTap(ByRef sender As Object, e As
System.Windows.Input.GestureEventArgs)' does not have a signature
compatible with delegate 'Delegate Sub EventHandler(Of
System.Windows.Input.GestureEventArgs)(sender As Object, e As
System.Windows.Input.GestureEventArgs)'.
at line : "AddHandler item.Tap, AddressOf ItemTap"
Any ideas why i have this one ??
thank you !
You're trying to combine two strings and an object and it can't do this.
I strongly suspect that lbi.Content (in the line that is erroring) is a TextBlock, so your code says "concatenate a string, a TextBlock and a string together".
I suspect that you want the text that is displayed in the TextBlock, so just cast it accordingly:
"/" & DirectCast(lbi.Content, TextBlock).Text & ".xaml"

how can i use ActiveDirectory

I have an active Directory (window) on the server ..and i want to connect it with my web pages..
this is my vb code:
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Data
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.DirectoryServices ' cannot be found '
Imports System.Runtime.InteropServices
Imports System.Configuration
Imports System.Data.SqlClient
Partial Class Default3
Inherits System.Web.UI.Page
Public Function IsADUser(ByVal UserName As [String], ByVal Password As [String]) As [Boolean]
Dim entry As New DirectoryEntry()
entry.Username = UserName
entry.Password = Password
Dim searcher As New DirectorySearcher(entry)
searcher.Filter = "(objectclass=user)"
Dim Authentecated As [Boolean] = False
Try
searcher.FindOne()
Authentecated = True
Catch ex As COMException
Authentecated = False
End Try
Return (Authentecated)
End Function
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class
The ASP.NET Membership supports Active Directory as well. Check it out:
http://msdn.microsoft.com/en-us/library/ms998360.aspx
To use Active Directory manually, you should add System.DirectoryServices.dll as a reference before.