How to disable/enable the allowinsert in telerik radscheduler - asp.net

I have develop a Telerik Radscheduler in that i have write the code like below in that i want disable/Enable the perticuler time-slot for an event,in this disable is working fine but enable not working i can't understand why it is not enable to allow-insert.please help me where i need to change to resolve this problem...
protected void RadScheduler1_TimeSlotCreated1(object sender, TimeSlotCreatedEventArgs e)
{
//Getting Business hour time
mybusinesscalendarEntities objEntity = new mybusinesscalendarEntities();
var Result = from bhours in objEntity.businesshours where bhours.BusinessId == businessid select bhours;
if (Result.Count() > 0)
{
var Hours = (from bhours in objEntity.businesshours where bhours.BusinessId == businessid select bhours).First();
//Get particular day businee hour timings and disable the time slot
string Day = System.DateTime.Today.DayOfWeek.ToString();
if (Day == "Monday")
{
string WorkDay = Hours.MondayFromTime.Value.ToShortTimeString();
string WorkDayStart = WorkDay.Remove(WorkDay.Length - 2, 2);
string WorkDayEnd = Hours.MondayToTime.Value.ToShortTimeString();
string WorkDayEndTime = WorkDayEnd.Remove(WorkDayEnd.Length - 2, 2);
if ((e.TimeSlot.Start.TimeOfDay < TimeSpan.Parse(WorkDayStart.Trim())) || (e.TimeSlot.Start.TimeOfDay > TimeSpan.Parse(WorkDayEndTime.Trim())))
{
e.TimeSlot.CssClass = "Disabled";
RadScheduler1.ReadOnly = true;
}
else
{
RadScheduler1.ReadOnly = false;
RadScheduler1.AllowInsert = true;
RadScheduler1.AllowEdit = true;
RadScheduler1.AllowDelete = true;
}

If when your last timeslot is created (last time event is fired) this part evaluates to true.
if ((e.TimeSlot.Start.TimeOfDay < TimeSpan.Parse(WorkDayStart.Trim())) || (e.TimeSlot.Start.TimeOfDay > TimeSpan.Parse(WorkDayEndTime.Trim())))
{
e.TimeSlot.CssClass = "Disabled";
RadScheduler1.ReadOnly = true;
}
Then your entire scheduler will be in read only mode. This means no editing inserting deleting moving etc.
Your intention seems to be to disabled specific timeslots. I dont think you intend to set these properties in this particular event.
RadScheduler1.ReadOnly = false;
RadScheduler1.AllowInsert = true;
RadScheduler1.AllowEdit = true;
RadScheduler1.AllowDelete = true;
Test by commenting out the lines that set the readonly, allowinster, allowedit, allowdelete properties since they are not per timeslot, rather for the entire scheduler

Related

I have a "Upload Record" PXAction to load records to grid and release these records

I have a custom PXbutton called UploadRecords, when I click this button I should populate the grid with records and release the records.
Release Action is pressed in the UploadRecords action delegate. The problem I get with this code is, the code here function properly for less records by release action but when passes thousands of records to release, it takes huge time(> 30 min.) and show the error like Execution timeout.
suggest me to avoid more execution time and release the records fastly.
namespace PX.Objects.AR
{
public class ARPriceWorksheetMaint_Extension : PXGraphExtension<ARPriceWorksheetMaint>
{
//public class string_R112 : Constant<string>
//{
// public string_R112()
// : base("4E5CCAFC-0957-4DB3-A4DA-2A24EA700047")
// {
// }
//}
public class string_R112 : Constant<string>
{
public string_R112()
: base("EA")
{
}
}
public PXSelectJoin<InventoryItem, InnerJoin<CSAnswers, On<InventoryItem.noteID, Equal<CSAnswers.refNoteID>>,
LeftJoin<INItemCost, On<InventoryItem.inventoryID, Equal<INItemCost.inventoryID>>>>,
Where<InventoryItem.salesUnit, Equal<string_R112>>> records;
public PXAction<ARPriceWorksheet> uploadRecord;
[PXUIField(DisplayName = "Upload Records", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
[PXButton]
public IEnumerable UploadRecord(PXAdapter adapter)
{
using (PXTransactionScope ts = new PXTransactionScope())
{
foreach (PXResult<InventoryItem, CSAnswers, INItemCost> res in records.Select())
{
InventoryItem invItem = (InventoryItem)res;
INItemCost itemCost = (INItemCost)res;
CSAnswers csAnswer = (CSAnswers)res;
ARPriceWorksheetDetail gridDetail = new ARPriceWorksheetDetail();
gridDetail.PriceType = PriceTypeList.CustomerPriceClass;
gridDetail.PriceCode = csAnswer.AttributeID;
gridDetail.AlternateID = "";
gridDetail.InventoryID = invItem.InventoryID;
gridDetail.Description = invItem.Descr;
gridDetail.UOM = "EA";
gridDetail.SiteID = 6;
InventoryItemExt invExt = PXCache<InventoryItem>.GetExtension<InventoryItemExt>(invItem);
decimal y;
if (decimal.TryParse(csAnswer.Value, out y))
{
y = decimal.Parse(csAnswer.Value);
}
else
y = decimal.Parse(csAnswer.Value.Replace(" ", ""));
gridDetail.CurrentPrice = y; //(invExt.UsrMarketCost ?? 0m) * (Math.Round(y / 100, 2));
gridDetail.PendingPrice = y; // (invExt.UsrMarketCost ?? 0m)* (Math.Round( y/ 100, 2));
gridDetail.TaxID = null;
Base.Details.Update(gridDetail);
}
ts.Complete();
}
Base.Document.Current.Hold = false;
using (PXTransactionScope ts = new PXTransactionScope())
{
Base.Release.Press();
ts.Complete();
}
List<ARPriceWorksheet> lst = new List<ARPriceWorksheet>
{
Base.Document.Current
};
return lst;
}
protected void ARPriceWorksheet_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected InvokeBaseHandler)
{
if (InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (ARPriceWorksheet)e.Row;
uploadRecord.SetEnabled(row.Status != SPWorksheetStatus.Released);
}
}
}
First, Do you need them all to be in a single transaction scope? This would revert all changes if there is an exception in any. If you need to have them all committed without any errors rather than each record, you would have to perform the updates this way.
I would suggest though moving your process to a custom processing screen. This way you can load the records, select one or many, and use the processing engine built into Acumatica to handle the process, rather than a single button click action. Here is an example: https://www.acumatica.com/blog/creating-custom-processing-screens-in-acumatica/
Based on the feedback that it must be all in a single transaction scope and thousands of records, I can only see two optimizations that may assist. First is increasing the Timeout as explained in this blog post. https://acumaticaclouderp.blogspot.com/2017/12/acumatica-snapshots-uploading-and.html
Next I would load all records into memory first and then loop through them with a ToList(). That might save you time as it should pull all records at once rather than once for each record.
going from
foreach (PXResult<InventoryItem, CSAnswers, INItemCost> res in records.Select())
to
var recordList = records.Select().ToList();
foreach (PXResult<InventoryItem, CSAnswers, INItemCost> res in recordList)

Xamarin.Forms How to display progress indicator while sound recording/playback takes place

I would like to display a progress indicator while recording sound in my app.
The amount of time allocated for the recording is predefined. I set that up in code, lets say 10 seconds maximum recording time, but the user can stop the recording in less time, and of course he progress indicator would stop and reset.
I have been trying to make it work right could you please offer some guidance.
Note: I am using the NateRickard AudioRecorder nuget package.
if (!recorder.IsRecording)
{
buttonRecord.IsEnabled = false;
buttonPlay.IsEnabled = false;
DependencyService.Get<IAudioService>().PrepareRecording();
// start recording
var recordTask = await recorder.StartRecording();
// set up progress bar
//progressBarRecordTime.Progress = 1.0;
//await progressBarRecordTime.ProgressTo(1.0, 10000, Easing.Linear);
buttonRecord.Text = "Stop Recording";
buttonRecord.IsEnabled = true;
// get the recorded file
var recordedAudioFile = await recordTask;
buttonRecord.Text = "Record";
buttonPlay.IsEnabled = true;
if (recordedAudioFile != null)
{
var recordingFileDestinationPath = Path.Combine(FileSystem.AppDataDirectory, AppConstants.CUSTOM_ALERT_FILENAME);
if (File.Exists(recordingFileDestinationPath))
{
File.Delete(recordingFileDestinationPath);
}
File.Copy(recordedAudioFile, recordingFileDestinationPath);
}
}
Place an ActivityIndicator (name it ind) in your xaml code (view)
At the top of your code above:
ind.IsRunning = true;
//
if (!recorder.IsRecording)
//
when you are done, add this below your code
//
}
File.Copy(recordedAudioFile, recordingFileDestinationPath);
}
}
ind.IsRunning = false;

Trying to understand sorting in the Table widget for a Page

I am trying to understand how sorting works in Table widgets works when loading a page. For most of my pages using the Table widget, the page loads sorted by the first column.
I do see the below code in the onAttach event for the Table panel in a page. I am wondering if this is the code that sets the sorting when a page loads.
// GENERATED CODE: modify at your own risk
window._am = window._am || {};
if (!window._am.TableState) {
window._am.TableState = {};
window._am.inFlight = false;
}
if (!window._am.sortTableBy) {
window._am.sortTableBy = function(datasource, field, fieldHeader, tableState) {
if (!field) {
throw "Can't sort the table because specified field was not found.";
}
tableState.inFlight = true;
if (tableState.sortByField === field.name) {
tableState.ascending = !tableState.ascending;
} else {
if (tableState.fieldHeader) {
tableState.fieldHeader.text = tableState.fieldHeaderText;
tableState.fieldHeader.ariaLabel = "";
}
tableState.sortByField = field.name;
tableState.ascending = true;
tableState.fieldHeader = fieldHeader;
tableState.fieldHeaderText = fieldHeader.text;
}
datasource.query.clearSorting();
var sortDirection = tableState.ascending ? "ascending" : "descending";
datasource.query.sorting[field.name]["_" + sortDirection]();
datasource.query.pageIndex = 1;
datasource.load(function() {
tableState.inFlight = false;
fieldHeader.text = fieldHeader.text.replace(/ (\u25B2|\u25BC)/g, "");
if (tableState.sortByField === field.name) {
fieldHeader.ariaLabel = fieldHeader.text + " sort " + sortDirection;
fieldHeader.text = fieldHeader.text + (tableState.ascending ? " \u25B2" : " \u25BC");
app.accessibility.announce(fieldHeader.ariaLabel);
}
});
};
}
Sorting is set on your datasource.
Click the model (top left) that your table is using.
Click Datasources and expand your Datasource (there will only be one, unless you have created additional ones).
Once you choose the field you want the table to use for sorting, you can choose "Ascending" or "Descending".
The problem is with adding new records from a separate create form. The new records always appear at the end of the list , until a subsequent 'load' is performed.

Switching sprites of a object in different rooms

I am creating a character selection which changes the sprites of the main character.
To do this I have an arrow object which the user clicks to change the sprite of the main character.
global.Mario = true;
global.PrincessPeach = false;
global.Luigi = false;
global.Bowser = false;
if (mouse_check_button_pressed(mb_left)) {
if (global.Mario = true) {
Mario = false;
PrincessPeach= true;
}
if (global.PrincessPeach= true) {
PrincessPeach = true;
Mario = false;
}
if (global.Luigi = true) {
Luigi = false;
Bowser = true;
}
if (global.Bowser = true) {
Bowser = false;
Mario = true;
}
}
Then, on my main character I have a created an event executing code similar to the following:
if (global.Mario = true) {
sprite_index = Mario_NotJumping;
}
if (global.Luigi = true) {
sprite_index = Luigispr;
}
However, when I run my game to test it out, I get the following error:
FATAL ERROR in
action number 1
of Create Event
for object Mario_selection:
Push :: Execution Error - Variable Get -5.Mario(100000, -1)
at gml_Object_Mario_selection_Create_0 (line 1) - if (global.Mario = true) {
The object Mario_selection has the exact create event and same code as the main character. To display changes to the user.
If anyone could help me out, I am fairly new to GameMaker so I have a feeling I'm just misunderstanding global variables.
It looks like the var global.Mario, has not been declared. In the arrow objects create event put,
global.Mario = true;
global.PrincessPeach = false;
global.Luigi = false;
global.Bowser = false;
If i were you, i would save the chosen "image" of the user in 1 simple variable.
Add a few constants;
PLAYER_MARIO = 0;
PLAYER_PEACH = 1;
PLAYER_LUIGI = 2;
PLAYER_BOWSER = 3;
Then you can use those constants and save them in a global variable;
global.player_image = PLAYER_LUIGI;
Then you can use those in your objects like so;
switch (global.player_image) {
case PLAYER_MARIO:
sprite_index = Mario_NotJumping;
break;
case PLAYER_PEACH:
sprite_index = Peach_NotJumping;
break;
case PLAYER_LUIGI:
sprite_index = Luigi_NotJumping;
break;
case PLAYER_BOWSER:
sprite_index = Bowser_NotJumping;
break;
}
The specific error you were getting was because the global variable was not defined at the time of use.
A better method by the way, would be something like this - saving all sprite handles into specific variables, then using those.
Define some constants for readability;
P_LEFT = 0;
P_RIGHT = 1;
P_JUMP = 2;
Then whenever a player switches its character;
//When the user switches to peach;
global.player_sprite[P_LEFT] = spr_Peach_Left;
global.player_sprite[P_RIGHT] = spr_Peach_Right;
global.player_sprite[P_JUMPING] = spr_Peach_Jumping;
And overwrite;
//When the user switches to Luigi;
global.player_sprite[P_LEFT] = spr_Luigi_Left;
global.player_sprite[P_RIGHT] = spr_Luigi_Right;
global.player_sprite[P_JUMPING] = spr_Luigi_Jumping;
Then you can code all code like this;
if (jumping) {
sprite_index = global.player_sprite[P_JUMPING];
} else {
sprite_index = global.player_sprite[P_LEFT];
}
Do you understand what i mean? This way you won't need the switch statements everywhere, and just store the chosen sprites in 1 single array at the beginning of the game.
You can then code the game without having to check what player image the player chose.
Also, always define global variables at the beginning of the game. Global variables will always exist in the game, in every room, at any given moment.
You should use var mario=true; instead.

Most efficient way to check to see if there is any data in a SQL row

The code below works, but I know it can't be the most efficient. Is there another way to ask if there are any rows rather than using Any()?
I'd like to have the NoResults Div hidden by default and only turned on when no rows are present, likewise have the repeater show up by default and only hidden when no results are listed.
using (AgileEntities context = new AgileEntities())
{
int StoryID = Convert.ToInt32(Request["StoryID"]);
var tasks = from t in context.Tasks
where t.StoryId == StoryID
orderby t.Number
select t;
rptTasks.DataSource = tasks;
rptTasks.DataBind();
if (tasks.Any())
{
rptTasks.Visible = true;
NoResults.Visible = false;
}
else
{
rptTasks.Visible = false;
NoResults.Visible = true;
}
}
Caution - calling .Any() may re-execute your query
I would do this a bit 'safer' to ensure single execution.
//force execution once
var taskList = tasks.ToList();
rptTasks.Visible = taskList.Count>0;
NoResults.Visible = taskList.Count==0;
And
rptTasks.DataSource = tasksList;
rptTasks.DataBind();
The problem with Any() and Count() is they cause your code to execute over and over - a test case
static void Main(string[] args)
{
//Populate the test class
List list = new List(1000);
for (int i=0; i o.CreateDate.AddSeconds(5) > DateTime.Now);
while (newList.Any())
{
//Note - are actual count keeps decreasing.. showing our 'execute' is running every time we call count.
Console.WriteLine(newList.Any());
System.Threading.Thread.Sleep(500);
}
}
You can replace Any() with Count() above to show. Basically the code keeps evaluating the query when you call Any() - I'm not sure if this applies to Linq to Sql though if there is any different caching mechanism.
var tasks = from t in context.Tasks
where t.StoryId == StoryID
orderby t.Number
select t;
var tasksList = tasks.ToList();
rptTasks.DataSource = tasksList;
rptTasks.DataBind();
if (tasksList.Count > 0)
{
rptTasks.Visible = true;
NoResults.Visible = false;
}
else
{
rptTasks.Visible = false;
NoResults.Visible = true;
}
The ToList() call will execute the query and create a list of tasks objects
Your DataBind() call has already caused the query to be executed, so calling Any() on top of that shouldn't cost you anything further.
You can change this with :
rptTasks.Visible = tasks.Any();
NoResults.Visible = !rptTasks.Visible;

Resources