I'm trying to save a simple app setting ("LanguagePairId") this way:
if (rdbtnEnglishPersian.IsChecked == true) // because "IsChecked" is a nullable bool, the "== true" is necessary
{
langPairId = 1;
}
else if (rdbtnEnglishGerman.IsChecked == true)
{
langPairId = 2;
}
else if (rdbtnEnglishSpanish.IsChecked == true)
{
langPairId = 3;
}
else if (rdbtnGermanSpanish.IsChecked == true)
{
langPairId = 4;
}
else if (rdbtnGermanPersian.IsChecked == true)
{
langPairId = 5;
}
else if (rdbtnSpanishPersian.IsChecked == true)
{
langPairId = 6;
}
AppSettings.Default.LanguagePairId = langPairId;
LanguagePairId is being assigned the expected value (if rdbtnEnglishSpanish is checked, it is assigned 3, etc.)
But trying to read the app setting value on app startup:
int langPairId;
public MainWindow()
{
InitializeComponent();
RecheckTheLastSelectedRadBtn();
}
private void RecheckTheLastSelectedRadBtn()
{
langPairId = AppSettings.Default.LanguagePairId;
switch (langPairId)
{
case 1:
rdbtnEnglishPersian.IsChecked = true;
break;
. . .
...fails -- AppSettings.Default.LanguagePairId is seen as 0 on restaring the app. Why? What must I do to get the value to be saved and restored?
I don't see a call to AppSettings.Default.Save() anywhere.
Without that, your changes to the settings won't be saved.
Try adding it immediately after you set the property. E.g.:
AppSettings.Default.LanguagePairId = langPairId;
AppSettings.Default.Save();
Related
I have written a Switch/Case statement. The purpose of this statement is to check whether a specific checkbox is selected or not. If the checkbox is selected, the case statements get the true value and the name of the checkbox. For example, if I select Ford in the XAML front end interface, a label gets updated and it adds the value of 10 and if it is unselected, it subtracts 10 as to get the value back. However, I'm just getting the value subtracted. Even when I select the checkbox, I end up with -10, -20 etc values.
I can't figure out where I am going wrong with this.
public static int storage = 0;
public static void StorageRequired(string carName, bool state)
{
switch (carName)
{
case "Ford":
if (state)
{
storage += 10;
}
else
{
storage -= 10;
}
return;
case "Honda":
if (state)
{
storage += 10;
}
else
{
storage -= 10;
}
return;
case "McLaren":
if (state)
{
storage += 10;
}
else
{
storage -= 10;
}
return;
case "Mercedes":
if (state)
{
storage += 10;
}
else
{
storage -= 10;
}
return;
default:
storage = 0;
return;
}
}
Now I have a some checkboxes such as Ford, Honda etc, one for each case. And I am calling them StorageRequired method like this:
private void Single_Checked(object sender, RoutedEventArgs e)
{
if (InstallFord?.IsChecked == true)
{
InstallAE.IsChecked = true;
CarConfigs.StorageRequired("Ford", true);
}
if (InstallFord?.IsChecked == false)
{
InstallAE.IsChecked = false;
CarConfigs.StorageRequired("Ford", false);
}
if (InstallHonda?.IsChecked == true)
{
CarConfigs.StorageRequired("Honda", true);
}
if (InstallHonda?.IsChecked == false)
{
CarConfigs.StorageRequired("Honda", false);
}
if (InstallMcLaren?.IsChecked == true)
{
CarConfigs.StorageRequired("McLaren", true);
}
if (InstallMcLaren?.IsChecked == false)
{
CarConfigs.StorageRequired("McLaren", false);
}
if (InstallMercedesvisitor?.IsChecked == true)
{
CarConfigs.StorageRequired("Mercedes", true);
}
if (InstallMercedesvisitor?.IsChecked == true)
{
CarConfigs.StorageRequired("Mercedes", false);
}
lblRequiredSpace.Content = $"Required space: {CarConfigs.storage} Mb";
}
The problem is that when I click and check a checkbox, for instance Ford, I get -10 instead of 10. And then when I uncheck it again, I get -20. I'd really appreciate some help in figuring out where I am going wrong here. Basically, I should get 10 added if I am checking any of the cars and similarly, 10 subtracted to get back to original value if that car is unchecked.
Note: 10 is just arbitrary here to make things simple.
Here is your problem. Never put return in a switch case, you should use break; instead of return.
I am not really sure what CarConfigs.GetSpaceConsumed is, So I will assume that its a number. So if you are getting a number you should (You don't have to but I reccomend) use return functions.
So this should probably work, however I made the storage to be local variable so it will return number from the switch statement and the whole function in this case would a return function.
public static int StorageRequired(string carName, bool state)
{
int storage = 0;
switch (carName)
{
case "Ford":
if (state){
storage += 10;
}else{
storage -= 10;
}
break;
case "Honda":
if (state){
storage += 10;
}else{
storage -= 10;
}
break;
case "McLaren":
if (state){
storage += 10;
}else{
storage -= 10;
}
break;
case "Mercedes":
if (state){
storage += 10;
}else{
storage -= 10;
}
break;
}
return storage;
}
With the || Operator, Microsoft describes short circuit evaluation here Short Circuit Evaluation
However, I have the following code which seems to contradict this process:
if ((_opcLoaded || DoLoadOPC()) &&
(_tagsAdded || DoAddTags()) &&
DoWriteRecipe() &&
(DoResume()))
What I'm trying to prevent is the function DoAddTags from being called if _tagsAdded is true (DoAddTags sets _tagsAdded to true).
However, I'm finding that DoAddTags is called even when _tagsAdded is true. It's the same for _opcLoaded and DoLoadOPC. I've had to put a condition inside DoAddTags to check for _tagsAdded, which shouldn't be necessary.
Can someone explain why this is happening?
Here is the Complete Code
//
// Resume a Paused recipe
case MonitoredTasks.Resume:
Task.Factory.StartNew(() =>
{
MonitoredTask = MonitoredTasks.None;
if ((_opcLoaded || DoLoadOPC()) &&
**(_tagsAdded || DoAddTags())** &&
DoWriteRecipe() &&
(DoResume()))
{
MonitoredTask = MonitoredTasks.None;
RunningState = RecipeRunningStates.Running;
Status = CIPStatuses.Running;
}
else
{
MonitoredTask = MonitoredTasks.Resume;
}
});
break;
And the code for DoAddTags
/// <summary>
/// Adds all necessary tags to the OPC Server Manager
/// </summary>
/// <returns></returns>
bool DoAddTags()
{
bool result = false;
var oldActivity = Activity;
//
// Not doing anything OPC related?
if (Activity != CIPActivities.AddingOPCTags && !_tagsAdded && Activity != CIPActivities.StartingOPC)
{
lock (_locks[LOCK_OPC])
{
Activity = CIPActivities.AddingOPCTags;
Status = CIPStatuses.Initialising;
RecipeError = Errors.None;
try
{
//
// Reset connection and internal tags list
_serverManager.Reset();
//
// Now to add all OPC Tags - Area
CIPStatusTag = _serverManager.AddTag(_area.CIPStatusTag);
RecipeIDTag = _serverManager.AddTag(_area.RecipeIDTag);
RecipeInstructionIDTag = _serverManager.AddTag(_area.RecipeInstructionIDTag);
HandshakingTag = _serverManager.AddTag(_area.HandshakingTag);
GlobalInstructionIDTag = _serverManager.AddTag(_area.GlobalInstructionIDTag);
InstructionAttemptsTag = _serverManager.AddTag(_area.InstructionAttemptsTag);
//
// Area tags OK?
if (CIPStatusTag == null || RecipeIDTag == null || RecipeInstructionIDTag == null || HandshakingTag == null || GlobalInstructionIDTag == null || InstructionAttemptsTag == null)
{
RecipeError = Errors.InvalidAreaTags;
DoError(new RecipeErrorHandlerEventArgs(this) { Message = FormatMessage("CIPRecipe.DoAddTags - Invalid AREA Tags"), Sender = this });
}
else
{
VM_CIPInstruction vm = null;
bool instructionTagErrors = false;
//
// For each area instruction that is used, assig a link to the instruction
foreach (var i in _areaInstructions)
{
//
// Create a View Model for the specified area instruction : this allows us to determine the number of parameters (tags) that apply to the instruction
vm = new VM_CIPInstruction(i.Value.Instruction);
//
// Assign device reference tags
if (vm.DeviceReferencesAvailable)
{
i.Value.DeviceTag = _serverManager.AddTag(i.Value.Instruction.DeviceReferenceTag);
instructionTagErrors = i.Value.DeviceTag == null;
}
//
// For each required parameter, add tag
for (int paramNo = 1; paramNo <= vm.NoOfParams; paramNo++)
{
switch (paramNo)
{
case 1:
//
// Tag defined? Add it
if (vm.AreaInstruction.Param1Tag >= 0)
{
i.Value.Param1 = _serverManager.AddTag(i.Value.Instruction.Param1Tag);
if (i.Value.Param1 == null)
{
instructionTagErrors = true;
}
}
else
{
instructionTagErrors = true;
}
break;
case 2:
//
// Tag defined? Add it
if (vm.AreaInstruction.Param2Tag >= 0)
{
i.Value.Param2 = _serverManager.AddTag(i.Value.Instruction.Param2Tag);
if (i.Value.Param2 == null)
{
instructionTagErrors = true;
}
}
else
{
instructionTagErrors = true;
}
break;
case 3:
//
// Tag defined? Add it
if (vm.AreaInstruction.Param3Tag >= 0)
{
i.Value.Param3 = _serverManager.AddTag(i.Value.Instruction.Param3Tag);
if (i.Value.Param3 == null)
{
instructionTagErrors = true;
}
}
else
{
instructionTagErrors = true;
}
break;
case 4:
//
// Tag defined? Add it and then check quality
if (vm.AreaInstruction.Param4Tag >= 0)
{
i.Value.Param4 = _serverManager.AddTag(i.Value.Instruction.Param4Tag);
if (i.Value.Param4 == null)
{
instructionTagErrors = true;
}
}
else
{
instructionTagErrors = true;
}
break;
case 5:
//
// Tag defined? Add it and then check quality
if (vm.AreaInstruction.Param5Tag >= 0)
{
i.Value.Param5 = _serverManager.AddTag(i.Value.Instruction.Param5Tag);
if (i.Value.Param5 == null)
{
instructionTagErrors = true;
}
}
else
{
instructionTagErrors = true;
}
break;
case 6:
//
// Tag defined? Add it and then check quality
if (vm.AreaInstruction.Param6Tag >= 0)
{
i.Value.Param6 = _serverManager.AddTag(i.Value.Instruction.Param6Tag);
if (i.Value.Param6 == null)
{
instructionTagErrors = true;
}
}
else
{
instructionTagErrors = true;
}
break;
}
}
if (instructionTagErrors)
{
RecipeError = Errors.InvalidInstructionTags;
DoError(new RecipeErrorHandlerEventArgs(this) { Message = FormatMessage(String.Format("CIPRecipe.DoAddTags - Invalid Instruction {0} Tags", vm.Name)), Sender = this });
break;
}
}
//
// Any problems adding tags?
if (RecipeError == Errors.None)
{
Activity = CIPActivities.StartingOPC;
//
// Once all tags added, start OPC Server
result = _serverManager.Start();
if (!result)
{
Status = CIPStatuses.AddTagsFailed;
RecipeError = Errors.OPC;
DoError(new RecipeErrorHandlerEventArgs(this) { Message = FormatMessage("CIPRecipe.DoAddTags - Start of OPC failed"), Sender = this });
}
else
{
**_tagsAdded = true;**
Status = CIPStatuses.TagsAdded;
}
}
else
{
Status = CIPStatuses.AddTagsFailed;
}
}
}
catch (Exception ex)
{
RecipeError = Errors.Exception_AddTags;
DoError(new RecipeErrorHandlerEventArgs(this) { Message = FormatMessage("CIPRecipe.DoAddTags"), Exception = ex, Sender = this });
}
finally
{
Activity = oldActivity;
}
}
}
return Status == CIPStatuses.TagsAdded;
}
I've highlighted the relevant lines with **
On the first pass DoAddTags is executed and _tagsAdded set to TRUE- I've placed a breakpoint here, so I know it is being set. Shortly afterwards (with or without the former breakpoint) DoAddTags is again entered (on the first line) despite_doAddTags == true.
I've even set a breakpoint on the code "(_tagsAdded || DoAddTags())". _tagsAdded == true, yet DoAddTags is still entered.
So what I'm seeing is, and all the Watches/Debugging info is consistent with is that DoAddTags is being called whilst _tagsAdded == true
This code won't display the behavior you describe, the short-circuiting works just as described.
What actually happens: _tagsAdded is initially false, so DoAddTags() is called, which sets _tagsAdded to true.
Then the debugger kicks in, you inspect _tagsAdded and see it's true.
Instead step through your code using F11 and inspect or watch all relevant variables.
I have a structure of different tables in SQL server that allows me to store multiple roles and users (in this case, an User can handle multiple roles).
When I try to turn visible a control in an .aspx depending of the role that the logged-in user has, it gets tired to handle whether to show or not, enable or not the controls that the role should handle.
I already have a solution, but it is hard to maintain. The problem is that the client usually asks for updates from time to time.
What is the best practice to enable controls in .aspx depending on a user role?
An apology for my poor English.
...
...
Every time the client loged-in enter into a .aspx I display different buttons with the roles that he have. For example, if person A have rol 1 and 2 then I display buttons for role 1 and 2. I allow him to choose the role with which he wants to enter the form. If person B have only one rol (for example: rol 3) then I just load the content for rol 3.
protected void accesos()
{
try
{
bool acceso1 = false;
bool acceso2 = false;
bool acceso3 = false;
bool acceso4 = false;
int count = 0;
int intparse = -1;
if (FL.ValidaAcceso(int.Parse(Request.QueryString["IDSubForma"].ToString()), 3, ((clsUsuario)Session["clsUsuario"]).IDUsuario))
{
acceso1 = true;
count = count + 1;
}
if (FL.ValidaAcceso(int.Parse(Request.QueryString["IDSubForma"].ToString()), 2, ((clsUsuario)Session["clsUsuario"]).IDUsuario))
{
acceso2 = true;
count = count + 1;
}
if (FL.ValidaAcceso(int.Parse(Request.QueryString["IDSubForma"].ToString()), 1, ((clsUsuario)Session["clsUsuario"]).IDUsuario))
{
acceso3 = true;
count = count + 1;
}
if (FL.ValidaAcceso(int.Parse(Request.QueryString["IDSubForma"].ToString()), 4, ((clsUsuario)Session["clsUsuario"]).IDUsuario))
{
acceso4 = true;
count = count + 1;
}
if (count > 1)
{
intparse = lblAcceso.Text.Equals("") ? 0 : (Int32.TryParse(lblAcceso.Text, out intparse) ? intparse : 0);
if (intparse <= 0)
{
//IDENTIFICAR QUE BOTONES MOSTRAR
if (acceso1 == false)
{
wcFirmas.Visible = false;
btn1.Visible = false;
}
if (acceso2 == false)
{
wcFirmas.Visible = false;
btn2.Visible = false;
}
if (acceso3 == false)
{
wcFirmas.Visible = false;
btn3.Visible = false;
}
if (acceso4 == false)
{
wcFirmas.Visible = false;
btn4.Visible = false;
}
divMultipleAcceso.Visible = true;
divForma.Visible = false;
}
}
else if (acceso1 == true)
{
lblAcceso.Text = "3";
divForma.Visible = true;
cargarForma(txtNoLote);
}
else if (acceso2 == true)
{
lblAcceso.Text = "2";
divForma.Visible = true;
cargarForma(txtNoLote);
}
else if (acceso3 == true)
{
lblAcceso.Text = "1";
divForma.Visible = true;
cargarForma(txtNoLote);
}
else if (acceso4 == true)
{
lblAcceso.Text = "4";
divForma.Visible = true;
cargarForma(txtNoLote);
}
else
{
divForma.Visible = false;
Master.MostrarMsn("El usuario no cuenta con privilegios de acceso.", 0);
return;
}
}
catch (Exception ex) { Master.MostrarMsn(ex.Message, 0); }
}
I save the rol number into a label to compare it in every control of the form to see if I need to display it or not. Then I do something like:
if(lblAcceso.Text.Equals("2"))
The problem is, if I add an extra rol to this form, (for example, rol 5) then I have to modify the code. The goal is to modify the code as little as possible.
Thanks everyone that have comment so far.
ASP.net role management:
https://msdn.microsoft.com/en-us/library/5k850zwb.aspx
if (!Roles.IsUserInRole(User.Identity.Name, "ROLENAME"))
{
UsersListBox.Visible = false;
return;
}
https://msdn.microsoft.com/en-us/library/4z6b5d42(v=vs.110).aspx
Assuming you are configured to use the built in .net role provider
you can do
if (this.User.IsInRole("RoleName"))
{YourControl.Visible = true }
or
YourControl.Visible = this.User.IsInRole("RoleName")
I want realize arithmetic operations with my list, in this case:
Column "width" * Column "height" should re-Write the Column "Partial".
I have tried do a loop but It is not working.
I put a breakPoint at the row:
_Area[i].Partial = _Area[i].width * _Area[i].height;
And the debug never stop them I can think this line is not been readed.
This is my Collection View Model:
public class CollectionVM_Area : BindableBase
{
private Values_Area _Area = new Values_Area();
public Values_Area Area
{
get { return _Area; }
set { SetProperty(ref _Area, value); }
}
public CollectionVM_Area()
{
_Area.Add(new Area()
{
width=10,
height=11,
});
_Area.Add(new Area()
{
width=5,
height=5,
Partial=1,
});
bool NeedPartial = false;
int i = 0;
while (NeedPartial = false && i < _Area.Count)
{
if (_Area[i].Partida == true)
{
NeedPartial = true;
}
else
{
i++;
}
}
if (NeedPartial==true)
{
_Area[i].Partial = _Area[i].width * _Area[i].height;
NeedPartial = false;
}
else
{
NeedPartial = true;
}
}
}
My Project is a UWP but I think is no different in with a windows forms in lists, any help is appreciated.
You have two mistalkes in your code. First your while-loop makes an assignement instead of a comparisson (= towards ==). Thus the first term within your while-condition allways evaluates to false. Secondly your calculation is located outside the loop causing the NeedPartial-value to be set but not never be read which I doubt is what you want.
Write this therefor:
bool NeedPartial = false;
int i = 0;
while (NeedPartial == false && i < _Area.Count) // or even simpler: while (!NeedPartial ...)
{
if (_Area[i].Partida == true) // or simply: if (_Area[i].Partida) { ... }
{
NeedPartial = true;
}
else
{
i++;
}
if (NeedPartial==true) // if (NeedPartial) ...
{
_Area[i].Partial = _Area[i].width * _Area[i].height;
NeedPartial = false;
}
else
{
NeedPartial = true;
}
}
Edit: Answered.
The Correct Loop is:
bool NeedPartial = false;
int i = 0;
while (!NeedPartial && i < _Area.Count)
{
if (_Area[i].Partida)
{
NeedPartial = true;
}
else
{
i++;
}
if (NeedPartial)
{
_Area[i].Partial = _Area[i].width * _Area[i].height;
NeedPartial = false;
i++;
}
else
{
NeedPartial = true;
}
}
Thanks to HimBromBeere for your help.
i have a form with more than one NumericUpDown as controls to input answer. i want every input is true for an operation (multiplication, sum etc), NumericUpDown for that operation will be disable. i have used the code below (just for sum operation), but i think its not efficient because i have to make a method to check every operation.
private void IsSumTrue() {
if (add1 + add2 == sum.Value)
{
sum.Enabled = false;
}
}
private void IsDifferenceTrue()
{
if (add1 - add2 == difference.Value)
{
difference.Enabled = false;
}
}
private void IsProductTrue()
{
if (add1 * add2 == product.Value)
{
product.Enabled = false;
}
}
private void IsQuotientTrue()
{
if (add1 / add2 == quotient.Value)
{
quotient.Enabled = false;
}
}
anyone have idea how to make it more efficient with just a method for all operation?
below is my idea, but to check the value is true for every NumericUpDown i don't know how.
private void DisableIfValueIsTrue()
{
foreach(Control control in this.Controls)
{
NumericUpDown value = control as NumericUpDown;
// if(value [NEED HELP]
}
}
Considering your situtaion, you can set a tag for each NumericUpDown in design mode like this:
sum.Tag=1;
square.Tag=2;
etc
Then define some int variables:
int iSum=add1+add2;
int iSquare= //Whatever you want
etc
And finally loop through your controls this way:
foreach (NumericUpDown control in this.Controls.OfType<NumericUpDown>())
{
int intCondition = Convert.ToInt32(control.Tag) == 1
? iSum
: Convert.ToInt32(control.Tag) == 2
? iSquare
: Convert.ToInt32(control.Tag) == 3
? i3
: i4; //You should extend this for your 8 controls
control.Enabled = intCondition == control.Value;
}
OK! Second way I offer
Since you will have to always check 8 different conditions, you could simply forget about looping through the controls and just change your method like this:
private void DisableIfValueIsTrue()
{
sum.Enabled = add1 + add2 != sum.Value;
difference.Enabled= add1 - add2 != difference.Value;
product.Enabled= add1 * add2 != product.Value;
quotient.Enabled= (add2 !=0) && (add1 / add2 != quotient.Value);
//etc
}
I came across this while doing some research and would like to give my solution I used for my situation and hope it helps people. I needed minimum and maximum numbers for a calculation, so mine are named appropriately and I correlated these with some CheckBoxes. I used null in beginning of minimum and end of maximum to account for empty. I also had to create an event handler SubscribeToEvents() shown below.
In my load event for my form:
SubscribeToEvents();
_checkBoxs = new[] { cbXLight, cbLight, cbMedium, cbHeavy, cbXHeavy, cbXXHeavy, cbXXXHeavy };
_minimumsNumericUpDowns = new[] { null, nLightMin, nMediumMin, nHeavyMin, nXHeavyMin, nXXHeavyMin, nXXXHeavyMin };
_maximumsNumericUpDowns = new[] { nXLightMax, nLightMax, nMediumMax, nHeavyMax, nXHeavyMax, nXXHeavyMax, null };
then I created a method:
private void DisableNumericUpDowns()
{
// disable everything:
foreach (var n in _minimumsNumericUpDowns)
{
if (n != null)
n.Enabled = false;
}
foreach (var n in _maximumsNumericUpDowns)
{
if (n != null)
n.Enabled = false;
}
}
The event handler:
private bool _eventsSubscribed;
private void SubscribeToEvents()
{
if (_eventsSubscribed)
return;
_eventsSubscribed = true;
cbXXHeavy.CheckedChanged += CheckBox_NumericState;
cbXHeavy.CheckedChanged += CheckBox_NumericState;
cbXLight.CheckedChanged += CheckBox_NumericState;
cbHeavy.CheckedChanged += CheckBox_NumericState;
cbLight.CheckedChanged += CheckBox_NumericState;
cbMedium.CheckedChanged += CheckBox_NumericState;
cbXXXHeavy.CheckedChanged += CheckBox_NumericState;
}
Now I can used this to check when they are enabled and if they are greater than or less than 0 if needed in the method CheckBox:
private void CheckBox_NumericState(object sender, EventArgs e)
{
// disable everything
DisableNumericUpDowns();
// see if more than one checkbox is checked:
var numChecked = _checkBoxs.Count((cb) => cb.Checked);
// enable things if more than one item is checked:
if (numChecked <= 1) return;
// find the smallest and enable its max:
var smallest = -1;
for (var i = 0; i < _checkBoxs.Length; i++)
{
if (!_checkBoxs[i].Checked) continue;
if (_maximumsNumericUpDowns[i] != null)
{
_maximumsNumericUpDowns[i].Enabled = true;
}
smallest = i;
break;
}
// find the largest and enable its min:
var largest = -1;
for (var i = _checkBoxs.Length - 1; i >= 0; i--)
{
if (!_checkBoxs[i].Checked) continue;
if (_minimumsNumericUpDowns[i] != null)
{
_minimumsNumericUpDowns[i].Enabled = true;
}
largest = i;
break;
}
// enable both for everything between smallest and largest:
var tempVar = largest - 1;
for (var i = (smallest + 1); i <= tempVar; i++)
{
if (!_checkBoxs[i].Checked) continue;
if (_minimumsNumericUpDowns[i] != null)
{
_minimumsNumericUpDowns[i].Enabled = true;
}
if (_maximumsNumericUpDowns[i] != null)
{
_maximumsNumericUpDowns[i].Enabled = true;
}
}
}
So I can check each state as required:
I want to check if Extra Light is check:
// Extra Light
if (!cbXLight.Checked) return;
if (nXLightMax.Enabled == false)
{
_structCategoryType = XLight;
CheckStructureSheets();
}
else
{
if (nXLightMax.Value > 0)
{
_dMax = nXLightMax.Value;
_structCategoryType = XLight;
CheckStructureSheets();
}
else
{
MessageBox.Show(#"Extra Light Max cannot be zero (0)");
}
}
and next light checks both:
// Light
if (cbLight.Checked)
{
if (nLightMin.Enabled == false && nLightMax.Enabled == false)
{
_structCategoryType = Light;
CheckStructureSheets();
}
else
{
if (nLightMin.Enabled && nLightMin.Value > 0)
{
if (nXLightMax.Enabled && nLightMin.Enabled && nLightMax.Enabled == false)
{
_dMin = nLightMin.Value;
_structCategoryType = Light;
CheckStructureSheets();
}
else
{
if (nLightMax.Value > 0)
{
_dMin = nLightMin.Value;
_dMax = nLightMax.Value;
_structCategoryType = Light;
CheckStructureSheets();
}
else
{
MessageBox.Show(#"Light Max cannot be zero (0)");
return;
}
}
}
else if (nLightMin.Enabled == false && nLightMax.Enabled)
{
if (nLightMax.Value > 0)
{
_dMax = nLightMax.Value;
_structCategoryType = Light;
CheckStructureSheets();
}
else
{
MessageBox.Show(#"Light Max cannot be zero (0)");
}
}
else
{
MessageBox.Show(#"Light Min cannot be zero (0)");
return;
}
}
}
Hope this helps someone.
Tim
thanks for #AlexJoliq and #BrettCaswell. just want to inform that before Alex edited his answer from using "==" to "!=", i (thought) already solved the problem. but i don't know where is the more effective and efficient way, alex's or mine.
below is my code for DisableIfValueIsTrue():
if (add1 + add2 == sum.Value) sum.Enabled = false;
if (add1 - add2 == difference.Value) difference.Enabled = false;
if (add1 * add2 == product.Value) product.Enabled = false;
if (add1 / add2 == quotient.Value) quotient.Enabled = false;