|
nlowdon wrote: statements like "this is horrble code" doesn't really help
While the statement may not have been very diplomatic, it is helpful once you push a bruised ego out of the way.
Christian did point out area where the code could be improved.
Yes, the while loop in this instance would be better served as a for(;;) loop.
The comment on "close inner if statement" isn't as useful as it might appear. A more normal practice is to repeat the condition if you are going to have a comment there so you know what that code block was doing. However, if you need to do that then you might want to think about refactoring your code. If your code blocks are so long that you can no longer see the orginal opening condition then it is an indication that the code is poorly written. Also, tools such as DevExpress's CodeRush and Refactor will decorate your IDE so it makes it very clear what bracket belongs to what if/while/using/method/class/namespace/etc.
The issue regarding the brackets around the 2 is also valid. If it was a more complex expression and you wanted to be explicit about the order of precidence then fair enough, however for a simple literal value it is overkill. If you've moved from a language that needed that then it will take a little time to get used to not needing it. It took me some time to move from some habits I picked up over the years when writing C++ code after I moved to C#.
Finally the issue over "" + i is also valid. It reminds me of when I first started programming and I wanted a negative number I would write 0 - 10 until I realised I could just write -10 .
Don't take the comments too personally, Christian is trying to help in his own way.
|
|
|
|
|
Hi There,
Thanks for the reply, a little 'diplomacy' goes a long way.
In my original posting there was actually 2 instances of a similar loop - the 2nd being a 'for' loop.
Unfortunately that doesn't work either
The extensive commenting of code mearly helps me at the moment as i am very new to this (as the simple coding may suggest - lol)
Anyway - tried lots now and still no joy - the execution of the method is called by a timer which i've slowed right down also - no joy.
Thanks again for the post - nice to see a fellow 'Jock' ??
|
|
|
|
|
MessageBox.Show(tempnum.ToString());
}
//second loop
..
..
Remove the '}'
|
|
|
|
|
}
cat.Location = newLoc;
MessageBox.Show("" + i);
Should be ("" + i.ToString());
|
|
|
|
|
Maybe there are some exception? just check it!
|
|
|
|
|
Thanks for all your help. have another question.
I have a database name star. My star database have 4 tables contact, units invoices and payments
in my contact table I have columns contact id, Fname, LName, Address, City, State, zip, email.
in the invoice table I have columns invoice id, contact id, startdate, enddate, subtotal, total,
I wrote a little app from the help from here to migrate my data because SSIS 2005 was having problems with null value data in the contact table import perfectly and invoice imports as well.
But my contact id in the Contact table is not matching the contact id in the invoice table it blank.
I need help to make them match and also make sure that when I open the app that using the star database show the contact information for that contactid and when I open the form for the invoice
the contact information matches to. The app with an empty data base because I create new accounts trying to migrate old data so the software use it. This way I don't have to manual imput every record.
if I can get the a sample of some code in c#
Learning to Code
|
|
|
|
|
If the referential integrity is lost in the migration process, I don't think there's any way to restore the correct foreign keys afterwards (unless you have other logic in the data that can combine correct invoice and contact).
Based on your description, it seems that the referential integrity is not enforced in your database and this lead to these problems. What I suggest is that you repeat the migration, but this time before migrating the data, put constraints to enforce the integrity.
I take it, that you use identity columns in the new database. If this is the case, your migration logic should be something like:
while (ReadOriginalContact) {
InsertContactToNewDatabase
GetTheNewIdentityForContact
while (ReadOriginalInvoiceForThisContact)
InsertInvoiceToNewDatabaseWithNewContactId)
}
}
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
The help i need with the WebBrowser is making a link (when clicked on) opens in a new tab in my browser. any ideas on how to get that to work?
here is what I have so far.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
System.Collections.ArrayList tabpages = new System.Collections.ArrayList();
System.Collections.ArrayList webpages = new System.Collections.ArrayList();
int current_tab_count = 0;
public Form1()
{
InitializeComponent();
tabControl1.TabPages.Clear();
Create_a_new_tab();
WebBrowser webpage = GetCurrentWebBrowser();
webpage.GoHome();
}
private void toolStripButton5_Click(object sender, EventArgs e)
{
WebBrowser thiswebpage = GetCurrentWebBrowser();
thiswebpage.GoHome();
timer1.Enabled = true;
}
private void button_back_Click(object sender, EventArgs e)
{
WebBrowser thiswebpage = GetCurrentWebBrowser();
if (thiswebpage.CanGoBack)
thiswebpage.GoBack();
}
private void toolStripButton4_Click(object sender, EventArgs e)
{
WebBrowser thiswebpage = GetCurrentWebBrowser();
thiswebpage.Refresh();
timer1.Enabled = true;
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
WebBrowser thiswebpage = GetCurrentWebBrowser();
if (thiswebpage.CanGoForward)
thiswebpage.GoForward();
}
private void toolStripButton3_Click(object sender, EventArgs e)
{
WebBrowser thiswebpage = GetCurrentWebBrowser();
thiswebpage.Stop();
}
private void toolStripButton6_Click(object sender, EventArgs e)
{
string url = toolStripComboBox1.Text;
if (url == "") return;
WebBrowser thiswebpage = GetCurrentWebBrowser();
thiswebpage.Navigate(url);
timer1.Enabled = true;
}
private void toolStripComboBox1_KeyPress(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter) toolStripButton6.PerformClick();
}
private void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
toolStripButton6.PerformClick();
}
private void Create_a_new_tab()
{
if (current_tab_count == 10) return;
TabPage newpage = new TabPage("Loading...");
tabpages.Add(newpage);
tabControl1.TabPages.Add(newpage);
current_tab_count++;
WebBrowser webpage = new WebBrowser();
webpages.Add(webpage);
webpage.Parent = newpage;
webpage.Dock = DockStyle.Fill;
webpage.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webpage_DocumentCompleted);
timer1.Enabled = true;
tabControl1.SelectedTab = newpage;
}
private WebBrowser GetCurrentWebBrowser()
{
TabPage current_tab = tabControl1.SelectedTab;
WebBrowser thiswebpage = (WebBrowser)webpages[tabpages.IndexOf(current_tab)];
return thiswebpage;
}
private void UpdateAllNames()
{
foreach (TabPage tb in tabControl1.TabPages)
{
UpdateName(tb);
}
}
void webpage_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
UpdateAllNames();
UpdateBackForwardButtons();
timer1.Enabled = false;
}
private void UpdateBackForwardButtons()
{
WebBrowser thiswebpage = GetCurrentWebBrowser();
if (thiswebpage.CanGoBack) button_back.Enabled = true;
else button_back.Enabled = false;
if (thiswebpage.CanGoForward) toolStripButton2.Enabled = true;
else toolStripButton2.Enabled = false;
if (current_tab_count > 1) closeCurrentTabToolStripMenuItem.Enabled = true;
else closeCurrentTabToolStripMenuItem.Enabled = false;
}
private void tabControl1_Selected(object sender, TabControlEventArgs e)
{
UpdateBackForwardButtons();
}
private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
private void closeCurrentTabToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void UpdateName(TabPage tb)
{
TabPage current_tab = tb;
WebBrowser thiswebpage = (WebBrowser)webpages[tabpages.IndexOf(current_tab)];
if (thiswebpage.Document != null)
current_tab.Text = thiswebpage.Document.Title;
else
current_tab.Text = "Zzz";
}
private void newTabToolStripMenuItem_Click(object sender, EventArgs e)
{
Create_a_new_tab();
WebBrowser thiswebpage = GetCurrentWebBrowser();
if (toolStripComboBox1.Text == "")
thiswebpage.GoHome();
else
thiswebpage.Navigate(toolStripComboBox1.Text);
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
}
private void tabPage2_Click(object sender, EventArgs e)
{
}
}
}
|
|
|
|
|
Do you have any problem with your code?
Life is 5: 3 me, 1 you.
|
|
|
|
|
Nope there is no errors in the code. The help I need is when I test the browser and click on a link that suppose to open in a new tab, actually opens in Mozilla Firefox instead. Still need Help with this I think I have the correct code in there but its not doing what it suppose to do. Any suggestions will do.
lekira
|
|
|
|
|
Really opened in FireFox?!! Too odd! I read your code, seems everything's fine. However this code worked fine for me in creating new WebBrowser in a new TabPage:
TabPage tp = new TabPage();
WebBrowser wb = new WebBrowser();
wb.Dock = DockStyle.Fill;
wb.GoHome();
tp.Controls.Add(wb);
tabControl1.TabPages.Add(tp);
Hope can help you...
Life is 5: 3 me, 1 you.
|
|
|
|
|
still don't work..
leKira is my Username here but I'm World Wide know as Naiakoa Call me by any of these.
modified on Thursday, November 20, 2008 9:11 PM
|
|
|
|
|
Say I have three classes, each a child of the previous. Can I explicitly call each of a classes methods that have been overridden?
class A
{
public A() { }
protected virtual void MakeLunch()
{
}
}
.
class B : A
{
public B() { }
protected override void MakeLunch()
{
base.MakeLunch();
}
}
.
class C : B
{
public C() { }
protected override void MakeLunch()
{
A.MakeLunch();
}
}
From class C, can I skip the banana and just get a cheese sandwich and a drink? Or do I need one of my five-a-day?
My current favourite word is: Nipple!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
I wouldn't imagine you could since B overrides A C should not "know" about A. However, if B used new on MakeLunch instead then it would be possible by casting C as A.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
I don't want to do that, it would cause more complications than it would solve. Thanks anyway.
My current favourite word is: Nipple!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
I figured which is why I initially hesitated in responding. However, I think the reasoning is why such an action is prevented by the compiler.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: However, if B used new on MakeLunch instead then it would be possible by casting C as A.
But that won't work too since the MakeLunch is marked as protected . Please correct me if I am wrong.
|
|
|
|
|
I haven't tried it but it might, since C would still be in the inheritance chain for A
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
It does not work in C# , but it is possible at IL level.
So I guess its simply a rule that prevents you to skip layers of abstraction in C#.
|
|
|
|
|
I have an existing application which requires the addition of a multi-function display area.
Currently I'm using a SplitterControl, which can give me the choice of two different UI displays within the same parent area.
This works fine and dandy. But now we need another two formats within the same area. I could use yet another SplitterControl and just collapse the unused panels when they are not required.
But I wonder what other ways can you guys suggest please?
|
|
|
|
|
|
Hello all
i have a web application that runs on the internal network, i want to access it through a desktop application, i want to fill in data in text fields and simulate button clicks, and even i want to access the "view source command" through my desktop application, i had search the internet and found that may i use BHO for IE, but i couldn't able to find a simple example that fit my needs,
please help.
|
|
|
|
|
Live connect with Java and Javascript would work but most likely you would need to setup polling with Ajax.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
i dont understand that using a desktop application
|
|
|
|
|
hello
is there a simple way to read cells data from excel file in my projects directory
into an array or matrix in c# ?
|
|
|
|