473,396 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 ***
Sep 28 '08 #1
8 1532
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 "successfull" 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" <cs*******@yahoo.comschrieb im Newsbeitrag
news:%2***************@TK2MSFTNGP06.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 ***
Sep 28 '08 #2


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 ***
Sep 29 '08 #3
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 ***
Sep 29 '08 #4


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 ***
Oct 2 '08 #5
On 2 Oct, 10:16, csharpula csharp <csharp...@yahoo.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 Developersdexhttp://www.developersdex.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()
{
InitializeComponent();
}

private void Form1_FormClosing(object sender, FormClosingEventArgs
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_TextChanged(object sender, EventArgs e)
{
// If change occurs the is dirty is true
_isDirty = true;
}

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

// if successful set isDirty to false
_isDirty = false;
}
}
Oct 3 '08 #6
On 3 Oct, 13:18, "JTC^..^" <d...@jazzthecat.co.ukwrote:
On 2 Oct, 10:16, csharpula csharp <csharp...@yahoo.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 Developersdexhttp://www.developersdex.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()
* *{
* * * InitializeComponent();
* *}

* *private void Form1_FormClosing(object sender, FormClosingEventArgs
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_TextChanged(object sender, EventArgs e)
* *{
* * * // If change occurs the is dirty is true
* * * _isDirty = true;
* *}

* *private void button1_Click(object 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_TextChanged handler by
attaching it to each control - you don't need a handler for each.
Oct 3 '08 #7
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 ***
Oct 6 '08 #8
On 6 Oct, 09:47, csharpula csharp <csharp...@yahoo.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 Developersdexhttp://www.developersdex.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;
OnPropertyChanged();
}
}

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

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

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

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

private void LoadData()
{
}

private void Form1_FormClosing(object sender, FormClosingEventArgs
e)
{
// check if data is dirty
if (_myDataItem.IsDirty == true)
{
MessageBox.Show("You have a pending save");
// cancel the closing event
e.Cancel = true;
}
}

private void button1_Click(object sender, EventArgs e)
{
// Save here
_myDataItem.Save();
}
Oct 14 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nel | last post by:
I have recently updated an on-line petition at www.fuelprotest.com The confirmation email contained a verification link like...
7
by: SOR | last post by:
Although this currently defeats the spam bots in some respects - isnt it just a mater of time before the spammers figure out a way to verify a signup via email using rotating disposable email...
0
by: pwilliams | last post by:
NCOALink Change of Address Verification Each year over 40 million Americans change their mailing addresses. This change is equivalent to every person in California deciding to change addresses...
13
by: Kal | last post by:
I have a small console app that started out in dotnet 1.1 in VS 2003. That version can be copied to a W2K3 server where it runs fine. I set up a new project in VS 2005 and copied the code files...
3
by: Jano | last post by:
Hi - Happy New Year! I have a web-site which accepted paypal payment for membership. No-one's buying so I want to make it free. The page which inputs the member details into the database needs...
3
by: KDawg44 | last post by:
Hi, I would like a verification image for new sign ups on a website. Is there a way to call the PHP script through an AJAX call and have the image passed back and then display? Is there a way...
15
by: sb5309 | last post by:
When one uses CAPTCHA (form with verification code), a session is required to keep the session data. In examples that I have seen on the net, I did not see a session is closed after use. ...
4
by: sangam56 | last post by:
I have used cookieless mode of ASPState sql server session mode. I have used the CreateUserWizard to register user in the web site. And users must click the email verification link before being...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.