Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Victor
Jun 18, 2004
The example isn't perfect -- I don't even think it's correct syntax (the type placeholder T isn't defined at class scope). Perhaps it would behoove you to do a little research on reflection and generics, in part to solve your property problem and in part to learn two powerful features of .NET.

Adbot
ADBOT LOVES YOU

JediGandalf
Sep 3, 2004

I have just the top prospect YOU are looking for. Whaddya say, boss? What will it take for ME to get YOU to give up your outfielders?
Ok. I have a .NET (in C#) service that needs to make connection to a projector through TCP. It serves as a back end to a GUI. Reason why it is this way is because I need the GUI to show up just under the login prompt. The idea is that anyone can use the projector w/o having the need to log in to the machine (say to play a DVD). The service is set to start automatically.

The problem:
I keep getting System.IO.IOException: System unable to write data to the transport connection: an existing connection was forcibly closed by the remote host. Now here's the kicker. If I login to the machine and kill the service and then turn it back on, everything runs hunky dory. I can turn the drat thing on/off and what not. And it works for every single subsequent login/logout until the next reboot.

Here's the code that throws the exception.
code:
//m_ns is a NetworkStream object
try
{
    //Write to the port but have to convert string -> byte[]
    if (m_ns.CanWrite)
    {
        m_ns.Write(Encoding.ASCII.GetBytes(cmd), 0, cmd.Length);
    }
    else
    {
        LogFile.WriteLog("!ERROR! OnscreenService: Unable to write to the socket");
        return false;
    }
    return true;
}
catch (SocketException se)  //Exceptions for sockets
{
    //There is code here but I don't think it is relevant to this issue.
}
catch (System.IO.IOException ioe)  //Exceptions for NetworkStream
{
    LogFile.WriteLog(string.Format("!ERROR! Onscreenservice (System.IO.IOException): {0} {1}",
        ioe.Source, ioe.Message, ioe.StackTrace));
    return false;
}
I'm baffled since should .CanWrite return false if the host (projector) forced the connection to close? However, I do not see the "can't write" message anywhere in my log files.

bartholomew_j
Nov 8, 2005
How do I create a 'compact' textbox? (As seen in the search box in firefox) I can't seem to get the Focus events correct...
code:
namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_GotFocus(object sender, EventArgs e)
        {
            textBox1.ForeColor = SystemColors.WindowText;
            textBox1.Text = "";
        }

        private void textBox1_LostFocus(object sender, EventArgs e)
        {
            textBox1.ForeColor = SystemColors.ControlDark;
            textBox1.Text = "Search";
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            
        }

    }
}
What're the correct event handlers to use?

JediGandalf
Sep 3, 2004

I have just the top prospect YOU are looking for. Whaddya say, boss? What will it take for ME to get YOU to give up your outfielders?
Enter/Leave

Edit:
code:
private void mainBox_Enter(object sender, EventArgs e)
{
    mainBox.ForeColor = SystemColors.WindowText;
    mainBox.Text = string.Empty;
}

private void mainBox_Leave(object sender, EventArgs e)
{
    mainBox.ForeColor = SystemColors.ControlDark;
    mainBox.Text = "boobies!";
}

JediGandalf fucked around with this message at 02:13 on Mar 1, 2007

bartholomew_j
Nov 8, 2005

JediGandalf posted:

Enter/Leave

Edit:
code:
private void mainBox_Enter(object sender, EventArgs e)
{
    mainBox.ForeColor = SystemColors.WindowText;
    mainBox.Text = string.Empty;
}

private void mainBox_Leave(object sender, EventArgs e)
{
    mainBox.ForeColor = SystemColors.ControlDark;
    mainBox.Text = "boobies!";
}

Still doesn't work - does it depend on my form setup or something?

Edit: fixed - required me to add an event handler:

code:
this.mainBox.Enter += new System.EventHandler(this.mainBox_Enter);

bartholomew_j fucked around with this message at 02:19 on Mar 1, 2007

JediGandalf
Sep 3, 2004

I have just the top prospect YOU are looking for. Whaddya say, boss? What will it take for ME to get YOU to give up your outfielders?
Well change mainBox to whatever name you desire. That's what I named my textbox control.

Arms_Akimbo
Sep 29, 2006

It's so damn...literal.
Pulling my hair out over this one...

I need to basically be able to do the following:

code:
iInteger = rsRecordset!index_id
...with an SqlDataSource in asp.net 2.0, and I have no clue how. I assume the SDS itself is a fancy new version of the old Connection in VB6, but I don't know how to get to the dataset/recordset in order to pull data from it programmatically.

Any help would be awesome. I'm still figuring this beast out.

rotor
Jun 11, 2001

classic case of pineapple on pizzadog derangement syndrome
Can someone recommend me a c# arbitrary sized integer library? Like if I wanted to keep track of a collection of ~10k digit number and add and subtract them?

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Victor helped me with my first question, but this one is still giving me trouble.

I want the user to be able to drag a textfield around the form and when it's released to swap values with the textfield underneath it. In Java I used a MouseInputListener which had the methods for mousePressed, mouseDragged, and mouseReleased. I'm trying it with the MouseClick and MouseMoved but the text field keeps flickering between 0,0 and the mouse cursor.

code:
private void strField_MouseDown(object sender, MouseEventArgs e)
        {
            originalLoc = ((TextBox)sender).Location;
            mouseDown = true;
        }

        private void strField_MouseMove(object sender, MouseEventArgs e)
        {
            if (mouseDown)
            {
                Point p = new Point(e.X, e.Y);
                ((TextBox)sender).Location = p;
            }
        }

        private void strField_MouseUp(object sender, MouseEventArgs e)
        {
            ((TextBox)sender).Location = originalLoc;
            mouseDown = false;
        }

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
I don't have much experience with it, but shouldn't you be able to use the DragDrop event rather than manually doing this?

wwb
Aug 17, 2004

Arms_Akimbo posted:

Pulling my hair out over this one...

I need to basically be able to do the following:

code:
iInteger = rsRecordset!index_id
...with an SqlDataSource in asp.net 2.0, and I have no clue how. I assume the SDS itself is a fancy new version of the old Connection in VB6, but I don't know how to get to the dataset/recordset in order to pull data from it programmatically.

Any help would be awesome. I'm still figuring this beast out.

Forget about the old VB6 poo poo.

What are you trying to do here--get the data programmatically or bind to a control or what?

havelock
Jan 20, 2004

IGNORE ME
Soiled Meat

rotor posted:

Can someone recommend me a c# arbitrary sized integer library? Like if I wanted to keep track of a collection of ~10k digit number and add and subtract them?

BigInt is supposed to be added to the framework sometime, though it may not be until the next VS release. I know both IronPython and F# include an arbitrary int package. You could always grab either of those and give it a shot (hooray for being able to use multiple languages).

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Hiro2k posted:

Victor helped me with my first question, but this one is still giving me trouble.

I want the user to be able to drag a textfield around the form and when it's released to swap values with the textfield underneath it. In Java I used a MouseInputListener which had the methods for mousePressed, mouseDragged, and mouseReleased. I'm trying it with the MouseClick and MouseMoved but the text field keeps flickering between 0,0 and the mouse cursor.

You could try setting e.Handled at the end of your event:

code:
        private void strField_MouseMove(object sender, MouseEventArgs e)
        {
            if (mouseDown)
            {
                Point p = new Point(e.X, e.Y);
                ((TextBox)sender).Location = p;
                e.Handled = true;
            }
        }
You could also try attaching your handler to the MouseHover event of the form rather than the TextBox since it's the location of the mouse on the form that you really want.

This MSDN page about the MouseMove event might be helpful if you haven't seen it already.

JediGandalf
Sep 3, 2004

I have just the top prospect YOU are looking for. Whaddya say, boss? What will it take for ME to get YOU to give up your outfielders?
No one's got any suggestions for my conundrum (top of this page)? :smith:

rotor
Jun 11, 2001

classic case of pineapple on pizzadog derangement syndrome

havelock posted:

BigInt is supposed to be added to the framework sometime, though it may not be until the next VS release. I know both IronPython and F# include an arbitrary int package. You could always grab either of those and give it a shot (hooray for being able to use multiple languages).

This idea never occurred to me, as I've never used other languages in my c# apps. Can I use the BigInteger code from J#? And if so, how much lard will this add to the binary?

poopiehead
Oct 6, 2004

rotor posted:

This idea never occurred to me, as I've never used other languages in my c# apps. Can I use the BigInteger code from J#? And if so, how much lard will this add to the binary?

The binary just has MSIL for any language, so there shouldn't be any extra lard for using a different language.

Potassium Problems
Sep 28, 2001

rotor posted:

This idea never occurred to me, as I've never used other languages in my c# apps. Can I use the BigInteger code from J#? And if so, how much lard will this add to the binary?
It should be cool, I used it for the java.util.zip library in an old project and it didn't bloat the binary at all.

Lakario
Dec 15, 2006

by Fistgrrl
I am trying to figure out how I can parse a file into my program and output its contents as the hex equivalent. I've done plenty of file parsing, but converting to hex is unknown to me. Could anyone offer me some classes to look at for my purposes?

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



JediGandalf posted:

No one's got any suggestions for my conundrum (top of this page)? :smith:

A guy on google groups* says that canWrite returning true doesn't mean there's a valid connection for the write to go into and goes on to suggest that the machine may be attempting a larger number of connections than is supported by the OS (XP is apparently limited to 5). This makes sense to me because there would be a number of connections being made when the machine starts up. Have you tried looping then waiting while you get that exception?

edit:
* http://groups.google.com/group/microsoft.public.win32.programmer.networks/browse_thread/thread/7a387e592cd9ceb6/070e566f4d23f40d?lnk=st&q=system+service+%22System.IO.IOException%3A%22+System+unable+to+write+data+to+the+transport+connection%3A+an+existing+connection+was+forcibly+closed+by+the+remote+host&rnum=1&hl=en#070e566f4d23f40d

I'm not too surprised that the forum software couldn't parse that

rotor
Jun 11, 2001

classic case of pineapple on pizzadog derangement syndrome

poopiehead posted:

The binary just has MSIL for any language, so there shouldn't be any extra lard for using a different language.

:krad: I am so trying this tonight :w00t:

wwb
Aug 17, 2004

Lone_Strider posted:

It should be cool, I used it for the java.util.zip library in an old project and it didn't bloat the binary at all.

At least presuming the user had j# installed, which is not part of the default .NET deployment IIRC.

Arms_Akimbo
Sep 29, 2006

It's so damn...literal.

wwb posted:

Forget about the old VB6 poo poo.

What are you trying to do here--get the data programmatically or bind to a control or what?

All I need is a value in a field in the first record. I need an index to relate multiple records I'll be saving to two seperate tables, and I just need to find out what the highest index currently is so I can increment it by one. Binding to controls is pretty cut and dry, it's getting access to individual records to extract data in code that's got me caught up.

wwb
Aug 17, 2004

Well, that is mainly because SqlDataSource and the like are not really meant for direct data access but rather for binding to controls. You could do this a few ways:

1) Add a sql data source just to get the value.
1a) Just make a separate function to get the data using ExecScalar()
2) Capture one of the gridview events--like RowDataBound--and pick up the value there.
3) Use the field as a datakey and get the value there after the data is bound.

For something more akin to ADO.OLD, you really have to forget about the DataSource controls and go back to good ole ADO.NET.

Just-In-Timeberlake
Aug 18, 2003
I've got this asp.net problem and was wondering if anybody has any idea what is wrong:

I'm developing this web site that uses a SiteMap file and roles based authorization to allow certain menu items to show up based on the users role (admins, customers, etc). I've configured it to use our SQL 2005 database to authenticate the users and IIS is configured to see the directory (its a sub directory to the root of our regular site, I'm using it just for testing purposes) as a virtual directory so it shows up.

I've developed this on my local machine, and it works fine. But when deployed to our web server (Server 2003/IIS6), the roles aren't working. I can log in just fine, but I'm not getting any roles assigned.

Here is some sample role checking I have:
code:
<asp:LoginView ID="MainLogin" runat="server">
        <AnonymousTemplate>
            Welcome to Sound Management 
        </AnonymousTemplate>
        
        <RoleGroups>
            <asp:RoleGroup Roles="admins">
                <ContentTemplate>
                    <%Response.Redirect("admins/admincp.aspx")%>
                </ContentTemplate>
            </asp:RoleGroup>
    
            <asp:RoleGroup Roles="co-ops">
                <ContentTemplate>
                    <%Response.Redirect("coops/coopDefault.aspx)%>
                </ContentTemplate>
            </asp:RoleGroup>
    
            <asp:RoleGroup Roles="customers">
                <ContentTemplate>
                    <%Response.Redirect("coops/customerDefault.aspx)%>
                </ContentTemplate>
            </asp:RoleGroup>
    
        </RoleGroups>
        
        <LoggedInTemplate>
            You are logged in.
        </LoggedInTemplate>
    </asp:LoginView>
Now, when I log in, it always goes to the LoggedInTemplate, even though I should be following the Admins path. Any ideas what might be wrong?

Just-In-Timeberlake
Aug 18, 2003
I just found my answer here

Arms_Akimbo
Sep 29, 2006

It's so damn...literal.

wwb posted:

Well, that is mainly because SqlDataSource and the like are not really meant for direct data access but rather for binding to controls. You could do this a few ways:

1) Add a sql data source just to get the value.
1a) Just make a separate function to get the data using ExecScalar()
2) Capture one of the gridview events--like RowDataBound--and pick up the value there.
3) Use the field as a datakey and get the value there after the data is bound.

For something more akin to ADO.OLD, you really have to forget about the DataSource controls and go back to good ole ADO.NET.

I have a GridView on the page that has the information I need, the topmost index is always first in the list, it's unsortable on the client side. Can I pull a value from that? How would I go about doing that?

I guess I could make an ugly hack and bind the data to an invisible label or something and pull it out of there.

JediGandalf
Sep 3, 2004

I have just the top prospect YOU are looking for. Whaddya say, boss? What will it take for ME to get YOU to give up your outfielders?

Munkeymon posted:

A guy on google groups* says that canWrite returning true doesn't mean there's a valid connection for the write to go into and goes on to suggest that the machine may be attempting a larger number of connections than is supported by the OS (XP is apparently limited to 5). This makes sense to me because there would be a number of connections being made when the machine starts up. Have you tried looping then waiting while you get that exception?

edit:
*
[table breaking URL]

I'm not too surprised that the forum software couldn't parse that
That actually did help me a little. Thank you :)

Arms_Akimbo
Sep 29, 2006

It's so damn...literal.

Arms_Akimbo posted:

I have a GridView on the page that has the information I need, the topmost index is always first in the list, it's unsortable on the client side. Can I pull a value from that? How would I go about doing that?

I guess I could make an ugly hack and bind the data to an invisible label or something and pull it out of there.

Screw it. I'm just going back to ADO. Nothing works the way it used to, heh. Thanks to the people who tried to help out.

Celebrity Toaster
Jan 21, 2007

Don't worry boys, I'm on the guest list
I'm trying to set the text of a listview sub item, but it doesn't appear to be playing ball :( I currently have the code

foreach (sensibleField field in selectedList)
{
string msgstring = recordBuffer.Substring(field.Offset, field.Size);

listView1.Items[j].SubItems[1].Text = "!!!!";

j++;
}

I can get the existing text out of the cell, but on any subitem other than the one at index 0 it refuses to set the text, what am I missing here?

Grid Commander
Jan 7, 2007

thank you mr. morrison
Make sure that there are some collumns in the listview.
Make sure that the view is set to details.

Here is some code to add an item that has a subitem.

ListViewItem i = new ListViewItem();
i.Text = "List Item";

ListViewItem.ListViewSubItem si = new ListViewItem.ListViewSubItem();
si.Text = "List Sub Item";
i.SubItems.Add(si);
listView1.Items.Add(i);

Edit: here is some code to change the text of the subitem

this.listView1.Items[0].SubItems[1].Text = "hey";

Grid Commander fucked around with this message at 00:00 on Mar 3, 2007

Celebrity Toaster
Jan 21, 2007

Don't worry boys, I'm on the guest list
There are already columns in the listview, and they all have text in them (which I set when the subitems were created). If i set the text of a subItem, then display its contents in a messagebox, the text in the messagebox is correct, but the subitem hasn't updated on screen.

I've tried using the InvalidateRect and Update() methods on the listview, but I just cannot for the life of me get it to display the correct text in the field :(

Belgarath
Feb 21, 2003
What is the best way to go about converting legacy c++ code to .Net? As I understand it, you can write C++\CLI wrapper classes, which you could then use in C# projects.

How easy is this to do? Is there a better solution?

Does anyone have any guides/books on doing this?

gabensraum
Sep 16, 2003


LOAD "NICE!",8,1
Can visual studio sort the code within a class by return type or method name? That'd be handy.

Nurbs
Aug 31, 2001

Three fries short of a happy meal...Whacko!
I have a parametrized SQL query that doesn't seem to work

the commandText is "SELECT ID FROM tableAddress WHERE firstStreetLine = @firstStreetLine"

I am building the parameter as ("@firstStreetLine", data)

data is either a string or system.dbnull.value

I'm not 100% sure it works for string values but I'm 100% sure it doesn't return anything with the null value.

What value should I be using to get a returned value if the value of firstStreetLine is null?

It inserts fine.

(SQL Server 2005 express edition)

Nurbs fucked around with this message at 06:17 on Mar 5, 2007

csammis
Aug 26, 2003

Mental Institution

deep square leg posted:

Can visual studio sort the code within a class by return type or method name? That'd be handy.

Not as a refactoring operation, but I always use the dropdown lists at the top of the codeview to do navaigation in large files. They sort alphabetically by member name.

Joe Anglican
Mar 24, 2005

I've got a megaphone I've been saving for a special occasion.

Nurbs posted:

I have a parametrized SQL query that doesn't seem to work

the commandText is "SELECT ID FROM tableAddress WHERE firstStreetLine = @firstStreetLine"

I am building the parameter as ("@firstStreetLine", data)

data is either a string or system.dbnull.value

I'm not 100% sure it works for string values but I'm 100% sure it doesn't return anything with the null value.

What value should I be using to get a returned value if the value of firstStreetLine is null?

It inserts fine.

(SQL Server 2005 express edition)

The problem is that you can't evaluate NULLs with the "=" operator.

In order to know if a value is null, you have to use the syntax "IS NULL". Here's an example you can run in Query Analyzer.
code:
If 1=1
Print '1=1'
If NULL=NULL
Print 'Null=Null'
If NULL IS NULL 
Print 'Null IS Null'
A possible workaround might be to use the "IsNull" function.. (NOTE: Not the same as IS NULL)

code:
SELECT ID FROM tableAddress WHERE IsNull(firstStreetLine,-1) = @firstStreetLine
This will return a value of -1 for any NULLS. Then you just have to wrap your data in an IIF or something to convert dbnull.value to -1.

Incidentally, why not just build the command string directly so as to avoid futzing with the parameter?

Joe Anglican fucked around with this message at 19:48 on Mar 5, 2007

CapnBry
Jul 15, 2002

I got this goin'
Grimey Drawer
I'm playing around with rewriting a part of one of my company's products as a proof-of-concept, a windows service that connects hospital equipment together. As it stands now, we use named pipes to RPC from the UI to the service running in the background. What I'd like to experiment with is .NETizing it.

I'd like to use ASP.NET as the UI and use remoting to call into the running .NET windows service. I've used .NET remoting as a method to communicate between 2 services on another project, but the company writing the other side pretty much said "do it this way and don't ask questions". Googling mutli-tier remoting turns up what I'd call some pretty shaky solutions as well. Can someone recommend some resources for advanced "Best Practices" n-Tier applications with .NET front-ends?

To give you a little about my background and what I mean by advanced, I've been a full-time C++/Delphi/.NET developer for the past 12 years and have worked with mechanisms from shared memory regions to NamedPipes to DCOM to CORBA to SOAP to RPC-Via-FTP. I need something that will explain going beyond "Hello World" to something that scales well to hundreds of users without bringing the server to its knees.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Joe Anglican posted:

Incidentally, why not just build the command string directly so as to avoid futzing with the parameter?
Isn't the whole point of doing parameterized queries to avoid building the command string directly so as to avoid security holes?

Anyway, couldn't you also do something like "SELECT ID FROM tableAddress WHERE firstStreetLine = @firstStreetLine OR (@firstStreetLine IS NULL AND firstStreetLine IS NULL)" or maybe have two separate queries, one which is the original and one which is just "SELECT ID FROM tableAddress WHERE firstStreetLine IS NULL" and then check in your code (assuming you are using this query in some external app) if the data is null, and if it is, run the second query instead.

Nurbs
Aug 31, 2001

Three fries short of a happy meal...Whacko!

Jethro posted:

Isn't the whole point of doing parameterized queries to avoid building the command string directly so as to avoid security holes?

Anyway, couldn't you also do something like "SELECT ID FROM tableAddress WHERE firstStreetLine = @firstStreetLine OR (@firstStreetLine IS NULL AND firstStreetLine IS NULL)" or maybe have two separate queries, one which is the original and one which is just "SELECT ID FROM tableAddress WHERE firstStreetLine IS NULL" and then check in your code (assuming you are using this query in some external app) if the data is null, and if it is, run the second query instead.

Let me back up, I thought there was a simple answer to this.

I am migrating from one database schema to another.

I have a function fnInsertAddress(s1,s2,city,state,zip,country)

In order to prevent duplication I have a function call in this function

fnGetAddressID(s1,s2,city,state,zip,country)

The purpose of fnGetAddressID is to query the database for this address, and if it is already in the database, return the primary key of that record

The problem I have found is that if any of the variables are NULL then they are not treated properly by the SELECT statement.

So what you guys are saying is that I have to dynamically rewrite the commandText for each null variable? doable but a pain in the butt.

Thanks for the help.

Adbot
ADBOT LOVES YOU

wwb
Aug 17, 2004

Hmm, could you re-normalize the table to have empty strings rather than nulls? Then you could just use the ISNULL function to replace things with empty strings in the query.

  • Locked thread