|
Hi All,
Suppose each element of a one-dimensional array is a single text character, how can I put all of them together to create a single number? I know that one must convert them into characters of type Int or Double, but what about the comma and the period? For instance if the first element of the array is the text character 9, the second is a comma, the third is the text character 11, and the fourth is the text character 8. How can I put them together to form the number 9,118? Thanks in advance for your reply.
|
|
|
|
|
|
hello everyone,
how can i send data to server??
I am using visual studio 2010.The program is working but i am not getting the option of " click here to send data to server" in the Form1 window that comes after client-server acknowledgment.Kindly guide me.
client program is
using System;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Text;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
System.Net.Sockets.TcpClient clientSocket = new System.Net.Sockets.TcpClient();
NetworkStream serverStream;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
msg("Client Started");
clientSocket.Connect("127.0.0.1", 8888);
label1.Text = "Client Socket Program - Server Connected ...";
}
private void button1_Click(object sender, EventArgs e)
{
NetworkStream serverStream = clientSocket.GetStream();
byte[] outStream = System.Text.Encoding.ASCII.GetBytes("Message from Client$");
serverStream.Write(outStream, 0, outStream.Length);
serverStream.Flush();
byte[] inStream = new byte[10025];
serverStream.Read(inStream, 0, (int)clientSocket.ReceiveBufferSize);
string returndata = System.Text.Encoding.ASCII.GetString(inStream);
msg("Data from Server : " + returndata);
}
public void msg(string mesg)
{
textBox1.Text = textBox1.Text + Environment.NewLine + " >> " + mesg;
}
}
}
the server program is
using System;
using System.Threading;
using System.Net.Sockets;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
TcpListener serverSocket = new TcpListener(8888);
TcpClient clientSocket = default(TcpClient);
int counter = 0;
serverSocket.Start();
Console.WriteLine(" >> " + "Server Started");
counter = 0;
while (true)
{
counter += 1;
clientSocket = serverSocket.AcceptTcpClient();
Console.WriteLine(" >> " + "Client No:" + Convert.ToString(counter) + " started!");
handleClinet client = new handleClinet();
client.startClient(clientSocket, Convert.ToString(counter));
}
clientSocket.Close();
serverSocket.Stop();
Console.WriteLine(" >> " + "exit");
Console.ReadLine();
}
}
public class handleClinet
{
TcpClient clientSocket;
string clNo;
public void startClient(TcpClient inClientSocket, string clineNo)
{
this.clientSocket = inClientSocket;
this.clNo = clineNo;
Thread ctThread = new Thread(doChat);
ctThread.Start();
}
private void doChat()
{
int requestCount = 0;
byte[] bytesFrom = new byte[10025];
string dataFromClient = null;
Byte[] sendBytes = null;
string serverResponse = null;
string rCount = null;
requestCount = 0;
while ((true))
{
try
{
requestCount = requestCount + 1;
NetworkStream networkStream = clientSocket.GetStream();
networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize);
dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom);
dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$"));
Console.WriteLine(" >> " + "From client-" + clNo + dataFromClient);
rCount = Convert.ToString(requestCount);
serverResponse = "Server to clinet(" + clNo + ") " + rCount;
sendBytes = Encoding.ASCII.GetBytes(serverResponse);
networkStream.Write(sendBytes, 0, sendBytes.Length);
networkStream.Flush();
Console.WriteLine(" >> " + serverResponse);
}
catch (Exception ex)
{
Console.WriteLine(" >> " + ex.ToString());
}
}
}
}
}
please guide me.
Regards.
modified on Saturday, July 3, 2010 3:19 AM
|
|
|
|
|
Can you please edit your post and use "Pre" tag to format your code so that
it is easier to read/understand and give proper reply.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
|
I was wondering if anyone knows if the amazon api supports kindle book look.
What I'm trying to do is take and make a database that stores the asins and then searchs amazon for recommended reads.
Example if my database has Dan Brown = Lost Symbol
I would hit search recommendations and then it would spit out a list
Dan Brown = Angels and Demons
Jeffery Deaver =Broken Window
so on
Just wondering if anyone knows how that might be done? Or a good tutorial of how to do it?
I went to amazon's page but was lost. Not sure what api to download or which documentation to read. Sorry for the bother hopefully someone can shed some light on me..
thanks
|
|
|
|
|
Do you mean kindle API? Then see here.
|
|
|
|
|
Well what I was hoping to do is make a program in c# that would allow me to enter all my books that I have read kind of like the calibre program.
However this program would do nothing more than take and parse amazon for similar books (recommendations) then check to see if the books i already in the database if it isn't then take and automatically used the amazon sample feature and send a sample of those books to the kindle.
|
|
|
|
|
Hi all,
I have searched whole day now, for a solution that could fit my needs, yet again, I have to hope that some of your pro's here can help me getting closerto a solution.
I'm using DataGridView in C# WinForms to show 6 coloumns (CustomerName, Subscribers, unsubcribed, specialCases, potential, percentage connected in %), it would look like:
CustomerName 20 4 0 24 20/24*100=83%
CustomerName2 12 10 1 22 12/22*100=55%
etc.
And the rows just continue basedon the number of customers of cause. Now, thats ain't any problem, and I get all my data proper as wanted.
Now I want to make it a little bit more useful, and HIGHLIGHT every cell/row with a lightRed color, where the percentage is BELOW 70% (like row number 2 in my example).
I have try'd with:
private void grid_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
if (e.ListChangedType != ListChangedType.ItemDeleted)
{
DataGridViewCellStyle red = grid.DefaultCellStyle.Clone();
red.BackColor = Color.LightPink;
foreach (DataGridViewRow r in grid.Rows)
{
if ((int)r.Cells["nummer6"].Value < 70)
{
r.DefaultCellStyle = red;
}
}
}
}
or with a more similar code:
foreach (DataGridViewRow row in grid.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
if (cell.ColumnIndex == 5)
{
if ((int)cell.Value < 70)
{
row.DefaultCellStyle.BackColor = Color.LightPink;
}
}
}
}
But no matter what, then I can't get the backColor changed on rows where the % value in the last column cell is below 70%.
Any ideas and help are preciated....
|
|
|
|
|
I have done an experiment using the good old Northwind Database Suppliers table, modifying your code to suit
Here is the code
private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
if (e.ListChangedType != ListChangedType.ItemDeleted)
{
DataGridViewCellStyle red = dataGridView1.DefaultCellStyle.Clone();
red.BackColor = Color.LightPink;
foreach (DataGridViewRow r in dataGridView1.Rows)
{
if (r.Cells["countryDataGridViewTextBoxColumn"].Value != null)
{
if (r.Cells["countryDataGridViewTextBoxColumn"].Value.ToString() == "USA")
{
r.DefaultCellStyle = red;
}
}
}
}
}
It works fine.
So your problem probably lies in your if ((int)r.Cells["nummer6"].Value < 70) line.
You could try something like if ((int.TryParse(r.Cells["nummer6"].Value.ToString()) < 70) , although it is a bit of a kludge.
I will continue experimenting and will come back to you if I find anything.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas? - Because 31 Oct = 25 Dec.
Business Myths of the Geek #4 'What you think matters.'
|
|
|
|
|
From the experiments that I have done, I can only conclude that the ValueType of your nummer6 column is not int .
I would have expected the cast to int to throw an exception, but it doesn't, or at least hasn't in my tests.
So, I suggest that you find out the true ValueType of your column and cast it appropriately. One way to do this is to temporarily add the following inside your foreach loop, run it once to get the type then delete it.
if (r.Index == 0)
{
MessageBox.Show("Column 6 datatype is " + r.Cells["nummer6"].ValueType.ToString());
}
Sorry not to be more help.
Good luck!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas? - Because 31 Oct = 25 Dec.
Business Myths of the Geek #4 'What you think matters.'
|
|
|
|
|
Hi there,
Thnx for your experimenting, making me a step closer to understand how it work behind. I'm affraid that as you say, the values ain't intergers but strings. I know that the values I have into the cells ARE intergers (count of subscribers in a interger). But seems that the parsing from string to interger won't work.
Any ideas?
I have decided to show some more source code, since it seems that my _databindingComplete event doesn't even trigger. Sorry for some words in danish (tell me if you need any explained):
public partial class KundeStat_GUI : Form
{
private FrontController Controller = FrontController.Instance;
private decimal fiberbyTotal_tilmeldt = 0;
private decimal fiberbyTotal_utilmeldt = 0;
private decimal fiberbytotal_særaftale = 0;
private decimal serviceTotal_tilmeldt = 0;
private decimal serviceTotal_utilmeldt = 0;
private decimal serviceTotal_særaftale = 0;
private decimal erhvervTotal_tilmeldt = 0;
private decimal erhvervTotal_utilmeldt = 0;
private decimal erhvervTotal_særaftale = 0;
public KundeStat_GUI()
{
InitializeComponent();
}
private void KundeStat_GUI_Load(object sender, EventArgs e)
{
Dictionary<string, DataGridView> datas = new Dictionary<string, DataGridView>();
foreach (Kundetype item in Controller.HentAlleKundetyper())
{
grid = new DataGridView();
grid.Columns.Add("nummer1", "Foreningsnavn");
grid.Columns.Add("nummer2", "Tilmeldte");
grid.Columns.Add("nummer3", "Ikke tilmeldt");
grid.Columns.Add("nummer4", "Særaftale");
grid.Columns.Add("nummer5", "Potentielle");
grid.Columns.Add("nummer6", "% tilslutning");
grid.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
grid.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
grid.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
grid.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
grid.Columns[4].AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
grid.Columns[5].AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
grid.Columns[5].ValueType = typeof(decimal);
grid.ReadOnly = true;
grid.AllowUserToAddRows = false;
grid.AllowUserToDeleteRows = false;
grid.RowHeadersVisible = false;
grid.Dock = DockStyle.Fill;
datas.Add(item.Type, grid);
TabPage tp = new TabPage(item.Type);
tp.Controls.Add(grid);
tabControl1.TabPages.Add(tp);
}
foreach (Kunde item in Controller.HentAlleKunder())
{
decimal tilmeldte = 0;
decimal ikketilmeldt = 0;
decimal særaftale = 0;
foreach (Lejlighed item1 in item.Lejligheds)
{
#region 24ports switch
if (item1.Switch.AntalPorte == 26)
{
}
#endregion
#region 48ports switch
else if (item1.Switch.AntalPorte == 50)
{
}
#endregion
}
decimal procent = 0;
try
{
procent = (tilmeldte / (tilmeldte + ikketilmeldt)) * 100;
}
catch (DivideByZeroException)
{
}
datas[item.Kundetype.Type].Rows.Add(item.KundeNavn, tilmeldte, ikketilmeldt, særaftale, tilmeldte + ikketilmeldt, procent.ToString("###"));
}
foreach(Kundetype kundet in Controller.HentAlleKundetyper())
{
decimal procentTotal = 0;
try
{
if (kundet.Type.Equals("Fiberby"))
procentTotal = (fiberbyTotal_tilmeldt / (fiberbyTotal_tilmeldt + fiberbyTotal_utilmeldt)) * 100;
if (kundet.Type.Equals("Serviceaftale"))
procentTotal = (serviceTotal_tilmeldt / (serviceTotal_tilmeldt + serviceTotal_utilmeldt)) * 100;
if (kundet.Type.Equals("Erhverv"))
procentTotal = (erhvervTotal_tilmeldt / (erhvervTotal_tilmeldt + erhvervTotal_utilmeldt)) * 100;
}
catch (DivideByZeroException)
{
}
if (kundet.Type.Equals("Fiberby"))
datas[kundet.Type].Rows.Add("Total", fiberbyTotal_tilmeldt, fiberbyTotal_utilmeldt, fiberbytotal_særaftale, fiberbyTotal_tilmeldt + fiberbyTotal_utilmeldt, procentTotal.ToString("###") + "%");
else if (kundet.Type.Equals("Serviceaftale"))
datas[kundet.Type].Rows.Add("Total", serviceTotal_tilmeldt, serviceTotal_utilmeldt, serviceTotal_særaftale, serviceTotal_tilmeldt + serviceTotal_utilmeldt, procentTotal.ToString("###") + "%");
else if (kundet.Type.Equals("Erhverv"))
datas[kundet.Type].Rows.Add("Total", erhvervTotal_tilmeldt, erhvervTotal_utilmeldt, erhvervTotal_særaftale, erhvervTotal_tilmeldt + erhvervTotal_utilmeldt, procentTotal.ToString("###") + "%");
else
datas[kundet.Type].Rows.Add("Total", "", "", "", "", procentTotal.ToString("###") + "%");
}
}
private void grid_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
if (e.ListChangedType != ListChangedType.ItemDeleted)
{
DataGridViewCellStyle red = grid.DefaultCellStyle.Clone();
red.BackColor = Color.LightPink;
foreach (DataGridViewRow r in grid.Rows)
{
if ((int)r.Cells["nummer6"].Value < 50)
{
r.DefaultCellStyle = red;
}
}
}
}
}
And here is a view of some of the designer generated code:
private void InitializeComponent()
{
this.tabControl1 = new System.Windows.Forms.TabControl();
this.grid = new System.Windows.Forms.DataGridView();
this.SuspendLayout();
this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tabControl1.Location = new System.Drawing.Point(2, 57);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(738, 539);
this.tabControl1.TabIndex = 1;
this.grid.DataBindingComplete += new System.Windows.Forms.DataGridViewBindingCompleteEventHandler(this.grid_DataBindingComplete);
}
#endregion
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.DataGridView grid;
Any1 who can see the link of why grid_databindingComplete() doesn't trigger?
modified on Monday, July 5, 2010 7:27 AM
|
|
|
|
|
At the moment I can not see any reason why your DatabindingComplete handler doesn't fire. I will continue to look at that though.
Even if that was working there are two lines in the code that you posted which are contradictory and may cause problems.
grid.Columns[5].AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
<big>grid.Columns[5].ValueType = typeof(decimal);</big>
datas[item.Kundetype.Type].Rows.Add(item.KundeNavn, tilmeldte, ikketilmeldt, særaftale, tilmeldte + ikketilmeldt, <big>procent.ToString("###")</big>);
In the first block you are setting the ValueType to Decimal and yet in the second you are filling it with a string procent.ToString("###") . This is incompatible.
It might be better to modify the last one to simply use the result of your percentage calculation and take care of the displayed data by using the CellFormatting event of the DataGridView
Like this:
datas[item.Kundetype.Type].Rows.Add(item.KundeNavn, tilmeldte, ikketilmeldt, særaftale, tilmeldte + ikketilmeldt, procent);
with the CellFormatting handler something like this:
private void grid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if ((e.Value == DBNull.Value) || (e.Value == null))
{
return;
}
if (this.dataGridView1.Columns[e.ColumnIndex].Name == "nummer6")
{
string nummer6Format = e.Value.ToString("###") + " %";
e.Value = unitPriceFormat;
e.FormattingApplied = true;
}
}
This way you get to keep a numeric value in the DataGridViewCell/Column, much easier to deal with for comparisons, whilst displaying a prettified version, much easier for humans to deal with.
If the DataFormattingComplete ever works you can then use your
if ((<big>decimal</big>)cell.Value < 70)
{
row.DefaultCellStyle.BackColor = Color.LightPink;
}
with more confidence.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas? - Because 31 Oct = 25 Dec.
Business Myths of the Geek #4 'What you think matters.'
|
|
|
|
|
Thnx a lot. I still havn't got it working yet... I'm kinda affraid that its because the dataGridView is "coded" and not drag n' drop'ed... Its just annoying to start over with code who seems too work as they are, but just not when you want this new feature. Its one of my old partners who developed the code, which is why I ain't 100% confident with it yet.
If you find an answer why my event ain't triggered, plz let me know (note that this win form has a TabControl and 3 TabPages).
|
|
|
|
|
We have a utility that we use for analysing log files created by our app.
As it works currently, there is a list of log items and based on a filter [not important] we want to display them.
I use a string builder to populate a rich text box, something like this:
StringBuilder sb = new sb();
foreach (LogItem item in logFile)
{
if (item.Show(filter))
{
sb.Append(item.FullDescription);
}
}
rtf.Text = sb.ToString();
}
I now need a bit more than just text. I'm thinking along the lines of using some rtf markup (can I?) to annotate the text so that when the user clicks on somewhere in the displayed text, I can retrieve the message number. This is to support some extended things[tm] where I need access to the underlying item from the file.
I'm using rtf so that we can copy the text easily into other documents and I don't really want to loose that ability. It may also be worth noting that some of these files can get rather large ~200MB and the displayed text gets rebuilt regularly - or with a bit of fudging it could be amended.
Any help and I'll send you a free badger!
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
|
|
|
|
|
I was going to help till you mentioned the badger!
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
Don't even think about it!
Anyone trying to show a 200MB file in one chunk is looking for unhappy users.
Think about it. There is a log you need to look at. Through the use of very clever code, it loads immediately (Oh look! Flying Bacon! And it's flossing!), and when it does you can scroll through looking for the bit you want. Shouldn't take you more than a week or so...
Page it in. Provide search facilities, save facilities, and filters. Don't even think of loading it into a RTB unless there is less than 100 lines - and even then, try to cut it down. Think about using a DataGridView, or a TreeView instead - be nice to the poor user!
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
OriginalGriff wrote: Provide search facilities [...] filters
Already has it.
The file is loaded, but not displayed and the user [that's me] selects which items to display [not important].
I might have '000s of items but I'll only be displaying a few dozen at any one time. Loading the file and tockenising is done I want to be able to reference back from a click on the displayed text to the underlying item with all the big gubananas in.
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
|
|
|
|
|
BTW: Don't send me a badger - we have hedgepigs!
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
How about a used lepracan?
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
|
|
|
|
|
Is that a diseased Irish Fairy?
(A Leprous Leprechaun)
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
[teenager attributes=[hunch up] [hood on]]
Wot eva! u nt me dad, u cnt tll me wot 2 do! giv o...
[/teenager]
Jeez, that was awful, like have spots all over again.
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
|
|
|
|
|
For that kind of functionality, as it is line-oriented, I'd go for a ListBox, not a TextBox/RichTextBox.
Fancy styling/coloring/... requires a UserDrawn mode; no biggy.
You could, not saying you should, load everything in the ListBox, and decide which of all those items are actually visible. No data movement at all!
The one thing you have to add yourself is the RTF output, since now RTF is not used for visualization; you can implement a Key event handler that acts on CTRL/C or CTRL/S (or whatever) and saves the selected items in the appropriate format. The drawback here is you would be emitting RTF code that you haven't looked at yet. You may consider adding a preview in an actual RTB.
PS: Make sure the leprous clown brings a pot of gold with him.
|
|
|
|
|
list box et al won't be any good as the messages are multi line.
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
|
|
|
|
|
a listbox holds items, not necessarily strings; listbox items can take whatever height you want (constant or variable), and can look however you like. So that is not an issue. The main characteristic is: all items are arranged vertically, and there is no speed penalty as the content grows.
|
|
|
|
|