|
You should be using radio buttons, not checkboxes; your options are mutually exclusive. Which also implies fewer fields. You have architectural issues.
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
|
|
|
|
|
The user may need to filter West and East parts, for example. Thus, I have to provide toggle checkboxes.
|
|
|
|
|
In that case, use checkboxes.
So far, it would seem easier to create a new datatable by "filtering" the original; instead of compacting the original.
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 all, I use a partial view in my net core MVC Web project ( personal project not work ) which receives a Model ViewButtonText
public class ViewButtonText
{
public string ButtonText { get; set; }
}
and the partial view is
@model Commands.Models.ViewButtonText
<input type="submit" name="submit" value=@Model.ButtonText>
<input type="submit" name="submit" value="Cancel" />
All works as expected until I set ButtonText to a value which has a space in it e.g. "My Button" which results in the text on the button only showing the first word - any idea why guys ?
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|
|
@model Commands.Models.ViewButtonText
<input type="submit" name="submit" value="@Model.ButtonText">
<input type="submit" name="submit" value="Cancel" />
"Time flies like an arrow. Fruit flies like a banana."
|
|
|
|
|
Thanks Matthew
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|
|
Hi,
Could you help with all possible ways of autoconnection of shapes dropped in WPS canvas?
We are assuming that:
1. Shapes have connectors/adorners
2. Shapes have in same layer
3. Second shape dragged from shapes library and brought close to first shape.
4. Next - happens autonnection of close to each other connectors.
The visual (only) reference can be seen (from 8m11sec) GERU Tutorial: Logic Flow & Email Messages - YouTube[^]
The main problem of using the option of constant comparison/calculation of connectors' distance will be done during the move of shapes.
And it will load the CPU as technically each/any movement of any shape (there can be dozen) in canvas will be calculated then heavily loading the CPU=slowing down the app...
Are there different ways or tips/tricks of doing it?
Ideally some sample of code if feasible?
Thanks a lot!
modified 31-Mar-21 13:35pm.
|
|
|
|
|
Visio doesn't "auto connect" ... they would have figured it out if it was wanted / practical.
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
|
|
|
|
|
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
|
|
|
|