WebButton.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using FastReport.Dialog;
  2. using System.Windows.Forms;
  3. using static FastReport.Web.Constants;
  4. namespace FastReport.Web
  5. {
  6. public partial class Dialog
  7. {
  8. private void ButtonClick(ButtonControl button)
  9. {
  10. if (button.DialogResult == DialogResult.OK)
  11. {
  12. if (FormClose(button, CloseReason.None))
  13. CurrentForm++;
  14. }
  15. else if (button.DialogResult == DialogResult.Cancel)
  16. {
  17. if (FormClose(button, CloseReason.UserClosing))
  18. _webReport.Canceled = true;
  19. }
  20. button.OnClick(null);
  21. }
  22. private bool FormClose(ButtonControl button, CloseReason reason)
  23. {
  24. DialogPage dialog = button.Report.Pages[CurrentForm] as DialogPage;
  25. dialog.Form.DialogResult = button.DialogResult;
  26. FormClosingEventArgs closingArgs = new FormClosingEventArgs(reason, false);
  27. dialog.OnFormClosing(closingArgs);
  28. if (closingArgs.Cancel)
  29. return false;
  30. FormClosedEventArgs closedArgs = new FormClosedEventArgs(reason);
  31. dialog.OnFormClosed(closedArgs);
  32. dialog.ActiveInWeb = false;
  33. return true;
  34. }
  35. private string GetButtonHtml(ButtonControl control)
  36. {
  37. return $"<input style=\"{GetButtonStyle(control)}\"" +
  38. $" type=\"button\" name=\"{control.Name}\"" +
  39. $" value=\"{control.Text}\" onclick=\"{GetEvent(ONCLICK, control, REALOAD)}\"" +
  40. $" title=\"{control.Text}\" {(control.Enabled ? "" : "disabled")}/>";
  41. }
  42. private string GetButtonStyle(ButtonControl control)
  43. {
  44. return $"{GetStandardStyle(control)} {GetControlAlign(control)} padding:0;margin:0;";
  45. }
  46. }
  47. }