|
Use an Event handler for the column A. Whenever a cell's value changes you reset the appropriate cell in column B
|
|
|
|
|
Hi Richard, Thanks a lot for replied,
Actualy This is use for checking Log data from fingerprint device,
Cells on column A in Gridview will automaticaly fill by Log data from finger print,
I need column B to show the result PASS or FAIL
Please advice, Thanks in advance
|
|
|
|
|
Then you need to check which events get fired when the log data information arrives at the view. How is this done automatically?
|
|
|
|
|
I'd recommend calculating "pass" or "fail" before loading the data into a gridview. Gridviews shouldn't used to manipulate data, but to display it.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello,
I am populating the root nodes of the treenode1 via the formload() function, I guess you could say they are hard coded.
After that I want to select a root node (which will be a domain) and enumerate the OUs of that domain and then make the outputted (via the code below) sub nodes of the root node (domain) that is already listed.
The function below makes the output, root nodes under the formload() created root nodes instead of subnodes under the formload() created root nodes, how can I make them subnodes of the original formload() root nodes?
Sorry if this is written in a confusing manner, I've tried to reread it and make it less confusing amidst my own confusion.
private void searchForOus(string ouPath)
{
DirectoryEntry ADentry = new DirectoryEntry(ouPath, @"domain\user", "password", AuthenticationTypes.Secure);
DirectorySearcher Searcher = new DirectorySearcher(ADentry);
Searcher.Filter = ("(objectClass=organizationalUnit)");
foreach (DirectoryEntry entry in Searcher.SearchRoot.Children)
{
Console.WriteLine(entry.Path);
if (entry.Path == "LDAP://OU=Core Member Servers,dc=XXX,dc=XXX,dc=XX,dc=XXX")
{
if (ShouldAddNode(entry.SchemaClassName))
{
treeView1.Nodes.Add(GetChildNode(entry));
}
}
}
private TreeNode GetChildNode(DirectoryEntry entry)
{
TreeNode node = new TreeNode(entry.Name.Substring(entry.Name.IndexOf('=') + 1));
foreach (DirectoryEntry childEntry in entry.Children)
{
if (ShouldAddNode(childEntry.SchemaClassName))
{
node.Nodes.Add(GetChildNode(childEntry));
}
}
return node;
}
private bool ShouldAddNode(string schemaClass)
{
bool returnValue = false;
if (schemaClass == "organizationalUnit")
{
returnValue = true;
}
return returnValue;
}
|
|
|
|
|
I don't see you creating the root node that you want to add sub-nodes to and using that outside the recursive call. See if this gives you some ideas:
1. take/create the selected root node of the file/directory structure
2. create the root level TreeNode that maps to root #1
e. recursively iterate the sub-nodes of #1, selecting by your 'should add' function
DirectoryEntry ADentry = new DirectoryEntry(ouPath, @"domain\user", "password", AuthenticationTypes.Secure);
DirectorySearcher Searcher = new DirectorySearcher(ADentry);
Searcher.Filter = "@(objectClass=organizationalUnit)";
string EntryPath = @"LDAP:/OU=Core Member Servers,dc=XXX,dc=XXX,dc=XX,dc=XXX");
string schemaClass = @"organizationalUnit";
TreeNode WorkingTreeNode;
private void searchForOus(string ouPath)
{
foreach (DirectoryEntry entry in Searcher.SearchRoot.Children.Where(ent => ent.Path == EntryPath))
{
Console.WriteLine(entry.Path);
WorkingTreeNode = new TreeNode(entry.Name);
treeView1.Nodes.Add(WorkingTreeNode);
if (ShouldAddNode(entry.SchemaClassName))
{
WorkingTreeNode.Nodes.Add(GetChildNode(entry));
}
}
}
} Note: this code "sketch" has not been compiled/tested; use it for ideas, only.
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
I have to make an app where the users inputs the # of units they purchased in a text box. Then, they click a "calculate" box and it yields 3 labels: Their % of savings, their amount saved, and their total after savings. Here is my code for the calculate button click event.
So first I declare my variables:
const double PACKAGE_COST_double = 99;
int purchased;
double retail;
double discountrate;
double saved;
double total;
Then I have my formulas for each of my variables:
purchased = int.Parse(purchasedTextBox.Text);
saved = (purchased * PACKAGE_COST_double) * discountrate;
retail = purchased * PACKAGE_COST_double;
total = retail * discountrate;
Then I have my if/else statement to determine what the discountrate is going to be:
if (purchased >= 100)
{
discountLabel.Text = "50%";
discountrate = .5;
}
else if (purchased >= 50 && purchased <= 99)
{
discountLabel.Text = "40%";
discountrate = .4;
}
else if (purchased >= 20 && purchased <= 49)
{
discountLabel.Text = "30%";
discountrate = .3;
}
else if (purchased <= 19 && purchased >= 10)
{
discountLabel.Text = "20%";
discountrate = .2;
}
else if (purchased >= 0 && purchased <= 10);
{
discountrate = 0;
}
And at this point I am pretty much lost. I am not sure what to do now. I know I need to incorporate a try/catch, I have a red line under discountrate when I use it in the first formula at the top, and I am not sure where to go from here. Any help/critiques/comments would be greatly appreciated!
|
|
|
|
|
|
You are trying to use the discountrate variable in a calculation before you have given it a value.
double discountrate;
purchased = int.Parse(purchasedTextBox.Text);
saved = (purchased * PACKAGE_COST_double) * discountrate;
You could also simplify your if else blocks.
And leave setting the label until the end by a simple calculation:
if (purchased >= 100)
{
discountrate = .5;
}
else if (purchased >= 50)
{
discountrate = .4;
}
else if (purchased >= 20)
{
discountrate = .3;
}
else if (purchased >= 10)
{
discountrate = .2;
}
else
{
discountrate = 0;
}
discountLabel.Text = string.Format("{0}%", discountrate * 100);
|
|
|
|
|
Thanks! I finished the assignment but I am quite sure that my code is very poorly written. I need help cleaning it up. I feel like it can be written with fewer variables and cleaner, fewer lines of code. (Also, to the guy who refers to himself as a "prick", I wasn't sure how to implement that thing into my code. I tried but I got an error. I do not know what that is. Thanks for your help though!)
Here's what I have so far!! (it works perfectly, as an application):
namespace Software_Sales
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void calculateButton_Click(object sender, EventArgs e)
{
const double PACKAGE_COST_double = 99;
const double FIFTY_PCT_double = .5;
const double FORTY_PCT_double = .4;
const double THIRTY_PCT_double = .3;
const double TWENTY_PCT_double = .2;
const double ZERO_PCT_double = 0;
double retail;
double discountrate;
double saved;
double total;
int purchased;
purchased = int.Parse(purchasedTextBox.Text);
try
{
purchased = int.Parse(purchasedTextBox.Text);
if (purchased >= 100)
{
discountrate = .5;
saved = (purchased * PACKAGE_COST_double) * FIFTY_PCT_double;
retail = purchased * PACKAGE_COST_double;
total = retail - saved;
}
else if (purchased >= 50)
{
discountrate = .4;
saved = (purchased * PACKAGE_COST_double) * FORTY_PCT_double;
retail = purchased * PACKAGE_COST_double;
total = retail - saved;
}
else if (purchased >= 20)
{
discountrate = .3;
saved = (purchased * PACKAGE_COST_double) * THIRTY_PCT_double;
retail = purchased * PACKAGE_COST_double;
total = retail - saved;
}
else if (purchased >= 10)
{
discountrate = .2;
saved = (purchased * PACKAGE_COST_double) * TWENTY_PCT_double;
retail = purchased * PACKAGE_COST_double;
total = retail - saved;
}
else
{
discountrate = 0;
saved = (purchased * PACKAGE_COST_double) * ZERO_PCT_double;
retail = purchased * PACKAGE_COST_double;
total = retail - saved;
}
discountLabel.Text = string.Format("{0}%", discountrate * 100);
totalLabel.Text = total.ToString("c");
total = retail - saved;
retail = purchased * PACKAGE_COST_double;
savedLabel.Text = saved.ToString("c");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
|
|
|
|
|
As it is working I suggest you keep it in a safe place . However as I suggested earlier you can simplify your if/else blocks by removing the common code and putting it at the end. Also, why set the discountrate to a hard coded value when you previously declared constants for the various rates? So it could be something like:
if (purchased >= 100)
{
discountrate = FIFTY_PCT_double;
}
else if (purchased >= 50)
{
discountrate = FORTY_PCT_double;
}
else if (purchased >= 20)
{
discountrate = THIRTY_PCT_double;
}
else if (purchased >= 10)
{
discountrate = TWENTY_PCT_double;
}
else
{
discountrate = ZERO_PCT_double;
}
saved = (purchased * PACKAGE_COST_double) * discountrate;
retail = purchased * PACKAGE_COST_double;
total = retail - saved;
discountLabel.Text = string.Format("{0}%", discountrate * 100);
totalLabel.Text = total.ToString("c");
total = retail - saved;
retail = purchased * PACKAGE_COST_double;
savedLabel.Text = saved.ToString("c");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
|
|
|
|
|
 Thanks so much! This is the simplest version I have been able to come up with. Can someone help me with my catch exception bit? It doesn't seem to work very well.
namespace Software_Sales
{
public partial class salesForm : Form
{
public salesForm()
{
InitializeComponent();
}
private void calculateButton_Click(object sender, EventArgs e)
{
const double PACKAGE_COST_double = 99;
const double FIFTY_PCT_double = .5;
const double FORTY_PCT_double = .4;
const double THIRTY_PCT_double = .3;
const double TWENTY_PCT_double = .2;
const double ZERO_PCT_double = 0;
double retail;
double discountrate;
double saved;
double total;
int purchased;
purchased = int.Parse(purchasedTextBox.Text);
try
{
purchased = int.Parse(purchasedTextBox.Text);
if (purchased >= 100)
{
discountrate = FIFTY_PCT_double;
}
else if (purchased >= 50)
{
discountrate = FORTY_PCT_double;
}
else if (purchased >= 20)
{
discountrate = THIRTY_PCT_double;
}
else if (purchased >= 10)
{
discountrate = TWENTY_PCT_double;
}
else
{
discountrate = ZERO_PCT_double;
}
retail = purchased * PACKAGE_COST_double;
saved = (purchased * PACKAGE_COST_double) * discountrate;
total = retail - saved;
discountLabel.Text = string.Format("{0}%", discountrate * 100);
totalLabel.Text = total.ToString("c");
savedLabel.Text = saved.ToString("c");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
|
|
|
|
|
What doesn't work? As far as I can see it will catch all exceptions, and display a message when it does so.
|
|
|
|
|
"Exception" blocks (or "try ... catch" blocks) are for handling "exceptional" (unanticipated) error conditions.
You should be able to "set up your math" (in your case) so you don't get exceptions. (e.g. test for "zero" BEFORE dividing by a possible zero).
Adding "try .. catch" without justification is a short-cut to becoing a mediocre developer / coder / programmer.
(And once your "try" block gets to a certain size, you should consider putting it in a "sub-routine"; else you'll start getting confused on what is scoped where, etc.)
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I have an Account class, which has a function
double WithDraw(double amountToWithdraw) {
...some code here....
}
If the balance of this account is <= 0, then what should I do?
==> throw an exception (which one?)
==> return 0.0 with some additional information? (in which way?)
I guess:
a) throwing an exception could be wrong, because this scenario is not "exceptional", but standard
b) returning some additional information requires to return a object with additional attributes or a reference to an object in the parameterlist. Seems to be crazy too.
|
|
|
|
|
You could return an instance of a structure instead of a double. This structure could contain any number of fields, which would provide you with unlimited information.
struct TransactionResult
{
double amount;
bool Success;
int ErrorCode;
}
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Frygreen wrote: b) returning some additional information requires to return a object with additional attributes or a reference to an object in the parameterlist. Seems to be crazy too. Why? If you want to communicate "what" went wrong you'll probably need a reference to a resource-text that is translated, and provide the variables.
Frygreen wrote: a) throwing an exception could be wrong, because this scenario is not "exceptional", but standard c) exceptions aren't there to model business cases, but for handling unexpected results in code. Yours isn't.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
The real question is "Is a withdrawal allowed if it results in a negative balance?" and that isn't necessarily a function of that method - for example, my current account has a "permitted overdraft" permanently attached so by balance can genuinely and acceptably go negative, up to a preset limit.
So having a Withdraw method that automatically refuses a transaction if it would result in a negative balance may be against the business logic. In addition, accounts often have "pending transactions" which may not be reflected in the balance but which could change the "approve / reject" decision.
Think about how you are doing this: you should probably divide the responsibilities up into three sections - Presentation (user interface), Business logic, and Data handling - and a withdrawal request would come from the Presentation to the Business for approval, and on then be committed to Data storage by the Business logic if approved, or rejected to the Presentation if not.
Certainly, I don't think an exception would be right - normal processing shouldn't use exceptions for flow control.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Depends on the requirements.
I personally try not to throw exceptions unless it makes sense to do so. You don't have to return additional info.
In this case, overdrafts might be allowed (if they are, you can also specify an overdraft limit, but I leave that as an exercise for you).
public decimal MakeWithdraw(ref decimal balance, decimal amount, bool allowOverdraft=false)
{
decimal widthdrawn = (amount <= balance) ? amount : ((allowOverdraft) ? amount : balance);
balance -= withdrawn;
return widthdrawn;
}
BTW, using decimal instead of double is a good idea because math performed on doubles is not as accurate as math performed on decimals.
".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
|
|
|
|
|
If this is the basis of an "accounting" system, then "transactions" never "fail".
And you don't "withdraw", you post a "debit" (increase in asset accounts / decrease in a liability account; etc.); or "credit".
And each "amount" "posted" to one account, is offset by an entry to another account (i.e. credit cash - debit accounts payable).
At the end of the day, the "reports" indicate who owes what, etc.
(A "mini" blockchain if you will; i.e. "ledger")
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Based on all of your feedback and some additional search I have the following solution for me
I will return a Transaction-Object
struct TransactionResult {
double amountReturned;
EnumTransactionResult eReturn;
}
Some more info:
- I have no complicated scenarios as "Pending Transactions"
- Of course: I can overdraw the account upto an allowed value, which can be less than zero
- This fully fulfills my use-case
Thank you for your input. My question is fully answered
|
|
|
|
|
I cannot debug (set breakpoints,...) my UnitTests with NUnit3.
What works already
My Test-Dll's contain all the tests. They are executed and the result is displayed correctly in the output-window when I run them with the console-runner. So, the test-setup itself seems to be correct.
What I want:
I want to DEBUG my tests when they are executed with the console-runner and stop at breakpoints.
What I did so far:
=> I create a Dll, which contains the testcases/-fixtures.
=> I have set this Dll-Project as startup-project
=> At Properties | Debug of the Dll-Project I select the console-runner as"Start external Program"
and I add the command-line arguments ( my dll )
=> I set breakpoints in my test-code
=> I start a debug-session: The tests are executed, but not breakpoints are hit
It seems, I misunderstand some concept completely
|
|
|
|
|
Have you copied your pdb files in as well?
This space for rent
|
|
|
|
|
yes, the complete dll-bunch is in one single directory. Together with all pdb's
|
|
|
|
|