Cependant dans ma boucle je fais également une somme d'une quantité que je souhaite afficher dans un label, contrairement à avant ce n'est qu'une somme de toutes les opérations., la valeur n'est plus dans la liste.
C'est l'avant dernière ligne avec le Binding strTotaux
J'aimerais remplir une variable strTotaux, qui n'a plus rien à avoir avec ma liste et afficher son contenu
Dans mon cas j'ai des données qui s'affichent si je fais une variable strTotaux dans ma classe mais du coup il ne m'affiche que la valeur de strTotaux de la classe du 1er enregistrement de la liste donc rien n'est encore additionné.
Comment procéder ? merci
- Edité par Fellerson 15 septembre 2017 à 16:10:02
Mon code C# : (j'ai mis en commentaire dans la boucle ou je fais les actions)
public partial class MainWindow : Window
{
public ObservableCollection<CL_Operation> lstOperationsTemp = new ObservableCollection<CL_Operation>();
public List<string> lstSelectedLignesChoisi = new List<string>();
public List<string> lstSelectedIlotsChoisi = new List<string>();
public List<string> lstPostesTravailChoisi = new List<string>();
DispatcherTimer dtTimer = new DispatcherTimer();
DataTable dtOps = new DataTable();
DataView dvOps = new DataView();
Thread thrGetList;
string connectionString = "Data Source=SERVER\\INSTANCE;Initial Catalog=DB;Integrated Security=True";
string strOrderBy;
string strResultTri;
string strWhere;
string strWhereLigne;
string strWhereIlot;
string strWherePosteTravail;
int iTimer = 30;
public MainWindow()
{
InitializeComponent();
dtTimer.Tick += new EventHandler(timer_Tick);
dtTimer.Interval = new TimeSpan(0, 0, 1);
//dtTimer.Start();
thrGetList = new Thread(GetList);
thrGetList.Start();
}
public CL_Operation clOp { get; set; }
public void GetList()
{
dvOps = dtOps.DefaultView;
Application.Current.Dispatcher.Invoke(new Action(() => lstOperationsTemp.Clear()));
dtOps.Clear();
string strQueryDatas;
SqlConnection con = new SqlConnection(connectionString);
strQueryDatas = "SELECT * FROM [DB].[dbo].[VIEW] " + strWhere + " " + strOrderBy;
SqlDataAdapter adOps = new SqlDataAdapter(strQueryDatas, con);
adOps.Dispose();
try
{
con.Open();
SqlCommand sqlCmd = new SqlCommand(strQueryDatas, con);
sqlCmd.CommandTimeout = 500;
adOps.SelectCommand = sqlCmd;
adOps.Fill(dtOps);
adOps.Dispose();
sqlCmd.Dispose();
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
DateTime dtNow = DateTime.Now;
double dblTotalQte = 0;
double dblTotalOp = 0;
double dblTotalTemps=0;
for (int i = 0; i < dvOps.Count; i++)
{
clOp = new CL_Operation();
clOp.strWidth = Convert.ToString(Convert.ToInt32(System.Windows.SystemParameters.PrimaryScreenWidth) / 2);
clOp.strNoOfOp = dvOps[i]["NumOF"].ToString().Trim() + " - " + dvOps[i]["NumOP"].ToString().Trim();
clOp.strAuart = dvOps[i]["AUART"].ToString().Trim();
clOp.strMaufnr = dvOps[i]["MAUFNR"].ToString().Trim();
clOp.strCodeLigne = dvOps[i]["CodeLigne"].ToString().Trim();
//clOp.strNumOp = dvOps[i]["NumOP"].ToString().Trim();
clOp.strRueck = dvOps[i]["RUECK"].ToString().Trim();
clOp.strDescriptionOp = dvOps[i]["DesOpe"].ToString().Trim();
clOp.strNoArticle = dvOps[i]["NumArt"].ToString().Trim();
clOp.strDateFormatee = dvOps[i]["DateFormatee"].ToString().Trim();
clOp.strPcesPoste = Convert.ToString(Convert.ToDouble(String.Format("{0:0}", dvOps[i]["QtePoste"].ToString().Trim()))) + " pces";
clOp.strTpsPoste = Convert.ToString(Convert.ToDouble(String.Format("{0:0.00}", dvOps[i]["TpsChargePoste"].ToString()))) + " Hrs";
clOp.strClient = dvOps[i]["NomClientCourt"].ToString().Trim();
clOp.strTypeOp = dvOps[i]["MAKTX"].ToString();
clOp.strPriorite = dvOps[i]["PriorOF"].ToString();
clOp.strSsSect = dvOps[i]["SsSect"].ToString();
clOp.strDateDerBadge = Convert.ToDateTime(dvOps[i]["DatDerBadg"]);
// C'est ici que je calcule les totaux
dblTotalQte += Convert.ToDouble(dvOps[i]["QtePoste"].ToString().Trim());
dblTotalTemps += Convert.ToDouble(dvOps[i]["TpsChargePoste"].ToString().Trim());
dblTotalOp++;
// Que je veux passer dans une variable ici pour afficher dans le label en bas de mon XAML
clOp.strTotaux = "Nb OPs : " + dblTotalOp.ToString() + " Qte totale : " + dblTotalQte.ToString() + " Pces Temps total : " + dblTotalTemps + " Hrs";
Application.Current.Dispatcher.Invoke(new Action(() => lstOperationsTemp.Add(clOp)));
DateTime dtRetard = Convert.ToDateTime(clOp.strDateFormatee);
DateTime dtTempsPoste = Convert.ToDateTime(clOp.strDateDerBadge);
TimeSpan tRetard = dtNow.Date - dtRetard.Date;
TimeSpan tTempsPoste = dtNow - dtTempsPoste;
clOp.strRetardAvanceText = Convert.ToString(Math.Abs(Convert.ToDouble(tRetard.TotalDays))) + " jrs";
clOp.scbBackColor.Freeze();
clOp.scbColorRetardAvance.Freeze();
}
ObservableCollection<CL_Operation> lstOperations = new ObservableCollection<CL_Operation>(lstOperationsTemp);
Application.Current.Dispatcher.Invoke(new Action(() => this.DataContext = lstOperations));
}
private void Test(object sender, MouseButtonEventArgs e)
{
string str = ((TextBlock)sender).Tag.ToString();
MessageBox.Show(str);
foreach (var item in lstOperationsTemp)
{
if (item.strRueck == str)
{
MessageBox.Show(item.strNoOfOp);
break;
}
}
}
public class MainWindowViewModel : INotifyPropertyChanged
{
//private ObservableCollection<LS_Operation> _operations;
//public ObservableCollection<LS_Operation> Operations
//{
// get { return _operation; }
// set
// {
// if (value == _operations) return;
// _operations = value;
// OnPropertyChanged("Operations");
// }
//}
public string _strTotal;
public string StrTotal
{
get { return _strTotal; }
set
{
if (value == _strTotal) return;
_strTotal = value;
OnPropertyChanged("StrTotal");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}
Ma classe :
using System;
using System.Collections.Generic;
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;
using System.Data;
using System.Data.SqlClient;
namespace Project
{
public class CL_Operation
{
public string strWidth { get; set; }
public string strAuart { get; set; }
public string strMaufnr { get; set; }
public string strNoOfOp { get; set; }
public string strRueck { get; set; }
public string strCodeLigne { get; set; }
public string strNumOp { get; set; }
public string strDescriptionOp { get; set; }
public string strNoArticle { get; set; }
public string strDateFormatee { get; set; }
public string strPcesPoste { get; set; }
public string strTpsPoste { get; set; }
public string strClient { get; set; }
public string strTypeOp { get; set; }
public string strPriorite { get; set; }
public string strPoste { get; set; }
public string strSsSect { get; set; }
public string strTotaux { get; set; }
public DateTime strDateDerBadge { get; set; }
public string strTempsPoste { get; set; }
public string strRetardAvanceText { get; set; }
public SolidColorBrush scbColorNumOfOp { get; set; }
public SolidColorBrush scbColorRetardAvance { get; set; }
public SolidColorBrush scbBackColor { get; set; }
}
}
C'est dans cette classe comme tu peux voir que j'ai mis une public string strTotaux.
La variable se remplie bien avec mon code C# ci-dessus dans la boucle cependant pour chaque objet dans ma liste la valeur est différente et il m'affiche la valeur de la 1ère, donc tout à 1 ... rien additionné.
Merci
- Edité par Fellerson 19 septembre 2017 à 9:28:57
WPF - 2ème source de valeur
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.