Hi Team
I am trying to fetch date column, im using entity from Manager uses class has a store proc(this has a table in the table). Here is my logic below. The problem with this code i only get the current DateTime, this logic is not correct it must pull from the table then users must not edit the date in UI.
// xaml code
// xaml cs code
// view class
public DateTime Date
{
get
{
DateTime date;
if (DateTime.TryParse(DateTextBox.Text, out date))
{
if (date != DateTime.MinValue)
{
return date;
}
}
return DateTime.Now;
}
set
{
DateTextBox.Text = value.ToString("M/d/yyyy");
}
}
// method must use to get this column uses store proc
public void GetDateForBatch(int batchNumber)
{
Managers.PremixControlManager.SetAdriotConnection();
var controlSheet = Managers.PremixControlManager.GetPremixControlByPK(batchNumber);
if (controlSheet != null)
{
View.Date = controlSheet.Date;
}
else
{
View.Date = DateTime.MinValue;
}
}
// class fetches store proc from the DB
class PremixControlManager
{
//get primary key from the table.
public static PremixControl GetPremixControlByPK(int batchID)
{
return DataAccessProvider.GetEntity(PremixControl.PROC_NAME_GET,new object[] { "PK", batchID, null, null, null, null, null, null, null, null, null }
);
}
// interface
public interface IPremixBatch {
DateTime Date { get; set; }
}
// presenter
public void GetDateForBatch(int batchNumber)
{
Managers.PremixControlManager.SetAdriotConnection();
var controlSheet = Managers.PremixControlManager.GetPremixControlByPK(batchNumber);
if (controlSheet != null)
{
View.Date = controlSheet.Date;
}
else
{
View.Date = DateTime.MinValue;
}
}
Abhishek YadavPosted Jul 18, 2024, 3:30 AM
To ensure that the date is correctly fetched from the database and not editable by users in the UI, you need to bind the date property from your database to the
TextBoxwithout allowing user input. Additionally, make sure your data fetching logic is correctly implemented.Here’s how you can revise your code:
TextBoxread-only.XAML Code
Update the
TextBoxto make it read-only:View Class
Ensure that the
Dateproperty in the view class is correctly set:Method to Fetch Date
Update your method to correctly fetch and set the date:
PremixControlManager Class
Ensure the
PremixControlManagercorrectly fetches data from the stored procedure:IPremixBatch Interface
Ensure your interface correctly defines the
Dateproperty:Presenter Class
Your presenter class method to fetch and set the date:
Summary
With these adjustments, the
DateTextBoxwill be read-only, and the date will be correctly fetched from the database using your stored procedure. The users will not be able to edit the date directly in the UI, ensuring the integrity of the data displayed.If this solution works for you, please accept the answer to help others who might have the same question!