Use Save as and custom save event.

Hi,

i want to use custom save dialog when user click on save command of the designer.So i have used the option using a custom event.

Config.DesignerSettings.CustomSaveDialog += DesignerSettings_CustomSaveDialog;

But once i used the above code it will replace the save as menu event as well.My requirement is once user click on save button i ned to save the report to database.and on save as event i need users to give the option of saving report in to the file system.

and my second question is once we have attached the custom event using the above code, i need to detach the event as well.i can see in the designer toolbar save button only enable when user has done changes.can we track that user changes? i meant it has been expose as a event or a property? then i can easily attached and detached the event.

tnx in advance


chaminda

Comments

  • edited 5:26PM
    Hello,

    Sorry, both Save and SaveAs commands use the same code. If you replace the standard Save dialog, it will be used for SaveAs as well. You may add a button in your dialog to allow save to file.
    Normally you should attach an event before running a designer, and detach it after closing the designer. You cannot cath the modified flag.
  • edited 5:26PM
    Hi,

    Any Event argument to check which button has clicked by user ?

    chaminda
  • edited 5:26PM
    I am using FastReport designer with a Custom save dialog.i have couple of issues when i am using custom save event.i am attaching the event on the form load event of report designer form. and detach it when the form is closed.When user click on save button for the first time dialog box is prompt without any issues.and then save button is getting disabled in the tool bar ant the menu.but if user do any changes for the report then the save buttons and the menu will be enable again.
    But if user click on save button again now that attached event is not working.is there a work around for that?

  • edited 5:26PM
    AlexTZ wrote: »
    Hello,

    Sorry, both Save and SaveAs commands use the same code. If you replace the standard Save dialog, it will be used for SaveAs as well. You may add a button in your dialog to allow save to file.
    Normally you should attach an event before running a designer, and detach it after closing the designer. You cannot cath the modified flag.


    Hi ,

    I could not find CustomSaveDialog in .NET version.I am using verison 1.9.11.0



    Config.DesignerSettings.CustomSaveDialog += DesignerSettings_CustomSaveDialog;

    Kind regards
  • edited May 2018
    upgrade your version, or add your custom button and inject to designer form, code to learn the structure :

    notes: open the text file with excel ( separator = | ) and https://msdn.microsoft.com/en-us/library/dd460756.aspx
    using System;
    using System.IO;
    using System.Windows.Forms;
    
    namespace ReportDesigner
    {
        static class Program
        {
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                FastReport.Utils.Config.DesignerSettings.CustomSaveDialog += new FastReport.Design.OpenSaveDialogEventHandler(CustomSaveDialog);
    
                using (FastReport.Report report = new FastReport.Report())
                {
                    using (FastReport.Design.StandardDesigner.DesignerForm designer = new FastReport.Design.StandardDesigner.DesignerForm(false))
                    {
                        designer.Designer.Report = report;
                        //designer.ShowInTaskbar = true;
                        //designer.ShowDialog();
                        using (StreamWriter writer = new StreamWriter(@"d:\designercontrols.txt"))
                        {
                            DumpControls(writer, 0, designer.GetType().ToString(), designer.Controls);
                        }
                    }
                }
            }
    
            private static int counter = 0;
    
            private static void DumpControls(StreamWriter writer, int parentId, string parentType, Control.ControlCollection objects) 
            {            
                foreach (Control item in objects)
                {
                    counter += 1;
                    Type t = item.GetType();
                    string typeName = t.ToString();
    
                    writer.WriteLine(string.Format("Parent Id: {0}|Parent Type: {1}|Id: {2}|Name: {3}|Type: {4}", parentId, parentType, counter, item.Name, typeName));
    
                    if (item.HasChildren)
                        DumpControls(writer, counter, typeName, item.Controls);
    
                    if (t.GetProperty("Items") != null)
                    {
                        dynamic x = item;
                        if (x.Items.Count > 0)
                            DumpItems(writer, counter, typeName, x.Items);
                    }
                    if (t.GetProperty("SubItems") != null)
                    {
                        dynamic x = item;
                        if (x.SubItems.Count > 0)
                            DumpItems(writer, counter, typeName, x.SubItems);
                    }
                }
            }
    
            private static void DumpItems(StreamWriter writer, int parentId, string parentType, dynamic objects)
            {
                foreach (var item in objects)
                {
                    counter += 1;
                    Type t = item.GetType();
                    string typeName = t.ToString();
                    if (t == typeof(string))
                        continue;
    
                    writer.WriteLine(string.Format("Parent Id: {0}|Parent Type: {1}|Id: {2}|Name: {3}|Type: {4}", parentId, parentType, counter, item.Name, typeName));
    
                    if (t.GetProperty("Items") != null)
                    {
                        dynamic x = item;
                        if (x.Items.Count > 0)
                            DumpItems(writer, counter, typeName, x.Items);
                    }
                    if (t.GetProperty("SubItems") != null)
                    {
                        dynamic x = item;
                        if (x.SubItems.Count > 0)
                            DumpItems(writer, counter, typeName, x.SubItems);
                    }
                }
            }
    
            private static void DumpSubItems(StreamWriter writer, int parentId, string parentType, dynamic objects)
            {
                foreach (var item in objects)
                {
                    counter += 1;
                    Type t = item.GetType();
                    string typeName = t.ToString();
                    if (t == typeof(string))
                        continue;
    
                    writer.WriteLine(string.Format("Parent Id: {0}|Parent Type: {1}|Id: {2}|Name: {3}|Type: {4}", parentId, parentType, counter, item.Name, typeName));
    
                    if (t.GetProperty("Items") != null)
                    {
                        dynamic x = item;
                        if (x.Items.Count > 0)
                            DumpItems(writer, counter, typeName, x.Items);
                    }
                    if (t.GetProperty("SubItems") != null)
                    {
                        dynamic x = item;
                        if (x.SubItems.Count > 0)
                            DumpItems(writer, counter, typeName, x.SubItems);
                    }
                }
            }
    
            private static void CustomSaveDialog(object sender, FastReport.Design.OpenSaveDialogEventArgs e)
            {
                Console.Beep();
            }
        }
    }
    
  • I solve it using the following way:


    designerControl1.MainMenu.miFileSaveAs.Visible = false;

    var buttonSaveAs = designerControl1.MainMenu.CreateMenuItem("save as", new EventHandler(MySaveAs));

    designerControl1.MainMenu.miFile.SubItems.Insert(4, buttonSaveAs);


    public void MySaveAs(object sender, EventArgs e)

    {

    using (SaveFileDialog dialog = new SaveFileDialog())

    {

    dialog.Filter = "Report files (*.frx)|*.frx";

    // get default file name from e.FileName

    dialog.FileName = ".frx";

    if (dialog.ShowDialog() == DialogResult.OK)

    {

    designerControl1.Report.Save(dialog.FileName);

    }

    }

    }

    good luck🙂

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.