public Dictionary <String, Object> GetSAPIVAMat(Int64 MaterialId) { Dictionary <String, Object> response = null; try { var config = System.Configuration.ConfigurationManager.GetSection(ConfigurationName.Trim()) as NameValueCollection; var resultSeparator = config["ResultSeparator"].ToCharArray()[0]; RfcDestinationManager.RegisterDestinationConfiguration(this.SAPConfig); RfcDestination rfcDest = RfcDestinationManager.GetDestination(this.ConfigurationName); RfcRepository rfcRep = null; rfcRep = rfcDest.Repository; IRfcFunction qry = rfcRep.CreateFunction("RFC_READ_TABLE"); qry.SetValue("QUERY_TABLE", "MLAN"); qry.SetValue("DELIMITER", resultSeparator); IRfcTable FIELDS = qry.GetTable("FIELDS"); FIELDS.Append(); FIELDS.SetValue("FIELDNAME", "TAXM1"); IRfcTable OPTIONS = qry.GetTable("OPTIONS"); OPTIONS.Append(); OPTIONS.SetValue("TEXT", "MATNR EQ '" + CompleteCodes(MaterialId.ToString(), 18) + "' AND"); OPTIONS.Append(); OPTIONS.SetValue("TEXT", "ALAND EQ 'CO'"); IRfcTable DATA = qry.GetTable("DATA"); qry.Invoke(rfcDest); response = new Dictionary <string, object>(); if (DATA.ToList().Count > 0) { var result = DATA.ToList().First()["WA"]; var value = result.GetValue(); response.Add("Response", true); response.Add("SAPIVAMat", value.ToString()); } else { response.Add("Response", false); } } catch (RfcLogonException le) { return(new Dictionary <string, object>() { { "Response", false }, { "Message", le.Message } }); } catch (Exception ex) { return(new Dictionary <string, object>() { { "Response", false }, { "Message", ex.Message + " : " + ex.StackTrace } }); } finally { RfcDestinationManager.UnregisterDestinationConfiguration(this.SAPConfig); } return(response); }
public SearchResultVariantsDataTable SearchForVariants(WorkSpace WorkSpace, string UserGroupName, string QueryName) { SearchResultVariantsDataTable table = new SearchResultVariantsDataTable(); IRfcFunction function = this._des.Repository.CreateFunction("RSAQ_REMOTE_QUERY_CALL_CATALOG"); function["WORKSPACE"].SetValue((WorkSpace == WorkSpace.GlobalArea) ? "X" : " "); function["GENERIC_QUERYNAME"].SetValue(QueryName); function["GENERIC_USERGROUP"].SetValue(UserGroupName); function["GENERIC_FUNCAREA"].SetValue("*"); function.Invoke(_des); IRfcTable table2 = function.GetTable("QUERYCATALOG"); foreach (IRfcStructure structure in table2.ToList()) { string str = structure["VARIANT"].GetValue().ToString().Trim(); string descriptionText = structure["VTEXT"].GetValue().ToString().Trim(); bool flag = false; if (!str.Equals("")) { foreach (SearchResultVariantsRow row in table.Rows) { if (row.VariantName.Trim().Equals(str)) { flag = true; } } if (!flag) { table.AddSearchResultVariantsRow(str, descriptionText); } } } return(table); }
public SearchResultQueryDataTable SearchForQueries(WorkSpace WorkSpace, string SearchPatternUserGroup, string SearchPatternQueryName, string SearchPatternFunctionAreaName) { SearchResultQueryDataTable table = new SearchResultQueryDataTable(); IRfcFunction function = this._des.Repository.CreateFunction("RSAQ_REMOTE_QUERY_CATALOG"); function["WORKSPACE"].SetValue((WorkSpace == WorkSpace.GlobalArea) ? "X" : " "); if (SearchPatternQueryName.Trim().Equals("")) { SearchPatternQueryName = "*"; } if (SearchPatternUserGroup.Trim().Equals("")) { SearchPatternUserGroup = "*"; } if (SearchPatternFunctionAreaName.Trim().Equals("")) { SearchPatternFunctionAreaName = "*"; } function["GENERIC_QUERYNAME"].SetValue(SearchPatternQueryName); function["GENERIC_USERGROUP"].SetValue(SearchPatternUserGroup); function["GENERIC_FUNCAREA"].SetValue(SearchPatternFunctionAreaName); function.Invoke(_des); IRfcTable table2 = function.GetTable("QUERYCATALOG"); foreach (IRfcStructure structure in table2.ToList()) { table.AddSearchResultQueryRow(structure["QUERY"].GetValue().ToString().Trim(), structure["NUM"].GetValue().ToString().Trim(), structure["QTEXT"].GetValue().ToString().Trim()); } return(table); }
public SearchResultUserGroupsDataTable SearchForUserGroups(WorkSpace WorkSpace, string UserGroupSearchPattern) { SearchResultUserGroupsDataTable table = new SearchResultUserGroupsDataTable(); IRfcFunction function = this._des.Repository.CreateFunction("RSAQ_REMOTE_USERGROUP_CATALOG"); function["WORKSPACE"].SetValue((WorkSpace == WorkSpace.GlobalArea) ? "X" : " "); function["GENERIC_USERGROUP"].SetValue(UserGroupSearchPattern); function.Invoke(_des); IRfcTable table2 = function.GetTable("USERGROUPCATALOG"); foreach (IRfcStructure structure in table2.ToList()) { string userGroup = structure["NUM"].GetValue().ToString().Trim(); string descriptionText = structure["UTEXT"].GetValue().ToString().Trim(); table.AddSearchResultUserGroupsRow(userGroup, descriptionText); } return(table); }
internal void RefreshFieldsAndSelections() { if (this._UserGroup.Trim().Equals("") || this._Name.Trim().Equals("")) { throw new SAPException(Messages.PleasemakesurethatthefieldsUserGroupandNamearefilledcorrectly); } //RFCFunction function = RFCFunctionFactory.GenerateFunctionObjectForRSAQ_REMOTE_QUERY_FIELDLIST(this._con.IsUnicode); IRfcFunction function = _des.Repository.CreateFunction("RSAQ_REMOTE_QUERY_FIELDLIST"); //function.Connection = this._con; if (this._WorkArea == WorkSpace.StandardArea) { function.SetValue("WORKSPACE", " "); } else { function.SetValue("WORKSPACE", "X"); } function["QUERY"].SetValue(this._Name); function.SetValue("USERGROUP", this._UserGroup); //function.Exports["USERGROUP"].ParamValue = this._UserGroup; try { function.Invoke(_des); // function.Execute(); IRfcTable table = function.GetTable("FIELDS"); IRfcTable table2 = function.GetTable("SEL_FIELDS"); this._Fields.Clear(); this._SelectionParameters.Clear(); string str = ""; foreach (IRfcStructure structure in table.ToList()) { if (str == "") { str = structure["LID"].GetValue().ToString(); } if (str == structure["LID"].GetValue().ToString()) { QueryField newParameter = new QueryField(structure["NAME"].GetValue().ToString(), structure["TYPE"].GetValue().ToString(), Convert.ToInt32(structure["OLENG"].GetValue()), Convert.ToInt32(structure["DECIMALS"].GetValue()), ""); this._Fields.Add(newParameter); if ((!structure["CURRY"].GetValue().ToString().Trim().Equals("") && !structure["CURRY"].GetValue().ToString().Trim().Equals("W")) && !structure["CURRY"].GetValue().ToString().Trim().Equals("E")) { QueryField field2 = new QueryField(structure["NAME"].GetValue().ToString() + "-" + structure["LINE"].GetValue().ToString() + structure["POS"].GetValue().ToString(), "C", 10, 0, ""); this._Fields.Add(field2); } } } foreach (IRfcStructure structure2 in table2.ToList()) { if (!structure2["SPNAME"].GetValue().ToString().Substring(0, 1).Equals("%")) { string descriptionText = structure2["FTEXT"].GetValue().ToString(); if (descriptionText.StartsWith("D ")) { descriptionText = descriptionText.Substring(8); } QuerySelectionParameter parameter = new QuerySelectionParameter(structure2["SPNAME"].GetValue().ToString(), structure2["FNAME"].GetValue().ToString(), descriptionText, Convert.ToInt32(structure2["LENGTH"].GetValue()), structure2["OBLIGATORY"].GetValue().ToString().Equals("X"), structure2["NODISPLAY"].GetValue().ToString().Equals("X"), structure2["KIND"].GetValue().ToString().Equals("S") ? Kind.SelectOption : Kind.Parameter); this.SelectionParameters.Add(parameter); } } } catch (RfcAbapException ee) { throw new SAPException(ee.Key + ee.Message); } catch (Exception ee) { throw new SAPException(ee.Message); } }
private void InitWhereClause(ref IRfcTable toptions) { toptions.Clear(); if (this._WhereClause.Equals("")) { for (int i = 0; i < this.options.Count; i++) { toptions.Append(); toptions.CurrentRow.SetValue("TEXT", this.options[i].ToString()); //toptions.AddRow()["TEXT"] = this.options[i].ToString(); } } else { for (int j = 0; j < this._WhereClause.Length; j += 0x48) { if ((this._WhereClause.Length - j) > 0x48) { IRfcStructure structure2 = toptions.Metadata.LineType.CreateStructure(); bool flag = false; for (int k = 0; k < 0x47; k++) { if (this._WhereClause.Substring((j + 0x47) - k, 1).Equals(" ")) { structure2["TEXT"].SetValue(this._WhereClause.Substring(j, 0x48 - k)); toptions.Append(structure2); j -= k; flag = true; k = 0x48; } } if (!flag) { structure2["TEXT"].SetValue(this._WhereClause.Substring(j, 0x48)); toptions.Append(structure2); } } else { // toptions.AddRow()["TEXT"] = this._WhereClause.Substring(j); toptions.Append(); toptions.CurrentRow["TEXT"].SetValue(this._WhereClause.Substring(j)); } } string str = ""; foreach (IRfcStructure structure4 in toptions.ToList()) { str = str + structure4["TEXT"].ToString() + "\r\n"; } } if (this._UsePrimaryKeyPackaging) { if (toptions.ToList().Count == 0) { this.AddWhereLine(toptions, "("); } else { this.AddWhereLine(toptions, "AND ("); } for (int m = 0; m < this._PrimaryKeys.Count; m++) { string whereline = this._PrimaryKeys[m].FieldName + " >= '" + this._PrimaryKeys[m].LastKeyValue + "'"; if (m == 0) { whereline = "( " + whereline; } else { whereline = "AND " + whereline; } if (m == (this._PrimaryKeys.Count - 1)) { whereline = whereline + " )"; } this.AddWhereLine(toptions, whereline); } for (int n = 0; n < this._PrimaryKeys.Count; n++) { for (int num6 = n; num6 >= 0; num6--) { string str3; if (num6 == n) { str3 = "OR ( " + this._PrimaryKeys[num6].FieldName + " > '" + this._PrimaryKeys[num6].LastKeyValue + "'"; } else { str3 = "AND " + this._PrimaryKeys[num6].FieldName + " >= '" + this._PrimaryKeys[num6].LastKeyValue + "'"; } if (num6 == 0) { str3 = str3 + " )"; } this.AddWhereLine(toptions, str3); } } //toptions.AddRow()["TEXT"] = ")"; toptions.Append(); toptions.CurrentRow.SetValue("TEXT", ")"); } //if (!this.con.LogDir.Equals("")) //{ // this.con.Log("Building where: "); // foreach (RFCStructure structure6 in toptions.Rows) // { // this.con.Log(structure6["TEXT"].ToString()); // } //} }
public List <ObraDTO> GetSAPPrice(List <string> DocComercial) { List <ObraDTO> response = new List <ObraDTO>(); try { var config = System.Configuration.ConfigurationManager.GetSection(ConfigurationName.Trim()) as NameValueCollection; var resultSeparator = config["ResultSeparator"].ToCharArray()[0]; RfcDestinationManager.RegisterDestinationConfiguration(this.SAPConfig); RfcDestination rfcDest = RfcDestinationManager.GetDestination(this.ConfigurationName); RfcRepository rfcRep = null; rfcRep = rfcDest.Repository; IRfcFunction qry = rfcRep.CreateFunction("RFC_READ_TABLE"); qry.SetValue("QUERY_TABLE", "KONP"); qry.SetValue("DELIMITER", resultSeparator); IRfcTable FIELDS = qry.GetTable("FIELDS"); FIELDS.Append(); FIELDS.SetValue("FIELDNAME", "KBETR"); IRfcTable OPTIONS = qry.GetTable("OPTIONS"); foreach (var p in DocComercial) { OPTIONS.Append(); OPTIONS.SetValue("TEXT", "KNUMH EQ '" + p + "' OR"); } OPTIONS.Append(); OPTIONS.SetValue("TEXT", "KNUMH EQ '" + DocComercial.Last() + "'"); IRfcTable DATA = qry.GetTable("DATA"); qry.Invoke(rfcDest); if (DATA.ToList().Count > 0) { for (int i = 0; i < DATA.ToList().Count; i++) { var result = DATA.ToList().ElementAt(i)["WA"]; var value = result.GetValue(); response.Add(new ObraDTO() { Contrato = value.ToString() }); } } else { response.Add(new ObraDTO() { Contrato = "False" }); } } catch (RfcLogonException le) { return(new List <ObraDTO>() { new ObraDTO() { Contrato = le.Message } }); } catch (Exception ex) { return(new List <ObraDTO>() { new ObraDTO() { Contrato = ex.Message } }); } finally { RfcDestinationManager.UnregisterDestinationConfiguration(this.SAPConfig); } return(response); }
public List <ObraDTO> GetSAPPrecioMat2(long Material, string Centro, string CondPago) { List <ObraDTO> response = new List <ObraDTO>(); try { var config = System.Configuration.ConfigurationManager.GetSection(ConfigurationName.Trim()) as NameValueCollection; var resultSeparator = config["ResultSeparator"].ToCharArray()[0]; RfcDestinationManager.RegisterDestinationConfiguration(this.SAPConfig); RfcDestination rfcDest = RfcDestinationManager.GetDestination(this.ConfigurationName); RfcRepository rfcRep = null; rfcRep = rfcDest.Repository; IRfcFunction qry = rfcRep.CreateFunction("RFC_READ_TABLE"); qry.SetValue("QUERY_TABLE", "A707"); qry.SetValue("DELIMITER", resultSeparator); IRfcTable FIELDS = qry.GetTable("FIELDS"); FIELDS.Append(); FIELDS.SetValue("FIELDNAME", "KNUMH"); IRfcTable OPTIONS = qry.GetTable("OPTIONS"); OPTIONS.Append(); OPTIONS.SetValue("TEXT", "MATNR EQ '" + CompleteCodes(Material.ToString(), 18) + "' AND"); OPTIONS.Append(); OPTIONS.SetValue("TEXT", "KSCHL EQ 'YCP1' AND"); OPTIONS.Append(); OPTIONS.SetValue("TEXT", "VKORG EQ '7460' AND"); OPTIONS.Append(); OPTIONS.SetValue("TEXT", "WERKS EQ '" + Centro + "' AND"); OPTIONS.Append(); OPTIONS.SetValue("TEXT", "ZTERM EQ '" + CondPago + "' AND"); OPTIONS.Append(); OPTIONS.SetValue("TEXT", "DATBI GT '" + (DateTime.Now.Year + (DateTime.Now.Month >= 10 ? DateTime.Now.Month.ToString() : "0" + DateTime.Now.Month.ToString()) + (DateTime.Now.Day >= 10 ? DateTime.Now.Day.ToString() : "0" + DateTime.Now.Day.ToString())) + "' AND"); OPTIONS.Append(); OPTIONS.SetValue("TEXT", "DATAB LE '" + (DateTime.Now.Year + (DateTime.Now.Month >= 10 ? DateTime.Now.Month.ToString() : "0" + DateTime.Now.Month.ToString()) + (DateTime.Now.Day >= 10 ? DateTime.Now.Day.ToString() : "0" + DateTime.Now.Day.ToString())) + "'"); IRfcTable DATA = qry.GetTable("DATA"); qry.Invoke(rfcDest); if (DATA.ToList().Count > 0) { for (int i = 0; i < DATA.ToList().Count; i++) { var result = DATA.ToList().ElementAt(i)["WA"]; var value = result.GetValue(); response.Add(new ObraDTO() { Contrato = value.ToString() }); } } else { response.Add(new ObraDTO() { Contrato = "False" }); } } catch (RfcLogonException le) { return(new List <ObraDTO>() { new ObraDTO() { Contrato = le.Message } }); } catch (Exception ex) { return(new List <ObraDTO>() { new ObraDTO() { Contrato = ex.Message } }); } finally { RfcDestinationManager.UnregisterDestinationConfiguration(this.SAPConfig); } return(response); }
public Dictionary <String, Object> GetSAPPrecio(Int64 ObraId, Int64 MaterialId, int Volumen) { Dictionary <String, Object> response = null; try { var config = System.Configuration.ConfigurationManager.GetSection(ConfigurationName.Trim()) as NameValueCollection; var resultSeparator = config["ResultSeparator"].ToCharArray()[0]; RfcDestinationManager.RegisterDestinationConfiguration(this.SAPConfig); RfcDestination rfcDest = RfcDestinationManager.GetDestination(this.ConfigurationName); RfcRepository rfcRep = null; rfcRep = rfcDest.Repository; IRfcFunction qry = rfcRep.CreateFunction("RFC_READ_TABLE"); qry.SetValue("QUERY_TABLE", "A502"); qry.SetValue("DELIMITER", resultSeparator); IRfcTable FIELDS = qry.GetTable("FIELDS"); FIELDS.Append(); FIELDS.SetValue("FIELDNAME", "KNUMH"); IRfcTable OPTIONS = qry.GetTable("OPTIONS"); OPTIONS.Append(); OPTIONS.SetValue("TEXT", "(KSCHL EQ 'ZCAK' OR KSCHL EQ 'ZCA1') AND "); OPTIONS.Append(); OPTIONS.SetValue("TEXT", "KUNWE EQ '" + CompleteCodes(ObraId.ToString(), 10) + "' AND"); OPTIONS.Append(); OPTIONS.SetValue("TEXT", "MATNR LIKE '%" + MaterialId + "' AND"); OPTIONS.Append(); OPTIONS.SetValue("TEXT", "DATBI GT '" + (DateTime.Now.Year + (DateTime.Now.Month > 10 ? DateTime.Now.Month.ToString() : "0" + DateTime.Now.Month.ToString()) + (DateTime.Now.Day > 10 ? DateTime.Now.Day.ToString() : "0" + DateTime.Now.Day.ToString())) + "' AND"); OPTIONS.Append(); OPTIONS.SetValue("TEXT", "DATAB LE '" + (DateTime.Now.Year + (DateTime.Now.Month > 10 ? DateTime.Now.Month.ToString() : "0" + DateTime.Now.Month.ToString()) + (DateTime.Now.Day > 10 ? DateTime.Now.Day.ToString() : "0" + DateTime.Now.Day.ToString())) + "'"); IRfcTable DATA = qry.GetTable("DATA"); qry.Invoke(rfcDest); response = new Dictionary <string, object>(); if (DATA.ToList().Count > 0) { var result = DATA.ToList().First()["WA"]; var value = result.GetValue(); response.Add("Response", true); response.Add("SAPKNUMHId", value.ToString()); } else { response.Add("Response", false); } } catch (RfcLogonException le) { return(new Dictionary <string, object>() { { "Response", false }, { "Message", le.Message } }); } catch (Exception ex) { return(new Dictionary <string, object>() { { "Response", false }, { "Message", ex.Message + " : " + ex.StackTrace } }); } finally { RfcDestinationManager.UnregisterDestinationConfiguration(this.SAPConfig); } return(response); }