|
Hey all I have been racking my brain trying to figure out what it is I am missing from the code below in order for the value "7:50 pm" to be placed into the variable theCntDownTimerTime from the TinyWS.cs class.
Let say the code below starts out with the time "7:00 pm".
I send the command from PostMAN (7:50 pm) and it picks it up just fine and the jsonSent.changeCNT does have the correct value of "7:50 pm". However, after this it seems to lose that value once the timer updates in the clockCoiuntDown.xaml.cs page for the theCntDownTimerTime.ToLower(). That value is still the same value (7:00 pm) as it was when the program started up and read my text file to get the default time.
clockCountDown.xaml.cs
namespace laptopWatcher {
public partial class clockCountDown: Window {
public string theCntDownTimerTime = "";
public clockCountDown() {
InitializeComponent();
theCntDownTimerTime = getTimeToStart();
}
private void Window_Loaded(object sender, RoutedEventArgs e) {
var desktopWorkingArea = SystemParameters.WorkArea;
this.Left = desktopWorkingArea.Right - this.Width - 20;
this.Top = desktopWorkingArea.Top + this.Height - 30;
var ts = ((60 - DateTime.Now.Second) * 1000 - DateTime.Now.Millisecond);
clockTimer.Tick += new EventHandler(clockTimer_tick);
clockTimer.Interval = new TimeSpan(0, 0, 35);
clockTimer.Start();
bgTxt.Text = DateTime.Now.ToString("h:mm tt");
txt.Text = DateTime.Now.ToString("h:mm tt");
if (txt.Text.ToLower().Equals(theCntDownTimerTime.ToLower())) {
_timer.Stop();
TimeSpan time = TimeSpan.Parse(theCntDownTimerTime);
cdownTimer((_time).TotalSeconds);
}
_tws = new TinyWS();
Thread t = new Thread(new ThreadStart(_tws.startWS));
t.Start();
}
private void clockTimer_tick(object sender, EventArgs e) {
bgTxt.Text = DateTime.Now.ToString("h:mm tt");
txt.Text = DateTime.Now.ToString("h:mm tt");
Console.WriteLine(txt.Text.ToLower() + " vs " + theCntDownTimerTime.ToLower());
}
public string getTimeToStart() {
string line;
using(StreamReader sr = new StreamReader(Environment.CurrentDirectory + "\\timestart.txt")) {
line = sr.ReadLine();
}
return line.ToLower();
}
}
}
TinyWS.cs
namespace laptopLogin {
class TinyWS: clockCountDown {
HttpListener listener = new HttpListener();
clockCountDown ccd = new clockCountDown();
public class receivedData {
public string changeCNT {
get;
set;
}
public int timeAdd {
get;
set;
}
public bool internet {
get;
set;
}
public bool shutdownNow {
get;
set;
}
}
public void startWS() {
var prefixes = new List < string > () {
"http://*:8888/"
};
foreach(string s in prefixes) {
listener.Prefixes.Add(s);
}
listener.Start();
Console.WriteLine("Listening...");
while (true) {
HttpListenerContext context = listener.GetContext();
HttpListenerRequest request = context.Request;
string documentContents;
using(Stream receiveStream = request.InputStream) {
using(StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8)) {
documentContents = readStream.ReadToEnd();
}
}
Console.WriteLine($"Recived request for {request.Url}");
Console.WriteLine(documentContents);
HttpListenerResponse response = context.Response;
receivedData jsonSent = JsonConvert.DeserializeObject < receivedData > (documentContents);
if (jsonSent.changeCNT.ToLower() != ccd.getTimeToStart()) {
using(StreamWriter sw = new StreamWriter(Environment.CurrentDirectory + "\\timestart.txt", false)) {
sw.WriteLine(jsonSent.changeCNT);
}
ccd.theCntDownTimerTime = jsonSent.changeCNT;
}
string responseString = "hit";
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
response.ContentLength64 = buffer.Length;
Stream output = response.OutputStream;
output.Write(buffer, 0, buffer.Length);
output.Close();
}
}
public void stopWS() {
listener.Stop();
}
}
}
So what would I be missing? It looks fine to me but just doesn't store the value over.
I also have tried:
public string theCntDownTimerTime = "";
public string _newCNT {
get {
return theCntDownTimerTime;
} z
set {
theCntDownTimerTime = value;
}
}
And on the TinyWS.cs page I have it sending by like ccd._newCNT = jsonSent.changeCNT;
But that also does not hold the new value.
|
|
|
|
|
From the code you've shown, your clockCountDown window only sets the theCntDownTimerTime field when it first loads. Nothing else in that class touches it.
Your window creates a new instance of the TinyWS class, which inherits from clockCountDown . That window is never shown.
That invisible window instance creates yet another instance of clockCountDown , which is also never shown.
It is only the field on that new invisible instance which is updated. The field on the original window instance is never touched.
I suspect you need to go back to the beginning and review the basics of how C# and OOP work:
Introduction to C# - interactive tutorials | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
I want to detect the user email address when the user clicks on a link sent to their email, the following:
1. From my c# windows application I send an email to (a@y.com,b@y.com) and in the cc (c@y.com).
2. when the user open his email and click an a link inside the email body, this link will open a web page, I want to know the user who clicked the link. is (a@y.com or b@y.com or c@y.com).
Please let me know if it is possible an how to do that
Thank You
|
|
|
|
|
The only option you have is to include the users email address in your link. The site would have to parse out the email address from the URL parameters.
|
|
|
|
|
Dave suggests one way, but another is to add a query code to the link. Make it unreadable - a Guid is fine - and use that value to lookup in your "sent emails" database which user email address it was sent to.
This way, you don't expose any sensitive info, and it's not possible (or at least feasible in a reasonable timeframe) to give a fake email and then confirm it without the actual email sent by you. It's also simple to "expire" confirmations. What you end up with is a URL that is readable, copy'n'pasteable, or clickable, but preety much impossible to guess:
mydomain.com/register.aspx?ec=50660b24af1f4056afc292ed3f9cece1
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
As the other answers have pointed out, you need to include something in the link to identify the address you sent it to.
What might not be obvious is that this means you cannot send the same link to multiple addresses and expect to identify which one clicked the link. That means you need to send different messages to a@y.com , b@y.com , and c@y.com .
If there are multiple addresses in the "To" field, or you're using both "To" and "Cc", you cannot determine which recipient clicked the link.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'm using DevExpress in my own project. I have two forms. the main form is DevExpress Spreadsheet. I want to access spreadsheet form information (cells information) in my second form. The second form isn't spreadsheet and used as a PivoteTable for creating charts. How is it possible?
|
|
|
|
|
|
And assuming the controls are "public"; etc. It's a third party product.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hopefully not - that's why you write properties in the Form that fetch the data without the outside world knowing what controls are used internally - but you know that, I'm writing for the OP here!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
No "experts" in the DevExpress forums?
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hi,
I want to check for existing open forms and if the desired form was not open, open it.
The problem is that my code gives runtime error:
System.InvalidOperationException: 'Collection was modified; enumeration operation may not execute.'
this error occurs in this part of the code:
foreach (Form frm in fc)
How can I fix this?
my code:
FormCollection fc = Application.OpenForms;
foreach (Form frm in fc)
{
if (frm.Name == "Chart")
{
MessageBox.Show("The form is open","error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
else
{
Chart myCharts = new Chart();
myCharts.Show();
}
}
modified 25-Mar-21 5:35am.
|
|
|
|
|
You don't show the code of your loop body, but from the error message you are either adding or removing a control / form from the collection fc inside the loop. You can't do that: modifying the source of an iterator while the iterator is in use because if you did, it would not be clear what the next iteration value should be!
You could change to a for loop, but you may need to run it backwards to avoid getting a similar problem in your own code.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I forgot to provide my code. I added it to the main question.
I repeat it again:
FormCollection fc = Application.OpenForms;
foreach (Form frm in fc)
{
if (frm.Name == "Chart")
{
MessageBox.Show("The form is open","error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
else
{
Chart myCharts = new Chart();
myCharts.Show();
}
}
|
|
|
|
|
Yes - and you are adding a form to the collection.
When you call Show, it adds the new form to the Application.OpenForms collection, and since fc is a reference to that collection, you are modifying the collection which you are iterating over it. Worse, you are adding it every time an existing form is not teh one you are looking for!
You can't do that.
The way I'd do it is simpler:
if (!Application.OpenForms.Cast<Form>().Any(frm => frm.Name == "Chart"))
{
... add your new form ...
}
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
NB: In your current code, you will open another instance of the chart form for every non-chart form you have open, regardless of how many instances of the chart form are already open.
Try:
ChartForm myCharts = Application.OpenForms.OfType<Chart>().FirstOrDefault();
if (myCharts == null)
{
myCharts = new Chart();
myCharts.Show();
}
else
{
myCharts.Activate();
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Please help me to create a code for copy a selected gridview row to the same gridview in asp.net c#
|
|
|
|
|
You create a new row; you then copy the selected row to the new row.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Now now, isn't suggesting problem decomposition a bit unfair? That requires more thought than "cOdEz PlZ!"
"Never attribute to malice that which can be explained by stupidity."
- Hanlon's Razor
|
|
|
|
|
Slightly off topic:
Thanks for your sig
"Never attribute to malice that which can be explained by stupidity."
- Hanlon's Razor
I've been using the quote for a long time (and I'd misremembered it as "Never attribute to malevolence that which can be explained by stupidity.") and had not found out where it had originated.
|
|
|
|
|
Eh, you may well have it right; it's existed in many forms over the years. I think the original went with "incompetence" as well, but I have admittedly picked a version that reflects my own feelings.
At any rate, it's an absolutely essential attitude when working in cybersecurity.
"Never attribute to malice that which can be explained by stupidity."
- Hanlon's Razor
|
|
|
|
|
Nathan Minier wrote: At any rate, it's an absolutely essential attitude when working in cybersecurity. or when getting edicts from management!
|
|
|
|
|
I am creating a book site for that, I have created dynamic buttons so that if on a particular category is clicked then that row will be fetched from the database and required information will be displayed. Now I want that if the user clicks on any particular book then the data of that book should be displayed in another panel and the current panel should hide.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.UI.HtmlControls;
namespace WebApplication1
{
<pre>
public partial class Genre : System.Web.UI.Page
{
private int num;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);<br />
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "Romance";
Panel2.Visible = false;
con.Open();
String SQL = "Select * from Book_List where Book_category='" + Label1.Text + "'";
SqlDataAdapter da = new SqlDataAdapter(SQL, con);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
da.Fill(ds);
num = ds.Tables[0].Rows.Count;
HtmlGenericControl Book = new HtmlGenericControl("div");
Book.Attributes.Add("class", "books");
Panel1.Controls.Add(Book);
for (int i = 1; i < num; i++)
{
HtmlGenericControl myDiv = new HtmlGenericControl("div");
myDiv.Attributes.Add("class", "myDiv");
ImageButton image = new ImageButton();
image.ImageUrl = ds.Tables[0].Rows[i]["Book_image"].ToString();
image.CssClass = "Img";
image.Click += new ImageClickEventHandler(this.image_Click);
HtmlGenericControl content = new HtmlGenericControl("div");
content.Attributes.Add("class", "content");
Label name = new Label();
name.CssClass = "name";
name.Text = ds.Tables[0].Rows[i]["Book_name"].ToString();
Label cost = new Label();
cost.CssClass = "cost";
cost.Text = "<br/> Rs " + ds.Tables[0].Rows[i]["Book_cost"].ToString();
Button wishlist = new Button();
wishlist.CssClass = "wishlist";
wishlist.Text = "ADD TO WISHLIST";
Book.Controls.Add(myDiv);
myDiv.Controls.Add(image);
myDiv.Controls.Add(content);
content.Controls.Add(name);
content.Controls.Add(cost);
content.Controls.Add(wishlist);
}
}
protected void image_Click(object sender, ImageClickEventArgs e)
{
ImageButton image = sender as ImageButton;
Panel2.Visible = true;
Panel1.Visible = false;
}
</pre>
|
|
|
|
|
Every control in .NET has a Tag property, which is an object so it can store any instance of any class. If you create a class to hold the book information, you could set the Tag of the button to that class instance when you create the Button.
Then in the Click handler you can get the Button instance from the sender parameter, and use that to get the book information from it's Tag.
Then you can do with it what you wish!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Not in a WebForms app.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|