|
JOIN the tables before loading them into a collection. You'll have two SQL statements now; paste 'em both, and we'll make a single statement of it. Prerequisite would be that you're using Sql Server (adding in the other DB as a linked database)
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Currently, I use IMAPI library to get the used space of DVD disc on Win7. The calculation is start when insert DVD (handle by WM_DEVICECHANGE window event).
However, with multi session disk (disk that is write many time without finalize), sometime it takes long time to get used space (double when comparing with Window Explorer).
I also investigated and found some other ways to get used space (use IOCTL_DISK_GET_DRIVE_GEOMETRY, IOCTL_SCSI_PASS_THROUGH_DIRECT). The calculating time is improved but result is different from Window result.
I also wonder there is any way that I can reuse the result of window (window also calculated the used space right after insert DVD) without re-calculating? Or any one else to calculate the used space?
Thank you for your interested and helping me.
|
|
|
|
|
WMI may come to your aid - check out the Win32_CDROMDrive class[^].
|
|
|
|
|
Can you explain more detail?
I search and found the way to get all properties from Win32_CDROMDrive. However, the capacity information of DVD Drive seems not to be retrieved.
|
|
|
|
|
Hey guys got a ? that I know is going to get a very objective answer, but here goes anyways. I'm deploying to Afghanistan soon, so I'll have some time at nights to read without interruption from the kids. I'm a beginner programmer, learning the basics of c#. Should I get a book on ASP.net MVC 4, or WFP 4.5? I'm down with learning both desktop development and web development.
Thanks for any input!
|
|
|
|
|
If you are wanting to learn the basics I'd get one of the "Learn C# in XX days" books, and then it really is a preference where you go from there. WPF has a lot of cool things you can do, but its only visible to those you send the executable to. ASP is a good skill to have and MVC can be translated to WPF when you get into that.
There isn't a "this is the one" answer, but if you are starting with basics then get basic books. Learning the back-end of a language before you work on the pretty front end will save you a lot of headaches later.
BTW, thanks for serving and stay safe out there.
|
|
|
|
|
Ron,
Thank you for your reply and safe wishes. I am no longer serving our country in the military though. I just separated from the US Navy, and am now going back out to Afghanistan to support the troops as a contractor.
I'm currently reading two books to learn the basics of C#, Rob Miles C# Yellow Pages and Pro C# 2012 and .NET 4.5
The Pro C# 2012 book has a section on WPF. How much information do I need on WPF to be able to put together a small program?
Thanks,
Jeramy
|
|
|
|
|
You really don't need much. WPF is XML with a .CS code behind. You can use the visual designer to make a form without writing any code at all, but it really gets more powerful if you hand code the XML. There are tools to help though, Microsoft Expression Blend can do some pretty bad-ass stuff without the need to hand code.
|
|
|
|
|
Awesome. I will definitely look into WPF more.
|
|
|
|
|
In my opinion you're better off with a book on .Net with C# (so more general). Something that starts with "Hello world" and builds up from there.
Start with console applications, then winforms, then ASP.NET (web development adds a bunch of complexity) and if that all works out you can check out WPF, LINQ, WCF, ... which is already pretty specific.
I'm pretty sure amazon has some cool books to start out with, make sure to check out the rating.
I would recommend to also install VS express and SQL Server express (incl. management studio), which are free (need to register though) and very easy to use.
hope this helps.
|
|
|
|
|
V,
Thank you for the reply. I think I have a great .Net with C# book (I guess I'll find out once I've read it all the way through).
I was unaware that I could get SQL Server Express. That's definitely good to know.
Thanks,
Jeramy
|
|
|
|
|
You should learn HTML5 and JQuery first. DON'T BE that "developer" who doesn't understand what we're doing here. ASP, MVC, PHP, etc, are all just fancy ways to get HTML, CSS, and Javascript into the browser. If you don't understand that goal, you're going to be a lousy web developer regardless of what other languages you know. The WWW is written in HTML, CSS, and Javascript. Get solid on those basics before tackling higher-level stuff.
TRUST ME. I've had people fired for not knowing HTML, in an ASP.Net shop. Learn to hand-code HTML - it's your bread and butter as a web developer.
For Windows Desktop apps, it's a little different - the foundation of that is basic C# or VB code. Learn the basics by making console apps, and do that for a long time, before you add the complexity of Forms, Events, and all that. Event-based programming is a little hard to understand sometimes, but it's how Windows Desktop apps work, so the idea is to be solid on the basics, so that stuff doesn't trip you up as you learn the higher level stuff.
|
|
|
|
|
My 2c
Choose either one and learn it, ignoring the other. The two are very different (and very similar!) and I would wait until you are comfortable with one, then convert to the other.
If it was me, I'd go the ASP route to start with.
My route (and this will get me downvoted, I'm sure) will be what someone alludes to below;
Start by getting familiar enough with html and css to knock up a static web page.
Learn a bit about Javascript and JQuery so you can 'play' with the page contents.
Now you have a web page that does stuff you start looking at the ASP side and interacting with the server.
MVVM # - I did it My Way
___________________________________________
Man, you're a god. - walterhevedeich 26/05/2011
.\\axxx
(That's an 'M')
|
|
|
|
|
I'm coming up with a different way than the one I previously posted with subject "usb device in use".
I've enumerated the usb device, while filtering out the usb device with vendor & product id. These devices are not volume type (i.e. thumb drives, external hard drives, etc). It is the communication box that communicates with RFID.
I've acquired these usb path from 2 devices from List<strings>:
[0] = "\\\\?\\hid#vid_0483&pid_0003#8&374204f5&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}"
[1] = "\\\\?\\hid#vid_0483&pid_0003#8&f40948&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}"
From what I can see and understand that these numbers "374204f5" and "f40948" are serial numbers. The question is on how do I acquire these serial numbers using one of those USB methods? Or I would just find through string.substring method?
I was looking online and saw WMI class. I couldn't figure out which Win32 class to use. Most examples online I could find are for volume drives
P.S. If you want me to post the code, I would be glad to.
modified 4-Jun-13 14:07pm.
|
|
|
|
|
Be careful...What you're calling a serial number CAN be the device serial number IF it's in the hardware and can be picked up by PnP. If not, a serial number is randomly generated. So, what you see here might be the actual serial number of the device, or it may not. There is no way to tell from the device instance path.
Also, plugging the exact same device into a different post will assign it a different serial number if its not available.
You really have to explain what your doing and why. Just by looking at this post and your last one, "usb device in use", there's no way to determine what the goal of all this is.
|
|
|
|
|
What I was trying to do is to have my software to connect up to 4 USB Communication Box. This box would communicate with RFID tag. In some cases, the USB box would somehow loses connection and the software would detect the loss of communication to the box. Also that when the USB box is reconnected, the software would re-connect and re-communicate again. This software would ensure that the "address" would be unique from other 3 USB devices.
here's my sample code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using HID_API_Library;
using System.Security.Permissions;
namespace USB_Device_Connect_Disconnect_Test
{
public partial class Form1 : Form
{
public enum WM : uint
{
WM_DEVICECHANGE = 0x0219,
WM_PARENTNOTIFY = 0x0210,
DBT_DEVTYP_DEVICEINTERFACE = 5,
DBT_DEVTYP_HANDLE = 6,
DBT_DEVICEARRIVAL = 0x8000,
DBT_DEVICEQUERYREMOVE = 0x8001,
DBT_DEVICEREMOVECOMPLETE = 0x8004,
DBT_DEVTYP_VOLUME = 0x00000002,
DBT_DEVNODES_CHANGED = 7,
BROADCAST_QUERY_DENY = 0x424D5144,
}
byte[] Read_Input = new byte[9];
byte[] DeviceFirmwareVersion = new byte[9];
byte[] inputReport = new byte[9];
HID_API[] hid = new HID_API[4];
GroupBox[] gbDevice = new GroupBox[4];
List<string> usbDevices;
public Form1()
{
InitializeComponent();
MonitorUSBDevices();
}
int ReadPort(int deviceID, ref byte data)
{
int status = hid[deviceID].ExchangeInputAndOutputReports(ref Read_Input, ref inputReport, deviceID);
if (status == 1)
{
data = inputReport[1];
}
else
status = -530;
return status;
}
int GetDeviceFirmwareVersion(int deviceID, ref byte versionDeviceFirmware)
{
byte[] result = new byte[9];
int status = hid[deviceID].ExchangeInputAndOutputReports(ref DeviceFirmwareVersion, ref result, deviceID);
if (status == 1)
versionDeviceFirmware = result[0];
else
{
versionDeviceFirmware = 0x00;
status = -510;
}
return status;
}
int GetBoxID(int deviceID, ref byte boxId)
{
int status = ReadPort(deviceID, ref boxId);
if (status == 1)
{
boxId = (byte)~boxId;
boxId &= 0x0F;
if ((boxId & 0x08) == 0x08)
{
boxId &= 0x06;
boxId >>= 1;
boxId += 1;
}
else
{
boxId = 0;
status = -520;
}
}
else
status = -521;
return status;
}
void CreateGroupBoxes()
{
int yLoc = 12;
for (int i = 0; i < 4; i++)
{
gbDevice[i] = gb_Device0;
gbDevice[i].Location = new Point(218, yLoc);
yLoc += 106;
}
this.Controls.AddRange(gbDevice);
}
List<string> SeekHIDDevices()
{
HID_API hid_api = new HID_API();
return hid_api.EnumerateUSBDevices(0x0003, 0x0483);
}
private void MonitorUSBDevices()
{
usbDevices = SeekHIDDevices();
byte boxID = 0x00;
for (int i = 0; i < usbDevices.Count; i++)
{
hid[i] = new HID_API();
hid[i].OpenUSBDrive(usbDevices[i]);
hid[i].RegisterHidNotification(this.Handle);
}
if (usbDevices.Count >= 1)
{
GetBoxID(0, ref boxID);
lbl_BoxID0.Text = boxID.ToString("X2");
if (usbDevices.Count >= 2)
{
GetBoxID(1, ref boxID);
lbl_BoxID1.Text = boxID.ToString("X2");
if (usbDevices.Count >= 3)
{
GetBoxID(2, ref boxID);
lbl_BoxID2.Text = boxID.ToString("X2");
if (usbDevices.Count == 4)
{
GetBoxID(3, ref boxID);
lbl_BoxID3.Text = boxID.ToString("X2");
}
}
}
}
}
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
protected override void WndProc(ref Message m)
{
int devType = 0;
switch ((WM)m.Msg)
{
case WM.WM_DEVICECHANGE:
{
switch ((WM)m.WParam)
{
case WM.DBT_DEVICEARRIVAL:
{
break;
}
case WM.DBT_DEVICEREMOVECOMPLETE:
{
break;
}
case WM.DBT_DEVNODES_CHANGED:
{
HID_API hid_api = new HID_API();
List<string> usbPath = hid_api.EnumerateUSBDevices(0x0003, 0x0483);
break;
}
}
break;
}
}
base.WndProc(ref m);
}
}
}
|
|
|
|
|
try
{
con1.ConnectionString = SQLConnectionString;
if (con1.State == ConnectionState.Closed)
{
con1.Open();
}
trans = con1.BeginTransaction();
SqlCommand cmd1 = new SqlCommand(“select name from testinfo WITH(XLOCK) where ID=’” + textBox1.Text + “‘”, con1,trans);
SqlDataReader dr1 = cmd1.ExecuteReader();
if (dr1.HasRows)
{
while (dr1.Read())
{
label1.Text = dr1["name"].ToString();
}
}
catch (Exception ee)
{
trans.Commit();
con1.Close();
MessageBox.Show(“Access By Other User “);
}
}
this is working properly ,it generate an exception which is correct , gives an message “access by another user ” ,but this system define exception required lot of time min 10 sec it take , so i want to find any other condition which will show that this row is access by another user.is there is any other parameter so i can identify that this row is exclusive lock by other user.
|
|
|
|
|
From the docs; "Specifies that exclusive locks are to be taken and held until the transaction completes." What did you lock? A row, a page or the entire table?
One doesn't need a transaction to select data; there's also nothing to commit.
GauravSatpute wrote: but this system define exception required lot of time min 10 sec it take , so i want to find any other condition which will show that this row is access by another user.is there is any other parameter so i can identify that this row is exclusive lock by other user. The default method provided by the software will be the most efficient one, I'd presume.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
The reason why it needs a few seconds is because the SqlServer tries to also complete subsequent request on the (locked) table. However, you can specify a Timeout for the SqlCommand (for example 1 Second).
Have a look at this MSDN Page (including an example): System.Data.Sqlclient.Sqlcommand.CommandTimeout.aspx[^]
|
|
|
|
|
GauravSatpute wrote: so i want to find any other condition which will show that this row is access by
another user
Which is probably a very bad idea.
What exactly is your BUSINESS case where all of the following are true
- There are two users
- They are acting on the data at the same time.
- They are modifying the data with different values.
- The above is correct behavior (thus the valid business case.)
|
|
|
|
|
I was just confusing How it works ?
|
|
|
|
|
|
Here you go[^]
The concept of recursion is pretty much that a method keeps calling itself, in c# this is can be summed up with:
public void MyMethod()
{
MyMethod();
}
Note that this will cause an exception because, for practical purposes, the program cannot execute an infinite number of methods without the method ending (technically, there is a stack which monitors method calls, by recursing you add to the stack without removing. As this has limited space, you eventually cause the stack to overflow). So you need to make sure there is an end condition that will always break the loop:
public void MyMethod(int i)
{
if(i < 10)
{
i++;
MyMethod(i)
}
}
looks reasonable. But it will get stack overflow if you start with values of i >= 10. This brings in one of the disadvantages of recursion, that sometimes getting the end condition can be hard. For a simple example it is easy, but for more complicated stuff it isn't.
The final thing to remember is, just because you can, it doesn't mean you should. Aside from performance concerns, recursive algorithms can be harder to understand than plain loops (and you can always write a loop as a recursion, and always write a recursion as a loop) so you need to decide whether the recursive solution is neater than a looping one. As an example, I'd loop across a list, but recursively traverse a tree (which can be seen as a recursive data structure).
“Education is not the piling on of learning, information, data, facts, skills, or abilities - that's training or instruction - but is rather making visible what is hidden as a seed” “One of the greatest problems of our time is that many are schooled but few are educated”
Sir Thomas More (1478 – 1535)
|
|
|
|
|
|
Recursion ->
CallMethod()
{
while (IsTrue())
{
Console.Write("Recursing...");
CallMethod();
}
Console.Write("Done");
}
|
|
|
|
|