|
What s the problem with codE ?
|
|
|
|
|
Undocumented, magic numbers, unnecessary else condition, doesn't work with all characters sets, difficult to reuse without copy'n'paste, can be bypassed with no effort to put non-numeric characters in the TextBox, trivial problem that has better solutions (including the use of standard controls), only works efficiently in app based code - it's a gawd awful solution for a web based project.
Even the TextBox name it's attached to violates C# naming conventions[^] ...
That's why I think it's poor quality code...
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Incidentally, I have need for a similar solution (except for my issue is with a .NET System.Windows.Forms textbox). I agree that he doesn't actually ask a question here so we are not sure how to help. However, since I am facing what appears to be a similar situation (from what I can tell...) I will try and interpret: he is probably saying that his editbox doesn't catch the backspace button. I have the same problem with an editbox that is for supplying a zip code. It works fine except that the backspace key is not accepted as a control key so it doesn't respond to backspace (the back/back delete key)
|
|
|
|
|
pr1mem0ver wrote: he is probably saying that his editbox doesn't catch the backspace button
if (e.KeyChar == Convert.ToChar(8)) Also, backspace and delete are not the same button, and have a different effect.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Yeah... already tried that. It doesn't work either.
|
|
|
|
|
Then you have an error in your code
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
@pr1mem0ver Using a sub-classed TextBox, and its KeyPress event, 'Delete is not registered because it is a Control Key.
However, 'Delete will do the usual in such a TextBox.
If you start a new post here and post your current code with a description of what your goal is, and what's not working, I'll respond in detail.
cheers, Bill
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
modified 9-Mar-19 8:01am.
|
|
|
|
|
If you think you're posting that for the benefit of others, that code will only work with keyboards that are rooted in a Latin character set. Your code is limited to the straight numeric values in ASCII. Try that on a Chinese or Japanese keyboard and you'll see the problem with it.
It's also not built into its own control so it can easily be reused, which itself is easy enough to do.
There are other, much better ways to do this, but I don't have the time to go into it right now.
|
|
|
|
|
Thank you for comment. This is best what I can do. If you have better solution. Please share it.
|
|
|
|
|
|
Bayram Demirci wrote: This is best what I can do. No, this is what you've done so far, and you can do better by studying the posts in this thread carefully.
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
|
namespace CustomControls
{
public enum NumModel
{
PositiveInteger,
PositiveFloat
}
public class NumberTextBox : TextBox
{
private NumModel numModel = NumModel.PositiveInteger;
public NumModel NumModel
{
get
{
return numModel;
}
set
{
numModel = value;
}
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
if ((e.KeyChar >= '0' && e.KeyChar <= '9') || (e.KeyChar == 8) || (e.KeyChar == 46))
{
if (numModel == NumModel.PositiveInteger)
{
if ((e.KeyChar == 46))
{
e.Handled = true;
}
else
{
e.Handled = false;
}
}
else
{
if ((this.Text.Contains(".") && (e.KeyChar == 46)))
{
e.Handled = true;
}
else
{
e.Handled = false;
}
}
}
else
{
e.Handled = true;
}
}
protected override void OnKeyUp(KeyEventArgs e)
{
double num;
if (this.Text != null && this.Text != "" && !double.TryParse(this.Text, out num))
{
this.Text = this.Text.Substring(0, this.Text.Length - 1);
this.Select(this.Text.Length, 0);
}
base.OnKeyUp(e);
}
}
}
|
|
|
|
|
Hi, I'd like to update an item from my collection. I used the code below but this calls the Dispose event which I'd like to avoid.
this.CurrentUser.Companies[idx] = comp;
So instead I'd like to use something like below which works and doesn't trigger the Dispose but seems inefficient with 4 calls made. Does that make sense? Can anybody please recommend a more efficient approach?
private void UpdateCompanyFields(int idx, Company comp)
{
this.CurrentUser.Companies[idx].BusinessName = comp.BusinessName;
this.CurrentUser.Companies[idx].Address.AddressOne = comp.Address.AddressOne;
this.CurrentUser.Companies[idx].Address.AddressTwo = comp.Address.AddressTwo;
this.CurrentUser.Companies[idx].Address.City = comp.Address.City;
}
|
|
|
|
|
You first line of code will not automatically "call the Dispose event" unless your Companies collection specifically does that when you overwrite an element - in which case there is probably a very, very good reason for it.
And your second code does not do the same thing at all - it overwrites parts of the class instance held by the collection which alters the instance throughout the app.
For example:
class MyClass
{
public int Value {get; set;}
public MyClass(int x) { Value = x;}
}
MyClass[] data = new MyClass[2];
MyClass x = new MyClass(333);
MyClass y = new MyClass(666);
myClass z = new MyClass(999);
myClass[0] = x;
myClass[1] = y;
myClass[0] = z;
myClass[1].Value = 111;
Changing x.Value will not affect the value in MyClass[0] and vice versa, changing the value of y will affect the value of myClass[1] and vice versa. Changing myClass[0] or z will affect both because they are the same instance.
I think you need to think a bit more carefully before you continue, and find out why the collection is calling Dispose - it implies the Company has important other info which needs to be replaced and Disposed, which your second code example does not do.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
The real inefficiency comes from the memory management in the second instance. With your original code there is an object in memory already and this line
this.CurrentUser.Companies[idx] = comp;
simply copies the memory address of "comp" to the Companies array at index idx. However this code;
this.CurrentUser.Companies[idx].BusinessName = comp.BusinessName;
Looks at the length of comp.BusinessName, reserves the same amount of memory elsewhere, copies the contents of BusinessName into that memory, then assigns that memory address to Companies[idx].BusinessName. All that memory management makes that operation slow, and you are doing it multiple times.
There is nothing wrong with the dispose event being called, it doesn't make the code inefficient. Unnecessary memory management is more likely to be a cause of inefficiency.
|
|
|
|
|
COBOL has a MOVE CORRESPONDING that accomplishes what you want.
Internally, the compiler will still generate "4 moves". Why do you think that is?
And what part is "disposable"?
And how exactly is your code "calling Dispose"?
Or, are you bluffing?
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
The Properties > Publish page of my App shows a Publish Version of 5.0.0.7.
When I use:-
Assembly assembly = Assembly.GetExecutingAssembly();
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
it always gives 1.0.0.0.
How do I access the version number from the properties page?
|
|
|
|
|
These are the methods I use:
public string AssemblyTitle
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
if (attributes.Length > 0)
{
AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
if (titleAttribute.Title != "")
{
return titleAttribute.Title;
}
}
return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
}
}
public string AssemblyVersion
{
get
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}
public string AssemblyDescription
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyDescriptionAttribute)attributes[0]).Description;
}
}
public string AssemblyProduct
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyProductAttribute)attributes[0]).Product;
}
}
public string AssemblyCopyright
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
}
}
public string AssemblyCompany
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCompanyAttribute)attributes[0]).Company;
}
}
Note that is the Executing Assembly it fetches data for - i.e. the assembly that that specific code is compiled into. If that is a DLL used by the app - i.e. a code library - it will fetch the data for the DLL, not the original EXE that called it. For the original EXE assembly data, replace GetExecutingAssembly with GetEntryAssembly
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
AssemblyVersion still returns 1.0.0.0 despite the Properties > Publish page showing 5.0.0.7. That is with GetExecutingAssembly or with GetEntryAssembly.
Am I missing something?
|
|
|
|
|
Probably, yes. From here though it's difficult to tell what.
Start by looking in the project Properties folder at the file AssemblyInfo.cs - copy and paste that so we can read it, along with the full path to the file - the version info is normally at the bottom.
Then show exactly the code you used, what it displayed, and tell us the location of the file it's in (the full path helps here as well)
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thanks, got it. I am getting the correct details from AssemblyInfo.cs.
I'll just have to update that and not rely on the automatically incremented Publish Version as on the Properties > Publish page. I'll keep looking for a way to increment the former.
|
|
|
|
|
I will develop a new application with this specification:
read only from a folder (txt, xml, csv)
read only from a given database
generate files (txt, xml)
read and write from/to another database
communicate with printing server
communicate with email server
connect to a Web Service (Migration)
I think that the best approache is DDD (or hexagonal) maybe both but I have some questions:
1- DDD vs hexagonal (I can't find the real difference)
2- parsing files like txt, csv ... must be in the infrastructure layer that's mean we must use the repository pattern but how?
3- I have only read for some data sources so why we don't use the CQRS pattern (Read model / Write model)
4- the new web service will provide us the same data as a txt file so how could test our app and hide the data sources?
5- how Anti-Corruption Layer pattern can be used for this migration (cvs,txt ---> web service)
|
|
|
|
|
For a trivial app, you're over-thinking this. Start with some "DFD's" (Data Flow Diagrams).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Basically, I agree with Gerry Schmitz that your question is a case of bringing up a lot of accidental complexity into question.
1. The goal of DDD is to model a complex domain with a lot of business rules. From your specs it doesn't sound like you have a complex business domain. It doesn't sound like you have a domain at all, what you do is just a couple of CRUDs and printing/sending emails.
2. How does something put into the infrastructure layer means that you MUST use a repository pattern? Why do you have to use repository pattern at all? There is a lot of argument that having a repository atop of ORM (if you plan to use one) is a leaky abstraction. Building repository atop of csv, txt generation? Sounds even more questionable.
3. Practicing CQRS means increasing the cost of synchronization between your read and write models? Why is it worth it? To practice DDD, which is the original motivation for CQRS?
4. Basically, you can test it with on a lot of different layers, namely e2e, integration, unit tests.
5. Anticorruption layer means that you have to protect your complex business domain during the integration with legacy service. Do you have a complex business domain worth protecting? I doubt it.
|
|
|
|