private object[] GetKeys <T>(T obj, BoObjectTypes objType, string[] args) { Type type = typeof(T); object[] ret; ret = new object[args.Length]; for (int i = 0; i < args.Length; i++) { ret[i] = type.InvokeMember(args[i], BindingFlags.GetField | BindingFlags.GetProperty | BindingFlags.Public, null, obj, null); } if (objType == BoObjectTypes.oUserFields) { ret[1] = ExecuteSqlForObject <string>( String.Format(this.GetSQL("GetCUFDKey.sql"), ret[0], ret[1])); if (ret[1] == null) { ret[1] = "-1"; } } return(ret); }
public static int?GetDocEntryFromDocNum(BoObjectTypes type, int docNum, int?seriesCode = null) { using (var factory = new SboDisposableBusinessObjectFactory()) { var recordSet = factory.Create <Recordset>(BoObjectTypes.BoRecordset); if (!seriesCode.HasValue) { seriesCode = GetDefaultSeries(type).Series; } var objectTypeDefinition = ObjectTypeDefinitions.FirstOrDefault((def) => { return(def.ObjectType.Equals(type)); }); if (objectTypeDefinition != null) { return(recordSet.DoQueryValue <int?>(string.Format("SELECT {0} FROM {1} WHERE {2} = '{3}' AND Series = '{4}'", objectTypeDefinition.DocEntryColumn, objectTypeDefinition.DataBaseTable, objectTypeDefinition.DocNumColumn, docNum, seriesCode))); } else { throw new ArgumentOutOfRangeException("type"); } } }
public T Create <T>(BoObjectTypes objectType) { var bo = (T)SboAddon.Instance.Company.GetBusinessObject(objectType); _businessObjects.Add(bo); return(bo); }
public static Dictionary <string, object> DocumentContact(BoObjectTypes type, int docEntry, params string[] fields) { if (fields == null || fields.Length == 0) { fields = new[] { "*" } } ; var query = string.Format(@" SELECT {2} FROM (SELECT ObjType, DocEntry, CntctCode FROM OQUT WHERE ObjType = '{0}' UNION ALL SELECT ObjType, DocEntry, CntctCode FROM ORDR WHERE ObjType = '{0}' UNION ALL SELECT ObjType, DocEntry, CntctCode FROM ODLN WHERE ObjType = '{0}' UNION ALL SELECT ObjType, DocEntry, CntctCode FROM ORDN WHERE ObjType = '{0}' UNION ALL SELECT ObjType, DocEntry, CntctCode FROM OINV WHERE ObjType = '{0}' UNION ALL SELECT ObjType, DocEntry, CntctCode FROM ODPI WHERE ObjType = '{0}' UNION ALL SELECT ObjType, DocEntry, CntctCode FROM ORIN WHERE ObjType = '{0}' UNION ALL SELECT ObjType, DocEntry, CntctCode FROM OPOR WHERE ObjType = '{0}' ) DOC INNER JOIN OCPR CPR ON DOC.CntctCode = CPR.CntctCode WHERE DOC.ObjType = '{0}' AND DOC.DocEntry = '{1}' ", (int)type, docEntry, String.Join(",", fields.Select(f => "CPR." + f))); return(SboDiUtils.QueryList(query).FirstOrDefault()); } }
public static SboReportDocument FromDefaultReportFor(BoObjectTypes objectType, BoDocumentTypes documentType, string cardCode, int?userSign = null) { return (FromDefaultReportFor( SboDiUtils.ObjectTypeDefinitions.Single(def => def.ObjectType.Equals(objectType)).BaseReportCode + (documentType.Equals(BoDocumentTypes.dDocument_Service) ? "1" : "2"), cardCode, userSign)); }
/// <summary> /// Get Changed Items for object since timestamp /// </summary> /// <param name="timeStamp">Timestamp (seconds from a given start point)</param> /// <param name="objectType">BoObject Type</param> /// <returns>Collection of Key and timestamp for updated objects</returns> public ICollection <KeyAndTimeStampModel> GetChanged(int timeStamp, BoObjectTypes objectType) { using (var sboDbConnection = new SboDbConnection()) { var sql = FrameworkQueries.Instance.GetChangedQuery(timeStamp, (int)objectType); return(sboDbConnection.Query <KeyAndTimeStampModel>(sql).ToList()); } }
public T CreateSingle <T>(BoObjectTypes objectType) { if (!_singleBusinessObjects.ContainsKey(objectType)) { _singleBusinessObjects[objectType] = (T)SboAddon.Instance.Company.GetBusinessObject(objectType); } return((T)_singleBusinessObjects[objectType]); }
public ObjectTypeDefinition(BoObjectTypes type, string friendlyName, string formType, string table, string docEntryCol = "DocEntry", string docNumCol = "DocNum", string seriesCol = "Series", string baseReportCode = null) { ObjectType = type; FriendlyName = friendlyName; FormType = formType; DataBaseTable = table; DocEntryColumn = docEntryCol; DocNumColumn = docNumCol; SeriesColumn = seriesCol; BaseReportCode = baseReportCode; }
private static bool UpdateTransferStatus(int docEntry, BoObjectTypes transferType) { var oTransitTransfer = (StockTransfer)DIApplication.Company.GetBusinessObject(transferType); oTransitTransfer.GetByKey(docEntry); oTransitTransfer.UserFields.Fields.Item("U_GLO_Status").Value = "C"; if (oTransitTransfer.Update() != 0) { LogService.WriteError("TransferDI (Update TransferRequest) " + DIApplication.Company.GetLastErrorDescription()); return(false); } return(true); }
public string GetXMLBom <V>(object[] keys, BoObjectTypes objType) { XDocument bom = null; Type type = typeof(V); V obj = default(V); company.XMLAsString = true; company.XmlExportType = BoXmlExportTypes.xet_ExportImportMode; foreach (var key in keys) { try { obj = (V)company.GetBusinessObject(objType); bool found = (bool)type.InvokeMember("GetByKey", BindingFlags.InvokeMethod | BindingFlags.Public, null, obj, ProcessTuple(key)); if (found) { var xml = (string)type.InvokeMember("GetAsXML", BindingFlags.InvokeMethod | BindingFlags.Public, null, obj, null); XDocument tempDoc = XDocument.Parse(xml); if (bom == null) { bom = tempDoc; } else { XElement tempBO = tempDoc.Element("BOM").Element("BO"); if (tempBO != null) { bom.Element("BOM").Add(tempBO); } } } } catch (Exception e) { Logger.Error(String.Format(Messages.GetXMLBOMError, e.Message), e); throw e; } finally { if (obj != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(obj); } } } return(bom.ToString()); }
public static void AddDocumentAttachment(BoObjectTypes type, int docEntry, params string[] filenames) { if (docEntry <= 0) { return; } using (var factory = new SboDisposableBusinessObjectFactory()) { var sapDocument = factory.Create <Documents>(type); sapDocument.GetByKey(docEntry); var attachment = factory.Create <Attachments2>(BoObjectTypes.oAttachments2); if (sapDocument.AttachmentEntry > 0) { attachment.GetByKey(sapDocument.AttachmentEntry); attachment.Lines.Add(); } foreach (var file in filenames) { attachment.Lines.SourcePath = Path.GetDirectoryName(file); attachment.Lines.FileName = Path.GetFileNameWithoutExtension(file); attachment.Lines.FileExtension = Path.GetExtension(file).TrimStart('.'); attachment.Lines.Add(); } if (sapDocument.AttachmentEntry > 0) { if (attachment.Update() != 0) { throw new Exception(SboAddon.Instance.Company.GetLastErrorDescription()); } } else { if (attachment.Add() != 0) { throw new Exception(SboAddon.Instance.Company.GetLastErrorDescription()); } var attachmentId = SboAddon.Instance.Company.GetNewObjectKey(); sapDocument.AttachmentEntry = Convert.ToInt32(attachmentId); if (sapDocument.Update() != 0) { throw new Exception(SboAddon.Instance.Company.GetLastErrorDescription()); } } } }
public static Series GetDefaultSeries(BoObjectTypes type) { var companyService = SboAddon.Instance.Company.GetCompanyService(); var seriesService = (SeriesService)companyService.GetBusinessService(ServiceTypes.SeriesService); var documentTypeParams = (DocumentTypeParams)seriesService.GetDataInterface(SeriesServiceDataInterfaces.ssdiDocumentTypeParams); documentTypeParams.Document = Convert.ToInt32(type).ToString(CultureInfo.InvariantCulture); var series = (Series)seriesService.GetDataInterface(SeriesServiceDataInterfaces.ssdiSeries); series = seriesService.GetDefaultSeries(documentTypeParams); return(series); }
public static NextNumberResponse GetNextNumber(BoObjectTypes documentType, string documentSubType = null, int?serieId = null) { var companyService = SboApp.Company.GetCompanyService(); var seriesService = companyService.GetBusinessService(ServiceTypes.SeriesService) as SeriesService; var docTypeParams = seriesService.GetDataInterface(SeriesServiceDataInterfaces.ssdiDocumentTypeParams) as DocumentTypeParams; try { docTypeParams.Document = ((int)documentType).ToString(); if (documentSubType != null) { docTypeParams.DocumentSubType = documentSubType; } Series serie = null; if (serieId.HasValue) { var allSeries = seriesService.GetDocumentSeries(docTypeParams); foreach (Series s in allSeries) { if (s.Series == serieId.Value) { serie = s; break; } } if (serie == null) { throw new Exception($"Could not find serie {serieId.Value}"); } } else { serie = seriesService.GetDefaultSeries(docTypeParams); } return(new NextNumberResponse { NextNumber = $"{serie.Prefix}{serie.NextNumber}{serie.Suffix}", Series = serie.Series }); } finally { System.Runtime.InteropServices.Marshal.ReleaseComObject(seriesService); } }
public static Dictionary <string, object> DocumentHead(BoObjectTypes type, int docEntry, params string[] fields) { if (fields == null || fields.Length == 0) { fields = new[] { "*" } } ; else { var temp = fields.ToList(); if (!temp.Contains("DocEntry", StringComparer.OrdinalIgnoreCase)) { temp.Add("DocEntry"); } if (!temp.Contains("ObjType", StringComparer.OrdinalIgnoreCase)) { temp.Add("ObjType"); } fields = temp.ToArray(); } var query = string.Format(@" SELECT {2} FROM (SELECT {2} FROM OQUT WHERE ObjType = '{0}' UNION ALL SELECT {2} FROM ORDR WHERE ObjType = '{0}' UNION ALL SELECT {2} FROM ODLN WHERE ObjType = '{0}' UNION ALL SELECT {2} FROM ORDN WHERE ObjType = '{0}' UNION ALL SELECT {2} FROM OINV WHERE ObjType = '{0}' UNION ALL SELECT {2} FROM ODPI WHERE ObjType = '{0}' UNION ALL SELECT {2} FROM ORIN WHERE ObjType = '{0}' UNION ALL SELECT {2} FROM OPOR WHERE ObjType = '{0}' ) DOC WHERE DOC.ObjType = '{0}' AND DOC.DocEntry = '{1}' ", (int)type, docEntry, String.Join(",", fields)); return(SboDiUtils.QueryList(query).FirstOrDefault()); }
public static int?GetDocNumFromDocEntry(BoObjectTypes type, int docEntry) { using (var factory = new SboDisposableBusinessObjectFactory()) { var recordSet = factory.Create <Recordset>(BoObjectTypes.BoRecordset); var objectTypeDefinition = ObjectTypeDefinitions.FirstOrDefault(def => def.ObjectType.Equals(type)); if (objectTypeDefinition != null) { return(recordSet.DoQueryValue <int?>( $@"SELECT ""{objectTypeDefinition.DocNumColumn}"" FROM {objectTypeDefinition.DataBaseTable} WHERE ""{objectTypeDefinition.DocEntryColumn}"" = '{docEntry}'")); } else { throw new ArgumentOutOfRangeException("type"); } } }
/// <summary> /// Get Changed Items for object since timestamp /// </summary> /// <param name="timeStamp">Timestamp (secounds from a given startpoint)</param> /// <param name="objectType">BoObject Type</param> /// <returns>Collection of Key and timestamp for updated objects</returns> public ICollection <KeyAndTimeStampModel> GetChanged(int timeStamp, BoObjectTypes objectType) { using (var query = new SboRecordsetQuery( "SELECT DISTINCT [U_ITCO_CT_Key] AS [Key], CAST([Code] AS int) AS [Timestamp] FROM [@ITCO_CHANGETRACKER] " + $"WHERE [U_ITCO_CT_Obj] = {(int) objectType} AND CAST([Code] AS int) > {timeStamp} " + "ORDER BY CAST([Code] AS int) ASC")) { if (query.Count == 0) { return(new List <KeyAndTimeStampModel>()); } return(query.Result.Select(r => new KeyAndTimeStampModel { Key = r.Item(0).Value.ToString(), Timestamp = int.Parse(r.Item(1).Value.ToString()) }).ToList()); } }
public string nextObjectKey(BoObjectTypes type, string subType, string seriesName) { string ret = ""; try { Series oSeries; SeriesService oSeriesService; SeriesParams oSeriesParams; //string qry = "SELECT NextNumber, FROM NNM1 WHERE ObjectCode = " + (int)type; //qry += bplID > 0 ? " and BPLid = " + bplID : ""; //qry += !string.IsNullOrEmpty(seriesName) ? " and SeriesName = '" + seriesName + "'" : ""; //ret = queryValue("NextNumber", qry, "").ToString(); Recordset rs = Query("SELECT Series FROM NNM1 " + " WHERE ObjectCode = " + (int)type + " and DocSubType = '" + subType + "' and SeriesName = '" + seriesName + "'"); oSeriesService = oConnection.Company.GetCompanyService().GetBusinessService(ServiceTypes.SeriesService); oSeriesParams = oSeriesService.GetDataInterface(SeriesServiceDataInterfaces.ssdiSeriesParams); oSeriesParams.Series = rs.Fields.Item("Series").Value; oSeries = oSeriesService.GetSeries(oSeriesParams); ret = oSeries.Prefix + (oSeries.NextNumber + oSeries.Suffix).PadLeft(oSeries.DigitNumber, '0'); } catch (Exception e) { ret = ""; logger.log("Erro: " + e.Message, Logger.LogType.ERROR, e, false); } return(ret); }
/// <summary> /// Get table name from BoObjectTypes /// </summary> /// <param name="boObjectType"></param> /// <returns>Table name</returns> public static string GetTableName(this BoObjectTypes boObjectType) { switch (boObjectType) { case BoObjectTypes.oBusinessPartners: return("OCRD"); case BoObjectTypes.oItems: return("OITM"); case BoObjectTypes.oInvoices: return("OINV"); case BoObjectTypes.oDeliveryNotes: return("ODLN"); case BoObjectTypes.oOrders: return("ORDR"); case BoObjectTypes.oCreditNotes: return("ORIN"); } throw new NotImplementedException($"I dont know the table for {boObjectType} yet :("); }
/// <summary> /// Copy document /// </summary> /// <param name="sourceDocument"></param> /// <param name="copyToType"></param> /// <param name="copyExpenses">Copy Expenses</param> /// <param name="setObjectProperties">Set extra target document properties</param> /// <returns>DocEntry</returns> public static int CopyTo(this IDocuments sourceDocument, BoObjectTypes copyToType, bool copyExpenses = true, Action <Documents> setObjectProperties = null) { using (var copyTo = SboApp.Company.GetBusinessObject <Documents>(copyToType)) { var targetDocument = copyTo.Object; targetDocument.CardCode = sourceDocument.CardCode; setObjectProperties?.Invoke(targetDocument); foreach (var sourceLine in sourceDocument.Lines.AsEnumerable()) { SboApp.Logger.Debug($"CopyTo.Line: DocEntry={sourceLine.DocEntry}, LineNum={sourceLine.LineNum}, DocObjectCode={sourceDocument.DocObjectCode}"); targetDocument.Lines.BaseEntry = sourceLine.DocEntry; targetDocument.Lines.BaseLine = sourceLine.LineNum; targetDocument.Lines.BaseType = (int)sourceDocument.DocObjectCode; targetDocument.Lines.Add(); } if (copyExpenses) { foreach (var sourceExpense in sourceDocument.Expenses.AsEnumerable().Where(e => e.LineTotal > 0)) { SboApp.Logger.Debug($"CopyTo.Expense: DocEntry={sourceDocument.DocEntry}, LineNum={sourceExpense.LineNum}, DocObjectCode={sourceDocument.DocObjectCode}"); targetDocument.Expenses.BaseDocEntry = sourceDocument.DocEntry; targetDocument.Expenses.BaseDocLine = sourceExpense.LineNum; targetDocument.Expenses.BaseDocType = (int)sourceDocument.DocObjectCode; targetDocument.Expenses.Add(); } } targetDocument.AddAndLoadEx(); return(targetDocument.DocEntry); } }
/// <summary> /// Get Disposable BusinessObject for better COM-object dispose handling /// </summary> /// <typeparam name="T"></typeparam> /// <param name="company"></param> /// <param name="boObjectTypes"></param> /// <returns></returns> /// <example> /// using (var sboIncomingPaymentBo = SboApp.Company.GetBusinessObject<Payments>(BoObjectTypes.oIncomingPayments)) /// { /// // Code here /// } /// </example> public static BusinessObject <T> GetBusinessObject <T>(this SAPbobsCOM.Company company, BoObjectTypes boObjectTypes) { return(new BusinessObject <T>(company, boObjectTypes)); }
public T GetBusinessObject <T>(BoObjectTypes objType) { return((T)DICompany.GetBusinessObject(objType)); }
public dynamic GetBusinessObject(BoObjectTypes objType) { return(company.GetBusinessObject(objType)); }
public static T Get <T>(this Company company, BoObjectTypes type) { return((T)company.GetBusinessObject(type)); }
/// <summary> /// BusinessObject /// </summary> /// <param name="company"></param> /// <param name="boObjectType"></param> public BusinessObject(SAPbobsCOM.Company company, BoObjectTypes boObjectType) { BoObjectType = boObjectType; Object = (T)company.GetBusinessObject(BoObjectType); }