I'm using Cbuilder XE and I want to use Rave Report with Mydac component but it seems to me that Rave recognize only the standard TQuery component and ignore the Mydac versions.
I would ask you if there is a way to feed a Rave report using TMyQuery component and possiby, a simple example which print a plain list of the result of such query.
I only know how to do this in Delphi, so you will have to translate it to CBuilder equivalents. I am pretty sure that Delphi and CBuilder are identical with respect to RAVE components. I don't know how to do this programmatically, but it is relatively easy using the RAVE report designer.
I use RAVE TRvDataSetConnection components to link TMyQuery components to reports.
You typically drop TRvDataSetConnection components on your datamodule, along with your queries - one TRvDataSetConnection per TMyQuery. You have to add all the SQL fields to your TMyQuery components to make the field names show up in the report designer. You can do this automatically by opening the Field Editor for a TMyQuery and hitting ^F. If you have a valid connection to your MySQL server then the fields will fill in and be assigned the proper data types.
Next, inside the RAVE report designer you create a New Data Object and select the Direct Data View item. Connect the DataView to the RvDataSetConnections in your datamodule. Now you can access all the fields to the TMyQuery. You link the DataView in the RAVE Designer to the report band you want to display the query contents in.
Plan B is to buy and install FastReports. RAVE is pretty bad :-)
MY own way to use Rave as generic print utility
void __fastcall TFormMain::Action_ReportExecute(TObject * Sender)
{
__try
{
Screen->Cursor = crHourGlass;
int maxrow = 0;
RvSystem1->Execute();
}
__finally
{
Screen->Cursor = crDefault;
}
}
RvSystem1Print : is the event onPrint of a RvSystem component
I can't be able to build it at run-time so I have to add a component for each form where I need the print utility
void __fastcall TFormMain::RvSystem1Print(TObject * Sender)
{
int maxrow = 0;
String Fun = "[FormMain::RvSystem1Prin] ";
try
{
RvSystem1->SystemPreview->FormWidth = ( Screen->Width > 900 ) ? 900 : Screen->Width ;
RvSystem1->SystemPreview->FormHeight = Screen->Height * 0.9;
TBaseReport * report = (TBaseReport*) Sender;
UtilClientPmv::DBGridToRaveReport(DBGrid1, report, maxrow);
}
catch (Exception & ex)
{
Mylog(Fun + Sysutils::Format("ERROR=[%s] ", ARRAYOFCONST((ex.Message))));
}
}
DBGridToRaveReport: scan and print all record in a table linked to a dbgrid ( included images )
int __fastcall UtilClientPmv::DBGridToRaveReport(TDBGrid * grid, TBaseReport * report, int maxrow)
{
String Fun = "[UtilClientPmv::DBGridToRaveReport] ";
TMWTable * mwTable = NULL;
int iret = IRET_OK;
try
{
mwTable = (TMWTable*) grid->DataSource->DataSet;
iret = MWTableToRaveReport(mwTable, report, maxrow);
}
catch (Exception & ex)
{
Util::mylog(Fun + Sysutils::Format("ERROR=[%s] ", ARRAYOFCONST((ex.Message))));
}
return iret;
}
MWTableToRaveReport: scan and print all record in a table ( included images )
int __fastcall UtilClientPmv::MWTableToRaveReport(TMWTable * mwTable, TBaseReport * report, int maxrow)
{
String fldName, fldValue, smsg, Fun = "[UtilClientPmv::MWTableToRaveReport] ";
int tot_row, tot_fld, tot_rec, iret = IRET_OK;
double x, y, y2, rpos, pgWidth;
TField * fld = NULL;
TBookmark bkMark; // TBookmark == TByteDynArray
Graphics::TBitmap * bitmap = NULL;
try
{
if (maxrow == 0)
{
maxrow = 1000;
}
__try
{
if (mwTable->Active == false)
{
mwTable->Active = true;
}
tot_row = mwTable->Data->RecordCount;
if (tot_row < 0)
{
throw Exception("RecordCount in Null");
}
if (tot_row > maxrow)
{
tot_row = maxrow;
}
report->StatusFormat = "Page %d";
report->Units = unMM;
pgWidth = report->PageWidth;
mwTable->DisableControls();
bkMark = mwTable->GetBookmark();
tot_fld = mwTable->FieldCount;
tot_rec = mwTable->RecordCount;
int irow = 1, icol;
mwTable->First();
report->SetFont("Courier New", 10);
report->PrintCenter("Report PmvManager", pgWidth / 2);
report->NewLine();
report->SetTab(10, pjLeft, 160, 0, 0, 0);
while (!mwTable->Eof)
{
smsg = Sysutils::Format("Record %03d / %03d", ARRAYOFCONST((irow, tot_row)));
report->PrintTab(smsg);
report->NewLine();
for (int icol = 0; icol < tot_fld; icol++)
{
String NumberFormat, strValue;
fld = mwTable->Fields->Fields[icol];
fldName = fld->DisplayName;
// int lnum = report->LineNum;
int lleft = report->LinesLeft();
if (lleft == 0)
{
report->NewPage();
}
if (fld->DataType == ftBlob)
{
smsg = Sysutils::Format("%30s : ", ARRAYOFCONST((fldName)));
report->PrintTab(smsg);
x = report->XPos;
y = report->YPos;
if (!fld->IsNull)
{
bitmap = new Graphics::TBitmap();
__try
{
TGraphicField * gFld = (TGraphicField*)fld;
if (gFld)
{
TMemoryStream * memStream = new TMemoryStream();
__try
{
gFld->SaveToStream(memStream);
if (memStream->Size > 1)
{
memStream->Seek(0, soFromBeginning);
bitmap->LoadFromStream(memStream);
report->PrintBitmapRect(x, y - 3, x + 12, y + 9, bitmap);
}
report->NewLine();
report->NewLine();
}
__finally
{
delete memStream;
memStream = 0;
}
}
}
__finally
{
delete bitmap;
bitmap = 0;
}
}
}
else
{
fldValue = fld->AsString;
smsg = Sysutils::Format("%30s : %s ", ARRAYOFCONST((fldName, fldValue)));
report->PrintTab(smsg);
}
report->NewLine();
}
irow++;
mwTable->Next();
x = report->XPos;
y = report->YPos;
report->MoveTo(2, y);
report->LineTo(pgWidth - 4, y);
report->MoveTo(x, y);
report->NewLine();
report->NewPara();
}
}
__finally
{
mwTable->GotoBookmark(bkMark);
mwTable->EnableControls();
mwTable->FreeBookmark(bkMark);
}
}
catch (Exception & ex)
{
Util::mylog(Fun + Sysutils::Format("ERROR=[%s] ", ARRAYOFCONST((ex.Message))));
}
return iret;
} // __________ UtilClientPmv::MWTableToRaveReport
Related
I am getting errors when I try to send string parameters using EF Core in ASP.NET Core 5 and use EF MySQL 5.0.8. The error is Input string was not in a correct format.
I am using this EF Core Library:
https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html
If I send int parameters the solution below works fine.
MYSQL Procedure
CREATE DEFINER=`MYUSER`#`%` PROCEDURE `test_sp`(
IN param1 int,
IN param2 text
#I tried type text, varchar, char
)
BEGIN
SELECT 1 as id, param1 as parameter, 'this is Parameter 1 INT' as text
UNION
SELECT 2 as id, param2 as parameter, 'this is Parameter 2 VARCHAR' as text;
END
ASP.NET CORE 5 CLASS
public async Task<List<T>> ExecuteStoredProcedure(string nameProcedure, List<MySqlParameter> parameters = null)
{
try
{
using (var data = new ContextBase(_optionBuilder))
{
//Add Space to separate sp name of the parameters
nameProcedure += "(";
var count = parameters.Count;
int i = 0;
//Insert the parameters in the procedure name
for (i = 0; i < count; i++)
{
nameProcedure += parameters[i].ParameterName;
if(i + 1 < count)
{
nameProcedure += ", ";
}
else
{
nameProcedure += ")";
}
}
//Remove the last Comma from the query
var responseData = await data.Set<T>().FromSqlRaw<T>("CALL " + nameProcedure, parameters.ToArray()).AsNoTracking().ToListAsync();
return responseData;
}
}
catch (Exception ex)
{
ErrorLog error = new ErrorLog();
error.Error = ex.Message;
error.Description = "Error encountered DB Procedure Execute ***. Message:" + ex.Message + " when getting the Generic Procedure Execute";
error.Section = "RepositoryProcedureGenerics.cs";
error.Layer = "Infra";
error.Date = DateTime.Now;
await this.CreateError(error);
return null;
}
}
ASP.NET CORE CONTROLLER
public async Task<IActionResult> ExecProcedure([FromQuery(Name = "param1")] int param1, [FromQuery(Name = "param2")] string param2)
{
//Create the list of Parameters
List<MySqlParameter> listParameters = new List<MySqlParameter>();
//int par = 1;
//string par2 = "XXX";
listParameters.Add(new MySqlParameter("#param1", MySqlDbType.Int32));
//I TRIED MySqlDbType.Text, MySqlDbType.VarChar and MySqlDbType.VarString
listParameters.Add(new MySqlParameter("#param2", MySqlDbType.Text));
listParameters[0].Value = param1;
listParameters[1].Value = param2;
string sp_name = "test_sp";
//Execute the Procedures
List<Test> test = await _procedureExecutor.ExecuteStoredProcedure(sp_name, listParameters.ToList());
return Ok();
}
Does someone knows where is my mistake?
I am working on an implementation to generate alternate Paths using via node method.
While checking for local optimality I do the following
forwardEdge = bestWeightMapFrom.get(viaNode);
reverseEdge = bestWeightMapTo.get(viaNode);
double unpackedUntilDistance = 0;
while(forwardEdge.edge != -1) {
double parentDist = forwardEdge.parent != null ? forwardEdge.parent.distance : 0;
double dist = forwardEdge.distance - parentDist;
if(unpackedUntilDistance + dist >= T_THRESHOLD) {
EdgeSkipIterState edgeState = (EdgeSkipIterState) graph.getEdgeProps(forwardEdge.edge, forwardEdge.adjNode);
unpackStack.add(new EdgePair(edgeState, false));
sV = forwardEdge.adjNode;
forwardEdge = forwardEdge.parent;
break;
}
else {
unpackedUntilDistance += dist;
forwardEdge = forwardEdge.parent;
sV = forwardEdge.adjNode;
}
}
int oldSV = forwardEdge.adjNode;
EdgeEntry oldForwardEdge = forwardEdge;
I unpack the edge in the stack to further narrow down sV.
I get vT and oldVt in a similar fashion by traversing reverseEdge.
if I determine that the path from sV and vT is <= length of unpacked edges I accept this via node and construct the alternatePath as follows.
PathBidirRef p = (PathBidirRef) algo.calcPath(oldSV, oldVT);
Path4CHAlt p1 = new Path4CHAlt(graph, flagEncoder);
p1.setSwitchToFrom(false);
p1.setEdgeEntry(oldForwardEdge);
p1.segmentEdgeEntry = p.edgeEntry;
double weight = oldForwardEdge.weight + oldReverseEdge.weight + p.edgeEntry.weight + p.edgeTo.weight;
p1.setWeight(weight);
p1.edgeTo = oldReverseEdge;
p1.segmentEdgeTo = p.edgeTo;
Path p2 = p1.extract();
Path4CHAlt is
public class Path4CHAlt extends Path4CH {
private boolean switchWrapper = false;
public EdgeEntry segmentEdgeTo;
public EdgeEntry segmentEdgeEntry;
public Path4CHAlt( Graph g, FlagEncoder encoder )
{
super(g, encoder);
}
public Path4CHAlt setSwitchToFrom( boolean b )
{
switchWrapper = b;
return this;
}
#Override
public Path extract()
{
System.out.println("Path4CHAlt extract");
if (edgeEntry == null || edgeTo == null || segmentEdgeEntry == null || segmentEdgeTo == null)
return this;
if (switchWrapper)
{
EdgeEntry ee = edgeEntry;
edgeEntry = edgeTo;
edgeTo = ee;
ee = segmentEdgeEntry;
segmentEdgeEntry = segmentEdgeTo;
segmentEdgeTo = ee;
}
EdgeEntry currEdge = segmentEdgeEntry;
while (EdgeIterator.Edge.isValid(currEdge.edge))
{
processEdge(currEdge.edge, currEdge.adjNode);
currEdge = currEdge.parent;
}
currEdge.parent = edgeEntry;
currEdge = edgeEntry;
while (EdgeIterator.Edge.isValid(currEdge.edge))
{
processEdge(currEdge.edge, currEdge.adjNode);
currEdge = currEdge.parent;
}
setFromNode(currEdge.adjNode);
reverseOrder();
currEdge = segmentEdgeTo;
int tmpEdge = currEdge.edge;
while (EdgeIterator.Edge.isValid(tmpEdge))
{
currEdge = currEdge.parent;
processEdge(tmpEdge, currEdge.adjNode);
tmpEdge = currEdge.edge;
}
currEdge.parent = edgeTo;
currEdge = edgeTo;
tmpEdge = currEdge.edge;
while (EdgeIterator.Edge.isValid(tmpEdge))
{
currEdge = currEdge.parent;
processEdge(tmpEdge, currEdge.adjNode);
tmpEdge = currEdge.edge;
}
setEndNode(currEdge.adjNode);
return setFound(true);
}
}
This is not working all the time. I get exceptions in Path4CH
java.lang.NullPointerException
at com.graphhopper.routing.ch.Path4CH.expandEdge(Path4CH.java:62)
at com.graphhopper.routing.ch.Path4CH.processEdge(Path4CH.java:56)
at com.graphhopper.routing.PathBidirRef.extract(PathBidirRef.java:95)
at com.graphhopper.routing.DijkstraBidirectionRef.extractPath(DijkstraBidirectionRef.java:99)
at com.graphhopper.routing.AbstractBidirAlgo.runAlgo(AbstractBidirAlgo.java:74)
at com.graphhopper.routing.AbstractBidirAlgo.calcPath(AbstractBidirAlgo.java:60)
In Path
java.lang.IllegalStateException: Edge 1506012 was empty when requested with node 1289685, array index:0, edges:318
at com.graphhopper.routing.Path.forEveryEdge(Path.java:253)
at com.graphhopper.routing.Path.calcInstructions(Path.java:349)
I dont know what I am doing wrong. I could really use some help with this.
Thanks.
I solved this issue.
Inside DijkstraBidirectionRef.calcPath I was trying to calculate shortest path from an arbitrary node to source node and vertex node.
The error used to occur because the original call to calcPath was operating on QueryGraph and inside I was creating a new Object of DijkstraBidirectionRef using LevelGraphStorage.
This was a problem because QueryGraph may create virtual nodes and edges for source and target nodes. Call to calcPath(node, virtualNode) operating on LevelGraphStorage would throw an exception.
The fix was to call algo.setGraph(queryGraph) after creating DijkstraBidirectionRef.
i ever ask a question at this link
how to take data from csv file and save into grails with mysql?
i am confuse..how to read next row..so the file csv like this
row 1 : bobby,1,20,628129456774,2 //this 2 means its have 2 child, it will import to different table.
row 2 : singer,50%
row 3 : dance,50%
so first line it will insert to table PERSON and the last digit "2" means table PERSON have 2 Child..
the row 2 and 3 will insert to table Hobby where the domain like thiss.
package com.teravin.collection.maintenance
import java.util.Date;
class Hobby{
String hobby
String likess
Person person
static constraints = {
}
def beforeInsert = {
// createdBy = springSecurityService.principal.username
createDate = new Date()
}
def beforeUpdate = {
// updatedBy = springSecurityService.principal.username
lastUpdated = new Date()
}
}
Try this sample: It loops to read next line from csv
public List Sample()
{
List<wsSample> result = new List<wsSample>();
string path = #"C:\Users\c_evtamondong\Desktop\sampleCsv.csv";
StreamReader csvSample = new StreamReader(path);
DataTable oDataTable = new DataTable();
int rowCount = 0;
string[] columnNames = null;
string[] CsvValues = null;
while (!csvSample.EndOfStream)
{
string RowData = csvSample.ReadLine().Trim();
if (RowData.Length > 0)
{
CsvValues = RowData.Split(new string[] {","}, StringSplitOptions.None);
if (rowCount == 0) //check if it's in the first line
{
rowCount = 1;
columnNames = CsvValues;
foreach (string csvHeader in columnNames)
{
// do nothing
// to eliminate the header in the .csv file
}
}
else
{
for (int i = 0; i < CsvValues.Length-1; i++ )
{
result.Add(new wsSample()
{
id = CsvValues[i],
name = CsvValues[i + 1],
lastname = CsvValues[i + 2]
});
i = i + 1;
}
}
}
}
csvSample.Close();
csvSample.Dispose();
return result;
}
I am writing a bridge to synchronise our client application with EWS via the managed API.
I'm running into a lot of problems caused by the fact that I don't know who has last updated the appointment I'm working with(Outlook client/owa/My bridge).
There are certain appointments (tagged with a category[0] = 'Booking') that I don't want the user to modify, but I cant tell whether it was updated by the user or my bridge.
is there a way I can create the appointment as Read-only, or get the old info for the appointment and revert it back ?
I've tried to kind of show what I mean below :
public void TimerCallback(object source, ElapsedEventArgs e)
{
FPollTimer.Enabled = false;
try
{
GetEventsResults notificationEvents = FCalendarSubscription.GetEvents();
EWSMethods.monitorFRM.log("Notification count = " + FEWSUser + ":" + notificationEvents.AllEvents.Count.ToString());
if (notificationEvents.AllEvents.Count > 0)
{
foreach (ItemEvent itemEvent in notificationEvents.ItemEvents)
{
// -- check to see if this is a valid appointment -- //
// -- Echange creates two appts and deletes one of -- //
// -- them for any appointment creation -- //
try
{
//Folder tempFolder = Folder.Bind(FEWSService, itemEvent.ParentFolderId.ToString());
EWSMethods.monitorFRM.log("Notification-" + FEWSUser + " : " + itemEvent.EventType.ToString());
// -- Is this item in the stack? -- //
if (NeedPingPongcheck(itemEvent))
{
CheckPingPong(itemEvent);
}
else
{
Appointment o_appointment = Appointment.Bind(FEWSService, itemEvent.ItemId.ToString());
if (o_appointment != null) WriteEventToDB(itemEvent);
}
}
catch (Exception exc2)
{
EWSMethods.monitorFRM.log("TimerCallBack inner " + exc2.Message);
}
}
}
}
catch (Exception exc)
{
EWSMethods.monitorFRM.log("timercallback outer " + exc.Message);
//MessageBox.Show(e.Message);
}
FPollTimer.Enabled = true;
}
public void WriteEventToDB(ItemEvent item)
{
try
{
EWSMethods.monitorFRM.log("Attempting write to DB ");
string s_allday;
string s_appointmentid;
//MessageBox.Show(item.ItemId.ToString());
// -- use the old item id for deleted (moved) appointments -- //
if (item.EventType == EventType.Moved)
{
s_appointmentid = item.OldItemId.ToString();
}
else
{
s_appointmentid = item.ItemId.ToString();
}
// Get all properties of email message
PropertySet pset = new PropertySet(BasePropertySet.FirstClassProperties);
// Get the body in text
pset.RequestedBodyType = Microsoft.Exchange.WebServices.Data.BodyType.Text;
// -- set up allDay flag -- //
Appointment o_appointment = Appointment.Bind(FEWSService, item.ItemId.ToString(),pset);
if ((o_appointment.IsAllDayEvent) & (o_appointment != null))
{
s_allday = "Y";
}
else
{
s_allday = "N";
}
// --
if (o_appointment.Categories[0] != "Booking")
{
AddInterimEntry(o_appointment,
item,
s_allday,
s_appointmentid,
item.EventType.ToString());
}
else
{
if ((item.EventType == EventType.Modified) || (item.EventType == EventType.Moved)) {
EWSMethods.monitorFRM.log("Booking item skipped." + item.OldItemId.ToString());
}
}
}
catch (Exception e)
{
EWSMethods.monitorFRM.log(e.Message);
}
}
Thanks in advance.
I am using DDE client to attach and listen stock market prices. That client has a callback method I implemented what to do when it receives price changes. The problem is that I get StackOverflowException (periodically and not at the same time interval). I found something about Thread.BeginCriticalRegion(), but I'm not sure if it would help. I have a few more hours until market opening when I can test it.
I would be more than greatful if someone could give me an idea how to override this exception.
Thanks in advance,
Aleksandar
IList<SymbolObject> _symbols; //initialized when the app runs for the first time
void _ddeClient_Advise(object sender, DdeAdviseEventArgs args)
{
if (!IsReady)
return;
if (string.IsNullOrEmpty(args.Text))
{
_logMessages.LogMessagesAdd("advise dde symbol", string.Format("args.Text is empty or NULL for {0}", args.Item), true);
return;
}
try
{
string[] argsArray = args.Text.Replace("\0", "").Replace('\0'.ToString(), "").Split(' '); // sometimes happens here
var list = _symbols.Where(s => s.DDESymbol == args.Item).ToList();
if (list.Count == 0)
return;
decimal? val = null;
try
{
var stringParts = StringUtils.CleanProphitXUrl(argsArray[0]).Split('.');
argsArray = null;
if (stringParts.Length >= 2)
val = decimal.Parse(stringParts[0] + "." + (stringParts[1].Length > 2 ? stringParts[1].Substring(0, 2) : stringParts[1]));
else
val = decimal.Parse(stringParts[0]);
stringParts = null;
}
catch (Exception ex)
{
_logMessages.LogMessagesAdd("call Price Alerts application service", ex.Message, true);
return;
}
foreach (var l in list)
{
if (_lastPrices[l.DDESymbol] == null)
continue;
if (_lastPrices[l.DDESymbol].ToString() != val.ToString())
{
try
{
_quotePublishingService.PublishQuote(l.DDESymbolId, l.Symbol, args.Item, val, WebSyncPublisherUrl,
PublishingChannel); // a call to wcf service
}
catch (Exception ex)
{
_logMessages.LogMessagesAdd("call the service", ex.Message, true); // save to sql db
return;
}
_lastPrices[l.DDESymbol] = val.ToString();
}
}
list = null;
val = null;
}
catch
{
}
}
public static string CleanProphitXUrl(string value) // StringUtils.CleanProphitXUrl snippet
{
StringBuilder sb = new StringBuilder();
sb.Append(value.Substring(0, value.LastIndexOf(".") + 1));
try
{
value = value.Replace('\r'.ToString(), "").Replace('\t'.ToString(), "").Replace('\n'.ToString(), "");
for (int i = sb.Length; i < value.Length; i++)
{
if (char.IsNumber(value[i]))
sb.Append(value[i]);
}
}
catch
{
}
return sb.ToString();
}
A StackOverflowException is caused by making to many method calls usually resulting from unintended recursion. Based on a cursory check of the code you posted I do not believe it is the culprit. The problem likely lies somewhere else.