zoukankan      html  css  js  c++  java
  • SaveData Functions

    Here are some save function for some situations:

    Yes/No

    /// <summary>
            ///保存数据到WCF
            /// </summary>
            /// <param name="ds"></param>
            public void SaveDataSetSingleOrTwoTables(DataSet ds, string parent, string child)
            {
                string message = "您想保存数据吗?";
                string caption = "保存数据";
    
                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);
                            TJ_Nurse_Service.NurseSvc.QualityCheckIBLLClient saveData = new TJ_Nurse_Service.NurseSvc.QualityCheckIBLLClient();
                            saveData.QualityCheckUpdate(ds1, ds2, null);
                            ds.AcceptChanges();
                            MessageBox.Show("数据已保存。");
                        }
                        catch (Exception ex)
                        {
                            Error.ErrProc(ex);
                            MessageBox.Show("由于某种原因,数据不能保存。数据丢失。");
                            ds.RejectChanges();
                            return;
                        }
    
                    }
                    else
                    {
                        ds.RejectChanges();
                        MessageBox.Show("数据没有保存。已修改的已恢复。");
                    }
                }
                else
                {
                    MessageBox.Show("没有数据要保存。");
                    ds.RejectChanges();
                }
    
            }
    View Code


    Yes/No/Cancel

     /// <summary>
            /// 保存数据到WCF
            /// </summary>
            /// <param name="ds"></param>
            /// <param name="parent"></param>
            /// <param name="child"></param>
            public void SaveDataSetSingleOrTwoTablesWithCancel(DataSet ds, string parent, string child)
            {
                string message = "您想保存数据吗";
                string caption = "保存数据";
    
                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);
                            TJ_Nurse_Service.NurseSvc.QualityCheckIBLLClient saveData = new TJ_Nurse_Service.NurseSvc.QualityCheckIBLLClient();
                            saveData.QualityCheckUpdate(ds1, ds2, null);
                            ds.AcceptChanges();
                            MessageBox.Show("数据已保存。");
                        }
                        catch (Exception ex)
                        {
                            Error.ErrProc(ex);
                            ds.RejectChanges();
                            MessageBox.Show("由于某种原因,数据不能保存。数据丢失。");
                            return;
                        }
    
                    }
                    else if (result == DialogResult.No)
                    {
                        ds.RejectChanges();
                        MessageBox.Show("数据没有保存。已修改的已恢复。");
                        return;
                    }
                    else
                    {
                        MessageBox.Show("您修改的数据没有保存。但您可以保存。");
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("没有数据要保存。");
                    ds.RejectChanges();
                }
    
            }
    View Code

    Yes/No => WCF

    /// <summary>
            ///保存数据到WCF
            /// </summary>
            /// <param name="ds"></param>
            public void SaveDataSetSingleOrTwoTables(DataSet ds, string parent, string child)
            {
                string message = "您想保存数据吗?";
                string caption = "保存数据";
    
                //index_item data changed?
                UpdateCurrentDetail();
    
                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))
                            {
                                tblChild = 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);
                            TJ_Nurse_Service.NurseSvc.QualityCheckIBLLClient saveData = new TJ_Nurse_Service.NurseSvc.QualityCheckIBLLClient();
                            saveData.QualityCheckUpdate(ds1, ds2, null);
                            ds.AcceptChanges();
                            MessageBox.Show("数据已保存。");
                        }
                        catch (Exception ex)
                        {
                            Error.ErrProc(ex);
                            MessageBox.Show("由于某种原因,数据不能保存。数据丢失。");
                            ds.RejectChanges();
                            return;
                        }
    
                    }
                    else
                    {
                        ds.RejectChanges();
                        MessageBox.Show("数据没有保存。已修改的已恢复。");
                    }
                }
                else
                {
                    MessageBox.Show("没有数据要保存。");
                    ds.RejectChanges();
                }
    
            }
    View Code

    Yes/No/Cancel

    /// <summary>
            /// 保存数据到WCF
            /// </summary>
            /// <param name="ds"></param>
            /// <param name="parent"></param>
            /// <param name="child"></param>
            public void SaveDataSetSingleOrTwoTablesWithCancel(DataSet ds, string parent, string child)
            {
                string message = "您想保存数据吗";
                string caption = "保存数据";
    
                //index_item data changed?
                UpdateCurrentDetail();
    
                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))
                            {
                                tblChild = 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);
                            TJ_Nurse_Service.NurseSvc.QualityCheckIBLLClient saveData = new TJ_Nurse_Service.NurseSvc.QualityCheckIBLLClient();
                            saveData.QualityCheckUpdate(ds1, ds2, null);
                            ds.AcceptChanges();
                            MessageBox.Show("数据已保存。");
                        }
                        catch (Exception ex)
                        {
                            Error.ErrProc(ex);
                            ds.RejectChanges();
                            MessageBox.Show("由于某种原因,数据不能保存。数据丢失。");
                            return;
                        }
    
                    }
                    else if (result == DialogResult.No)
                    {
                        ds.RejectChanges();
                        MessageBox.Show("数据没有保存。已修改的已恢复。");
                        return;
                    }
                    else
                    {
                        MessageBox.Show("您修改的数据没有保存。但您可以保存。");
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("没有数据要保存。");
                    ds.RejectChanges();
                }
    
            }
    View Code
  • 相关阅读:
    子组 正则表达式
    正则表达式
    马云北大演讲完整版:真心话,什么才是阿里的核心竞争力?-2014-03-20
    形象化的spring 依赖注入原理
    程序员的六层境界
    apache配置运行zendframework 2
    php编写简单的页面跳转功能
    php随机验证码
    没啥说的
    PHP流程控制语句下
  • 原文地址:https://www.cnblogs.com/kevinygq/p/3901444.html
Copyright © 2011-2022 走看看