private void btnCarga_ClickBefore(object sboObject, SAPbouiCOM.SBOItemEventArg pVal, out bool BubbleEvent) { BubbleEvent = true; mListObjLogin = new List <LoginDTO>(); AccountsDAO lObjAccounts = null; string lStrCtaPuente = ""; bool lBolResult = Check_txts(); if (lBolResult && gLstNomina.Count > 0) { //Tipo de Cambio USD if (!CheckCurrencyRate()) { Application.SBO_Application.StatusBar.SetText("Proceso Cancelado. Actualice el tipo de cambio USD.", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error); return; } try { this.UIAPIRawForm.Freeze(true); mObjJournalEntries = (SAPbobsCOM.JournalEntries)DIApplication.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oJournalEntries); mListObjLogin = GetSetupLogin(); LoginDTO lObjLoginDTO = mListObjLogin.FirstOrDefault(x => x.Code == int.Parse(lStrValueCmb)); lStrCtaPuente = lObjLoginDTO.AccountingAccount; if (lObjLoginDTO != null) { //Existe Cuentas string lStrResult = string.Empty; string lStrYear = txtYear.Value; string lStrPeriod = cmbPeriod.Value; string lStrNo = txtNo.Value; Application.SBO_Application.StatusBar.SetText("Procesando cuentas contables... Porfavor espere", SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Warning); lObjAccounts = new AccountsDAO(); var lVarGroupAcc = from p in gLstNomina group p by p.CUENTA into grouped select grouped; lStrResult = lObjAccounts.CheckAccounts(lVarGroupAcc); if (lStrResult != string.Empty) { Application.SBO_Application.StatusBar.SetText("Proceso Cancelado. Actualice las cuentas." + lStrResult, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error); return; } Application.SBO_Application.StatusBar.SetText("Procesando centros de costos... Porfavor espere", SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Warning); //Existe Centro de Costos lStrResult = string.Empty; lObjAccounts = new AccountsDAO(); var lVarGpCC = from p in gLstNomina group p by p.CUENTA2 into grouped select grouped; lStrResult = lObjAccounts.CheckCostingCode(lVarGpCC); if (lStrResult != string.Empty) { Application.SBO_Application.StatusBar.SetText("Proceso Cancelado. Actualice los Centros de Costo." + lStrResult, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error); return; } mDoubleImpoDedu = 0.0; mDoubleImpoPerc = 0.0; //Obtener Clave de SAP en empleados List <EmployeesDTO> lLstEmployeesDTO = mObjEmployeesDAO.GetEmployeeID(); var lObjQuery = from nom in gLstNomina join emp in lLstEmployeesDTO on nom.ATRAB equals emp.IdEmpSAP select new { nom, emp }; List <string> lLstMissingEmp = new List <string>(); foreach (var lObjQItem in lObjQuery) { if (lObjQItem.emp.IdEmpNomina == null) { lLstMissingEmp.Add(lObjQItem.emp.FullName); } lObjQItem.nom.ATRAB = (int?)lObjQItem.emp.IdEmpNomina; } if (lLstMissingEmp.Count > 0) { string lStrMissingEmp = string.Empty; foreach (var lObjEmpItem in lLstMissingEmp.Distinct().ToList()) { lStrMissingEmp += lObjEmpItem + ", "; } Application.SBO_Application.MessageBox("Para continuar, registre en SAP los siguientes empleados: " + lStrMissingEmp); NewSearch(); return; } mObjJournalEntries = PopulateJournalEntries(); //encabezado mObjJournalEntries = PopulateDetails(mObjJournalEntries, gLstNomina, lStrCtaPuente); //lineas int lIntRespJournal = mObjJournalEntries.Add(); if (lIntRespJournal == 0) { NewSearch(); Application.SBO_Application.MessageBox("Proceso terminado. Se cargo con exito el asiento contable"); Application.SBO_Application.StatusBar.SetText("Proceso terminado. Se cargo con exito el asiento contable", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success); } else { int lIntError = 0; string lStrError = string.Empty; string xdxd = DIApplication.Company.GetLastErrorDescription(); DIApplication.Company.GetLastError(out lIntError, out lStrError); Application.SBO_Application.StatusBar.SetText("Proceso Cancelado. Error al cargar el asiento contable " + lStrError, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error); } } else { Application.SBO_Application.StatusBar.SetText("No se puedo establecer la conexión con el Servidor de Nómina", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning); } } catch (Exception ex) { Application.SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error); } finally { this.UIAPIRawForm.Freeze(false); MemoryUtility.ReleaseComObject(mObjJournalEntries); //btnCarga.Item.Enabled = false; } } else { Application.SBO_Application.StatusBar.SetText("No hay datos a importar. Favor de primero Buscar Nómina", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning); } }