Skip to content

Commit

Permalink
FeatureAdd: DoubleClick, InsertTextWithCR
Browse files Browse the repository at this point in the history
new Release v1.0.8281
  • Loading branch information
c3rebro committed Sep 2, 2022
1 parent f91aa54 commit 1b24171
Show file tree
Hide file tree
Showing 12 changed files with 306 additions and 187 deletions.
169 changes: 69 additions & 100 deletions RFiDGear/DataAccessLayer/Remote/FromFile/ReportReaderWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@ public class ReportReaderWriter : IDisposable
#region fields
private static readonly string FacilityName = "RFiDGear";

PdfDocument pdfDoc;
PdfAcroForm form = null;

private readonly Version Version = Assembly.GetExecutingAssembly().GetName().Version;

private const string reportTemplateTempFileName = "temptemplate.pdf";
private const string taskDatabaseFileName = "taskdatabase.xml";
private readonly string appDataPath;
public string ReportOutputPath { get; set; }
public string ReportTemplatePath { get; set; }
Expand Down Expand Up @@ -67,52 +63,34 @@ public ReportReaderWriter()
}
}

/// <summary>
///
/// </summary>
/// <param name="_path"></param>
public void OpenReport(string _path = "")
public ObservableCollection<string> GetReportFields()
{
try
{
if (pdfDoc == null)
{
if (!string.IsNullOrEmpty(ReportOutputPath))
{
pdfDoc = new PdfDocument(new PdfReader(ReportTemplatePath ?? _path), new PdfWriter(ReportOutputPath));
}

else
{
pdfDoc = new PdfDocument(new PdfReader(ReportTemplatePath ?? _path));
}

form = PdfAcroForm.GetAcroForm(pdfDoc, true);
ObservableCollection<string> temp = new ObservableCollection<string>();

using (PdfDocument pdfDoc = new PdfDocument(new PdfReader(ReportTemplatePath)))
{
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
// Being set as true, this parameter is responsible to generate an appearance Stream
// while flattening for all form fields that don't have one. Generating appearances will
// slow down form flattening, but otherwise Acrobat might render the pdf on its own rules.
form.SetGenerateAppearance(true);
}
}
catch (XmlException e)
{
LogWriter.CreateLogEntry(string.Format("{0}; {1}; {2}", DateTime.Now, e.Message, e.InnerException != null ? e.InnerException.Message : ""), FacilityName);
Environment.Exit(0);
}
}
//form.SetNeedAppearances(true);

public ObservableCollection<string> GetReportFields()
{
try
{
ObservableCollection<string> temp = new ObservableCollection<string>();

if (form != null)
{
foreach (KeyValuePair<string, PdfFormField> _form in form.GetFormFields())
try
{
if (form != null)
{
foreach (KeyValuePair<string, PdfFormField> _form in form.GetFormFields())
{
temp.Add(_form.Key);
}
}
}
catch (Exception e)
{
temp.Add(_form.Key);
LogWriter.CreateLogEntry(e, FacilityName);
}
}

Expand All @@ -121,7 +99,7 @@ public ObservableCollection<string> GetReportFields()
}
catch (XmlException e)
{
LogWriter.CreateLogEntry(string.Format("{0}; {1}; {2}", DateTime.Now, e.Message, e.InnerException != null ? e.InnerException.Message : ""), FacilityName);
LogWriter.CreateLogEntry(e, FacilityName);
return null;
}
}
Expand All @@ -132,31 +110,42 @@ public void SetReportField(string _field, string _value)
{
try
{
ReportTemplatePath = System.IO.Path.Combine(appDataPath, reportTemplateTempFileName);

OpenReport();

try
using (PdfDocument pdfDoc = new PdfDocument(new PdfReader(ReportTemplatePath), new PdfWriter(ReportOutputPath)))
{
form.GetField(_field).SetBorderWidth(1);
form.GetField(_field).SetVisibility(PdfFormField.VISIBLE);
form.GetField(_field).SetReadOnly(false);
form.GetField(_field).SetValue(_value);
ReportTemplatePath = System.IO.Path.Combine(appDataPath, reportTemplateTempFileName);

if (form.GetField(_field) is PdfButtonFormField)
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
// Being set as true, this parameter is responsible to generate an appearance Stream
// while flattening for all form fields that don't have one. Generating appearances will
// slow down form flattening, but otherwise Acrobat might render the pdf on its own rules.
form.SetGenerateAppearance(true);
//form.SetNeedAppearances(true);

try
{
(form.GetField(_field) as PdfButtonFormField).SetBorderColor(ColorConstants.BLACK);
(form.GetField(_field) as PdfButtonFormField).SetBorderWidth(1);
if (form.GetField(_field) is PdfButtonFormField)
{
_ = (form.GetField(_field) as PdfButtonFormField)?.SetBorderWidth(1);
_ = (form.GetField(_field) as PdfButtonFormField)?.SetBorderColor(ColorConstants.BLACK);
}

_ = form.GetField(_field)?.SetVisibility(PdfFormField.VISIBLE);
_ = form.GetField(_field)?.SetReadOnly(false);
_ = form.GetField(_field)?.SetValue(_value);
}
catch (Exception e)
{
LogWriter.CreateLogEntry(e, FacilityName);
}

pdfDoc.Close();
}
catch (Exception e)
{
LogWriter.CreateLogEntry(string.Format("{0}; {1}; {2}", DateTime.Now, e.Message, e.InnerException != null ? e.InnerException.Message : ""), FacilityName);
}

File.Copy(ReportOutputPath, System.IO.Path.Combine(appDataPath, reportTemplateTempFileName), true);
}
catch (XmlException e)
{
LogWriter.CreateLogEntry(string.Format("{0}; {1}; {2}", DateTime.Now, e.Message, e.InnerException != null ? e.InnerException.Message : ""), FacilityName);
LogWriter.CreateLogEntry(e, FacilityName);
}
}

Expand All @@ -170,51 +159,39 @@ public void ConcatReportField(string _field, string _value)
{
ReportTemplatePath = System.IO.Path.Combine(appDataPath, reportTemplateTempFileName);

OpenReport();

try
using (PdfDocument pdfDoc = new PdfDocument(new PdfReader(ReportTemplatePath), new PdfWriter(ReportOutputPath)))
{
form.GetField(_field).SetBorderWidth(1);
form.GetField(_field).SetVisibility(PdfFormField.VISIBLE);
form.GetField(_field).SetValue(string.Format("{0}{1}", form.GetField(_field).GetValueAsString(), _value));

if (form.GetField(_field) is PdfButtonFormField)
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
// Being set as true, this parameter is responsible to generate an appearance Stream
// while flattening for all form fields that don't have one. Generating appearances will
// slow down form flattening, but otherwise Acrobat might render the pdf on its own rules.
form.SetGenerateAppearance(true);
//form.SetNeedAppearances(true);

try
{
(form.GetField(_field) as PdfButtonFormField).SetBorderColor(ColorConstants.BLACK);
(form.GetField(_field) as PdfButtonFormField).SetBorderWidth(1);
form.GetField(_field)?.SetVisibility(PdfFormField.VISIBLE);
form.GetField(_field)?.SetValue(string.Format("{0}{1}", form.GetField(_field)?.GetValueAsString(), _value));
}
catch (Exception e)
{
LogWriter.CreateLogEntry(e, FacilityName);
}

pdfDoc.Close();
}
catch (Exception e)
{
LogWriter.CreateLogEntry(string.Format("{0}; {1}; {2}", DateTime.Now, e.Message, e.InnerException != null ? e.InnerException.Message : ""), FacilityName);
}

File.Copy(ReportOutputPath, System.IO.Path.Combine(appDataPath, reportTemplateTempFileName), true);

}
catch (XmlException e)
{
LogWriter.CreateLogEntry(string.Format("{0}; {1}; {2}", DateTime.Now, e.Message, e.InnerException != null ? e.InnerException.Message : ""), FacilityName);
LogWriter.CreateLogEntry(e, FacilityName);
}
}

}

public void CloseReport()
{
try
{
pdfDoc.Close();

File.Copy(ReportOutputPath, System.IO.Path.Combine(appDataPath, reportTemplateTempFileName), true);

form = null;
pdfDoc = null;
}

catch (XmlException e)
{
LogWriter.CreateLogEntry(string.Format("{0}; {1}; {2}", DateTime.Now, e.Message, e.InnerException != null ? e.InnerException.Message : ""), FacilityName);
}
}

public void DeleteDatabase()
{
File.Delete(System.IO.Path.Combine(ReportOutputPath));
Expand All @@ -228,21 +205,13 @@ protected virtual void Dispose(bool disposing)
{
try
{
if (form != null)
{
pdfDoc.Close();
form = null;
pdfDoc = null;
}


// Dispose any managed objects
// ...
}

catch (XmlException e)
{
LogWriter.CreateLogEntry(string.Format("{0}; {1}; {2}", DateTime.Now, e.Message, e.InnerException != null ? e.InnerException.Message : ""), FacilityName);
LogWriter.CreateLogEntry(e, FacilityName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public override ERROR ReadChipPublic()
GenericChip.CardType = CARD_TYPE.DESFireEV3;
}

DesfireChip = new MifareDesfireChipModel(GenericChip);
DesfireChip = DesfireChip ?? new MifareDesfireChipModel(GenericChip);

return ERROR.NoError;
}
Expand Down
Loading

0 comments on commit 1b24171

Please sign in to comment.