Tuesday, August 2, 2016

How to generate QR Image for Scan !!!

Hi everyone !!!!!

here is the example to generate QR Image.

Step 1 : Open visual studio --> Start New Project (using C# or VB)

Step 2: In the solution explorer 'Right Click', add new item then from the online template (if Nugate not install) search QRCode Library

Step 3 : install QRCode library to your project

Step 4 : after install the QRCode Library , write your code as below



Step 5 : write the code behind on button click event 
            using the namespace 

            using MessagingToolkit.QRCode;
            using MessagingToolkit.QRCode.Codec;

private void generateQR(object sender, EventArgs e)
        {
            string QRstring ;
           string QRImagestring ;
            QRstring = txtPartNo.Text + "{" + txtQuantity.Text + "{" + txtUnit.Text + "{" + 
                               txtVendor.Text + "{" + txtTradingCode.Text + "{" + txtPONo.Text + "{" + 
                               txtInviceNo.Text + "{" + txtDeltaSerialNo.Text;

            QRImagestring = txtVendor.Text + txtPONo.Text + txtInviceNo.Text + 
                              DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + 
                              DateTime.Now.Day.ToString() + DateTime.Now.Minute.ToString() + 
                              DateTime.Now.Second.ToString();

            QRCodeEncoder encode = new QRCodeEncoder();

            Bitmap img = encode.Encode(QRstring);

            img.Save("C:\\QRImage\\" + QRImagestring + ".jpg", ImageFormat.Jpeg);
            
            QRImage.Image = Image.FromFile("C:\\QRImage\\" + QRImagestring + ".jpg");

            lblPartNo.Text = txtPartNo.Text;
            lblQuantity.Text = txtQuantity.Text;
            lblUnit.Text = txtUnit.Text;
            lblVendor.Text = txtVendor.Text;
            lblPONo.Text = txtPONo.Text;
            lblInviceNo.Text = txtInviceNo.Text;
            
        }
Step 6 : Build your project

that all the above scenario can create the QR Image for ready to scan.


Print the above QR code into small printer on print button

1. Add printDialog and print Document into your code or drag and drop to window page 
2. after it, copy the below code on button click event


//-----------button click ----------//
 private void printQR(object sender, EventArgs e)
   {
        System.Drawing.Printing.PrintDocument doc = new
                                                                                          System.Drawing.Printing.PrintDocument();
        doc.PrintPage += new 
                                    System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
         doc.Print();
    }


//------------function for print the panel having the print detail----------------//
  private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
    {
         Bitmap bmp = new Bitmap(panel1.Width, panel1.Height, panel1.CreateGraphics());
         panel1.DrawToBitmap(bmp, new Rectangle(0, 0, panel1.Width, panel1.Height));
         RectangleF bounds = e.PageSettings.PrintableArea;
         float factor = ((float)bmp.Height / (float)bmp.Width);
         e.Graphics.DrawImage(bmp, bounds.Left, bounds.Top, bounds.Width, factor * bounds.Width);
    }


this will print the above created QR code into small printer for scan the details 





Monday, March 14, 2016

How to upload picture/file to server/folder

here is the example to upload the file for the various file formate.

you can uplaod the file with the below paradigm, the below programme is to upload the jpg file formate.


protected void btnUpload_Click(object sender, EventArgs e)
    {
        string checkEmpPhoto ;

        checkEmpPhoto = txtEmpid.Text + ".JPG";

        if (upESDPhoto.HasFile)
        {
            string extension = System.IO.Path.GetExtension(upESDPhoto.FileName);
            if (extension.ToUpper() == ".JPG")
            {
                if (checkEmpPhoto.ToString().ToUpper() == upESDPhoto.FileName.ToString().ToUpper())
                {
                     if upload to same application folder
                    upESDPhoto.SaveAs(Server.MapPath("Folder Name") + "\\" + upESDPhoto.FileName);
                 
                    if upload to some other server folder
                    upESDPhoto.SaveAs(@"\\\\Server Name or Server IP\Folder Name" + "\\" + upESDPhoto.FileName);
                    lblMsg.Text = upESDPhoto.FileName + " uploaded Successfully.";
                }
                else
                {
                    lblMsg.Text = "Please check the Photo Name.";
                }
            }
            else if (extension.ToUpper() != ".JPG")
            {
                lblMsg.Text = "Wrong File Formate.";
            }
        }
        else
        {
            lblMsg.Text = "Please select File first.";
            upESDPhoto.Focus();
        }
    }


GridView Row Command

GridviewRowCommand is very useful event of Gridview. User can delete,view details or something else need to do with the selected Item Row within the gridview.

before need to do with rowCommand event, Grid should contain the item template with rowIndex item

<asp:Label id="lnkDocNo" runat="server" Text='<%# Container.DataItemIndex + 1 %>' ></asp:Label>

<asp:LinkButton id="lnkDocNo" runat="server" Text='<%# Eval("DocNo")%>' CommandName ="V" CommandArgument="<%# ((GridViewRow)Container).RowIndex%>"></asp:LinkButton>

on row command property of gridview

event handler of GridView is powerful property of gridview to do various action or to play with data .

protected void onRowCommand(object sender, GridViewCommandEventArgs e)
    {
        int rowIndex = Convert.ToInt16(e.CommandArgument);
        LinkButton lnkDocNo = (LinkButton)GridView.Rows[rowIndex].FindControl("lnkDocNo");

        if (e.CommandName == "V")
        {
           //do the Action with the Data here.
        }
    }