private void btnPdf_Click(object sender, EventArgs e)
        {
            if (txtLicPdfCode.Text == "" || txtLicPdfCode.Text == "Enter Pdf Verfication Code")
            {
                txtLicPdfCode.Focus();
                errorProvider1.SetError(txtLicPdfCode, "Enter Pdf Verfication Code");
                return;
            }
            else
            {
                errorProvider1.Clear();
            }


            var vehicelDetails = GetVehicelDetialsByLicPdfCode(txtLicPdfCode.Text);

            if (vehicelDetails != null && vehicelDetails.VehicelId != 0)
            {
                RequestToke token = Service_db.GetLatestToken();
                if (ObjToken != null)
                {
                    parternToken = token.Token;
                }

                pictureBox2.Visible    = true;
                pictureBox2.WaitOnLoad = true;

                String WebUrlPath       = WebConfigurationManager.AppSettings["WebUrlPath"];
                string filePath         = WebUrlPath + "/" + "Documents/License/" + vehicelDetails.VehicelId + ".pdf";
                string optionalFilePath = WebUrlPath + "/" + "Documents/License/" + vehicelDetails.RegistrationNo + ".pdf";
                //urlPath
                //var pdfPath = SavePdfFromUrl(filePath, optionalFilePath);
                //// var pdfPath = @"F:\sample.pdf";
                //PdfDocument doc = new PdfDocument();
                //doc.LoadFromFile(pdfPath);
                //doc.Pages.Insert(0);
                //doc.Pages.Add();
                //doc.Pages.RemoveAt(0);//Since First page have always Red Text if use Free Version.
                //doc.SaveToFile(pdfPath);


                string installedPath = @"C:\Users\Public\";
                string fileName      = "Certificate" + ".pdf";

                var destinationFileName = System.IO.Path.Combine(installedPath, System.IO.Path.GetFileName(fileName));


                PdfReader  reader  = new PdfReader(filePath);
                PdfStamper stamper = new PdfStamper(reader, new FileStream(destinationFileName, FileMode.Create));
                int        total   = reader.NumberOfPages;
                for (int pageNumber = total; pageNumber > 0; pageNumber--)
                {
                    stamper.InsertPage(pageNumber, PageSize.A4);
                }
                stamper.Close();
                reader.Close();


                MyMessageBox.ShowBox("Please Print Licence Disk. ", "Print License Disk");

                printPDFWithAcrobat(destinationFileName);
                pictureBox2.Visible = false;

                riskDetail = new RiskDetailModel {
                    CombinedID = vehicelDetails.CombinedID, LicenseId = vehicelDetails.LicenseId, RegistrationNo = vehicelDetails.RegistrationNo
                };


                this.Close();
                WebCertificateSerial obj = new WebCertificateSerial(riskDetail, parternToken);
                obj.Show();
            }
            else
            {
                pictureBox2.Visible = false;
                MyMessageBox.ShowBox("Certificate is not found for this code", "Message");
            }

            pictureBox2.Visible = false;
        }
        private void btnLicPrint_Click(object sender, EventArgs e)
        {
            pictureBox2.Visible    = true;
            pictureBox2.WaitOnLoad = true;

            //txtLicVrn.Text = "KJVV456456";
            try
            {
                if (txtLicVrn.Text == "" || txtLicVrn.Text == "Enter Registration Number")
                {
                    txtLicVrn.Focus();
                    errorProvider1.SetError(txtLicVrn, "Please enter Registration Number");
                    return;
                }
                else
                {
                    errorProvider1.Clear();
                }


                pictureBox2.Visible    = true;
                pictureBox2.WaitOnLoad = true;
                //PrintPreview1 dlg1 = new PrintPreview1(txtLicVrn.Text);
                //dlg1.ShowDialog();
                var vehicelDetails = GetVehicelDetials(txtLicVrn.Text);

                //    vehicelDetails.LicenseId = 2743;
                if (vehicelDetails != null && vehicelDetails.CombinedID != null)
                {
                    //ObjToken = IcServiceobj.getToken();
                    //if (ObjToken != null)
                    //{
                    //    parternToken = ObjToken.Response.PartnerToken;
                    //}

                    RequestToke token = Service_db.GetLatestToken();
                    if (ObjToken != null)
                    {
                        parternToken = token.Token;
                    }

                    // riskDetail = new RiskDetailModel { LicenseId = vehicelDetails.LicenseId.ToString(), RegistrationNo = vehicelDetails.RegistrationNo };

                    // _branchId = _branchId==null? "0" : _branchId;

                    riskDetail = new RiskDetailModel {
                        CombinedID = vehicelDetails.CombinedID, LicenseId = vehicelDetails.LicenseId, RegistrationNo = vehicelDetails.RegistrationNo
                    };

                    if (!string.IsNullOrEmpty(vehicelDetails.CombinedID) && (vehicelDetails.CombinedID != "0"))
                    {
                        DisplayLicenseDisc(riskDetail, parternToken);
                    }
                }
                else if (vehicelDetails != null && vehicelDetails.LicenseId != null)
                {
                    RequestToke token = Service_db.GetLatestToken();
                    if (ObjToken != null)
                    {
                        parternToken = token.Token;
                    }

                    // riskDetail = new RiskDetailModel { LicenseId = vehicelDetails.LicenseId.ToString(), RegistrationNo = vehicelDetails.RegistrationNo };


                    riskDetail = new RiskDetailModel {
                        LicenseId = vehicelDetails.LicenseId, RegistrationNo = vehicelDetails.RegistrationNo
                    };

                    if (!string.IsNullOrEmpty(vehicelDetails.LicenseId) && (vehicelDetails.LicenseId != "0"))
                    {
                        DisplayLicenseOnly(riskDetail, parternToken);
                    }
                }
                else
                {
                    pictureBox2.Visible = false;
                }
                //PrintPreview1 dlg1 = new PrintPreview1(licenseDiskList);
                //dlg1.ShowDialog();
            }
            catch (Exception ex)
            {
                pictureBox2.Visible = false;
            }
        }
        private void PrintOutByVRN(string vrn)
        {
            pictureBox2.Visible    = true;
            pictureBox2.WaitOnLoad = true;

            try
            {
                pictureBox2.Visible    = true;
                pictureBox2.WaitOnLoad = true;
                //PrintPreview1 dlg1 = new PrintPreview1(txtLicVrn.Text);
                //dlg1.ShowDialog();
                var vehicelDetails = GetVehicelDetials(vrn);

                //    vehicelDetails.LicenseId = 2743;
                if (vehicelDetails != null && vehicelDetails.CombinedID != null)
                {
                    //ObjToken = IcServiceobj.getToken();
                    //if (ObjToken != null)
                    //{
                    //    parternToken = ObjToken.Response.PartnerToken;
                    //}

                    RequestToke token = Service_db.GetLatestToken();
                    if (ObjToken != null)
                    {
                        parternToken = token.Token;
                    }

                    // riskDetail = new RiskDetailModel { LicenseId = vehicelDetails.LicenseId.ToString(), RegistrationNo = vehicelDetails.RegistrationNo };

                    // _branchId = _branchId==null? "0" : _branchId;

                    riskDetail = new RiskDetailModel {
                        CombinedID = vehicelDetails.CombinedID, LicenseId = vehicelDetails.LicenseId, RegistrationNo = vehicelDetails.RegistrationNo
                    };

                    if (!string.IsNullOrEmpty(vehicelDetails.CombinedID) && (vehicelDetails.CombinedID != "0"))
                    {
                        DisplayLicenseDisc(riskDetail, parternToken);
                    }
                }
                else if (vehicelDetails != null && vehicelDetails.LicenseId != null)
                {
                    RequestToke token = Service_db.GetLatestToken();
                    if (ObjToken != null)
                    {
                        parternToken = token.Token;
                    }

                    // riskDetail = new RiskDetailModel { LicenseId = vehicelDetails.LicenseId.ToString(), RegistrationNo = vehicelDetails.RegistrationNo };

                    riskDetail = new RiskDetailModel {
                        LicenseId = vehicelDetails.LicenseId, RegistrationNo = vehicelDetails.RegistrationNo
                    };

                    if (!string.IsNullOrEmpty(vehicelDetails.LicenseId) && (vehicelDetails.LicenseId != "0"))
                    {
                        DisplayLicenseOnly(riskDetail, parternToken);
                    }
                }
                else
                {
                    pictureBox2.Visible = false;
                }
                //PrintPreview1 dlg1 = new PrintPreview1(licenseDiskList);
                //dlg1.ShowDialog();
            }
            catch (Exception ex)
            {
                pictureBox2.Visible = false;
            }
        }