private static void AddSignature(PdfAcroForm form, PdfAssociation itempdf)
        {
            PdfArray position = form.GetField(itempdf.PDF_FIELD).GetWidgets()[0].GetRectangle();

            rectangle = position.ToRectangle();

            numPage = itempdf.NUM_PAGE;

            if (!string.IsNullOrEmpty(itempdf.BIOMETRIC))
            {
                form.RemoveField(itempdf.PDF_FIELD);
            }
        }
        private static void MergePdfTxt(PdfAcroForm form, PdfAssociation itempdf, object obj)
        {
            try
            {
                if (obj == null)
                {
                    throw new Exception("Oggetto non definito.");
                }

                string strValue = ManageValue(obj, itempdf);
                form.GetField(itempdf.PDF_FIELD).SetValue(strValue);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Errore: " + ex.Message, "Configurazione errata", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                throw ex;
            }
        }
        private static string ManageValue(object obj, PdfAssociation itempdf)
        {
            string ret = null;

            try
            {
                if (itempdf.FIELD == null)
                {
                    switch (itempdf.FORM_DATE)
                    {
                    case "dd":
                        ret = DateTime.Now.Day.ToString();
                        break;

                    case "MM":
                        ret = DateTime.Now.Month.ToString();
                        break;

                    case "yyyy":
                        ret = DateTime.Now.Year.ToString();
                        break;
                    }
                }
                else
                {
                    foreach (string part in itempdf.FIELD.Split(','))
                    {
                        ret = string.Concat(GetPropValue(obj, part), " ", ret);
                    }
                }
                return(ret);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #4
0
        public static List <PdfAssociation> LoadPdfAssociation(int intKeyPdf)
        {
            try
            {
                if (!GestioneMySql.OpenConnection())
                {
                    throw new Exception("Errore nell'apertura della connessione.");
                }

                var sb = new StringBuilder();
                List <PdfAssociation> pdfAssociationList = new List <PdfAssociation>();

                sb.AppendLine("SELECT *");
                sb.AppendLine("FROM PDFASSOCIATION");
                sb.AppendLine("WHERE KEY_TEMPL = @KEY_TEMPL");

                MySqlCommand cmd = new MySqlCommand(sb.ToString(), GestioneMySql.connection);
                cmd.Parameters.Add(new MySqlParameter("KEY_TEMPL", intKeyPdf));

                MySqlDataReader dr = cmd.ExecuteReader();

                while (dr.Read())
                {
                    PdfAssociation pdfAssociation = new PdfAssociation();

                    pdfAssociation.KEY_PDF = dr.GetInt16("KEY_PDF");

                    if (!string.IsNullOrEmpty(dr.GetString("PDF_FIELD")))
                    {
                        pdfAssociation.PDF_FIELD = dr.GetString("PDF_FIELD");
                    }

                    if (!string.IsNullOrEmpty(dr.GetString("TYPE")))
                    {
                        pdfAssociation.TYPE = dr.GetString("TYPE");
                    }

                    if (!dr.IsDBNull(dr.GetOrdinal("FIELD")))
                    {
                        if (!string.IsNullOrEmpty(dr.GetString("FIELD")))
                        {
                            pdfAssociation.FIELD = dr.GetString("FIELD");
                        }
                    }

                    if (!dr.IsDBNull(dr.GetOrdinal("BIOMETRIC")))
                    {
                        if (!string.IsNullOrEmpty(dr.GetString("BIOMETRIC")))
                        {
                            pdfAssociation.FIELD = dr.GetString("BIOMETRIC");
                        }
                    }

                    if (!dr.IsDBNull(dr.GetOrdinal("NUM_PAGE")))
                    {
                        if (!string.IsNullOrEmpty(dr.GetString("NUM_PAGE")))
                        {
                            pdfAssociation.NUM_PAGE = dr.GetInt32("NUM_PAGE");
                        }
                    }

                    if (!dr.IsDBNull(dr.GetOrdinal("FORM_DATE")))
                    {
                        if (!string.IsNullOrEmpty(dr.GetString("FORM_DATE")))
                        {
                            pdfAssociation.FORM_DATE = dr.GetString("FORM_DATE");
                        }
                    }
                    pdfAssociationList.Add(pdfAssociation);
                }
                dr.Close();

                if (!GestioneMySql.CloseConnection())
                {
                    throw new Exception("Errore nella chiusurua della connessione.");
                }

                return(pdfAssociationList);
            }
            catch (Exception ex)
            {
                GestioneMySql.CloseConnection();
                MessageBox.Show("Errore: " + ex.Message);
                return(null);
            }
        }