Пример #1
0
 public static string GetConfigEntry(string key, string Default, string Explanation = "")
 {
     try
     {
         using (var db = new DAL.SteinbachEntities())
         {
             string res = db.config.Where(s => s.mkey == key).FirstOrDefault().value;
             return(res);
         }
     }
     catch (Exception ex)
     {
         try
         {
             using (var db = new DAL.SteinbachEntities())
             {
                 var c = new DAL.config {
                     mkey = key, value = Default, Description = Explanation
                 };
                 db.AddToconfig(c);
                 db.SaveChanges();
                 return(Default);
             }
         }
         catch (Exception)
         {
             return("");
         }
     }
 }
Пример #2
0
        public static T GetConfigEntry(string key, string Default, string Explanation = "")
        {
            string result = string.Empty;

            try
            {
                using (var db = new DAL.SteinbachEntities())
                {
                    var res = db.config.Where(s => s.mkey == key).FirstOrDefault();

                    if (res != null)
                    {
                        result = res.value;
                    }
                    else
                    {
                        var c = new DAL.config {
                            mkey = key, value = Default, Description = Explanation
                        };
                        db.AddToconfig(c);
                        db.SaveChanges();
                        result = Default;
                    }
                }



                object ReturnVal = result;


                if (typeof(T) == typeof(string))
                {
                    return((T)ReturnVal);
                }

                else if (typeof(T) == typeof(int))
                {
                    int  iOut  = 0;
                    bool check = int.TryParse(result, out iOut);

                    if (check)
                    {
                        object ret = iOut;
                        return((T)ret);
                    }
                }

                return(default(T));
            }
            catch (Exception)
            {
                return(default(T));
            }
        }