So I have a WPF window. There are TextBoxes "Login" and "Ip Address" which are binded to "Login" and "IpAddress" properties. What I need is to save property Login into database as login#ipAddress.
I tried this, but it goes wrong:
public string Login
{
get { return _TModel.Login; }
set
{
if (value == _TModel.Login)
return;
_TModel.Login = value + "#" + IpAddress;
base.OnPropertyChanged("Login");
}
}
How can I do that? BTW I'm using NHibernate to work with the DB.
Thank you.
Replace # with "#":
public string Login
{
get { return _TModel.Login; }
set
{
if (value == _TModel.Login)
return;
value = string.Empty;
_TModel.Login = value + "#" + IpAddress;
base.OnPropertyChanged("Login");
}
}
Related
To be honest, I have no idea why the variable is being set to null. The object is set, then once I go through the DisplayPromptAsync, it sets the object to null.
I'm not sure what to try as I've never come across this issue.
Here's a gif of the issue. Once I enter into the field and press submit, an object gets reset.
async void OpenContainerItem()
{
// Pause the timer
blnTimerActive = false;
if (SelectedItem != null)
{
if (SelectedItem.intQuanChecked == SelectedItem.intQuantity)
return;
try
{
int intQuantity = 0;
// Ask for quantity
string result = await Application.Current.MainPage.DisplayPromptAsync("Quantity",
"How many " + SelectedItem.objItem.strItemName + " did you count?",
"Okay", cancel: "Cancel",
placeholder: "Quantity",
keyboard: Keyboard.Numeric);
// Check if it's been cancelled
if (result != null)
{
// check if theres nothing entered
if (result == "")
{
// Why tho?
await Application.Current.MainPage.DisplayAlert("Error", "Please enter a quantity.", "Okay");
}
else
{
intQuantity = int.Parse(result);
if (0 > ((SelectedItem.intQuantity - SelectedItem.intQuanChecked) - intQuantity))
{
Application.Current.MainPage.DisplayAlert("Error", "Thats too many items!", "Okay");
Reload();
blnTimerActive = true;
return;
}
modDatabaseUtilities.ContainerItemsPreCheck(SelectedItem.intContainerItemID, intQuantity, strCurrentUser);
Reload();
}
}
}
catch(Exception ex)
{
Application.Current.MainPage.DisplayAlert("Error", "Couldn't process this change. Please try again.", "Okay");
}
}
#ScottUphus - Is SelectedItem bound to a ListView? (If it is bound to anything, you should add that xaml in your question.) If so, then its a common problem: xamarin sets it back to null when the display layout is refreshed. (I'm not sure the exact "rule" for when it happens. In your case, I suspect the modal interaction causes this.)
This is how I solve such issues:
public MyItemType ValidSelectedItem { get; private set; }
public MyItemType SelectedItem
{
get => _SelectedItem;
set {
... your current setter code here ...
// Remember most recent non-null value.
if (value != null)
ValidSelectedItem = value;
}
}
private MyItemType _SelectedItem;
ValidSelectedItem remembers the non-null item, even if xamarin resets the selection back to null. Use it in code that needs that value.
Is there a difference in using "Okay" or "OK" in DisplayPromptAsync ? try to change it in your code.
this is default Page.DisplayPromptAsync Method:
public System.Threading.Tasks.Task<string> DisplayPromptAsync
(
string title,
string message,
string accept = "OK",
string cancel = "Cancel",
string placeholder = default,
int maxLength = -1,
Xamarin.Forms.Keyboard keyboard = default,
string initialValue = ""
);
public Login ClickGetStatus()
{
//IWebElement btnGetStatus = driver.FindElement(By.XPath("//*[contains(#id,'GetStatus')]"));
do
{
buttonName_GetStatus[0] = "abc";
Thread.Sleep(3000);
bool is_displayed =
wrapper.IsElementDisplayed(
driver.FindElement(By.XPath("//*[contains(#id,'GetStatus')]")));
//bool IsElementDisplayed = driver.FindElement(By.XPath("//*[contains(#id,'GetStatus')]")).Displayed;
if (is_displayed)
{
//wrapper.Click(btnExecute);
string getnameofbutton1 =
driver.FindElement(
By.XPath("//*[contains(#id,'GetStatus')]")).GetAttribute("id");
Console.WriteLine("Name of the button is : " + getnameofbutton1);
buttonName_GetStatus = getnameofbutton1.Split('_');
driver.FindElement(
By.XPath("//*[contains(#id,'GetStatus')]")).Click();
}
else
{
Console.WriteLine("Element is not displayed");
}
}
while (buttonName_GetStatus[0] == "GetStatus");
return this;
}
Below is the Logic for the above code
Checks for the button called Get Status
if it finds the button Get Status then clicks on it
i have used contains in the xpath as the element id for that button changes dynamically.
The above code runs fine and clicks on the Get Status button but doesn't come out from the loop when the name of the Get Status button changes to View Result and still searches for Get Status button
If the expected ID of the button after being updated is "ViewResult", then you can update your condition to use that.
while (buttonName_GetStatus[0] != "ViewResult");
This will keep looping round whilst the button does not equal "ViewResult".
Is this the behavior you're trying to achieve?
public Login ClickGetStatus()
{
//IWebElement btnGetStatus = driver.FindElement(By.XPath("//*
[contains(#id,'GetStatus')]"));
do
{
buttonName_GetStatus[0] = "abc";
Thread.Sleep(3000);
var elements = driver.FindElements(By.XPath("//*[contains(#id,'GetStatus')]"));
var is_displayed = elements.Count > 0;
//bool IsElementDisplayed = driver.FindElement(By.XPath("//*[contains(#id,'GetStatus')]")).Displayed;
if (is_displayed)
{
//wrapper.Click(btnExecute);
string getnameofbutton1 =
driver.FindElement(
By.XPath("//*[contains(#id,'GetStatus')]")).GetAttribute("id");
Console.WriteLine("Name of the button is : " + getnameofbutton1);
buttonName_GetStatus = getnameofbutton1.Split('_');
driver.FindElement(
By.XPath("//*[contains(#id,'GetStatus')]")).Click();
}
else
{
Console.WriteLine("Element is not displayed");
}
}
while (buttonName_GetStatus[0] != "ViewResult");
return this;
}
I think problem might be here, especially when you check if isDisplayed == true then this line buttonName_GetStatus = getnameofbutton1.Split('_'); overrides array so that infinitive loop appeared.
I have this code where I compare the values of oldState object by the currentState in fluent inhibernate, what I want is to log the property that has been changed and its value,here I get the new and the old values but I waant also to get the property name.
if I reflect #event.Entity I can get all the properties and their values so is there any way to get the property name by its value.
public void OnPostUpdate(NHibernate.Event.PostUpdateEvent #event)
{
var entityToAudit = #event.Entity as IAuditable;
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AuditLog.txt");
using (StreamWriter sw = File.AppendText(path))
{
for (int i = 0; i < #event.OldState.Length; i++)
{
if (#event.OldState[i] != null)
{
if (!#event.OldState[i].Equals(#event.State[i]))
{
sw.WriteLine("the value has ben changed from " + #event.OldState[i] + " to " + #event.State[i]);
}
}
else
{
if (#event.State[i] != null)
{
sw.WriteLine("the value has ben changed from being empty to " + #event.State[i]);
}
}
}
}
}
You don't need to use System.Reflection for that. PostUpdateEvent already contains all the property names in the order you need :
var propertyName = e.Persister.PropertyNames[i];
I'm working on a quote manager for my boss at work and I'm having some issues. This is a WPF C# application and it's the first time I've ever built anything that works with a SQL Server database. I'm currently having three issues.
Background:
When the user opens the application they're greeted with a DataGrid, a new quote button and several other controls that I haven't yet created. When they press the new quote button a new window pops up with a form that will have text boxes for things like Customer Name, quantity, etc. At the bottom of that form is a submit button, at which point the window will close and the information they added will be inserted into the DataGrid as a new row.
Problem One:
One of the fields in my database is called Open_Quote and it is supposed to be hold the date we received the order. This is handled programmatically and is what my first question involves. I'll include all of the code at the bottom of this post, but when the user hits submit I receive the following error: "Conversion failed when converting date and/or time from character string."
Problem Two:
In an attempt to test the rest of my code and go back later to fix the date issue, I commented that code out and tried running my program again. This time I get a different error: "Incorrect syntax around 'newQuote.Qty'."
Problem Three:
Again, commenting that code out in order to finally test the rest of my code, I received a third error: "string or binary data would be truncated. This process has been terminated."
My hope is that there's one piece of code that's causing all three of these issues, but I could be completely off there. I've been pulling my hair out for over a day trying to figure this out. Anyway, here's the code:
newQuote.xaml.cs:
private void SubmitQuotebtn_Click(object sender, RoutedEventArgs e)
{
CustomerData newQuote = new CustomerData();
int quantity;
quantity = Convert.ToInt32(Qtytxt.Text);
string theDate = System.DateTime.Today.Date.ToString("d");
newQuote.OpenQuote = theDate;
newQuote.CustomerName = CustNametxt.Text;
newQuote.OEMName = OemNametxt.Text;
newQuote.Qty = quantity;
newQuote.QuoteNumber = QuoteNumtxt.Text;
newQuote.FdNumber = FabDrawingNumtxt.Text;
newQuote.RfqNumber = RfqNumtxt.Text;
newQuote.RevNumber = RevNumtxt.Text;
try
{
string insertConString = Sqtm.Properties.Settings.Default.SqtmDbConnectionString;
using (SqlConnection insertConnection = new SqlConnection(insertConString))
{
insertConnection.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO General_Info(Open_Quote, Customer_Name, OEM_Name, Qty, Quote_Num, Fab_Drawing_Num, "
+ "Rfq_Num, Rev_Num) values('newQuote.OpenQuote', 'newQuote.CustomerName', 'newQuote.OemName', 'newQuote.Qty' "
+ "'newQuote.QuoteNumber', 'newQuote.FdNumber', 'newQuote.RfqNumber', 'newQuote.RevNumber')", insertConnection);
cmd.ExecuteNonQuery();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
CustomerData.cs:
class CustomerData
{
private string _CustomerName;
private string _OEMName;
private string _OpenQuote;
private int _Qty;
private string _QuoteNumber;
private string _FdNumber;
private string _RfqNumber;
private string _RevNumber;
public CustomerData()
{
// empty constructor
}
public string CustomerName
{
get { return _CustomerName; }
set { _CustomerName = value; }
}
public string OpenQuote
{
get { return _OpenQuote; }
set { _OpenQuote = value; }
}
public string OEMName
{
get { return _OEMName; }
set { _OEMName = value; }
}
public int Qty
{
get { return _Qty; }
set { _Qty = value; }
}
public string QuoteNumber
{
get { return _QuoteNumber; }
set { _QuoteNumber = value; }
}
public string FdNumber
{
get { return _FdNumber; }
set { _FdNumber = value; }
}
public string RfqNumber
{
get { return _RfqNumber; }
set { _RfqNumber = value; }
}
public string RevNumber
{
get { return _RevNumber; }
set { _RevNumber = value; }
}
}
And as a reference, here's how I set up this table in SQLServer:
Open_Quote, date, not null
Customer_Name, varchar(25), not null
OEM_Name, varchar(25), null
Qty, int, not null
Qute_Num, varchar(20), null
Fab_Drawing_Num, varchar(20), not null
Rfq_Num, varchar(10), null
Rev_Num, varchar(10), null
Thanks in advance to anyone who helps me out,
Andrew
Try again with parameters and let us know how it goes.
http://www.dotnetperls.com/sqlparameter
Edit: Or what Tieson T. said. That'd be even better just a little more involved.
To get the data to show in the datagrid, after you do the insert, you can rebind the grid. Make sure your update the datasource so it repulls the data you just inserted. If you have problems, show where/how you are setting the datasource for the grid.
Try this:
SqlCommand cmd = new SqlCommand("INSERT INTO General_Info(Open_Quote, Customer_Name, OEM_Name, Qty, Quote_Num, Fab_Drawing_Num, "
+ "Rfq_Num, Rev_Num) values('" + newQuote.OpenQuote + "','" + newQuote.CustomerName + "','" + newQuote.OemName + "','" + newQuote.Qty + "','" + newQuote.QuoteNumber + "','" + newQuote.FdNumber + "', '" + newQuote.RfqNumber + "','" + newQuote.RevNumber + "' "
+ " )", insertConnection);
I'm creating a simple composite control that has AJAX functionality. When trying to implement a MaskedEditValidator, the DisplayMoney property doesn't work. The MaskedEdit renders, without the dollar sign attached. Any ideas? Here's my code:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
priceTextbox.ID = this.ID + "_price";
quantityTextbox.ID = this.ID + "_quantity";
timeTextbox.ID = this.ID + "_time";
submitButton.ID = this.ID + "_submit";
submitButton.Text = "Submit";
priceMask.TargetControlID = priceTextbox.ClientID.ToString();
priceMask.ID = priceMask.TargetControlID.ToString() + "_extender";
priceMask.BehaviorID = "priceMaskExtender";
priceMask.Mask = "99.99";
priceMask.DisplayMoney = MaskedEditShowSymbol.Left;
}
Try adding the following line:
priceMask.MaskType = MaskedEditType.Number;
Optionally, set ClearMaskOnLostFocus to false if that is the behavior you want (it keeps the dollar sign even when not focused).
The DisplayMoney property setter only sets the property if MaskType is equal to MaskedEditType.Number.
set
{
if (MaskType == MaskedEditType.Number)
{
SetPropertyValue("DisplayMoney", value);
}
}
The DisplayMoney property setter only sets the property if MaskType is equal to MaskedEditType.Number.
set
{
if (MaskType == MaskedEditType.Number)
{
SetPropertyValue("DisplayMoney", value);
}
}
So you need to set:
priceMask.MaskType = MaskedEditType.Number;