|
Read each line, and use the String.Split Method (System)[^] to break it:
string[] separatedValues = inputLineOfText.Split(','); It returns each value between the commas as a separate string.
You can then load the values into your TextBoxes in the usual way.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Create 3 string arrays; split on ",".
Locate the index of the value entered (eg. 2) in array 1 (eg. 1).
Then use that index to retrieve the corresponding values from arrays 2 and 3 (i.e. 3 and 4).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I have an application that draws a 3D perspective view of a surface plot with axes. The user can rotate the view about 3 axes. The drawing is done using OpenTK. The axes are annotated with text using QuickFont. Unfortunately I have found issues:
1) QuickFont disables the ability to transform the model view multiple times. It would appear that the projection and model view are fixed once a value is assigned to the QuickFont.QFontDrawingPimitive.ProjectionMatrix field. For example, set a matrix view, draw text, draw some lines, transform the matrix view by 90 degrees about an axis, draw the same lines as before. The second set of lines are drawn as per the first i.e. not rotated. Remove the code that draws text, and then the lines drawn as expected i.e. the second set is 90 degrees to the first set.
2) When I draw text, the lines and the surface shading change colour to dark blue. If I comment out the text code, the lines are white and the surface is coloured.
Yes I have searched using Google and no I was unable to solve this. All of the examples I have seen are rather simple, with text and shapes drawn in 2D for example.
Update: It looks as if QuickFont either has bugs, or is not compatible with the OpenTK build I am using. In any case, I have written my own code to display strings, which allows the strings to be displayed in 3D, with perspective, rotations and translations as required. I may post sample code if I get the time as it might help others.
modified 9-May-18 3:34am.
|
|
|
|
|
I need help with binding JSON data generated from REST API call to rows in a table in MVC.Below is the code for Controller
public ActionResult Members()
{
var jsonString = "{\"roleMappings\":[{\"user\":{\"id\":\"4b147d87-64eb-4049-bbd3-ade96d18af89\",\"name\":\"PFRENC17\",\"actualName\":\"French, Phil (P.)\",\"displayName\":\"French, Phil (P.) (PFRENC17)\",\"email\":\"pfrenc17@abc.com\",\"deleted\":false,\"deletedDate\":0,\"authenticationRealm\":\"f4191d4b-4331-4637-af6f-c89781687bf6\",\"isLockedOut\":false,\"lastLoginDate\":1502803623890,\"isDeletable\":true},\"role\":{\"id\":\"3de854ce-34ed-4b7f-9b99-9fdf04c0345c\",\"name\":\"Developer\",\"description\":\"Application Developer\",\"isDeletable\":true}},{\"user\":{\"id\":\"3afd930e-9608-4257-a962-0a82b792a6e9\",\"name\":\"RSIEGLE3\",\"actualName\":\"Siegler, Ryan (R.)\",\"displayName\":\"Siegler, Ryan (R.) (RSIEGLE3)\",\"email\":\"rsiegle3@abc.com\",\"deleted\":false,\"deletedDate\":0,\"authenticationRealm\":\"f4191d4b-4331-4637-af6f-c89781687bf6\",\"isLockedOut\":false,\"lastLoginDate\":1500300166062,\"isDeletable\":true},\"role\":{\"id\":\"3de854ce-34ed-4b7f-9b99-9fdf04c0345c\",\"name\":\"Developer\",\"description\":\"Application Developer\",\"isDeletable\":true}},{\"user\":{\"id\":\"33dd9fea-4685-4505-91ba-5c0508301b56\",\"name\":\"Michael3\",\"actualName\":\"Michael (Y.)\",\"displayName\":\"Michael (Y.) (Michael3)\",\"email\":\"Michael3@abc.com\",\"deleted\":false,\"deletedDate\":0,\"authenticationRealm\":\"f4191d4b-4331-4637-af6f-c89781687bf6\",\"isLockedOut\":false,\"lastLoginDate\":1522249840141,\"isDeletable\":true},\"role\":{\"id\":\"f722b338-01c1-43cb-bc53-853cfb0d2249\",\"name\":\"UC Auto Discovery\",\"description\":\"\",\"isDeletable\":false}},{\"user\":{\"id\":\"33dd9fea-4685-4505-91ba-5c0508301b56\",\"name\":\"Michael3\",\"actualName\":\"Michael (Y.)\",\"displayName\":\"Michael (Y.) (Michael3)\",\"email\":\"Michael3@abc.com\",\"deleted\":false,\"deletedDate\":0,\"authenticationRealm\":\"f4191d4b-4331-4637-af6f-c89781687bf6\",\"isLockedOut\":false,\"lastLoginDate\":1522249840141,\"isDeletable\":true},\"role\":{\"id\":\"8421e59e-ce5f-477b-aa6f-0313aa1223e6\",\"name\":\"Application_Lead\",\"description\":\"Development Team Lead\",\"isDeletable\":true}},{\"user\":{\"id\":\"5599437f-68f9-4c20-bd0a-5c26d55628e1\",\"name\":\"UBLDUCD1\",\"actualName\":\"Blducd1, U (U.)\",\"displayName\":\"Blducd1, U (U.) (UBLDUCD1)\",\"deleted\":false,\"deletedDate\":0,\"authenticationRealm\":\"f4191d4b-4331-4637-af6f-c89781687bf6\",\"isLockedOut\":false,\"lastLoginDate\":1515694447960,\"isDeletable\":true},\"role\":{\"id\":\"8421e59e-ce5f-477b-aa6f-0313aa1223e6\",\"name\":\"Application_Lead\",\"description\":\"Development Team Lead\",\"isDeletable\":true}},{\"group\":{\"id\":\"7862c275-8eb2-42cf-895c-214c2826a0b8\",\"name\":\"config_viewer\",\"enabled\":true},\"role\":{\"id\":\"ba4cdbf1-6b97-436f-9b40-a7e21d8394f2\",\"name\":\"ReadOnly\",\"description\":\"Read-only access\",\"isDeletable\":true}}],\"id\":\"877eb9b9-6dd9-432d-b55a-01bd406d039a\",\"name\":\"AftImport Team\",\"isDeletable\":true}";
List<string> MemberNames = new List<string>();
var t = JObject.Parse(jsonString);
var pt = t["roleMappings"];
var COUNT = 0;
foreach (var v in pt)
{
if (COUNT > 4)
{
break;
}
var p = v["user"]["name"];
MemberNames.Add(p.ToString());
COUNT++;
}
return View(MemberNames);
}
Below is the code for View
<table border="1" align="center" style="font-family:Arial; width:900px;">
<tr height="50">
<th>Member</th>
<th>Roles</th>
<th>Actions</th>
</tr>
@foreach (var d in Model)
{
<tr height="30">
<th>@d</th>
<th></th>
<th><button class="editbtn">Delete User</button> <button class="editbtn">Change Role</button></th>
</tr>
}
</table>
As I have binded json data to the "Member" field in View to the Controller, I need help with binding "Roles" field in View to
"name": "Application_Lead", . I need Roles to be displayed on web page. Typical roles in the above JSON string are "Developer", "Application Lead"
|
|
|
|
|
But you are not returning those fields at all, the only thing you are returning is the name of the user in each of the element. See here,
List<string> MemberNames = new List<string>();
var p = v["user"]["name"];
MemberNames.Add(p.ToString());
return View(MemberNames);
You need to change the object that you are returning and then capture the values returned. Rendering the object will be as simple as,
foreach (var item in Model) {
<tr>
<td>@item.Name</td>
<td>@item.Role</td>
</tr>
}
Take my advice, return all the "required" fields, as an anonymous separate object (if you like). That way, you will contain every bit of information that you require on the client-side, and there you can render it easily.
Secondly, eyeballing the fields etc won't be a good approach. Consider mapping the fields from the database, and only capture those that are needed.
Consider reading my article about somewhat similar topic as well, From zero to hero in JSON with C#.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Thank you for responding. Could you share about the code in the Controller. How to create an object and capture the values returned. Should I be using "Dictionary" or "List"
|
|
|
|
|
I would like to add a dropdownlist to my gridview and then selecting an avaliable table from that list. The selected table would show and i could edit it.
I already have a form made with grid view and an option to update and show record in a table. It looks like this:
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
SqlDataAdapter sda;
SqlCommandBuilder scb;
DataTable dt;
public Form1()
{
InitializeComponent();
}
private void button1_click(object sender, EventArgs e)
{
scb = new SqlCommandBuilder(sda);
sda.Update(dt);
MessageBox.Show("Records updated");
}
private void button2_click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=GECKO-PM\\SQLEXPRESS;Initial Catalog=Gecko;Integrated Security=True");
sda = new SqlDataAdapter(@"SELECT ID_vzdrzevanje, Datum, Lokacija, Ime_vrtine, Delo FROM Vzdrzevanje",con);
dt = new DataTable();
sda.Fill(dt);
dataGridView1.DataSource = dt;
}
}
}
Thanks
|
|
|
|
|
I think you want to add the "drop down list" to the form; and NOT the grid.
The code you show has NOTHING to do with that.
So, show something that is relevant if you want help.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Yes im sorry, combobox is added on the form.
Now i've added this code to link combobox so it show all of my tables from SQL database:
String strConnection = "Data Source=GECKO-PM\\SQLEXPRESS;Initial Catalog=Gecko;Integrated Security=True";
SqlConnection con = new SqlConnection(strConnection);
try
{
con.Open();
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.Connection = con;
sqlCmd.CommandType = CommandType.Text;
sqlCmd.CommandText = "Select table_name from information_schema.tables";
SqlDataAdapter sqlDataAdap = new SqlDataAdapter(sqlCmd);
DataTable dtRecord = new DataTable();
sqlDataAdap.Fill(dtRecord);
comboBox1.DataSource = dtRecord;
comboBox1.DisplayMember = "TABLE_NAME";
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Now i would like to link a button with combobox so when i click on button it shows content of selected table in combobox. Or perhaps if the the table is automaticly shown when it is selected in combobox. Any ideas?
|
|
|
|
|
UPDATE:
I have managed to get the chosen table from combobox be shown on the grid view when clicked on a "show table" button. The code on the "show table" button looks like this:
string selected = this.comboBox1.GetItemText(this.comboBox1.SelectedItem);
SqlConnection con = new SqlConnection("Data Source=GECKO-PM\\SQLEXPRESS;Initial Catalog=Gecko;Integrated Security=True");
sda = new SqlDataAdapter(@"SELECT* FROM dbo."+selected,con);
dt = new DataTable();
sda.Fill(dt);
dataGridView1.DataSource = dt;
Be tuned for further improvments or question for help.
|
|
|
|
|
I have one more problem that im stuck on. I would like to add a button, that is in column in every row, to a table that is shown in datagridview. The problem is that this table is drawn from a database, so it si not manualy made, and therefore i dont know how to find that specific column and add a button to every row in that column.
Any help would be appreciated.
|
|
|
|
|
Hello,
As a first time poster, and not a developer (although competent with PowerShell!), I would be grateful for some assistance on the above issue.
I am using VS2013Express to create a windows form based application which will display and eventually print Visio documents, rather than relying on the browser based Visio Viewer. Needless to say this is a very specific requirement, so really don't need anyone telling me to use the MS Visio Viewer!
So far, I can open the Visio document, display it using the AxVisioViewer.dll control. I can even print... to a degree.
The issue is that I can only print currently using a PrintFromScreen method which basically captures the image of the form as displayed on screen and creates a Raster BitMap of it.
I copy the BitMap image to a hidden panel on the form (to remove toolbars etc), then print the contents of the panel. Simple (ish)!
What I want to be able to do is resize (Vector not Raster to retain scale) and centre the image as required to ensure the document prints properly.
This is my first delve into C# and so far it's fun... until you find you can't do something... then it becomes painful!
Any help would be very much appreciated!
Thank you.
Chubbsy.
|
|
|
|
|
chubbsy wrote: What I want to be able to do is resize (Vector not Raster to retain scale) and centre the image as required to ensure the document prints properly. The image you get from the control is a collection of pixels, not a vector-image.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hi Eddy,
Thanks for the response.
I agree, the control simply returns a collection of pixels, which is not possible to rescale (not that I've been able to at least).
Are you saying there is no way to properly re-scale the graphic being displayed using the AxVisioViewer ActiveX control?
Is there a different way to output from the control as a scaleable image for printing??
Cheers,
Simon.
|
|
|
|
|
Only by zooming. If the original is low-quality, the printed result will be too.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hello,
How can we save .pdf file to a remote server?
Below template is ok at local but I need to save the file at remote host.
I created folder and gave permission at remote host.
Directory.CreateDirectory("d:\\folder\\");
PdfWriter.GetInstance(pdfDosya, new FileStream("d:\\folder\\" + ".pdf", FileMode.Create));
Thanks.
modified 13-Feb-19 21:02pm.
|
|
|
|
|
It depends on how the remote folder is shared (which protocol is used).
Is it within a local network using SMB/CIFS (Windows share) or NFS (Unix)? Or is the remote server accessed using an internet protocol like [S]FTP?
|
|
|
|
|
It's SMB (Windows share)
modified 13-Feb-19 21:02pm.
|
|
|
|
|
Use
//ComputerName/ShareName/[SubDirectory/]FileName when the user account of the local machine has write access to the share on the remote system (e.g. when using domain accounts).
If you have to pass the credentials from your code it is getting more complicated. Search the web for something like "c# access network share with credentials".
|
|
|
|
|
[EDIT] There was a bug in VectorDot, now corrected. Vector2 doing better.
I am trying to compare various operation with normal .NET struct vs SIMD / System.Numerics.Vectors.Vector2 one.
I created this plain C# normal struct and SIMD extensions:
public struct Point2
{
public float X, Y;
<pre>
public Point2(float x, float y)
{
X = x;
Y = y;
}
public float Dot(Point2 p) => X * p.X + Y * p.Y;
public static Point2 operator +(Point2 p, Point2 p2) => new Point2(p.X + p2.X, p.Y + p2.Y);
public static float operator ^(Point2 p, Point2 p2) => p.Cross(p2);
public float Cross(Point2 p2)
{
return X * p2.Y - Y * p2.X;
}
}
public static class VectorExtensions
{
public static float Cross(this Vector2 v, Vector2 v2)
{
return v.X * v2.Y - v.Y * v2.X;
}
}</pre>
And made this text program
class Program
{
static void Main(string[] args)
{
int N = 10_000_000;
<pre>
DoVectorCross(1);
using (new MeasureBlock("Vectors Cross"))
DoVectorCross(N);
DoPointCross(1);
using (new MeasureBlock("Points Cross"))
DoPointCross(N);
DoVectorDot(1);
using (new MeasureBlock("Vectors Dots"))
DoVectorDot(N);
DoPointDot(1);
using (new MeasureBlock("Points Dots"))
DoPointCross(N);
DoVectorAdd(1);
using (new MeasureBlock("Vectors Add"))
DoVectorAdd(N);
DoPointAdd(1);
using (new MeasureBlock("Points Add"))
DoPointAdd(N);
Console.ReadLine();
}
static float DoVectorCross(int N)
{
var v1 = new Vector2(1, 2);
var v2 = new Vector2(2, 3);
float result = 0;
for (int i = 0; i < N; i++)
result += v1.Cross(v2);
return result;
}
static float DoVectorDot(int N)
{
var v1 = new Vector2(1, 2);
var v2 = new Vector2(2, 3);
float result = 0;
for (int i = 0; i < N; i++)
result += Vector2.Dot(v1, v2);
return result;
}
static Vector2 DoVectorAdd(int N)
{
var v1 = new Vector2(1, 2);
var v2 = new Vector2(2, 3);
for (int i = 0; i < N; i++)
v1 += v2;
return v1;
}
static float DoPointCross(int N)
{
var v1 = new Point2(1, 2);
var v2 = new Point2(2, 3);
float result = 0;
for (int i = 0; i < N; i++)
result += v1.Cross(v2);
return result;
}
static float DoPointDot(int N)
{
var v1 = new Point2(1, 2);
var v2 = new Point2(2, 3);
float result = 0;
for (int i = 0; i < N; i++)
result += v1.Dot(v2);
return result;
}
static Point2 DoPointAdd(int N)
{
var v1 = new Point2(1, 2);
var v2 = new Point2(2, 3);
for (int i = 0; i < N; i++)
v1 += v2;
return v1;
}
}</pre>
I get the following measurement for each compile target (x86, x64/ AnyCPU):
x64
Vectors Cross took 24ms.
Points Cross took 17ms.
Vectors Dots took 16ms.
Points Dots took 21ms.
Vectors Add took 35ms.
Points Add took 109ms.
x86
Vectors Cross took 41ms.
Points Cross took 38ms.
Vectors Dots took 49ms.
Points Dots took 40ms.
Vectors Add took 38ms.
Points Add took 47ms.
AnyCPU
Vectors Cross took 40ms.
Points Cross took 39ms.
Vectors Dots took 43ms.
Points Dots took 39ms.
Vectors Add took 49ms.
Points Add took 58ms.
Vector2 has now similar performance to Point2 , except when compiled for x64, Dot() is 25% faster and Add() is 3 times faster.
Custom Cross() operations is slower though.. How do I write efficient Cross operation?
modified 29-Apr-18 23:10pm.
|
|
|
|
|
I'm not a C# programmer and have only basic knowledge. So this might not be correct.
I guess that your Vector2 Cross function does not use any SIMD instructions or is at least not parallelised.
Have a look at the Vector2 source (Vector2_Intrinsics.cs[^]):
using System.Runtime.CompilerServices;
namespace System.Numerics
{
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Dot(Vector2 value1, Vector2 value2)
{
return value1.X * value2.X +
value1.Y * value2.Y;
}
} You might try to implement Cross similar.
|
|
|
|
|
This was actually a good idea!
Except, sadly, [Intrinsic] is not available to us, non MS programmer. I fear this might not just be possible to implement 3rd SIMD extension method. How sad....
|
|
|
|
|
Super Lloyd wrote: Except, sadly, [Intrinsic] is not available to us, non MS programmer So that is the reason why there is not much documentation about it.
But it seems to be the option that enables usage of processor specific instructions like SIMD.
|
|
|
|
|
Is it worth it?
I am writing a lib that do shape operation (shape being like polygon, just with bezier curve for contour instead of lines)
I have a lot of custom Math code, including custom Point2D, Vecto2D and Matrix3x2 and today.. I just saw that System.Numerics is such a library with such types but hardware accelerated (SIMD) maths.
Since my lib is quite performance intensive I wonder if it is worth rewriting?
Any link on performance guide and comparison with Numerics.Vectors?
I found some post on the internet where people had bad experience an unexpectedly worst performance with it.....
modified 29-Apr-18 20:59pm.
|
|
|
|
|
Hi All,
I am working on a project using c# .net and its related to connecting to device and streaming the information over the network . We are using RTSP protocol for connecting to that device. We have developed code using media-player-vlc, while testing the code we have observed a strange behavior , where we are able to play local file and public streaming url. where as when we try with our customer url. its giving the below error. the same url when we try to play using VLC media player its working fine.
[0b7204c0] live555 demux error: Failed to connect with rtsp:
[0b7204c0] live555 demux error: TCP rollover failed, aborting
Could any one please update me on this.
|
|
|
|
|