Save verification

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • csharpula csharp

    #1

    Save verification


    Hello,
    I am developing an application which gui is very rich with controls. My
    question is what is the best way to implement on c# a save require
    mechanism? I mean to check before closing the application that the
    changes in data in every control been saved?

    Thanks!


    *** Sent via Developersdex http://www.developersdex.com ***
  • =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?=

    #2
    Re: Save verification

    Hi,

    use a global boolean variable and set it to
    true on every change of your data. right before
    your application closes, check whether the varibale
    is set to true and if yes, save the changes or ask
    the user whether he/she/it wants the changes saved
    If the user saves the data manually, just set the variable
    to false on a "successful l" saving operation!


    Regards

    Kerem

    --
    -----------------------
    Beste Grüsse / Best regards / Votre bien devoue
    Kerem Gümrükcü
    Latest Project: http://www.codeplex.com/restarts
    Latest Open-Source Projects: http://entwicklung.junetz.de
    -----------------------
    "This reply is provided as is, without warranty express or implied."
    "csharpula csharp" <csharpula@yaho o.comschrieb im Newsbeitrag
    news:%23JnTNDWI JHA.468@TK2MSFT NGP06.phx.gbl.. .
    >
    Hello,
    I am developing an application which gui is very rich with controls. My
    question is what is the best way to implement on c# a save require
    mechanism? I mean to check before closing the application that the
    changes in data in every control been saved?
    >
    Thanks!
    >
    >
    *** Sent via Developersdex http://www.developersdex.com ***

    Comment

    • csharpula csharp

      #3
      Re: Save verification



      Is there a more efficent way than just set the variable on every
      control? I have a lot of controls and it seems that I need on update of
      each one to update this global variable? No other more efficient way?

      Thanks!

      *** Sent via Developersdex http://www.developersdex.com ***

      Comment

      • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

        #4
        Re: Save verification

        It is only one statement in the validating event setting a bool value to
        true. I don't believe this to be inefficient.

        "csharpula csharp" wrote:
        >
        >
        Is there a more efficent way than just set the variable on every
        control? I have a lot of controls and it seems that I need on update of
        each one to update this global variable? No other more efficient way?
        >
        Thanks!
        >
        *** Sent via Developersdex http://www.developersdex.com ***
        >

        Comment

        • csharpula csharp

          #5
          Re: Save verification



          But I need to update it each time someone updates any control? By the
          way,how can I do it,is there an update event common to each gui control
          in c#? Isn't therea more efficent way for this ?

          *** Sent via Developersdex http://www.developersdex.com ***

          Comment

          • JTC^..^

            #6
            Re: Save verification

            On 2 Oct, 10:16, csharpula csharp <csharp...@yaho o.comwrote:
            But I need to update it each time someone updates any control? By the
            way,how can I do it,is there an update event common to each gui control
            in c#?  Isn't therea more efficent way for this ?
            >
            *** Sent via Developersdexht tp://www.developersd ex.com***
            In it's simpliest implementation this form cannot be closed if the
            value in textBox1 changes and if the user hasn't saved (button1)

            public partial class Form1 : Form
            {
            private bool _isDirty;
            public Form1()
            {
            InitializeCompo nent();
            }

            private void Form1_FormClosi ng(object sender, FormClosingEven tArgs
            e)
            {
            // check if data is dirty
            if (_isDirty == true)
            {
            MessageBox.Show ("You have a pending save");
            // cancel the closing event
            e.Cancel = true;
            }
            }

            private void textBox1_TextCh anged(object sender, EventArgs e)
            {
            // If change occurs the is dirty is true
            _isDirty = true;
            }

            private void button1_Click(o bject sender, EventArgs e)
            {
            // Save here

            // if successful set isDirty to false
            _isDirty = false;
            }
            }

            Comment

            • JTC^..^

              #7
              Re: Save verification

              On 3 Oct, 13:18, "JTC^..^" <d...@jazztheca t.co.ukwrote:
              On 2 Oct, 10:16, csharpula csharp <csharp...@yaho o.comwrote:
              >
              But I need to update it each time someone updates any control? By the
              way,how can I do it,is there an update event common to each gui control
              in c#?  Isn't therea more efficent way for this ?
              >
              *** Sent via Developersdexht tp://www.developersd ex.com***
              >
              In it's simpliest implementation this form cannot be closed if the
              value in textBox1 changes and if the user hasn't saved (button1)
              >
              public partial class Form1 : Form
              {
                 private bool _isDirty;
                 public Form1()
                 {
                    InitializeCompo nent();
                 }
              >
                 private void Form1_FormClosi ng(object sender, FormClosingEven tArgs
              e)
                 {
                    // check if data is dirty
                    if (_isDirty == true)
                    {
                       MessageBox.Show ("You have a pending save");
                       // cancel the closing event
                       e.Cancel = true;
                    }
                 }
              >
                 private void textBox1_TextCh anged(object sender, EventArgs e)
                 {
                    // If change occurs the is dirty is true
                    _isDirty = true;
                 }
              >
                 private void button1_Click(o bject sender, EventArgs e)
                 {
                    // Save here
              >
                    // if successful set isDirty to false
                    _isDirty = false;
                 }
              >
              >
              >
              }- Hide quoted text -
              >
              - Show quoted text -
              Furthermore, you can reuse the textBox1_TextCh anged handler by
              attaching it to each control - you don't need a handler for each.

              Comment

              • csharpula csharp

                #8
                Re: Save verification

                But if I don't want to keep the boolean inside the gui form,isn't there
                any better design consept for holding and updating this info outside of
                the form?

                Thank you!



                *** Sent via Developersdex http://www.developersdex.com ***

                Comment

                • JTC^..^

                  #9
                  Re: Save verification

                  On 6 Oct, 09:47, csharpula csharp <csharp...@yaho o.comwrote:
                  But if I don't want to keep the boolean inside the gui form,isn't there
                  any better design consept for holding and updating this info outside of
                  the form?
                  >
                  Thank you!
                  >
                  *** Sent via Developersdexht tp://www.developersd ex.com***

                  Absolutely.... My previous was example was in it's simpliest form.
                  When Refactored.....

                  /* When DataItem is new, it is IsDirty.
                  When DataItem is loaded, it is not Dirty.
                  When DataItem property has changed, it is Dirty.
                  When DataItem is saved, it is no longer dirty.*/

                  public class MyDataItem
                  {
                  private bool _isDirty;
                  public MyDataItem()
                  {
                  _isDirty = true;
                  }

                  private int _id;
                  public int Id
                  {
                  get{return _id;}
                  }
                  private string _name;
                  public string Name
                  {
                  get{return _name;}
                  set
                  {
                  _name = value;
                  OnPropertyChang ed();
                  }
                  }

                  public void LoadData()
                  {
                  _name = DALC.GetDataIte m(...);
                  _isDirty = false;
                  }

                  public void Save()
                  {
                  DALC.Save(out _id);
                  // if save successful
                  _isDirty = false;
                  }
                  private void OnPropertyChang ed()
                  {
                  _isDirty = false;
                  }
                  }

                  public partial class Form1 : Form
                  {
                  private MyDataItem _myDataItem;
                  public Form1()
                  {
                  InitializeCompo nent();
                  }

                  private void CreateNewItem
                  {
                  _myDataItem = new MyDataItem();
                  }

                  private void LoadData()
                  {
                  }

                  private void Form1_FormClosi ng(object sender, FormClosingEven tArgs
                  e)
                  {
                  // check if data is dirty
                  if (_myDataItem.Is Dirty == true)
                  {
                  MessageBox.Show ("You have a pending save");
                  // cancel the closing event
                  e.Cancel = true;
                  }
                  }

                  private void button1_Click(o bject sender, EventArgs e)
                  {
                  // Save here
                  _myDataItem.Sav e();
                  }

                  Comment

                  Working...