Пример #1
0
        public static void Save(int templateId, List <TemplateTable> Tables)
        {
            if (Tables == null || Tables.Count() == 0)
            {
                throw new Exception("模板字段不能为空");
            }
            var template = Get(templateId);

            if (template == null)
            {
                throw new Exception("模板不存在");
            }
            else if (template.IsCommon == true)
            {
                throw new Exception("系统模板禁止修改");
            }

            using (var scope = new TransactionScope())
            {
                RPTemplateFieldDetail.Delete(p => p.TemplateID == templateId);
                RPTemplateTableDetail.Delete(p => p.TemplateID == templateId);
                var checkTs = Tables.Where(t => t.Checked).ToList();
                foreach (var tb in checkTs)
                {
                    var templateTable = new RPTemplateTableDetail()
                    {
                        TableID    = tb.ID,
                        TemplateID = template.ID
                    };
                    RPTemplateTableDetail.Add(templateTable);
                    var checkFs = tb.Fields.Where(t => t.Checked).ToList();
                    foreach (TemplateField field in checkFs)
                    {
                        var fieldDetail = new RPTemplateFieldDetail()
                        {
                            TemplateID    = template.ID,
                            TableID       = tb.ID,
                            FieldID       = field.ID,
                            ConditionText = field.ConditionText,
                            IsOrderBy     = field.IsOrderBy,
                            IsDESC        = field.IsDESC
                        };
                        RPTemplateFieldDetail.Add(fieldDetail);
                    }
                }
                scope.Complete();
            }
        }
Пример #2
0
 public static void Delete(int templateId)
 {
     RPTemplateFieldDetail.Delete(p => p.TemplateID == templateId);
     RPTemplateTableDetail.Delete(p => p.TemplateID == templateId);
     RPTemplate.Delete(p => p.ID == templateId);
 }