my task is simple i just wanna take data from gridview to REngine do random function get back rows and show them back in the gridview, I tried that
TextBox_Ville.Text = "I'm here";
DataTable dtb = (DataTable)Session["Grid"];
REngine engine = REngine.GetInstance();
string[,] stringData = new string[dtb.Rows.Count, dtb.Columns.Count];
for (int row = 0; row < dtb.Rows.Count; row++)
{
for (int col = 0; col < dtb.Columns.Count; col++)
{
stringData[row, col] = dtb.Rows[row].ItemArray[col].ToString();
}
}
CharacterMatrix matrix = engine.CreateCharacterMatrix(stringData);
engine.SetSymbol("myRDataFrame", matrix);
engine.Evaluate("myRDataFrame <- as.data.frame(myRDataFrame, stringsAsFactors = FALSE)");
// engine.Evaluate("str(myRDataFrame)");
DataFrame dataset = engine.Evaluate("myRDataFrame[sample(nrow(myRDataFrame), 1), ]").AsDataFrame();
DataTable dtt = new DataTable();
for (int i = 0; i < dataset.ColumnCount; ++i)
{
dtt.Columns.Add(new DataColumn(dataset.ColumnNames[i]));
}
for (int i = 0; i < dataset.RowCount; ++i)
{
var row = dtt.NewRow();
for (int k = 0; k < dataset.ColumnCount; ++k)
{
row[dataset.ColumnNames[k]] = dataset[i, k];
}
dtt.Rows.Add(row);
}
GridView1.DataSource = dtt;
GridView1.DataBind();
But it give me Stackoverflow error, can anyone help please. thanks :)
I see you omitted type when building your DataTable. Perhaps that is the problem?
dtt.Columns.Add(new DataColumn(dataset.ColumnNames[i], typeof(string)));
The other thing I noticed is that you use 'row' as an iterator in a for loop, then you use it again to build a DataRow. I can't tell if it's a problem or not.
Related
I'm tring to access the values of a dictionary property in a grid,such as Fluvial facies or lithologies etc.I have read the coursebook and help docs, but didn't find anything relevant.The coursebook only has examples of creating properties, but not accessing properties.Below is the code I tried:
Grid grid = arguments.Input_Grid;
if (grid == null)
{
PetrelLogger.ErrorStatus("HelloGrid: Arguments cannot be empty.");
return;
}
Index3 currentCell = new Index3();
int maxI = grid.NumCellsIJK.I;
int maxJ = grid.NumCellsIJK.J;
int maxK = grid.NumCellsIJK.K;
for (int i = 0; i < maxI; i++)
{
for (int j = 0; j < maxJ; j++)
{
for (int k = 0; k < maxK; k++)
{
currentCell.I = i; currentCell.J = j; currentCell.K = k;
if (grid.IsCellDefined(currentCell) && grid.HasCellVolume(currentCell))
{
//DictionaryProperty p = ???
//int val = p[currentCell] ???
}
}
}
}
You need to use the "FastDictionaryPropertyIndexer" or "FastPropertyIndexer" for regular properties.
foreach (var dictProp in grid.DictionaryProperties)
{
int numCellsI = dictProp.NumCellsIJK[0];
int numCellsJ = dictProp.NumCellsIJK[1];
int numCellsK = dictProp.NumCellsIJK[2];
float[] values = new float[dictProp.NumCells];
var dpsa = dictProp.SpecializedAccess;
using (var fdpi = dpsa.OpenFastDictionaryPropertyIndexer())
{
int index = 0;
for (int k = 0; k < numCellsK; k++)
{
for (int j = 0; j < numCellsJ; j++)
{
for (int i = 0; i < numCellsI; i++)
{
values[index] = fdpi[i, j, k];
index++;
}
}
}
}
}
You also need to be careful about the indexing since it varies by project. For instance, you may need to reverse the order of traversal in the J direction or you could end up with some strange results.
I am new to scripting and copied this one below and it works great but not all tables are the same in the document and I just want to affect the selected tables/text frames.
Is there an easy way to make this code work the way I am looking to do.
var myDoc = app.activeDocument;
var myWidths = [.5,.35,.44,.44];
for(var T=0; T < myDoc.textFrames.length; T++){
for(var i=0; i < myDoc.textFrames[T].tables.length; i++){
for(var j=0; j < myWidths.length; j++){
myDoc.textFrames[T].tables[i].columns[j].width = myWidths[j];
}
}
}
Thanks for any help, just starting to dive into InDesign Scripting and understand it.
Yes, it can be done quite easy:
var myWidths = [.5,.35,.44,.44];
var sel = app.selection;
if (sel.length != 1) exit();
var frame = sel[0];
if (frame.constructor.name != 'TextFrame') exit();
for (var i = 0; i < frame.tables.length; i++) {
for (var j = 0; j < myWidths.length; j++) {
frame.tables[i].columns[j].width = myWidths[j];
}
}
It will work for one selected text frame.
If you need to process several selected frames here is another variant of the code:
var myWidths = [.5,.35,.44,.44];
var frames = app.selection
var f = frames.length
while(f--) {
if (frames[f].constructor.name != 'TextFrame') continue;
var tables = frames[f].tables;
var t = tables.length;
while(t--) {
var table = tables[t];
var c = table.columns.length;
while(c--) {
table.columns[c].width = myWidths[c];
}
}
}
i have a working program where i can add an array to a Zedgraph and show this in a form.
Now i only want to change the display of the x-axis from points (0..400) to frequency (9e3..6e9 Hz).
Here are my currently working functions:
public void AddGraph(double[] Values, string LegendName)
{
int i = 0;
PointPairList list = new PointPairList();
for (i = 0; i < Values.Length; i++)
{
list.Add(i, Values[i]);
}
if (i > MaxXAxis)
MaxXAxis = i;
SList.Add(list);
SListColor.Add(Color.Black);
}
SListName.Add(LegendName);
}
public void ShowDiagram(string Title, string XAxisName, string YAxisName,
int Timeout_ms)
{
ZedGraph.ZedGraphControl zgc = new ZedGraphControl();
GraphPane myPane = zgc.GraphPane;
LineItem myCurve = null;
// Set the titles and axis labels
myPane.Title.Text = Title;
myPane.XAxis.Title.Text = XAxisName;
myPane.YAxis.Title.Text = YAxisName;
for (int i = 0; i < SList.Count(); i++)
{
myCurve = myPane.AddCurve(SListName[i], SList[i], SListColor[i],
SymbolType.None);
myCurve.Line.Width = 2;
}
// Add gridlines to the plot, and make them gray
myPane.XAxis.MinorGrid.IsVisible = true;
myPane.YAxis.MinorGrid.IsVisible = true;
myPane.XAxis.MinorGrid.Color = Color.LightGray;
myPane.YAxis.MinorGrid.Color = Color.LightGray;
myPane.XAxis.MinorGrid.DashOff = 0;
myPane.YAxis.MinorGrid.DashOff = 0;
myPane.XAxis.MajorGrid.IsVisible = true;
myPane.YAxis.MajorGrid.IsVisible = true;
myPane.XAxis.MajorGrid.Color = Color.Gray;
myPane.YAxis.MajorGrid.Color = Color.Gray;
myPane.XAxis.MajorGrid.DashOff = 0;
myPane.YAxis.MajorGrid.DashOff = 0;
// Move Legend to bottom
myPane.Legend.Position = LegendPos.Bottom;
zgc.AxisChange();
myPane.XAxis.Scale.Max = MaxXAxis;
zgc.Location = new Point(0, 0);
zgc.Size = new Size(panel_diagramm.ClientRectangle.Width, panel_diagramm.ClientRectangle.Height);
panel_diagramm.Controls.Add(zgc);
}
How can i change the above two functions that they display the frequency in the x-axis?
I already tried to change the AddGraph-function to pass the needed parameters and to calculate the list to have the correct values. But what then...?
public void AddGraph_Frequency(int **Points**, double **StartFrequency**,
double **StopFrequency**, double[] Values, string GraphColor, string LegendName)
{
...
double frequency = StartFrequency; //der erste Punkt
double Intervall = (StopFrequency - StartFrequency) / Points;
for (i = 0; i < Points; i++)
{
list.Add(frequency, Values[i]);
frequency = frequency + Intervall;
}
....
}
Thanks for any help
best regards
Solved.
Missing was:
myPane.XAxis.Scale.Max = Stopfrequency;
myPane.XAxis.Scale.Min = Startfrequency;
actually iam using one listbox which have multiple values when user select a values the item in listbox are inserted database like "Abc,xyz,gkl" type now i want to retrieve this value from database in front of form and as Selected how can i do that here is the my code
ds = new DataSet();
if (ds.Tables[0].Rows.Count > 0)
{
string[] arr_Electro_Therapy = ds.Tables[0].Rows[0]["Electro_Therapy"].ToString().Trim().Split(',');
for (int i = 0; i < arr_Electro_Therapy.Length; i++)
{
for (int k = 0; k < listBox1.Items.Count; k++)
{
if (listBox1.Items[k].Value.ToString().Trim() == arr_Electro_Therapy[i].ToString().Trim())
{
listBox1.Items[k].Selected = true;
hdSelected.Value = hdSelected.Value + ", " + listBox1.Items[k].;
}
}
}
i am using R.Net. in that i have done some database connection using R.Net in that i am getting the result in DataFrame format i need to convert it into DataSet
here is my code:
REngine.SetDllDirectory("#C:\Program Files\R\R-2.12.0\bin\i386")
engine = REngine.CreateInstance("RDotNet")
engine.EagerEvaluate("library(RODBC);")
engine.EagerEvaluate("con <- odbcConnect(dsn='rdsn', uid = 'sa', pwd = 'surya');")
cmdStr = SELECT DISTINCT Investment.InvestmentTypeCode,InvestmentTypeDescription, SortID FROM Investment,InvestmentTypeDef WHERE(Investment.InvestmentTypeCode = InvestmentTypeDef.InvestmentTypeCode) ORDER BY SortID
engine.EagerEvaluate("frm <- sqlQuery(con, '" + cmdStr + "');")
engine.GetSymbol("frm").AsDataFrame()
if any one knows plz help me...
There is not built-in functionality in R.Net or in the .NET Framework which can do that. But you can create and fill DataSets programmatically. So you will have to write your own conversion code.
See:
Creating A DataSet Programmatically
I recently had to convert a RDataFrame to a standard DataTable in C# - I'm assuming all the columns contain doubles:
public static DataTable RDataFrameToDataSet(DataFrame resultsMatrix) {
var dt = new DataTable();
var columns = new DataColumn[resultsMatrix.ColumnCount];
for (int i = 0; i < resultsMatrix.ColumnCount; i++) {
columns[i] = new DataColumn(resultsMatrix.ColumnNames[i], typeof(double));
}
dt.Columns.AddRange(columns);
for (int y = 0; y < resultsMatrix.RowCount; y++) {
var dr = dt.NewRow();
for (int x = 0; x < resultsMatrix.ColumnCount; x++) {
try {
dr[x] = resultsMatrix[y, x];
}
catch (Exception ex) {
Console.WriteLine(ex.Message);
}
}
dt.Rows.Add(dr);
}
return dt;
}