EXT.NET Dynamically created ComboBox and Store - c#

I am using Ext.Net 1.3 with ASP.NET 4.0
I would like to use C # dynamically generated ComboBox and Store, the following is my code.
var data = new object[]
{
new object[]{"AL", "Alabama", "The Heart of Dixie"},
new object[] { "AK", "Alaska", "The Land of the Midnight Sun"},
new object[] { "AZ", "Arizona", "The Grand Canyon State"},
new object[] { "AR", "Arkansas", "The Natural State"},
new object[] { "CA", "California", "The Golden State"},
new object[] { "CO", "Colorado", "The Mountain State"},
new object[] { "CT", "Connecticut", "The Constitution State"}
};
Ext.Net.ComboBox cmb = new Ext.Net.ComboBox();
cmb.TypeAhead = true;
cmb.ForceSelection = true;
cmb.DisplayField = "ItemCode";
cmb.ValueField = "ItemName";
cmb.MinChars = 1;
cmb.ListWidth = 400;
cmb.PageSize = 10;
cmb.ItemSelector = "tr.list-item";
Store s = new Store();
s.AddField(new RecordField() { Name = "ItemCode", Type = RecordFieldType.String }, 0);
s.AddField(new RecordField() { Name = "ItemName", Type = RecordFieldType.String }, 1);
s.AddField(new RecordField() { Name = "OnHand", Type = RecordFieldType.String }, 2);
s.SaveAllFields = true;
s.DataSource = data;
s.DataBind();
cmb.Store.Add(s);
StringBuilder sHtml = new StringBuilder();
sHtml.Append(" <tpl for=\".\"><tpl if=\"[xindex] == 1\">");
sHtml.Append("<table class=\"cbStates-list\" ><tr>");
sHtml.Append("<th style=\"color: #2f353b !important;\">ItemCode</th>");
sHtml.Append(" <th style=\"color: #2f353b !important;\">ItemName</th>");
sHtml.Append("<th style=\"color: #2f353b !important;\">OnHand</th>");
sHtml.Append("</tr> </tpl>");
sHtml.Append("<tr class=\"list-item\">");
sHtml.Append("<td style=\"padding:3px 0px;\">{ItemCode}</td>");
sHtml.Append("<td>{ItemName}</td>");
sHtml.Append("<td>{OnHand}</td>");
sHtml.Append("</tr> <tpl if=\"[xcount-xindex]==0\">");
sHtml.Append(" </table> </tpl> </tpl>");
cmb.Template.Html = sHtml.ToString();
Panel1.Items.Add(cmb);
If you do not bind the Store, the ComboBox will appear on the page.
If the Store is bound, nothing will be displayed. And the browser gives an error message.
enter image description here
How to solve this problem?

HttpProxy proxy = new HttpProxy
{
Method = HttpMethod.POST,
Url = "../../../Handlers/BoneWL.ashx"
};
// Create Reader
Ext.Net.JsonReader reader = new Ext.Net.JsonReader
{
Root = "plants",
TotalProperty = "total",
Fields = {
new RecordField("ItemCode"),
new RecordField("ItemName"),
new RecordField("OnHand")
}
};
// Add Proxy and Reader to Store
Store store = new Store
{
Proxy = { proxy },
Reader = { reader },
AutoLoad = false
};
// Create ComboBox
Ext.Net.ComboBox cmb = new Ext.Net.ComboBox
{
DisplayField = "ItemCode",
ValueField = "ItemCode",
TypeAhead = false,
LoadingText = "加载中...",
Width = 240,
PageSize = 10,
HideTrigger = true,
ItemSelector = "tr.list-item",
MinChars = 1,
Store = { store }
};
cmb.Listeners.TriggerClick.Handler = "UseDirectEvents('1');WinRowCancelEdit();";
cmb.Triggers.Add(new FieldTrigger() { Icon = TriggerIcon.Search });
cmb.TriggerIcon = TriggerIcon.Search;
StringBuilder sHtml = new StringBuilder();
sHtml.Append(" <tpl for=\".\"><tpl if=\"[xindex] == 1\">");
sHtml.Append("<table class=\"cbStates-list\" ><tr>");
sHtml.Append("<th style=\"color: #2f353b !important;\">ItemCode</th>");
sHtml.Append(" <th style=\"color: #2f353b !important;\">ItemName</th>");
sHtml.Append("<th style=\"color: #2f353b !important;\">OnHand</th>");
sHtml.Append("</tr> </tpl>");
sHtml.Append("<tr class=\"list-item\">");
sHtml.Append("<td style=\"padding:3px 0px;\">{ItemCode}</td>");
sHtml.Append("<td>{ItemName}</td>");
sHtml.Append("<td>{OnHand}</td>");
sHtml.Append("</tr> <tpl if=\"[xcount-xindex]==0\">");
sHtml.Append(" </table> </tpl> </tpl>");
cmb.Template.Html = sHtml.ToString();
Panel1.Items.Add(cmb);
Example.portal

Related

How to do show list of an Item in alexa skill using Alexa.Net.APL?

I am trying to display list of item on Echo show. Am using Alexa.Net.APL C# and below is what i have done so far but is not displaying i will appreciate help.
This is my method that generate Directive
private RenderDocumentDirective BuildDirective(string bg = "")
{
if (string.IsNullOrEmpty(bg))
{
bg = "https://i.ibb.co/5cWztFH/brown-on-seashore-near-mountain-1007657.jpg";
}
var mainLayout = new Layout(
new AlexaTextList
{
BackgroundImageSource = bg,
HeaderTitle = "Alexa text list header title",
HeaderSubtitle = "sub",
HeaderDivider = true,
BackgroundScale = new APLValue<Scale>(Scale.BestFill),
BackgroundAlign = new APLValue<string>("center"),
BackgroundColor = new APLValue<string>("transparent"),
ListItems = new APLValue<List<AlexaTextListItem>>()
{
Value = new List<AlexaTextListItem>
{
new AlexaTextListItem
{
PrimaryText = "Hello world! 1"
},
new AlexaTextListItem
{
PrimaryText = "Hello world! 2"
},
new AlexaTextListItem
{
PrimaryText = "Hello world! 3"
}
}
}
}
);
var renderDocument = new RenderDocumentDirective
{
Token = "randomToken",
Document = new APLDocument
{
MainTemplate = mainLayout
},
};
return renderDocument;
}
Here is where am calling it
var response = ResponseBuilder.Ask(d, rp, session);
var dr = BuildDirective();
response.Response.Directives.Add(dr);
return response;

DynamoDB Conditional SaveAsync

I'm using the following code:
DynamoDBContextConfig config = new DynamoDBContextConfig()
{
ConsistentRead = false,
Conversion = DynamoDBEntryConversion.V2
};
using (DynamoDBContext context = new DynamoDBContext(config))
{
long unixTimestamp = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
QTrackStatus qTrackStatus = new QTrackStatus()
{
Key = "m#m.com",
EventCode = "CC",
EventDateTime = "2019-09-09 14:00:30",
EventLocation = "BFS",
EventLastUpdate = unixTimestamp
};
DynamoDBOperationConfig dynamoDBOperationConfig = new DynamoDBOperationConfig()
{
QueryFilter = new List<ScanCondition>()
{
{ new ScanCondition("EventCode", ScanOperator.NotEqual, "CC") }
},
ConditionalOperator = ConditionalOperatorValues.And
};
await context.SaveAsync(qTrackStatus, dynamoDBOperationConfig);
}
What I'm trying to do is only save the record if the EventCode is not CC. Currently it's always saving. I could retrieve the record first, do a check and then call SaveAsync if required - however I'd like to do it all in the SaveAsync call. Is this possible?
Unless I've missed something, it doesn't look like this is possible with the higher level api. I ended up re-factoring to the following:
AmazonDynamoDBClient client = new AmazonDynamoDBClient();
UpdateItemRequest updateItemRequest = new UpdateItemRequest()
{
TableName = "QTrackStatus",
ReturnValues = ReturnValue.ALL_NEW,
ConditionExpression = "EventCode <> :ec",
UpdateExpression = "SET EventCode = :ec, EventDateTime = :edt, EventLocation = :el, EventLastUpdate = :elu",
ExpressionAttributeValues = new Dictionary<string, AttributeValue>()
{
{ ":ec", new AttributeValue("CC") },
{ ":edt", new AttributeValue("2019-09-09 14:00:30") },
{ ":el", new AttributeValue("BFS") },
{ ":elu", new AttributeValue() { N = ((long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString() } }
},
Key = new Dictionary<string, AttributeValue>()
{
{ "Key", new AttributeValue("m#m.com") }
}
};
try
{
UpdateItemResponse updateItemResponse = await client.UpdateItemAsync(updateItemRequest);
}
catch(ConditionalCheckFailedException e)
{
}
This allows me to achieve my goal.

ElasticSearch 5.1 filtered query with multiply filters

I need to use several filters (range and terms) for query request with ElasticSearch 5.1. If I use them separately (only one filter) it is OK:
var o = new
{
size = 20,
query = new
{
#bool = new
{
must = new
{
query_string = new
{
fields = new[] { "Title" },
query = search_query
}
},
filter = new
{
terms = new
{
SourceId = new[] {10,11,12}
}
}
}
}
};
OR
var o = new
{
size = 20,
query = new
{
#bool = new
{
must = new
{
query_string = new
{
fields = new[] { "Title" },
query = search_query
}
},
filter = new
{
range = new
{
PostPubDate = new
{
gte = "2015-10-01T00:00:00",
lte = "2015-11-01T12:00:00"
}
}
}
}
}
};
If I use them both I get response 400 error:
string url = "http://localhost:9200/neg_collector/posts/_search";
var request = (HttpWebRequest)HttpWebRequest.Create(url);
var o = new
{
size = 20,
query = new
{
#bool = new
{
must = new
{
query_string = new
{
fields = new[] { "Title" },
query = search_query
}
},
filter = new
{
terms = new
{
SourceId = new[] {10,11,12}
},
range = new
{
PostPubDate = new
{
gte = "2015-10-01T00:00:00",
lte = "2015-11-01T12:00:00"
}
}
}
}
}
};
request.Method = "POST";
var jsonObj = JsonConvert.SerializeObject(o);
var data = Encoding.UTF8.GetBytes(jsonObj);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
string responseString = string.Empty;
var response = (HttpWebResponse)request.GetResponse();
What am I doing wrong? Thank you
Your filter simply needs to be an array of objects:
...
filter = new object[]
{
new {
terms = new
{
SourceId = new[] {10,11,12}
}
},
new {
range = new
{
PostPubDate = new
{
gte = "2015-10-01T00:00:00",
lte = "2015-11-01T12:00:00"
}
}
}
}

ElasticSearch filtered query _search 400 error response

I am trying to use filter with search query. Search requset works correctly without filter. But using filter I get 400 error as response.
This is type mapping:
var mapp = new
{
mappings = new
{
posts = new
{
properties = new
{
FullText = new
{
type = "string",
analyzer = "russian"
},
Title = new
{
type = "string",
analyzer = "russian"
},
PostPubDate = new
{
type = "date"
},
Link = new
{
type = "string",
index = "not_analyzed"
},
RubricsIds = new
{
type = "integer"
},
ObjectsIds = new
{
type = "integer"
},
SourceId = new
{
type = "integer"
}
}
}
}
};
This is a request to index with filtered query:
string url = "http://localhost:9200/neg_collector/posts/_search";
var request = (HttpWebRequest)HttpWebRequest.Create(url);
var o = new
{
size = 20,
query = new
{
filtered = new
{
query = new
{
query_string = new
{
fields = new[] { "Title" },
query = search_query
}
},
filter = new
{
#bool = new
{
should = new
{
term = new
{
SourceId = sIds
}
}
}
}
}
}
};
request.Method = "POST";
var jsonObj = JsonConvert.SerializeObject(o);
var data = Encoding.UTF8.GetBytes(jsonObj);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
I want to use an array of integers to filter result with certain SourceId-s. But I got error 400.
What am I doing wrong? Thank you
So the problem was that this syntax was for elasticsearch 2 version (And it worked nice on another computer). Here I have ElasticSearch 5 and should use another was of filtering:
var o = new
{
size = 20,
query = new
{
#bool = new
{
must = new
{
query_string = new
{
fields = new[] { "Title" },
query = search_query
}
},
filter = new
{
terms = new
{
SourceId = new[] {10,11,12}
}
}
}
}
};
It is describerd HERE

NetSuite. How to select all attached files for current user (filter by InternalId)

I am using C# implementation of netsuite api from web reference com.netsuite.webservices
I released filter fileSearch.basic by name (you can see it commented) it is working fine.
Please help to write function to achieve all attached files for current user. Something is wrong in this code, it filters nothing and showing me all files as it is without any filter. Please help me.
public static void GetFileAttachmentByCustomerId(string customerId)
{
using (NetSuiteService netSuiteService = GetNetSuiteService())
{
FileSearch fileSearch = new FileSearch();
// this works fine (filter files by name)
//SearchStringField nameSearchParams = new SearchStringField
//{
// #operator = SearchStringFieldOperator.contains,
// operatorSpecified = true,
// searchValue = "some name",
//};
//fileSearch.basic = new FileSearchBasic() { name = nameSearchParams };
// this code not filter files at all
{
RecordRef nsCustomerRef = new RecordRef
{
internalId = customerId,
type = RecordType.customer,
typeSpecified = true,
};
SearchMultiSelectField shopperSearchParam = new SearchMultiSelectField
{
#operator = SearchMultiSelectFieldOperator.anyOf,
operatorSpecified = true,
searchValue = new RecordRef[] { nsCustomerRef }
};
fileSearch.shopperJoin = new CustomerSearchBasic { internalId = shopperSearchParam };
}
SearchResult result = netSuiteService.search(fileSearch);
// Get connected objects
{
Customer customer = GetCustomerById(netSuiteService, customerId);
Account account = GetAccountById(netSuiteService, "301395"); //
Folder folder = GetFolderById(netSuiteService, "3962");
}
File file = (File)result.recordList.First();
byte[] fileContent = GetFileContentByInternalId(file.internalId);
}
}
.
Try this:
var nsCustomerRef = new RecordRef
{
internalId = "4",
type = RecordType.employee,
typeSpecified = true,
};
var currentUser = new SearchMultiSelectField()
{
operatorSpecified = true,
#operator = SearchMultiSelectFieldOperator.anyOf,
searchValue = new List<RecordRef>() {nsCustomerRef}.ToArray()
};
var fileSearchBasic = new FileSearchBasic() {owner = currentUser};
var fileSearch = new FileSearch() { basic = fileSearchBasic };
var result = netSuiteService.search(fileSearch);
var file = (File)result.recordList.First();

Categories