
DannyT
Avatar/Signature-
Posts
36 -
Joined
-
Last visited
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by DannyT
-
I've been searching around and experimenting various things for days now for this but am just a bit too green to USB/HID to get my head around it. What I would ideally like to do is write a windows service in c# that will accept input from a USB HID device (specifically a barcode scanner). I want that service to dominate the input from a specific device I.e. the input will not be output to the currently focused application as if it were typed on a keyboard. Is this possible? I've managed to bodge-hijack input with a winforms app using windows events but that just trapped certain key combinations and stole focus and then returned focus on other key combinations. This didn't really work as it wasn't fast enough and some input was lost to the currently focused app or was disrupted if a user was typing whilst scanning. I want to detect a specific HID and then directly consume that HIDs input. Can anyone suggest how I might do this without resorting to writing device drivers? Is this even possible? Thanks for any help, very much appreciated. Dan
-
I'm creating an application that recieves input from a USB barcode scanner. By default the input from the scanner is exactly as if the input were from a usb keyboard, I.e. if I leave notepad open, scan a barcode that barcode sequence get's "typed" into notepad. What I want to do is detect when input is received from the barcode scanner and take that input and use it in my own application rather than wherever the cursor happens to be at the time. Has anyone any suggestions on how I could achieve this? Any help much apprecaited. Dan
-
Insert to db from new strongly typed datarow
DannyT replied to DannyT's topic in Database / XML / Reporting
Thanks plausibly, I am doing that, the above is just a generic function that I can throw any dataset at once updates have been made. I'm currently evaluating strongly typed datasets vs custom classes. -
Insert to db from new strongly typed datarow
DannyT replied to DannyT's topic in Database / XML / Reporting
ah thank you tfowler! I had explored that before but dismissed it, after your post I went back and realised where i was going wrong. For the benefit of others, here is how to update a dataset with a new dataadapter: Public Function ExecuteUpdateDS(ByVal ds as DataSet, ByVal sql as String) as Integer Dim da As New OleDbDataAdapter 'create new dbAdapter da.SelectCommand = New OleDbCommand(sql, myConnection) ' same select command that was used in the initial dataset population Dim autogen As New OleDbCommandBuilder(da) ' CommandBuilder, auto generates Update, Insert and Delete commands Dim rowsUpdated as Integer= da.Update(ds, "Customers") ' commit update ds.AcceptChanges() ' accept modifications to dataset ExecuteUpdateDS = rowsUpdated End Function -
Insert to db from new strongly typed datarow
DannyT replied to DannyT's topic in Database / XML / Reporting
Okay this got the better of me so I resorted to filling the dataset, I then needed to maintain a reference to that dataset which I have done, now I'm sending the dataset to a commitToDb function I realise I need a reference to the original dataadapter I filled it from?! Is this correct? How do I update a dataset to the database using a new dataadapter? I'm sorely missing a trick somewhere as using strongly datasets seems to be very tightly coupling my users' interaction with the data itself. -
I have a strongly typed dataset, called "Customers" for example. My user chooses to create new customer, i have no existing dataset, so i create a new instance of my Customers dataset. dim dsCustomers as new Customers and instantiate a new CustomersDataRow. dim drCustomer as new dsCustomers.Tables(0).NewRow() At this point i've not Filled my ds as I know i'm creating a new record and don't want to make an unneccessary call to the db. I populate my NewRow with the required data. How do I now insert this row into the actual database? I'm trying to pass it to my attempt at a data access layer (which currently has no reference to the original dataset). I seem to be stuck with a detached datarow and can't figure out how to commit it to the database? I'm sure this shouldn't be as difficult as i'm making it but i seem to be having a slow day so any help much appreciated. Regards, Dan
-
databinding multiple list controls to the same datasource
DannyT replied to DannyT's topic in Windows Forms
Thanks plausibly, i've just been looking at this. However, all i can find is examples of how to keep the same selections on bound controls. E.g. clicking a next button will increment a "current item" textfield and also the selected item in a combo. My form seems to already be doing this but I don't want it to, if you can come up with any samples that'd be great. I'll post back if I find anything too. Cheers, Dan -
On my form I have a combobox and 2 checklistboxes, I'm trying to populate them all from the same datasource (an arraylist). The populating is fine, however once populated, if I select something in the combobox, the same items get selected in the other two lists?! I didn't think an arraylist has a "selected" property or collection so why is it doing this? I want to bind to the same datasource but allow each of the lists to have their own different selections???
-
aha! Thanks plausibly, I'd bodged it by manually bubbling the event, but I think addhandler will be a cleaner approach. I'm working on a .net implementation of the ARP Flash Platform framework. So far its going well... Thanks again!
-
I have an MDI form i'm using as an Application class This application "has a" login form as a private property which is exposed to a consuming application controller class via a public getter. I want my controller to handle a login event raised by the login form, however I cannot seem to handle events of the login form as a property of the application? E.g. (pseudo code) Public Class Application private controller as Controller private login as LoginForm Public ReadOnly Property UserLoginForm() As LoginForm Get Return Me.login End Get End Property Private Sub Application_Load() Handles MyBase.Load Me.controller = controller.GetInstance Me.controller.RegisterApp(Me) RaiseEvent AppLaunched() End Sub End Class Public Class Controller Private Property withevents viewRef as Application Public Sub new(app as Application) me.viewRef = app End Sub Public Sub GetInstance() As Controller 'singleton code End Sub '**********THE PROBLEM CODE*********** Public Sub UserLogin() Handles viewRef.UserLoginForm.loginEvent 'can't access UserLoginForm's events??? 'do something with a command End Sub End Class The problem is my UserLogin function on the controller can't seem to access the Applications UserLoginForm property to handle it's events. Hope that makes some sort of sense and someone can help?
-
I have a windows app that i'm developing in vb.net running on an oracle9i db. I have some procedures that return data based on values input by the user, I now need to display the results of these procedures in graphs, I have never done anything like this so anyone that can point me in the right direction is much appreciated. I have attached a spreadsheet showing the exact graphs i'd like to recreate and some dummy source data. Cheers, Dan Graph_mock_ups.zip
-
I hope someone can shed some light on this it's driving me potty: I have a vb.net app running on an oracle 9i back end. The issue is with populating one datatable, on my dev machine, connecting to same db it works fine (even when running installed, deployed package), on another machine it completely ignores a field as follows: Table: CREATE TABLE tbl_order_status ( order_status_id NUMBER(10) NOT NULL, order_status NVARCHAR2(2) DEFAULT '00', order_status_name VARCHAR2(20), CONSTRAINT pk_order_status PRIMARY KEY(order_status) ); data: -- NB there is a trigger which inserts an autonumber type primary key into the first field INSERT INTO tbl_order_status(order_status, order_status_name) VALUES('00', 'status00'); INSERT INTO tbl_order_status(order_status, order_status_name) VALUES('0', 'status0'); INSERT INTO tbl_order_status(order_status, order_status_name) VALUES('01', 'status01'); INSERT INTO tbl_order_status(order_status, order_status_name) VALUES('02', 'status02'); INSERT INTO tbl_order_status(order_status, order_status_name) VALUES('03', 'status03'); INSERT INTO tbl_order_status(order_status, order_status_name) VALUES('04', 'status04'); INSERT INTO tbl_order_status(order_status, order_status_name) VALUES('05', 'status05'); INSERT INTO tbl_order_status(order_status, order_status_name) VALUES('5W', 'status5W'); INSERT INTO tbl_order_status(order_status, order_status_name) VALUES('06', 'status06'); INSERT INTO tbl_order_status(order_status, order_status_name) VALUES('07', 'status07'); INSERT INTO tbl_order_status(order_status, order_status_name) VALUES('08', 'status08'); INSERT INTO tbl_order_status(order_status, order_status_name) VALUES('09', 'status09'); INSERT INTO tbl_order_status(order_status, order_status_name) VALUES('10', 'status10'); INSERT INTO tbl_order_status(order_status, order_status_name) VALUES('11', 'status11'); INSERT INTO tbl_order_status(order_status, order_status_name) VALUES('99', 'status99'); stored procedure: CREATE OR REPLACE PACKAGE pkg_order_status AS TYPE rc_order_status IS REF CURSOR; END; / show errors CREATE OR REPLACE PROCEDURE sp_select_order_status (c_order_status OUT pkg_order_status.rc_order_status) IS BEGIN OPEN c_order_status FOR SELECT DISTINCT order_status_id, order_status, order_status_name FROM tbl_order_status; END; / When i run the procedure from SQL Plus (on either machine) I get the results as expected: SQL> VAR c1 REFCURSOR SQL> execute sp_select_order_status(:c1); PL/SQL procedure successfully completed. SQL> print c1 ORDER_STATUS_ID OR ORDER_STATUS_NAME --------------- -- -------------------- 1 00 Status00 2 0 Status0 3 01 Status01 4 02 Status02 5 03 Status03 6 04 Status04 7 05 Status05 8 5W Status5W 9 06 Status06 10 07 Status07 11 08 Status08 ORDER_STATUS_ID OR ORDER_STATUS_NAME --------------- -- -------------------- 12 09 Status09 13 10 Status10 14 11 Status11 15 99 Status99 15 rows selected. The problem is when i populate a dataset table with the results from that procedure it populates fine on my dev machine, but on the live machine the 2nd field (order_status) is always blank. ' get order statuses to dataset With dbadpt ' set command object properties With cmdOrderStatus .Connection = getCn() .CommandText = "sp_select_order_status" .CommandType = CommandType.StoredProcedure .Parameters.Add("c_order_status", OracleType.Cursor).Direction = ParameterDirection.Output End With ' select command .SelectCommand = cmdOrderStatus .TableMappings.Add("Table", "orderStatus") ' fill dataset .Fill(ds) .Dispose() End With ... Dim dr1 As DataRow For Each dr1 In ds.Tables("orderStatus").Select TextBox1.Text = TextBox1.Text & ", " & dr1(1) Next 'dev outputs: "00, 0, 01, 02, 03 .. etc" 'live outputs: ",,,,,,,, etc" This is obviously a pain in the arse to debug as it works fine on my machine! If anyone can offer any guidance or even a better way to debug and narrow down the problem, i'd be extremely grateful. If you need any more info please dont hesitate to ask. Cheers, Dan
-
Ahhh cheers plausibly, the descriptions in the Post Formatting section are a bit screwy for csharp. Ta!
-
I read other posts and they all contain wonderfully stylized c# samples. mine always displays massively spaced out and no colours: - [csharp] public class uglyFormatting { public void uglyFormatting { throw new Exception("UGLY"); } } [/csharp] i use [charp] and [/csharp ] tags is that wrong?
-
This is actually a method of a factory class implemented because i wanted to perform a common function with the type created by the factory which i was previously doing in the factory. E.g. //(before) public class MemberCollectionFactory { public ArrayList CreateCollection(DataEntity member, string type) { myCollection.Clear(); switch (type) { case "myString1": foreach (DataRow row in dt.Rows) { myEntity = new MyType1; myEntity.Create(row); // MyType1 overrides the Create(row) with implmentation ABC myCollection.Add(myEntity); } break; case "someType2": foreach (DataRow row in dt.Rows) { myEntity = new MyType2; myEntity.Create(row); // MyType2 overrides the Create(row) with implmentation XYZ myCollection.Add(myEntity); } break; //...etc } return myCollection; } } //(after) public class MyFactory { public ArrayList CreateCollection(DataEntity member, string type) { myCollection.Clear(); switch (type) { case "someType1": createList(new MyType1()); break; case "someType2": createList(new MyType2()); break; //etc } return myCollection; } public ArrayList createList(DataEntity mytype) { foreach (DataRow row in dt.Rows) { myEntity = (DataEntity)Activator.CreateInstance(mytype.GetType()); myEntity.Create(row); myCollection.Add(myEntity); } return myCollection; } } just refactoring, I'm sure there's a better way but this works, any suggestions on improvements gratefully recieved. Dan p.s. why does my c# code in here get so spaced out, does the same if I copy, paste or type directly in?
-
I want to instantiate a new variable to the same type as another in c# E.g. public ArrayList createList(DataTable dt, DataEntity mytype) foreach (DataRow row in dt.Rows) { myEntity = new mytype.GetType(); // THIS DOESN'T WORK myEntity.Create(row); myCollection.Add(myEntity); } } I'm trying to intantiate myEntity based on the base class of mytype (which inherits DataEntity). Any suggestions mucho appreciated :S
-
Connecting to SQL Server that is on the internet
DannyT replied to Khaledinho's topic in Database / XML / Reporting
http://www.connectionstrings.com -
Can any patterns gurus rip appart my attempt at encapsulating my data access layer. It's based on an abstract DataEntity superclass that abstracts its own Create, Retrieve, Update and Delete methods, all classes that utilise data from a db implement the DataEntity class. The DataEntity uses a DataManager which is a singleton responsible for making database calls. The Create method is overloaded to allow for 3 different implementations: 1 - no params Create() - creates a blank version to be added to the db 2 - an int param Create(int id) - calls for the row of information specific to the ID provided 3 - a DataRow param Create(DataRow dr) - no call to database creates self with datarow provided. * 3rd method allows for creation of a number of classes with 1 database call returning a datatable, rather than a call to return a list of IDs then repeat calls to get that IDs related information. Implmenetation as follows: - public abstract class DataEntity { private DataManager dm = DataManager.getInstance(); public abstract void Create(); // creates a new object (i.e. not already in Database) public void Create(int id) // calls getRow which gets data needed from db to setup fields { SetupFields(getRow(id)); } public void Create(DataRow row) // have all the data i need so i just SetupFields { SetupFields(row); } public abstract DataRow getRow(int id); // call to DataManager to get the required row protected abstract void SetupFields(DataRow row); // as per Experts Exchange example public abstract void Update(); public abstract void Delete(); } An example of implementation: - public class Member : DataEntity { private int memberId; private string name; private string gender; private int age; private string image; private string location; private bool online; # region Public Properties public int MemberId { get{return memberId;} } public string Name { get{return name;} set{name = value;} } public string Gender { get{return gender;} set{gender = value;} } public int Age { get{return age;} set{age = value;} } public string Image { get{return image;} set{image = value;} } public string Location { get{return location;} set{location = value;} } #endregion public override void Create() { memberId = -1; // identifies when updated that this is to be INSERTed into db name = ""; gender = ""; age = 0; image = ""; location = ""; online = false; } public override DataRow getRow(int id) { return DataManager.getMemberDetails(id); // our singleton datamanager has a call to return a row of member details } protected override void SetupFields(DataRow dr) { memberId = (int)dr["memberId"]; name = (string)dr["name"]; gender = (string)dr["gender"]; age = (int)dr["age"]; image = (string)dr["image"]; location = (string)dr["location"]; online = (bool)dr["onlineStatus"]; } public override void Update() { DataManager.updateMember(this); } public override void Delete() { DataManager.deleteMember(this); } } so i can create a new member by: - Member myMember = new Member(); myMember.create(); //an existing member like so: - myMember.create(someId); //create an arrayList of members like so: - foreach(DataRow dr in dtMembers) { myMember = new Member(); myMember.Create(dr); membersArray.Add(myMember); } Can someone please tell me if i'm on the right lines with this or not? Also if this is practicable i would like to address the following: - Some form of factory for the instantiation and creation (in the Create() sense of the word) of 'Member' so no need to instantiate then create. seems like the implementation of the DataManager could be better, at the moment I just have a large singleton class that does all the calls to the db and returns rows or tables as needed. Is there some form of common data object i can pass around instead of my classes knowing that the data will be a row or a table, is there some common practice for creating a common data object? Much appreciation to anyone that reads all of this, and even more so for any feedback. Cheers, Dan
-
Apologies I did not put anywhere near enough explanation into that, was the end of the day and i think my mind was elsewhere... I've sorted out what i was trying to achieve now, thanks for the replies!
-
Is there anyway to implment an abstract constructor? I.e. how can i acheive the following: - public abstract class MyAbstract { public abstract MyAbstract(); } I get the message "The modifier 'abstract' is not valid for this item" which i can understand by i wish to implement 3 overridable, overloading constructors for an abstract class. Can/should i do this? if not what am i not grasping properly? Cheers,
-
I just discovered that had I not been lazy in the first instance and used proper getters and setters instead of public properties then the DataBinder.Eval would have worked! Mildly annoying solution that took me best part of 2 days to figure out!
-
Thanks plausibly, you had given me the answer i was just dumb on syntax, figured it out now: - <%# ((SomeClass)Container.DataItem).myProperty1 %>
-
Use repeater to iterate hashtable containing objects with properties Here is a better description/example of what i'm trying to achieve: - I am trying to iterate through a hashtable that i have populated with objects using the repeater control. For each iteration i wish to output the values of properties of the objects I am populating the hashtable with. For example: - [csharp] Class SomeClass { public String myProperty1 public String myProperty2 public SomeClass() { this.myProperty1 = "hello"; this.myProperty2 = "goodbye"; } } Class TestSome { public Hashtable myHash = new Hashtable(); public TestSome() { myHash.Add("key1", new SomeClass()); } } [/csharp] In the webform codebehind: - [csharp] TestSome myTest = new TestSome(); this.myRepeater.DataSource = myTest.myHash; this.myRepeater.DataBind(); [/csharp] ASP html <asp:repeater id=myRepeater runat="server"> <ItemTemplate> <DIV style="FLOAT: left; MARGIN-LEFT: 10px"> <asp:Label id="Label2" runat="server" Width="160px"> <!-- how do i specify that i wish to use the class's properties here? --> <%# DataBinder.Eval(Container.DataItem, "myProperty1") %> <br> <%# DataBinder.Eval(Container.DataItem, "myProperty2") %> </asp:Label> </DIV> </ItemTemplate> </asp:repeater>
-
Thanks plausibly, sorry i'm still not quite with it, how do i refer to these properties when using the repeater? SomeClass myClass = new SomeClass(); //Some Class contains the property "myPropert" this.myHash.Add("key1", myClass); this.myRepeater.DataSource = this.myHash; this.myRepeater.DataBind(); <asp:repeater id=rptFeaturedUserBuddies runat="server"> <ItemTemplate> <DIV style="FLOAT: left; MARGIN-LEFT: 10px"> <asp:Label id="Label2" runat="server" Width="160px"> <!-- how do i specify that i wish to use myProperty here? --> <%# DataBinder.Eval(Container.DataItem, "myProperty") %> </asp:Label> </DIV> </ItemTemplate> </asp:repeater>
-
I have a hashtable that i have populated with instances of a custom class, the class has properties that i wish to access when iterating through the hashtable using a repeater. haven't got access to the code right now (at office), but if anyone can tell me how to return the values of a class' properties when iterating through a hashtable using a repeater I would be xtremely dot netting grateful. If needs be i'll post the code when i'm in first thing tomorrow. The error i'm getting is somethign along the lines of myClass.myHash does not contain the property myProperty, when it blatently does. Cheers!