public static string insertIntoMySqlDataBase(List <Entity.EntityInsertion> lista, string connectionString) { string insertId = ""; try { if (listRawMat.Contains(lista[0].rawMaterialId)) { return(""); //Para evitar LPN Duplicados consulto a una lista. } MySqlConnection mysqlConn = new MySqlConnection(ConfigurationManager.AppSettings[connectionString].ToString()); if (mysqlConn.State == ConnectionState.Closed) { mysqlConn.Open(); } using (MySqlCommand cmd = mysqlConn.CreateCommand()) { cmd.CommandText = lista[0].sp; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("_op", lista[0].batchId); cmd.Parameters.AddWithValue("_linMatWip", lista[0].wipLocation); cmd.Parameters.AddWithValue("_rawMaterial", lista[0].rawMaterialId); cmd.Parameters.AddWithValue("_codMat", lista[0].partNumber); cmd.Parameters.AddWithValue("_uniMedMat", lista[0].unityOfMeasure); cmd.Parameters.AddWithValue("_cantASolic", lista[0].qtyToRequest); cmd.Parameters.AddWithValue("_estadoLinea", lista[0].laneStatus); cmd.Parameters.AddWithValue("_linDest", lista[0].laneDestiny); cmd.Parameters.AddWithValue("_ubicOrig", lista[0].locationOrigin); cmd.Parameters.AddWithValue("_status", lista[0].status); cmd.Parameters.AddWithValue("_PROD_LINE", lista[0].laneNumber); cmd.Parameters.AddWithValue("_MAQUINA", lista[0].idMachine); cmd.Parameters.AddWithValue("_UBICACION", lista[0].location); insertId = cmd.ExecuteScalar().ToString(); listRawMat.Add(lista[0].rawMaterialId); // Agrego el LPN a la lista para su posterior comprobación. } } catch (Exception e) { Console.WriteLine(e.ToString()); } if ((insertId == "") || (insertId == null)) { try { insertId = SQLDataManager.getInsertedId(lista[0].rawMaterialId, connectionString); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } return(insertId); }
/*****************************************************************************************************/ /******************************* PIZARRA DATABASE ****************************************************/ internal static String IAServerInsertionLog(Entity.EntityInitRawMaterial q, string p) { if (p != null) { String partNumber = SQLDataManager.selectValuesFromMateriales(q.NumMaterial); String lastInserted = ""; String connectionStringFromAppConfig = "ConnectToMySQL"; String insertStringToMateriales = "INSERT INTO materiales(NumMaterial,Material,Orig_Ubic_Alm,Orig_Cant,Conf_Fecha,Conf_Hora,Conf_Usuario,Descripcion,Cantidad,Num_Pallet,Num_Ord_Transp,TimeStamp) values ('" + q.NumMaterial + "','" + partNumber + "','" + q.Orig_Ubic_Alm + "','" + q.Orig_Cant + "','" + q.Conf_Fecha + "','" + q.Conf_Hora + "','" + q.Conf_Usuario + "','" + q.Descripcion + "','" + q.Cantidad + "','" + q.Num_Pallet + "','" + q.Num_Ord_Transp + "',NOW())"; DataTable queryTable = new DataTable(); try { Conectivity.ConnectItAndExecuteMYSQL(insertStringToMateriales, connectionStringFromAppConfig); lastInserted = GetLastMySQLInsertedId("materiales", "idMateriales", "ConnectToMySQL"); if (lastInserted == null || lastInserted == "") { lastInserted = "1"; } String insertStringToDetMateriales = "INSERT INTO wsmensajeresponse(idMateriales,detalleMensaje) VALUES ('" + lastInserted + "','" + p + "')"; Conectivity.ConnectItAndExecuteMYSQL(insertStringToDetMateriales, connectionStringFromAppConfig); } catch (Exception e) { System.Console.WriteLine(e.Message); } return(p); } else { return(null); } }