AS 3 functions optional value getting error - apache-flex

I have a gui class, The functions optional value getting error. If i am not passing the fillcolor and other optional values.
Error:
ReferenceError: Error #1069: Property fillColor not found on String and there is no default value.
AS 3.0
var windowBase:Sprite = UIClip("Sprite");
/* sliderClip = Gui.UIClip("MovieClip",{width:100, height:50, fillColor:0xFFFF0D, alpha:.7});
*/
function UIClip (type:String, params:object = '') {
var clip;
trace("Hello")
if (type == 'MovieClip') {
clip = new MovieClip ;
} else {
clip = new Sprite;
}
//trace(params + "params.fillColor " + params.fillColor)
if (params is Object) {
clip.graphics.beginFill ((params.fillColor != "") ? params.fillColor : 0xFFFFFF, params.alpha ? params.alpha : 1 );
clip.graphics.lineStyle (params.lineThickness != "" ? params.lineThickness : 1, params.borderColor ? params.borderColor: 0x000000);
clip.graphics.drawRoundRect (0,0,
(params.width != undefined ) ? params.width : 100,
(params.height != undefined) ? params.height : 100 ,
params.eW ? params.eW : 0,
params.eH ? params.eH : 0);
clip.graphics.endFill ();
//trace("Hello")
}
return clip;
}
How can I solve this?

Condition "if (params is Object)" is true. String is object, too.
I'm using null for optional params if they have no default value.
Try this:
function UIClip (type:String, params:object = null)
and test "if (params != null)"

Related

Pagination on DevExtreme dxDataGrid with Skip / Take loadOptions

We have a table with a large amount of data and I do not want to load it at once for my dxDataGrid.
I want to implement paging with Skip / Take which is supplied from the dxDataGrid's DataSourceLoadOptions.
This is my controller:
[HttpGet]
public async Task<Object> GetSalesOrdersWithTotals(DataSourceLoadOptions loadOptions)
{
try
{
var results = await SalesOrderService.GetSalesOrdersWithTotals(loadOptions.Skip, loadOptions.Take, 40);
loadOptions.Skip = 0;
loadOptions.Take = 0;
return DataSourceLoader.Load(results, loadOptions);
}
catch (Exception ex)
{
return Json(new { code = "422", success = false, message = "Unable to fetch sales orders with totals - " + ex.ToString() });
}
}
This is the service that returns the data:
public async Task<IEnumerable<SalesOrderWithTotals>> GetSalesOrdersWithTotals(int skip, int take, int defaultPageSize)
{
if (take == 0)
{
//Fix for passing a 0 take
take = defaultPageSize;
}
var salesOrderWithTotals =
from o in _context.SalesOrder
select new SalesOrderWithTotals
{
SalesOrderId = o.SalesOrderId,
Net = _context.SalesOrderItem.Where(it => it.SalesOrderId == o.SalesOrderId).Select(it => it.Qty == null ? 0 : it.Qty.Value * it.UnitPrice == null ? 0 : it.UnitPrice.Value).Sum(),
Tax = _context.SalesOrderItem.Where(it => it.SalesOrderId == o.SalesOrderId).Select(it => it.Qty == null ? 0 : it.Qty.Value * it.UnitPrice == null ? 0 : it.UnitPrice.Value).Sum() * (o.Tax.Percentage /100),
Gross = _context.SalesOrderItem.Where(it => it.SalesOrderId == o.SalesOrderId).Select(it => it.Qty == null ? 0 : it.Qty.Value * it.UnitPrice == null ? 0 : it.UnitPrice.Value).Sum() + _context.SalesOrderItem.Where(it => it.SalesOrderId == o.SalesOrderId).Select(it => it.Qty == null ? 0 : it.Qty.Value * it.UnitPrice == null ? 0 : it.UnitPrice.Value).Sum() * (o.Tax.Percentage / 100),
Name = o.Customer.Name,
CustomerOrderNumber = o.CustomerOrderNumber,
Contact = o.Contact,
OrderDate = o.OrderDate
};
return await salesOrderWithTotals.Skip(skip).Take(take).ToListAsync();
}
Looking at SQL profiler, this takes the first 40 records but of course the dxDataGrid is not aware of the total count of records so pagination is not available.
What would be the best method to achieve what I want in this case?
Many thanks
You must do an extra query to get the count of your SalesOrder and keep it in for example salesOrderCount. Then keep the Load method return data as bellow.
LoadResult result = DataSourceLoader.Load(results, loadOptions);
LoadResult has a parameter called totalCount so set it with the real count of your data:
result.totalCount = salesOrderCount;
and then
return result;
Now the dxDataGrid is aware of the total count of records.

getting java.lang.ClassCastException: [Ljava.lang.Integer; cannot be cast to [I

Try to get a method return type int array and getting casting error
for(String s:oldOfferList)
{
LOGGER.log(Level.FINE, "Method name"+s);
Method getNameMethod = old_offer2.getClass().getMethod(s);
if(getNameMethod.getName().equals("getLevelId"))
{
#SuppressWarnings("unchecked")
int[] oldLevelids = (int[]) getNameMethod.invoke(old_offer2);
#SuppressWarnings("unchecked")
int[] newMethodsval = (int[]) getNameMethod.invoke(current_offer2);
if( !Arrays.equals(oldLevelids, newMethodsval)){
LOGGER.log(Level.FINE," oldLevelids not equals to newMethodsval : "
);
DiffPropValuesEntity dpv=new DiffPropValuesEntity(getNameMethod.getName().toString(),Arrays.toString(oldLevelids).replaceAll("\\s+", ""),Arrays.toString(newMethodsval).replaceAll("\\s+", ""));
listDiffPropValuesEntity.add(dpv);
}else {
LOGGER.log(Level.FINE," oldLevelids equals to newMethodsval : " );
}
continue;
}

Datatables Object Reference not set to instance of an object for one variable

This is my datatables serverside implementation. FilterInput contains 5 variables:
Level <- string
Message <- string
Exception <-string
StartDate <- DateTime
EndDate <- DateTime
For some reason when I run this code as it is, I will always get this error:
{System.NullReferenceException: Object reference not set to an
instance of an object.
This is referring to this line:
data = data.Where(
u => u.Level.ToString().ToLower().Contains(FilterInput.Level.ToLower()) &&
u.Message.ToString().ToLower().Contains(FilterInput.Message.ToLower()) &&
u.Exception.ToString().ToLower().Contains(FilterInput.Exception.ToLower())
).ToList();
However, if I remove the search for FilterInput.Exception, everything runs fine again. I have tested it with input ("abc") or without input ("") and the results are the same. The other FilterInputs don't have the same error.
public JsonResult Search(SearchViewModels Input, EventLogsSearchViewModel FilterInput)
{
JsonResult result = new JsonResult(null);
try
{
var data = dbContext.EventLogs.ToList();
int totalRecords = data.Count;
var modelStructure = new Dictionary<int, string>();
modelStructure.Add(1, "Level");
modelStructure.Add(2, "TimeStamp");
modelStructure.Add(3, "LogEvent");
modelStructure.Add(4, "Message");
modelStructure.Add(5, "MessageTemplate");
modelStructure.Add(6, "Exception");
modelStructure.Add(7, "Properties");
var StartDate = FilterInput.StartDate != default(DateTime);
var EndDate = FilterInput.EndDate != default(DateTime);
if ((!string.IsNullOrEmpty(FilterInput.Level) && !string.IsNullOrWhiteSpace(FilterInput.Level)) ||
(!string.IsNullOrEmpty(FilterInput.Message) && !string.IsNullOrWhiteSpace(FilterInput.Message)) ||
(!string.IsNullOrEmpty(FilterInput.Exception) && !string.IsNullOrWhiteSpace(FilterInput.Exception)) ||
(StartDate && EndDate))
{
data = data.Where(
u => u.Level.ToString().ToLower().Contains(FilterInput.Level.ToLower()) &&
u.Message.ToString().ToLower().Contains(FilterInput.Message.ToLower()) &&
u.Exception.ToString().ToLower().Contains(FilterInput.Exception.ToLower())
).ToList();
data = data.Where(u => u.TimeStamp >= FilterInput.StartDate && u.TimeStamp <= FilterInput.EndDate).ToList();
}
if (!(string.IsNullOrEmpty(Input.Order) && string.IsNullOrEmpty(Input.OrderDir)))
{
var columnName = modelStructure.FirstOrDefault(f => f.Key == Convert.ToInt32(Input.Order));
data = data.AsQueryable().OrderBy(columnName.Value + " " + Input.OrderDir).ToList();
}
int recFilter = data.Count;
data = data.Skip(Input.StartRec).Take(Input.PageSize).ToList();
var modifiedData = data.Select(u => new EventLogsListViewModel
{
Id = u.Id,
Message = u.Message,
MessageTemplate = u.MessageTemplate,
Level = u.Level,
TimeStamp = u.TimeStamp,
Exception = u.Exception,
Properties = u.Properties,
LogEvent = u.LogEvent
});
result = this.Json(new
{
draw = Convert.ToInt32(Input.Draw),
recordsTotal = totalRecords,
recordsFiltered = recFilter,
data = modifiedData,
order = Input.Order,
orderdir = Input.OrderDir
});
}
catch (Exception e)
{
logger.LogError(e, LoggingGlobals.LoadingException);
}
return result;
}
EDIT: The exception still happens even when FilterInput.Exception is not null

Range of all linkAttributed String in MutableAttributedString in swift

I have a mutableAttributedString in which few strings are linkAttributed,I want to find the Range of all link attributed string. How to do that in swift3 ?
When user start type # in textview i show list of few name. If user select any row then following method gets called.
func didSelectMemberId(_ model: BaseModel) {
var fullName = ""
if model.entityType == ReceiverType.Active.rawValue{
fullName = model.name
}else{
fullName = AtMention + model.name + " " + model.name2
}
let attributedString = NSMutableAttributedString(string:fullName, attributes:[NSFontAttributeName:(appNeedsAutoResize ? (UIUtils.getFontForApproprieteField(.headlineWithoutBold).font) : UIFont.systemFont(ofSize: 14))])
attributedString.addAttribute(NSLinkAttributeName, value: "connectmention://\(model.entityId.stringValue())", range: NSRange(location: 0, length: fullName.length))
attributedString.append(NSAttributedString(string: emptySpaceStringByUC, attributes:[NSFontAttributeName:(appNeedsAutoResize ? (UIUtils.getFontForApproprieteField(.headlineWithoutBold).font) : UIFont.systemFont(ofSize: 14))]))
self.composeBar.textView.textStorage.insert(attributedString, at:self.composeBar.textView.selectedRange.location)
}
self.composeBar.textView.selectedRange = NSMakeRange(self.composeBar.textView.selectedRange.location+fullName.length, 0 )
To get the link proprty I am using the following method
func getlinkActionRange(attributeString: NSAttributedString) -> [MentionStruct] {
var arrMentions = [MentionStruct]()
_ = attributeString.enumerateAttribute(NSLinkAttributeName, in: NSRange.init(location: 0, length: attributeString.length), options: [], using: { (value, range, stop) in
if let url = value {
let occurrence = (attributeString.string as NSString).substring(with:range)
arrMentions.append(MentionStruct(link: url as! String, text: occurrence, range: range))
}
})
return arrMentions
}
If user type anything after inserting that name , that type string also coming.

Case Statements in LINQ query - AnonymousType to String?

I basically have the following:
public ActionResult Search(string searchString, string clientNo, int status = -1)
{
var statusLst = new List<string>();
var statusNoQry = from b in db.Briefs
orderby b.Status
select new
{
status = (
b.Status == 0 ? "Requested" :
b.Status == 1 ? "In Progress" :
"Undefined"
)
};
statusLst.AddRange(statusNoQry.Distinct()); <<--- ERROR HERE
ViewBag.status = new SelectList(statusLst);
var ClientNoLst = new List<string>();
var ClientNoQry = from b in db.Briefs
orderby b.Client_No_
where b.Client_Type == 0
select b.Client_No_;
ClientNoLst.AddRange(ClientNoQry.Distinct());
ViewBag.clientNo = new SelectList(ClientNoLst);
var briefs = from b in db.Briefs
select b;
Session["searchString"] = searchString;
Session["clientNo"] = clientNo;
if (!String.IsNullOrEmpty(searchString))
{
briefs = briefs.Where(s => s.Client_No_.Contains(searchString) || s.Name.Contains(searchString));
}
if ((status > -1) && (status < 10))
{
briefs = briefs.Where(y => y.Status == status);
}
if (string.IsNullOrEmpty(clientNo))
return View(briefs);
else
return View(briefs.Where(x => x.Client_No_ == clientNo));
}
However, I receive the following area:
Error 7 Argument 1: cannot convert from 'System.Linq.IQueryable<AnonymousType#1>' to 'System.Collections.Generic.IEnumerable<string>'
Status is of type int but I would like to cast it to string for my dropdownlist. I'm quite new to all this, what is the appropriate way of achieving this?
Your selector is returning an anonymous type:
select new
{
status = (
b.Status == 0 ? "Requested" :
b.Status == 1 ? "In Progress" :
"Undefined"
)
};
You need to return a set of strings though. The error is telling you exactly what the problem is.
select
(b.Status == 0 ? "Requested" :
b.Status == 1 ? "In Progress" :
"Undefined");
Edit - You didn't post the rest of the method, but from you have your also not disposing your context object, which can cause problems. Normally you wrap this in a using clause.

Resources