コード例 #1
0
        protected bool CreateCertificate(string Template)
        {
            using (TransactionScope transactionScope = new TransactionScope())
            {
                try
                {
                    bool             Created        = false;
                    B_RecordSequence seqmanager     = new B_RecordSequence();
                    string           Certificate_No = "CE" + seqmanager.getNextSequence("CertificateSign").ToString();

                    CRHeader.RefferencNo = Certificate_No;

                    string LogoPath      = Server.MapPath(CertificateLOGO); // NCE Certificate logo Image path
                    string DirectoryPath = "~/Documents/" + DateTime.Now.ToString("yyyy")
                                           + "/Issued_Certificates/" + DateTime.Now.ToString("MMM") + "/" + DateTime.Now.ToString("dd") + "/"
                                           + Certificate_No;

                    string Tempary_Direct = "~/Temp/" + DateTime.Now.ToString("yyyy")
                                            + "/Issued_Certificates/" + DateTime.Now.ToString("yyyy_MM_dd")
                                            + "/" + Certificate_No;

                    //DirectoryPath which will save the NOT singed PDF File as NOT_Signed.pdf in the given Path
                    if (!Directory.Exists(Server.MapPath(DirectoryPath)))
                    {
                        Directory.CreateDirectory(Server.MapPath(DirectoryPath));
                    }

                    if (!Directory.Exists(Server.MapPath(Tempary_Direct)))
                    {
                        Directory.CreateDirectory(Server.MapPath(Tempary_Direct));
                    }

                    /**PDF Cerator
                     * Parameters
                     * M_Certificate
                     * Document Save Path
                     *
                     */
                    if (Template.Equals(ROWWITH_HS))
                    {
                        RowWithHSTemplate Certificate =
                            new RowWithHSTemplate(Certificate_No,
                                                  CRHeader,
                                                  LogoPath,
                                                  Server.MapPath(Tempary_Direct + "/_Not_Signed.pdf"),
                                                  _session.Person_Name, DateTime.Now.ToString("yyyy/MM/dd"));

                        Created = Certificate.CreateCertificate("");
                    }
                    else if (Template.Equals(ROWWITHOUTHS))
                    {
                        RowWithoutHSTemplate Certificate =
                            new RowWithoutHSTemplate(Certificate_No,
                                                     CRHeader,
                                                     LogoPath,
                                                     Server.MapPath(Tempary_Direct + "/_Not_Signed.pdf"),
                                                     _session.Person_Name, DateTime.Now.ToString("yyyy/MM/dd"));

                        Created = Certificate.CreateCertificate("");
                    }
                    else if (Template.Equals(GOLOBALTMP))
                    {
                        OrientGlobalCertificateTemplate Certificate =
                            new OrientGlobalCertificateTemplate(Certificate_No,
                                                                CRHeader,
                                                                LogoPath,
                                                                Server.MapPath(Tempary_Direct + "/_Not_Signed.pdf"),
                                                                _session.Person_Name, DateTime.Now.ToString("yyyy/MM/dd"));

                        Created = Certificate.CreateCertificate("");
                    }
                    else if (Template.Equals(MASSACTIVE))
                    {
                        MassActiveCertificateTemplate Certificate =
                            new MassActiveCertificateTemplate(Certificate_No,
                                                              CRHeader,
                                                              LogoPath,
                                                              Server.MapPath(Tempary_Direct + "/_Not_Signed.pdf"),
                                                              _session.Person_Name, DateTime.Now.ToString("yyyy/MM/dd"));

                        Created = Certificate.CreateCertificate("");
                    }
                    else if (Template.Equals(NINDROTMP))
                    {
                        NidroCertificateTemplate Certificate =
                            new NidroCertificateTemplate(Certificate_No,
                                                         CRHeader,
                                                         LogoPath,
                                                         Server.MapPath(Tempary_Direct + "/_Not_Signed.pdf"),
                                                         _session.Person_Name, DateTime.Now.ToString("yyyy/MM/dd"));

                        Created = Certificate.CreateCertificate("");
                    }
                    else if (Template.Equals(COLUMNWITHOUTHS))
                    {
                        ColumnWithoutHSTemplate Certificate =
                            new ColumnWithoutHSTemplate(Certificate_No,
                                                        CRHeader,
                                                        LogoPath,
                                                        Server.MapPath(Tempary_Direct + "/_Not_Signed.pdf"),
                                                        _session.Person_Name, DateTime.Now.ToString("yyyy/MM/dd"));

                        Created = Certificate.CreateCertificate("");
                    }
                    else if (Template.Equals(COLUMNWITHOUTHS2))
                    {
                        ColumnWithoutHSTemplate Certificate =
                            new ColumnWithoutHSTemplate(Certificate_No,
                                                        CRHeader,
                                                        LogoPath,
                                                        Server.MapPath(Tempary_Direct + "/_Not_Signed.pdf"),
                                                        _session.Person_Name, DateTime.Now.ToString("yyyy/MM/dd"));

                        Created = Certificate.CreateCertificate("");
                    }
                    else
                    {
                        ColumnWithHSTemplate Certificate =
                            new ColumnWithHSTemplate(Certificate_No,
                                                     CRHeader,
                                                     LogoPath,
                                                     Server.MapPath(Tempary_Direct + "/_Not_Signed.pdf"),
                                                     _session.Person_Name, DateTime.Now.ToString("yyyy/MM/dd"));

                        Created = Certificate.CreateCertificate("");
                    }

                    string Sealed    = Server.MapPath(Tempary_Direct + "/_Not_Signed.pdf");
                    string NotSigned = Server.MapPath(Tempary_Direct + "/_Not_Signed.pdf");;
                    string Signed    = Server.MapPath(DirectoryPath + "/" + Certificate_No + "_Certificate.pdf");
                    string pathe     = Server.MapPath(_session.PFX_path);             //From DB
                    //  string pathe = Server.MapPath("~/Signature/Samitha/Samitha.pfx");//From DB
                    string SignatureIMG = Server.MapPath(_session.SignatureIMG_Path); // From DB
                    //   string SignatureIMG = Server.MapPath("~/Signature/Samitha/sign.JPG");// From DB

                    var PFX = new FileStream(pathe, FileMode.OpenOrCreate);

                    Sign_ SignCertificate = new Sign_();

                    if (Convert.ToBoolean(CRHeader.SealRequired))
                    {
                        SignCertificate.AddSeal(Sealed, Server.MapPath(_session.SignatureIMG_Path));
                        NotSigned = Server.MapPath(Tempary_Direct + "/_Not_Signed_S.pdf");
                    }

                    bool singed = SignCertificate.signCertificate(NotSigned, Signed,
                                                                  PFX, _session.C_Password);
                    if (!singed)
                    {
                        PFX.Close();
                        //mp1.Show();
                        //lblError.Text = "Wrong password or Corrupted Certificate file.";
                        _session.C_Password = "";
                        return(false);
                    }

                    M_CertificateApprove Approve = new M_CertificateApprove();
                    Approve.Certificate_Name = Certificate_No + "_Certificate.pdf";
                    Approve.Certificate_Path = DirectoryPath + "/" + Certificate_No + "_Certificate.pdf";
                    // Approve.Created_By = "SAMITHA";
                    Approve.Created_By     = _session.User_Id;
                    Approve.Expiry_Date    = DateTime.Today.AddDays(120);
                    Approve.Is_Downloaded  = "N";
                    Approve.Is_Valid       = "Y";
                    Approve.Request_Id     = CRHeader.RequestReff;
                    Approve.Certificate_Id = Certificate_No;


                    bool result = objAprv.ApproveCertificate(Approve);

                    if (SupList.Count != 0)
                    {
                        if (!Directory.Exists(Server.MapPath(Tempary_Direct + "/Supporting-Doc")))
                        {
                            Directory.CreateDirectory(Server.MapPath(Tempary_Direct + "/Supporting-Doc"));
                        }

                        if (!Directory.Exists(Server.MapPath(DirectoryPath + "/Supporting-Doc")))
                        {
                            Directory.CreateDirectory(Server.MapPath(DirectoryPath + "/Supporting-Doc"));
                        }
                    }

                    for (int i = 0; i < SupList.Count(); i++)
                    {
                        if (SupList[i].Remarks != null)
                        {
                            if (SupList[i].Remarks.Equals("NCE_Certification"))
                            {
                                string SignedSD   = Server.MapPath(DirectoryPath + "/Supporting-Doc/" + SupList[i].DocumentName);
                                string SealedPath = Server.MapPath(Tempary_Direct + "/Supporting-Doc/" + SupList[i].DocumentName);

                                Sign_ SignDoc = new Sign_();

                                SignDoc.AddSealSD(Server.MapPath(SupList[i].UploadedPath), SealedPath, Server.MapPath(_session.SignatureIMG_Path));

                                var PFX2 = new FileStream(pathe, FileMode.OpenOrCreate);

                                bool Sign = SignDoc.signSupportingDoc(Certificate_No,
                                                                      SealedPath,
                                                                      SignedSD,
                                                                      PFX2, _session.C_Password);

                                if (!Sign)
                                {
                                    PFX.Close();
                                    PFX2.Close();
                                    //lblError.Text = "Corrupted Supporting Document file @ " + SupList[i].Request_Ref_No + ":" + SupList[i].Document_Id + ". Signature Placement Failed !";
                                    //mp1.Show();
                                    _session.C_Password = "";
                                    return(false);
                                }
                                SupList[i].CertifiedDocPathe = DirectoryPath + "/Supporting-Doc/" + SupList[i].DocumentName;
                                SupList[i].Status            = "A";
                                SupList[i].ClientId          = CRHeader.Client_Id;
                                SupList[i].ApprovedBy        = _session.User_Id;
                                SupList[i].ExpiredOn         = DateTime.Today.AddDays(120).ToString();


                                objSDAprv.setSupportingDocSignRequestINCertRequest(SupList[i]);

                                SupList[i].UploadedPath = DirectoryPath + "/Supporting-Doc/" + SupList[i].DocumentName;
                                objCr.UpdateSupportingDocCertified(SupList[i]);
                            }
                        }
                    }

                    transactionScope.Complete();
                    transactionScope.Dispose();
                    return(true);
                }
                catch (TransactionAbortedException Ex)
                {
                    transactionScope.Dispose();
                    ErrorLog.LogError(Ex);
                    return(false);
                }
                catch (FileNotFoundException Ex)
                {
                    ErrorLog.LogError(Ex);
                    return(false);
                }
                catch (FieldAccessException Ex)
                {
                    ErrorLog.LogError(Ex);
                    return(false);
                }
                catch (Exception Ex)
                {
                    ErrorLog.LogError(Ex);
                    return(false);
                }
            }
        }
コード例 #2
0
        public void CreateSample(M_Cerificate Model, string Reff)
        {
            bool   Created  = false;
            string Template = Model.TemplateId;

            string LogoPath      = Server.MapPath("~/Images/NCELOGO.PNG"); // NCE Certificate logo Image path
            string DirectoryPath = "~/Temp/" + DateTime.Now.ToString("yyyy")
                                   + "/Web_Certificates/" + DateTime.Now.ToString("MMM") + "/" + DateTime.Now.ToString("dd") + "/" + Reff;

            //HeaderR.Customer_Telephone = usrSessiong.Telephone_;
            //HeaderR.CustomerName1 = usrSessiong.Customer_Name;

            //DirectoryPath which will save the NOT singed PDF File as NOT_Signed.pdf in the given Path
            if (!Directory.Exists(Server.MapPath(DirectoryPath)))
            {
                Directory.CreateDirectory(Server.MapPath(DirectoryPath));
            }

            /**PDF Cerator
             * Parameters
             * M_Certificate
             * Document Save Path
             *
             */
            if (Template.Equals(ROWWITH_HS))
            {
                RowWithHSTemplate Certificate =
                    new RowWithHSTemplate(Reff, Model, LogoPath,
                                          Server.MapPath(DirectoryPath + "/" + Reff + "_Sample.pdf"), "", "");

                Created = Certificate.CreateCertificate("");
            }
            else if (Template.Equals(ROWWITHOUTHS))
            {
                RowWithoutHSTemplate Certificate =
                    new RowWithoutHSTemplate(Reff, Model, LogoPath,
                                             Server.MapPath(DirectoryPath + "/" + Reff + "_Sample.pdf"), "", "");

                Created = Certificate.CreateCertificate("");
            }
            else if (Template.Equals(GOLOBALTMP))
            {
                OrientGlobalCertificateTemplate Certificate =
                    new OrientGlobalCertificateTemplate(Reff, Model, LogoPath,
                                                        Server.MapPath(DirectoryPath + "/" + Reff + "_Sample.pdf"), "", "");

                Created = Certificate.CreateCertificate("");
            }
            else if (Template.Equals(MASSACTIVE))
            {
                MassActiveCertificateTemplate Certificate =
                    new MassActiveCertificateTemplate(Reff, Model, LogoPath,
                                                      Server.MapPath(DirectoryPath + "/" + Reff + "_Sample.pdf"), "", "");

                Created = Certificate.CreateCertificate("");
            }
            else if (Template.Equals(NINDROTMP))
            {
                NidroCertificateTemplate Certificate =
                    new NidroCertificateTemplate(Reff, Model, LogoPath,
                                                 Server.MapPath(DirectoryPath + "/" + Reff + "_Sample.pdf"), "", "");

                Created = Certificate.CreateCertificate("");
            }
            else if (Template.Equals(COLUMNWITHOUTHS))
            {
                ColumnWithoutHSTemplate Certificate =
                    new ColumnWithoutHSTemplate(Reff, Model, LogoPath,
                                                Server.MapPath(DirectoryPath + "/" + Reff + "_Sample.pdf"), "", "");

                Created = Certificate.CreateCertificate("");
            }
            else if (Template.Equals(COLUMNWITHOUTHS2))
            {
                ColumnWithoutHSTemplate Certificate =
                    new ColumnWithoutHSTemplate(Reff, Model, LogoPath,
                                                Server.MapPath(DirectoryPath + "/" + Reff + "_Sample.pdf"), "", "");

                Created = Certificate.CreateCertificate("");
            }
            else
            {
                ColumnWithHSTemplate Certificate =
                    new ColumnWithHSTemplate(Reff, Model, LogoPath,
                                             Server.MapPath(DirectoryPath + "/" + Reff + "_Sample.pdf"), "", "");

                Created = Certificate.CreateCertificate("");
            }
            if (Created)
            {
                objCr.setWebBasedCertificateCreation(Reff,
                                                     DirectoryPath + "/" + Reff + "_Sample.pdf",
                                                     Reff + "_Sample.pdf");
            }
        }