|
|
Thank you for your replies. Simply i didnt like cellformatting so i wrote my own function. I used a foreach and got all rows from datagridview and coloured related cells. I know it is against performence but this thing doesnt require much performence. Thanks again.
|
|
|
|
|
=-----------
<asp:GridView ID="GridView1" runat="server"
BorderStyle="Dashed" AutoGenerateColumns="False" onselectedindexchanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:TemplateField HeaderText="T" HeaderStyle-Width="2%">
<ItemTemplate>
<asp:Label ID="lblBookID" runat="server" Text='<%# Bind("BID")%>'></asp:Label>
</ItemTemplate>
<blockquote class="quote"><div class="op">Quote:</div> </asp:TemplateField>
<asp:CommandField HeaderText="Cart" ShowHeader="True" ShowSelectButton="True" SelectText="Add to Cart"/>
</Columns>
</asp:GridView>
C# Code
---------------------------
//This code reads the selected row, and extract the
Quote:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
int x = 0;
x = Convert.ToInt32(GridView1.SelectedRow.Cells[0].Text);
Label2.Text = x.ToString ();
}
Current out put
-----------------
It displays nothing.
I tried many examples from the internet, but since my gridview is using item templates seem to gives me problems.
|
|
|
|
|
i have 3 text box (line1,line2,line3) and 3 button(button5,button6,button7) if i enter some text in line1 textbox and click the button5.the data will saved in line no 1 in notepad.if i enter some text in line2 textbox and click the button6.the data will saved in line no 2 in notepad.simillary for others textboxes.
private void button5_Click(object sender, EventArgs e)
{
var lineCount = File.ReadLines(@"H:\\specicied.txt").Count();
for (int i = 0; i < 1; i++)
{
using (StreamWriter objWriter = new StreamWriter(@"H:\\specicied.txt"))
{
//objWriter.Write(txtname.Text);
objWriter.Write(line1.Text + Environment.NewLine);
MessageBox.Show("Details have been saved");
}
}
}
private void button6_Click(object sender, EventArgs e)
{
var lineCount = File.ReadLines(@"H:\\My Application\\dd\\data.txt").Count();
for (int i = 1; i < 2; i++)
{
using (StreamWriter objWriter = new StreamWriter(@"H:\\specicied.txt"))
{
//objWriter.Write(txtname.Text);
objWriter.Write(line2.Text + Environment.NewLine);
MessageBox.Show("Details have been saved");
}
}
}
private void button7_Click(object sender, EventArgs e)
{
var lineCount = File.ReadLines(@"H:\\specicied.txt").Count();
for (int i = 2; i < 3; i++)
{
using (StreamWriter objWriter = new StreamWriter(@"H:\\specicied.txt"))
{
//objWriter.Write(txtname.Text);
objWriter.Write(line3.Text + Environment.NewLine);
MessageBox.Show("Details have been saved");
}
}
}
|
|
|
|
|
That's harder than you might think!
The problem is that text files don't have "lines" in the way you think of them: they just contain human readable characters one of which is interpreted by some - but not all - applications as an "end of line" character.
So you can't "write to line 2" because it isn't at a fixed place - where line two starts is immediately after the end of line character indicating the end of line one. And you can't "insert" to a text file, as when you write it will overwrite the existing characters.
So instead of that, read all the lines from your file when your app starts:
private string[] lines;
...
lines = FileReadAllLines(pathToFile); Then when you want to change line 1:
lines[0] = line1.Text;
File.WriteAllLines(pathToFile, lines); And the same for line 2:
lines[1] = line2.Text;
File.WriteAllLines(pathToFile, lines);
BTW: Do yourself a favour, and stop using Visual Studio default names for everything - you may remember that "TextBox8" is the mobile number today, but when you have to modify it in three weeks time, will you then? Use descriptive names - "tbMobileNo" for example - and your code becomes easier to read, more self documenting, easier to maintain - and surprisingly quicker to code because Intellisense can get to to "tbMobile" in three keystrokes, where "TextBox8" takes thinking about and 8 keystrokes...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
modified 19-May-18 11:33am.
|
|
|
|
|
Do yourself another favor. Do not refer to writing a text file as "in notepad". Notepad is an application that edits text files, not a file itself.
|
|
|
|
|
It builds with no errors but it is not calculating the Net pay in the first if block or the gross pay and net pay in the second if block. Please help...
static void Main(string[] args)
{
const double SINGLE_RATE = .22;
const double MARRIED_RATE = .15;
const double WIDOWED_RATE = .13;
const double DIVORCED_RATE = .23;
string maritalStatus;
double hourlyRate = 0, hoursWorked = 0, regularPay = 0, overtimePay = 0, grossPay = 0, taxRate = 0, taxAmount = 0, netPay = 0;
Console.WriteLine("Please enter in your hourly rate: ");
hourlyRate = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Please enter in your hours worked: ");
hoursWorked = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Please enter in your marital status (M)arried, (S)ingle, (W)idowed, (D)ivorced: ");
maritalStatus = Console.ReadLine().ToUpper();
switch (maritalStatus)
{
case "M":
taxRate = MARRIED_RATE;
break;
case "S":
taxRate = SINGLE_RATE;
break;
case "W":
taxRate = WIDOWED_RATE;
break;
case "D":
taxRate = DIVORCED_RATE;
break;
}
if (hoursWorked <= 40)
{
grossPay = (hoursWorked * hourlyRate);
Console.WriteLine("Your gross pay is: " + grossPay.ToString("C"));
netPay = (grossPay - taxAmount);
Console.WriteLine("Your net pay is: " + netPay.ToString("C"));
}
{
taxAmount = (grossPay * taxRate);
}
if (hoursWorked > 40)
{
regularPay = (hoursWorked * hourlyRate);
Console.WriteLine(value: "Your regular pay is: " + regularPay.ToString("C"));
overtimePay = (hoursWorked - 40) * hourlyRate * 1.5;
Console.WriteLine("Your overtime pay is: " + overtimePay.ToString("C"));
grossPay = (regularPay + overtimePay);
Console.WriteLine("Your gross pay is: " + grossPay.ToString("C"));
netPay = (grossPay - taxAmount);
Console.WriteLine("Your net pay is: " + netPay.ToString("C"));
}
Console.WriteLine("Thank you for using our program");
Console.ReadLine();
}
}
}
|
|
|
|
|
Compiling does not mean your code is right!
Think of the development process as writing an email: compiling successfully means that you wrote the email in the right language - English, rather than German for example - not that the email contained the message you wanted to send.
So now you enter the second stage of development (in reality it's the fourth or fifth, but you'll come to the earlier stages later): Testing and Debugging.
Start by looking at what it does do, and how that differs from what you wanted. This is important, because it give you information as to why it's doing it. For example, if a program is intended to let the user enter a number and it doubles it and prints the answer, then if the input / output was like this:
Input Expected output Actual output
1 2 1
2 4 4
3 6 9
4 8 16 Then it's fairly obvious that the problem is with the bit which doubles it - it's not adding itself to itself, or multiplying it by 2, it's multiplying it by itself and returning the square of the input.
So with that, you can look at the code and it's obvious that it's somewhere here:
private int Double(int value)
{
return value * value;
}
Once you have an idea what might be going wrong, start using the debugger to find out why. Put a breakpoint on the first line of the method, and run your app. When it reaches the breakpoint, the debugger will stop, and hand control over to you. You can now run your code line-by-line (called "single stepping") and look at (or even change) variable contents as necessary (heck, you can even change the code and try again if you need to).
Think about what each line in the code should do before you execute it, and compare that to what it actually did when you use the "Step over" button to execute each line in turn. Did it do what you expect? If so, move on to the next line.
If not, why not? How does it differ?
Hopefully, that should help you locate which part of that code has a problem, and what the problem is.
This is a skill, and it's one which is well worth developing as it helps you in the real world as well as in development. And like all skills, it only improves by use!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
You do not calculate the taxAmount until after the first block has completed. You need to calculate tax as soon as you have the gross amount. So your logical sequence should be:
1. Calculate gross pay
2. If hours > 40 then add overtime pay to gross pay
3. Calculate tax on gross pay
4. Calculate net pay
5. Print reports
|
|
|
|
|
As already mentioned, the answer and the problem solution scenario using debugging will help, may I also suggest using full completion syntax on your statements, in particular, when using "if" statements. Please do not use shortcuts without well formed branches. Tip: Maybe also avoid using expressions syntax too until the "well formed" is clearer for you?
To be exact use full braces in each if branch and denote else and elseif if that's what is intended to avoid unknowingly not branching to the desired brace pair, meaning, do not include arbitrary brace pairs... it just makes code hard to read and you may have been able to figure out this particular problem yourself with well formed statements
Example: if(uncertain)
{
TryFormal(syntax);
}
else
{
ProblemsMyOccur = "many";
{
// Perhaps include reasons why each code line was included - especially if you intend to update your code down the road!
|
|
|
|
|
Hi, I am a hobbyist rather than a professional programmer so please go easy on me. I am asking about the feasibility of what I would like to achieve rather than how to actually go about programming it. (although any help gratefully received) - I have posted this in C# because it is the language I have some knowledge of, let me know if I need to move it.
The Problem
The company I work for has some software that allows us to 'publish' emails and their attachments from Outlook (2016) into a document management system. Some of the emails we receive have PDF attachments with no searchable text - just an image. We need to be able to OCR all of our PDF files as they arrive into a users Inbox. We need to keep the attachments in place so we can still publish directly from Outlook, preferably adding a [OCR] tag on the end of the filename. We need to keep the sender and recipient information as well - some OCR solutions allow you to email a server and it replies with the OCR'd documents, but it changes the senders address.
I have found a few companies who supply OCR software which comes with an SDK (Nuance and Abbyy), so I know at least that I can send a document for OCR. It is the attachment handling within Outlook I need information on. I need the workflow to look like this:
Email arrives > check for PDF attachment > If pdf found, send for OCR > save OCR result, either overwriting the original attachment or adding it to the original email but with the tagged filename.
Could anybody tell me if this level of attachment manipulation is possible with a received email?
I hope I explained my issue OK.
|
|
|
|
|
Jim607 wrote: Could anybody tell me if this level of attachment manipulation is possible with a received email? Yup.
How you get your image isn't important; it is a collection of bytes, and they can be sent by mail or come from another source. You can throw any kind of image into OCR-software and fetch results.
Sounds reasonable enough Are you expecting difficulties in a particular area?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
It was manipulating the attachments while they are sitting in the Outlook Inbox I was most unsure of, because it would mean replacing the original attachment.
I have seen lots of code snippets where attachments are extracted and saved, or documents attached to an outgoing email, but none that re-attach documents to the original received email. Do you think this is possible within the Outlook API then? This could solve a real headache for me. If you think the ability to do it is there, I will have to get learning the Outlook API.
I was quite surprised that there is not already a product to do this, but I have not been able to find anything.
|
|
|
|
|
Jim607 wrote: It was manipulating the attachments while they are sitting in the Outlook Inbox I was most unsure of, because it would mean replacing the original attachment. No, it doesn't; you should not modify the original, as it would imply to the user that the "sent" thing was changed when it is not.
Jim607 wrote: I have seen lots of code snippets where attachments are extracted and saved Which you would do, since no OCR-library is going to read emails; that's not the responsibility of an OCR-library.
Jim607 wrote: Do you think this is possible within the Outlook API then? I hope not; I'm pretty sure you can manipulate emails and attachments though.
Save the attachment locally, throw OCR at it, and save the results in a local DB. Don't go messing with original files.
Or, at least make a copy of the email and work on that. You want the original to debug if anything goes wrong
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
You keep talking about "OCR"; but I don't get the point.
There are plenty of "document management solutions" that aren't preoccupied with OCR ... which usually goes along with MICR.
A "file name" is as good as some "other tag" when thought out properly; while "document management systems", by default, allow one to apply other attributes to a document for searching.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Hi,
Every after 4-5 days, application is showing HTTP error 503 and after restart Application from IIS, then it is working, please suggest if anyone faced this issue.
Event Log as below:
Faulting application name: w3wp.exe, version: 10.0.14393.0, time stamp: 0x57899135
Faulting module name: mscorlib.ni.dll, version: 4.6.1586.0, time stamp: 0x575a1299
Exception code: 0xc00000fd
Fault offset: 0x0037198c
Faulting process id: 0x1138
Faulting application start time: 0x01d3de33a1b2c0e2
Faulting application path: C:\Windows\SysWoW64\inetsrv\w3wp.exe
Faulting module path: C:\Windows\assembly\NativeImages_v4.0.30319_32\mscorlib\40571abae9422cd2ca6fafbbde1c3cdc\mscorlib.ni.dll
Report Id: dc62cf7c-c780-400d-8912-a8597269ad96
Faulting package full name:
Faulting package-relative application ID:
|
|
|
|
|
Hmmm,
I'm not a C# guy but I do know that 0xc00000fd is not a memory leak... that's a stack overflow.
Best Wishes,
-David Delaune
|
|
|
|
|
As Randor says, Exception code 0xc00000fd is a stack overflow, not a memory leak - always Google exception codes if you don't know what they mean.
And there is only really one way to cause a stack overflow in a C# app: recursive code.
So start by looking through your code to find what might be recursing slowly - and I do mean slowly, if it's taking days then it's really slow - the stack is normally only around one megabyte, so it doesn't take much for a wildly recursing app to overflow it.
We can't do that for you, and the timescale involved makes the debugger less than practical so you are going to have to fall back on the old ways and add logging code to your app to find out where it enters a method, and doesn't exit before the method is called again. Hopefully, your app is written in a well structured way and that won't be too complicated.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thanks,
I am using Response.Redirect("~/Error.aspx");
So, Thread is aborted, this can be also cause to pressure in Stack?
Shall we use Response.Redirect("~/Error.aspx", false); ?
Thanks
|
|
|
|
|
We cannot tell.
We have no idea what your code is doing, because we can't see it!
You need to start logging this: at the moment you have no information, and are just guessing what is causing this.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hello,,
I need to find the first and second most repeated element in an array.If there are two most repeated numbers then it needs to print the maximum among them.can anyone suggest a solution for it.
|
|
|
|
|
Look at some of the answers below to your original question. You just need to adjust the code for the different counts that you want to collect.
|
|
|
|
|
What have you tried?
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
We can't just "give you a solution" even if we wanted to, because we have no idea how far you are into your course: the solution I'd use - a Linq Query - wouldn't work for you if Generics and Linq are still to be covered in your course.
And of course there is this: your tutor knows this site exists. He will be looking for students handing in other people's work as their own - it's called plagiarism - and can throw you off the course, or out of the school...
If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
this is the code which i tried.it is actually giving output for first frequent element but producing a false output for second frequent.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp14
{
class Program
{
static void Main(string[] args)
{
int i, j, count, maxcount = 0, number = 0, n = 10, part1 = 0, part2 = 0, number1 = 0;
int[] array = new int[10];
for(int k=0;k<10;k++)
{
array[k]= Convert.ToInt32(Console.ReadLine());
}
for (i = 0; i < n; i++)
{
count = 0;
for (j = 0; j < n; j++)
{
if (array[i] == array[j])
count++;
}
if (count > maxcount)
{
maxcount = count;
number = array[i];
}
else
if (count == maxcount)
{
if (array[i] > number)
number = array[i];
}
}
maxcount = 0;
for (i = 0; i < n; i++)
{
count = 0;
if(array[i]==number)
{
continue;
}
for (j = 0; j < n; j++)
{
if (array[i] == array[j])
count++;
}
if (count > maxcount)
{
maxcount = count;
number1 = array[i];
}
else
if (count == maxcount)
{
if (array[i] > number)
number1 = array[i];
}
}
part1 = number;
part2 = number1;
Console.WriteLine(part1);
Console.WriteLine(part2);
Console.ReadKey();
}
}
}
|
|
|
|
|
And now it's time for you to learn to use the debugger!
Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.
Time for you to learn a new (and very, very useful) skill: debugging! Trust me, get used to this - you will be using this a lot, and it's well worth learning while you are dealing with nice, little, self contained problems like this one - trying to learn it on a million line of code behemoth is a lot worse!
Give it a try: You'll be surprised now much information you can get.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|