writing a library class properly - asp.net

This is my very first library class that i am writing and i feel like i need to load up on that topic but cannot find the best sources. I have a web forms project that uploads a pdf and creates a qrcode for it and places it in the document. I need to create a library but don't know where to start or the exact structure. Every method it's own subclass in the library class? or can i have them all in one and what is a professional way of going about this.
This is party of my web forms application that i need to create a library for:
void UpdateStudentSubmissionGrid()
{
var usr = StudentListStep2.SelectedItem as User;
var lib = AssignmentListStep2.SelectedItem as Library;
if (usr == null || lib == null) return;
using (var dc = new DocMgmtDataContext())
{
var subs =
(from doc in dc.Documents
where doc.OwnedByUserID == usr.ID && doc.LibraryID == lib.ID
select new {DocID = doc.ID, Assignment = doc.Library.Name, Submitted = doc.UploadDT})
.OrderByDescending(c => c.Submitted)
.ToList();
StudentSubmissionGrid.DataSource = subs;
}
}
How do i start with this method?

By the looks of things you are using this function for a single webpage. You can call that function from any event i.e. user hits submit button. On the. Click the button and it will create a onclick event. Call the code from inside there UpdateStudentSubmissionGrid(); Just make sure the function is not nested inside another event or function. Webforms is already a class, you are just placing a function within the class.

Related

Get WorkflowDesigner from a ModelItem

I am trying to create a custom IExpressionEditor. In order to new one up I need a WorkflowDesigner, All I have is the ModelItem representing my custom activity. Is it possible to access the WorkflowDesigner from a given ModelItem?
List<ModelItem> variables = new List<ModelItem>();
List<ModelItem> nameSpaces = new List<ModelItem>();
// get the activity from the datacontext
CustomActivityDesigner cad = this.DataContext as CustomActivityDesigner;
// try to get the variables
// look for variables collection cant seem to find them
ModelProperty mp = cad.ModelItem.Properties["Variables"];
if(mp != null && mp.PropertyType == typeof(Collection<Variable>))
{
mp.Collection.ToList().ForEach(i => variables.Add(i));
}
// get name spaces
ModelProperty mp2 = cad.ModelItem.Properties["NameSpaces"];
if(mp2 != null && mp2.PropertyType == typeof(Collection<NameSpace>))
{
mp2.Collection.ToList().ForEach(i => nameSpaces.Add(i));
}
// finally need the WorkflowDesigner object
WorkflowDesigner designer = Modelitem.Root....??? as WorkflowDesigner
// now we have what we need we can create the IExpressionEditor
CustomExpressionEditior ce = new CustomExpressionEditior(designer, variables, nameSpaces)
Following the Using a Custom Expression Editor as reference, it seems you should be able to create a Custom Expression Service (which will be creating the Expression Editor instances) and register it to the Services collection on the WorkflowDesigner.
Once it's registered in the WorkflowDesigner's Services collection, you'll be able to:
Get the editing context for the ModelItem by using ModelItemExtensions.GetEditingContext
Access the Services property of the returned EditingContext
Retrieve the Custom Expression Service you registered on the WorkflowDesginer
Hope it helps!

Changelog method based on project tracker template

Based on the project tracker I have integrated a changelog into my app that relates my UserSettings model to a UserHistory model. The latter contains the fields FieldName, CreatedBy, CreatedDate, OldValue, NewValue.
The relation between both models works fine. Whenever a record is modified, I can see the changes in a changelog table. I now want add an "undo"-button to the table that allows the admin to undo a change he clicks on. I have therefore created a method that is handled by the widget that holds the changelog record:
function undoChangesToUserRecord(changelog) {
if (!isAdmin()) {
return;
}
var fieldName = changelog.datasource.item.FieldName;
var record = changelog.datasource.item.UserSettings;
record[fieldName] = changelog.datasource.item.OldValue;
}
In theory method goes the connection between UserHistory and UserSettings up to the field and rewrites its value. But when I click on the button, I get a "Failed due to circular reference" error. What am I doing wrong?
I was able to repro the issue with this bit of code:
google.script.run.ServerFunction(app.currentPage.descendants.SomeWidget);
It is kinda expected behavior, because all App Maker objects are pretty much complex and Apps Script RPC has some limitations.
App Maker way to implement it would look like this:
// Server side script
function undoChangesToUserRecord(key) {
if (!isAdmin()) {
return;
}
var history = app.models.UserHistory.getRecord(key);
if (history !== null) {
var fieldName = history.FieldName;
var settings = history.UserSettings;
settings[fieldName] = history.OldValue;
}
}
// Client side script
function onUndoClick(button) {
var history = widget.datasource.item;
google.script.run
.undoChangesToUserRecord(history._key);
}

Relational Query - 2 degrees away

I have three models:
Timesheets
Employee
Manager
I am looking for all timesheets that need to be approved by a manager (many timesheets per employee, one manager per employee).
I have tried creating datasources and prefetching both Employee and Employee.Manager, but I so far no success as of yet.
Is there a trick to this? Do I need to load the query and then do another load? Or create an intermediary datasource that holds both the Timesheet and Employee data or something else?
You can do it by applying a query filter to the datasource onDataLoad event or another event. For example, you could bind the value of a dropdown with Managers to:
#datasource.query.filters.Employee.Manager._equals
- assuming that the datasource of the widget is set to Timesheets.
If you are linking to the page from another page, you could also call a script instead of using a preset action. On the link click, invoke the script below, passing it the desired manager object from the linking page.
function loadPageTimesheets(manager){
app.showPage(app.pages.Timesheets);
app.pages.Timesheets.datasource.query.filters.Employee.Manager._equals = manager;
app.pages.Timesheets.datasource.load();
}
I would recommend to redesign your app a little bit to use full power of App Maker. You can go with Directory Model (Manager -> Employees) plus one table with data (Timesheets). In this case your timesheets query can look similar to this:
// Server side script
function getTimesheets(query) {
var managerEmail = query.parameters.ManagerEmail;
var dirQuery = app.models.Directory.newQuery();
dirQuery.filters.PrimaryEmail._equals = managerEmail;
dirQuery.prefetch.DirectReports._add();
var people = dirQuery.run();
if (people.length === 0) {
return [];
}
var manager = people[0];
// Subordinates lookup can look fancier if you need recursively
// include everybody down the hierarchy chart. In this case
// it also will make sense to update prefetch above to include
// reports of reports of reports...
var subortinatesEmails = manager.DirectReports.map(function(employee) {
return employee.PrimaryEmail;
});
var tsQuery = app.models.Timesheet.newQuery();
tsQuery.filters.EmployeeEmail._in = subortinatesEmails;
return tsQuery.run();
}

Suitescript 1.0 & handlebars js

I'm starting to review some requirements for processing a few HTML templates from within a suitelet using suitescript 1.0
I haven't been able to find any information on handlebars JS from within netsuite but I'm curious as to whether there is any requirements to configuring a suitelet that does the server side generation as I would prefer to use it compared to using the client side implementation
If anyone can share anything useful on how to get a suitelet prepared to make use of handlebars that would be greatly appreciated
Below is a sample from one of the Suitelets I use handlebars in. You setup the suitelet like any other by creating a form object and a html field to hold the rendered handlebar template.
var screenTitle = 'Form Title';
var form = nlapiCreateForm(screenTitle);
var pageTemplate = nlapiLoadFile('SuiteBundles/Bundle '+sitBundleId+'/src/sit_html_templates/template.html').getValue();
var hbTemplate = Handlebars.compile(pageTemplate);
Handlebars.registerHelper('if_eq',function(a,b,opts) { if(a == b) { return opts.fn(this); } else { return opts.inverse(this); } });
Handlebars.registerHelper('json', function(context) { return JSON.stringify(context); });
var data = {
"account_id":nlapiGetContext().getCompany(),
"bundle_id":sitBundleId,
"other_data":{}
};
var htmlValue = hbTemplate(data);
var templateField = form.addField('template_section','inlinehtml','',null,'main_group');
templateField.setDefaultValue(htmlValue);
response.writePage(form);
Thats the basics. Of course the Handlebar library must be added to the library sublist on the NetSuite Suitelet record.

Is there a API from Flex/Flash to list all the UIComponent?

I am trying to create an API utility using Adobe AIR where given a component name it should list all it methods, variables, and other properties of that component.
But I could not find an API to list all the UIComponents of Flex/Flash.
is there an API to lookup all the UIComponent or if there is no such API, can anyone tell me how do i lookup the components?
Note: I have tried using flash.utils.describeType() but it is not able to suit my requirement as the input to the method is passed dynamically using TextInput.
~Jegan
It sounds like you are asking two things:
How to list all of the properties/methods of a UIComponent.
How to list all of the UIComponents in the Flex SDK.
The first one can be done with describeType(). Given that the method is passed dynamically using TextInput, you need to just include all of the UIComponents into the SWF. You can do that with the following include statement for each component in the SDK (this example is with the Button):
include mx.controls.Button; Button;.
Then you can do something like this:
var className:String = myTextArea.text; // mx.controls::Button or mx.controls.Button
var clazz:Class = flash.utils.getDefinitionByName(className);
var methods:Array = getMethods(clazz);
var properties:Array = getProperties(clazz); // write a similar method for accessors and variables
/**
* Returns a list of methods for the class.
* Pass in the superclass depth for how many classes
* you want this to return (class tree). If it's -1, it will return the whole method list
*/
public static function getMethods(target:Object, superclassDepth:int = -1, keepGeneratedMethods:Boolean = false):Array
{
var description:XML = DescribeTypeCache.describeType(target).typeDescription;
var hierarchy:Array = getHierarchy(target);
var methodList:XMLList = description..method;
methodList += description.factory..method; // factory is required if target is Class
var methodName:String
var methods:Array = [];
var declaredBy:String;
var methodXML:XML;
var i:int = 0;
var n:int = methodList.length();
for (i; i < n; i++)
{
methodXML = methodList[i];
declaredBy = methodXML.#declaredBy;
methodName = methodXML.#name;
// we break because the xml list is orded hierarchically by class!
if (superclassDepth != -1 && hierarchy.indexOf(declaredBy) >= superclassDepth)
break;
// ignore methods that start with underscore:
if (methodName.charAt(0) == "_" && !keepGeneratedMethods)
continue;
methods.push(methodName);
}
// sort the method list, so there's some kind of order to the report:
methods.sort(Array.CASEINSENSITIVE);
return methods;
}
The second one, listing the UIComponents in the SDK, is a bit more complex because there's no stable list of components in the SDK (depends on version, etc.). What you can do, however, is get a list of every class included in the swf. You do this by generating a Link Report (which is used for helping out modules), which is just a compiler argument:
-link-report=my_report.xml
Then you can figure out a way to find the unique xml nodes in that file, and which ones extend UIComponent. I use ruby and the nokogiri xml parser for ruby to do that. There is also a neat AIR app to visualize the Link Report.
If you're doing the first case, that method should get you started on listing all properties/methods of a UIComponent. If you're doing the second, that will give you a list of all UIComponents included in the swf.
Let me know if that helps,
Lance
Do you need to do anything with the data, other than displaying it? If not, it might be easiest to pull up the right page from Adobe's online API docs.

Resources