How do I handle shift + a key for uppercase or option?
a could be any key like 1 or !
/ or ?
or
h or shift + h to get H with the uppercase.
I'm trying to build a WYSIWYG with Paper.js.
When I double click into a text item I want to be able to change the text. I have that working, but if I hit shift + a to get A I get shifta.
Characters such as !##$%^&*()_+ etc. should be handled properly by onKeyDown. To handle uppercase letters, check to see if the shift-modifier is active:
function onKeyDown(event) {
if (event.key == 'shift' || event.key == 'command' || event.key == 'option' || event.key == 'caps-lock' || event.key == 'control') return;
if (event.modifiers.shift || event.modifiers.capsLock) {
console.log('The ' + event.key.toUpperCase() + ' key was pressed!');
}
else console.log('The ' + event.key + ' key was pressed!');
}
function onKeyDown(event) {
if (event.key == 'shift' || event.key == 'command' || event.key == 'option' || event.key == 'caps-lock' || event.key == 'control') return;
if (event.modifiers.shift || event.modifiers.capsLock) {
text.content = text.content + event.key.toUpperCase();
}else if (Key.isDown('space')){
event.preventDefault();
text.content = text.content + " ";
}else if (Key.isDown('backspace')){
var subStr = text.content.substring(0, text.content.length - 1)
text.content = subStr;
}
else{
text.content = text.content + event.key;
}
}
This is what I ended up with.
Related
I have a table that I am filtering on. There is a four filters status, project, department, KPI
KPI is a boolean value. This filter has three value. True, False or both.
So, when the filter is true, it should return 'true' data, when the filter is 'false', return 'false' data; and when 'all' return both true and false data.
My code attached below, how can I enhance this code ? Can I write this with out if else conditions
var result = new List<TaskMaster>();
bool kpidata;
if (request.IsKPI == 1) { kpidata = true; } else { kpidata = false; }
//For KPI Tasks
if (request.IsKPI == 1 || request.IsKPI == 0)
{
result = await _context.TaskMaster.Where(c => c.IsActive && (c.Status == request.Status || request.Status == "All") && (c.ProjectId == request.ProjectId || request.ProjectId == 0) && (c.IsKPI == kpidata) && (c.AssignedTo.DepartmentId == request.DepartmentId || request.DepartmentId == 0)).Include(y => y.TaskActionLogs)
.Include(y => y.AssignedTo)
.Include(y => y.AssignedBy)
.Include(y => y.Project)
.AsSplitQuery().ToListAsync();
//For Non-KPI Tasks
}
else {
result = await _context.TaskMaster.Where(c => c.IsActive && (c.Status == request.Status || request.Status == "All") && (c.ProjectId == request.ProjectId || request.ProjectId == 0) && (c.AssignedTo.DepartmentId == request.DepartmentId || request.DepartmentId == 0)).Include(y => y.TaskActionLogs)
.Include(y => y.AssignedTo)
.Include(y => y.AssignedBy)
.Include(y => y.Project)
.AsSplitQuery().ToListAsync();
}
Revise the code, both queries are almost identical except c.IsKPI == kpidata part.
Few ways to remove the redundant:
Write the IQueryable query and append the .Where() if the condition meets. You are fine to append/extend the query before the query is materialized (via .ToList(), .First() etc.).
var result = new List<TaskMaster>();
bool kpidata;
if (request.IsKPI == 1) { kpidata = true; } else { kpidata = false; }
IQueryable<TaskMaster> query = _context.TaskMaster
.Where(c => c.IsActive
&& (c.Status == request.Status || request.Status == "All")
&& (c.ProjectId == request.ProjectId || request.ProjectId == 0)
&& (c.AssignedTo.DepartmentId == request.DepartmentId || request.DepartmentId == 0));
//For KPI Tasks
if (request.IsKPI == 1 || request.IsKPI == 0)
{
query = query.Where(c => c.IsKPI == kpidata);
}
result = await query.Include(y => y.TaskActionLogs)
.Include(y => y.AssignedTo)
.Include(y => y.AssignedBy)
.Include(y => y.Project)
.AsSplitQuery()
.ToListAsync();
You can also migrate the if logic to the query too.
&& (!(request.IsKPI == 1 || request.IsKPI == 0) || c.IsKPI == kpidata)
If !(request.IsKPI == 1 || request.IsKPI == 0) returns true, the c.IsKPI == kpidata part will be omitted.
result = await _context.TaskMaster
.Where(c => c.IsActive
&& (c.Status == request.Status || request.Status == "All")
&& (c.ProjectId == request.ProjectId || request.ProjectId == 0)
&& (c.AssignedTo.DepartmentId == request.DepartmentId || request.DepartmentId == 0)
&& (!(request.IsKPI == 1 || request.IsKPI == 0) || c.IsKPI == kpidata))
.Include(y => y.TaskActionLogs)
.Include(y => y.AssignedTo)
.Include(y => y.AssignedBy)
.Include(y => y.Project)
.AsSplitQuery()
.ToListAsync();
This
(request.IsKPI == 1 || request.IsKPI == 0)
can also be revised to:
(new List<int> { 0, 1 }).Contains(request.IsKPI)
Hi I am trying to do this query:
Select ProjInvoiceJour
where NOT (ProjInvoiceJour.ProjInvoiceType == ProjInvoiceType::Onaccount && ProjInvoiceJour.CountryRegionID != "ES")
But I need to do it whit querybuilder:
qbds.addRange(fieldnum(ProjInvoiceJour, ProjInvoiceType)).value(strfmt('!%1',
strfmt("((%1.%2 == %3) && (%4.%5 != '%6'))",
tablestr(ProjInvoiceJour),
fieldstr(ProjInvoiceJour, ProjInvoiceType),
any2int(ProjInvoiceType::OnAccount),
tablestr(ProjInvoiceJour),
fieldstr(ProjInvoiceJour, CountryRegionID),
queryvalue("ES"))));
But the query has some error:
SELECT * FROM ProjInvoiceJour WHERE ((NOT (ProjInvoiceType = 255)))
Thanks
The law of De Morgan comes to rescue:
select ProjInvoiceJour
where !(ProjInvoiceJour.ProjInvoiceType == ProjInvoiceType::Onaccount &&
ProjInvoiceJour.CountryRegionID != 'ES')
is equivalent to:
select ProjInvoiceJour
where ProjInvoiceJour.ProjInvoiceType != ProjInvoiceType::Onaccount ||
ProjInvoiceJour.CountryRegionID == 'ES'
Or in a query:
qbds.addRange(fieldnum(ProjInvoiceJour, ProjInvoiceType)).value(strfmt('((%1.%2 != %3) || (%4.%5 == "%6"))',
tablestr(ProjInvoiceJour),
fieldstr(ProjInvoiceJour, ProjInvoiceType),
0+ProjInvoiceType::OnAccount,
tablestr(ProjInvoiceJour),
fieldstr(ProjInvoiceJour, CountryRegionID),
'ES'));
Hi i got question for the entity query. Please see my code
var list = from table in db.USER_BETTINGS
where table.UserID == UserId
&& table.UserID !="admin"
//&& table.WinningAfterRebate != 0m
&& table.BettingTransactionTime >= fromDate &&
table.BettingTransactionTime <= toDAte
//&& table.WinningAfterRebate !=0m
// orderby table.BettingTransactionNumber descending//table.BettingNumber descending//, table.BettingTransactionTime descending//
select table;
if (loteryNumber != 0)
{
list= list.Where(x => x.LotteryNumber == loteryNumber);
}
if (gameNum != 0)
{
list= list.Where(x => x.GameNumber == gameNum);
}
if (periodDate != "")
{
list= list.Where(x => x.PeriodDate == periodDate);
}
if (close.Equals("Y"))
{
list= list.Where(w => w.WinningAfterRebate != 0m);
}
else
{
list= list.Where(x => x.WinningAfterRebate == 0);
}
But the list not filtering , It return all record? Anyone got face this problem before?
You need some makeover in this code. You have unnecessarily used so many if condition, we need to get rid of that first. Change your query with the following.
var list =( from table in db.USER_BETTINGS
where table.UserID == UserId
&& table.UserID !="admin"
&& table.BettingTransactionTime >= fromDate
&& table.BettingTransactionTime <= toDAte
&& table.LotteryNumber == (loteryNumber != 0 ? loteryNumber : table.LotteryNumber)
&& table.GameNumber == (gameNum != 0 ? gameNum : table.GameNumber)
&& table.PeriodDate == (periodDate != string.Empty ? periodDate : table.PeriodDate )
&& (close.Equals("Y") ? table.WinningAfterRebate != 0 : table.WinningAfterRebate == 0)
).ToList();
please find below code.It will through an error 'The source contains no DataRow' if ithe row is empty..How to handle this ??
if (dtTemSec.Rows.Count > 0)
{
grdStepDetails.DataSource = dtTemSec.AsEnumerable()
.Where(x => x.Field<string>("Status") != "D" && x.Field<string>("ID") == "ST" && x.Field<int>("Folder") == folder)
.CopyToDataTable();
grdStepDetails.DataBind();
ClientScript.RegisterStartupScript(GetType(), "Val", "ShowStepPopup();", true);
}
else
{
grdStepDetails.DataSource = null;
grdStepDetails.DataBind();
ClientScript.RegisterStartupScript(GetType(), "Val", "ShowStepPopup();", true);
}
Use like this :-
if (dtTemSec.Rows.Count > 0)
{
var table = dtTemSec;
var rows = table.AsEnumerable().Where(x => x.Field<string>("Status") != "D" && x.Field<string>("ID") == "ST" && x.Field<int>("Folder") == folder);
var dt = rows.Any() ? rows.CopyToDataTable() : table.Clone();
grdStepDetails.DataSource = dt;
grdStepDetails.DataBind();
ClientScript.RegisterStartupScript(GetType(), "Val", "ShowStepPopup();", true);
}
else
{
grdStepDetails.DataSource = null;
grdStepDetails.DataBind();
ClientScript.RegisterStartupScript(GetType(), "Val", "ShowStepPopup();", true);
}
Use a If condition as below.
if(dtTemSec != null)
{
if(dtTemSec.Rows.Count > 0)
{
}
}
EDIT:
If that is the case, then put the condition after the Filter
if(dtTemSec != null)
{
if(dtTemSec.Rows.Count > 0)
{
DataTable Temp = new DataTable();
Temp = dtTemSec.AsEnumerable()
.Where(x => x.Field<string>("Status") != "D" && x.Field<string>("ID") == "ST" && x.Field<int>("Folder") == folder)
.CopyToDataTable();
if(Temp != null)
{
if(Temp.Rows.Count > 0)
{
grdStepDetails.DataSource=Temp;
grdStepDetails.DataBind();
ClientScript.RegisterStartupScript(GetType(), "Val", "ShowStepPopup();", true);
}
}
}
}
i am trying to make the drop down list to be visible for certain user only. for example for user =1 i want the drop down list to be visible and for user = 2 i don't want the drop down list to be visible.
i have tried this.
if ((Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 1) ||
Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 2 ||
Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 4)
{
ddlSpecialist.Visible = true;
ddlSpecialist.DataSource = Lundbeck.Web.BusinessLogic.FrequencyReport.GetFrequencyReportbySpecialistList();
ddlSpecialist.DataTextField = "Repcode";
ddlSpecialist.DataValueField = "Repcode";
ddlSpecialist.DataBind();
ddlSpecialist.Items.Insert(0, new ListItem("All", "0"));
ddlSpecialist.SelectedValue = "0";
if (Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 3)
{
ddlSpecialist.Visible = false;
}
}
i dont get the result that i want when i do this. why is that?? thanks in advance.
What are you trying to do please see you if condition you are checking if user==1 || user==2 || user==4
than you are showing dropdownlist and in same if condition you are checking if user==3 how is this possible if user==1 || user==2 || user==4 than it cannot be ==3 change your code like this.
if ((Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 1) ||
Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 2 ||
Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 4)
{
ddlSpecialist.Visible = true;
ddlSpecialist.DataSource = Lundbeck.Web.BusinessLogic.FrequencyReport.GetFrequencyReportbySpecialistList();
ddlSpecialist.DataTextField = "Repcode";
ddlSpecialist.DataValueField = "Repcode";
ddlSpecialist.DataBind();
ddlSpecialist.Items.Insert(0, new ListItem("All", "0"));
ddlSpecialist.SelectedValue = "0";
}
else if (Convert.ToInt32(HttpContext.Current.Session["UserGroupId"]) == 3)
{
ddlSpecialist.Visible = false;
}