Find the items matching any condition from the generic list - c#

I have collection of patient in a lists named lst_Patient.
And this is method where i get the info from user:
public Patient[] GetPatientsBySearchParams(DataPair[] dataPair)
{
//return the array patients that match any of the criteria
//Right Now I ma doing this didn't get any success :
List<Patient> P = new List<Patient>();
P = lst_Patient.FindAll(p => { p.FirstName = dataPair[0].OutputValue.ToString();
p.LastName = dataPair[1].OutputValue.ToString();
return true;
return P.ToArray();
}
On a button click i take the info entered in the textbox by the user:
private DataPair[] dpair;
private void Button_Click(object sender, RoutedEventArgs e)
{
InvalidSearch.Visibility = Visibility.Collapsed;
SearchResults.Visibility = Visibility.Visible;
dpair = new DataPair[]{
new DataPair { Name = "FirstName", OutputValue = fst_Name.Text },
new DataPair { Name = "LastName", OutputValue = lst_Name.Text },
new DataPair { Name = "DateOfBirth", OutputValue = dob.Text },
new DataPair { Name = "SSN", OutputValue = ssn.Text },
new DataPair { Name = "PracticeNumber", OutputValue = pract_nbr.Text },
new DataPair { Name = "ReferenceNumber", OutputValue = ref_nbr.Text },
new DataPair { Name = "PlaceOfService", OutputValue = pos.Text },
new DataPair { Name = "DateOfService", OutputValue = dos.Text},
new DataPair { Name = "RenderingProvider", OutputValue = rndrng_prov.Text },
new DataPair { Name = "AdmissionDate", OutputValue = admsn_date.Text }
};
this.FetchData();
}
private void FetchData()
{
Patient[] p = client.GetPatientsBySearchParams(dpair);
}

public Patient[] GetPatientsBySearchParams(DataPair[] dataPair)
{
P = lst_Patient.FindAll(
delegate(Patient tmp){
if(tmp.FirstName = dataPair[0].OutputValue || tmp.LastName = dataPair[1].OutputValue)
return true;
else
return false;
}
);
return P.ToArray();
}

You should use reflection to call the property whose name gets passed.
p.GetType().GetProperty(dataPair[i].Name).GetValue(p) == dataPair[i].OutputValue;

Related

Acumatica rest API PUT for sales order line keeps returning a 500 error

I've been trying to upload a sales order with their sales line on Acumatica with a REST API, but I keep getting a 500 error.
I am using the default Sales Order endpoint. When I comment out the SalesOrderDetail list, it succeeds, so I think that's where the problem is.
PUT method:
public async Task<bool> PutSalesOrdersAsync(Models.AcumaticaSalesOrder customer)
{
if (await Login() == false) return false;
var uri = new Uri(settings.url + settings.endpoint + "SalesOrder"); //?$filter=Location eq 'MAIN'&$top=10");
try
{
var json = JsonConvert.SerializeObject(customer);
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PutAsync(uri, stringContent);
if (response.IsSuccessStatusCode)
{
//var content = await response.Content.ReadAsStringAsync();
//Customers = JsonConvert.DeserializeObject<List<Models.AcumaticaCustomer>>(content);
}
else
{
err = await response.Content.ReadAsStringAsync();
try
{
ResponseMessage msg = JsonConvert.DeserializeObject<ResponseMessage>(err);
if (msg != null && msg.exceptionMessage != "") err = msg.exceptionMessage;
return false;
}
catch (Exception ex)
{
err = ex.Message;
return false;
}
}
}
catch (Exception ex)
{
Debug.WriteLine(#" ERROR {0}", ex.Message);
err = ex.Message;
return false;
}
return true;
}
Acumatica Sales order setup:
public async Task<AcumaticaSalesOrder> ToAcumaticaSalesOrderAsync()
{
AcumaticaSalesOrder c = new AcumaticaSalesOrder();
c.CurrencyID = new StringField { value = this.CurrencyID };
c.CustomerID = new StringField { value = this.CustomerID };
// c.OrderSummaryCustomerName = new StringField { value = this.OrderSummaryCustomerName };
c.CustomerOrder = new StringField { value = this.CustomerOrder };
c.Date = new DateTimeField { value = this.Date };
c.Description = new StringField { value = this.Description };
c.FinancialSettings = new Models.AcumaticaSalesOrderFinancialSettings();
c.FinancialSettings.InvoiceNbr = new StringField { value = this.InvoiceNbr };
c.LocationID = new StringField { value = this.LocationID };
c.OrderNbr = new StringField { value = this.OrderNbr };
c.OrderTotal = new DecimalField { value = this.OrderTotal };
c.OrderedQty = new DecimalField { value = this.OrderedQty };
c.OrderType = new StringField { value = this.OrderType };
c.Status = new StringField { value = this.Status };
c.Totals = new Models.AcumaticaSalesOrderTotals();
c.Totals.LineTotalAmount = new DecimalField { value = this.LineTotalAmount };
c.Totals.MiscTotalAmount = new DecimalField { value = this.MiscTotalAmount };
c.TaxTotal = new DecimalField { value = this.TaxTotal };
c.Details = new List<AcumaticaSalesOrderDetail>();
c.Details = await GetSalesOrderLineAsync();
return c;
}
private async Task<List<AcumaticaSalesOrderDetail>> GetSalesOrderLineAsync()
{
AASDatabase db = new AASDatabase();
List<Models.AcumaticaSalesOrderDetail> asols = new List<AcumaticaSalesOrderDetail>();
List <Models.SalesOrderDetail> sols = await db.GetSalesOrderDetailByOrderNbrAsync(OrderNbr);
foreach (Models.SalesOrderDetail sol in sols)
{
Models.AcumaticaSalesOrderDetail c = new AcumaticaSalesOrderDetail();
c.LineNbr = new IntField { value = sol.LineNbr };
c.DiscountAmount = new DecimalField { value = sol.DiscountAmount };
c.LineType = new StringField { value = sol.LineType }; ;
c.LineDescription = new StringField { value = sol.LineDescription };
c.InventoryID = new StringField { value = sol.InventoryID };
c.UOM = new StringField { value = sol.UOM };
c.WarehouseID = new StringField { value = sol.WarehouseID };
c.OrderQty = new DecimalField { value = sol.OrderQty };
c.UnitPrice = new DecimalField { value = sol.UnitPrice };
asols.Add(c);
}
return asols;
}
The code is correct. The the json that I was sending over was not the right type of sales order. Thisput only dose type SO.

C# Botframework Loop inside of AdaptiveCard

I have created one dialog to evaluate our company consultant in our chatbot (C# botframework), but I can't use for or foreach inside of AdaptiveCard. I need to create one TextBlock() and one ChoiceSet() block for each item from List Pergunta, but I can't do it with foreach. Any suggestion or better idea to create this loop ?
Here is my complete dialog code in C#.
using System;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
using System.Collections.Generic;
using AdaptiveCards;
using SimpleEchoBot.Formulário;
namespace SimpleEchoBot.Dialogs
{
[Serializable]
public class RatingDialog : IDialog<EntidadeCliente>
{
public Task StartAsync(IDialogContext context)
{
context.Wait(this.MessageReceivedAsync);
return Task.CompletedTask;
}
public async virtual Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
var replyMessage = context.MakeMessage();
Attachment attachment = null;
attachment = CriarAdapativecard();
replyMessage.Attachments = new List<Attachment> { attachment };
await context.PostAsync(replyMessage);
}
public Attachment CriarAdapativecard()
{
AdaptiveCard card = new AdaptiveCard()
{
Body = new List<CardElement>()
{
new Container()
{
Items = new List<CardElement>()
{
new ColumnSet()
{
Columns = new List<Column>()
{
new Column()
{
Size = ColumnSize.Auto,
Items = new List<CardElement>()
{
new Image()
{
Url = "D:/EvaWeb.png",
Size = ImageSize.Medium,
Style = ImageStyle.Person
}
}
},
new Column()
{
Size = ColumnSize.Auto,
Items = new List<CardElement>()
{
new TextBlock()
{
Text = "Olá, temos uma novidade!",
Weight = TextWeight.Bolder,
IsSubtle = true
},
new TextBlock()
{
Text = "Gostaria de iniciar a avaliação do consultor?",
Wrap = true
}
}
}
}
}
}
}
},
// Buttons
Actions = new List<ActionBase>()
{
new ShowCardAction()
{
Title = "Sim",
Speak = "<s>Sim</s>",
Card = AvaliarConsultor("")
},
new ShowCardAction()
{
Title = "Não",
Speak = "<s>Não</s>",
Card = PularAvaliacao()
},
}
};
Attachment attachment = new Attachment()
{
ContentType = AdaptiveCard.ContentType,
Content = card
};
return attachment;
}
private static AdaptiveCard PularAvaliacao()
{
//does nothing on No option from user
return new AdaptiveCard()
{ };
}
private static AdaptiveCard AvaliarConsultor(List<string> Pergunta)
{
var adaptiveCard = new AdaptiveCard()
{
Body = new List<CardElement>()
{
new TextBlock()
{
Text = "Avaliação de questionário 1!",
Weight = TextWeight.Bolder,
Size = TextSize.Large
},
new TextBlock() { Text = Pergunta[0]},
new ChoiceSet()
{
Id = "nota",
Style = ChoiceInputStyle.Compact,
IsMultiSelect = false,
Choices = new List<Choice>()
{
new Choice()
{
Title = "⭐",
Value = "1"
},
new Choice()
{
Title = "⭐⭐",
Value = "2"
},
new Choice()
{
Title = "⭐⭐⭐",
Value = "3"
},
new Choice()
{
Title = "⭐⭐⭐⭐",
Value = "4"
},
new Choice()
{
Title = "⭐⭐⭐⭐⭐",
Value = "5"
}
}
}
},
Actions = new List<ActionBase>()
{
new SubmitAction()
{
Title = "Registrar",
Speak = "<s>Registrar avaliação</s>",
DataJson = "{ \"Type\": \"Registrar\" }"
}
}
};
return adaptiveCard;
}
}
}
I need to create one TextBlock() and one ChoiceSet() block for each item from List Pergunta, but I can't do it with foreach.
To achieve your requirement, please refer to the following code snippet.
private static AdaptiveCard AvaliarConsultor(List<string> Pergunta)
{
var adaptiveCard = new AdaptiveCard()
{
Body = new List<CardElement>()
{
new TextBlock()
{
Text = "Avaliação de questionário 1!",
Weight = TextWeight.Bolder,
Size = TextSize.Large
},
},
Actions = new List<ActionBase>()
{
new SubmitAction()
{
Title = "Registrar",
Speak = "<s>Registrar avaliação</s>",
DataJson = "{ \"Type\": \"Registrar\" }"
}
}
};
//dynamically generate TextBlock and ChoiceSet
//and then add to AdaptiveCard Body
foreach (var item in Pergunta)
{
var textblock = new TextBlock() { Text = item };
var choiceset = new ChoiceSet()
{
Id = "nota",
Style = ChoiceInputStyle.Compact,
IsMultiSelect = false,
Choices = new List<Choice>()
{
new Choice()
{
Title = "⭐",
Value = "1"
},
new Choice()
{
Title = "⭐⭐",
Value = "2"
},
new Choice()
{
Title = "⭐⭐⭐",
Value = "3"
},
new Choice()
{
Title = "⭐⭐⭐⭐",
Value = "4"
},
new Choice()
{
Title = "⭐⭐⭐⭐⭐",
Value = "5"
}
}
};
adaptiveCard.Body.Add(textblock);
adaptiveCard.Body.Add(choiceset);
}
return adaptiveCard;
}
Test result:

Google Sheets API .NET v4 Creating Drop-down list for a grid cell

I'm trying to create a drop-down list on a grid. I was following the advice on this page. However, I'm not able to enter any string values for UserEnteredValue. The underlined error I'm getting:
Cannot implicitly convert type 'Google.Apis.Sheets.v4.Data.ConditionValue' to 'System.Collections.Generic.IList'.An explicit conversion exists(are you missing a cast?)
public Request createDataValidationRequest(int sheetID, int startRow, int endRow, int startColumn, int endColumn)
{
var updateCellsRequest = new Request() {
SetDataValidation = new SetDataValidationRequest()
{
Range = new GridRange()
{
SheetId = sheetID,
StartRowIndex = startRow,
StartColumnIndex = startColumn,
EndRowIndex = endRow,
EndColumnIndex = endColumn
},
Rule = new DataValidationRule()
{
Condition = new BooleanCondition()
{
Type = "ONE_OF_LIST",
Values = new ConditionValue()
{
UserEnteredValue = "awer"
}
},
InputMessage = "Select an Option",
ShowCustomUi = true,
Strict = true
}
}
};
return updateCellsRequest;
}
I was able to get the following, for my situation to work.
SpreadsheetsResource.GetRequest request = _sheetsService.Spreadsheets.Get(newTimeSheet.Id);
Spreadsheet spreadsheet = request.Execute();
SheetProperties timeSheetProperties = new SheetProperties();
for (int z = 0; z < spreadsheet.Sheets.Count; z++)
{
SheetProperties sheetProperties = spreadsheet.Sheets[z].Properties;
if (sheetProperties.Title == "3c TIME")
{
timeSheetProperties = sheetProperties;
break;
}
}
var updateCellsRequest = new Request()
{
SetDataValidation = new SetDataValidationRequest()
{
Range = new GridRange()
{
SheetId = timeSheetProperties.SheetId,
StartRowIndex = 2,
StartColumnIndex = 0,
EndColumnIndex = 1
},
Rule = new DataValidationRule()
{
Condition = new BooleanCondition()
{
//Type = "ONE_OF_RANGE",
Type = "ONE_OF_LIST",
Values = new List<ConditionValue>()
{
new ConditionValue()
{
UserEnteredValue = "YES",
},
new ConditionValue()
{
UserEnteredValue = "NO",
},
new ConditionValue()
{
UserEnteredValue = "MAYBE",
}
}
},
InputMessage = "Select an Option",
ShowCustomUi = true,
Strict = true
}
}
};
var requestBody = new Google.Apis.Sheets.v4.Data.BatchUpdateSpreadsheetRequest();
var requests = new List<Request>();
requests.Add(updateCellsRequest);
requestBody.Requests = requests;
var batchRequest = _sheetsService.Spreadsheets.BatchUpdate(requestBody, newTimeSheet.Id);
batchRequest.Execute();

Netsuite search salesorder by customfield

Have a salesorder opject and I want to search by using a tranid field.
how can I do that?
I know how to search by using internalid or extrenalid, but no clue about tranid
Here is an example of how to do this in C#.
SearchResult result = service.search(new TransactionSearch()
{
basic = new TransactionSearchBasic()
{
type = new SearchEnumMultiSelectField() {
#operator = SearchEnumMultiSelectFieldOperator.anyOf,
operatorSpecified = true,
searchValue = new string[] { "_salesOrder" }
},
tranId = new SearchStringField()
{
#operator = SearchStringFieldOperator.#is,
operatorSpecified = true,
searchValue = "SO364886"
}
}
}
);
if(result.status.isSuccess && result.totalRecords == 1)
{
SalesOrder salesOrder = (SalesOrder)result.recordList[0];
System.Console.WriteLine("Internal ID = " + salesOrder.internalId);
} else
{
System.Console.WriteLine("Couldn't find sales order!");
}

EXT: append data to store (datasource)

I add static data to the store:
List<object> data = new List<object>() {
new { name="", grouptype="Normal Types", fieldtype="SimpleText", tooltip="", icon="../Images/buttons/01_simpletext.svg", tabular=1 }};
LabDatatoStore();
this.StoreControlTypes.DataSource = data;
this.StoreControlTypes.DataBind();
and I am calling LabDatatoStore() to add also some dynamic data from the database:
protected void LabDatatoStore()
{
DAL.DataContext dc = new DAL.DataContext();
var data = from i in dc.Tests
where i.id != "HEIGHT" && i.id != "WEIGHT"
select new { fieldtype = i.id, grouptype = "Data Types", tooltip = i.Name, icon = "../Images/test.png" };
this.StoreControlTypes.DataSource = data;
this.StoreControlTypes.DataBind();
}
But I get only the static data. How I can get both ones?
Here is how I solved it:
List<object> data = new List<object>() {
new { name="", grouptype="Normal Types", fieldtype="SimpleText", tooltip="", icon="../Images/buttons/01_simpletext.svg" },
new { name="", grouptype="Normal Types", fieldtype="LongText", tooltip="", icon="../Images/buttons/02_textlong.svg" },
new { name="", grouptype="Normal Types", fieldtype="Numeric", tooltip="", icon="../Images/buttons/03_numeric.svg" }
};
DAL.DataContext dc = new DAL.DataContext();
var dataDyn = from i in dc.Tests
where i.id != "HEIGHT" && i.id != "WEIGHT"
select new { fieldtype = i.id, grouptype = "Data Types", tooltip = i.Name, icon = "../Images/test.png" };
data.AddRange(dataDyn.ToArray());
this.StoreControlTypes.DataSource = data;
this.StoreControlTypes.DataBind();

Categories

Resources