Exemplo n.º 1
0
        int DeleteAll()
        {
            int retTrueCount = 0;

            addList = addList.OrderBy(info => info.GetType().Name).ToList();
            BaseMODEL        topMod  = null;
            List <BaseMODEL> toplist = new List <BaseMODEL>();

            foreach (var info in deleteList)
            {
                FileClass fs = FileClass.GetFileClassBymodel(info);
                if (topMod != null && topMod.GetType().Name == topMod.GetType().Name)
                {
                    deleteItem(toplist, info);
                }
                else
                {
                    toplist = GetListModel(fs.ReadFile(), info.GetType());
                    deleteItem(toplist, info);
                }
                fs.WriteInFile(JsonConvert.SerializeObject(toplist), true);
                retTrueCount++;
            }
            return(retTrueCount);
        }
Exemplo n.º 2
0
        public static FileClass GetFileClassBymodel(BaseMODEL info)
        {
            string dataSaveFile = "/DataFile/JSONDATA";
            string fileName     = info.GetType().Name + ".datas";

            return(new FileClass(dataSaveFile, fileName));
        }
Exemplo n.º 3
0
        void deleteItem(List <BaseMODEL> list, BaseMODEL info)
        {
            PropertyInfo[] p    = info.GetType().GetProperties();
            List <KeyBox>  kbox = GetKeyList(p, info);

            foreach (KeyBox item in kbox)
            {
                if (string.IsNullOrEmpty(item.Dbpara.Value + ""))
                {
                    throw new Exception("未将主键赋值");
                }
            }
            if (kbox.Count == 1)
            {
                var wlist = list.Where(s => s.GetType().GetProperties().Where(ps => ps.Name == kbox[0].Key && ps.GetValue(s, null) == kbox[0].Dbpara.Value).Count() == 1);
                foreach (var item in wlist)
                {
                    list.Remove(item);
                }
            }
            if (kbox.Count == 2)
            {
                var wlist = list.Where(s => s.GetType().GetProperties().Where(ps => ps.Name == kbox[0].Key && ps.GetValue(s, null) == kbox[0].Dbpara.Value).Count() == 1 && s.GetType().GetProperties().Where(ps => ps.Name == kbox[1].Key && ps.GetValue(s, null) == kbox[1].Dbpara.Value).Count() == 1);
                foreach (var item in wlist)
                {
                    list.Remove(item);
                }
            }
        }