示例#1
0
 //Перводит строку в HashSet
 public static SetS ToPropertyHashSet(this string str, string separator = ";")
 {
     try
     {
         var res = new SetS();
         if (!str.IsEmpty())
         {
             string[] st = str.Split(new[] { separator }, StringSplitOptions.RemoveEmptyEntries);
             foreach (var s in st)
             {
                 res.Add(s);
             }
         }
         return(res);
     }
     catch { return(new SetS()); }
 }
示例#2
0
        //То же самое, но база данных не задается
        public void SaveDicToTable <T>(DicS <T> dic, string tabl, string keyField = "Code", string keyField2 = "", string delField = "Del") where T : ISaveToRecDao
        {
            var old = new SetS();
            var add = new SetS();

            using (var rec = new RecDao(this, tabl, RecordsetTypeEnum.dbOpenTable))
                while (rec.Read())
                {
                    var code = rec.GetString(keyField);
                    if (!keyField2.IsEmpty())
                    {
                        code += "." + rec.GetString(keyField2);
                    }
                    if (dic.ContainsKey(code))
                    {
                        old.Add(code);
                    }
                    else
                    {
                        rec.Put(delField, true);
                    }
                }
            Execute("DELETE * FROM " + tabl + " WHERE " + delField + "=True");

            foreach (var ap in dic.Keys)
            {
                if (!old.Contains(ap))
                {
                    add.Add(ap);
                }
            }
            using (var rec = new RecDao(this, tabl, RecordsetTypeEnum.dbOpenTable))
            {
                while (rec.Read())
                {
                    dic[rec.GetString(keyField) + (keyField2.IsEmpty() ? "" : ("." + rec.GetString(keyField2)))].ToRecordset(rec, false);
                }
                foreach (var p in add.Keys)
                {
                    dic[p].ToRecordset(rec, true);
                }
            }
        }