Would I use a Main module in a GUI driven program? - module

Context I am a student learning with Pseudocode currently and my final project is to be a GUI driven program where it gets the location displays it and saves it to file each time it changes. Each Module has taken care of each bit but I don't know if I need a main module or not and if I do how to go about using it.
Pseudocode here
MODULE Init()
DECLARE OutputFile Append Mode Location
DECLARE Real Lat = Location.getLatitude()
DELCARE Real Long = Location.getLongitude()
OPEN Location "Location.txt"
LatitudeLabel.Text = realToString(Location.getLatitude())
LongitudeLabel.Text = realToString(Location.getLongitude())
WRITE Location Lat,Long
END MODULE
MODULE Location_LocationChanged()
LatitudeLabel.Text = realToString(Location.getLatitude())
LongitudeLabel.Text = realToString(Location.getLongitude())
WRITE Location Lat,Long
END MODULE
MODULE exitButton_Click()
CLOSE
END MODULE```

Related

Print SSRSReport to file (.PDF)

I need to find a way to "print" a SrsReport, in my case SalesInvoice, as .PDF (or any kind of file) to a specific location.
For this I modified the SRSPrintDestinationSettings to output the SalesInvoice-Report as a .PDF:
settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::PDF);
settings.overwriteFile(true);
settings.fileName(#'\\AXDEV\Bottomline\Test\test.pdf');
Somehow this gets ignored and I recive a Email with the report as .PDF attached.
For example this will run on ax 2012 but won't print to PDF for me.
SRSPrintDestinationSettings settings;
CustInvoiceJour custInvoiceJour;
SrsReportRunController controller = new SrsReportRunController();
PurchPurchaseOrderContract rdpContract = new PurchPurchaseOrderContract();
SalesInvoiceContract salesInvoiceContract = new SalesInvoiceContract();
select firstOnly1 * from custInvoiceJour where custInvoiceJour.SalesId != "";
// Define report and report design to use
controller.parmReportName(ssrsReportStr(SalesInvoice,Report));
// Use execution mode appropriate to your situation
controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
rdpContract.parmRecordId(custInvoiceJour.RecId);
controller.parmReportContract().parmRdpContract(rdpContract);
// Explicitly provide all required parameters
salesInvoiceContract.parmRecordId(custInvoiceJour.RecId); // Record id must be passed otherwise the report will be empty
controller.parmReportContract().parmRdpContract(salesInvoiceContract);
salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo()); // comment this code if tested in pre release
// Change print settings as needed
settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::PDF);
settings.overwriteFile(true);
settings.fileName(#'\\AXDEV\Bottomline\Test\test.pdf');
//tokens = settings as SrsPrintDestinationTokens();
//controller.parmPrintDestinationTokens(null);
//Suppress report dialog
controller.parmShowDialog(false);
// Execute the report
controller.startOperation();
Questions:
Is this the correct way to print a srsReport to .pdf?
Am I passing/setting the printerSettings correctly?
Where does it say "Send Email"?
EDIT: Code is working fine. We are using external code of a company which simply doesnt implement this.
Use the cleaner code of Alex Kwitny
Here is working code for me. I just quickly coded this from scratch/memory based off of glancing at yours, so compare for differences.
I have two things marked (1) and (2) for you to try with your code, or just copy/paste mine.
static void JobSendToPDFInvoice(Args _args)
{
SrsReportRunController controller = new SrsReportRunController();
SRSPrintDestinationSettings settings;
CustInvoiceJour custInvoiceJour = CustInvoiceJour::findRecId(5637925275);
SalesInvoiceContract salesInvoiceContract = new SalesInvoiceContract();
Args args = new Args();
controller.parmReportName(ssrsReportStr(SalesInvoice, Report));
controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
controller.parmShowDialog(false);
salesInvoiceContract.parmRecordId(custInvoiceJour.RecId);
salesInvoiceContract.parmDocumentTitle(CustInvoiceJour.InvoiceId);
salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo());
// (1) Try by passing args
args.record(custInvoiceJour);
args.parmEnum(PrintCopyOriginal::Original);
args.parmEnumType(enumNum(PrintCopyOriginal));
controller.parmReportContract().parmRdpContract(salesInvoiceContract);
controller.parmArgs(args);
// (2) Try explicitly preventing loading from last value
// controller.parmLoadFromSysLastValue(false);
// Change print settings as needed
settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::PDF);
settings.overwriteFile(true);
settings.fileName(#'C:\Temp\Invoice.pdf');
controller.startOperation();
}
Since you are talking about the sales invoice the report is using the print management feature and you cannot simply override the print settings like that.
You need to override the runPrintMgmt on the controller class and determine there whether you want default print management or your own code.
See this post for an example: http://www.winfosoft.com/blog/microsoft-dynamics-ax/manipulating-printer-settings-with-x

How to open/operate file in batch classes?

I have to import in a Table from file (csv for example).
I used this code:
public void run ()
{
TextIO textIO;
str filename, fileOpen, folder;
int handle;
Io thisMYFile;
FileIoPermission perm;
#File
#avifiles
#OCCRetryCount
[handle, filename] = WINAPI::findFirstFile(folder + "\\*.csv");
fileOpen = strFmt (folder + "\\" + filename);
perm = new FileIoPermission(fileOpen, 'w');
perm.assert();
thisMYFile = new CommaTextIo(fileOpen , 'w');
}
But in Debug the class IO thisMYFile is null and so I can't to read and get information.
In my class declaration I extends RunBaseBarch.
If I used a "normal" classes (not batch) I can read,write,move file etc, but now I can't to open.
I know the WinAPI classes not work in Batch, now I think there is also another way to read/open file in batch? With WinAPIServerclass I can findFirstFile ?
A clarification, I have also a same problem if I don't schedule the process batch : flag Batch processing is false, in the batch dialog, and clicked only Ok. (example image)
If you've a tutorial, any advice or help,
Thanks all,
enjoy!
Beware that the batch runs on an other machine, the AOS will not have access to your local files.
Therefore always use a full UNC file path to the file, ex. \\MyHost\Temp\x.csv
If new CommaTextIO fails to open the file, it returns null, it does not throw an exception. If you do not test for null your code will fail later.

Find total number of Unit Test in different DLLs

I have a Project where we have different kinds of unit tests in different DLLs. I want to know total number of unit tests in whole solution as well as the Test Category, Owner name, etc. using some VB/C# code.
Actually, I need to prepare report daily, where I need to show how many unit test are written by whom and under which category
I do not want to open Visual Studio to know this.
This is an example signature for one of the unit tests:
<TestMethod()> <Owner("OwnerName"), TestCategory("Category22")>
Public Sub TestName()
............
............
End Sub
Since the test methods are documented using .Net Framework attributes, you can use reflection to obtain the information you need. In VB.net, you can do it as follows.
'Imports System.Reflection
'Imports TestLibrary <- wherever the attributes are defined
Dim assy As Assembly = Assembly.LoadFrom(filename)
Dim owner As OwnerAttribute
Dim category As TestCategoryAttribute
For Each t As Type In assy.GetTypes()
For Each mi As MethodInfo In t.GetMethods(BindingFlags.Public Or BindingFlags.Instance)
If Not mi.GetCustomAttributes(GetType(TestMethodAttribute)).Count() = 0 Then
owner = mi.GetCustomAttribute(Of OwnerAttribute)()
category = mi.GetCustomAttribute(Of TestCategoryAttribute)()
System.Diagnostics.Debug.Print("{0} : Owner='{1}' Category='{2}'",
mi.Name, owner.OwnerName, category.CategoryName)
End If
Next
Next
You do have to add the test framework DLL as a reference to the project. filename is the full path to the compiled assembly (EXE, DLL, etc). I didn't include error checking for space reasons.
If your test method isn't public, or it's static you can get it by changing the binding flags to BindingFlags.NonPublic or BindingFlags.Static respectively. (More information is available in the documentation.)
Note that this method also works in C#
Assembly assy = Assembly.LoadFrom(filename);
OwnerAttribute owner = null;
TestCategoryAttribute category = null;
foreach(Type t in assy.GetTypes())
{
foreach (MethodInfo mi in t.GetMethods(BindingFlags.Public | BindingFlags.Instance))
{
if (mi.GetCustomAttributes(typeof(TestMethodAttribute)).Count() != 0)
{
owner = mi.GetCustomAttribute<OwnerAttribute>();
category = mi.GetCustomAttribute<TestCategoryAttribute>();
System.Diagnostics.Debug.Print("{0} : Owner='{1}' Category='{2}'",
mi.Name, owner.OwnerName, category.CategoryName);
}
}
}

OOP in Corona, accessing vars from outside class

looking for some help with accessing variables from outside a Corona OOP class. Here's the bare-bones code:
module(..., package.seeall)
local widget = require "widget"
picker = {}
picker.__index = picker
function picker.new()
local picker_object = {}
setmetatable(picker_object,picker)
picker_object.theHour = 12
picker_object.theMin = 0
picker_object.am = true
return picker_object
end
function picker:getHour()
return self.theHour
end
function picker:getMin()
return self.theMin
end
self is coming back as nil when I try and call getHour and getMin from outside the class. What syntax should I use instead to return my theHour and theMin variables?
Thanks!!
I tried out your code and there's nothing wrong with it. The problem is probably in the way you're accessing this module. Here's my main.lua that works with your code (I gonna guess your file is named picker.lua):
local picker = require "picker"
local picker_obj = picker.picker.new()
-- the first picker is the module (picker.lua)
-- the second is the picker class in the file
print("minute: " .. picker_obj:getMin())
print("hour: " .. picker_obj:getHour())
Also, The module(..., package.seeall) command has been deprecated, see this blog post for a better way to make your module. If you use this method to create your module and still call your file picker.lua, the first two lines in my main.lua would change to:
local picker = require "picker"
local picker_obj = picker.new()
Here's the simplest way I would modify your code to use the new way of creating modules. Only the beginning and end change, everything else stays the same:
-- got rid of module(), made picker local
local picker = {}
picker.__index = picker
... -- all the functions stay the same
return picker

Entity Model Not Being Updated on SaveChanges

I have a misunderstanding somewhere with the Entity Framework. This code is from my unit testing:
Public Sub UpdateRosterLinkTest()
Dim target As PlayerAdmin = New PlayerAdmin()
target.PlayerAdminManager = playerAdminTestManager
target.Team = playerAdminTestManager.GetAirForceMensBB()
playerAdminTestManager.resetRosterLink(target)
Assert.IsNull(target.Team.RosterLink)
Dim playerAdmin As PlayerAdmin = New PlayerAdmin()
playerAdmin.TeamId = 12434
playerAdmin.RosterLink = "Roster Link"
playerAdmin.UpdateRosterLink()
Dim team As DAL.Team = playerAdminTestManager.GetAirForceMensBB()
Assert.AreEqual("Roster Link", team.RosterLink)
End Sub
I'm creating a PlayerAdmin, which is a model class. target.Team is an Entity object. What I do is reset the RosterLink field in the Team just to make sure our test starts out at the same place. Then I call the UpdateRosterLink() function. That looks like:
Function UpdateRosterLink() As Integer
If (PlayerAdminManager Is Nothing) Then
PlayerAdminManager = New PlayerAdminManager()
End If
Team = PlayerAdminManager.GetTeamByTeamId(TeamId)
Team.RosterLink = RosterLink
Dim numberOfChanges As Integer = PlayerAdminManager.SaveChanges()
Return numberOfChanges
End Function
When I run this code, I can see the changes saved to the SQL Server this pulls from (RosterLink = Roster Link, like I set in the unit test).
However, my unit test is failing, because team.RosterLink is still Nothing. The function GetAirForceMensBB() returns the Team with TeamId = 12434:
Function GetAirForceMensBB() As DAL.Team
Return (From team In Container.Teams Where team.TeamId = 12434).SingleOrDefault
End Function
I'm sure I'm using the entity framework incorrectly and it probably has something to do with the fact that I am calling the PlayerAdminTestManager in different places, but I don't understand why. Although, I set the PlayerAdminManager to be the PlayerAdminTestManager. PlayerAdminTestManager extends PlayerAdminManager, fyi.
Why is team.RosterLink not showing the update from UpdateRosterLink?
Thanks
EDIT
Container is my ObjectContext. This is how I access the information stored in the database. Container.Teams represents my Teams table.
The problem was I was referencing different instantiations of the Container (each manager created its own). Thus, the entity items were not attached to anything.
Doh!