Salut Noxen
Merci beaucoup pour ta réponse
Cependant je ne comprends pas :
1 2 3 4 5 6 7 8 9 10 11
| private ObservableCollection<LS_Operation> _operations;
public ObservableCollection<LS_Operation> Operations
{
get { return _operation; }
set
{
if (value == _operations) return;
_operations = value;
OnPropertyChanged("Operations");
}
} |
Pourquoi ce bout de code ?
Je déclare déjà en haut ma liste :
public ObservableCollection<CL_Operation> lstOperationsTemp = new ObservableCollection<CL_Operation>();
De plus, tu nommes la variable strTotal ou _strTotal et dans le Binding on envoie strTotaux ? je suis un peu perdu. Pour peut-être un peu clarifier tout ça :
Mon code XAML :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| <Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Plutus" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="Plutus.MainWindow"
Title="MainWindow" Height="523.725" Width="898" Background="#FF3A3939" WindowStartupLocation="CenterScreen" WindowState="Maximized">
<Window.Resources>
<Style TargetType="ScrollBar">
<Setter Property="Width" Value="35"/>
</Style>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="0.03*" />
<RowDefinition Height="0.04*" />
<RowDefinition Height="0.04*" />
<RowDefinition Height="0.88*"/>
<RowDefinition Height="0.02*" />
</Grid.RowDefinitions>
<Label Grid.Row="1" />
<Button Name="btnParamsAffichage" Content="Paramètres" HorizontalAlignment="Left" Width="100" Grid.Row="1" Background="#b2c9ef" Click="btnParamsAffichage_Click" />
<Label Grid.Row="2" />
<ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="3" >
<ItemsControl VerticalAlignment="Top" x:Name="lvDataBinding" HorizontalContentAlignment="Stretch" BorderThickness="0" Margin="10" Grid.Row="3" Background="{x:Null}" ItemsSource="{Binding}" Foreground="White">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type local:CL_Operation}">
<Border BorderBrush="White" BorderThickness="1" CornerRadius="3" Margin="0,3" Grid.ColumnSpan="0" Background="Transparent" HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid Width="{Binding strWidth}" Height="60" Background="Transparent" Margin="0,1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.06*" />
<ColumnDefinition Width="0.09*" />
<ColumnDefinition Width="0.1*" />
<ColumnDefinition Width="0.12*" />
<ColumnDefinition Width="0.1*" />
<ColumnDefinition Width="0.1*" />
<ColumnDefinition Width="0.1*" />
<ColumnDefinition Width="0.05*" />
<ColumnDefinition Width="0.05*" />
<ColumnDefinition Width="0.05*" />
<ColumnDefinition Width="0.05*" />
<ColumnDefinition Width="0.03*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<UniformGrid Tag="{Binding strRueck}" Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" MouseLeftButtonUp="Test" >
<UniformGrid.Style>
<Style TargetType="{x:Type UniformGrid}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" Value="White"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="false">
<Setter Property="Background" Value="{Binding scbBackColor}"/>
</Trigger>
</Style.Triggers>
</Style>
</UniformGrid.Style>
<TextBlock Text="{Binding strPriorite}" FontSize="36" Foreground="Red" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold"/>
</UniformGrid>
<UniformGrid Grid.Column="0" Grid.Row="2" Background="{Binding scbBackColor}" MouseLeftButtonUp="Test" >
<TextBlock Text="{Binding strSsSect}" FontSize="14" Foreground="Black" HorizontalAlignment="Right" VerticalAlignment="Bottom" FontWeight="Bold" />
</UniformGrid>
<UniformGrid Grid.Column="1" Grid.Row="0" Grid.RowSpan="3">
<TextBlock Text="{Binding strRetardAvanceText}" FontSize="28" Foreground="{Binding scbColorRetardAvance}" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" />
</UniformGrid>
<UniformGrid Grid.Column="2" Grid.Row="0" Grid.ColumnSpan="2" Grid.RowSpan="2">
<UniformGrid.Style>
<Style TargetType="{x:Type UniformGrid}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" Value="Gray"/>
</Trigger>
</Style.Triggers>
</Style>
</UniformGrid.Style>
<TextBlock Tag="{Binding strRueck}" Foreground="{Binding scbColorNumOfOp}" Text="{Binding strNoOfOp}" FontSize="26" FontWeight="Bold" MouseLeftButtonUp="Test"/>
</UniformGrid>
<UniformGrid Grid.Column="2" Grid.Row="2" Grid.ColumnSpan="3">
<TextBlock Text="{Binding strDescriptionOp}" FontSize="14" Foreground="White"/>
</UniformGrid>
<UniformGrid Grid.Column="4" Grid.Row="0">
<TextBlock Text="{Binding strNoArticle}" FontSize="14" Foreground="White"/>
</UniformGrid>
<UniformGrid Grid.Column="4" Grid.Row="1">
<TextBlock Text="{Binding strDateFormatee}" FontSize="14" Foreground="White"/>
</UniformGrid>
<UniformGrid Grid.Column="5" Grid.Row="0">
<TextBlock Text="{Binding strPcesPoste}" FontSize="14" Foreground="White"/>
</UniformGrid>
<UniformGrid Grid.Column="5" Grid.Row="1">
<TextBlock Text="{Binding strTpsPoste}" FontSize="14" Foreground="White"/>
</UniformGrid>
<UniformGrid Grid.Column="6" Grid.Row="0">
<TextBlock Text="{Binding strTempsPoste}" FontSize="14" Foreground="White"/>
</UniformGrid>
<UniformGrid Grid.Column="6" Grid.Row="1">
<TextBlock Text="{Binding strClient}" FontSize="14" Foreground="White"/>
</UniformGrid>
<UniformGrid Grid.Column="5" Grid.Row="2" Grid.ColumnSpan="3">
<TextBlock Text="{Binding strTypeOp}" FontSize="14" Foreground="White"/>
</UniformGrid>
<UniformGrid Grid.Column="9" Grid.Row="3">
<TextBlock Text="{Binding strAuart}" FontSize="12" Foreground="White" FontWeight="Bold"/>
</UniformGrid>
</Grid>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="2"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</ScrollViewer>
<Label HorizontalAlignment="Right" Foreground="White" Grid.Row="4" Content="{Binding Path=StrTotal}"></Label>
<Label HorizontalAlignment="Center" Foreground="White" Grid.Row="4" Content=""></Label>
</Grid>
</Window> |
Mon code C# : (j'ai mis en commentaire dans la boucle ou je fais les actions)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
| 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 (ClassStructure.cs)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| 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
Partager