zoukankan      html  css  js  c++  java
  • 取得程序设定的常用代码.

    using System;
    using System.Configuration;

    namespace HXBTools.Util
    {
        
    /// <summary>
        
    /// Class1 的摘要说明。
        
    /// </summary>

        public class Config
        
    {
            
    public Config()
            
    {
                
    //
                
    // TODO: 在此处添加构造函数逻辑
                
    //
            }


            
    public static string GetSettingString(string sKeyName, string sDefault)
            
    {
                
    string s = ConfigurationSettings.AppSettings[sKeyName];
                
    if (s == null)
                
    {
                    
    return sDefault;
                }

                
    else
                
    {
                    
    return s;
                }

            }


            
    public static int GetSettingInt(string sKeyName, int iDefault)
            
    {
                
    string s = Config.GetSettingString(sKeyName, null);
                
    if (s == null)
                    
    return iDefault;

                
    int i;
                
    try
                
    {
                    i 
    = int.Parse(s);
                    
    return i;
                }

                
    catch
                
    {
                    
    return iDefault;
                }


            }



            
    public static long GetSettingLong(string sKeyName, long lDefault)
            
    {
                
    string s = Config.GetSettingString(sKeyName, null);
                
    if (s == null)
                    
    return lDefault;

                
    long l;
                
    try
                
    {
                    l 
    = long.Parse(s);
                    
    return l;
                }

                
    catch
                
    {
                    
    return lDefault;
                }


            }



            
    public static decimal GetSettingDecimal(string sKeyName, decimal dcDefault)
            
    {
                
    string s = Config.GetSettingString(sKeyName, null);
                
    if (s == null)
                    
    return dcDefault;

                
    decimal dc;
                
    try
                
    {
                    dc 
    = decimal.Parse(s);
                    
    return dc;
                }

                
    catch
                
    {
                    
    return dcDefault;
                }


            }


            
            
    public static DateTime GetSettingDateTime(string sKeyName, DateTime dtDefaule)
            
    {
                
    string s = Config.GetSettingString(sKeyName, null);
                
    if (s == null)
                    
    return dtDefaule;

                DateTime dt;
                
    try
                
    {
                    dt 
    = DateTime.Parse(s);
                    
    return dt;
                }

                
    catch
                
    {
                    
    return dtDefaule;
                }


            }


            
    public static bool GetSettingBool(string sKeyName, bool bDefault)
            
    {
                
    string s = Config.GetSettingString(sKeyName, null);
                
    if (s == null)
                    
    return bDefault;
                
                
    switch(s.Trim().ToLower())
                
    {
                    
    case "true":
                    
    case "":
                    
    case "":
                    
    case "1":
                    
    case "yes":
                    
    case "ok":
                    
    case "-1":
                        
    return true;
                    
    case "false":
                    
    case "0":
                    
    case "":
                    
    case "":
                    
    case "":
                    
    case "":
                    
    case "no":
                    
    case "not":
                    
    case "never":
                        
    return false;
                    
    default:                    
                        
    return bDefault;
                }

            }
            
        }

    }

  • 相关阅读:
    几个用于序列化的代码片段
    一个统计查询写的哥要哭了
    pb数据窗口数据输入的下拉选择效果
    PB代码块
    获取指定表的字段信息sql2005
    TSQL时间格式化显示
    Atitit 为什么互联网金融会得到高层的支持 面子工程战略 政绩战略 大事业战略 高层需要在意识形态创新全球,政绩工程 得到合法性。 银行有很多家,而且别的区域也有。。不独特。。但是支付
    Atitit 软件与互联网理论 attilax总结
    Atitit 软件与开发的未来趋势 attilax总结 1.1. Sdx软件重构世界 软件定义未来 1 1.2. 《软件和信息技术服务业发展规划(20162020年)》( 2 1.3. Iot物联
    Atitit it业界与软件界的定律 原则 准则 法则 效应
  • 原文地址:https://www.cnblogs.com/haoxiaobo/p/89932.html
Copyright © 2011-2022 走看看