.NET

Hello guys, its been a while since a posted something on this blog. I was working on this project where an item can have as many pictures as possible, as part of the requirement , a report was to be generated to show the item information and its pictures ( in a multicolumn way).

Below are the steps to show pictures in crystal reports (Note that the the data type used is image and hence using datasets as the data source for the reports, the picture can easily be dragged onto the report)

1. To start, the picture is dragged to the detail section of the report as shown in the picture below

2. Then right click on the “detail section” tab and choose the “section expert” as shown in the picture below

3. In the dialog box that appear, make sure the “details” section is selected and on the right hand side, on the “common” tab make sure “Format with Multiple columns “ is checked. The move to the “Layout” tab, make the required changes and make sure in the “printing direction” section you select “across” and down.

4. You are now done, with the reports, run you program and something as shown in the picture below should be shown.

Sometimes in web applications (ASP.NET) we prefer printing a window without some controls that appear on the interface. For example, printing a window by clicking on a print button without showing the print button on the printed document. In this example we are printing a student’s results without showing the Print and the close buttons.

To start, we place the two control in a DIV control.Drag the “DIV” control from the HTML controls section. Name the DIV control by giving a value to ID property as shown below. Place the print and close button in the DIV control.

Note that in creating ASP.NET applications, there are two types of source codes, the VB/C# source code and the HTML code. First we create a script to hide the DIV control as shown below. In the script below the “dv1” is the ID value of the DIV control

Add this script to the HTML source

1: <script language="javascript" type="text/javascript">

2:function hidePrint(){

3: document.getElementById("dv1").style.display='none';

4: window.print();

5: window.close();

6: }

7: </script>

Note that the script should be in between the <head></head> tag of the html source code

Select the print button and go to the html source code and add the onclick property . The value of the onclick property should be the created javascript function (named hidePrint()). The button’s html code should look like the one below after the addition of the onclick property

1: <input type="button" id="Button1" runat="server"

2: value="Print"class="fltbutton" style="width:60px"

3: onclick="javascript:hidePrint();" />

This is all you have to do and you are good to go.

Below is a window showing the student’s results and the Print and the Close Button

Due to flexibility in creating reports with some tools in the .NET framework , using PrintDocument() class in creating reports is fading out. But sometimes you don’t have a choice but to use it. For instance creating reports without any predefined data source or generating reports where needed columns are determined at runtime.

In this post we will go through creating a report using the PrintDocument. Our datasoure will also come from a listview which contains a list of file types and their sizes from an indexed drive. When using the report document everything is drawn to the report interface, thus you draw a string, an image,a line. the difficulty in here also is, you yourself determine at runtime where your text, lines and images should be positioned

To start with, first drag a PrintPreviewDialog control on your form. The control is named “PrintPreview1”.

‘declaring fonts to use in your reports Dim backFont As New Font("Arial", 10, FontStyle.Italic) Dim HeaderFont As New Font("Arial", 20, FontStyle.Bold) Dim normfont As New Font("Times New Roman", 18, FontStyle.Regular)

‘ Calculate the number of lines per page. linesPerPage = e.MarginBounds.Height / normfont.GetHeight(e.Graphics)

Generating random numbers can be sometimes frustrating, especially when you want them to be unique.

Example in this instance is when you give users unique usernames when they register with you websites.

Below is a simple function to generate random numbers. To make these generated random strings unique (for the purpose of your application you can add the row index, when inserting it into a database, to make it unique. In this case you will be generating always unique random variables)

Function Generate() As String‘key_chars, is the length of random numbers u want to generate

Dim i_key As Integer

Dim RandomNo As SingleDim arrIndex As Int16Dim sb As New StringBuilderDim RandomLetter As String

lstLetters = "abcdefghijklmnopqrstuvwxyz"

lstNumber = "0123456789"

LettersArray = Me.Key_Letters.ToCharArray

NumbersArray = Me.lstNumber.ToCharArray

For i_key = 1 To Key_Chars

Randomize()

RandomNo = Rnd()

arrIndex = -1‘the number 101 was randomly chosen

If (CType(Random1 * 101, Integer)) Mod 2 = 0 Then

‘if the number generated from the if condition is even get a letter else get a number

Whatever application you develop been it for the national security or for a one-man provision kiosk, some data should be encrypted. Things like database configuration variables, user login passwords and some application settings. In this article we will go through two methods of encrypting your variable with a basic knowledge in computing. The first been saving your records in bytes and the other in scrambled strings

Saving as bytes

Public SharedFunction encrypt(ByVal password AsString) AsByte()

Dim byteValue() AsByte = Encoding.UTF8.GetBytes(password)

Return byteValue

EndFunction

PublicSharedFunction decrypt(ByVal pass AsByte()) AsString

Dim password AsString = Encoding.UTF8.GetString(pass)

Return password

EndFunction

For example, to encrypt your password fields, in the database design make the data type of the field and image. Then in your code write the simple methods below. You are done. At least you have encrypted the field to some extent; no one can easily get the password by easily checking from the backed

Encrypting Strings

In cases where you want to save your password as strings, or saving some application settings in the “My Settings” one simple way is by encrypting the string by adding a chosen value to each character in the string to change its meaning. Check the methods below