/// <summary> /// constructor for new entry pesage 2 /// </summary> /// <param name="poids_bascule_"></param> /// <param name="owner_"></param> public EntreeStock(int entry_n, double poids_bascule_) { InitializeComponent(); this.Text = "Entrée Stock : Pesage 2"; operation = 1; _p = PesageHeaderDao.getPesageHeader(entry_n); nticket_tb.Text = _p.n_ticket; date_entree_dtp.Value = _p.date_entree; camion_cb.Text = _p.matricule_camion; chauffeur_cb.Text = _p.nom_chauffeur; poids_recep_tb.Text = _p.poids_reception.ToString(); //date_sortie_dtp.Value = _p.date_sortie; --> pesage1_tb.Text = _p.pesage_1.ToString(); pesage2_tb.Text = poids_bascule_.ToString(); poids_net_tb.Text = Math.Abs((double.Parse(pesage1_tb.Text) - double.Parse(pesage2_tb.Text))).ToString("0.000"); // controls status nticket_tb.Enabled = false; date_entree_dtp.Enabled = false; camion_cb.Enabled = false; chauffeur_cb.Enabled = false; pesage1_tb.Enabled = false; }
/// <summary> /// Save pesage 2 new operation /// </summary> /// <param name="_p"></param> /// <returns></returns> public static int closurePesageHeader(PesageHeaderModel _p) { SqlConnection oSQLConn = new SqlConnection(GlobVars.navisionDBCnx); oSQLConn.Open(); SqlTransaction oSQLTransaction = oSQLConn.BeginTransaction(); SqlCommand cmd_op = new SqlCommand(); cmd_op.CommandText = "UPDATE [SOMEPA$Pesage Header] SET Pesage2=@Pesage2, [Poids Net]=@Poids_Net,[Ecart Poids]=@Ecart_p, [Date Sortie]=@Date_Sortie, Etat=2 WHERE [Entry N°] = @entry_n"; cmd_op.Parameters.Add("@Date_Sortie", SqlDbType.DateTime).Value = _p.date_sortie; cmd_op.Parameters.Add("@entry_n", SqlDbType.Int).Value = _p.entry_n; cmd_op.Parameters.Add("@Pesage2", SqlDbType.Int).Value = _p.pesage_2; cmd_op.Parameters.Add("@Poids_Net", SqlDbType.Int).Value = _p.poids_net; cmd_op.Parameters.Add("@Ecart_p", SqlDbType.Int).Value = _p.ecart_poids; cmd_op.Connection = oSQLConn; cmd_op.Transaction = oSQLTransaction; try { cmd_op.ExecuteNonQuery(); oSQLTransaction.Commit(); oSQLConn.Close(); return(0); } catch (Exception exep) { System.Windows.Forms.MessageBox.Show(exep.Message); oSQLTransaction.Rollback(); oSQLConn.Close(); return(1); } }
/// <summary> /// Get pesage operation /// </summary> /// <param name="entry_n"></param> /// <returns></returns> public static PesageHeaderModel getPesageHeader(int entry_n) { PesageHeaderModel _p = new PesageHeaderModel(); _p.entry_n = entry_n; SqlCommand cmd_op = new SqlCommand(); cmd_op.CommandText = "SELECT * from [SOMEPA$Pesage Header] WHERE [Entry N°] = @entry_n "; cmd_op.Parameters.Add("@entry_n", SqlDbType.Int).Value = entry_n; /// Connexion a la base SqlConnection oSQLConn = new SqlConnection(GlobVars.navisionDBCnx); oSQLConn.Open(); cmd_op.Connection = oSQLConn; SqlDataReader reader = cmd_op.ExecuteReader(); if (reader.Read()) { _p.n_ticket = reader["N° Ticket"].ToString(); _p.type_oper = int.Parse(reader["Type Opération"].ToString()); _p.date_entree = DateTime.Parse(reader["Date Entrée"].ToString()); _p.date_sortie = DateTime.Parse(reader["Date Sortie"].ToString()); _p.matricule_camion = reader["Matricule Camion"].ToString(); _p.nom_chauffeur = reader["Nom Chauffeur"].ToString();; _p.destination = reader["Destination"].ToString(); _p.poids_reception = double.Parse(reader["Poids Réception"].ToString()); _p.pesage_1 = double.Parse(reader["Pesage1"].ToString()); _p.pesage_2 = double.Parse(reader["Pesage2"].ToString()); _p.poids_net = double.Parse(reader["Poids Net"].ToString()); _p.ecart_poids = double.Parse(reader["Ecart Poids"].ToString()); } reader.Close(); return(_p); }
/// <summary> /// Save new pesage 1 operation /// </summary> /// <param name="_p"></param> /// <returns> id of inserted row </returns> public static int savePesageHeader(PesageHeaderModel _p) { int ret = 0; SqlConnection oSQLConn = new SqlConnection(GlobVars.navisionDBCnx); oSQLConn.Open(); SqlTransaction oSQLTransaction = oSQLConn.BeginTransaction(); SqlCommand cmd; cmd = new SqlCommand(); cmd.CommandText = "INSERT INTO [SOMEPA$Pesage Header] " + " ([Type Opération],[Date Entrée],[N° Ticket],[Matricule Camion],[Nom Chauffeur],[Pesage1],[Pesage2],[Poids Net],[Poids Réception],[Ecart Poids] ,[Date Sortie],[Destination],[Etat]) " + " OUTPUT INSERTED.[Entry N°] " // to get id of inserted rowin database + " VALUES (@Type_Op,@Date_Enree,@N_Ticket,@Mat_Camion,@Nom_Chauf,@Pesage1,0,0,0,0,@Date_Sortie,@Destination,0) "; cmd.Parameters.Add("@Type_Op", SqlDbType.Int).Value = _p.type_oper; cmd.Parameters.Add("@Date_Enree", SqlDbType.DateTime).Value = _p.date_entree; cmd.Parameters.Add("@N_Ticket", SqlDbType.VarChar).Value = _p.n_ticket; cmd.Parameters.Add("@Mat_Camion", SqlDbType.VarChar).Value = _p.matricule_camion; cmd.Parameters.Add("@Nom_Chauf", SqlDbType.VarChar).Value = _p.nom_chauffeur; cmd.Parameters.Add("@Pesage1", SqlDbType.Decimal).Value = _p.pesage_1; cmd.Parameters.Add("@Date_Sortie", SqlDbType.DateTime).Value = _p.date_entree; cmd.Parameters.Add("@Destination", SqlDbType.VarChar).Value = _p.destination; cmd.Connection = oSQLConn; cmd.Transaction = oSQLTransaction; try { ret = Convert.ToInt32(cmd.ExecuteScalar()); oSQLTransaction.Commit(); oSQLConn.Close(); return(ret); } catch (Exception exep) { System.Windows.Forms.MessageBox.Show(exep.Message); oSQLTransaction.Rollback(); oSQLConn.Close(); return(-1); } }
/// <summary> /// update pesage operation /// </summary> /// <param name="_p"></param> /// <returns></returns> public static int updatePesageHeader(PesageHeaderModel _p) { SqlConnection oSQLConn = new SqlConnection(GlobVars.navisionDBCnx); oSQLConn.Open(); SqlTransaction oSQLTransaction = oSQLConn.BeginTransaction(); SqlCommand cmd; cmd = new SqlCommand(); cmd.CommandText = "UPDATE [SOMEPA$Pesage Header] SET [Date Entrée]=@Date_Entree,[N° Ticket]=@N_Ticket,[Matricule Camion]=@Mat_Camion,[Nom Chauffeur]=@Nom_Chauf, " + " Pesage1=@Pesage1,Destination=@Destination,Pesage2=@Pesage2,[Poids Net]=@Poids_Net,[Ecart Poids]=@Ecart_p,[Date Sortie]=@Date_Sortie WHERE [Entry N°] = @Entry_n "; // P1 cmd.Parameters.Add("@Entry_n", SqlDbType.Int).Value = _p.entry_n; cmd.Parameters.Add("@Date_Entree", SqlDbType.DateTime).Value = _p.date_entree; cmd.Parameters.Add("@N_Ticket", SqlDbType.VarChar).Value = _p.n_ticket; cmd.Parameters.Add("@Mat_Camion", SqlDbType.VarChar).Value = _p.matricule_camion; cmd.Parameters.Add("@Nom_Chauf", SqlDbType.VarChar).Value = _p.nom_chauffeur; cmd.Parameters.Add("@Pesage1", SqlDbType.Decimal).Value = _p.pesage_1; //cmd.Parameters.Add("@Poids_Reception", SqlDbType.Decimal).Value = _p.poids_reception; // P2 cmd.Parameters.Add("@Date_Sortie", SqlDbType.DateTime).Value = _p.date_sortie; cmd.Parameters.Add("@Pesage2", SqlDbType.Decimal).Value = _p.pesage_2; cmd.Parameters.Add("@Poids_Net", SqlDbType.Decimal).Value = _p.poids_net; cmd.Parameters.Add("@Ecart_p", SqlDbType.Decimal).Value = _p.ecart_poids; cmd.Parameters.Add("@Destination", SqlDbType.VarChar).Value = _p.destination; cmd.Connection = oSQLConn; cmd.Transaction = oSQLTransaction; try { cmd.ExecuteNonQuery(); oSQLTransaction.Commit(); oSQLConn.Close(); return(0); } catch (Exception exep) { System.Windows.Forms.MessageBox.Show(exep.Message); oSQLTransaction.Rollback(); oSQLConn.Close(); return(1); } }
/// <summary> /// constructor for update old entry /// </summary> /// <param name="poids_bascule_"></param> /// <param name="owner_"></param> /// <param name="entry_n"></param> public EntreeStock(int entry_n) { InitializeComponent(); this.Text = "Entrée Stock : Modification Pesage"; operation = 2; _p = PesageHeaderDao.getPesageHeader(entry_n); // P1 nticket_tb.Text = _p.n_ticket; date_entree_dtp.Value = _p.date_entree; camion_cb.Text = _p.matricule_camion; chauffeur_cb.Text = _p.nom_chauffeur; pesage1_tb.Text = _p.pesage_1.ToString(); //P2 poids_recep_tb.Text = _p.poids_reception.ToString(); date_sortie_dtp.Value = _p.date_sortie; pesage1_tb.Text = _p.pesage_1.ToString(); pesage2_tb.Text = _p.pesage_2.ToString(); poids_net_tb.Text = _p.poids_net.ToString(); }