|
Sure, Gerry. Thanks for your comment. I meant the "shapes library similar to Visio's".
To avoid the confusion I have deleted that part.
Thanks again
|
|
|
|
|
Visio requires one to drag and drop connectors, and join each end.
"Auto-connect" will encounter all the problems you identified.
If I was to improve on Visio:
1) Drag and drop shapes (already does this)
What it can't do:
2) Initiate a "connect" operation, using a given connector, and some "motion"
3) "Tap" connection points 1 (tail) and 2 (head)
4) Visio adds the connection, respecting the head and tail symbols, if present.
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
|
|
|
|
|
Thanks Gerry. But , again, there is No need of doing/improving/doing anything with Visio.
Just about ways to autoconnect shapes in WPF.
|
|
|
|
|
So, you're unable to take the references to Visio and relate them to your situation?
(I have no actual plans to "improve" Visio).
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
|
|
|
|
|
Nope. I am trying to understand the ways it can be done from more skilled coders...
|
|
|
|
|
Hi, I'm trying to make a library where you can add books, search for books etc, I have a hardcoded book that you should be able to search for but it only displays the after I add a new book and then it will display the hardcoded book if you search for it again
the code
public class Book
{
public String BookName { get; set; }
public String AuthorName { get; set; }
public int NumberOfCopiesInStock { get; set; }
public String ISBN { get; set; }
public Book(String bookName, String authorName, int numberOfCopiesInStock, String isbn)
{
this.BookName = bookName;
this.AuthorName = authorName;
this.NumberOfCopiesInStock = numberOfCopiesInStock;
this.ISBN = isbn;
}
public override String ToString()
{
return ("BookName: " + BookName
+ "\n"
+ "Author Name: " + AuthorName
+ "\n"
+ "Number Of Copies: " + NumberOfCopiesInStock
+ "\n"
+ "ISBN: " + ISBN);
}
}
public class Search
{
public Boolean SearchForBook()
{
Console.WriteLine("Please enter name of book: ");
String search = Console.ReadLine();
UserInput.MakeTheComputerSleep();
foreach (Book b in UserInput.bookList)
{
if (b.BookName.Equals(search))
{
Console.WriteLine(b);
return true;
}
}
Console.WriteLine("Book doesn't exist! ");
return false;
}
}
<pre>public class UserInput
{
public static Boolean KeepGoing = true;
public static List<Book> bookList = new List<Book>();
private static readonly String INPUT_ERROR_MESSAGE = "Please only enter NUMBERS!";
private static readonly String INVALID_CHOICE = "INVALID CHOICE ENTERED!";
private static readonly String SEARCH_MESSAGE = "Searching for book,please wait......";
private static Random RandomObject = new Random();
public static void WelcomeMessage()
{
Console.WriteLine("********************");
Console.WriteLine("* Cork *");
Console.WriteLine("* Library *");
Console.WriteLine("********************");
}
private static void MenuHeader()
{
Console.WriteLine("********************");
Console.WriteLine("* Menu *");
Console.WriteLine("* Options *");
Console.WriteLine("********************");
}
private static void MenuOptions()
{
Console.WriteLine("1.) Add Book. ");
Console.WriteLine("2.) Search for Book. ");
Console.WriteLine("3.) Delete Book. ");
Console.WriteLine("4.) Display all Book. ");
Console.WriteLine("0.) Exit. ");
}
public static void GetUserInput()
{
int choice;
MenuHeader();
do
{
MenuOptions();
Console.WriteLine(">");
choice = 0;
while (!int.TryParse(Console.ReadLine(), out choice))
{
Console.WriteLine(INPUT_ERROR_MESSAGE);
}
PickChoice(choice);
} while (choice != 0);
}
private static void PickChoice(int choice)
{
switch (choice)
{
case 1:
AddBook addBook = new AddBook();
addBook.EnterBookInfo();
break;
case 2:
Search search = new Search();
search.SearchForBook();
break;
case 3:
break;
case 4:
AddBook addBook1 = new AddBook();
addBook1.PrintListOfBooks();
break;
case 0:
Exit exit = new Exit();
exit.Exit_Application();
break;
default:
Console.WriteLine(INVALID_CHOICE);
break;
}
}
public static void MakeTheComputerSleep()
{
int number = RandomObject.Next(10) + 1;
Console.WriteLine("Searching for Book.......");
Thread.Sleep(number * 1000);
}
}
public class AddBook
{
public void EnterBookInfo()
{
while (UserInput.KeepGoing)
{
Console.WriteLine("Please enter name of book: ");
String BookName = Console.ReadLine();
if (BookName.Equals("end"))
{
break;
}
Console.WriteLine("Please enter Author Name: ");
String AuthorName = Console.ReadLine();
Console.WriteLine("Please enter ISBN Number: ");
String ISBN = Console.ReadLine();
Console.WriteLine("Please enter number of books: ");
int NumberOfCopiesInStock = Convert.ToInt32(Console.ReadLine());
Book book1 = new Book("Neverwhere", "Neil Gaimen", 1, "aaaaa");
Book book = new Book(BookName, AuthorName, NumberOfCopiesInStock, ISBN);
UserInput.bookList.Add(book);
UserInput.bookList.Add(book1);
}
}
public void PrintListOfBooks()
{
foreach (Book b in UserInput.bookList)
{
Console.WriteLine(b.ToString());
Console.WriteLine();
}
}
}
class Program
{
public static void Main(string[] args)
{
UserInput.WelcomeMessage();
UserInput.GetUserInput();
}
}
any help at all would be appreciated , thanks.
|
|
|
|
|
This would be EASILY found running the code under the debugger.
Look at the flow of your code, specifically when you call EnterBookInfo AND where you put the "hardcoded" books to get added. So, yeah, those books won't get added until you call, and wait for, user input.
You're program structure is a bit messed up. You should NOT have a class called "AddBook". That should be a method on a collection class called Books. Typically, if you have a name that starts with a verb, "Add", it should be a method in a class. Nouns should be classes, like "Book" or "Books".
"Search" should also be a method of the Books class. Both methods should NOT be prompting or handling user input.
"PrintListOfBooks" should also be a method of a Books class.
Your "UserInput" class, while OK, is a bit misplaced. You should be expanding it a bit to handle all prompting and user input for all menu options.
|
|
|
|
|
I did some messing around and I added a method called AddBooks(); with the hardcoded books and then I added method calls within the switch statment to that method and it now seems to work the way I want it too
<pre>public static Boolean KeepGoing = true;
public static List<Book> bookList = new List<Book>();
private static readonly String INPUT_ERROR_MESSAGE = "Please only enter NUMBERS!";
private static readonly String INVALID_CHOICE = "INVALID CHOICE ENTERED!";
private static readonly String SEARCH_MESSAGE = "Searching for book,please wait......";
private static Random RandomObject = new Random();
public static void WelcomeMessage()
{
Console.WriteLine("********************");
Console.WriteLine("* Cork *");
Console.WriteLine("* Library *");
Console.WriteLine("********************");
}
private static void MenuHeader()
{
Console.WriteLine("********************");
Console.WriteLine("* Menu *");
Console.WriteLine("* Options *");
Console.WriteLine("********************");
}
private static void MenuOptions()
{
Console.WriteLine("1.) Add Book. ");
Console.WriteLine("2.) Search for Book. ");
Console.WriteLine("3.) Delete Book. ");
Console.WriteLine("4.) Display all Book. ");
Console.WriteLine("0.) Exit. ");
}
public static void GetUserInput()
{
int choice;
MenuHeader();
do
{
MenuOptions();
Console.WriteLine(">");
choice = 0;
while (!int.TryParse(Console.ReadLine(), out choice))
{
Console.WriteLine(INPUT_ERROR_MESSAGE);
}
PickChoice(choice);
} while (choice != 0);
}
private static void PickChoice(int choice)
{
switch (choice)
{
case 1:
AddBook addBook = new AddBook();
addBook.EnterBookInfo();
break;
case 2:
Search search = new Search();
search.SearchForBook();
AddBook();
break;
case 3:
break;
case 4:
AddBook addBook1 = new AddBook();
AddBook();
addBook1.PrintListOfBooks();
break;
case 0:
Exit exit = new Exit();
exit.Exit_Application();
break;
default:
Console.WriteLine(INVALID_CHOICE);
break;
}
}
public static void MakeTheComputerSleep()
{
int number = RandomObject.Next(10) + 1;
Console.WriteLine("Searching for Book.......");
Thread.Sleep(number * 1000);
}
public static void AddBook()
{
Book book1 = new Book("Neverwhere", "Neil Gaimen", 1, "aaaaa");
bookList.Add(book1);
}
I don't think this is the most optimal way though?
|
|
|
|
|
It'll work. But for "optimal", you'd have to scrap your entire code and start from scratch, except for the Book class. That's about the only thing you've got going that's correct for "optimal".
|
|
|
|
|
Thanks for posting dave, I'll scrap everything and start over and try again.
|
|
|
|
|
I have a DataTable which all of its columns are in string format. But some columns have only numeric values and I want to convert them into numbers so I can do numeric calculations over them. I used this code but it gives runtime error:
int cellvalue3 = int.Parse(my_table3.Rows[i][19].ToString());
The error is on this line and says:
System.FormatException: 'Input string was not in a correct format.'
How can I fix this issue?
|
|
|
|
|
At least one row has a value in column 20 which is not numeric. You need to debug your code and examine the value that's causing the problem to see why it's not the value you're expecting.
If your column could contain a mixture of numeric and non-numeric values, and you only want to process the numeric values, use int.TryParse instead:
Int32.TryParse Method (System) | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
dont forget a comma is not numeric
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
int cellvalue3 = !string.IsNullOrEmpty(Convert.ToString(my_table3.Rows[i][19])) ? Convert.ToInt32(my_table3.Rows[i][19]) : 0;
|
|
|
|
|
That won't cope with non-empty non-numeric strings. What if the cell contains "Foo" ?
Use TryParse[^] instead.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
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!
|
|
|
|