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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
| public partial class MainWindow : Window, INotifyPropertyChanged
{
#region Évenement qui permet de déclencher l'événement INotifyPropertyChanged et mettre à jour le binding
public void Set<TValue>(ref TValue field, TValue newValue, [CallerMemberName] string propertyName = "")
{
if (EqualityComparer<TValue>.Default.Equals(field, default(TValue)) || !field.Equals(newValue))
{
field = newValue;
if (PropertyChanged != null)
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
public event PropertyChangedEventHandler PropertyChanged;
#endregion
public static RangeObservableCollection<CL_Operation> _lstOperations = new RangeObservableCollection<CL_Operation>();
public static RangeObservableCollection<CL_Operation> LstOperations
{
get { return _lstOperations; }
set { _lstOperations = value; }
}
private string _strTotaux;
public string strTotaux
{
get { return _strTotaux; }
set { Set(ref _strTotaux, value); }
}
private string _strShowMenu;
public string strShowMenu
{
get { return _strShowMenu; }
set { Set(ref _strShowMenu, value); }
}
private string _strSelection;
public string strSelection
{
get { return _strSelection; }
set { Set(ref _strSelection, value); }
}
private string _strFiltres;
public string strFiltres
{
get { return _strFiltres; }
set { Set(ref _strFiltres, value); }
}
public MainWindow()
{
InitializeComponent();
DataContext = this;
}
public void GetList()
{
strShowMenu = "Hidden";
RangeObservableCollection<CL_Operation> _lstOperationsTemp = new RangeObservableCollection<CL_Operation>();
strSelection = "";
foreach (var item in Var.lstSelectedLignesChoisi)
{
strSelection += item.ToString() + " ";
}
foreach (var item in Var.lstSelectedIlotsChoisi)
{
strSelection += " " + item.ToString() + " ";
}
foreach (var item in Var.lstSelectedPostesTravailChoisi)
{
strSelection += " " + item.ToString() + " ";
}
strFiltres = "";
foreach (var item in Var.lstSelectedOperations)
{
strFiltres += item.ToString() + " ";
}
foreach (var item in Var.lstSelectedTypesDiamant)
{
strFiltres += item.ToString() + " ";
}
foreach (var item in Var.lstSelectedClient)
{
strFiltres += item.ToString() + " ";
}
foreach (var item in Var.lstSelectedMatricule)
{
strFiltres += item.ToString() + " ";
}
foreach (var item in Var.lstSelectedTypeOrdre)
{
strFiltres += item.ToString() + " ";
}
foreach (var item in Var.lstSelectedPriorites)
{
strFiltres += item.ToString() + " ";
}
if (!string.IsNullOrEmpty(Var.strFiltreNoOF))
strFiltres += Var.strFiltreNoOF;
if (!string.IsNullOrEmpty(Var.strFiltreArticle))
strFiltres += Var.strFiltreArticle;
if (!string.IsNullOrEmpty(Var.strFiltreComposant))
strFiltres += Var.strFiltreComposant;
if (!string.IsNullOrEmpty(Var.strFiltreAgentOrdo))
strFiltres += Var.strFiltreAgentOrdo;
if (!string.IsNullOrEmpty(Var.strFiltreGestMRP))
strFiltres += Var.strFiltreGestMRP;
if (!string.IsNullOrEmpty(Var.strFiltreSquelette) && Var.strFiltreSquelette != "TOUS")
strFiltres += Var.strFiltreSquelette + " SQUELETTE";
strWhere = "";
strWhere = Where(Var.lstSelectedLignesChoisi, Var.lstSelectedIlotsChoisi, Var.lstSelectedPostesTravailChoisi, Var.lstSelectedOperations, Var.lstSelectedTypesDiamant, Var.lstSelectedClient, Var.lstSelectedMatricule, Var.lstSelectedTypeOrdre, Var.strFiltreArticle, Var.strFiltreNoOF, Var.strFiltreComposant, Var.strFiltreAgentOrdo, Var.strFiltreGestMRP, Var.lstSelectedPriorites, Var.strFiltreSquelette);
CreateOrderBy();
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;
double dblTotalJoursRetard = 0;
for (int i = 0; i < dvOps.Count; i++)
{
clOp = new CL_Operation();
clOp.strWidth = Convert.ToString(Convert.ToInt32(System.Windows.SystemParameters.PrimaryScreenWidth) / 2);
if (dvOps[i]["OP_IsWorking"].ToString().Trim() != "")
clOp.bIsWorking = Convert.ToBoolean(dvOps[i]["OP_IsWorking"].ToString().Trim());
else
clOp.bIsWorking = false;
clOp.bAnoOp = Convert.ToBoolean(dvOps[i]["AnoOP"].ToString().Trim());
if (clOp.bIsWorking && clOp.bAnoOp)
{
clOp.strImageToDisplay = "Images/TravailAnomalie.png";
clOp.strWorkingVisibility = "Visible";
}
else if (clOp.bAnoOp)
{
clOp.strImageToDisplay = "Images/Anomalie.png";
clOp.strWorkingVisibility = "Visible";
}
else if (clOp.bIsWorking)
{
clOp.strImageToDisplay = "Images/Travail.png";
clOp.strWorkingVisibility = "Visible";
}
else
{
clOp.strImageToDisplay = "Images/Travail.png";
clOp.strWorkingVisibility = "Hidden";
}
if (dvOps[i]["OP_IsAssigned"].ToString().Trim() != "")
clOp.bIsAssigned = Convert.ToBoolean(dvOps[i]["OP_IsAssigned"].ToString().Trim());
else
clOp.bIsAssigned = false;
if (clOp.bIsAssigned)
clOp.strAttributionVisibility = "Visible";
else
clOp.strAttributionVisibility = "Hidden";
clOp.strDesBlocage = dvOps[i]["DesBlocage"].ToString().Trim();
if(!string.IsNullOrEmpty(dvOps[i]["MATRICULE"].ToString().Trim()))
clOp.strMatriculeAssigned = Convert.ToInt32(dvOps[i]["MATRICULE"]).ToString().Trim();
clOp.strNameAssigned = dvOps[i]["NAME"].ToString().Trim();
clOp.strFirstNameAssigned = dvOps[i]["FIRSTNAME"].ToString().Trim();
clOp.strEmpAssigned = dvOps[i]["NAME"].ToString().Trim() + " " + dvOps[i]["FIRSTNAME"].ToString().Trim();
clOp.strNoOf = dvOps[i]["NumOF"].ToString().Trim();
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.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().Trim();
clOp.strPriorite = dvOps[i]["PriorOF"].ToString().Trim();
clOp.strSsSect = dvOps[i]["SsSect"].ToString().Trim();
clOp.strDateDerBadge = Convert.ToDateTime(dvOps[i]["DatDerBadg"]);
clOp.strWorkStart = dvOps[i]["DATETIMEDEBUT"].ToString().Trim();
clOp.strNumOp = dvOps[i]["NumOpSt"].ToString().Trim();
clOp.strIDRegroupement = dvOps[i]["USR02"].ToString().Trim();
clOp.strFlagPostePrev = dvOps[i]["FlagPostePrev"].ToString().Trim();
clOp.strNumArtPere = dvOps[i]["NumArtPere"].ToString().Trim();
clOp.strMAKTXPere = dvOps[i]["MAKTXPere"].ToString().Trim();
//int iCountRegr = 0;
if (!string.IsNullOrEmpty(clOp.strIDRegroupement))
{
//string strQueryDatas2;
//SqlConnection con2 = new SqlConnection(connectionString);
SqlConnection con3 = new SqlConnection(connectionString);
SqlConnection con4 = new SqlConnection(connectionString);
//strQueryDatas2 = "SELECT COUNT (*) FROM [db].[dbo].[view] WHERE USR02 = '" + clOp.strIDRegroupement + "'";
//try
//{
// con2.Open();
// SqlCommand sqlCmd = new SqlCommand(strQueryDatas2, con2);
// iCountRegr = (Int32)sqlCmd.ExecuteScalar();
// //sqlCmd.CommandTimeout = 500;
// con2.Close();
//}
//catch (Exception ex)
//{
// MessageBox.Show(ex.Message);
//}
string strQueryDatas3;
strQueryDatas3 = "SELECT COUNT (*) FROM [db].[dbo].[Table] WHERE FlagPostePrev = 'POSTE' AND USR02 = '" + clOp.strIDRegroupement + "'";
try
{
con3.Open();
SqlCommand sqlCmd = new SqlCommand(strQueryDatas3, con3);
clOp.iCountRegrPoste = (Int32)sqlCmd.ExecuteScalar();
//sqlCmd.CommandTimeout = 500;
con3.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
string strQueryDatas4;
strQueryDatas4 = "SELECT COUNT (*) FROM [db].[dbo].[Table] WHERE FlagPostePrev = 'PREV' AND USR02 = '" + clOp.strIDRegroupement + "'";
try
{
con4.Open();
SqlCommand sqlCmd = new SqlCommand(strQueryDatas4, con4);
clOp.iCountRegrPrev = (Int32)sqlCmd.ExecuteScalar();
//sqlCmd.CommandTimeout = 500;
con4.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
clOp.strPostePrevCount = "Poste : " + clOp.iCountRegrPoste.ToString() + " / Prév : " + clOp.iCountRegrPrev.ToString();
}
if (string.IsNullOrEmpty(clOp.strIDRegroupement))
clOp.strRegroupementVisibility = "Hidden";
else
clOp.strRegroupementVisibility = "Visible";
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;
if (dtTempsPoste.ToString() == "01.01.1900 00:00:00")
dtTempsPoste = dtNow;
TimeSpan tTempsPoste = dtNow - dtTempsPoste;
dblTotalQte += Convert.ToDouble(dvOps[i]["QtePoste"].ToString().Trim());
dblTotalTemps += Convert.ToDouble(dvOps[i]["TpsChargePoste"].ToString().Trim());
dblTotalOp++;
clOp.strRetardAvanceText = Convert.ToString(Math.Abs(Convert.ToDouble(tRetard.TotalDays))) + " jrs";
clOp.scbBackColor.Freeze();
clOp.scbColorRetardAvance.Freeze();
}
strTotaux = "Total retard : " + dblTotalJoursRetard.ToString() + " Jours Nb OPs : " + dblTotalOp.ToString() + " Qte totale : " + dblTotalQte.ToString() + " Pces Temps total : " + dblTotalTemps + " Hrs";
Application.Current.Dispatcher.Invoke(new Action(() => LstOperations.Clear()));
Application.Current.Dispatcher.Invoke(new Action(() => LstOperations.AddRange(_lstOperationsTemp)));
Var.lstSelectedOperations.Clear();
Var.lstSelectedTypesDiamant.Clear();
Var.lstSelectedClient.Clear();
Var.lstSelectedMatricule.Clear();
Var.lstSelectedTypeOrdre.Clear();
Var.strFiltreNoOF = "";
Var.strFiltreArticle = "";
Var.strFiltreComposant = "";
Var.strFiltreAgentOrdo = "";
Var.strFiltreGestMRP = "";
Var.strFiltreSquelette = "";
strShowMenu = "Visible";
}
} |
Partager