|
hi
am developing c# winforms application.
my requirement is basedon tag_id(sEPC) ,i need to get the data from inventory table and populate that data(tagid,categoryid,productid,productname,gateid and remarks) on listview
next check the transaction table whether the out time is null. if out_time is null ,then update the record using tag_id.
if not null then insert the new record in transaction table.
here is the code:
string query = "SELECT tag_id,category_id,product_id,product_name,gate_id,remarks FROM inventory where tag_id Like '" + sEPC + "'";
MySqlCommand cmd;
MySqlDataReader rdr;
MySqlConnection connection = new MySqlConnection(MyConnectionString);
connection.Open();
// DataTable dt = new DataTable();
cmd = new MySqlCommand(query, connection);
rdr = cmd.ExecuteReader();
/*Received Epc matched in the Inventory Table */
if (rdr != null)
{
String s2 = DateTime.Now.ToString("yyyy-MM-dd HH:MM:ss").Trim();
// ListView1_EPC.Items[j].Remove();
if (rdr.Read())
{
String a1;
cnt = ListView1_EPC.Items.Count;
ListViewItem item = new ListViewItem(rdr.GetString(0));
// cnt = ListView1_EPC.Items.Count;
item.SubItems.Add(rdr.GetString(1));
item.SubItems.Add(rdr.GetString(2));
item.SubItems.Add(rdr.GetString(3));
item.SubItems.Add(rdr.GetString(4));
item.SubItems.Add("");
item.SubItems.Add("");
item.SubItems.Add(rdr.GetString(5));
//item.SubItems[Remarks.Index].Text = rdr.GetString(5);
ListView1_EPC.Items.Add(item);
rdr.Close();
cnt = ListView1_EPC.Items.Count;
MessageBox.Show("cnt:"+cnt);
string query1 = "SELECT tag_id,category_id,product_id,product_name,gate_id,remarks FROM transaction where tag_id Like '" + sEPC + "' AND out_time=NULL";
MySqlCommand cmd1 = new MySqlCommand(query1, connection);
MySqlDataReader rdr1 = cmd1.ExecuteReader();
if (rdr1 == null)
{
item.SubItems[INTime.Index].Text = s2;
//String str = "insert into transaction(tag_id,category_id,product_id,product_name,gate_id,in_time,out_time,remarks)values('" + ListView1_EPC.Items[i].Text.Trim() + "','" + item.SubItems[CategoryID.Index].Text.Trim() + "','" + item.SubItems[ProductID.Index].Text.Trim() + "','" + item.SubItems[ProductName.Index].Text.Trim() + "','" + item.SubItems[GateID.Index].Text.Trim() + "','" + item.SubItems[INTime.Index].Text.Trim() + "','" + item.SubItems[OUTTime.Index].Text + "','" + item.SubItems[Remarks.Index].Text.Trim() + "')";
// MySqlCommand cmd;
String str = "insert into transaction(tag_id,category_id,product_id,product_name,gate_id,in_time,remarks)values('" + ListView1_EPC.Items[i].Text.Trim() + "','" + item.SubItems[CategoryID.Index].Text.Trim() + "','" + item.SubItems[ProductID.Index].Text.Trim() + "','" + item.SubItems[ProductName.Index].Text.Trim() + "','" + item.SubItems[GateID.Index].Text.Trim() + "','" + item.SubItems[INTime.Index].Text.Trim() + "','" + item.SubItems[Remarks.Index].Text.Trim() + "')";
MySqlConnection connection1 = new MySqlConnection(MyConnectionString);
cmd = new MySqlCommand(str, connection1);
connection1.Open();
testret = cmd.ExecuteNonQuery();
}
else
{
item.SubItems[OUTTime.Index].Text = s2;
String str = "update transaction set out_time='" + item.SubItems[OUTTime.Index].Text + "' where tag_id='" + ListView1_EPC.Items[i].Text + "' ";
// String str = "insert into transaction(tag_id,category_id,product_id,product_name,gate_id,in_time,out_time,remarks)values('" + ListView1_EPC.Items[i].Text.Trim() + "','" + item.SubItems[CategoryID.Index].Text.Trim() + "','" + item.SubItems[ProductID.Index].Text.Trim() + "','" + item.SubItems[ProductName.Index].Text.Trim() + "','" + item.SubItems[GateID.Index].Text.Trim() + "','" + item.SubItems[INTime.Index].Text.Trim() + "','" + item.SubItems[OUTTime.Index].Text + "','" + item.SubItems[Remarks.Index].Text.Trim() + "')";
// String str = "insert into transaction(tag_id,out_time)values('" + sEPC + "','" + item.SubItems[OUTTime.Index].Text + "')";
MySqlConnection connection1 = new MySqlConnection(MyConnectionString);
cmd = new MySqlCommand(str, connection1);
connection1.Open();
testret = cmd.ExecuteNonQuery();
}
}//if
while excecution.am getting the error as:
InvalidArgument=Value of '20' is not valid for 'index'.
Parameter name: index
in update query.
plz help me......
there is no index 20 in listview.
my listview is having just:
tagid,categoryid,productid,productname,gateid,intime,outtime,remarks.
|
|
|
|
|
Could you put the code in pre tags? (you can use the "code" button)
It's a little annoying to read this way.
|
|
|
|
|
I'm missing field-names in your update query. How does MySQL know which column you want to push each value into?
UPDATE [tablename]
SET col1 = value1,
col2 = value2 I can only see values in your query, not the fieldnames.
Further you'd like to make that a parameterized query, to prevent attacks on your application using sql-injection. And you should wrap those disposables in a using -block.
..and you might want to do simply a "SELECT COUNT(*)" to test whether the record exists; then you can use ExecuteScalar , which would be a bit more efficient.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
it's ok. thanq
But am getting error as ArgumentOutORange exception at
item.SubItems[INTime.Index].Text = s2;
Listview consists 0nly 7 colums.
string query = "SELECT tag_id,category_id,product_id,product_name,gate_id,remarks FROM inventory where tag_id Like '" + sEPC + "'";
MySqlCommand cmd;
MySqlDataReader rdr;
MySqlConnection connection = new MySqlConnection(MyConnectionString);
connection.Open();
cmd = new MySqlCommand(query, connection);
rdr = cmd.ExecuteReader();
if (rdr != null)
{
String s2 = DateTime.Now.ToString("yyyy-MM-dd HH:MM:ss").Trim();
if (rdr.Read())
{
cnt = ListView1_EPC.Items.Count;
ListViewItem item = new ListViewItem(rdr.GetString(0));
cnt = ListView1_EPC.Items.Count;
item.SubItems.Add(rdr.GetString(1));
item.SubItems.Add(rdr.GetString(2));
item.SubItems.Add(rdr.GetString(3));
item.SubItems.Add(rdr.GetString(4));
item.SubItems.Add(rdr.GetString(5));
ListView1_EPC.Items.Add(item);
cnt = ListView1_EPC.Items.Count;
rdr.Close();
string query1 = "SELECT tag_id,category_id,product_id,product_name,gate_id,remarks FROM transaction where tag_id Like '" + sEPC + "' AND out_time=NULL";
MySqlCommand cmd1= new MySqlCommand(query1,connection);
MySqlDataReader rdr1 = cmd1.ExecuteReader();
if (rdr1 != null)
{
item.SubItems[INTime.Index].Text = s2;
ListView1_EPC.Items.Add(item);
String s1 = "update transaction set out_time='" + s2 + "' where tag_id='" + ListView1_EPC.Items[i].Text + "' ";
MySqlCommand cmd2 = new MySqlCommand(s1, connection);
cmd2.ExecuteNonQuery();
}
else
{
item.SubItems[Remarks.Index].Text = s2;
ListView1_EPC.Items.Add(item);
String str = "insert into transaction(tag_id,category_id,product_id,product_name,gate_id,in_time,remarks)values('" + ListView1_EPC.Items[i].Text.Trim() + "','" + item.SubItems[CategoryID.Index].Text.Trim() + "','" + item.SubItems[ProductID.Index].Text.Trim() + "','" + item.SubItems[ProductName.Index].Text.Trim() + "','" + item.SubItems[GateID.Index].Text.Trim() + "','" + item.SubItems[Remarks.Index].Text.Trim() + "','" + item.SubItems[OUTTime.Index].Text.Trim() + "')";
MySqlCommand cmd2 = new MySqlCommand(str, connection);
cmd2.ExecuteNonQuery();
}
}
|
|
|
|
|
Member 10263519 wrote: But am getting error as ArgumentOutORange exception at item.SubItems[INTime.Index].Text = s2;
Add a "Debug.WriteLine(INTime.Index)", and verify that you got the right column.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I am working with C# windows application. I have html source, which im converting to html node collection using htmlagilitypack. I am parsing through each node and searching for a text. I want to get the relation between two nodes.
For eg:
<div>
<a href="www.google.com"></a>
</div>
<div>
<a href="www.abc.com">structure</a>
</div>
My node1 = <a href="www.google.com"></a>. I will search for text "structure" in other nodes and as a result i get node2 = <a href="www.abc.com">structure</a>
Can i relate these two nodes? say node2 is sibling or parent or child or descendant of node1.
Please help me...
My node1 = <a href="www.google.com"></a>. I will search for text "structure" in remaining nodes and as a result i get node2 = <a href="www.abc.com">structure</a>
Can i relate these two nodes? Like node2 is in sibling or parent or child or descendant etc of node1.
Please help me...
|
|
|
|
|
How do you determine whether a node is a sibling/parent/child of another node? By its location in the same container (div) element? Something else? Not clear to me.
|
|
|
|
|
It can be in the same container or different. I want to relate the nodes.
Say node1's parent's sibling is node2 or node1's sibling is node2 or any scenario that gives the connection between the two nodes.
For Ex:
<div>
<node1/>
</div>
<div>
<node2/>
</div>
node2 is node1's parent's (div1) sibling's (div2) child
I hope this is clear.
|
|
|
|
|
Logically, the only relation between the two is that they are siblings - they are both children of the parent node that encompases them. Neither of these is a parent or child to the other.
|
|
|
|
|
AshwiniSH wrote: Can i relate these two nodes? Yes, but how do you determine the relationship? As it stands there is nothing to connect the two nodes, they are just independent URIs; you need to set some rules that specify how they relate to each other.
Veni, vidi, abiit domum
|
|
|
|
|
Hello,
Can someone explain to me how the matrices work in code and how i can code in order to make an object move?
|
|
|
|
|
That's hardly a question for a forum like this. You need to go and find some teaching materials or articles that discuss the subject.
Veni, vidi, abiit domum
|
|
|
|
|
Hi everyone, I'm currently having a problem in fixing my program. I put a comment in the code below where I think the problem is. I can't pass the values in the methods getWood and getDrawer to the method calcPrice. In the Main(), it should display there all of the information. I'm stuck in this thing please help me thank you so much.
using System;
public class DesksP
{
static int Main()
{
int drawerA = getDrawer();
string getWoodA = getWood();
int getPrice = calcPrice();
Console.WriteLine("The number of drawers is/are: {0}", drawerA);
Console.WriteLine("The type of wood is: {0}", getWoodA);
Console.WriteLine("The total cost of drawer/s is/are: {0}", getPrice);
return 0;
}
private static int getDrawer()
{
int numDrawers;
Console.Write("Enter number of drawer/s: ");
return numDrawers = Convert.ToInt32((Console.ReadLine()));
}
private static string getWood()
{
string woodType;
Console.WriteLine("Enter the type of wood. m for Mahogany, p for Pine and o for Oak: ");
return woodType = Console.ReadLine();
}
private static int calcPrice(int drawerA, char getWoodA)
{
int total = 0;
if(getWoodA == 'p')
total = drawerA * 100;
else if(getWoodA == 'o')
total = drawerA * 140;
else
total = drawerA * 180;
return total;
}
}
modified 26-Nov-13 8:27am.
|
|
|
|
|
The message is pretty explicit: "no overload for method 'calcPrice' takes 0 arguments"
So why are you trying to call it without handing it the parameters it is looking for?
private static int calcPrice(int drawerA, char getWoodA)
Needs two parameters, which you are asking how to pass - so call it with the parameters you want it to work on supplied!
int drawerA = getDrawer();
string getWoodA = getWood();
int getPrice = calcPrice(drawerA, getWoodA);
|
|
|
|
|
Hi I tried your code but I still have an error, anyway I explored my code again and tied to modify it again but it still has an error
using System;
public class ComputePriceDesk
{
public static void Main()
{
double calc = usersDrawers();
Console.WriteLine ("The total of your desk is $ {0}", calc);
}
public static double usersDrawers()
{
int New;
string HowManyDrawers = "";
Console.Write("How many drawers will you like in your desk?: ");
HowManyDrawers = Console.ReadLine();
New = Convert.ToInt32(HowManyDrawers);
return New;
}
public static int woodType()
{
string woodType;
char charWoodType;
Console.WriteLine ("What type of Wood will your desk be? ");
Console.WriteLine ("m for mahogony");
Console.WriteLine ("o for oak");
Console.WriteLine ("p for pine");
woodType = Console.ReadLine();
charWoodType = Convert.ToChar(woodType);
return 0;
}
public static int usersWood()
{
const int moh = 180;
const int oak = 140;
const int pine = 100;
int wood;
if (woodType.Equals('m') || woodType.Equals('M'))
wood = moh;
else if (woodType.Equals('o') || woodType.Equals('O'))
wood = oak;
else
wood = pine;
return wood;
}
public static void calculations(int totalDrawers, char wood)
{
int totalDrawers;
char wood;
int calc;
calc = totalDrawers * wood;
}
}
|
|
|
|
|
This looks okay:
double calc = usersDrawers();
Then you explicitly state that the return value is a double , yet you return an int .
public static double usersDrawers()
{
int New;
...
return New;
}
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
I think the time has come for you to step away from the keyboard, take a deep breath, and re-read your lecture notes - because you appear to be making changes at random!
Your original question was about calling the method you have renamed to "calculations", but you now don't call it at all. You also don't tell us what your "still has an error" is - or where it is, or whether it is run time of compile, etc.
All your code would do if you could run it is ask the user how many drawers he wants, and then tell him a desk will cost that number of dollars!
But you can't run it, can you? Because it doesn't compile. Why not? Because your "usersWood" method needs a parameter called "woodType" that you haven't told it it should expect, so it reports it can't find a variable called "woodType" in the current context. But that's ok - you don't call it anyway...
Seriously: sit down, read through your notes and try to think what you need to do, because at the moment you are probably getting frustrated because nothing you try works, and you don't know what to do, and why are computers so stupid, and...
If you stop and think about the whole task, I believe you can do this. But just guessing and hoping it will work isn't going to do anything pleasant, any more than it would if you tried to learn to drive by jumping in a Bugatti Veyron and slamming the accelerator to the floor...
|
|
|
|
|
Go and read the book I recommended to you, it explains in detail this and other issues in C#.
Veni, vidi, abiit domum
|
|
|
|
|
Hi All,
Need Decrypt C# code for below Encryption code---
public string CreatePwdHash(string pwd)
{
string s = "";
ASCIIEncoding encoding = new ASCIIEncoding();
for (int i = 0; i < pwd.Length; i++)
{
char ch = pwd[i];
byte[] bytes = encoding.GetBytes(ch.GetHashCode().ToString());
char ch2 = pwd[i];
s = s + ch2.GetHashCode().ToString() + Convert.ToBase64String(bytes);
}
return Convert.ToBase64String(encoding.GetBytes(s)).ToUpper();
}
|
|
|
|
|
That's not encryption at all.
That's is a very poor method of converting meaningless data to Base64. There is no way to convert a HashCode back to the original string that it came from.
Also, you should NEVER include code in your application that decrypts a password, no matter how it's encrypted. This increases the level of security in your application making it far more difficult to get users passwords.
If you want to know how to cryptographically hash passwords, read this[^].
|
|
|
|
|
It looks as if you don't believe what I've already told you.
Do yourself a favour and look up one way functions[^].
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
As you have been told (here and in the Lounge) you can't "decrypt" a hash value - it is not encryption.
See here: Password Storage: How to do it.[^] it should explain it to you.
|
|
|
|
|
Where did you find that gem? From the viewpoint of security, it is: bad.
Since you are calling GetHashCode on each character of the string, that thing might actually be reversible... (though hash functions are actually meant to be irreversible, but the input value has a far too narrow range).
Actually, you only need a table containg the hash code for all possible char values (note: release version, not debug version, as they might be different).
No, do not do so. Throw that function away.
If you need to identify users of your application, use proper hashing, with salt!
If you need to pass the password to another service (database, email provider, ...) use proper encryption.
|
|
|
|
|
Hi,
I have develop Chat application like gtalk, Some one help me, how start and develop.
Thanks for reading..
|
|
|
|
|
You can start by searching CodeProject, where you'll find many resources.
As you design your application, and start to write code, you can ask specific questions here, or on the QA forums, and many people will be glad to help you ... if ... you take the time to write your questions clearly, specify what you are doing, and give details about the problems you are having.
"What Turing gave us for the first time (and without Turing you just couldn't do any of this) is he gave us a way of thinking about and taking seriously and thinking in a disciplined way about phenomena that have, as I like to say, trillions of moving parts.
Until the late 20th century, nobody knew how to take seriously a machine with a trillion moving parts. It's just mind-boggling." Daniel C. Dennett
|
|
|
|
|