예제 #1
0
        /// <summary>
        /// 文件信息保存
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private void FileInfoSavle(HttpContext context)
        {
            string fileInfoListStr             = context.Request.Form["FileInfoList"];
            string sorceID                     = context.Request.Form["SOURCE_ID"];
            string sorceType                   = context.Request.Form["SOURCE_TYPE"];
            string sorceField                  = context.Request.Form["SOURCE_FIELD"];
            List <T_SYS_ATTACHModel> modelList = SerializerHelper.Deserialize <List <T_SYS_ATTACHModel> >(fileInfoListStr);
            var           sql                  = SqlModel.SelectAll().From(DB.T_SYS_ATTACH).Where(T_SYS_ATTACH.SOURCE_ID == sorceID & T_SYS_ATTACH.SOURCE_TYPE == sorceType & T_SYS_ATTACH.SOURCE_FIELD == sorceField);
            var           existAttachList      = sql.ExecToDynamicList();
            List <string> keepFileIDList       = new List <string>();//保留的文件信息ID

            modelList.ForEach(model => {
                bool isKeep = existAttachList.Exists(c => StringHelper.DynamicToString(c["ID"]) == StringHelper.DynamicToString(model.ID));
                if (isKeep)
                {
                    keepFileIDList.Add(model.ID.ToString());
                }
                else
                {
                    model.SOURCE_ID    = sorceID;
                    model.SOURCE_TYPE  = sorceType;
                    model.SOURCE_FIELD = sorceField;
                    model.Insert();
                }
            });
            //删除过时的文件信息
            T_SYS_ATTACHModel deleteModel = new T_SYS_ATTACHModel();

            existAttachList.ForEach(attach => {
                if (!keepFileIDList.Contains(StringHelper.DynamicToString(attach["ID"])))
                {
                    deleteModel.Delete(T_SYS_ATTACH.ID == attach["ID"]);
                }
            });
        }
예제 #2
0
        public static void FileMessageSave(RequestData data, string sorceID)
        {
            string attachStr = string.Format("[{0}]", data.Get("attach"));
            var    list      = SerializerHelper.Deserialize <List <List <T_SYS_ATTACHModel> > >(attachStr);

            List <T_SYS_ATTACHModel> attachList = new List <T_SYS_ATTACHModel>();

            foreach (var childList in list)
            {
                attachList.AddRange(childList);
            }

            string sourceMsg  = string.Format("[{0}]", data.Get("source"));//只有SOURCE_TYPE、SOURCE_FIELD
            var    sourceList = SerializerHelper.Deserialize <List <T_SYS_ATTACHModel> >(sourceMsg);

            foreach (T_SYS_ATTACHModel source in sourceList)
            {
                var    oneSource  = attachList.Where(item => item.SOURCE_TYPE == source.SOURCE_TYPE && item.SOURCE_FIELD == source.SOURCE_FIELD);
                string sorceType  = source.SOURCE_TYPE;
                string sorceField = source.SOURCE_FIELD;
                List <T_SYS_ATTACHModel> modelList = oneSource != null?oneSource.ToList() : new List <T_SYS_ATTACHModel>();

                var           sql             = SqlModel.SelectAll().From(DB.T_SYS_ATTACH).Where(T_SYS_ATTACH.SOURCE_ID == sorceID & T_SYS_ATTACH.SOURCE_TYPE == sorceType & T_SYS_ATTACH.SOURCE_FIELD == sorceField);
                var           existAttachList = sql.ExecToDynamicList();
                List <string> keepFileIDList  = new List <string>();//保留的文件信息ID
                modelList.ForEach(model => {
                    bool isKeep = existAttachList.Exists(c => StringHelper.DynamicToString(c["ID"]) == StringHelper.DynamicToString(model.ID));
                    if (isKeep)
                    {
                        keepFileIDList.Add(model.ID.ToString());
                    }
                    else
                    {
                        model.SOURCE_ID = sorceID;
                        model.Insert();
                    }
                });
                //删除过时的文件信息
                T_SYS_ATTACHModel deleteModel = new T_SYS_ATTACHModel();
                existAttachList.ForEach(attach => {
                    if (!keepFileIDList.Contains(StringHelper.DynamicToString(attach["ID"])))
                    {
                        deleteModel.Delete(T_SYS_ATTACH.ID == attach["ID"]);
                    }
                });
            }
        }