private void btn_Validate_Click(object sender, EventArgs e) { if (UnvalidatedConstant != null && UnvalidatedConstant.DetectionLimit != 0 && UnvalidatedConstant.BackgroundNoise != 0) { if (UnvalidatedConstant.EncodedBy.ToUpper() != SynapseForm.FormUser.UserID.ToUpper()) { o_Constant LastValidConstant = o_Constant.Load("where ChainID=" + cb_Chaine.SelectedValue + " and DateTo='" + DateTime.MaxValue.ToString("yyyy-MM-dd") + "' AND DateFrom<>'" + DateTime.MaxValue.ToString("yyyy-MM-dd") + "'").FirstOrDefault(); if (LastValidConstant != null) { if (LastValidConstant.DateFrom >= dtp_ValidFrom.Value.AddDays(-1)) { MessageBox.Show(SynapseForm.GetLabel("messages.errorconstantdateerror"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } LastValidConstant.DateTo = dtp_ValidFrom.Value.AddDays(-1); LastValidConstant.save(); } UnvalidatedConstant.ValidationBy = SynapseForm.FormUser.UserID; UnvalidatedConstant.ValidationDate = DateTime.Now; UnvalidatedConstant.DateFrom = dtp_ValidFrom.Value; UnvalidatedConstant.save(); cb_Chaine_SelectedIndexChanged(this, e); } else { MessageBox.Show(SynapseForm.GetLabel("messages.errordoublevalidation"), SynapseForm.GetLabel("messages.errordoublevalidationtitle"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { MessageBox.Show("no constant to validate"); } }
private void cb_Chaine_SelectedIndexChanged(object sender, EventArgs e) { Constant = o_Constant.Load("where ChainID=" + cb_Chaine.SelectedValue + " AND DateFrom<='" + DateTime.Now.ToString("yyyy-MM-dd") + "' AND DateTo>='" + DateTime.Now.ToString("yyyy-MM-dd") + "'").FirstOrDefault(); if (Constant == null) { Constant = new o_Constant(); } lb_DateFrom.Text = "Actif depuis le " + Constant.DateFrom.ToString("dd/MM/yyyy"); txt_OldBackNoise.Text = Constant.BackgroundNoise.ToString("0.000E+00"); txt_OldDetectionLimit.Text = Constant.DetectionLimit.ToString("0.000E+00"); string olduserencode = "inconnu"; string olduservalid = "inconnu"; try { olduserencode = SynapseCore.Entities.SynapseUser.LoadByUserID(Constant.EncodedBy).ToString(); } catch (Exception) { } try { olduservalid = SynapseCore.Entities.SynapseUser.LoadByUserID(Constant.ValidationBy).ToString(); } catch (Exception) { } lb_oldvalid.Text = string.Format(SynapseForm.GetLabel("messages.encodedmessage"), Constant.EncodedDate.ToString("dd/MM/yyyy HH:mm"), olduserencode, Constant.ValidationDate.ToString("dd/MM/yyyy HH:mm"), olduservalid); UnvalidatedConstant = o_Constant.Load("where ChainID=" + cb_Chaine.SelectedValue + " AND DateFrom='" + DateTime.MaxValue.ToString("yyyy-MM-dd") + "' AND DateTo='" + DateTime.MaxValue.ToString("yyyy-MM-dd") + "'").FirstOrDefault(); if (UnvalidatedConstant != null) { txt_NewBackNoise.Text = UnvalidatedConstant.BackgroundNoise.ToString("0.000E+00"); txt_NewDetectionLimit.Text = UnvalidatedConstant.DetectionLimit.ToString("0.000E+00"); gb_Validate.Enabled = true; pnl_waitingvalidation.Visible = true; btn_ApplyC.Enabled = false; string newuserencode = ""; try { newuserencode = SynapseCore.Entities.SynapseUser.LoadByUserID(UnvalidatedConstant.EncodedBy).ToString(); } catch (Exception) { } lb_newvalid.Text = string.Format(SynapseForm.GetLabel("messages.encodedmessage"), UnvalidatedConstant.EncodedDate.ToString("dd/MM/yyyy HH:mm"), newuserencode, "", ""); } else { txt_NewBackNoise.Text = ""; txt_NewDetectionLimit.Text = ""; gb_Validate.Enabled = false; pnl_waitingvalidation.Visible = false; lb_newvalid.Text = ""; btn_ApplyC.Enabled = true; } }
private void button1_Click(object sender, EventArgs e) { if (cb_Tranche.SelectedValue != null && cb_Chaine.SelectedValue != null) { if (UnvalidatedConstant == null) { UnvalidatedConstant = new o_Constant(); } UnvalidatedConstant.ChainID = (Int64)cb_Chaine.SelectedValue; UnvalidatedConstant.BackgroundNoise = double.Parse(txt_NewBackNoise.Text.Replace('.', Convert.ToChar(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator)).Replace(',', Convert.ToChar(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator))); UnvalidatedConstant.DetectionLimit = double.Parse(txt_NewDetectionLimit.Text.Replace('.', Convert.ToChar(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator)).Replace(',', Convert.ToChar(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator))); UnvalidatedConstant.EncodedBy = SynapseForm.FormUser.UserID; UnvalidatedConstant.EncodedDate = DateTime.Now; UnvalidatedConstant.DateFrom = DateTime.MaxValue; UnvalidatedConstant.DateTo = DateTime.MaxValue; UnvalidatedConstant.save(); cb_Chaine_SelectedIndexChanged(this, e); } }
private void button1_Click(object sender, EventArgs e) { using (OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\hce339\Desktop\GAZIVIEW_DATA.accdb")) { conn.Open(); foreach (o_Unit u in Units) { string unitstr = trancheequiv.SingleOrDefault(te => te.Key == u.Name).Value; o_Constant CurrentConstant = new o_Constant(); foreach (o_Chain c in Chains.Where(ch => ch.UnitID == u.ID)) { int rowcount = 0; using (OleDbCommand cmd = new OleDbCommand("SELECT Rejet.*, Chaine.NomChaine FROM Chaine INNER JOIN Rejet ON Chaine.IdChaine = Rejet.IdChaine WHERE Chaine.NomChaine='" + c.Name + "' AND Chaine.NomTranche='" + unitstr + "' ORDER BY DateRejet", conn)) { bool CurrentActive = false; OleDbDataReader Reader = cmd.ExecuteReader(); //if (Reader.HasRows) if (Reader.HasRows) { while (Reader.Read()) { DateTime Date = ((DateTime)Reader["DateRejet"]).AddDays(-1); double RejetGaz = Convert.ToDouble(Reader["RejetGaz24h"] is DBNull ? 0 : Reader["RejetGaz24h"]); double VolumeGaz = Convert.ToDouble(Reader["VolumeGaz24h"] is DBNull?0:Reader["VolumeGaz24h"]); string Remarque = Reader["Remarque"].ToString(); double Bdf = Convert.ToDouble(Reader["BDFRejet"] is DBNull ? 0 : Reader["BDFRejet"]); double SeuilDecision = Convert.ToDouble(Reader["SeuilDecision"] is DBNull ? 0 : Reader["SeuilDecision"]); string Trigramme = Reader["Trigramme"].ToString(); double LimitDetection = SeuilDecision * 2; if (CurrentActive == false) { CurrentConstant = new o_Constant() { ChainID = c.ID, BackgroundNoise = Bdf, DetectionLimit = LimitDetection, DateFrom = Date, DateTo = Date }; CurrentActive = true; } if (CurrentConstant.BackgroundNoise == Bdf && CurrentConstant.DetectionLimit == LimitDetection) { CurrentConstant.DateTo = Date; } else { Constants.Add(CurrentConstant); CurrentConstant = new o_Constant() { ChainID = c.ID, BackgroundNoise = Bdf, DetectionLimit = LimitDetection, DateFrom = Date, DateTo = Date }; } Emissions.Add(new o_GasEmission() { Date = Date, ChainID = c.ID, Remarque = Remarque, EncodedDate = Date.AddDays(1), EncodedBy = Trigramme, Valid = true, ValidationBy = "System", ValidationDate = Date.AddDays(2), GasEmission = RejetGaz, GasVolume = VolumeGaz }); rowcount++; } CurrentConstant.DateTo = DateTime.MaxValue; Constants.Add(CurrentConstant); } } richTextBox1.AppendText(string.Format("Unité {0} Chaine {1} : {2} Rejets chargés / {3} Constante créées / {4} Rejets importés\n", u.Name, c.Name, rowcount, Constants.Where(co => co.ChainID == c.ID).Count(), Emissions.Where(em => em.ChainID == c.ID).Count())); this.Refresh(); this.Update(); } } List <KeyValuePair <string, string> > trigtouser = new List <KeyValuePair <string, string> >(); trigtouser.Add(new KeyValuePair <string, string>("ah", "CORP\\ADH220")); trigtouser.Add(new KeyValuePair <string, string>("arv", "CORP\\CHG415")); trigtouser.Add(new KeyValuePair <string, string>("BES", "CORP\\FGJ032")); trigtouser.Add(new KeyValuePair <string, string>("CLA", "CORP\\AAJ475")); trigtouser.Add(new KeyValuePair <string, string>("dcp", "CORP\\EGF093")); trigtouser.Add(new KeyValuePair <string, string>("dgl", "CORP\\EDB021")); trigtouser.Add(new KeyValuePair <string, string>("dns", "CORP\\ECC007")); trigtouser.Add(new KeyValuePair <string, string>("drg", "CORP\\CIK103")); trigtouser.Add(new KeyValuePair <string, string>("EHE", "CORP\\CAJ200")); trigtouser.Add(new KeyValuePair <string, string>("gsb", "CORP\\EIH005")); trigtouser.Add(new KeyValuePair <string, string>("gsn", "CORP\\GEJ361")); trigtouser.Add(new KeyValuePair <string, string>("HEL", "CORP\\FJH023")); trigtouser.Add(new KeyValuePair <string, string>("Lah", "CORP\\ADH220")); trigtouser.Add(new KeyValuePair <string, string>("lbm", "CORP\\GBC037")); trigtouser.Add(new KeyValuePair <string, string>("LPN", "CORP\\AFE434")); trigtouser.Add(new KeyValuePair <string, string>("nlf", "CORP\\EJB173")); trigtouser.Add(new KeyValuePair <string, string>("ost", "CORP\\BJD405")); trigtouser.Add(new KeyValuePair <string, string>("urm", "CORP\\IGA484")); trigtouser.Add(new KeyValuePair <string, string>("vhp", "CORP\\HAL173")); foreach (o_GasEmission E in Emissions) { E.EncodedBy = trigtouser.SingleOrDefault(ttu => ttu.Key == E.EncodedBy).Value; } this.Refresh(); this.Update(); } }