private void CuentaSAP(Int32 Linea)
        {
            IvkFormInterface oFormvk  = null;
            String           oPath    = System.IO.Path.GetDirectoryName(TMultiFunctions.ParamStr(0));
            String           sArchivo = "";
            String           oUid;

            try
            {
                oDBDSHeader.Clear();
                oDBDSHeader.InsertRecord(0);
                oDBDSHeader.SetValue("DocEntry", 0, oDataTable.GetValue("DocEntry", Linea).ToString().Trim());
                oDBDSHeader.SetValue("U_Cuenta", 0, ((System.String)oDataTable.GetValue("Cuenta", Linea)).Trim());
                oDBDSHeader.SetValue("U_Desc", 0, ((System.String)oDataTable.GetValue("Descripcion", Linea)).Trim());
                oDBDSHeader.SetValue("U_Clasif", 0, ((System.String)oDataTable.GetValue("Clasificacion", Linea)).Trim());

                oFormvk                = (IvkFormInterface)(new TCuentaSAP());
                TCuentaSAP.DocEntry    = ((System.Int32)oDataTable.GetValue("DocEntry", Linea));
                TCuentaSAP.oDBDSHeader = oDBDSHeader;

                oUid = FSBOf.generateFormId(FGlobalSettings.SBOSpaceName, FGlobalSettings);
                oFormvk.InitForm(oUid, "forms\\", ref FSBOApp, ref FCmpny, ref FSBOf, ref FGlobalSettings);
                FoForms.Add(oFormvk);
            }
            catch (Exception e)
            {
                FSBOApp.StatusBar.SetText(e.Message + " ** Trace: " + e.StackTrace, BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Error);
                OutLog("Error Abrri Sueldos: " + e.Message + " ** Trace: " + e.StackTrace);
            }
        }
Esempio n. 2
0
        public override void initApp()
        {
            String XlsFile;
            String s;

            base.initApp();
            String  Local;
            Boolean bCargar = false;

            try
            {
                // compilacion SQL HANA
                GlobalSettings.SBO_f   = SBOFunctions;
                GlobalSettings.SBOMeta = SBOMetaData;
                //


                //oLog.LogFile = "C:\\Visualk\\xxx.log";
                oLog.LogFile = System.IO.Path.GetDirectoryName(TMultiFunctions.ParamStr(0)) + "\\VD.log";
                SAPbobsCOM.Recordset oRecordSet;
                oRecordSet = (SAPbobsCOM.Recordset)(SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset));
                try
                {
                    if (GlobalSettings.RunningUnderSQLServer)
                    {
                        s = "SELECT SUPERUSER FROM OUSR WHERE USER_CODE = '{0}'";
                    }
                    else
                    {
                        s = @"SELECT ""SUPERUSER"" FROM ""OUSR"" WHERE ""USER_CODE"" = '{0}'";
                    }
                    s = String.Format(s, SBOCompany.UserName.Trim());
                    oRecordSet.DoQuery(s);
                    if (((System.String)oRecordSet.Fields.Item("SUPERUSER").Value).Trim() == "Y")
                    {
                        bCargar = true;
                    }
                }
                catch
                {
                    if (bCargar == false)
                    {
                        SBOApplication.MessageBox("El addon se esta iniciando por primera vez, debe inicar con un super usuario");
                    }
                }
                finally
                {
                    SBOFunctions._ReleaseCOMObject(oRecordSet);
                    oRecordSet = null;
                }


                //if (SBOCompany.UserName == "manager")
                if (bCargar)
                {
                    XlsFile = System.IO.Path.GetDirectoryName(TMultiFunctions.ParamStr(0)) + "\\Docs\\UDFFELEC.xls";
                    if (!SBOFunctions.ValidEstructSHA1(XlsFile))
                    {
                        oLog.OutLog("InitApp: Estructura de datos 1 - Facturación Electronica");
                        SBOApplication.StatusBar.SetText("Inicializando AddOn Factura Electronica(1).", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Warning);
                        if (!SBOMetaData.SyncTablasUdos("1.1", XlsFile))
                        {
                            SBOFunctions.DeleteSHA1FromTable("EDAG.xls");
                            oLog.OutLog("InitApp: sincronización de Estructura de datos fallo");
                            CloseSplash();
                            SBOApplication.MessageBox("Estructura de datos con problemas, consulte a soporte...", 1, "Ok", "", "");
                            Halt(0);
                        }
                    }

                    XlsFile = System.IO.Path.GetDirectoryName(TMultiFunctions.ParamStr(0)) + "\\Docs\\UDFFELECCL.xls";
                    if (!SBOFunctions.ValidEstructSHA1(XlsFile))
                    {
                        oLog.OutLog("InitApp: Estructura de datos 2 - Facturación Electronica CL");
                        SBOApplication.StatusBar.SetText("Inicializando AddOn Factura Electronica(2).", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Warning);
                        if (!SBOMetaData.SyncTablasUdos("1.1", XlsFile))
                        {
                            SBOFunctions.DeleteSHA1FromTable("UDFFELECCL.xls");
                            oLog.OutLog("InitApp: sincronización de Estructura de datos fallo");
                            SBOApplication.MessageBox("Estructura de datos con problemas, consulte a soporte...", 1, "Ok", "", "");
                        }
                    }


                    XlsFile = System.IO.Path.GetDirectoryName(TMultiFunctions.ParamStr(0)) + "\\Docs\\UDFSAP.xls";
                    if (!SBOFunctions.ValidEstructSHA1(XlsFile))
                    {
                        oLog.OutLog("InitApp: Estructura de datos 3 - Facturación Electronica CL");
                        SBOApplication.StatusBar.SetText("Inicializando AddOn Factura Electronica(3).", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Warning);
                        if (!SBOMetaData.SyncTablasUdos("1.1", XlsFile))
                        {
                            SBOFunctions.DeleteSHA1FromTable("UDFSAP.xls");
                            oLog.OutLog("InitApp: sincronización de Estructura de datos fallo");
                            SBOApplication.MessageBox("Estructura de datos con problemas, consulte a soporte...", 1, "Ok", "", "");
                        }
                    }
                }

                oLog.DebugLvl             = 20;
                MainObj[0].GlobalSettings = GlobalSettings;
                MainObj[0].SBOApplication = SBOApplication;
                MainObj[0].SBOCompany     = SBOCompany;
                MainObj[0].oLog           = oLog;
                MainObj[0].SBOFunctions   = SBOFunctions;


                //SetFiltros();


                MainObj[0].AddMenus();

                InitOK = true;
                oLog.OutLog("App SBO in C# - Init!");
                SBOApplication.StatusBar.SetText("Aplicación Inicializada.", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Success);


                if (1 == 1) //(SBOFunctions.AccessStr.Substring(10,1) = 'P') then
                {
                    GlobalSettings.SBO_f      = SBOFunctions;
                    MainObj[0].GlobalSettings = GlobalSettings;
                    MainObj[0].SBOApplication = SBOApplication;
                    MainObj[0].SBOCompany     = SBOCompany;
                    MainObj[0].oLog           = oLog;
                    MainObj[0].SBOFunctions   = SBOFunctions;
                }

                SetFiltros();

                if (1 == 1) // (SBOFunctions.AccessStr.Substring(10,1) = 'P') then
                {
                    //MainObj[0].AddMenus();
                    SAPbouiCOM.Menus    oMenus    = null;
                    SAPbouiCOM.MenuItem oMenuItem = null;


                    System.Xml.XmlDocument oXmlDoc = null;
                    oXmlDoc = new System.Xml.XmlDocument();

                    oXmlDoc.Load(System.IO.Path.GetDirectoryName(TMultiFunctions.ParamStr(0)) + "\\Menus\\RemoveMenu.xml");


                    string sXML = oXmlDoc.InnerXml.ToString();
                    SBOApplication.LoadBatchActions(ref sXML);

                    oXmlDoc.Load(System.IO.Path.GetDirectoryName(TMultiFunctions.ParamStr(0)) + "\\Menus\\Menu.xml");

                    sXML = oXmlDoc.InnerXml.ToString();
                    SBOApplication.LoadBatchActions(ref sXML);

                    //GlobalSettings.AddMenusRepAux(False);
                    //GlobalSettings.AddMenusRepAux(True);
                }

                InitOK = true;
                oLog.OutLog("C# - Shine your crazy diamond!");
                SBOApplication.StatusBar.SetText("Aplicación Inicializada.", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Success);
            }
            catch (Exception ex)
            {
                oLog.OutLog("Error iniApp, " + ex.Message + ", TRACE " + ex.StackTrace);
            }
            finally
            {
                CloseSplash();
            }
        }
        private void MostrarPDF(Int32 Linea)
        {
            String  Code;
            String  sXml;
            String  TipoDoc;
            String  Folio;
            String  RUTEmisor;
            String  oPath;
            String  sNombreArchivo;
            String  sNombrePDF;
            Boolean flag = true;
            String  Pass = "";

            try
            {
                oGrid     = (Grid)(oForm.Items.Item("grid").Specific);
                Code      = Convert.ToString(((System.Int32)oGrid.DataTable.GetValue("DocEntry", Linea)), _nf);
                sXml      = ((System.String)oGrid.DataTable.GetValue("xml", Linea));
                TipoDoc   = ((System.String)oGrid.DataTable.GetValue("TipoDoc", Linea));
                RUTEmisor = ((System.String)oGrid.DataTable.GetValue("RUT", Linea));
                Folio     = Convert.ToString(((System.Int32)oGrid.DataTable.GetValue("Folio", Linea)), _nf);
                if (sXml != "")
                {
                    oPath = System.IO.Path.GetDirectoryName(TMultiFunctions.ParamStr(0));
                    try
                    {
                        if (GlobalSettings.RunningUnderSQLServer)
                        {
                            sNombreArchivo = oPath + "\\Reports\\CL\\SQL\\ReporteXML.rpt";
                        }
                        else
                        {
                            sNombreArchivo = oPath + "\\Reports\\CL\\HANA\\ReporteXML.rpt";
                        }
                        sNombrePDF = oPath + @"\PDF\" + RUTEmisor + "_" + TipoDoc + "_" + Folio + ".pdf";
                        if (File.Exists(sNombrePDF))
                        {
                            System.Diagnostics.Process proc = new System.Diagnostics.Process();
                            proc.StartInfo.FileName = sNombrePDF;
                            proc.Start();
                        }
                        else
                        {
                            FSBOf.AddRepKey(Code, "FEREPORTXML", "FEREPORTXML");//oForm.TypeEx);
                            GlobalSettings.CrystalReportFileName = sNombreArchivo;
                            try
                            {
                                FSBOApp.Menus.Item("4873").Activate();
                            }
                            catch { }

                            /*FSBOApp.Menus.Item("4873").Activate();
                             * var oFormB = FSBOApp.Forms.ActiveForm;
                             * ((EditText)oFormB.Items.Item("410000004").Specific).Value = sNombreArchivo;
                             * oFormB.Items.Item("410000005").Click(BoCellClickType.ct_Regular);*/
                        }
                    }
                    catch (Exception p)
                    {
                        FSBOApp.StatusBar.SetText(p.Message + " ** Trace: " + p.StackTrace, BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Error);
                        OutLog("Cargar Crystal: " + p.Message + " ** Trace: " + p.StackTrace);
                    }
                }
                else
                {
                    FSBOApp.StatusBar.SetText("No se ha encontrado xml que genera PDF", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Warning);
                }
            }
            catch (Exception x)
            {
                FSBOApp.StatusBar.SetText(x.Message + " ** Trace: " + x.StackTrace, BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Error);
                OutLog("MostrarPDF: " + x.Message + " ** Trace: " + x.StackTrace);
            }
        }
        }//fin InitForm

        public new void FormEvent(String FormUID, ref SAPbouiCOM.ItemEvent pVal, ref Boolean BubbleEvent)
        {
            //SAPbouiCOM.DataTable oDataTable;
            //inherited FormEvent(FormUID,var pVal,var BubbleEvent);
            String Local;

            SAPbouiCOM.CheckBox oCheckBox;
            base.FormEvent(FormUID, ref pVal, ref BubbleEvent);


            try
            {
                if ((pVal.EventType == BoEventTypes.et_ITEM_PRESSED) && (pVal.BeforeAction == true))
                {
                    if ((pVal.ItemUID == "1") && ((oForm.Mode == BoFormMode.fm_ADD_MODE) || (oForm.Mode == BoFormMode.fm_UPDATE_MODE)))
                    {
                        s = "1";
                        oDBDSHeader.SetValue("Code", 0, s);
                        if (1 != FSBOApp.MessageBox("¿ Desea actualizar los parametros ?", 1, "Ok", "Cancelar", ""))
                        {
                            BubbleEvent = false;
                        }
                        else
                        {
                            BubbleEvent = false;

                            if (oForm.SupportedModes == 1)
                            {
                                s = "1";
                            }
                            else
                            {
                                s = "3";
                            }

                            if (AddDatos(s))
                            {
                                FSBOApp.StatusBar.SetText("Datos actualizados satisfactoriamente", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Success);
                                oForm.Mode = BoFormMode.fm_OK_MODE;
                                //Remover menu y colocar los nuevos segun parametros


                                System.Xml.XmlDocument oXmlDoc = null;
                                oXmlDoc = new System.Xml.XmlDocument();
                                oXmlDoc.Load(System.IO.Path.GetDirectoryName(TMultiFunctions.ParamStr(0)) + "\\Menus\\RemoveMenuPE.xml");

                                string sXML = oXmlDoc.InnerXml.ToString();
                                FSBOApp.LoadBatchActions(ref sXML);

                                oXmlDoc.Load(System.IO.Path.GetDirectoryName(TMultiFunctions.ParamStr(0)) + "\\Menus\\Menu.xml");

                                sXML = oXmlDoc.InnerXml.ToString();
                                FSBOApp.LoadBatchActions(ref sXML);
                            }
                        }
                    }
                }

                if ((pVal.EventType == BoEventTypes.et_ITEM_PRESSED) && (!pVal.BeforeAction))
                {
                    if (pVal.ItemUID == "btnProcFE")
                    {
                        CargarProcedimientos();
                    }
                }
            }
            catch (Exception e)
            {
                if (FCmpny.InTransaction)
                {
                    FCmpny.EndTransaction(BoWfTransOpt.wf_RollBack);
                }
                FSBOApp.StatusBar.SetText(e.Message + " ** Trace: " + e.StackTrace, BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Error);
                OutLog("FormEvent: " + e.Message + " ** Trace: " + e.StackTrace);
            }
        }//fin FormEvent
        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);
            }
        }