Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 480.4k

How to fetch date colum from the back end in wpf?

Jul 17 2024 4:37 PM

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

<Label x:Name="lblDate" FontWeight="SemiBold" Visibility="Visible" Content="Date:" HorizontalAlignment="Left" VerticalAlignment="Top" Width="179" HorizontalContentAlignment="Right" Background="#FFE3E3E3" Margin="20,60,0,0" BorderThickness="1" BorderBrush="#FFBEBEBE"/>
        <TextBox x:Name="DateTextBox" FontSize="10" Foreground="Black" HorizontalAlignment="Left" Visibility="Visible" Height="26" Margin="205,60,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="210" RenderTransformOrigin="1.19,-3.084" Text="{Binding Date, UpdateSourceTrigger=PropertyChanged, StringFormat=d}"/>

// 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>(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;
    }
}

 


Answers (1)