}//fin MenuEvent private void GuardarRegistros() { TFunctions Reg; Int32 i; Int32 DocEntryAsig; String User, Pass; try { if (ValidarMatrix()) { Reg = new TFunctions(); Reg.SBO_f = FSBOf; oMtx.FlushToDataSource(); FCmpny.StartTransaction(); i = 0; while (i < oMtx.RowCount) { User = (System.String)(oDBDSH.GetValue("U_Usuario", i)); Pass = (System.String)(oDBDSH.GetValue("U_Password", i)); //s = Reg.Encriptar(Pass); oDBDSH.SetValue("U_Password", i, Pass); if ((System.String)(oDBDSH.GetValue("DocEntry", i)) == "") { DocEntryAsig = Reg.FEMultiSocAdd((System.String)(oDBDSH.GetValue("U_Servidor", i)), (System.String)(oDBDSH.GetValue("U_RUT", i)), (System.String)(oDBDSH.GetValue("U_Base", i)), (System.String)(oDBDSH.GetValue("U_Usuario", i)), (System.String)(oDBDSH.GetValue("U_Password", i)), (System.String)(oDBDSH.GetValue("U_Sociedad", i)), (System.String)(oDBDSH.GetValue("U_Habilitada", i))); oDBDSH.SetValue("DocEntry", i, DocEntryAsig.ToString()); } else { Reg.FEMultiSocUpt((System.String)(oDBDSH.GetValue("DocEntry", i)), (System.String)(oDBDSH.GetValue("U_Servidor", i)), (System.String)(oDBDSH.GetValue("U_RUT", i)), (System.String)(oDBDSH.GetValue("U_Base", i)), (System.String)(oDBDSH.GetValue("U_Usuario", i)), (System.String)(oDBDSH.GetValue("U_Password", i)), (System.String)(oDBDSH.GetValue("U_Sociedad", i)), (System.String)(oDBDSH.GetValue("U_Habilitada", i))); } //oDBDSH.SetValue("U_Password", i, Pass); i++; } FCmpny.EndTransaction(BoWfTransOpt.wf_Commit); oDBDSH.InsertRecord(i); oMtx.LoadFromDataSource(); oMtx.AutoResizeColumns(); FSBOApp.StatusBar.SetText("Sociedades registradas satisfactoriamente", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Success); } } catch (Exception e) { FSBOApp.MessageBox(e.Message + " ** Trace: " + e.StackTrace, 1, "Ok", "", ""); OutLog("GuardarRegistros: " + e.Message + " ** Trace: " + e.StackTrace); if (FCmpny.InTransaction) { FCmpny.EndTransaction(BoWfTransOpt.wf_RollBack); } } }//fin GuardarRegistros
private void GuardarRegistros() { SAPbouiCOM.Grid oGrid; Boolean Paso = false; String ObjType; Int32 DocEntry; String Tipo; String Serie; String Folio; Int32 lRetCode; String errMsg; Int32 errCode; XDocument miXMLDoc; XmlDocument oXml; String UserWS = ""; String PassWS = ""; String TaxIdNum = ""; String URL = ""; String ExternalFolio = ""; XmlNode oNode; SAPbobsCOM.Documents oDocs; SAPbobsCOM.StockTransfer oStock; SAPbobsCOM.Payments oPay; try { if (GlobalSettings.RunningUnderSQLServer) { s = @"SELECT T0.U_URLDarBaja 'URL', ISNULL(T0.U_UserWS,'') 'UserWS', ISNULL(T0.U_PassWS,'') 'PassWS', ISNULL(T0.U_MostrarXML,'N') 'MostrarXML', ISNULL(A0.TaxIdNum,'') 'TaxIdNum' FROM [@VID_FEPARAM] T0 , OADM A0"; } else { s = @"SELECT T0.""U_URLDarBaja"" ""URL"", IFNULL(T0.""U_UserWS"",'') ""UserWS"", IFNULL(T0.""U_PassWS"",'') ""PassWS"", IFNULL(T0.""U_MostrarXML"",'N') ""MostrarXML"", IFNULL(A0.""TaxIdNum"",'') ""TaxIdNum"" FROM ""@VID_FEPARAM"" T0, ""OADM"" A0"; } oRecordSet.DoQuery(s); if (oRecordSet.RecordCount == 0) { FSBOApp.StatusBar.SetText("No se ha ingresado URL", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Error); } else if (((System.String)oRecordSet.Fields.Item("URL").Value).Trim() == "") { FSBOApp.StatusBar.SetText("No se ha ingresado URL", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Error); } //else if (((System.String)oRecordSet.Fields.Item("UserWS").Value).Trim() == "") // throw new Exception("No se encuentra usuario en Parametros"); //else if (((System.String)oRecordSet.Fields.Item("PassWS").Value).Trim() == "") // throw new Exception("No se encuentra password en Parametros"); else if (((System.String)oRecordSet.Fields.Item("TaxIdNum").Value).Trim() == "") { throw new Exception("No se encuentra RUC de Emisor, Gestión -> Inicialización Sistema -> Detalle Sociedad -> Datos de Contabilidad -> ID fiscal general 1"); } else { UserWS = Funciones.DesEncriptar((System.String)(oRecordSet.Fields.Item("UserWS").Value).ToString().Trim()); PassWS = Funciones.DesEncriptar((System.String)(oRecordSet.Fields.Item("PassWS").Value).ToString().Trim()); TaxIdNum = ((System.String)oRecordSet.Fields.Item("TaxIdNum").Value).Trim(); URL = ((System.String)oRecordSet.Fields.Item("URL").Value).Trim(); } oGrid = ((SAPbouiCOM.Grid)oForm.Items.Item("grid").Specific); FCmpny.StartTransaction(); for (Int32 iLinea = 0; iLinea <= oGrid.DataTable.Rows.Count - 1; iLinea++) { if (((System.String)oGrid.DataTable.GetValue("Sel", iLinea)).Trim() == "Y") { try { Paso = true; ObjType = ((System.String)oGrid.DataTable.GetValue("ObjType", iLinea)); DocEntry = ((System.Int32)oGrid.DataTable.GetValue("DocEntry", iLinea)); Tipo = ((System.String)oGrid.DataTable.GetValue("TipoDoc", iLinea)); Serie = ((System.String)oGrid.DataTable.GetValue("Serie", iLinea)); Folio = ((System.String)oGrid.DataTable.GetValue("Folio", iLinea)); ExternalFolio = ((System.String)oGrid.DataTable.GetValue("ExtFolio", iLinea)); if (ObjType == "67") { oStock = ((SAPbobsCOM.StockTransfer)FCmpny.GetBusinessObject(BoObjectTypes.oStockTransfer)); if (oStock.GetByKey(DocEntry)) { lRetCode = oStock.Cancel(); } } else if (ObjType == "46") { oPay = ((SAPbobsCOM.Payments)FCmpny.GetBusinessObject(BoObjectTypes.oVendorPayments)); if (oPay.GetByKey(DocEntry)) { lRetCode = oPay.Cancel(); } } else { if (ObjType == "21") { oDocs = ((SAPbobsCOM.Documents)FCmpny.GetBusinessObject(BoObjectTypes.oPurchaseReturns)); } else if (ObjType == "15") { oDocs = ((SAPbobsCOM.Documents)FCmpny.GetBusinessObject(BoObjectTypes.oDeliveryNotes)); } else if (ObjType == "14") { oDocs = ((SAPbobsCOM.Documents)FCmpny.GetBusinessObject(BoObjectTypes.oCreditNotes)); } else if (ObjType == "203") { oDocs = ((SAPbobsCOM.Documents)FCmpny.GetBusinessObject(BoObjectTypes.oDownPayments)); } else { oDocs = ((SAPbobsCOM.Documents)FCmpny.GetBusinessObject(BoObjectTypes.oInvoices)); } if (oDocs.GetByKey(DocEntry)) { var oDocCancel = oDocs.CreateCancellationDocument(); lRetCode = oDocCancel.Add();// Cancel(); if (lRetCode != 0) { FCmpny.GetLastError(out errCode, out errMsg); throw new Exception("No se ha encontrado Documento " + Tipo + " " + Serie + "-" + Folio + ": " + errMsg); } else { //enviar baja al portal miXMLDoc = new XDocument( new XDeclaration("1.0", "utf-8", "yes") , new XElement("documentoelectronico", new XElement("DocNum", TaxIdNum), new XElement("DocType", Tipo), new XElement("IdDocumento", ExternalFolio.Trim() )) ); oXml = new XmlDocument(); using (var xmlReader = miXMLDoc.CreateReader()) { oXml.Load(xmlReader); } s = Funciones.UpLoadDocumentByUrl(oXml, null, GlobalSettings.RunningUnderSQLServer, URL, UserWS, PassWS, "D-" + ExternalFolio); oXml.LoadXml(s); oNode = oXml.DocumentElement.SelectSingleNode("/Error/ErrorCode"); string ticket = oNode.InnerText; oNode = oXml.DocumentElement.SelectSingleNode("/Error/ErrorText"); string errorText = oNode.InnerText; oNode = oXml.DocumentElement.SelectSingleNode("/Error/IdDocument"); string idDocument = oNode.InnerText; if (errorText != "OK") { FSBOApp.StatusBar.SetText("Mensaje: " + errorText + " " + Tipo + " " + Serie + "-" + Folio, BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Warning); } else { FSBOApp.StatusBar.SetText("Se ha creado cancelacion del documento " + Tipo + " " + Serie + "-" + Folio, BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Success); //insertar en la tabla y consultar por el estado mismo codigo que insert de factura } } } else { FSBOApp.StatusBar.SetText("No se ha encontrado Documento " + Tipo + " " + Serie + "-" + Folio, BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Warning); } } oDocs = null; oPay = null; oStock = null; } catch (Exception ss) { FSBOApp.StatusBar.SetText("Dar de Baja: " + ss.Message + " ** Trace: " + ss.StackTrace, BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Error); OutLog("Dar de Baja: " + ss.Message + " ** Trace: " + ss.StackTrace); if (FCmpny.InTransaction) { FCmpny.EndTransaction(BoWfTransOpt.wf_RollBack); } } } } if (!Paso) { FSBOApp.StatusBar.SetText("Debe seleccionar un documento minimo", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Warning); } else { if (FCmpny.InTransaction) { FCmpny.EndTransaction(BoWfTransOpt.wf_Commit); } } } catch (Exception e) { FSBOApp.StatusBar.SetText("GuardarRegistros: " + e.Message + " ** Trace: " + e.StackTrace, BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Error); OutLog("GuardarRegistros: " + e.Message + " ** Trace: " + e.StackTrace); if (FCmpny.InTransaction) { FCmpny.EndTransaction(BoWfTransOpt.wf_RollBack); } } }
}//fin FormDataEvent private void IngresarFolio(String sDocEntry, String ObjType) { Boolean FolioUnico = false; Int32 lRetCode; try { if (GlobalSettings.RunningUnderSQLServer) { s = @"select isnull(U_FolioGuia,'N') FolioUnico from [@VID_FEPARAM] where code = '1'"; } else { s = @"select IFNULL(""U_FolioGuia"",'N') ""FolioUnico"" from ""@VID_FEPARAM"" where ""Code"" = '1'"; } oRecordSet.DoQuery(s); if (oRecordSet.RecordCount > 0) { if ((System.String)(oRecordSet.Fields.Item("FolioUnico").Value) == "Y") { FolioUnico = true; } } if (FolioUnico) { var oTransfer = (SAPbobsCOM.StockTransfer)(FCmpny.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oStockTransfer)); FCmpny.StartTransaction(); if (GlobalSettings.RunningUnderSQLServer) { s = @"SELECT 'GE' BeginStr, NextNumber FROM NNM1 WHERE (ObjectCode = 'VD_FEEntreg')"; } else { s = @"SELECT 'GE' ""BeginStr"", ""NextNumber"" FROM ""NNM1"" WHERE (""ObjectCode"" = 'VD_FEEntreg')"; } oRecordSet.DoQuery(s); if (ObjType == "67") { if (oTransfer.GetByKey(Convert.ToInt32(sDocEntry))) { oTransfer.FolioNumber = (System.Int32)(oRecordSet.Fields.Item("NextNumber").Value); oTransfer.FolioPrefixString = (System.String)(oRecordSet.Fields.Item("BeginStr").Value); lRetCode = oTransfer.Update(); if (lRetCode != 0) { if (GlobalSettings.RunningUnderSQLServer) { s = @"UPDATE OWTR SET FolioPref = '{0}', FolioNum = '{1}', Printed = 'Y' WHERE DocEntry = {3}"; } else { s = @"UPDATE ""OWTR"" SET ""FolioPref"" = '{0}', ""FolioNum"" = '{1}', ""Printed"" = 'Y' WHERE ""DocEntry"" = {3}"; } s = String.Format(s, oTransfer.FolioPrefixString, Convert.ToString(oTransfer.FolioNumber), oTransfer.DocEntry); oRecordSet.DoQuery(s); } //actualiza siguiente numero folio para documento if (GlobalSettings.RunningUnderSQLServer) { s = @"UPDATE NNM1 SET NextFolio = {0} WHERE (Series = {1})"; } else { s = @"UPDATE ""NNM1"" SET ""NextFolio"" = {0} WHERE (""Series"" = {1})"; } s = String.Format(s, oTransfer.FolioNumber + 1, oTransfer.Series); oRecordSet.DoQuery(s); //actualiza siguiente numero folio para serie del addon entrega electronica if (GlobalSettings.RunningUnderSQLServer) { s = @"UPDATE NNM1 SET NextNumber = {0} WHERE (ObjectCode = 'VD_FEEntreg')"; } else { s = @"UPDATE ""NNM1"" SET ""NextNumber"" = {0} WHERE (""ObjectCode"" = 'VD_FEEntreg')"; } s = String.Format(s, oTransfer.FolioNumber + 1); oRecordSet.DoQuery(s); //actualiza LPgFolioN if (GlobalSettings.RunningUnderSQLServer) { s = @"update OWTR set LPgFolioN = FolioNum where DocEntry = {0}"; } else { s = @"update ""OWTR"" set ""LPgFolioN"" = ""FolioNum"" where ""DocEntry"" = {0}"; } s = String.Format(s, oTransfer.DocEntry); oRecordSet.DoQuery(s); } } else if (ObjType == "15") { var oDocumento = (SAPbobsCOM.Documents)(FCmpny.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDeliveryNotes)); if (oDocumento.GetByKey(Convert.ToInt32(sDocEntry))) { oDocumento.FolioNumber = (System.Int32)(oRecordSet.Fields.Item("NextNumber").Value); oDocumento.FolioPrefixString = (System.String)(oRecordSet.Fields.Item("BeginStr").Value); lRetCode = oDocumento.Update(); if (lRetCode != 0) { if (GlobalSettings.RunningUnderSQLServer) { s = @"UPDATE ODLN SET FolioPref = '{0}', FolioNum = '{1}', Printed = 'Y' WHERE DocEntry = {3}"; } else { s = @"UPDATE ""ODLN"" SET ""FolioPref"" = '{0}', ""FolioNum"" = '{1}', ""Printed"" = 'Y' WHERE ""DocEntry"" = {3}"; } s = String.Format(s, oDocumento.FolioPrefixString, Convert.ToString(oDocumento.FolioNumber), oDocumento.DocEntry); oRecordSet.DoQuery(s); } //actualiza siguiente numero folio para documento if (GlobalSettings.RunningUnderSQLServer) { s = @"UPDATE NNM1 SET NextFolio = {0} WHERE (Series = {1})"; } else { s = @"UPDATE ""NNM1"" SET ""NextFolio"" = {0} WHERE (""Series"" = {1})"; } s = String.Format(s, oDocumento.FolioNumber + 1, oDocumento.Series); oRecordSet.DoQuery(s); //actualiza siguiente numero folio para serie del addon entrega electronica if (GlobalSettings.RunningUnderSQLServer) { s = @"UPDATE NNM1 SET NextNumber = {0} WHERE (ObjectCode = 'VD_FEEntreg')"; } else { s = @"UPDATE ""NNM1"" SET ""NextNumber"" = {0} WHERE (""ObjectCode"" = 'VD_FEEntreg')"; } s = String.Format(s, oDocumento.FolioNumber + 1); oRecordSet.DoQuery(s); //actualiza LPgFolioN if (GlobalSettings.RunningUnderSQLServer) { s = @"update ODLN set LPgFolioN = FolioNum where DocEntry = {0}"; } else { s = @"update ""ODLN"" set ""LPgFolioN"" = ""FolioNum"" where ""DocEntry"" = {0}"; } s = String.Format(s, oDocumento.DocEntry); oRecordSet.DoQuery(s); } } else if (ObjType == "21") { var oDocumento = (SAPbobsCOM.Documents)(FCmpny.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseReturns)); if (oDocumento.GetByKey(Convert.ToInt32(sDocEntry))) { oDocumento.FolioNumber = (System.Int32)(oRecordSet.Fields.Item("NextNumber").Value); oDocumento.FolioPrefixString = (System.String)(oRecordSet.Fields.Item("BeginStr").Value); lRetCode = oDocumento.Update(); if (lRetCode != 0) { if (GlobalSettings.RunningUnderSQLServer) { s = @"UPDATE ORPD SET FolioPref = '{0}', FolioNum = '{1}', Printed = 'Y' WHERE DocEntry = {3}"; } else { s = @"UPDATE ""ORPD"" SET ""FolioPref"" = '{0}', ""FolioNum"" = '{1}', ""Printed"" = 'Y' WHERE ""DocEntry"" = {3}"; } s = String.Format(s, oDocumento.FolioPrefixString, Convert.ToString(oDocumento.FolioNumber), oDocumento.DocEntry); oRecordSet.DoQuery(s); } //actualiza siguiente numero folio para documento if (GlobalSettings.RunningUnderSQLServer) { s = @"UPDATE NNM1 SET NextFolio = {0} WHERE (Series = {1})"; } else { s = @"UPDATE ""NNM1"" SET ""NextFolio"" = {0} WHERE (""Series"" = {1})"; } s = String.Format(s, oDocumento.FolioNumber + 1, oDocumento.Series); oRecordSet.DoQuery(s); //actualiza siguiente numero folio para serie del addon entrega electronica if (GlobalSettings.RunningUnderSQLServer) { s = @"UPDATE NNM1 SET NextNumber = {0} WHERE (ObjectCode = 'VD_FEEntreg')"; } else { s = @"UPDATE ""NNM1"" SET ""NextNumber"" = {0} WHERE (""ObjectCode"" = 'VD_FEEntreg')"; } s = String.Format(s, oDocumento.FolioNumber + 1); oRecordSet.DoQuery(s); //actualiza LPgFolioN if (GlobalSettings.RunningUnderSQLServer) { s = @"update ORPD set LPgFolioN = FolioNum where DocEntry = {0}"; } else { s = @"update ""ORPD"" set ""LPgFolioN"" = ""FolioNum"" where ""DocEntry"" = {0}"; } s = String.Format(s, oDocumento.DocEntry); oRecordSet.DoQuery(s); } } FCmpny.EndTransaction(BoWfTransOpt.wf_Commit); } } catch (Exception e) { OutLog("IngresarFolio " + e.Message + " ** Trace: " + e.StackTrace); FSBOApp.StatusBar.SetText(e.Message, BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Error); // Captura errores no manejados if (FCmpny.InTransaction) { FCmpny.EndTransaction(BoWfTransOpt.wf_RollBack); } } }//fin IngresarFolio