Is there a "Change" Flag for Teechart?

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Dave
Advanced
Posts: 139
Joined: Mon Sep 22, 2008 12:00 am

Is there a "Change" Flag for Teechart?

Post by Dave » Mon Jun 07, 2010 1:00 pm

Hello Support

Id like to be able to prompt the user if he/she would like to save changes before closing the chart.
Is there a flag I can check that will tell me if the user has made any changes using the chart editor?

regards

Dave
Advanced
Posts: 139
Joined: Mon Sep 22, 2008 12:00 am

Re: Is there a "Change" Flag for Teechart?

Post by Dave » Wed Jun 09, 2010 10:54 am

Hi

Maybe Ive not explained this well enough.

Im developing a windows application using C#.NET. The application contains a form that includes a TChart.

I have provided an option that lets the user use the Tchart editor. As most of you will know this allows the user to change things such as titles, legends, scales, Themes, colours as well as removing series.

After the editor has closed can I query the Tchart such that I can find out whether anything within the chart has been modified? Is there a flag set for example. If I know something has changed I can then prompt the user (when he is closing the application) to save changes.

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Is there a "Change" Flag for Teechart?

Post by Yeray » Thu Jun 10, 2010 9:13 am

Hi Dave,

There isn't a flag to check it right now. However, we are investigating if we can propose a solution to do it manually.
We'll be back here asap.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Is there a "Change" Flag for Teechart?

Post by Yeray » Thu Jun 10, 2010 1:51 pm

Hi Dave,

First, note that this is a feature request already in the wish list to be implemented in future releases (TV52011331).

In the meanwhile here it is an example of how you could do it manually, saving the chart into a MemoryStream before opening the editor, saving the chart once the editor is closed, and compare both memorystreams:

Code: Select all

        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            bar1.FillSampleValues();
            bar1.XValues.DataMember = "X";
            bar1.YValues.DataMember = "Bar";
        }

        void EditorButton1_Click(object sender, EventArgs e)
        {
            byte[] tmpbuffer1, tmpbuffer2;

            tmpbuffer1 = ExportToByte(tChart1);
            tChart1.ShowEditor();
            tmpbuffer2 = ExportToByte(tChart1);

            if (!CompareByteArrays(tmpbuffer1, tmpbuffer2))
            {
                System.Windows.Forms.SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                saveFileDialog1.DefaultExt = tChart1.Export.Template.FileExtension;
                saveFileDialog1.FileName = tChart1.Name + "." + saveFileDialog1.DefaultExt;
                saveFileDialog1.Filter = Steema.TeeChart.Texts.TENFilter;
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    tChart1.Export.Template.Save(saveFileDialog1.FileName);
                }
            }
        }

        private byte[] ExportToByte(Steema.TeeChart.TChart chart)
        {
            System.IO.MemoryStream tmpStream = new System.IO.MemoryStream();
            chart.Export.Template.Save(tmpStream);
            byte[] tmpbuffer = new byte[tmpStream.Length];
            tmpStream.Read(tmpbuffer, 0, (int)tmpStream.Length);

            return tmpbuffer;
        }

        private static bool CompareByteArrays(byte[] data1, byte[] data2)
        {
            if (data1 == null && data2 == null) return true;
            if (data1 == null || data2 == null) return false;
            if (data1.Length != data2.Length) return false;

            for (int i = 0; i < data1.Length; i++)
            {
                if (data1[i] != data2[i]) return false;
            }

            return true;
        }
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Dave
Advanced
Posts: 139
Joined: Mon Sep 22, 2008 12:00 am

Re: Is there a "Change" Flag for Teechart?

Post by Dave » Thu Jun 10, 2010 2:09 pm

Thanks Yeray I will try this out.

Dave
Advanced
Posts: 139
Joined: Mon Sep 22, 2008 12:00 am

Re: Is there a "Change" Flag for Teechart?

Post by Dave » Thu Jun 10, 2010 4:03 pm

Yeray have you tested this example?

It seems to work almost every time when the editor is displayed and closed. ie. it correctly identifies when changes have been made and when no changes have been made.

However the exception is the very first time the editor is displayed and closed. In this case it always records changes have been even when there is no change.

Im not sure what is happening. The arrays should be reset every time, its a bit bizarre.

Dave
Advanced
Posts: 139
Joined: Mon Sep 22, 2008 12:00 am

Re: Is there a "Change" Flag for Teechart?

Post by Dave » Thu Jun 10, 2010 4:19 pm

Im getting it to work correctly ALL times if I do the following before calling the editor. Dont know if something is being cleared somewhere but it works

byte[] tmpbuffer1, tmpbuffer2;
tmpbuffer1 = ExportToByte(tChart1);
tmpbuffer2 = ExportToByte(tChart1);

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Is there a "Change" Flag for Teechart?

Post by Yeray » Fri Jun 11, 2010 9:33 am

Hi Dave,

We found that the first time the Serialization doesn't serialize DataMembers. That's the reason why I added the following lines in the InitializeChart process, before the first call to the comparison:

Code: Select all

bar1.XValues.DataMember = "X";
bar1.YValues.DataMember = "Bar";
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Is there a "Change" Flag for Teechart?

Post by Yeray » Fri Jun 11, 2010 2:03 pm

Hi Dave,

In addition to above, the problem was that the Serialization accesses the DataSource, and when the GetDataSource is accessed the DataMembers are set. This may involve in a different serialization the first time.
We've included a check that ensures the DataSource won't be serialized if it's null so the workaround explained in my last post won't be needed. This will be included in the next maintenance release.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply