make a structure for generating custom form - c#

I am developing a learning management system with asp.net c#
now i want to make a structure for generating university forms , but these forms may change in future or need new forms , i want make a structure for admin of website to generate custom forms without coding, admin only add the name of feilds and type of that ( its text box or checkbox and ... ) , then it should be a printable from , also admin can add explanation in diffrent part of the form...
i dont know how should i do this ?
is there any API or some idea ?

You could make some clases for your form controls like: InputBox, TextBox, CheckBox, RadioButton. Then a form class could contain lists of your input controls.
class FormInputControl
{
public string Description { get; set; } //Every form input has a description like User, link, what you want that form input control instance to describe
public abstract object Value { get; set; }
}
class InputBox : FormInputControl
{
public string Text { get; set; }
public overwrite object Value
{
get { return Text; }
set { Text = value as string; }
}
}
class Form
{
public IList<FormInputControls> { get; set; }
}

Related

Creating a list of checkboxes from a DbSet

I have a table in the database that is a list of Products. Then I have a Fundraiser class (made into a controller and views) that will have a "collection" of Products. The point is that "for this fundraiser, I am selling these selected products".
My idea is to have a list of checkboxes so that the user can select which products are to be included in the fundraiser. I know that the typical way of doing this is to have an intermediary table that has a compound key of ProductID and FundraiserID. I don't want to do this.
Instead my idea is to make the list of products as checkboxes, use JavaScript to create a JSON string as the user selects/deselects the checkboxes, then save that JSON string into a simple text field in the Fundraiser table.
public class Fundraiser
{
public int FundraiserID { get; set; }
public string EventName { get; set; }
public string ItemsList { get; set; }
}
public class Product
{
public int ProductID { get; set; }
public string Name { get; set; }
}
So, there are two ways that I'm thinking this can go.
How do I write raw HTML so that I can manually iterate through the resultset of the Products table and create the checkboxes. Right now, the HTML I write is shown literally on the page instead of interpreted.
ViewData["ProductList"] = "<input type='checkbox' id='prod12' checked>";
// Is escaped or something so that it does not render as an HTML input
OR
Is there an HTML helper or some other tool that will do this through class methods or something (so that I can do it in the 'proper' OOP style)?
ViewData["ProductList"] = new ListOfCheckBoxes(_context.Products, "ProductID"......
I have a background in PHP programming, and I rarely used third-party code, so having all these high-level "helpers" is really confusing for me. I just want to write the code!

Is there a way to add some tabs inside Composite C1 function?

I'm using the 6th version of Composite c1 CMS. And i'm wondering about is there a way to add some kind of tabs inside Composite functions? For example, i have a function
`public override string MyFunction
{
get { return "SomeFunction"; }
}
[FunctionParameter(DefaultValue = "Nad")]
public string Name { get; set; }
[FunctionParameter(Label = "Another Field", DefaultValue = "", HideInSimpleView = true)]
public string AnotherField { get; set; }
[FunctionParameter(Label = "Some URL", DefaultValue = "", HideInSimpleView = true)]
public string Url { get; set; }`
and i want to add some kind of tabs, that user should interact with only if, for example, function name is "someName". Is there a way to a)add that kind of tabs,so user could switch between the main tab and the other one; and b)conditionally show this tabs?
No, unlike data forms, where the layout can be defined with an xml file, such functionality isn't implemented for function calls, when one only can define widgets for function parameters but not the overall layout.
It is possible to replace the default function call editor with a custom page, like it is done in the FormBuilder package.
http://docs.c1.orckestra.com/Console/Custom-Function-Call-Editor
The available example is based on WebForms, so it may not be straightforward to implement.
http://docs.c1.orckestra.com/Console/Custom-Function-Call-Editor/Web-Form

Web API parameter bind dynamically built table values to model?

Imagine you were creating an online test application. It lets you add multiple choice test questions. So the user clicks "Add new test question" and a dialog comes up. The dialog asks for the question text, a list of possible answers, and the correct answer. So something like this would be the result:
Which color has the letter "G" in it?
A. Blue
B. Red
----> C. Green
D. Yellow
E. Purple
Each new question would likely have different number of options. So the next question might be:
Does NYC have 5 boroughs?
---> A. Yes
B. No
I've created a dialog that allows the user to dynamically build those questions (add answers, designate the correct one, etc.) inside a form. Is there anyway to create a model and a Web API that would seamlessly parameter bind that structure on form submission? I was thinking something crazy like if my form had a table in it that I could somehow bind that to an array in my model? Probably doesn't work like that but looking for a creative idea.
A model could look something like this
public class Question {
public string Text { get; set;}
public IList<Answer> Answers { get; set;}
}
public class Answer {
public string Label { get; set;}
public string Text { get; set;}
public bool IsCorrect { get; set;}
}
An api endpoint would take a collection of these to form a test.
public class Test {
public IList<Question> Questions { get; set; }
}
public class TestController : ApiController {
[HttpPost]
public IHttpActionResult Create(Test test) { ... }
}

How to send array of images to rdlc reports?

I need to send a title and some images to a report, this is my class
public class ReportDataModel
{
public string Text { get; set; }
public IEnumerable<byte[]> Images { get; set; }
}
when i create a report file and set this class as the data source class and then in design i drag the image field on the report, on run time instead of images it shows "#Error".
thanks in advance.
Your current ReportDataModel uses a master-detail structure. It would not therefore be possible to drag drop images property to the report without showing "#Error", unless you are using an expression like First(Fields!Image.Value).
Change ReportDataModel to the following:
public class ReportDataModel
{
public string Text { get; set; }
public byte[] Image { get; set; }
}
Then instead of dragging the Image field directly on the report, drag an Image from the ToolBox, set image source to Database, select your image field and set MIME type.

Store and export data from C# application

I'll try to explain this the best I can!
I've written a program that after some input, it brings 4 different text items into 4 separate ReadOnly text boxes. I'm looking to, when a user presses a button, it will store the strings from the 4 text boxes into a sort of table, so when the user then enters more data and it calculates a new set of 4 strings, when the press the button again, it will also store these values. The user should then be able to print this "table" style storage or export it into excel.
One approach could be -
You can create a class with properties to hold all the text boxes values. Something like this -
public class TextBoxesDetails
{
public string TextBox1Value { get; set; }
public string TextBox2Value { get; set; }
public string TextBox3Value { get; set; }
public string TextBoxValue4 { get; set; }
}
Next declare a global list variable of this type
List<TextBoxesDetails> TextBoxesDetails = new List<TextBoxesDetails>();
Now at the click of your button, store the values of all the text boxes into this list -
TextBoxesDetails.Add(new TextBoxesDetails {
TextBox1 = TextBox1Value.Text ,
TextBox2 = TextBox2Value.Text,
TextBox3 = TextBox3Value.Text,
TextBox4 = TextBox4Value.Text"
});
Now just use this list to export to excel.
For exporting to excel, I would suggest, https://npoi.codeplex.com/. The tool is also available through Nuget packages.

Categories