
Cags
Avatar/Signature-
Posts
699 -
Joined
-
Last visited
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by Cags
-
Dates in C# 2005 Express - Conversion, Validation and Comparison
Cags replied to jcrcarmo's topic in Visual C# .NET
Using the method marble_eater suggests you don't need an IsDate function at all you would just do the following... bool bValid; DateTime myDate; string sDate; bValid = DateTime.TryParse(sDate, out myDate); if(bValid) { MessageBox.Show("Valid"); // any other code... } else { MessageBox.Show("InValid"); // any other code... } On a side note, I believe this is a 2.0 feature only as my VisualStudio does not support the TryParse() method and as far as I know there isn't a better way of doing it in 1.1 than the one I suggest. I realise the exception would be 'expensive' but am un-aware of any way round the problem. -
To get the debugger to display information you need to set a breakpoint. Todo this click in the gray bar to the left hand side of the code level with a line that contains the variable returndata, then when the application reaches that line it will stop and if you point at the variable it will tell you its value. Alternatively if you didn't understand that output a Messagebox with returndata just before the If statement and see what it contains.
-
It seems odd to me that you showed where the string pass comes from but then don't use it, and yet you don't show where the string returndata comes from which is whats supposedly causing your problem. I can see no reason this code would always show "Correct ID". On a side note you should perhaps consider using String.Empty instead of "".
-
-
One method for doing this is something along the lines of... public bool IsDate(object inValue) { bool bValid; try { DateTime myDT = DateTime.Parse(inValue); bValid = true; } catch (FormatException e) { bValid = false; } return bValid; } That throws an error because the overload requires a type and your passing it an object. You could change the DateTime to typeof(DateTime), don't know if that would help though I haven't tried it.
-
The obvious solution is to have a CanEdit property for every property in the Customer class. I'm guessing that you already thought of that though, and discounted it as it hardly lends itself to making an extensible framework. How about having CanEdit as an arraylist of strings in the user classes. Then wherever you are displaying the information, for each property you check the user class for CanEdit.Contains("Name") if it does you enable edit else you don't. Heres the code... public interface User { ArrayList CanEdit { get; } } public class User1 : User { private ArrayList arrCanEdit; public ArrayList CanEdit { get { return arrCanEdit; } } public User1() { string[] sCanEdit = new string[] { "Name" }; arrCanEdit = new ArrayList(); arrCanEdit.AddRange(sCanEdit); } } public class User2 : User { private ArrayList arrCanEdit; public ArrayList CanEdit { get { return arrCanEdit; } } public User2() { string[] sCanEdit = new string[] { "Region" }; arrCanEdit = new ArrayList(); arrCanEdit.AddRange(sCanEdit); } } public class Customer { private string sName = "Peter"; private string sTerm = "Summer"; private string sRegion = "Here and there"; public string Name { get { return sName; } set { sName = value; } } public string Term { get { return sTerm; } set { sTerm = value; } } public string Region { get { return sRegion; } set { sRegion = value; } } public Customer() { } } and then on the form something like this... private void Form1_Load(object sender, System.EventArgs e) { myUser = new User1(); Customer myCustomer = new Customer(); textBox1.Text = myCustomer.Name; textBox2.Text = myCustomer.Term; textBox3.Text = myCustomer.Region; if(myUser.CanEdit.Contains("Name")) textBox1.ReadOnly = false; else textBox1.ReadOnly = true; if(myUser.CanEdit.Contains("Term")) textBox2.ReadOnly = false; else textBox2.ReadOnly = true; if(myUser.CanEdit.Contains("Region")) textBox3.ReadOnly = false; else textBox3.ReadOnly = true; } Perhaps not the most elegant solution, but it should work and could be extended to include more properties with relative ease.
-
Its strange how the '"' actually has 2 escape characters, the example I gave also works.
-
MDIParent controlling MDIChild richTextBox control
Cags replied to jcrcarmo's topic in Windows Forms
If you declare the richtextbox as public you can access its properties from the mdi parent, however thats perhaps not the best method. You could create a public method called LoadText as part of the mdi child, you can then call the method from the mdi parent, which will then load the text into the richtextbox. -
I'm slightly confused about your question. Are the Customer objects members of the user groups, or are the user groups a seperate entity that can view / alter the Customer objects. If the later is true then alot depends on how the data is being displayed to the viewer in the first place. Perhaps a bit more information and I could help more.
-
As odd as it looks you can use this... str1 = str2.Replace(@"""", "");
-
Database Backup Routine - From VB2005 to C# 2005
Cags replied to jcrcarmo's topic in Directory / File IO / Registry
I could be wrong, but I think what PlausiblyDamp meant was... System.IO.File.Copy(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "myDB.mdb"), SavePath + FileName, true); but I see no reason this can't be shortend to System.IO.File.Copy(System.IO.Path.Combine(Application.StartupPath, "myDB.mdb"), SavePath + FileName, true); Also its worth noting that my VisualStudio doesn't recognise the following, perhaps its not part of the 1.1 framework? Environment.SpecialFolder.MyDocuments -
You would use that code like this, but I'm not sure it's the best way to achieve what you want.... Dim rectOne As Rectangle = New Rectangle(0, 0, 100, 100) Dim rectTwo As Rectangle = New Rectangle(100, 100, 100, 100) If rectOne.IntersectsWith(New Rectangle(rectOne.Left, rectOne.Top, 1, rectOne.Height)) Then ' Left side ElseIf rectOne.IntersectsWith(New Rectangle(rectOne.Left, rectOne.Bottom - 1, rectOne.Width, 1)) Then ' Bottom side ElseIf rectOne.IntersectsWith(New Rectangle(rectOne.Right - 1, rectOne.Top, 1, rectOne.Height)) Then ' Right side ElseIf rectOne.IntersectsWith(New Rectangle(rectOne.Left, rectOne.Top, rectOne.Width, 1)) Then ' Top side End If rectOne & rectTwo would be the bounds of your two picture boxes.
-
You may not be able to check for a crashed process but you can test for a running process, if the process is no longer running, you start it again. I guess thats assuming that the crashes exit the process which is not neccessarily the case though. You may also wish to try some networking style code, sending a ping / pong event to each other every few minutes as in IRC. Not sure how well that would work on a single pc but it should be possible.
-
Locking all controls on a form - From VB2005 to C# 2005
Cags replied to jcrcarmo's topic in Windows Forms
private void LockForm() { foreach(Control ctrlTemp in this.Controls) { if(ctrlTemp is TextBox) { TextBox txtTemp = (TextBox)ctrlTemp; txtTemp.ReadOnly = true; txtTemp.BackColor = Color.White; } /*// handle other types else if(ctrlTemp is CheckBox) { CheckBox chkTemp = (CheckBox)ctrlTemp; // etc... } */ } } -
Your right it certainly wouldn't be simple to get a decent 3d tile based system working, but its not as uncommon as you might think. An example of a (reasonably) modern game that uses one is Neverwinter Nights. I realise this might not directly help the poster but maybe if you look into the map creation tool of a game that uses a 3d tile system you will get some inspiration.
-
I would concur with marble_eater on this one, I thought that was part of the problem that rossyboy was trying to fix. I guess that rossyboy is the only one that knows either way for certain. But either way comments like... aren't really necessary. As for marble_eaters reply I think you may have overloaded my sarcasm parser with that one. ;)
-
Say I have the following... ArrayList arr1 = new ArrayList(); ArrayList arr2 = new ArrayList(); ArrayList arr3 = new ArrayList(); arr1.AddRange(new int[] { 1,2,3,4,5,6,7,8,9 }); arr2.AddRange(new int[] { 2, 5, 7 }); I need to populate arr3 with values that are in both arr1 and arr2. I'm currently doing it with the following, does anyone know of a better way of achieving this? for(int i = 0; i < arr1.Count; i++) if(arr2.Contains(arr1[i])) arr3.Add(arr1[i]); Just to clarify arr3 should now contain 2, 5 and 7. As I've been typing this post I've realised that in this example arr1 is larger than arr2 so it would perhaps be prudent to loop through the smaller arr2 so I might add an if statement if nobody else can think of a better solution.
-
I don't know if you just didn't try it or I'm being stupid, but PlausiblyDamp's code clearly defines the add variable as an Integer and using his exact code does not order the list correctly on my machine. Perhaps people are using either different version of the .Net Framework or Visual Studio .Net.
-
True enough, I was replying to SimDucks questions however and was merely clarifying the point incase they tried your suggestion.
-
My answer was assuming by 'initial file' you meant the executable, which if I'm not mistaken could not be deleted with the method DiverDan describes.
-
Just out of interest I took a look at the old project and commented code out abit at a time to find out what was causing the error. I eventually tracked it down to a single line in the resize event of the form. I was setting myForm.ClientSize = myControl.Size this obviously caused a problem because when the constructor is ran myControl is null. It was basically an oversight, as the resize event should have been attached to the control not the form (hence making the form the right size to fit my control in). Copying my class to another project solved the problem as I was being less retarded at the time and actually attached the event to the right object.
-
It works, but it doesn't add the items in the correct numerical order. For example if you add 1 then 2 then 10 it will order them 1 10 2 rather than 1 2 10
-
I would have posted the code but I didn't know what to write as it was essentially a standard form with a single class added. I copied the class to another project along with the declaration and it works fine now. I still have no idea what caused the error which isn't ideal, but I'm not going to worrry about it unless it happens again.
-
I believe you'll have to launch a seperate thread, then close the initial file which will give you access to delete it.
-
This is just an idea as I've never really done asp, but have you tried screen.width + "px"