Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 480.4k

How to save fields to the table and prepopulate them to next window?

Aug 8 2024 6:16 AM

Hi Team

I have this front end fields and will share my code, basically need to find a way when the recipes loads. I need to find each product its specific color for that but it must be pulled from the database, i dont have the column for colors. Then i must be able to save these fields to the table. [dbo].[Adr_Batch_Suite].[Premix_Control], so that when i click Preview button, i can able to see these saved fields in this window, so far already this loads window pop up screen but not saving them need help on this. But the saved fields must be able to view on this form. Help me on my current logic. I will share back end first code, followed by front end. 

 

// Store procedure for dynamic queries

//Managers class access the entities(uses store procedures these entities from the database)
  


public static DataTable GetRecipeIngredients(int recipeID, string productAllocation, int NoPremix)
        {
            Managers.BatchMaterialManager.SetAdriotConnection();
            return DataAccessProvider.GetDataTable(PremixBatch.PROC_NAME_GET, new object[] { "Calculate", null, null, recipeID, productAllocation, NoPremix });
        }


//Entities class uses store proc
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Feedmill_Weighbridge.Entities
{
    public class PremixBatch
    {
        public const string PROC_NAME_GET = "[dbo].[spGetPremixBatch]";
        // public const string PROC_NAME_STORE = "[quality].[spStorePellet]";


        //string _Description;
        // string _BatchSize;
        //string _ProdCode;
        public PremixBatch()
        {
        }
        // int _IDX;
        //string _RecCode;
        string _RecDesc;
        string _ProdCode;
        int _TotalWeight;


        public string ProdCode
        {
            get
            {
                return _ProdCode;
            }
            set
            {
                _ProdCode = value;
            }
        }

        public string RecDesc
        {
            get
            {
                return _RecDesc;
            }

            set
            {
                _RecDesc = value;
            }
        }

        public int TotalWeight
        {
            get
            {
                return _TotalWeight;
            }

            set
            {
                _TotalWeight = value;
            }
        }



    }
}


//Presenter class handles cs logic
  // ingredients for the combo box.
        public void PopulateComboBox()
        {
            Managers.BatchMaterialManager.SetAdriotConnection();

            var Recipes = Managers.PremixBatchManager.GetProdCode();

            Recipes.DefaultView.Sort = "idx";
            View.ComboProdCode.ItemsSource = null;
            View.ComboProdCode.ItemsSource = Recipes.DefaultView;

            View.ComboProdCode.DisplayMemberPath = "ProdCode";
            View.ComboProdCode.SelectedValuePath = "idx";
            View.ComboProdCode.SelectedIndex = 1;
        }


 public void loadRecipe(int recipeID)
        {
            var Premix = new Entities.PremixBatch();
            Managers.BatchMaterialManager.SetAdriotConnection();
            Premix = Managers.PremixBatchManager.GetBatchRecipeByPK(recipeID);

            if (Premix != null)
            {
                var FeedRecipe = Managers.PremixBatchManager.GetFeedRecipeByRecipeName(Premix.ProdCode);

                //  View.IDX = Recipe.IDX;
                View.Description = Premix.RecDesc;
                View.BatchSize = Premix.TotalWeight.ToString();



            }

        }

// presentation class handles relationship between ui and back end

using Feedmill_Weighbridge.Presenter;
using Feedmill_Weighbridge.View;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Feedmill_Weighbridge.Presentation
{
    /// <summary>
    /// Interaction logic for UCManagePremixBatch.xaml
    /// </summary>
    public partial class UCManagePremixBatch : UserControl, IPremixBatch
    {
        public ManagePremixBatchPresenter presenter;
        //private string _cbxRecipe;
        private ComboBox _cbxRecipe;
        public UCManagePremixBatch()
        {
            InitializeComponent();
            presenter = new ManagePremixBatchPresenter(this);
        }
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            LoadControl();

        }
        public void LoadControl()
        {
            Managers.BatchMaterialManager.SetDefaultConnection();

            presenter.PopulateComboBox();
            //CollectionViewSource _StockCodeList = new CollectionViewSource();
            //_StockCodeList = (CollectionViewSource)this.FindResource("StockCode");

            //CollectionViewSource _OTPStockCodeList = new CollectionViewSource();
            //_OTPStockCodeList = (CollectionViewSource)this.FindResource("OTPStockCode");

            // presenter.PopulateGrid();
            Properties.Settings.Default.Process = "Premix Batch";
        }
        #region Properties

      

        public ComboBox ComboProdCode
        {
            get
            {
                return cbxProductCode;
            }
            set
            {
                cbxProductCode = value;
            }
        }


        //premix batch number from combo box.
        public ComboBox ComboBatchNum
        {
            get { return _cbxRecipe; }
            set { _cbxRecipe = value; }
        }

       
        public string Description
        {
            get
            {
                return txtDescription.Text;
            }
            set
            {
                txtDescription.Text = value;
            }
        }
        public string BatchSize
        {
            get
            {
                return txtBatchSize.Text;
            }
            set
            {
                txtBatchSize.Text = value;
            }
        }

        #endregion

        #region Events
        private void cbxProductCode_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            LoadRecipe();

        }
        private void btnRefresh_Click(object sender, RoutedEventArgs e)
        {
            //dgvMicroMaterialData.Visibility = Visibility.Visible;
            //presenter.PopulateGrid(Convert.ToInt32(txtNoPremix.Text));

            frmPremixPostData dt = new frmPremixPostData();

            dt.ShowDialog();
        }
        //Printevent
        private void btnRefresh_Copy_Click(object sender, RoutedEventArgs e)
        {
           
        }
        //Clear Event
        private void btnRefresh_Copy1_Click(object sender, RoutedEventArgs e)
        {
            Clear();
        }
        #endregion

        #region Methods
        public void LoadRecipe()
        {

            Managers.BatchMaterialManager.SetAdriotConnection();

            presenter.loadRecipe(Convert.ToInt32(cbxProductCode.SelectedValue));
            //  presenter.PopulateGrid();

        }


        public void Clear()
        {
            txtNoPremix.Text = string.Empty;
            //dgvMicroMaterialData.Visibility = Visibility.Hidden;
        }

        #endregion


    }
}

// front end fields

         mc:Ignorable="d"  Loaded="UserControl_Loaded" >
    <Grid Background="White" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
        <Grid VerticalAlignment="Top" Height="489" Margin="0,-2,7,0"  >
            <Label Content="Premix Batch Management" BorderThickness="1.5" BorderBrush="#FF0B0B0B" Background="#FF383838" Foreground="White" FontSize="18" HorizontalContentAlignment="Center" VerticalAlignment="Top" Margin="10,10,10,0" FontWeight="SemiBold" />

            <Label x:Name="lblDriverName_Copy" FontWeight="SemiBold" Visibility="Visible" Content="Product Code:" HorizontalAlignment="Left" VerticalAlignment="Top" Width="179" HorizontalContentAlignment="Right" Background="#FFE3E3E3" Margin="17,56,0,0" BorderThickness="1" BorderBrush="#FFBEBEBE"/>
            <ComboBox x:Name="cbxProductCode" TabIndex="1" IsTextSearchEnabled="True"   IsEditable="True"    IsTextSearchCaseSensitive="False"  Foreground="Black" HorizontalAlignment="Left" Margin="207,57,0,0" VerticalAlignment="Top" Width="214" SelectionChanged="cbxProductCode_SelectionChanged">
                <ComboBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel />
                    </ItemsPanelTemplate>
                </ComboBox.ItemsPanel>
            </ComboBox>
            <Label x:Name="lblDriverName_Copy1" FontWeight="SemiBold" Visibility="Visible" Content="Product Description:" HorizontalAlignment="Left" VerticalAlignment="Top" Width="179" HorizontalContentAlignment="Right" Background="#FFE3E3E3" Margin="17,85,0,-29" BorderThickness="1" BorderBrush="#FFBEBEBE"/>
            <TextBox x:Name="txtDescription" FontSize="10" Foreground="Black" HorizontalAlignment="Left" IsReadOnly="True" Visibility="Visible" Height="26" Margin="209,82,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="209" RenderTransformOrigin="1.19,-3.084"/>
            <Label x:Name="lblDriverName_Copy2" FontWeight="SemiBold" Visibility="Visible" Content="Batch Size:" HorizontalAlignment="Left" VerticalAlignment="Top" Width="179" HorizontalContentAlignment="Right" Background="#FFE3E3E3" Margin="17,113,0,-31" BorderThickness="1" BorderBrush="#FFBEBEBE"/>
            <TextBox x:Name="txtBatchSize" FontSize="10" Foreground="Black" HorizontalAlignment="Left" IsReadOnly="True" Visibility="Visible" Height="26" Margin="209,111,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="210" RenderTransformOrigin="1.19,-3.084"/>
            <Label x:Name="lblColors" FontWeight="SemiBold" Visibility="Visible" Content="Colors:" HorizontalAlignment="Left" VerticalAlignment="Top" Width="179" HorizontalContentAlignment="Right" Background="#FFE3E3E3" Margin="17,142,0,-29" BorderThickness="1" BorderBrush="#FFBEBEBE"/>
            <TextBox x:Name="txtColor"   IsEnabled="False"    FontSize="10" Foreground="Black" HorizontalAlignment="Left" IsReadOnly="True" Visibility="Visible" Height="26" Margin="207,140,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="214" RenderTransformOrigin="1.19,-4.084"/>
            <Label x:Name="lblDate" FontWeight="SemiBold" Visibility="Visible" Content="Date:" HorizontalAlignment="Left" VerticalAlignment="Top" Width="179" HorizontalContentAlignment="Right" Background="#FFE3E3E3" Margin="17,172,0,-29" BorderThickness="1" BorderBrush="#FFBEBEBE"/>
            <DatePicker x:Name="dpDate" HorizontalAlignment="Left" Margin="207,173,0,0" VerticalAlignment="Top" Width="214" Foreground="Black">
            <DatePicker.Resources>
                <Style TargetType="TextBox">
                    <Setter Property="Foreground" Value="Black"/>
                </Style>
            </DatePicker.Resources>
            </DatePicker>

             
            <Label x:Name="lblDriverName_Copy3" FontWeight="SemiBold" Visibility="Visible" Content="NO. OF PREMIX PACKS MADE :" HorizontalAlignment="Left" VerticalAlignment="Top" Width="179" HorizontalContentAlignment="Right" Background="#FFE3E3E3" Margin="478,54,0,0" BorderThickness="1" BorderBrush="#FFBEBEBE"/>
            <TextBox x:Name="txtNoPremix" FontSize="10" Foreground="Black" HorizontalAlignment="Left"  Visibility="Visible" Height="26" Margin="665,55,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="210" RenderTransformOrigin="1.19,-3.084"/>
            <Label x:Name="lblWeight" FontWeight="SemiBold" Visibility="Visible" Content="Weight per Premix :" HorizontalAlignment="Left" VerticalAlignment="Top" Width="179" HorizontalContentAlignment="Right" Background="#FFE3E3E3" Margin="478,94,0,0" BorderThickness="1" BorderBrush="#FFBEBEBE"/>
            <TextBox x:Name="txtWeight"  IsEnabled="False"     FontSize="10" Foreground="Black" HorizontalAlignment="Left"  Visibility="Visible" Height="26" Margin="665,95,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="210" RenderTransformOrigin="1.19,-3.084"/>
            <Button x:Name="btnRefresh" Click="btnRefresh_Click" BorderBrush="Green" Height="22" FontWeight="SemiBold" FontSize="12" VerticalAlignment="Top" Background="Green"  Width="100" HorizontalAlignment="Left" Margin="762,180,0,0" >
                <StackPanel Orientation="Horizontal">
                    <materialDesign:PackIcon Kind="Refresh"/>
                    <TextBlock Text="Preview" VerticalAlignment="Top" FontSize="10"/>
                </StackPanel>
            </Button>
            <Button x:Name="btnRefresh_Copy" Click="btnRefresh_Copy_Click" BorderBrush="Green" Height="22" FontWeight="SemiBold" FontSize="12" VerticalAlignment="Top" Background="Green"  Width="100" HorizontalAlignment="Left" Margin="631,180,0,0" >
                <StackPanel Orientation="Horizontal">
                    <materialDesign:PackIcon Kind="Refresh"/>
                    <TextBlock Text="Save" VerticalAlignment="Top" FontSize="10"/>
                </StackPanel>
            </Button>
            <Button x:Name="btnRefresh_Copy1" Click="btnRefresh_Copy1_Click" BorderBrush="Red" Height="22" FontWeight="SemiBold" FontSize="12" VerticalAlignment="Top" Background="Red"  Width="100" HorizontalAlignment="Left" Margin="500,180,0,0" >
                <StackPanel Orientation="Horizontal">
                    <materialDesign:PackIcon Kind="Refresh"/>
                    <TextBlock Text="Clear" VerticalAlignment="Top" FontSize="10"/>
                </StackPanel>
            </Button>

        </Grid>
    </Grid>
</UserControl>

 


Answers (1)