Esempio n. 1
0
        public bool Insertar(BE_PLA_MARCACION entMarcacion, DataTable dtMarcaciones)
        {
            bool             booOk      = false;
            int              n_row      = 0;
            DatosMySql       xMiFuncion = new DatosMySql();
            MySqlTransaction trans;

            trans = mysConec.BeginTransaction();

            try
            {
                if (xMiFuncion.StoreEjecutar("pla_marcacion_insertar", entMarcacion, mysConec, 1) == true)
                {
                    int n_id = Convert.ToInt32(xMiFuncion.intIdGenerado);
                    for (n_row = 0; n_row <= dtMarcaciones.Rows.Count - 1; n_row++)
                    {
                        dtMarcaciones.Rows[n_row]["n_idmar"] = n_id;
                    }

                    using (StreamWriter writer = new StreamWriter("C:\\SSF-Net\\marcacion.csv"))
                    {
                        funIO.DataTableToCVS(dtMarcaciones, writer, true);
                    }

                    string c_sql = "";

                    c_sql = "LOAD DATA LOCAL  INFILE 'C:/SSF-Net/marcacion.csv' " +
                            " INTO TABLE pla_marcaciondet FIELDS  terminated by ',' ENCLOSED BY '\"'  lines terminated by '\r\n' ignore 1 lines ";

                    if (xMiFuncion.EjecutarSQL(c_sql, mysConec) == false)
                    {
                        b_OcurrioError = xMiFuncion.booOcurrioError;
                        c_ErrorMensaje = xMiFuncion.StrErrorMensaje;
                        n_ErrorNumber  = xMiFuncion.IntErrorNumber;
                        booOk          = false;
                        trans.Rollback();
                        return(booOk);
                    }

                    booOk = true;
                }
                else
                {
                    b_OcurrioError = xMiFuncion.booOcurrioError;
                    c_ErrorMensaje = xMiFuncion.StrErrorMensaje;
                    n_ErrorNumber  = xMiFuncion.IntErrorNumber;
                    booOk          = false;
                    trans.Rollback();
                    return(booOk);
                }
                //}
                trans.Commit();
            }
            catch (Exception exc)
            {
                // SI SUCEDE UN ERROR DEVOLVEMOS FALSO
                b_OcurrioError = xMiFuncion.booOcurrioError;
                c_ErrorMensaje = xMiFuncion.StrErrorMensaje;
                n_ErrorNumber  = xMiFuncion.IntErrorNumber;
                booOk          = false;
                trans.Rollback();
                return(booOk);
            }

            return(booOk);
        }