示例#1
0
        public static FormModel CreateFromTemplate(long sourceId, long formId, long templateId)
        {
            FormModel form = GetItem(templateId);

            if (form == null)
            {
                return(null);
            }

            Delete(formId);
            form.ID       = formId;
            form.SourceID = sourceId;
            SetItem(form);

            IEnumerable <FormAdmin> admins = GetItemAdmins(templateId);

            foreach (FormAdmin admin in admins)
            {
                admin.ID = 0;
            }
            SetItemAdmins(formId, admins);

            IEnumerable <FieldModel> fields = FieldDAO.GetItems(templateId);

            foreach (FieldModel field in fields)
            {
                field.ID       = WorkLib.GetItem.NewSN();
                field.ParentID = formId;
                FieldDAO.SetItem(field);
            }

            return(form);
        }
示例#2
0
        public static void SaveTemplate(long id, string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return;
            }

            FormModel item = GetItem(id);

            item.ID       = WorkLib.GetItem.NewSN();
            item.SourceID = null;
            SetItem(item);

            string sql = $"Update Form Set TemplateName = N'{ name.Replace("'", "''") }' Where ID = { item.ID }";

            SQLData.Database db = new SQLData.Database(WebInfo.Conn);
            db.ExecuteNonQuery(sql);

            IEnumerable <FormAdmin> admins = GetItemAdmins(id);

            foreach (FormAdmin admin in admins)
            {
                admin.ID = 0;
            }
            SetItemAdmins(item.ID, admins);

            IEnumerable <FieldModel> fields = FieldDAO.GetItems(id);

            foreach (FieldModel field in fields)
            {
                field.ID       = WorkLib.GetItem.NewSN();
                field.ParentID = item.ID;
                FieldDAO.SetItem(field);
            }
        }