ReportOptionsForm.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. using System;
  2. using System.IO;
  3. using System.Windows.Forms;
  4. using System.Drawing;
  5. using FastReport.Utils;
  6. using System.Collections.Generic;
  7. using System.Reflection;
  8. using FastReport.Controls;
  9. namespace FastReport.Forms
  10. {
  11. internal partial class ReportOptionsForm : BaseDialogForm
  12. {
  13. private Report report;
  14. public Report Report
  15. {
  16. get { return report; }
  17. set { report = value; }
  18. }
  19. private void ReportOptionsForm_Shown(object sender, EventArgs e)
  20. {
  21. // needed for hidpi mode
  22. }
  23. private void ReportOptionsForm_FormClosing(object sender, FormClosingEventArgs e)
  24. {
  25. if (!Done())
  26. e.Cancel = true;
  27. }
  28. private void btnLoad_Click(object sender, EventArgs e)
  29. {
  30. if (Dialogs.OpenImage(out string fileName))
  31. {
  32. try
  33. {
  34. pbPicture.Image = ImageHelper.LoadFromFile(fileName);
  35. }
  36. catch (Exception ex)
  37. {
  38. FRMessageBox.Error(ex.Message);
  39. }
  40. }
  41. }
  42. private void btnClear_Click(object sender, EventArgs e)
  43. {
  44. pbPicture.Image = null;
  45. }
  46. private void btnAdd_Click(object sender, EventArgs e)
  47. {
  48. using (OpenFileDialog dialog = new OpenFileDialog())
  49. {
  50. dialog.Filter = Res.Get("FileFilters,Assembly");
  51. if (dialog.ShowDialog() == DialogResult.OK)
  52. AddPlugin(dialog.FileName);
  53. }
  54. }
  55. private void BtnRemove_Click(object sender, System.EventArgs e)
  56. {
  57. if (lbRefAssemblies.SelectedIndex == -1)
  58. return;
  59. lbRefAssemblies.Items.Remove(lbRefAssemblies.SelectedItem);
  60. }
  61. private void tbPasswordLoad_TextChanged(object sender, EventArgs e)
  62. {
  63. tbRetypePassword.Text = "";
  64. }
  65. private void rbInherit_CheckedChanged(object sender, EventArgs e)
  66. {
  67. btnBrowse.Enabled = rbInherit.Checked;
  68. }
  69. private void btnBrowse_Click(object sender, EventArgs e)
  70. {
  71. using (OpenFileDialog dialog = new OpenFileDialog())
  72. {
  73. dialog.Filter = Res.Get("FileFilters,Report");
  74. if (dialog.ShowDialog() == DialogResult.OK)
  75. lblBaseName.Text = dialog.FileName;
  76. else
  77. lblBaseName.Text = "";
  78. }
  79. }
  80. private void tbDescription_ButtonClick(object sender, EventArgs e)
  81. {
  82. using (StringCollectionEditorForm form = new StringCollectionEditorForm())
  83. {
  84. form.PlainText = tbDescription.Text;
  85. if (form.ShowDialog() == DialogResult.OK)
  86. tbDescription.Text = form.PlainText;
  87. }
  88. }
  89. private void lbPlugins_SelectedIndexChanged(object sender, EventArgs e)
  90. {
  91. btnRemove.Enabled = lbRefAssemblies.SelectedIndex != -1;
  92. }
  93. private string GetFullAssemblyReference(string relativeReference, string defaultPath)
  94. {
  95. // in .NET Core we get the AssemblyReference in FR.Compat
  96. #if !(NETSTANDARD || NETCOREAPP)
  97. if (relativeReference == null || relativeReference.Trim() == "")
  98. return "";
  99. // Strip off any trailing ".dll" ".exe" if present.
  100. string dllName = relativeReference;
  101. if (string.Compare(relativeReference.Substring(relativeReference.Length - 4), ".dll", true) == 0 ||
  102. string.Compare(relativeReference.Substring(relativeReference.Length - 4), ".exe", true) == 0)
  103. dllName = relativeReference.Substring(0, relativeReference.Length - 4);
  104. // See if the required assembly is already present in our current AppDomain
  105. foreach (Assembly currAssembly in AppDomain.CurrentDomain.GetAssemblies())
  106. {
  107. if (string.Compare(currAssembly.GetName().Name, dllName, true) == 0)
  108. {
  109. // Found it, return the location as the full reference.
  110. return currAssembly.Location;
  111. }
  112. }
  113. // See if the required assembly is present in the ReferencedAssemblies but not yet loaded
  114. foreach (AssemblyName assemblyName in Assembly.GetExecutingAssembly().GetReferencedAssemblies())
  115. {
  116. if (string.Compare(assemblyName.Name, dllName, true) == 0)
  117. {
  118. // Found it, try to load assembly and return the location as the full reference.
  119. try
  120. {
  121. return Assembly.ReflectionOnlyLoad(assemblyName.FullName).Location;
  122. }
  123. catch { }
  124. }
  125. }
  126. // See if the required assembly is present locally
  127. string path = Path.Combine(defaultPath, relativeReference);
  128. if (File.Exists(path))
  129. return path;
  130. #endif
  131. return relativeReference;
  132. }
  133. private string GetToolTipText(string location)
  134. {
  135. if (location == null || !File.Exists(location)) return "";
  136. FileInfo info = new FileInfo(location);
  137. var versionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(location);
  138. return info.Name + "\n" +
  139. Res.Get("Forms,PluginsOptions,Description") + " " +
  140. versionInfo.FileDescription + "\n" +
  141. Res.Get("Forms,PluginsOptions,CompanyName") + " " +
  142. versionInfo.CompanyName + "\n" +
  143. Res.Get("Forms,PluginsOptions,Version") + " " +
  144. versionInfo.FileVersion + "\n" +
  145. Res.Get("Forms,PluginsOptions,Date") + " " + info.CreationTime.ToString() + "\n" +
  146. Res.Get("Forms,PluginsOptions,Size") + " " + FileSize.ConvertToString(info.Length) + "\n" +
  147. Res.Get("Forms,PluginsOptions,Path") + "\n" + location;
  148. }
  149. private void AddPlugin(string location)
  150. {
  151. lbRefAssemblies.Items.Add(new ListBoxItem(Path.GetFileName(location), GetToolTipText(location)));
  152. }
  153. private void Init()
  154. {
  155. cbDoublePass.Checked = Report.DoublePass;
  156. cbCompress.Checked = Report.Compressed;
  157. cbUseFileCache.Checked = Report.UseFileCache;
  158. cbConvertNulls.Checked = Report.ConvertNulls;
  159. cbxTextQuality.SelectedIndex = (int)Report.TextQuality;
  160. cbSmoothGraphics.Checked = Report.SmoothGraphics;
  161. tbName.Text = Report.ReportInfo.Name;
  162. tbAuthor.Text = Report.ReportInfo.Author;
  163. tbVersion.Text = Report.ReportInfo.Version;
  164. tbDescription.Text = Report.ReportInfo.Description;
  165. pbPicture.Image = Report.ReportInfo.Picture;
  166. cbSavePreviewPicture.Checked = Report.ReportInfo.SavePreviewPicture;
  167. lblCreated1.Text = Report.ReportInfo.Created.ToString();
  168. lblModified1.Text = Report.ReportInfo.Modified.ToString();
  169. rbC.Checked = Report.ScriptLanguage == Language.CSharp;
  170. rbVB.Checked = Report.ScriptLanguage == Language.Vb;
  171. for (int i = 0; i < Report.ReferencedAssemblies.Length; i++)
  172. {
  173. AddPlugin(GetFullAssemblyReference(Report.ReferencedAssemblies[i], ""));
  174. }
  175. tbPassword.Text = Report.Password;
  176. tbRetypePassword.Text = tbPassword.Text;
  177. if (Report.IsAncestor)
  178. {
  179. lblInheritance.Text = Res.Get("Forms,ReportOptions,Inherited") + "\r\n" + Report.BaseReport;
  180. }
  181. else
  182. {
  183. lblInheritance.Text = Res.Get("Forms,ReportOptions,NotInherited");
  184. rbDetach.Enabled = false;
  185. }
  186. tbRecipients.Text = Report.EmailSettings.RecipientsText;
  187. tbSubject.Text = Report.EmailSettings.Subject;
  188. tbMessage.Text = Report.EmailSettings.Message;
  189. }
  190. private bool Done()
  191. {
  192. if (DialogResult == DialogResult.OK)
  193. {
  194. if (tbPassword.Text != tbRetypePassword.Text)
  195. {
  196. FRMessageBox.Error(Res.Get("Forms,ReportOptions,PasswordError"));
  197. pcPages.ActivePage = pnSecurity;
  198. tbRetypePassword.Focus();
  199. return false;
  200. }
  201. Report.DoublePass = cbDoublePass.Checked;
  202. Report.Compressed = cbCompress.Checked;
  203. Report.UseFileCache = cbUseFileCache.Checked;
  204. Report.ConvertNulls = cbConvertNulls.Checked;
  205. Report.TextQuality = (TextQuality)cbxTextQuality.SelectedIndex;
  206. Report.SmoothGraphics = cbSmoothGraphics.Checked;
  207. Report.ReportInfo.Name = tbName.Text;
  208. Report.ReportInfo.Author = tbAuthor.Text;
  209. Report.ReportInfo.Version = tbVersion.Text;
  210. Report.ReportInfo.Description = tbDescription.Text;
  211. Report.ReportInfo.Picture = pbPicture.Image;
  212. Report.ReportInfo.SavePreviewPicture = cbSavePreviewPicture.Checked;
  213. Report.ScriptLanguage = rbC.Checked ? Language.CSharp : Language.Vb;
  214. List<string> assemlies = new List<string>();
  215. for (int i = 0; i < lbRefAssemblies.Items.Count; i++)
  216. {
  217. assemlies.Add(lbRefAssemblies.Items[i].ToString());
  218. }
  219. Report.ReferencedAssemblies = assemlies.ToArray();
  220. Report.Password = tbPassword.Text;
  221. if (rbDetach.Checked)
  222. {
  223. Report.BaseReport = "";
  224. }
  225. else if (rbInherit.Checked && !String.IsNullOrEmpty(lblBaseName.Text.Trim()))
  226. {
  227. Report.BaseReport = lblBaseName.Text;
  228. }
  229. Report.EmailSettings.RecipientsText = tbRecipients.Text;
  230. Report.EmailSettings.Subject = tbSubject.Text;
  231. Report.EmailSettings.Message = tbMessage.Text;
  232. }
  233. return true;
  234. }
  235. public override void Localize()
  236. {
  237. base.Localize();
  238. MyRes res = new MyRes("Forms,ReportOptions");
  239. Text = res.Get("");
  240. pnGeneral.Text = res.Get("General");
  241. pnDescription.Text = res.Get("Description");
  242. pnScript.Text = res.Get("Script");
  243. pnSecurity.Text = res.Get("Security");
  244. pnInheritance.Text = res.Get("Inheritance");
  245. pnEmail.Text = res.Get("Email");
  246. cbDoublePass.Text = res.Get("DoublePass");
  247. cbCompress.Text = res.Get("Compress");
  248. cbUseFileCache.Text = res.Get("UseFileCache");
  249. cbConvertNulls.Text = res.Get("ConvertNulls");
  250. lblTextQuality.Text = res.Get("TextQuality");
  251. cbxTextQuality.Items.AddRange(new string[] {
  252. res.Get("QualityDefault"), res.Get("QualityRegular"),
  253. res.Get("QualityClearType"), res.Get("QualityAntiAlias"),
  254. res.Get("QualitySingleBPP"), res.Get("QualitySingleBPPGridFit")});
  255. cbSmoothGraphics.Text = res.Get("SmoothGraphics");
  256. lblName.Text = res.Get("Name");
  257. lblAuthor.Text = res.Get("Author");
  258. lblDescription.Text = res.Get("Description1");
  259. lblVersion.Text = res.Get("Version");
  260. lblPicture.Text = res.Get("Picture");
  261. btnLoad.Text = res.Get("Load");
  262. btnClear.Text = res.Get("Clear");
  263. cbSavePreviewPicture.Text = res.Get("SavePreviewPicture");
  264. lblCreated.Text = res.Get("Created");
  265. lblModified.Text = res.Get("Modified");
  266. lblLanguage.Text = res.Get("Language");
  267. lblScriptNote.Text = res.Get("Note");
  268. lblRefAssemblies.Text = res.Get("RefAssemblies");
  269. btnAdd.Text = res.Get("Add");
  270. btnRemove.Text = res.Get("Remove");
  271. lblPassword.Text = res.Get("Password");
  272. lblRetypePassword.Text = res.Get("RetypePassword");
  273. lblChooseInheritance.Text = res.Get("Choose");
  274. rbDontChange.Text = res.Get("DontChange");
  275. rbDetach.Text = res.Get("Detach");
  276. rbInherit.Text = res.Get("Inherit");
  277. btnBrowse.Text = res.Get("Browse");
  278. lblRecipients.Text = res.Get("Recipients");
  279. lblSubject.Text = res.Get("Subject");
  280. lblMessage.Text = res.Get("Message");
  281. }
  282. public override void UpdateDpiDependencies()
  283. {
  284. base.UpdateDpiDependencies();
  285. lblInheritance.Width = lblInheritance.Parent.Width - 18;
  286. //tbDescription.Height = btnLoad.Top - tbDescription.Top - 14;
  287. lbRefAssemblies.Height = btnAdd.Top - lbRefAssemblies.Top - 12;
  288. tbRecipients.Height = lblSubject.Top - tbRecipients.Top - 8;
  289. tbMessage.Height = pnEmail.Height - tbMessage.Top - 16;
  290. tbDescription.Image = GetImage(68);
  291. }
  292. public ReportOptionsForm(Report report)
  293. {
  294. this.report = report;
  295. InitializeComponent();
  296. Localize();
  297. Init();
  298. UIUtils.CheckRTL(this);
  299. UpdateDpiDependencies();
  300. }
  301. }
  302. }