|
This is one of the many reasons I have email me switched off in my profile.
This space for rent
|
|
|
|
|
Why couldn't you simply set some variables in the Checked handler, which would make the switch statement irrelevant?
Paragraph q1 = null;
public void radio54_ischecked(...)
{
this.q1 = new Paragraph(string.Format("{0} {1}", label10Text, radioButton54.Text));
}
public void radio22_ischecked(...)
{
this.q1 = new Paragraph(string.Format("{0} {1}", label10Text, radioButton22.Text));
}
public void radio1_ischecked(...)
{
this.q1 = new Paragraph(string.Format("{0} {1}", label10Text, radioButton1.Text));
}
at that point, switch statement could be removed and replaced with this line of code, because q1 would already be ready (or null, depending on how your code is written):
if (q1 != null) pdfDosya.Add(q1);
EDIT ==================================
There are ways you can further reduce the code in the checked event handlers (depending on what framework you're dealing with), but I'll leave that as an exercise for the programmer.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 24-May-18 14:55pm.
|
|
|
|
|
Hello guys,
Im using .NET3.5 with ClosedXML libraray version is 0.75.0.0 .
I just inserted into merged cells on excel file. But when i convert to XPS file image is not in cell. Now image size is in pixel.
The questions are:
1. How to correctly insert image into merged cell?.
2. When i print file it's dependent on screen settings . How to solve this problem perfectly.
Thanks
|
|
|
|
|
|
Hi. I have a cellformatting event of a datagridview. No problem when loading and running first time. But what should i do if i click on a button and run cellformatting with this click. I couldnt manage this. Even i run databindingcompleted manually but it didnt help run cellformatting.
|
|
|
|
|
|
Hi. I try to color specific cells of a datagridview in cellformatting. everything is ok but if i color first row's cell, other rows' cells are coloured with the same color. so, for the time being i excluded to color first row. what should be the problem? this is the code:
if (e.ColumnIndex == 2)
{
if (dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString() !=bookmark_id.ToString())
{
if (dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString() == ((int)specialStates.Anlasildi).ToString()) { dataGridView1.Rows[e.RowIndex].Cells["content"].Style.BackColor = Renk_Anlasildi_Backcolor; dataGridView1.Rows[e.RowIndex].Cells["content"].Style.ForeColor = Renk_Anlasildi_Forecolor; }
else if (dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString() == ((int)specialStates.Onemli).ToString()) { dataGridView1.Rows[e.RowIndex].Cells["content"].Style.BackColor = Renk_Onemli_Backcolor; ; dataGridView1.Rows[e.RowIndex].Cells["content"].Style.ForeColor = Renk_Onemli_Forecolor; }
else if (dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString() == ((int)specialStates.Soru).ToString()) { dataGridView1.Rows[e.RowIndex].Cells["content"].Style.BackColor = Renk_Soru_Backcolor; dataGridView1.Rows[e.RowIndex].Cells["content"].Style.ForeColor = Renk_Soru_Forecolor; }
}
}
|
|
|
|
|
Hi,
DataGridView may well be the most complex Control in the entire WinForms universe.
Cells have a DefaultStyle and a Style.
First row and/or first column may have different behavior (e.g. for column headers).
IMHO inside the CellFormatting handler you are expected to only alter the Value and the CellStyle fields of the DataGridViewCellFormattingEventArgs that is passed to you, and both apply to the cell that is invoking the handler.
If you need more than that, I'm afraid you may need to use explicitly created DataGridViewCellStyle objects for each cell you may want to alter the style of. You may want to start reading here: Cell Styles in the Windows Forms DataGridView Control | Microsoft Docs[^]
Anyhow, it may take quite some experimentation to tame the beast.
PS: if you don't have column headers right now, the easiest way out could well be to add them; that way you dont have actual data in row zero!
|
|
|
|
|
|
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
|
|
|
|
|