MISSION AND VISION 2012


On this Blog you can gain and collect some ideas, information about different kinds of topics about computer, tutorial and tips that can be applied. You can share your ideas too thru posting comment and feedback to said topic.

Thank You :)

Note : If the Link(s) doesn't work/broken please Comment.

(If this site helps you, please Comment and click the link to say Thanks)
Please Click here to Say Thank You :)



Showing posts with label PROGRAMMING TUTORIALS. Show all posts
Showing posts with label PROGRAMMING TUTORIALS. Show all posts

Friday, June 21, 2013

Get Values and Subtotals in One Shot

If you need to show values with totals and subtotals in a report, you could make two separate queries. But it is safer and quicker to do both in one go.
You might need to produce a report that shows values and calculates subtotals. In Figure, the subtotals are listed at the end of each group.

Table values and subtotals
itemserialNumberprice
Awl110
Awl310
Awlsubtotal20
Bowl210
Bowl510
Bowl610
Bowlsubtotal30
Cowl410
Cowlsubtotal10

For a simple query like this, the time cost of the round trip to the database server may dominate the cost of the query itself. So, making two trips to the database is a lot like going to the bar to buy a drink, walking away, and then going back to the bar for your change.
More than one trip to the database also introduces the possibility that someone else has added a row between your visits. If that happens, your total could be wrong.
A simple UNION will add the subtotals to your result:
mysql> SELECT item, serialNumber, price FROM source
    -> UNION
    -> SELECT item, NULL,         SUM(price)
    ->   FROM source
    ->  GROUP BY item
    -> ORDER BY item;
+------+--------------+-------+
| item | serialNumber | price |
+------+--------------+-------+
| Awl  |         NULL |    20 |
| Awl  |            1 |    10 |
| Awl  |            3 |    10 |
| Bowl |         NULL |    30 |
| Bowl |            2 |    10 |
| Bowl |            5 |    10 |
| Bowl |            6 |    10 |
| Cowl |         NULL |    10 |
| Cowl |            4 |    10 |
+------+--------------+-------+

The database server still has roughly the same amount of work to do as before, but the overall performance should be improved because you have saved the cost of sending a query and getting the results back.
The query works fine. The only slight problem is that subtotals show up as the first row for each item (depending on the SQL implementation you are using). Traditionally, the subtotals show up as the last item in each run.
You can change the ORDER BY expression to c, COALESCE(seq, 1E9). This will ensure that the NULL values in the serialNumber column show up last (1E9 is the number 1,000,000,000). You can have the UNION as a derived table to make it clear that the ORDER BY applies to the whole UNION:
mysql> SELECT item, serialNumber, price FROM(
    ->   SELECT item, serialNumber, price FROM source
    ->   UNION
    ->   SELECT item, NULL,         SUM(price)
    ->     FROM source
    ->    GROUP BY item
    -> ) t
    -> ORDER BY item, COALESCE(serialNumber,1E9);
+------+--------------+-------+
| item | serialNumber | price |
+------+--------------+-------+
| Awl  |            1 |    10 |
| Awl  |            3 |    10 |
| Awl  |         NULL |    20 |
| Bowl |            2 |    10 |
| Bowl |            5 |    10 |
| Bowl |            6 |    10 |
| Bowl |         NULL |    30 |
| Cowl |            4 |    10 |
| Cowl |         NULL |    10 |
+------+--------------+-------+


ROLLUP and GROUPING SETS

SQL Server, MySQL, and DB2 can do this using the WITH ROLLUP clause. Oracle has a GROUPING SETS clause that covers this (DB2 supports this as well).

SQL Server, MySQL, and DB2
In SQL Server, MySQL, and DB2:
mysql> SELECT item, serialNumber, SUM(price)
    ->   FROM source
    ->  GROUP BY item,serialNumber WITH ROLLUP;
+------+--------------+------------+
| item | serialNumber | SUM(price) |
+------+--------------+------------+
| Awl  |            1 |         10 |
| Awl  |            3 |         10 |
| Awl  |         NULL |         20 |
| Bowl |            2 |         10 |
| Bowl |            5 |         10 |
| Bowl |            6 |         10 |
| Bowl |         NULL |         30 |
| Cowl |            4 |         10 |
| Cowl |         NULL |         10 |
| NULL |         NULL |         60 |
+------+--------------+------------+


Oracle and DB2
In Oracle and DB2:
SQL> SELECT item, serialNumber, SUM(price)
  2    FROM source
  3    GROUP BY GROUPING SETS ((item,serialNumber),(item),(  ));

ITEM                           SERIALNUMBER SUM(PRICE)
------------------------------ ------------ ----------
Awl                                       1         10
Awl                                       3         10
Awl                                                 20
Bowl                                      2         10
Bowl                                      5         10
Bowl                                      6         10
Bowl                                                30
Cowl                                      4         10
Cowl                                                10
                                                    60


Hacking the Hack

Of course, there is no reason why you shouldn't include the GRAND TOTAL in another UNION:
mysql> SELECT item, serialNumber, price FROM(
    ->   SELECT item, serialNumber, price FROM source
    ->   UNION
    ->   SELECT item, NULL,         SUM(price)
    ->     FROM source
    ->    GROUP BY item
    ->   UNION
    ->   SELECT NULL, NULL,         SUM(price)
    ->     FROM source
    -> ) t
    -> ORDER BY COALESCE(item,'zzz'), COALESCE(serialNumber,1E9);
+------+--------------+-------+
| item | serialNumber | price |
+------+--------------+-------+
| Awl  |            1 |    10 |
| Awl  |            3 |    10 |
| Awl  |         NULL |    20 |
| Bowl |            2 |    10 |
| Bowl |            5 |    10 |
| Bowl |            6 |    10 |
| Bowl |         NULL |    30 |
| Cowl |            4 |    10 |
| Cowl |         NULL |    10 |
| NULL |         NULL |    60 |
+------+--------------+-------+

But having totals showing in the same column as the values themselves can make for a confusing report. If you can format the subtotals and totals so that they stand out, it can help. But it improves readability if you can put these in different columns.
You can add two more columns to the UNION. It takes a little care to put the NULL values in the right place:
mysql> SELECT item,serialNumber,price,sub,grand FROM (
    ->    SELECT item,serialNumber,price,NULL AS sub,NULL AS grand
    ->      FROM source
    ->    UNION
    ->    SELECT item,NULL,        NULL, SUM(price), NULL
    ->      FROM source
    ->     GROUP BY item
    ->    UNION
    ->    SELECT NULL,NULL,        NULL, NULL,       SUM(price)
    ->      FROM source
    ->  ) t
    ->  ORDER BY COALESCE(item,'zzz'), COALESCE(serialNumber,1E9);
+------+--------------+-------+------+-------+
| item | serialNumber | price | sub  | grand |
+------+--------------+-------+------+-------+
| Awl  |            1 |    10 | NULL |  NULL |
| Awl  |            3 |    10 | NULL |  NULL |
| Awl  |         NULL |  NULL |   20 |  NULL |
| Bowl |            2 |    10 | NULL |  NULL |
| Bowl |            5 |    10 | NULL |  NULL |
| Bowl |            6 |    10 | NULL |  NULL |
| Bowl |         NULL |  NULL |   30 |  NULL |
| Cowl |            4 |    10 | NULL |  NULL |
| Cowl |         NULL |  NULL |   10 |  NULL |
| NULL |         NULL |  NULL | NULL |    60 |
+------+--------------+-------+------+-------+
 
Source : Direct Link 
 
 
*If this site helps you, please click the link below to say Thanks*

Please Register here to Say Thank You :)
 


Friday, May 4, 2012

Store and Retrieve Image in MYSQL Database using Binary Data

Follow the instruction and you may not get an error.

Do this:
>> Go to MySQL Administrator  >> Startup Variable >> Advanced Networking  >>
Change Max. Pocket Size to 4M or 16M  >> Apply Changes >> Exit.

1. Create a table in your MYSQL Database

Database name: "photo"
Table name: "tblpicture"

Fields name and type:

>> "Picture"  as  LONG BLOB    'where you can save the Image using Binary Data

>> "Picturesize" as Integer    'where you can save the File Size of the Image

>> "ID" as Number , check Autoincrement


2. Then Go to Your Visual Basic 6.0


>>You Need:

Two Modules , One Form and One Picture in your Folder name "No Picture.jpg"

>> In your Form you need two "Image"  , Stretch = True

Name: "Image2" and "Image3"

>> three "Command Buttons"

Name: "cmdUpload" and "cmdSave" and "cmdRetrieve"

>>One "CommonDialog"

Name: "CommonDialog1"



3. Code  (Form) >> Copy/Paste

 'Declaration

Option Explicit
Dim picdialog As Integer
Dim PictureFileName As String

Private Sub cmdUpload_Click()
    'For Browsing Pictures

    On Error GoTo errhandler
    CommonDialog1.CancelError = True

    CommonDialog1.Filter = "All Picture Files|*.jpg;*.gif;*.bmp;*.wmf;*.ico|JPEG Images(*.jpg)|*.jpg|Bitmap Images (*.bmp)|*.bmp|Word Meta Files (*.wmf)|*.wmf|GIF Images (*.gif)|*.gif"
    CommonDialog1.DialogTitle = "Insert Picture"
   
   
    CommonDialog1.ShowOpen

            picdialog = 2
            Image2.Visible = True
            Image2.Picture = LoadPicture(CommonDialog1.filename)
            PictureFileName = CommonDialog1.filename
            If Image2.Picture = Picture Then
                Image3.Visible = True
            Else
                Image3.Visible = False
            End If

Exit Sub
errhandler:
    Select Case Err
    Case 32755 '  Dialog Cancelled
        MsgBox "you cancelled the dialog box"
    Case Else
        MsgBox "Unexpected error. Err " & Err & " : " & Error
    End Select
End Sub

Private Sub cmdSave_Click()
       
   
    With rsPhoto
    .AddNew

      If MsgBox("Are you sure you want to save picture?", vbQuestion + vbYesNo, "Save") = vbYes Then
                            If picdialog = 1 Then
                                CommonDialog1.filename = App.Path & "\No Picture.jpg"
                                GetPhoto CommonDialog1.filename, rsPhoto, "Picture", "Picturesize"
                                .Update
                            ElseIf picdialog = 2 Then
                              
                                If Not IsNull(CommonDialog1.filename) Then GetPhoto CommonDialog1.filename, rsPhoto, "Picture", "Picturesize"
                                .Update
                            End If
                          
                  
                  
                    MsgBox "Record Save", vbInformation, "Save"
                    Image3.Picture = LoadPicture(App.Path & "\No Picture.jpg")
                    Image2.Picture = LoadPicture(App.Path & "\No Picture.jpg")
                    Image2.Visible = False
                    Image3.Visible = True
       Else
                        .CancelUpdate
       End If
    End With
End Sub

Private Sub cmdRetrieve_Click()
       

        Image3.Visible = False
        Image2.Visible = True
        If Not IsNull(rsPhoto!Picture) Then FillPhoto rsPhoto, "Picture", "Picturesize", Image2 Else: Image3.Visible = True

End Sub

Private Sub Form_Load()
    picdialog = 1
    Image2.Visible = False
   
    Closerecordset
    Openrecordset ("Select * from tblpicture")
End Sub

Private Sub Form_Unload(Cancel As Integer)
    rsPhoto.Close
    Set rsPhoto = Nothing
    CloseConnection
End Sub



4. Module (Name: "ADOConnection") >> Copy/Paste

Global con As New ADODB.Connection
Global conn As New ADODB.Connection
Global rsPhoto As New ADODB.Recordset
Global imsConnectionString As String

Public Sub main()
    On Error Resume Next
    DoEvents

        imsConnectionString = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=Photo;User='root';Password=''"
        con.ConnectionString = imsConnectionString

    Debug.Print "Connection Object Created"

    con.Open

        If con.State = adStateClosed Then
            MsgBox "Unable to connect to database", vbCritical
            Form1.Show
            Exit Sub
        End If
   
    con.CursorLocation = adUseClient
    Form1.Show
End Sub

Public Sub CloseConnection()
    con.Close
    Set con = Nothing
End Sub

Public Function Openrecordset(YourQuery As String)
    If rsPhoto.State = 0 Then rsPhoto.Open YourQuery, con, adOpenDynamic, adLockOptimistic
End Function

Public Function Closerecordset()
    If rsPhoto.State = 1 Then rsPhoto.Close
End Function


5. Module (Name : "modGenDec") >> Copy/Paste

'Declaration for Save/Load Picture

Public StudentIDselect As String
Public costumerpic As IPictureDisp

Private Declare Function GetTempFileName Lib "kernel32" Alias "GetTempFileNameA" (ByVal lpszPath As String, ByVal lpPrefixString As String, ByVal wUnique As Long, ByVal lpTempFileName As String) As Long
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Public Const MAX_PATH = 260
Public Const BLOCK_SIZE = 10000
Public frm2Show As String

Public Sub FillPhoto(rstMain As Recordset, PFName As String, SizeField As String, picEmp As Image)

On Error Resume Next
Dim bytes() As Byte
Dim file_name As String
Dim file_num As Integer
Dim file_length As Long
Dim num_blocks As Long
Dim left_over As Long
Dim block_num As Long
Dim hgt As Single

    'me.imgPhoto.Visible = False
    Screen.MousePointer = vbHourglass
    DoEvents

    ' Get a temporary file name.
    file_name = TemporaryFileName()

    ' Open the file.
    file_num = FreeFile
    Open file_name For Binary As #file_num

    ' Copy the data into the file.
    file_length = rstMain(SizeField)
    num_blocks = file_length / BLOCK_SIZE
    left_over = file_length Mod BLOCK_SIZE

    For block_num = 1 To num_blocks
        bytes() = rstMain(PFName).GetChunk(BLOCK_SIZE)
        Put #file_num, , bytes()
    Next block_num

    If left_over > 0 Then
        bytes() = rstMain(PFName).GetChunk(left_over)
        Put #file_num, , bytes()
    End If

    Close #file_num

    picEmp.Picture = LoadPicture(file_name)

    Screen.MousePointer = vbDefault

End Sub


Public Sub GetPhoto(filename As String, rstMain As Recordset, FieldName As String, SizeField As String)
On Error Resume Next
Dim file_num As String
Dim file_length As Long
Dim bytes() As Byte
Dim num_blocks As Long
Dim left_over As Long
Dim block_num As Long

    file_num = FreeFile
    Open filename For Binary Access Read As #file_num

    file_length = LOF(file_num)
    If file_length > 0 Then
        num_blocks = file_length / BLOCK_SIZE
        left_over = file_length Mod BLOCK_SIZE

        rstMain(SizeField) = file_length

        ReDim bytes(BLOCK_SIZE)
        For block_num = 1 To num_blocks
            Get #file_num, , bytes()
            rstMain(FieldName).AppendChunk bytes()
        Next block_num

        If left_over > 0 Then
            ReDim bytes(left_over)
            Get #file_num, , bytes()
            rstMain(FieldName).AppendChunk bytes()
        End If

        Close #file_num
    End If
Exit Sub
End Sub

Public Function TemporaryFileName() As String
Dim temp_path As String
Dim temp_file As String
Dim Length As Long

    ' Get the temporary file path.
    temp_path = VBA.Space$(MAX_PATH)
    Length = GetTempPath(MAX_PATH, temp_path)
    temp_path = Left$(temp_path, Length)

    ' Get the file name.
    temp_file = VBA.Space$(MAX_PATH)
    GetTempFileName temp_path, "per", 0, temp_file
    TemporaryFileName = Left$(temp_file, InStr(temp_file, VBA.Chr$(0)) - 1)
End Function




******Remember**********
>> In your "Project Explorer" right side of your window screen,then "Project Property" Right click
 set the "Startup Object" to "Sub Main" then Run your Program


*****Oooopsss!!!********
>> In the "cmdRetrieve_Click()" you can now use your "LOGIC" to retrieve the picture you want :)

ENJOY :)

Wednesday, February 24, 2010

Programming a MS SQL Server 2000 Database Video Tutorial

Author - Mark Long/Certified Instructor
Total Time - 8 Hours

SQL Server Overview
Course Intro
SQL Server Terminology
SQL 2000 & Windows 2000
SQL 2000 Features
SQL Applications (2/3/n Tier)
Transact SQL

Download:
Code: http://www.megaupload.com/?d=W0N7T27Z

xSLT Video Tutorials

Author - Anthony Knox / Total Time - 6 Hours

xSLT (Extensible Style Language of Transformations) serves as both a style and a programming language. Author Anthony Knox begins this Virtual Training Company tutorial with an introduction to xSLT, the necessary tools, terminology, and the basics of creating a xSLT document. He covers both Top Level and Low Level elements, and explains additional functions. To get started, simply click one of the topics below.

Download (about 42MBs RARed)
Code: http://rapidshare.com/files/32872767/xSLT_VidTuts.rar

XML Video Tutorials

Author - Anthony Knox / Total Time - 3 Hours

XML (Extensible Markup Language) is a W3C-recommended general-purpose markup language for creating special-purpose markup languages. It is capable of describing many different kinds of data. Its primary purpose is to facilitate the sharing of data across different systems, particularly systems connected via the Internet. XML allows more control over data and is instumental in the use of RDF, RSS, XHTML and SVG. VTC Author, Mark Long guides you through the first steps of utilizing XML for your data and your websites. Whether you are building an RSS feed for a podcast or building a Java based program, this tutorial will give you the foundation to move ahead.

Download (About 63MBs RARed):
Code: http://rapidshare.com/files/29243941/XML_VidTuts.rar

Perl Video Tutorial

Author - Joshua Mostafa / Total Time - 7.5 Hours

Author Joshua Mostafa takes users through the versatile and powerful programming language known as PERL, a server side language whose primary duty is to handle dynamic content and service clients on the Internet.
What separates PERL from other scripting languages is its flexibility. Users don't need to code in a certain way to effectively use PERL and have fun doing it. Joshua shows you what tools you need to get started in PERL and what resources to visit in order to perfect your scripting.

Download ( MBs):
Code: http://rapidshare.com/files/23176415/Perl_VidTuts.rar

Microsoft Visual Basic .NET Video Tutorials

Author - Mark Long / Certified Instructor
Total Time - 6 Hours

Microsoft Visual Basic has evolved throughout the years, but has steadily remained one of the most popular programming languages today. Visual Basic .NET is undoubtedly the most significant change to occur to Visual Basic yet. Significant new features include: unity of programming models, extension of the program to include mobile device capabilites, Performance Counters and Server Explorer, flashy new capabilities in Windows Forms, anchoring controls, opacity and transparency properties, and much more.

In this six hour tutorial, Microsoft Certified Instructor Mark Long will introduce and expand upon Microsoft Visual Basic .NET and what users can do with it.

Download (86 MBs):
Code: http://www.megaupload.com/?d=UD4VV3MZ

MS Visual Studio .NET Video Tutorials

With it's powerful WYSIWYG editor for Web designs, HTML IntelliSense and Style Sheet Editor, Visual Studio.net makes it simple for developers to create solutions spanning any Internet device.

Author Dave Mercer teaches developers how to harness the power of this powerful Internet application builder that allows for the targeting of operating systems and languages. Choose from a host of modernized languages and make use of the familiar syntax users of Visual Basic are familiar with, as well as the Object Oriented Programming power and inheritance features. Create and deploy server based logic. No more sifting through tedious code! Save on time and build scalable applications using reusable .NET user interfaces, databases, and server components.

Download (58 MBs):
Code: http://www.megaupload.com/?d=HIKACVTW

Introduction to Microsoft. NET Framework Video Tutorials

Microsoft’s .NET Framework has revolutionized the way we build and use computer applications.

In the Introduction to the Microsoft. NET Framework, Certified Instructor Mark Long will use simplified explanations to introduce the viewer to the .NET technologies.
This course is recommended as a precursor to any other .NET courses.

Download (95 MBs):
Code: http://www.megaupload.com/?d=IOBQZ3OF

C Plus Plus Video Tutorials

C Plus Plus (C++) is a programming language that is both procedure-oriented and object-oriented.

In this tutorial, Professor Arthur Lee will explain the environment of C++, then guide you into writing equations, creating functions and output, looping, and much more.

VTC C++ Programming Tutorial (14.5MBs)
Code: http://www.megaupload.com/?d=F282CDHP

C Programming Video Tutorials

Virtual Training Company's C Programming tutorial is taught by an expert C programmer, Mark Virtue, who has been using C for over 15 years, and has been teaching C programming for over 5 years. Perfect for beginners, this tutorial starts at an introductory level, assuming that you have no prior programming experience.

The instructor takes you through the basic concepts and techniques of C, and gives you exercises with which he guides you through to get to the solutions. You will be taken smoothly into more advanced concepts, such as pointers and dynamic memory. If you are already familiar with programming, you can skip past what you already know.

VTC C Programming Tutorial (97.7MBs)
Code: http://www.megaupload.com/?d=NFOEPSB3

Introduction to the Java Programming Language Video Tutorials

Java is a simple, scalable object oriented, general purpose programming language with a multitude of uses. With the power to develop everything from simple web animations to high-end business applications that program hand-held devices, microwaves, cross platform server applications and more, it's no wonder why Java is on everyone's mind.

This practical "how to" course by Java expert Arthur Griffith, starts from the beginning and uses practical examples to demonstrate the Java programming language.


Download (about 130MBs RARed)
Code: http://rapidshare.com/files/25491656...ntro.part1.rar
http://rapidshare.com/files/25534013...ntro.part2.rar