SaveData Functions

Here are some save function for some situations:

Yes/No

/// <summary>
        ///
        /// </summary>
        /// <param name="ds"></param>
        public void SaveDataSet(DataSet ds, string parent, string child)
        {
            string message = "Do you want to save the data";
            string caption = "Save Data";

            if (ds.HasChanges())
            {
                DialogResult result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        //DataSet dsChanged = ds.GetChanges();
                        DataTable tblParent = null;
                        DataTable tblChild = null;

                        if (!string.IsNullOrEmpty(parent))
                        {
                            tblParent = ds.Tables[parent].GetChanges(); //error if table not existing
                        }

                        if (!string.IsNullOrEmpty(child))
                        {
                            tblParent = ds.Tables[child].GetChanges(); //error if table not existing
                        }

                        DataSet ds1 = new DataSet();
                        if (tblParent != null) ds1.Tables.Add(tblParent);
                        DataSet ds2 = new DataSet();
                        if (tblChild != null) ds2.Tables.Add(tblChild);

                        //call save method(tblParent, tblChild, null);
                        ds.AcceptChanges();
                    }
                    catch (Exception ex)
                    {
                        //Error.ErrProc(ex);
                        MessageBox.Show("Error");
                        ds.RejectChanges();
                        return;
                    }

                }
            }
            else
            {
                MessageBox.Show("No Data Saved.");
                ds.RejectChanges();
            }

        }

Yes/No/Cancel

public void SaveDataSetWithCancel(DataSet ds, string parent, string child)
        {
            string message = "Do you want to save the data";
            string caption = "Save Data";

            if (ds.HasChanges())
            {
                DialogResult result = MessageBox.Show(message, caption, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        //DataSet dsChanged = ds.GetChanges();
                        DataTable tblParent = null;
                        DataTable tblChild = null;

                        if (!string.IsNullOrEmpty(parent))
                        {
                            tblParent = ds.Tables[parent].GetChanges(); //error if table not existing
                        }

                        if (!string.IsNullOrEmpty(child))
                        {
                            tblParent = ds.Tables[child].GetChanges(); //error if table not existing
                        }

                        DataSet ds1 = new DataSet();
                        if (tblParent != null) ds1.Tables.Add(tblParent);
                        DataSet ds2 = new DataSet();
                        if (tblChild != null) ds2.Tables.Add(tblChild);

                        //call save method(tblParent, tblChild, null);
                        ds.AcceptChanges();
                        MessageBox.Show("Data Saved.");
                    }
                    catch (Exception ex)
                    {
                        //Error.ErrProc(ex);
                        MessageBox.Show("Error, try again");
                        return;
                    }

                }
                else if (result == DialogResult.No)
                {
                    MessageBox.Show("your data modified is discarded. it is not saved.");
                    ds.RejectChanges();
                    return;
                }
                else
                {
                    MessageBox.Show("your data is not saved. but it is still here.");
                    return;
                }
            }
            else
            {
                MessageBox.Show("No new Data Saved.");
                ds.RejectChanges();
            }

        }

SaveData Functions,布布扣,bubuko.com

时间: 2024-10-28 19:54:50

SaveData Functions的相关文章

Adding New Functions to MySQL(User-Defined Function Interface UDF、Native Function)

catalog 1. How to Add New Functions to MySQL 2. Features of the User-Defined Function Interface 3. User-Defined Function 4. UDF Argument Processing 5. UDF Return Values and Error Handling 6. UDF Compiling and Installing 7. Adding a New Native Functio

POJ 1080 Human Gene Functions(LCS)

Description It is well known that a human gene can be considered as a sequence, consisting of four nucleotides, which are simply denoted by four letters, A, C, G, and T. Biologists have been interested in identifying human genes and determining their

学习Oracle分析函数(Analytic Functions)

Oracle提供了一些功能很强大的分析函数,使用这些函数可以完成可能需要存储过程来实现的需求. 分析函数计算基于一组数据行的聚合值,它们不同于聚合函数的是,它们为每一组返回多行结果.分析函数是除ORDER BY子句之外,在查询语句中最后执行的.所有的join和所有的WHERE ,GROUP BY 和HAVING子句都在分析函数之前执行.所以分析函数只能出现在select或ORDER BY子句中. 下图为11.2版本官方文档中给出的语法示意图: 下面简单介绍一下各个部分: analytic_fun

模板类的约束模板友元函数:template friend functions

本来这篇博客是不打算写的,内容不是很难,对于我自己来讲,更多的是为了突出细节. 所谓template friend functions,就是使友元函数本身成为模板.基本步骤:1,在类定义的前面声明每个模板函数.eg:template <typename T> void counts(); template <typename T> void report<>(T &);2,在类声明中再次将模板声明为友元. template <typename TT>

&lt;QtEndian&gt; - Endian Conversion Functions

The <QtEndian> header provides functions to convert between little and big endian representations of numbers. More... Functions T qFromBigEndian(const uchar * src)T qFromBigEndian(T src)T qFromLittleEndian(const uchar * src)T qFromLittleEndian(T src

python3.4 build in functions from 官方文档 翻译中

2. Built-in Functions https://docs.python.org/3.4/library/functions.html?highlight=file The Python interpreter has a number of functions and types built into it that are always available. They are listed here in alphabetical order.     Built-in Funct

The difference of Methods and Functions

Functions Functions are self-contained chunks of code that perform a specific task. You give a function a name that identifies what it does, and this name is used to “call” the function to perform its task when needed. Swift’s unified function syntax

NVIDIA CG语言 函数之所有数学类函数(Mathematical Functions)

数学类函数(Mathematical Functions) abs(x) 返回标量和向量x的绝对值 如果x是向量,则返回每一个成员的绝对值 acos(x) 返回标量和向量x的反余弦 x的范围是[-1,1],返回值的范围是[0,π], 如果x是向量,则返回每一个成员的反余弦 all(x) 如果一个布尔标量为真,或者布尔向量的所有成员为真,则返回真 any(x) 如果一个布尔标量为真,或者布尔向量成员存在真值,则返回真 asin(x) 返回标量和向量x的反正弦 x的范围是[-1,1],返回值的范围是

Functions

1 Local static variables Local static variables are not destroyed when the function ends; they are destroyed when the program terminates. 2. Function parameter list Parameter names are optional. However, there is no way to use an unnamed parameter. A