I try to use jQuery slide for price, as in this picture
So the user can filter the result as he want,
the jQuery code that i used is as follows:
<script>
var min = parseInt($('#<%=lbmin.ClientID%>').html());
var max = parseInt($('#<%=lbMax.ClientID%>').html());
var Smin = parseInt($('#<%=lbrangeMin.ClientID%>').html());
var Smax = parseInt($('#<%=lbrangeMax.ClientID%>').html());
if (Smin = isNaN )
{
Smin = min;
}
if (Smax = isNaN) {
Smax = max;
}
$(function () {
$("#slider-range").slider({
range: true,
min: min,
max: max,
values: [Smin, Smax],
slide: function (event, ui) {
var start = parseInt(ui.values[0]);
var end = parseInt(ui.values[1]);
$("#amount").val($('#<%=hfCur.ClientID%>').val() + " " + ui.values[0] + " - " + $('#<%=hfCur.ClientID%>').val() + " " + ui.values[1]);
$('#<%=lbrange.ClientID%>').html(ui.values[0] + " - " + ui.values[1]);
$('#<%=lbrangeMin.ClientID%>').html(ui.values[0] );
$('#<%=lbrangeMax.ClientID%>').html(ui.values[1]);
$('#<%=hfrange.ClientID%>').val(ui.values[1]);
}
});
$("#amount").val($('#<%=hfCur.ClientID%>').val() + " " + $("#slider-range").slider("values", 0) +
" - " + $('#<%=hfCur.ClientID%>').val() + " " + $("#slider-range").slider("values", 1));
});
So when page loads the first time min and max value will set on the label lbmin and lbmax, and when the user pulls the tape the range will change as pulling. and the value will set in other label lbrangeMin and lbrangeMax.
and until now everything works fine,
my request is: I need to run C# method like
protected void ttt()
{ some code }
I found several solutions, but all of it using a static method with a return value, and another thing when page post-back the ring should not reset.
Related
Ok quite simply I have a selenium script in C# and you choose a name from the dropdown box, choose the dates and counts the number of results page by page. Now can someone help me speed this process because it almost takes 5 seconds for the next button to be clicked to go on the next page.
Here is my code:
int entityCount = 0;
int totalCount = 0;
try
{
System.Threading.Thread.Sleep(5000);
while (_AuditRep.nextButton.Enabled && _AuditRep.nextButton.Displayed)
{
System.Threading.Thread.Sleep(5000);
_AuditRep.nextButton.Click();
entityCount += _AuditRep.AuditResultsByEntity("Users").Count;
totalCount += _AuditRep.AuditTotalResults.Count;
}
if (entityCount != totalCount)
{
Assert.Fail("The count of Drivers is " + entityCount + " whereas "
+ "the total count is " + totalCount);
}
else
{
Console.WriteLine("The count of entity Drivers is " + entityCount + " and "
+ "the total count is " + totalCount);
}
}
catch
{
if (_AuditRep.AuditResultsByEntity("Users").Count != _AuditRep.AuditTotalResults.Count)
{
Assert.Fail("The count of Drivers is " + _AuditRep.AuditResultsByEntity("Users").Count + " whereas "
+ "the total count is " + _AuditRep.AuditTotalResults.Count);
}
else
{
Console.WriteLine("The count of entity Drivers is " + _AuditRep.AuditResultsByEntity("Users").Count + " and "
+ "the total count is " + _AuditRep.AuditTotalResults.Count);
}
}
I am making the game minesweeper and I am trying to implement a highScores feature. I am trying to load 3 different files (each one holds the high scores for each of the 3 difficulty settings) into 3 different richTextBox's. When I run the app and click the 'high scores' tab from the menu strip it works the first time. However if I play a game and then try to access the high scores form I get an Exception error -
An unhandled exception of type 'System.IO.IOException' occurred in
mscorlib.dll
Additional information: The process cannot access the file
'C:\Users\jzcon_000\Copy\Visual
Studio\Projects\Assignment1\Assignment1\bin\Debug\highScoresMed.txt'
because it is being used by another process
This is where the call is made
private void highScoresToolStripMenuItem_Click(object sender, EventArgs e)
{
Minesweeper.HighSc highScore = new Minesweeper.HighSc();
highScore.read();
highScore.Show();
}
This is the method in my HighSc class
public void read()
{
StreamReader readerE = File.OpenText("highScoresEasy.txt");
StreamReader readerM = File.OpenText("highScoresMed.txt");
StreamReader readerH = File.OpenText("highScoresHard.txt");
if (readerE != null)
{
string readEasy = File.ReadAllText("highScoresEasy.txt");
richTextBox1.Text = readEasy;
}
readerE.Close();
if (readerM != null)
{
string readMed = File.ReadAllText("highScoresMed.txt");
richTextBox2.Text = readMed;
}
readerM.Close();
if (readerH != null)
{
string readHard = File.ReadAllText("highScoresHard.txt");
richTextBox3.Text = readHard;
}
readerH.Close();
}
Heres the save high scores class
namespace Minesweeper
{
class Save
{
int diff, hr, min, sec;
string player;
public Save(int difficulty, int hour, int minute, int second, string playerN)
{
diff = difficulty;
hr = hour;
min = minute;
sec = second;
player = playerN;
}
public void save()
{
StreamWriter writerEasy = new StreamWriter("highScoresEasy.txt", true);
StreamWriter writerMed = new StreamWriter("highScoresMed.txt", true);
StreamWriter writerHard = new StreamWriter("highScoresHard.txt", true);
if (diff == 1)
{
writerEasy.WriteLine("Time: " + hr + ":" + min + ":" + sec + " " + "Name: " + player);
writerEasy.Close();
}
else if (diff == 2)
{
writerMed.WriteLine("Time: " + hr + ":" + min + ":" + sec + " " + "Name: " + player);
writerMed.Close();
}
else if (diff == 3)
{
writerHard.WriteLine("Time: " + hr + ":" + min + ":" + sec + " " + "Name: " + player);
writerHard.Close();
}
}
}
}
So when you have the difficulty level set to 1 and then save, you open the StreamWriters for both the level2 and level3 but never close them.
This could only mean that when you try to load the highscore for these two levels you will find your files locked by your previous save.
You should change your Save method to open only the required file
public void save()
{
if (diff == 1)
{
using(StreamWriter writerEasy = new StreamWriter("highScoresEasy.txt", true))
{
writerEasy.WriteLine("Time: " + hr + ":" + min + ":" + sec + " " + "Name: " + player);
}
}
else if (diff == 2)
....
else if (diff == 3)
....
I suggest also to use the using statement in your reading method to be sure that also in case of exceptions the stream are correctly disposed
This question already has answers here:
What is a NullReferenceException, and how do I fix it?
(27 answers)
Closed 8 years ago.
So I have my memory class which looks like this:
namespace GeminiCore
{
public class Memory
{
public static int[] memory = new int[256];
public string nextInstruction;
public static int cacheSize = 8;
public CPU myCPU;
public struct frame
{
public bool dirtyBit;
public int isEmpty;
public int value;
public int tag;
public frame(int cacheSize)
{
dirtyBit = false;
isEmpty = 1;
value = 0;
tag = 0;
}
}
public int solveMemory(int value, int instr, frame[] myCache)
{
Console.WriteLine("I reached the solveMemory!!!");
int block = value % cacheSize;
if(instr == 127 || instr == 125 || instr == 124 || instr == 123
|| instr == 122 || instr == 121|| instr == 120)
{
Console.WriteLine("I reached the read section!!!");
if(myCache[block].isEmpty == 0) //Read hit
if(myCache[block].tag == value)
return myCache[block].value;
else
{
myCache[block].value = memory[value]; //Read Miss
myCache[block].tag = value;
myCache[block].isEmpty = 0;
Console.WriteLine("Read Miss --- The Cache is as follows: block = " + block + " the value at this block is: " + myCache[block].value + " the tag at this block is: " + myCache[block].tag);
return myCache[block].value;
}
}
else
{
Console.WriteLine("I reached the write section!!!");
if (myCache[block].isEmpty == 1) //Write Miss
{
Console.WriteLine("Write Miss --- The Cache is as follows: block = " + block + " the value at this block is: " + myCache[block].value + " the tag at this block is: " + myCache[block].tag);
memory[value] = myCPU.ACC;
}
else
{
if (myCache[block].dirtyBit == false)
{
if (myCache[block].tag != value)
{
myCache[block].value = myCPU.ACC; //Write Hit
myCache[block].dirtyBit = true;
myCache[block].tag = value;
Console.WriteLine("Write Hit --- The Cache is as follows: block = " + block + " the value at this block is: " + myCache[block].value + " the tag at this block is: " + myCache[block].tag);
}
}
else
{
memory[myCache[block].tag] = myCache[block].value;
myCache[block].value = myCPU.ACC;
myCache[block].tag = value;
myCache[block].dirtyBit = false;
Console.WriteLine("Write Hit --- The Cache is as follows: block = " + block + " the value at this block is: " + myCache[block].value + " the tag at this block is: " + myCache[block].tag);
}
}
}
return value;
}
}
}
and then I have my CPU class, and I will just post a small snippet of where the error is occurring:
public Memory myMemory;
public static Memory.frame[] myCache = new Memory.frame[Memory.cacheSize];
public void doInstruction()
{
var instr = (finalCodes[i] >> 9) & 127; //Parses op code to find instruction
var immed = (finalCodes[i] >> 8) & 1; //Parses op code to find immediate value
var value = (finalCodes[i] & 255); //Parse op code to find value
foreach (Memory.frame x in myCache)
{
Console.WriteLine("Dirtybit: " + x.dirtyBit + " isEmpty: " + x.isEmpty + " tag: " + x.tag + " value: " + x.value);
}
switch (instr)
{
case (127): //LDA instruction
if (immed == 1)
ACC = value;
else if (immed == 0)
//ACC = Memory.memory[value];
ACC = myMemory.solveMemory(value, instr, myCache);
break;
case (126): //STA instruction
if (immed == 0)
{
Console.WriteLine("The value is: " + value + " The instruction is: " + instr);
foreach (Memory.frame x in myCache)
{
Console.WriteLine("Dirtybit: " + x.dirtyBit + " isEmpty: " + x.isEmpty + " tag: " + x.tag + " value: " + x.value);
}
//Memory.memory[value] = ACC;
myMemory.solveMemory(value, instr, myCache);
}
So here is my problem, when I run my test which takes in assembly code and translates it to binary then runs through the code, when I get to the second command "sta" it should go to the line:
myMemory.solveMemory(value, instr, myCache);
It then gives me a Null Reference Exception when it reaches that point. As you can see I have some command line output to try and see where it is going. It prints out the contents of myCache right before that line. It does not reach any of the debug statements in the solveMemory function however, not even the first one that says:
Console.WriteLine("I reached the solveMemory!!!");
I'm not really sure what is causing this error and I've been looking at it for quite some time. Hopefully one of you will be able to find where exactly I am messing up. Thanks for the time.
public Memory myMemory;
should be:
public Memory myMemory = new Memory();
Hi i want to auto refresh the checked page without refreshing the other page. I got two pop up's which is working fine, i just want radio button to work fine when it's check. presently it's refreshing the page which is not checked after 10 sec, please someone help me. Swift response will be appriciated. Thanks
<script type="text/JavaScript">
$(document).ready(function() {
setTimeout("timerefresh();", 10000);
});
function timerefresh()
{
alert(document.getElementById('hdnReload').value + " Before IF");
if (document.getElementById('hdnReload').value == 'MainPage')
{
var SelectedRadioBtn;
var radioButtons = document.getElementsByName("rdbOptions");
for (var x = 0; x < radioButtons.length; x++) {
if (radioButtons[x].checked) {
alert("You checked " + radioButtons[x].id + " which has the value " + radioButtons[x].value);
SelectedRadioBtn = radioButtons[x].value;
//$('input[value ="lstScheduled"]').prop('checked', true);
}
}
setTimeout("location.reload(true);", 10000);
$('input[value ="'+SelectedRadioBtn+'"]').attr('checked', true);
}
else
{
setTimeout("timeRefresh()",10000);
}
}
</script>
You can use setInterval instead of setTimeout and it will reduce your code.
setInterval(function () {
alert(document.getElementById('hdnReload').value + " Before IF");
if (document.getElementById('hdnReload').value == 'MainPage') {
var SelectedRadioBtn;
var radioButtons = document.getElementsByName("rdbOptions");
for (var x = 0; x < radioButtons.length; x++) {
if (radioButtons[x].checked) {
alert("You checked " + radioButtons[x].id + " which has the value "
radioButtons[x].value);
SelectedRadioBtn = radioButtons[x].value;
//$('input[value ="lstScheduled"]').prop('checked', true);
}
}
setTimeout("location.reload(true);", 10000);
$('input[value ="' + SelectedRadioBtn + '"]').attr('checked', true);
}
}, 10000)
Setting a Scintilla.Net textbox with a string and scrolling to last line doesn't work.
This Q & A How make autoscroll in Scintilla? has the answer but it wont work at the same time as setting the text.
Bare bones repro:
private void button1_Click(object sender, EventArgs e)
{
string s = RandomString(400);
scintilla1.Text = s + " " + s + " " + s + " " + s + " " + s;
scintilla1.Scrolling.ScrollBy(0, 10000); //<-doesn't work (but does work eg in a Button2_click)
}
private static Random random = new Random((int)DateTime.Now.Ticks);
private string RandomString(int size)
{
StringBuilder builder = new StringBuilder();
char ch;
for (int i = 0; i < size; i++)
{
ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
builder.Append(ch);
}
return builder.ToString();
}
Does anyone know how to scroll vertically down to end line after setting the text?
Well you can try to put Refresh() after adding the text;
scintilla1.Text = s + " " + s + " " + s + " " + s + " " + s;
scintilla1.Refresh();
for this case i found out that you will need to Refresh() twice depend on the length of the string you put on the textbox.
For anyone wondering in the end I ditched Scintilla in favor of ICSharpCode.TextEditor. <- This one was a little unstable so I used the Digitalrune version of the ICsharp.TextEditor
I found enhancing the ICSharpCode.TextEditor was trivial compared with Scintilla.
Another huge benefit of ICSharpCode.TextEditor is that allows you to customize/build your own Syntax Highlighting, eg: https://github.com/icsharpcode/SharpDevelop/wiki/Syntax-highlighting