|
Read the license of Office; Or use an alternative way to write your Excel-file - there are a few of them.
As an easy alternative solution; you could turn it from a windows service and run it as a normal application.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
The excel workbook creation and saving is fine in normal user interactive application. But I need to automatically generate an excel report once a week and once a month so I'm using windows service. I haven't really looked into task scheduler. I don't have much luck with quartz.net (but this is still to be used in service mode). But if Microsoft Office doesn't allow non-user-interactive application (like my windows service), I wonder if task scheduler can do the job.
|
|
|
|
|
Hi,
I have written the below code to connect to the server.Also I should login to the server to fetch data from it.How to supply credentials via socket so that the server allows the client to fetch the data from server.
byte[] receivedBytes = new byte[1024];
int portno = Convert.ToInt32(txtportnum.Text);
IPHostEntry ipHost = Dns.GetHostByName("192.168.x.y");
IPAddress ipAddress = ipHost.AddressList[0];
IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, portno);
txtstatus.Text = "Creating socket object...";
Socket send_soc = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,ProtocolType.Tcp);
send_soc.Connect(ipEndPoint);
txtstatus.AppendText("\nSuccessfully connected to:" + "\t" + send_soc.RemoteEndPoint);
txtstatus.AppendText("\nConnecting via :" + "\t" + send_soc.LocalEndPoint);
string sendingMessage = "abcde";
SendMessage(send_soc, sendingMessage);
int totalBytesReceived = send_soc.Receive(receivedBytes);
string dff = "";
string s = System.Text.UTF7Encoding.UTF7.GetString(receivedBytes, 0, totalBytesReceived);
txtRx.AppendText(s);
send_soc.Shutdown(SocketShutdown.Both);
send_soc.Close();
try
{
FileStream dr = new FileStream("E:/Demo/IpData/Call.txt", FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite);
StreamReader fg = new StreamReader(dr);
string df = fg.ReadToEnd();
dff = df;
fg.Dispose();
dr.Dispose();
}
catch (Exception dfjdfs)
{
throw dfjdfs;
}
try
{
File.Delete("E:/Demo/IpData/Call.txt");
}
catch (Exception jhu)
{
throw jhu;
}
try
{
FileStream cd = new FileStream("E:/Demo/IpData/Call.txt", FileMode.Create);
StreamWriter cdf = new StreamWriter(cd);
cdf.Write(dff);
cdf.Write(s);
cdf.Dispose();
cd.Dispose();
}
catch (Exception hgy)
{
throw hgy;
}
}
Any guidance on how to supply credentials will be of great help.
|
|
|
|
|
Sockets and credentials aren't really related with each other... TCP just specifies the protocol for how to the communication should work (e.g. how the packets look like etc.). If you take a look at the OSI model[^]:
TCP is layer 4 (Transport Layer[^].
Credentials etc. should be on layer 5 (Session Layer[^])
Session 5-7 are those Layers that you need to implement yourself in your application (or use functionality provided by a framework)
So you need to provide some more details what you're trying to accomplish as " I should login to the server to fetch data from it." doesn't say anything about what you need to do.
What does the server do? Which protocol does it use for communication etc.?
|
|
|
|
|
Since you're using sockets, you're using the transport layer. Credentials are at the application layer. In order to provide those to the server you would have to know exactly what it expects and exactly how it needs to be formatted, byte-for-byte.
Since we know nothing about your server, it's impossible to answer your question. In order to supply that information to us, you would also have to understand it, making your question a moot point.
|
|
|
|
|
Arjun Mourya wrote: I have written the below code to connect to the server. What kind of server?
Arjun Mourya wrote: Also I should login to the server to fetch data from it If your server happens to be a database, you'd use a database-connection - not a raw socket. You don't need to login to use a socket; the server only needs to accept the connection.
Arjun Mourya wrote: <layer>How to supply credentials via socket so that the server allows the client to fetch the data from server. Did you write the server? Does it have a routine to check any credentials supplied?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
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();
}
|
|
|
|
|