settingdbfunc.cs

来自「JAVA的精彩实例」· CS 代码 · 共 79 行

CS
79
字号
using System;
using System.Collections.Generic;
using System.Text;

using System.Data;

namespace feiyun0112.cnblogs.com.CSDNReader.Functions
{
    class SettingDBFunc
    {
        private SettingDBFunc()
        {
        }
        public static  DataView GetSetting()
        {
            DataView dvw = null;
            DBFunc db = new DBFunc(false, false);
            try
            {                
                string strSql = "select * from Settings";
                dvw = db.GetDataSet(strSql).Tables[0].DefaultView;
                
            }
            catch (Exception e)
            {
                dvw = null;
                MsgFunc.ShowWarning(e.Message);
                return dvw;
            }
            finally
            {
                db.CloseCon();
            }
            return dvw;
        }

        public static string GetSettingValue(string strID)
        {
            DataView dvwSetting = GetSetting();
            string strValue = "";
            dvwSetting.RowFilter = "ID='" + strID + "'";
            if (dvwSetting.Count > 0)
            {
                strValue = dvwSetting[0]["Value"].ToString();
            }

            return strValue;
        }


        public static void SetSetting(string strID, string strNewValue)
        {
            DBFunc db = new DBFunc(false, false);

            
            try
            {
                string strSql = "delete * from Settings where Id='" + strID + "'";
                db.ExecuteSql(strSql);

                strSql = "insert into Settings([ID],[Value]) values('" + strID + "','" + DBFunc.SpecialChar(strNewValue) + "')";
                db.ExecuteSql(strSql);
            }
            catch (Exception e)
            {
                
                MsgFunc.ShowWarning(e.Message);
                return ;
            }
            finally
            {
                db.Dispose();
            }


        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?