JerryShaw 46 Posting Pro in Training

Just for clarity's sake, a private const is an instruction to the compiler to effect its use within the local class, and a public constant can be used outside of the class it is assigned by referencing the class name it is contained within (observing class scope). The compiler does not use an object assigned the const attribute like it does with a commonly defined variable.
A constant is however not a "static" object by the strict use of that definition within OOP. It is a more like a compiler directive than a variable. The compiler reads all the constant declarations for a project, then it performs a: Replace all references of this key word to this value within the source code.

Sorry for continuing such an out dated posting

JerryShaw 46 Posting Pro in Training

Try not using an SqlDataReader.... instead use a simple adapter and table. Most likely the original problem is that you did not set the SqlCommand CommandType property. No reason for the IF statement because the SQL will only return a row if it meets the criteria. Anyway, study the revised code, and ask questions for anything you do not understand.

-- Jerry

        private void LoGoBt_Click(object sender, EventArgs e)
        {
            if (LoUNameTxt.TextLength <= 0)
            {
                MessageBox.Show("Enter User Name");
                LoUNameTxt.Focus();
            }
            else if (LoPassTxt.TextLength <= 6)
            {
                MessageBox.Show("Enter Password greater than 6 char");
                LoPassTxt.Focus();
            }
            else if (LoAccTxt.TextLength < 8)
            {
                MessageBox.Show("enter Account Number 0f 11 character");
                LoAccTxt.Focus();
            }
            else if (LoMobTxt.TextLength < 10)
            {
                MessageBox.Show("enter 10 digit.");
                LoMobTxt.Focus();
            }
            else if (LoEmailTxt.TextLength <= 0)
            {
                MessageBox.Show("enter Email ID");
                LoEmailTxt.Focus();
            }
            else
            {
                DataTable table = new DataTable();
                SqlDataAdapter adapter = new SqlDataAdapter(
                        string.Format("SELECT TOP 1 * FROM olb_login WHERE log_username='{0}' AND log_password='{1}'", LoUNameTxt.Text, LoPassTxt.Text)
                        , @"Data Source=TRIMBAKKAR\SQLEXPRESS;Initial Catalog=OLB_DB;Integrated Security=True");
                try
                {
                    adapter.Fill(table);
                    if (table.Rows.Count > 0)
                    {
                        MessageBox.Show("login success");
                        MDI Form2 = new MDI();
                        Form2.Show();
                        Form2.MDIStartBt.Enabled = false;
                        Form2.MDIBackBt.Enabled = false;
                        Form2.MDIBalanceBt.Enabled = true;
                        Form2.MDIMoneyBt.Enabled = true;
                        Form2.MDILogutBt.Enabled = true;
                        this.Hide();
                    }
                    else
                    {
                        MessageBox.Show("access denied");
                    }

                }
                catch (SqlException sqlError)
                {
                    MessageBox.Show(sqlError.Message, "Error " + sqlError.Number.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    table.Dispose();
                    adapter.Dispose();
                }

                /* Old Way
                SqlConnection sqlcon = new SqlConnection(@"Data Source=TRIMBAKKAR\SQLEXPRESS;Initial Catalog=OLB_DB;Integrated Security=True");
                sqlcon.Open();
                MessageBox.Show("connection open");
                SqlCommand cmd = new SqlCommand("SELECT log_username, log_password FROM olb_login WHERE log_username='" + LoUNameTxt.Text + "' AND log_password='" + LoPassTxt.Text + …
JerryShaw 46 Posting Pro in Training

I have uploaded the code in the attachment

JerryShaw 46 Posting Pro in Training

bhagyap
Are you wanting to store the data to a file so that when the application starts it performs the checks and listbox actions? or just retain what the user did in this session for redisplay when the form is reloaded?
Really does not make much difference if you create a simple structure with two elements. The StringValue and the CheckValue. Then pass that in a collection to the form when it opens and it can iterate though to perform the checks and listbox load.
Now if it were me and I wanted to reload those values anytime the application started, I would create a simple data table with two columns (StrValue,CheckValue), populate it with the defaults if it did not exist. If it does exist, then load it from disk (built in function of a datatable). Pass this table to the form. Anytime the form works with this datatable, it will make sure it is updated, then when the application closes, just write the datatable to disk as XML (built in function of a datatable).
Are you looking for code to do this.. or can you figure it out on your own?

JerryShaw 46 Posting Pro in Training

Hmmmm, you must not have read the last line of my earlier reply...

The code snippet below uses what we call a recursive method.
In this example, there is a button click event just to fire up the process of searching for the menu item with text of "Default". It does this by calling a method I have named SearchForMenuByName.
Recursive methods usually start off with a main loop that will call another method that is the actual recursive method. SearchForMenuByName is that main loop method. For each of the main menu items at the top level, it will call a method named SearchSubItems. SearchSubItems is the recursive method that will call itself to drill down through menu levels.

private void button1_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem item = SearchForMenuByName("Default");
            if (item != null)
                item.Checked = true;
        }

        private ToolStripMenuItem SearchForMenuByName(string value)
        {
            ToolStripMenuItem result = null;
            foreach (ToolStripMenuItem item in contextMenuStrip1.Items)
            {
                result = SearchSubItems(item,value);
                if (result != null)
                    break;
            }
            return result;
        }

        private ToolStripMenuItem SearchSubItems(ToolStripMenuItem menu,string searchFor)
        {
            ToolStripMenuItem result = null;
            if (menu.Text.Equals(searchFor))
                return menu;
            else if (menu.HasDropDownItems)
            {
                foreach (ToolStripMenuItem subItem in menu.DropDownItems)
                {
                    result = SearchSubItems(subItem, searchFor);
                    if (result != null)
                        break;
                }
            }
            return result;
        }
JerryShaw 46 Posting Pro in Training

If your context menu is a single level menu then use this:

foreach (ToolStripMenuItem item in contextMenuStrip1.Items)
            {
                if (item.Text.Equals("Default"))
                    item.Checked = true;
            }

If not, then build a recursive method that can dive into each of the item's items collection. If you don't know how to do that, then reply with a request for help, but please try to do it on your own before asking.

JerryShaw 46 Posting Pro in Training

My appologies Mr. CodeReflex
So first, why did you respond to a post that is 3.5 years old? Don't you know that when you do that, everyone that has participated in that thread gets an email ?

Since you are a professional developer, and felt you should navigate the DaniWeb user to your site for the answer to this thread... why didn't you provide a quality code sample with comments to explain to the new or student developer what the code is doing, and why, and better yet, the construction of the SQL ConnectionString.

Sorry, but as a professional developer myself, I did not see any value in your post or your website sample code.

JerryShaw 46 Posting Pro in Training

codereflex is a website BOT that is spamming all developer sites trying to drive traffic to their site.
The example this one points to is very lame.
Just use the System.Data.SqlClient.SqlConnectionBuilder class to generate your connection string. The rest is trivial.

JerryShaw 46 Posting Pro in Training

If the other machine has a directory marked as shared you can just use the System.IO name space and the File.Move or File.Copy methods. Then use the fully qualified directory path

System.IO.File.Copy( "C:\\MyFile.txt", @"\\machine\sharepath\MyFile.txt");
JerryShaw 46 Posting Pro in Training

Seffix, Good question. Local class variables starting with an underscore and all lower case is a coding standard. You will see many Microsoft code examples using this standard.

This standard makes it easy for others to see code snippets and understand that "these" variables are class scoped variables.

Most of the people I work with used to work at Microsoft, so it was natural for our company has adopted their standards.

// Jerry

JerryShaw 46 Posting Pro in Training

There are a number of issues with your snippet, but its just a snipet, so I won't go into that....
Here is a snippet I wrote for you, starting with your own code.

using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DW_Rect1
{
    public partial class Form1 : Form
    {
        private bool _start = false;
        private Rectangle _rect = new Rectangle(10, 10, 0, 0);

        public Form1()
        {
            InitializeComponent();
        }

        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                _start = true;
                _rect.X = e.Location.X;
                _rect.Y = e.Location.Y;
                _rect.Width = 0;
                _rect.Height = 0;
            }
            else
                _start = false;
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (_start && e.Button == MouseButtons.Left)                    
            {
                _rect.Width = e.X - _rect.X;
                _rect.Height = e.Y - _rect.Y;
                pictureBox1.Invalidate();    
            }
        }

        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawRectangle(Pens.Red, _rect);
        }

    }
}

Review the changes, and ask questions about why I did this or that.
// Jerry

JerryShaw 46 Posting Pro in Training

Are you drawing the rectangle inside of the Paint event of the picture box ?
Need to, and sending the picturebox to the background has no effect because you are drawing on top of the object no matter where it is in the Z order.

JerryShaw 46 Posting Pro in Training

This is another version of updating Label`s text over the thread:

delegate void LabelDelegate(string message);
        public Form1()
        {
            InitializeComponent();         
        }

        private void UpdatingLabel(string msg)
        {
            if (this.label1.InvokeRequired)
                this.label1.Invoke(new LabelDelegate(UpdatingLabel), new object[] { msg });
            else
                this.label1.Text = msg;
        }

Its faster and easier...

Mitja, inline delegate assignment is not any faster in execution. As for easier, only saves the typing of a delegate type and a variable name. As for maintenance and readability, I prefer the longer form especially is using non standard EventArg handlers.
JMO

JerryShaw 46 Posting Pro in Training

Man this is a really old thread...
Easiest way to do this is with the SqlConnectionStringBuilder class.
Just create an instance of that class, provide values for DataSource (aka the server), InitialCatalog (the name of the database), IntegratedSecurity (aka Windows authentication=True, or false meaning you need to supply a username and password,
and finally if not using Windows authentication, set the UserID and Password values.
Now, once you set those values, you can use its ConnectionString property for your SqlConnection instance.
That little helper class takes all the guess work out of it.
Have Fun,
Jerry

JerryShaw 46 Posting Pro in Training

When you try to open the connection, SQL will throw an error if the credentials are not correct. A nice little component to use in building the connection string is SqlConnectionStringBuilder. Here is the code you are looking for using that component.

using System.Data;
            using System.Data.SqlClient;

            SqlConnectionStringBuilder scsb = new SqlConnectionStringBuilder();
            scsb.DataSource = "YourServerName";
            scsb.InitialCatalog = "YourDatabaseName";
            scsb.IntegratedSecurity = false; // set to true is using Windows Authentication
            scsb.UserID = "YourUserName";
            scsb.Password = "YourPassword";
            SqlConnection conn = new SqlConnection(scsb.ConnectionString);
            try
            {
                conn.Open();
                MessageBox.Show("Connection Successful", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (SqlException loginError)
            {
                MessageBox.Show(loginError.Message, "Failed to connect", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            finally
            {
                conn.Dispose();
            }
JerryShaw 46 Posting Pro in Training

You will be wrapping the code that creates the database anyway, so just supply good error messaging and go with the assumption. IOW, why add additional code when SQL is going to do those checks for you anyway regardless of your pre-checks.
JMO

JerryShaw 46 Posting Pro in Training

Sure, you can do it without using List<>, just use an array of MealContent. You can even do it without MealContent. There is enough info within the example for you to figure it out.

JerryShaw 46 Posting Pro in Training

Something like this: Using a class to handle the information. You can then do all kinds of things inside that class such as add a method to apply your Cost = 1.8 * Price

class Program
    {
        static void Main(string[] args)
        {
            string[] meals = System.IO.File.ReadAllLines("meals.csv");
            List<MealContent> menu = new List<MealContent>();
            List<string> mealTimes = new List<string>();
            foreach(string meal in meals)
            {
                if( !string.IsNullOrEmpty(meal) )
                    menu.Add(new MealContent(meal));
            }

            foreach (MealContent content in menu)
                if (mealTimes.IndexOf(content.MealTime) == -1)
                    mealTimes.Add(content.MealTime);

            mealTimes.Sort();
            foreach(string str in mealTimes)
            {
                Console.WriteLine("* " + str + " *");
                foreach (MealContent content in menu)
                    if (content.MealTime.Equals(str))
                        Console.WriteLine(string.Format("${0} {1}, {2}", content.Price, content.Entre, content.UnitOfIssue));
                Console.WriteLine();
            }

            Console.ReadKey();
        }

        class MealContent
        {
            public string MealTime;
            public string Entre;
            public string UnitOfIssue;
            public double Price = 0.0d;
            public MealContent(string csvData)
            {
                string[] parts = csvData.Split(',');
                MealTime = parts[0];
                Entre = parts[1];
                UnitOfIssue = parts[2];
                parts[3] = parts[3].Replace('$', ' ').Trim();
                Price = double.Parse(parts[3]);
            }
        }
    }
JerryShaw 46 Posting Pro in Training

Ah that gets more interesting. Let me try something

JerryShaw 46 Posting Pro in Training

Why so much code?
Try this to get started

static void Main(string[] args)
        {
            string[] meals = System.IO.File.ReadAllLines("meals.csv");
            foreach (string meal in meals)
                Console.WriteLine(meal);
            Console.ReadKey();
        }
JerryShaw 46 Posting Pro in Training

Sorry for any confusion. Somehow, DaniWeb spawned this new thread from another thread that is real old. I was answering a post that was sent to me today, but DaniWeb also moved that request off to somewhere else, and posted my reply here.
Anyway, you can ignore this thread

JerryShaw 46 Posting Pro in Training

Be aware, that calling IsDisposed on an object that has not been initialized (IOW is null) will throw an Exception.
Also, IsDisposed is not set until Disposing is done. That is why it is a good idea to check the object for null before using or initializing it, then when done using it Dispose() of it (which marks it for garbage collection), then set the instance to null which just releases the local variable for reuse, the GC will still remove the memory footprint of the original instance address.

JerryShaw 46 Posting Pro in Training

***what is MyGrid referring to in this code ^^^ ???***
Answer: A DataGridView

***hi ... how to create the stored procedure?, and how to call the stored procedure in c# ?.... ***
Answer: Creating a stored procedure is done at the SQL Server using the tools provided by the database vendor. DaniWeb has a forum for SQL for this question, or any one of the public tutorials and MSDN tutorials on how to create a stored procedure.
Calling a stored procedure is done by its name. See the example near the top of this thread. The SqlCommand instance contains the name of the stored procedure to be executed. It is also set to be CommandType.StoredProcedure. You can pass parameters to it by adding to the Parameters collection as shown in the example above. There are other ways to add parameters, that is just the shortest syntax.
Hope this answered your questions, or put you on the path to meet your goal,
Cheers,
Jerry

JerryShaw 46 Posting Pro in Training

I not sure how you can do it from within your user control, but you can experiment around using the tabcontrol's selecting event handler. Have the save button set the _saved var.

public partial class Form1 : Form
    {
        private bool _saved = false;
        public Form1()
        {
            InitializeComponent();
        }

        private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
        {
            if ( !string.IsNullOrEmpty(textBox1.Text) && !_saved && !e.TabPage.Equals(textBox1.Parent))
            {
                if (MessageBox.Show("You have not saved\r\nDo you really want to leave me?"
                    , "Not Saved"
                    , MessageBoxButtons.YesNo
                    , MessageBoxIcon.Question) == DialogResult.No)
                {
                    e.Cancel = true;
                    textBox1.Focus();
                }
            }
        }
    }

Hi
I have a user control which has 1 textbox and a Save button.If a user type some text in the textbox and forgets to save and moves to another tab,I want to show a dialog result.If the user selects yes then the user will move to another tab.But if the user selects no I want the user to stay in this form.How can I do it?
thnx in advance

JerryShaw 46 Posting Pro in Training

You may have stumbled upon a known bug within the grid's internal binding logic. But, before I say that for sure, maybe you should post some code that shows your symptom, and we will see.

I assume you have a binding source for the grid ?

JerryShaw 46 Posting Pro in Training

im sorry but just to ask whether how to go about it?
sorry im still very new to C#

That's okay, lots of the members here are new to C#.

If you want some coding example, you can type this into Google, and you will see many ways to get a custom button to do what you want. Click on the link below:

c# custom button shape

JerryShaw 46 Posting Pro in Training

i need to read contents of a file(of any format) into a char array, how can i do this

FileInfo fz = new FileInfo(tempFile);
FileStream fzs = fz.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
byte[] data = new byte[fz.Length];
fzs.Position = 0;
fzs.Read(data, 0, Convert.ToInt32(fz.Length));
string strData = Encoding.UTF8.GetString(data);
char[] ch = strData.ToCharArray();

Remember to dispose, and try..catch, all that stuff.
Basically you stream the file, read the stream into a byte array, then encode the byte array into a string where you can turn it into a char array. You may need to try differenent encoding depending on culture settings, etc.

Jerry


Just thought of a one liner that also does this: (if it is a text file you are working with)

char[] ch = File.ReadAllText("filename.txt").ToCharArray();
JerryShaw 46 Posting Pro in Training

Just a thought, but you could use the PictureBox control and make it look however you want. You can swap the image out based on Mouse Enter / Leave, and Click events. That gives you total control of what the user sees.

Jerry

JerryShaw 46 Posting Pro in Training

Setting the Enable property of the grid will prevent the user from moving to any subsquent rows.

You may have to manually prevent them from selecting that row by trapping the row in the Select event. Then setting the CurrentCell to the next selectable row. This could get messy because they could use the keyboard or the mouse. You may have to monitor the last Up/Down key used for the grid to know which direction they were going.

Another option maybe to just set all of the cells for the invalid row(s) to ReadOnly before you give them control of the grid. If you do that, even if they select the row, they can not do anything with it.

In any case, you should use the CellFormating event handler to indicate this is not a selectable cell. You can even set the colors to give them the illusion that it is not selectable:

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    if (e.RowIndex == 3) // some condition meaning not editable
    {
e.CellStyle.BackColor = Color.White;
e.CellStyle.ForeColor = Color.Black;
e.CellStyle.SelectionBackColor = Color.White;
e.CellStyle.SelectionForeColor = Color.Black;
     }
}

If you want to go the messy way (and this is just a start), Give youself a key var to track with, format the cell to make them think they can not select it, and monitor mouse and key strokes. Finally move the selection when they attempt to select a row you do not want them to.

private Keys _lastKey …
JerryShaw 46 Posting Pro in Training

adatapost gave you exactly what I would have done.
But if you really want to know what to put in that space you have tagged as "WHAT TYPE HERE?"

// Display items in the ListView control
    foreach (DataRow row in dtable.Rows)
    {

       //WHAT TYPE HERE? 
      listViewUsers.Items.Add( new ListViewItem(new string[]{
              row["mobile_phone"].ToString() ,
              row["name"].ToString() }));

    }
kvprajapati commented: Cool! +6
JerryShaw 46 Posting Pro in Training

Interesting that this thread is back alive after a year.
The SqlDataAdapter will automatically take care of opening and closing the connection, but the others such as SqlCommand do not. The adpater is a nice and easy to use component, but on the down side, it is a heavy class. If you need high throughput, consider using a DataReader.

It is better to keep the connection string as a global var than an SqlConnection. It is better to create new, open, use, and dispose of an SqlConnection instance because connections can be broken when you least expect it.

However, sometimes, you do need to keep a connection open for an extended period of time when building things like mass data transports. Consider a process where 100 rows per second need to be transferred from a socket into a database. Creating 100 SqlConnections per second doesn't work (for very long :).

Most commercial applications use a Data Access Layer (DAL) class to manage their database requirements. This is usually a static class which makes it available to all forms and classes in the entire application. A DAL also decouples your application from a specific DBMS. If your company decides to move to a different or newer version of the DBMS , (if written correctly) all that needs to change is the DAL class which lowers the cost because there is minimal regression testing.

Well, off my soap box, have a Happy New Year

JerryShaw 46 Posting Pro in Training

I think you are stuck with Invoke because that is how C# moves the object pointer into the memory stack of the thread that wants to use it.
A little trick on sending the event to something that does not know how to check for InvokeRequired is to replace sender with null, and check that when it hits the handler. Replace sender in the delegate with this, or some non null value so it knows not to re-throw the invoke.

Good Luck

Thanks jerry, but calling the event from the 2nd thread always fails in my code. but I guess its because I haven't disabled the cross thread warnings.

I really don't like having to check if an invoke is required in the event handler on the form, I know an Invoke will always be required because that events exists in my code for the sole reason of threading. But I don't know how to get around it.

as I posted above, I did find a way to just run the methods asynchronously easy returning the data. but I still have the problem of having to invoke the response data in order to use it and I wish there was a way around it.

JerryShaw 46 Posting Pro in Training

If the receivers of the event absolutely must have the information back into thier own thread (like a Windows App sometimes does) then you would handle the invoke for arguments in those receiving threads.
Move your delegate out into the name space so that receivers outside of this class can use it. Really your choice, they can use fully qualified naming to get to it as well.

When the thread is ready to push the data into the event, then check to see if it is assigned, and then call it.

The receiver needs to check to see if invoke is required. Your Something class may itself be called from another thread, so to be safe, let the receivers deal with it.
(see more below this code snip)

using System.Threading;

namespace WindowsFormsApplication1
{
    public delegate void onTimelineHandler(object sender, TimelineArgs e);
    class SomeClass
    {
        public SomeClass() { }
        public event onTimelineHandler OnTimelineRecieved;

        public void TimelineAsyncStart(string url)
        {
            Thread myAsyncer = new Thread(new ParameterizedThreadStart(doTimelineAsync));
            string[] objar = new string[] { url, "username", "password" };
            myAsyncer.Start(objar);
        }

        private void doTimelineAsync(object objar)
        {
            string[] sa2 = (string[])objar;
            string url = sa2[0];
            string username = sa2[1];
            string password = sa2[2];
            object myobject = "411"; // just something to play with
            //some stuff happens here
            if( OnTimelineRecieved != null )
            {
                TimelineArgs targs = new TimelineArgs(myobject);
                OnTimelineRecieved(null, targs);
            }
        }
    }

    public class TimelineArgs
    {
        public object Something = null;
        public TimelineArgs(object something)
        {
            Something = something;
        }
    }

}

If …

JerryShaw 46 Posting Pro in Training

I changed your code so that you can actually click on the other buttons.

public partial class Form1 : Form
    {
        private int controlnum = 0;
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Button homebtn = new Button(); 
            this.panel1.Controls.Add(homebtn);
            homebtn.Text = "New Button" + controlnum.ToString();
            homebtn.Location = new Point( 20, controlnum * 23); 
            homebtn.Size = new System.Drawing.Size(175, 23); 
            homebtn.Name = "Control" + controlnum.ToString(); 
            controlnum = controlnum + 1; 
            homebtn.Click += new System.EventHandler(this.SelectEditableControl); 
        }
        public void SelectEditableControl(object sender, EventArgs e)
        {
            propertyGrid1.SelectedObject = sender;
            propertyGrid1.Refresh();
        }
    }

// Jerry

JerryShaw 46 Posting Pro in Training

Post your code that sets up the connection string and I will take a look. The error you mention is a typical syntax issue.

// Jerry

JerryShaw 46 Posting Pro in Training

DataRow[] rows = yourTable.Select(string.Format("ID='{0}'",cbIDs.Text));

yourLabel.Text = (string)rows[0]["Name"];

JerryShaw 46 Posting Pro in Training
DataTable tbl = new DataTable();
SqlDataAdapter adapt = new SqlDataAdapter(string.Format("select cust_address,customer_city  from customers where customer_id = {0}", customerID), con);
adapt.Fill(tbl);
if (tbl.Rows.Count > 0)
{
       lblAddress1.Text = (string)tbl.Rows[0]["cust_address"];
       lblCity.Text = (string)tbl.Rows[0]["customer_city"];
}
tbl.Dispose();

Just one of many ways of doing this.

JerryShaw 46 Posting Pro in Training

Maybe posting the rest of the code (or entire project) will help. The adapter.table is a bit of a mystery.
The acceptchanges is not really needed until later after the rows have all been added. I think the use of the adapter object in the for loop may be at the root of the problem, but until it is more obvious as to what that object is... it is just an assumption.

JerryShaw 46 Posting Pro in Training

When you scrub off all the fluffy help methods like WriteLn etc, you see that all communications through the comport are actually in byte[] format. Your BMP can be placed into a byte array, and sent to the comport.

JerryShaw 46 Posting Pro in Training

estimatorDataSet.QuoteCalcHeader["estimateno"]. <<== is estimateno correct ? does the QuoteCalcHeader accept a string as the indexer ?
What is QuoteCalcHeader ? (Type?)

You can ignore the code below, I think your problem is with indexing that QuoteCalcHeader object, but the formatting below might help you after resolving that issue, so I left it in this response.

private void findBN_Click(object sender, EventArgs e) 
{ 
    int num;
    string aFilter = string.Empty; 
    if( !string.IsNullOrEmpty(estfindTB.Text) && Int.TryParse(estfindTB.Text, out num) )
         aFilter = "Id="+estfindTB.Text;
  estimatorDataSet.QuoteCalcHeader["estimateno"].DefaultView.RowFilter = aFilter; }

// Jerry

JerryShaw 46 Posting Pro in Training

Place an Applicaiton.DoEvents(); inside of the loop so that the main thread has a chance to service its message queue and this should allow your label to update.

// Jerry

JerryShaw 46 Posting Pro in Training

Why do you think this is an error.
Your timer is on a 1000 ms loop, and the TryEnter has a max wait time of 1ms. It should always return true, because there was nothing preventing it (IOW nothing else locking the object for more than 1001ms.

Try having another method or timer that holds the lock for more than one second while the 1second timer is active, and see if it reacts the way you think it should.

// Jerry

JerryShaw 46 Posting Pro in Training

Does the button have a BackColor property ?
button.BackColor = Color.Red;

JerryShaw 46 Posting Pro in Training

Are you saying that when you change rows, you want to know how to set the radio buttons to have the correct one checked ?
The BindingSource has an event for position change. Setup a BindingSource for this table, and attach an event handler to its PositionChanged event.

// Jerry

JerryShaw 46 Posting Pro in Training

Jonny,

You can send your code to me at shawjh@meadowcrk.com
Using the forum is more difficult to work out the details, so we can do it through emails.

// Jerry

JerryShaw 46 Posting Pro in Training

Jonny,

Too bad you had to work today... got to pay the bills though :)

Plugins will certainly work in your case. Before jumping into that, let me offer another option for your situation.

Your reply in regards to "My Form (I belive you call this an interface)" makes me want to explain a little more about what an interface is.

Let me do that by providing an example of a program I am currently working on. I am building a communications driver for a piece of hardware that is capable of communicating either by TCP (sockets) or by Serial (COM1, etc). The user can set in the database which method of communications will be done for each board. The driver will handle both types of communication at the same time.
Both the Serial and TCP versions must have the same events, and methods definitions (at least those that are publicly visible).
What I did was create an interface named CommunicationsInterface

public [U][B]interface[/B][/U] CommunicationsInterface
{
        event ReceiveData onReceiveData;
        event SendData onSendData;
        event SocketConnect onSocketConnect;

        bool Open();
        bool Close();
..... many more
}

I placed all of the prototype methods and events into this interface file. Next I created two more classes TCPCom and SerialCom. These new classes derive from the CommunicationsInterface.

public class TCPCom : CommunicationsInterface
{
       public event ReceiveData onReceiveData;
        public event SendData onSendData;
        public event SocketConnect onSocketConnect;

        public bool Open(){...}
        public bool Close(){...}
}

-- Same for the SerialCom class …

JerryShaw 46 Posting Pro in Training

a) Tell the main exe to find and load the new dll (keeping in mind that the dll file name will not be hard coded)

What some plugin systems use is the file extension or a subdirectory where it knows add-ons will be located.

I use a configuration (XML) file that tells my program which files it is authorized to load. The configuration file has additional information for each plugin like the Menu text it will have, and under what menu it should appear.

b)How would one dynamically ask the exe to call new functions in this new dll?

There are two ways of doing this. I have seen some examples, where the main application will use reflection to find all the public methods in the plugin. The second method is what I use, and that is to create an interface, and have all of my plugins use that interface (and I only allow the main application to load plugins that are of this interface). Then your main application will know exactly what methods will be in every plugin.
Obviously we don't want to re-write the interface everytime we need to add some new method, therefore it is common to put a generic catch all method that we can pass a command to (a phrase with parameters). Example: All of my plugins have this method:

public void ExecuteCommand(IPlugin sender, string command, params Object[] Params)

Sender can be null, and is null when called by …

JerryShaw 46 Posting Pro in Training

If you are referring to licensing the software application on the target machine, you may want to checkout this website:
http://www.eziriz.com/intellilock.htm

I use this product, and it is very nice, plus it will prevent others from reverse engineering it.

The target machine will need dot net, and you can put that into your installer.

// Jerry

JerryShaw 46 Posting Pro in Training

I think what Jonny wants to do is have two dlls with the same name. Some customers get the one version , and other customers get the other one.

Many programmers have a debug version of a class library, and the production version, and this is exactly what we do is to replace the production DLL on the target machine with the Debug version. Same file name is referenced in the project.

The property settings for the referenced class library is important to make this work.

Another approach, however more complicated is to dynamically load the DLL that you want to use, and deliver both. This is commonly referred to as Plugins or in VS lingo, Add-ons.

I write most of my large projects using the plugin approach because some customers need some extra feature, or want some feature totally different, so we just setup the main application configuration so they can pick the File they want to use from a menu or button, or preload the filename to use in a configuration file, and just load it for them. Another advantage, is that many programmers can work on the project at the same time without bumping into each other, and you can upgrade a customer site with just the changed libraries instead of monolythic exe.

There are many examples of building plugins for C# on the net, but if someone is truely interested in this approach, I can point them to the websites I …

JerryShaw 46 Posting Pro in Training

Make sure your DateTime value is enclosed in single quotes.

You might find it easier (to read and build) if you assemble the string using the string.Format() method.

SqlConnection conn = new SqlConnection();
SqlDateTime sTime = new SqlDateTime(DateTime.Now);
SqlCommand command = new SqlCommand(
string.Format("INSERT INTO Sensors VALUES ('{0}','{1}',{2},'{3}' )"
                    , sensors[i].getName()
                    , sensors[i].getType()
                    , sensors[i].getVal()
                    , sTime.Value
                    )
                , conn
                );
command.ExecuteNonQuery();