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
{
///
/// Interaction logic for UCManagePremixBatch.xaml
///
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" >
Ananthakrishna VPosted Aug 8, 2024, 11:43 AM
Can you please try this implementations,
1. Add a Column for Colors in the Database:
Since you mentioned that there isn't a column for colors in your database, you need to add one in the
[dbo].[Adr_Batch_Suite].[Premix_Control]table. You can do this by running an SQL command:2. Update Stored Procedure to Handle Color:
Assuming you have a stored procedure for inserting and updating data, you'll need to modify it to include the new
Colorcolumn. For instance:3. Save the Data in the Backend Code:
Modify your backend C# code to handle the saving of the color field. Update your
loadRecipeand other relevant methods:Trigger this method when the "Save" button is clicked:
4. Load and Prepopulate Fields:
When loading the recipe, ensure the color field is populated from the database:
In your XAML code, ensure that the
txtColortextbox is enabled for editing if necessary:5. Preview Button Logic:
When the Preview button is clicked, load the previously saved data into the form:
let me know if this helps!