private void CargarCtaSII()
        {
            SAPbouiCOM.ProgressBar oProgressBar = null;
            Int32 NroLineas;

            System.Data.DataTable dtConceptos;
            Boolean bRegistroOk;
            String  sHojaExcel;
            String  sCuenta;
            String  sRegistro;
            String  Padre;
            //String Hijo;
            String           sPeriodoActual;
            String           strConn;
            Boolean          bIngresaConceptos = false;
            DataSet          ADOQueryExcel;
            Int32            Entry;
            OleDbDataAdapter adapter;
            String           sPathArchivo = "";

            try
            {
                sPathArchivo = Directory.GetCurrentDirectory() + "\\SQLs\\CL\\Carga\\DiccionarioSII.xls";
                sHojaExcel   = "[CTASII$]";
                strConn      = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Excel 8.0;Mode=ReadWrite";
                strConn      = String.Format(strConn, sPathArchivo);

                adapter       = new OleDbDataAdapter("Select * from [CTASII$]", strConn);
                ADOQueryExcel = new DataSet();
                try
                {
                    adapter.Fill(ADOQueryExcel, "CTASII");
                    dtConceptos = new System.Data.DataTable();
                    dtConceptos = ADOQueryExcel.Tables["CTASII"];
                }
                catch //(Exception y)
                {
                    FSBOApp.StatusBar.SetText("Error leyendo archivo excel...", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Error);
                    return;
                }

                if (dtConceptos.Rows.Count == 0)
                {
                    FSBOApp.StatusBar.SetText("No existen Cuentas SII para importar...", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Error);
                    return;
                }

                oProgressBar = FSBOApp.StatusBar.CreateProgressBar("Importando Cuentas SII...", dtConceptos.Rows.Count + 2, false);
                NroLineas    = 1;
                foreach (DataRow oRow in dtConceptos.Rows)
                {
                    bIngresaConceptos = false;
                    sCuenta           = oRow.Field <String>("Cuenta");
                    if (sCuenta != null)
                    {
                        sRegistro = Convert.ToString(oRow.Field <Double>("Registro"));

                        if (Convert.ToString(oRow.Field <String>("Glosa")).Trim() == "")
                        {
                            s = @"UPDATE {0} SET validacion = 'Debe ingresar Glosa' where [Registro] = {1}";
                            s = String.Format(s, sHojaExcel, sRegistro);
                            Funciones.EjecutarSQLOleDb(s, strConn);
                        }
                        else
                        {
                            bIngresaConceptos = true;
                        }


                        if (bIngresaConceptos)
                        {
                            oDBDSHeader.Clear();

                            oDBDSHeader.InsertRecord(0);
                            oDBDSHeader.SetValue("U_Cuenta", 0, Convert.ToString(oRow.Field <String>("Cuenta")).Trim());
                            oDBDSHeader.SetValue("U_Desc", 0, Convert.ToString(oRow.Field <String>("Glosa")).Trim());
                            oDBDSHeader.SetValue("U_Clasif", 0, Convert.ToString(oRow.Field <String>("Clasificacion")).Trim());

                            Entry = Funciones.AddDataSourceInt1("VID_FEPLANCTA", oDBDSHeader, "", null, "", null, "", null);


                            if (Entry > 0)
                            {
                                var ss = FCmpny.GetNewObjectKey();
                                s = @"UPDATE {0} SET validacion = 'OK' WHERE [Registro] = {1}";
                                s = String.Format(s, sHojaExcel, sRegistro);
                            }
                            else
                            {
                                var err = FCmpny.GetLastErrorDescription();
                                s = @"UPDATE {0} SET validacion = 'Error al crear {1}' WHERE [Registro] = {2}";
                                s = String.Format(s, sHojaExcel, err, sRegistro);
                            }
                            Funciones.EjecutarSQLOleDb(s, strConn);
                        }
                    }
                    else
                    {
                        oProgressBar.Value = oProgressBar.Maximum;
                        break;
                    }

                    oProgressBar.Value = NroLineas;
                    NroLineas          = NroLineas + 1;
                }

                FSBOApp.StatusBar.SetText("Fin de la importación", BoMessageTime.bmt_Long, BoStatusBarMessageType.smt_Success);
                FSBOApp.MessageBox("Fin de la importación", 1, "Ok", "", "");
            }
            catch (Exception e)
            {
                FSBOApp.MessageBox(e.Message + " ** Trace: " + e.StackTrace, 1, "Ok", "", "");
                OutLog("Error importando Conceptos desde: " + sPathArchivo + ". Error: " + e.Message + " ** Trace: " + e.StackTrace);
            }
            finally
            {
                if (oProgressBar != null)
                {
                    oProgressBar.Stop();
                }
                FSBOf._ReleaseCOMObject(oProgressBar);
            }
        }
        private void Guardar_Registros()
        {
            String CardCode;
            String CardName;
            String Activado;
            Int32  DocEntry;
            Int32  lRetCode;

            SAPbouiCOM.ProgressBar oProgressBar = null;

            oForm.Freeze(true);
            try
            {
                FSBOApp.StatusBar.SetText("Inicio de actualización lista negra", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Success);
                oProgressBar = FSBOApp.StatusBar.CreateProgressBar("Actualizando lista negra...", odt.Rows.Count, false);

                for (Int32 iCont_1 = 0; iCont_1 < odt.Rows.Count; iCont_1++)
                {
                    if (((System.String)odt.GetValue("U_CardCode", iCont_1)).Trim().Length > 0)
                    {
                        oDBDSHeader.Clear();
                        oDBDSHeader.InsertRecord(0);

                        DocEntry = ((System.Int32)odt.GetValue("DocEntry", iCont_1));
                        CardCode = ((System.String)odt.GetValue("U_CardCode", iCont_1)).Trim();
                        CardName = ((System.String)odt.GetValue("U_CardName", iCont_1)).Trim();
                        s        = ((System.String)odt.GetValue("U_Activado", iCont_1)).Trim();
                        if (s == "")
                        {
                            Activado = "N";
                        }
                        else
                        {
                            Activado = s;
                        }
                        oDBDSHeader.SetValue("U_CardCode", 0, CardCode);
                        oDBDSHeader.SetValue("U_CardName", 0, CardName);
                        oDBDSHeader.SetValue("U_Activado", 0, Activado);

                        if (DocEntry != 0)
                        {
                            oDBDSHeader.SetValue("DocEntry", 0, DocEntry.ToString());
                            lRetCode = Funciones.UpdDataSourceInt1("VID_FELISTANE", oDBDSHeader, "", null, "", null, "", null);
                        }
                        else
                        {
                            lRetCode = Funciones.AddDataSourceInt1("VID_FELISTANE", oDBDSHeader, "", null, "", null, "", null);
                        }

                        if (lRetCode == 0)
                        {
                            FSBOApp.StatusBar.SetText("No se ha actualizado proveedor " + CardCode, BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Error);
                        }
                        else
                        {
                            FSBOApp.StatusBar.SetText("Se ha actualizado proveedor " + CardCode, BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Success);
                        }
                    }
                    oProgressBar.Value = iCont_1 + 1;
                }
                oProgressBar.Value = oProgressBar.Maximum;

                oForm.Mode = SAPbouiCOM.BoFormMode.fm_OK_MODE;
                CargarGrid();
            }
            catch (Exception e)
            {
                FSBOApp.StatusBar.SetText(e.Message, BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Error);
                OutLog("Guardar_Registros: " + e.Message + " ** Trace: " + e.StackTrace);
            }
            finally
            {
                oForm.Freeze(false);
                oProgressBar.Stop();
                FSBOf._ReleaseCOMObject(oProgressBar);
            }
        }
        private void Exportar()
        {
            String      path;
            String      xmlString = "";
            String      Periodo   = "";
            String      PeriodoD  = "";
            String      PeriodoH  = "";
            XmlDocument oXml      = null;

            System.Object[] array1;

            try
            {
                if (odt.IsEmpty)
                {
                    FSBOApp.StatusBar.SetText("No se encontrado datos para exportar", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Warning);
                }
                else
                {
                    if (!Directory.Exists("C:\\Libros Contable Elect"))
                    {
                        Directory.CreateDirectory("C:\\Libros Contable Elect");
                    }
                    //path = "C:\\Libros Contable Elect\\DICC" + Periodo.Replace("-","") + ".xml";

                    if (oForm.Title == "Libro Diario y Mayor")
                    {
                        Periodo = ((System.String)((ComboBox)oForm.Items.Item("Periodo").Specific).Selected.Description).Trim();
                    }
                    else if (oForm.Title == "Balance")
                    {
                        PeriodoD = ((System.String)((ComboBox)oForm.Items.Item("PeriodoD").Specific).Selected.Description).Trim();
                        PeriodoH = ((System.String)((ComboBox)oForm.Items.Item("PeriodoH").Specific).Selected.Description).Trim();
                    }
                    else if (oForm.Title == "Diccionario")
                    {
                        Periodo = ((System.String)((ComboBox)oForm.Items.Item("Periodo").Specific).Selected.Description).Trim();
                    }


                    if (oForm.Title == "Diccionario")
                    {
                        //xmlString = CrearXMLDiccionario(Periodo);
                        array1    = new System.Object[3];
                        array1[0] = Periodo;
                        array1[1] = odt;
                        array1[2] = FSBOApp;
                        var miExtensionAssembly = System.Reflection.Assembly.LoadFile(System.IO.Path.GetDirectoryName(TMultiFunctions.ParamStr(0)) + "\\LibrosElectronicos.dll");
                        var miExtensionType     = miExtensionAssembly.GetType("LibrosElectronicosXml.LEXml");
                        var miExtensionObjeto   = Activator.CreateInstance(miExtensionType);
                        xmlString = ((System.String)miExtensionObjeto.GetType().InvokeMember("CrearXMLDiccionario", System.Reflection.BindingFlags.InvokeMethod, System.Type.DefaultBinder, miExtensionObjeto, array1));
                        FSBOf._ReleaseCOMObject(miExtensionAssembly);
                        FSBOf._ReleaseCOMObject(miExtensionType);
                        FSBOf._ReleaseCOMObject(miExtensionObjeto);
                    }
                    else if (oForm.Title == "Libro Diario y Mayor")
                    {
                        //xmlString = LibrosElectronicosXml.LEXml.CrearXMLLibroDiarioMayor(Periodo, ref odt, ref odt2, ref FSBOApp);
                        array1    = new System.Object[4];
                        array1[0] = Periodo;
                        array1[1] = odt;
                        array1[2] = odt2;
                        array1[3] = FSBOApp;
                        var miExtensionAssembly = System.Reflection.Assembly.LoadFile(System.IO.Path.GetDirectoryName(TMultiFunctions.ParamStr(0)) + "\\LibrosElectronicos.dll");
                        var miExtensionType     = miExtensionAssembly.GetType("LibrosElectronicosXml.LEXml");
                        var miExtensionObjeto   = Activator.CreateInstance(miExtensionType);
                        xmlString = ((System.String)miExtensionObjeto.GetType().InvokeMember("CrearXMLLibroDiarioMayor", System.Reflection.BindingFlags.InvokeMethod, System.Type.DefaultBinder, miExtensionObjeto, array1));
                        FSBOf._ReleaseCOMObject(miExtensionAssembly);
                        FSBOf._ReleaseCOMObject(miExtensionType);
                        FSBOf._ReleaseCOMObject(miExtensionObjeto);
                    }
                    else if (oForm.Title == "Balance")
                    {
                        xmlString = CrearXMLBalance(PeriodoD, PeriodoH);

                        /*array1 = new System.Object[4];
                         * array1[0] = PeriodoD;
                         * array1[1] = PeriodoH;
                         * array1[2] = odt;
                         * array1[3] = FSBOApp;
                         * var miExtensionAssembly = System.Reflection.Assembly.LoadFile(System.IO.Path.GetDirectoryName(TMultiFunctions.ParamStr(0)) + "\\LibrosElectronicos.dll");
                         * var miExtensionType = miExtensionAssembly.GetType("LibrosElectronicosXml.LEXml");
                         * var miExtensionObjeto = Activator.CreateInstance(miExtensionType);
                         * xmlString = ((System.String)miExtensionObjeto.GetType().InvokeMember("CrearXMLBalance", System.Reflection.BindingFlags.InvokeMethod, System.Type.DefaultBinder, miExtensionObjeto, array1));
                         * FSBOf._ReleaseCOMObject(miExtensionAssembly);
                         * FSBOf._ReleaseCOMObject(miExtensionType);
                         * FSBOf._ReleaseCOMObject(miExtensionObjeto);*/
                    }

                    if (xmlString == "")
                    {
                        FSBOApp.StatusBar.SetText("No se ha creado el XML", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Error);
                    }
                    else
                    {
                        oXml = new XmlDocument();
                        oXml.LoadXml(xmlString);

                        if (oForm.Title == "Diccionario")
                        {
                            if (File.Exists("C:\\Libros Contable Elect\\DICC" + Periodo.Replace("-", "") + ".xml"))
                            {
                                File.Delete("C:\\Libros Contable Elect\\DICC" + Periodo.Replace("-", "") + ".xml");
                            }
                            oXml.Save("C:\\Libros Contable Elect\\DICC" + Periodo.Replace("-", "") + ".xml");
                            FSBOApp.StatusBar.SetText("Exportado satisfactoriamente en C:\\Libros Contable Elect\\", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Success);
                        }
                        else if (oForm.Title == "Libro Diario y Mayor")
                        {
                            if (File.Exists("C:\\Libros Contable Elect\\LDIMA" + Periodo.Replace("-", "") + ".xml"))
                            {
                                File.Delete("C:\\Libros Contable Elect\\LDIMA" + Periodo.Replace("-", "") + ".xml");
                            }
                            oXml.Save("C:\\Libros Contable Elect\\LDIMA" + Periodo.Replace("-", "") + ".xml");
                            FSBOApp.StatusBar.SetText("Exportado satisfactoriamente en C:\\Libros Contable Elect\\", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Success);
                        }
                        else if (oForm.Title == "Balance")
                        {
                            if (File.Exists("C:\\Libros Contable Elect\\BALANCE" + PeriodoH.Replace("-", "") + ".xml"))
                            {
                                File.Delete("C:\\Libros Contable Elect\\BALANCE" + PeriodoH.Replace("-", "") + ".xml");
                            }
                            oXml.Save("C:\\Libros Contable Elect\\BALANCE" + PeriodoH.Replace("-", "") + ".xml");
                            FSBOApp.StatusBar.SetText("Exportado satisfactoriamente en C:\\Libros Contable Elect\\", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Success);
                        }
                    }
                }
            }
            catch (Exception x)
            {
                FSBOApp.StatusBar.SetText(x.Message + " ** Trace: " + x.StackTrace, BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Error);
                OutLog("Exportar: " + x.Message + " ** Trace: " + x.StackTrace);
            }
        }