How to update cell value at infragistics at method beforecellupdate - c#

I'm using an Infragistics UltraGrid and I have a table where the first column is a Double field, I use a dll NCalc.Expression so the user can input a formula and get a double value, of course only if it is a valid formula. The problem is on method beforeCellUpdate, I can't change the value to the value generated by the evaluate method from NCalc.Expression. I tried to store the new value as a class variable and then update the value at afterCellUpdate method but then I get a Data Error - data error due to formula being not a double but a string, input not valid
What does this mean? And how can it be fixed?

After all night I use the method berofeExitEditMode, that way I evaluate the input formula, if its not valid cancel the event, if the formula its correct, then change the value for the generated value.
It worked so far.
IF anyone knows a better way it would be much appreciated

You may check this article where is shown how you can validate the user's input "Validate User Input"

Related

Testing database field types for compatibility

I have some generic database routines. One that I make use of quite frequently is based on code similar to this code, but for an OleDbDataReader, not the generic IDataReader from that code.
I was playing around with this, and decided to test what would if I tried to (say) retrieve a value from a field, where I had input the incorrect type. Eg: I try to get a double value from a database column that is actually an integer:
reader.GetValue<double>("Column_that_is_Integer_Type");
...and, unexpectedly, it seamlessly converts the database column integer value to a double. Hmm. OK - I get a usable value back, but what about other conversions?
reader.GetValue<bool>("Column_that_is_Integer_Type");
This returns true. Not exactly what I want, and I get no error.
reader.GetValue<DateTime>("Column_that_is_Integer_Type");
This one at least throws an InvalidCast Exception.
Because of all this, I added the follow type checks to the code:
if (theReader.GetFieldType(fieldIndex) == typeof(T))
{
//Carry on...
}
else
{
//Raise an error
}
I think this is the safest way of preventing issues, but was wondering if there is a somewhat 'generic' compatibility check that can be performed? My onward use of a given variable probably won't care whether '39.5' retrieved from a database that stores it as a double is passed around as a decimal, but it will certainly care if it is being passed around as a bool.
My default position will be to throw an error if someone gets the column data type wrong, but I was interested enough to ask the question: Is there a robust method for checking whether type conversions preserve appropriate data integrity?
Eg. Integer type converted to Double: OK. Double converted to Integer: Nope.
Double type converted to Decimal: OK. Double converted to DateTime: Nope.
I think I've answered my own question, but interested in opinions.

Devexpress Gridview how get row value in decimal type cell?

I have a grid control and I wanna get the value of the selected row. I could get the value of varchar type cell in row but I'm having trouble in getting the value for cell in decimal type.
Here's my code for every row click:
private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
{
var productPrice = Convert.ToDecimal(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "product_price").ToString());
MessageBox.Show(productPrice.ToString());
}
For more info the product_price column is set to be in decimal type with length of (10,2) so the value its displaying is like 13,233.00
Thank you I hope you can help me to solve this problem
My first thought: Is there no focused row? Add this and see if it fixes the issue:
if (gridView1.SelectedRowsCount == 0)
return;
That wasn't the issue? Okay, add this to your code and set a breakpoint:
object o = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "product_price");
Type t = o.GetType();
When you add a watch (or hover) over t, does it say System.Decimal or String?
If it's a decimal, you should be in good shape, and what I would suggest is to just change the code to the following:
var productPrice = Convert.ToDecimal(gridView1.GetRowCellValue(
gridView1.FocusedRowHandle, "product_price"));
The only thing I omitted was the ToString(), so we can let the Convert function apply against the (raw) object. I don't know how or why, and it actually seems like a long shot, but maybe ToString() is formatting the output in accordance with the grid display.
I'm guessing that is not the case, and your original supposition is correct in that the data coming from MySQL is actually formatted as a string, or your C# code is reading it as a string. If this is the case, run the actual SQL and see what datatype is being rendered. Is it numeric? If so, is your C# reading it as numeric (reader.GetDecimal(x)) or, perhaps is there a reader.GetValue(x).ToString() that is ignoring datatypes?
In other words, is MySQL adding the formatting and sending a string, or is your C# changing a decimal to a string? Find out what's doing that and put a stop to it.
You can certainly unformat the string and then convert to a decimal, but that seems like a long, LONG path to your end goal.

How to get Test variable through custom code in HP UFT - ApiTest

I want to set value to the Test Variable using Custom Code.
Can you tell me how to do it as i am not able to access the variable from code.
I need to access the User Variable URL in my custom code and set the value.
Please help me if you know how to do it using Custom Code.
Thanks,
Madhan
Based on your question:
1. Click on File menu and then Settings, it will open Properties pane.
2. Click on "+" to add user variable and give a name.
3. In your custom code, type below code:
string s = "https://www.google.com/";
this.Context.TestProfile.SetVariableValue("NameOfYourVariable",s);
To retrieve the value of given variable:
string ss = this.Context.TestProfile.GetVariableValue("NameOfYourVariable");
CodeActivity5.Report("Variable is : ", ss); //(This line will print your variable value)
answer provided here is valid when the need is to set string values. The "SetVariableValue" method takes two "String" type parameters. This limits the ability to set Int32 type variables. Obviously, C# throws an error when trying to set an integer value.
Now, an integer value is particularly useful while setting values for loop iterations. I am not sure whether this is a limitation of the tool or whether my lack of knowledge. So, to work around this, i used the output property of custom code activity. To do this, create a custom code activity and create an output property of the desired type, say Int. Now, assign a value to this output property using the line:
this.ActivityName.Output.property name = property value
This is available in UFT help and can be useful while trying to pass values other than string between different activities in a flow.

Add .00 to an int number using javascript

Is it possible say a person enters an integer value 5 in a Textbox and automaticall a .00 is added in the end say 5.00
<asp:TextBox ID="txtAmountTransfer" runat="server" Width="55%" CssClass="right"></asp:TextBox>
You can use .toFixed(2) which will add the zero's
see this for an example js Fiddle
#CR41G14 is correct. .toFixed(2) is all you need.
As far as where and how, I would recommend using the change event on the input box as it is the least intrusive for the user. (The blur event would also not be unreasonable)
Since the value of the text field will be a string you will need to parse it as #Snuffleupagus points out. In your case, I would recommend parseFloat because then your field could potentially handle the user entering 5.2 which could become 5.20. (using parseInt you would end up with 5.00).
One additional note is recognizing that if the user types non-numeric characters (or really any value that will not parse) into the field, it will result in a display of NaN, which actually seems fairly reasonable in your case.
Using jQuery:
$('#txtAmountTransfer').change(function(){
$(this).val(parseFloat($(this).val()).toFixed(2))
});
Similar example using native code:
var textField = document.getElementById('txtAmountTransfer');
textField.onchange = function(){
this.value = parseFloat(this.value).toFixed(2);
}

Milliseconds missing when getting a DateTime value from Excel using .Net Interop

If I put a DateTime value into an Excel cell using Range.set_value through .Net COM Interop, and then retrieve the value of that same cell using Range.get_value, the Millisecond part of the value is not returned, though everything else is correct.
Is this a bug?
What is the workaround? I'm guessing that using the Value2 property instead might help. Has anybody else tried this?
If you set a date/time with a millisecond value in Excel manually, does it maintain it? I don't know about the Excel internal object model, but it's conceivable that it just doesn't support milliseconds.
EDIT: Okay, now we know that the set fails (the get may also fail, of course)... you could try setting it as a double after converting it via DateTime.ToOADate(). I'm not saying I'm holding out much hope, but it's worth a try...
As Jon suggested, converting the DateTime to a double using DateTime.ToOADate (then back again using DateTime.FromOADate) works if you set the value using the Range.Value2 property.
The only trouble with this property is that, if you don't already know, it doesn't tell you that the cell is supposed to be treated as a DateTime. I guess to solve this, you'd need to use a two-pass approach: get cell values using Range.get_Value to determine their type, then, for any DateTime cells, get their values again using Range.Value2, then convert using DateTime.FromOADate.
It's probably because of the issue described in this KB article.
In which case, setting the Value2 property should work.

Categories