Duki 552 Nearly a Posting Virtuoso

Was able to modify your code to get it working. Thanks for the help.

private void textBox_End_Miles_TextChanged(object sender, EventArgs e)
        {
            int End_Miles_Value = Convert.ToInt32(textBox_End_Miles.Text);
            int Start_Miles_Value;

            if (Int32.TryParse(label_Start_Miles1.Text, System.Globalization.NumberStyles.Number, null, out Start_Miles_Value) && End_Miles_Value > Start_Miles_Value)
                label_Miles_Drove1.Text = (End_Miles_Value - Start_Miles_Value).ToString();
        }
Duki 552 Nearly a Posting Virtuoso

That works fine - it shows the value as 10000.

Duki 552 Nearly a Posting Virtuoso

I just tried:

int Start_Miles_Value = Convert.ToInt32(label_Start_Miles1.Text);

and I get the same Input string was not in a correct format error.

This label is tied to a db. During debug, it shows "10,000" as the text.

Duki 552 Nearly a Posting Virtuoso

Great, thanks. The only problem is, my label is tied to a database - I think that may be what's causing the issue. Every time I try to convert the Start_Miles1 label, it gives me errors. During debug, it shows the value as "10,000" (pulled from db).

Duki 552 Nearly a Posting Virtuoso

Maybe I should add more code and a description.

private void textBox_End_Miles_TextChanged(object sender, EventArgs e)
        {
            if (textBox_End_Miles.Text != "" && Convert.ToInt32(textBox_End_Miles.Text) > Convert.ToInt32(label_Start_Miles1.Text))
                label_Miles_Drove1.Text = (System.Convert.ToInt32(textBox_End_Miles.Text) - System.Convert.ToInt32(label_Start_Miles1.Text)).ToString();
            else
                label_Miles_Drove1.Text = "0"; 
        }

I want the "Miles Drove" label to automatically update when (a) the text in "Ending Miles" is not "", and (b) the text in the "Ending Miles" is > the text in "Starting Miles". I"m getting this error when I start typing:

Input string was not in a correct format.

Is there a better way to do this? I want to make sure only numeric values are entered, but I'm not sure how without using a maskedTextBox. I can't get it to work either way right now though (i.e., my test input is "4").

Duki 552 Nearly a Posting Virtuoso

OK, thanks!

Duki 552 Nearly a Posting Virtuoso

What am I missing here:

if (textBox_End_Miles.Text != "" && Convert.ToInt32(textBox_End_Miles.Text) > Convert.ToInt32(label_Start_Miles1.Text))

I keep getting a runtime error any time I modify the textbox.

Duki 552 Nearly a Posting Virtuoso

Welp, it's not working quite right. I added this:

private void linkLabel_Expense_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            tabControl_Expenses.Visible = true;
        }

And it doesn't do anything.

edit> Also, How can I keep controls at the bottom of my form and have them move when the tab_control is visible? E.g., I need to have an OK, and Cancel button at the bottom. How can I make them "float" as the main form grows and shrinks?

Duki 552 Nearly a Posting Virtuoso

Excellent. Thanks. So how do I use that padding control?

Duki 552 Nearly a Posting Virtuoso

Hmm I can't get mine to work - here's what I'm doing (just for testing right now):

private void Form_Vehicle_Checkin_Load(object sender, EventArgs e)
        {
            this.AutoSize = true;
            this.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            tabControl1.Visible = false;
        }

When it loads I just get blank space on my form.

Duki 552 Nearly a Posting Virtuoso

Hey Everyone,

I'm trying to have a form autosize when a user clicks on a Link Label. When the Link Label is clicked, I want the form to expand slightly, and show a tab control that I've created. I can't figure out how to use the this.autosize feature correctly for this though. Can someone give me a hand? Thanks

Duki 552 Nearly a Posting Virtuoso

Not sure that this is the best way to go about it, but I just added a c# class for my SQL command - this seems to work fine:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace REG_Asset_Checkout
{
    class SQL_cmd
    {

        public SqlCommand cmd;
        public SqlConnection conn;

        public void SQL_Update(string name, DateTime checkinDate, DateTime checkoutDate, string user, bool isCheckedOut)
        {
            cmd = new SqlCommand("UPDATE Laptops SET Name=@name, isCheckedOut = @ischeckedout, Checkout_Date=@checkout, Checkin_Date=@checkin, Checked_Out_By=@checkedoutby", conn);

            cmd.Parameters.AddWithValue("@name", name);
            cmd.Parameters.AddWithValue("@checkin", checkinDate.Date);
            cmd.Parameters.AddWithValue("@checkout", checkoutDate.Date);
            cmd.Parameters.AddWithValue("@checkedoutby", user);
            cmd.Parameters.AddWithValue("@ischeckedout", isCheckedOut);
        }

        public void SQL_Update(string name, DateTime checkinDate, DateTime checkoutDate, string user, bool isCheckedOut, string authorizedby)
        {
            cmd = new SqlCommand("UPDATE Laptops SET Name=@name, isCheckedOut = @ischeckedout, Checkout_Date=@checkout, Checkin_Date=@checkin, Checked_Out_By=@checkedoutby, Authorized_By=@authorizedby", conn);

            cmd.Parameters.AddWithValue("@name", name);
            cmd.Parameters.AddWithValue("@checkin", checkinDate.Date);
            cmd.Parameters.AddWithValue("@checkout", checkoutDate.Date);
            cmd.Parameters.AddWithValue("@checkedoutby", user);
            cmd.Parameters.AddWithValue("@authorizedby", authorizedby);
            cmd.Parameters.AddWithValue("@ischeckedout", isCheckedOut);
        }

        public void SQL_Update(string name, DateTime checkinDate, DateTime checkoutDate, string user, bool isCheckedOut, string authorizedby, string notes)
        {
            cmd = new SqlCommand("UPDATE Laptops SET Name=@name, isCheckedOut = @ischeckedout, Checkout_Date=@checkout, Checkin_Date=@checkin, Checked_Out_By=@checkedoutby, Authorized_By=@authorizedby, Notes=@notes", conn);

            cmd.Parameters.AddWithValue("@name", name);
            cmd.Parameters.AddWithValue("@checkin", checkinDate.Date);
            cmd.Parameters.AddWithValue("@checkout", checkoutDate.Date);
            cmd.Parameters.AddWithValue("@checkedoutby", user);
            cmd.Parameters.AddWithValue("@authorizedby", authorizedby);
            cmd.Parameters.AddWithValue("@notes", notes);
            cmd.Parameters.AddWithValue("@ischeckedout", isCheckedOut);
        }

        public void SQL_Update(string name, DateTime checkinDate, DateTime checkoutDate, string user, string notes, bool isCheckedOut)
        {
            cmd = new SqlCommand("UPDATE Laptops SET Name=@name, isCheckedOut = @ischeckedout, Checkout_Date=@checkout, Checkin_Date=@checkin, Checked_Out_By=@checkedoutby, Notes=@notes", conn);

            cmd.Parameters.AddWithValue("@name", name);
            cmd.Parameters.AddWithValue("@checkin", checkinDate.Date);
            cmd.Parameters.AddWithValue("@checkout", checkoutDate.Date);
            cmd.Parameters.AddWithValue("@checkedoutby", user);
            cmd.Parameters.AddWithValue("@notes", notes);
            cmd.Parameters.AddWithValue("@ischeckedout", isCheckedOut);
        }

        public void SQL_Update(DateTime checkinDate, bool isCheckedOut, string authorizedby)
        {
            cmd = new SqlCommand("UPDATE Laptops SET isCheckedOut = @ischeckedout, Checkin_Date=@checkin, Authorized_By=@authorizedby", conn);

            cmd.Parameters.AddWithValue("@checkin", checkinDate.Date);
            cmd.Parameters.AddWithValue("@ischeckedout", isCheckedOut);
            cmd.Parameters.AddWithValue("@authorizedby",
Duki 552 Nearly a Posting Virtuoso

Hey guys,

I have some overloaded functions that I want to get out of my main form.cs - is there an easy way to do this? I know in C++ you can just #include somefile.h and whatnot, but I can't find a way to do this using C#? Basically, all I want is to move a large chunk of code from my main_form.cs to a separate code file, so my main_form.cs isn't so cluttered:

private void SQL_Update(string name, DateTime checkinDate, DateTime checkoutDate, string user, bool isCheckedOut)
{
    cmd = new SqlCommand("UPDATE Laptops SET Name=@name, isCheckedOut = @ischeckedout, Checkout_Date=@checkout, Checkin_Date=@checkin, Checked_Out_By=@checkedoutby", conn);

    cmd.Parameters.AddWithValue("@name", name);
    cmd.Parameters.AddWithValue("@checkin", checkinDate.Date);
    cmd.Parameters.AddWithValue("@checkout", checkoutDate.Date);
    cmd.Parameters.AddWithValue("@checkedoutby", user);
    cmd.Parameters.AddWithValue("@ischeckedout", isCheckedOut);
}

private void SQL_Update(string name, DateTime checkinDate, DateTime checkoutDate, string user, bool isCheckedOut, string authorizedby)
{
    cmd = new SqlCommand("UPDATE Laptops SET Name=@name, isCheckedOut = @ischeckedout, Checkout_Date=@checkout, Checkin_Date=@checkin, Checked_Out_By=@checkedoutby, Authorized_By=@authorizedby", conn);

    cmd.Parameters.AddWithValue("@name", name);
    cmd.Parameters.AddWithValue("@checkin", checkinDate.Date);
    cmd.Parameters.AddWithValue("@checkout", checkoutDate.Date);
    cmd.Parameters.AddWithValue("@checkedoutby", user);
    cmd.Parameters.AddWithValue("@authorizedby", authorizedby);
    cmd.Parameters.AddWithValue("@ischeckedout", isCheckedOut);
}

private void SQL_Update(string name, DateTime checkinDate, DateTime checkoutDate, string user, bool isCheckedOut, string authorizedby, string notes)
{
    cmd = new SqlCommand("UPDATE Laptops SET Name=@name, isCheckedOut = @ischeckedout, Checkout_Date=@checkout, Checkin_Date=@checkin, Checked_Out_By=@checkedoutby, Authorized_By=@authorizedby, Notes=@notes", conn);

    cmd.Parameters.AddWithValue("@name", name);
    cmd.Parameters.AddWithValue("@checkin", checkinDate.Date);
    cmd.Parameters.AddWithValue("@checkout", checkoutDate.Date);
    cmd.Parameters.AddWithValue("@checkedoutby", user);
    cmd.Parameters.AddWithValue("@authorizedby", authorizedby);
    cmd.Parameters.AddWithValue("@notes", notes);
    cmd.Parameters.AddWithValue("@ischeckedout", isCheckedOut);
}

private void SQL_Update(string name, DateTime checkinDate, DateTime checkoutDate, string user, string notes, bool isCheckedOut)
{
    cmd = new SqlCommand("UPDATE Laptops SET Name=@name, isCheckedOut = @ischeckedout, Checkout_Date=@checkout, Checkin_Date=@checkin, Checked_Out_By=@checkedoutby, Notes=@notes", conn);

    cmd.Parameters.AddWithValue("@name", name);
    cmd.Parameters.AddWithValue("@checkin", checkinDate.Date);
    cmd.Parameters.AddWithValue("@checkout", checkoutDate.Date);
    cmd.Parameters.AddWithValue("@checkedoutby", user);
    cmd.Parameters.AddWithValue("@notes",
Duki 552 Nearly a Posting Virtuoso
linkLabel1_LinkClicked(null, null);

Worked great - thanks!

Duki 552 Nearly a Posting Virtuoso

Hey guys,

Is there any way to call the click event of a linklabel? E.g., I have a form that should call linkLabel_refresh_LinkClicked when it closes. Is that possible?

Thanks

Duki 552 Nearly a Posting Virtuoso

Great - I love this. Here's some of my updated coded; I've added SQL_cmd builder functions throughout my app.

private void SQL_Update(string name, DateTime checkinDate, DateTime checkoutDate, string user, bool isCheckedOut)
        {
            cmd = new SqlCommand("UPDATE Laptops SET Name=@name, isCheckedOut = @ischeckedout, Checkout_Date=@checkout, Checkin_Date=@checkin, Checked_Out_By=@checkedoutby", conn);

            cmd.Parameters.AddWithValue("@name", name);
            cmd.Parameters.AddWithValue("@checkin", checkinDate);
            cmd.Parameters.AddWithValue("@checkout", checkoutDate);
            cmd.Parameters.AddWithValue("@checkedoutby", user);
            cmd.Parameters.AddWithValue("@ischeckedout", isCheckedOut);
        }
kvprajapati commented: Update query without where clause will update all rows.... +10
Duki 552 Nearly a Posting Virtuoso

Very neat - I'll give that a whirl now.

Duki 552 Nearly a Posting Virtuoso

NEVERMIND - didn't have ,conn);

Edited my previous post :)

Duki 552 Nearly a Posting Virtuoso

Hey Guys,

I'm connecting to an SQL server and updating some fields. This works:

cmd = new SqlCommand("UPDATE Laptops SET Checkout_Date = '" + form_CheckOut.checkout + "' WHERE name='pen-laptop1'", conn);
cmd.ExecuteNonQuery();

But this one doesn't:

cmd = new SqlCommand("UPDATE Laptops SET " +
" isCheckedOut = 0" +
" Checkout_Date = '" + form_CheckOut.checkout + 
"', Checkin_Date = '" + form_CheckOut.checkin +
"', Checked_Out_By = '" + form_CheckOut.user + 
"', WHERE name = 'pen-laptop1'");

cmd.ExecuteNonQuery();

EDIT - FIXED CODE BELOW

cmd = new SqlCommand("UPDATE Laptops SET isCheckedOut = 0" +
                    ", Checkout_Date = '" + form_CheckOut.checkout + 
                    "', Checkin_Date = '" + form_CheckOut.checkin +
                    "', Checked_Out_By = '" + form_CheckOut.user + 
                    "' WHERE Name = '" + name + "'", conn);
Duki 552 Nearly a Posting Virtuoso

Hey guys,

I have a splash screen I'm loading here:

private void main_Form_Load(object sender, EventArgs e)
        {
            //Load Splash Screen
            this.Hide();
            Form_Splash form_Splash = new Form_Splash();
            form_Splash.Owner = this;
            form_Splash.Show();
            System.Threading.Thread.Sleep(3000);

            form_Splash.progressBar_splash.Value = 10;
            form_Splash.label_Process.Text = "Checking Authentication...";
            System.Threading.Thread.Sleep(2000);

            // Create the context for the principal object. 
            PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "REG");

            // Retrieve the group principal object for the group you need.
            GroupPrincipal groupPrincipal = GroupPrincipal.FindByIdentity(ctx, "Domain Admins");

            // Check to see if this user is a member of the "Administrators" group.
            bool isMember = UserPrincipal.Current.IsMemberOf(groupPrincipal);

            if (!isMember)
            {
                form_Splash.label_Process.Text = "Authentication Failed!";
                MessageBox.Show("You do not have the appropriate permissions - Some controls may be disabled.  If you feel you have received this notification in error, contact your system administrator.", "Authentication Notice", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            else
            {
                try
                {
                    form_Splash.progressBar_splash.Value = 30;
                    form_Splash.label_Process.Text = "Initializing SQL Connections...";
                    System.Threading.Thread.Sleep(2000);

                    //sql connection string
                    string cs = "Data Source=REG-PENTREE1\\SQLEXPRESS;Initial Catalog=reg_checkout;Integrated Security=SSPI";
                    conn = new SqlConnection(cs);
                    form_Splash.progressBar_splash.Value = 50;
                    System.Threading.Thread.Sleep(2000);

                    //open sql connection
                    form_Splash.label_Process.Text = "Openning SQL Connections...";
                    conn.Open();

                    form_Splash.label_Process.Text = "Starting...";
                    form_Splash.progressBar_splash.Value = 80;
                    System.Threading.Thread.Sleep(2000);

                    // cmd = new SqlCommand("UPDATE Laptops SET isCheckedOut=1 WHERE name='pen-laptop1'", conn);
                    // cmd.ExecuteNonQuery();
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    Console.WriteLine("Source: " + ex.Source);
                    Console.WriteLine("Exception Message: " + ex.Message);
                }
                catch (System.Exception ex)
                {
                    Console.WriteLine("Source: " + ex.Source);
                    Console.WriteLine("Exception Message: " + ex.Message);
                }
            }
            form_Splash.progressBar_splash.Value = 100;
            System.Threading.Thread.Sleep(2000);
            form_Splash.Close();   

            // TODO: This line of code loads data into the 'reg_checkoutDataSet1.Laptops' table. You can move, or remove it, as needed.
            this.laptopsTableAdapter.FillByCheckedIn(this.reg_checkoutDataSet1.Laptops);
          
        }

The screen loads, …

Duki 552 Nearly a Posting Virtuoso

I've spent the last couple of days researching how to connect to a database server and modify the data in that server. I was able to find a lot of information on how to Read from a database, but I found very little material to assist with Writing to a database.

This is an example code snippet of connecting to an SQL database on your network and modifying records within that database. My example only creates one connection, but it's easy enough to see how you can create multiple Connection Strings (cs) and then create multiple SQL Connections (conn) to different databases.

Some useful links:
http://www.csharp-station.com/tutorials/adodotnet/Lesson02.aspx
http://www.csharp-station.com/tutorials/adodotnet/Lesson03.aspx
http://www.sqlcommands.net/sql+update/

Duki 552 Nearly a Posting Virtuoso

Ok, I know I'm kind of talking to myself here - but just in case, here's what I have so far. I did away with the code above and am instead doing this:

private void button_Checkout_Click(object sender, EventArgs e)
        {
            DataGridViewRow row = dataGridView1.SelectedRows[0];
            MessageBox.Show(Convert.ToString((row.Cells[0].Value)));
            row.Cells[0].Value = "Pen-Laptop3";
....

This will change the database entry in my application, but it doesn't actually write it to the database. Any ideas?

Duki 552 Nearly a Posting Virtuoso

Is the only way to do this through sql connections? I've started a bit of code, but I have no idea if what I'm doing is correct... I'm getting compile errors so I'm apparently misunderstanding something.

public main_Form()
        {
            InitializeComponent();
            ADODB.Connection cn = new ADODB.Connection();
            ADODB.Recordset rs = new ADODB.Recordset();
            string cnStr;
            string query;

            //Connection string.
            cnStr = "Data Source=REG-PENTREE1//SQLEXPRESS;Initial Catalog=reg_assetcheckout;User ID=user;Password=pw";
            cn.Open(cnStr, null, null, 0);


        }

Is there an easier, maybe built-in way to do database updating?

Duki 552 Nearly a Posting Virtuoso

I have a datagrid showing my items - I want to modify a field in the database when the user clicks a button. So if row 3 is selected, I want to modify "SomeField" in Row3 to True. Is there an easy way to accomplish that?

Duki 552 Nearly a Posting Virtuoso

For some reason it works when I add it to the click event?

Duki 552 Nearly a Posting Virtuoso

I've got it figured out to a point. I've modified my SQL statement to grab the data I want - however, my tabChanged doesn't seem to be kicking in. Maybe I have something wrong?

private void tabControl_Assets_TabIndexChanged(object sender, EventArgs e)
        {
            switch (tabControl_Assets.SelectedIndex)
            {
                case 0:
                    // TODO: This line of code loads data into the 'reg_checkoutDataSet1.Laptops' table. You can move, or remove it, as needed.
                    this.laptopsTableAdapter.FillByCheckedIn(this.reg_checkoutDataSet1.Laptops);
                    break;
                case 1:
                    // TODO: This line of code loads data into the 'reg_checkoutDataSet1.Laptops' table. You can move, or remove it, as needed.
                    this.laptopsTableAdapter.FillByCheckedOut(this.reg_checkoutDataSet1.Laptops);
                    break;
            }
        }

Nothing shows up in my datagrid

Duki 552 Nearly a Posting Virtuoso

Awesome - didn't even realize that. Thanks

Duki 552 Nearly a Posting Virtuoso

I'm trying to find an event that handles which tab is clicked? I know it has to be simple, I'm just missing it. I want to say "when tab1 is clicked, do this, when tab2 is clicked, do that"

Duki 552 Nearly a Posting Virtuoso

I may be overlooking something here. I can't find a way to skip to page 2,3,4,etc. of threads I'm posting in until scrolling to the bottom. Would it be a bad thing to have the page links at both the top and bottom of the thread you're posting in?

Duki 552 Nearly a Posting Virtuoso

I've noticed a lot of complaints about the new layout of DaniWeb. Even I bickered when I started coming back recently.

I just wanted to say that I'm starting to really like the new layout and features. Specifically I like how speedy the page loads are, the floating menus at the bottom, and especially the icons representing "new post", "new post in a thread you've posted in", etc. For people like me that may only create 2 or 3 threads a day, this makes scrolling the page to find my post extremely easy.

I did like the color scheme of the old Dani - but purple's cool too :)

..................

As a side thought, how hard would it be to have several color schemes available in the control panel of each user?

Duki 552 Nearly a Posting Virtuoso

Oh ok - Personally, I love the huge button. But I understand that may cause troubles with spacing at the top.

Duki 552 Nearly a Posting Virtuoso

Wait... am I missing it somewhere?

Duki 552 Nearly a Posting Virtuoso

:) Awesome!

Duki 552 Nearly a Posting Virtuoso

Ok, thanks. How do I specify which data to show in the datagrid view? How do I make it check for a certain field in my database to be true before displaying the data?

Duki 552 Nearly a Posting Virtuoso

I think I can modify my program to not need the link labels by adding a single "checkout" button - but how do I modify data entries in the database from there? E.g., When they click Checkout, I want the selected database entry to change isCheckedOut to true.

Duki 552 Nearly a Posting Virtuoso

I've attached a screenshot of my app - hopefully this will make it clearer. I have a field called "isCheckedOut". I just want to load the isCheckedOut=false items in the first tab.

Also, I want to have a link to a checkout page for each row that's displayed. I've created linklabels for now, but I want a way to have them tied to each item in the database. Any ideas?

Duki 552 Nearly a Posting Virtuoso

Hey Guys,

I have a tabpage on my form, and I want to populate it according to which fields are set in a database. For example, I want tab#1 to list database fields of all items that have a particular field set to True. I want tab#2 to list the fields that do not have the key-field set to True. Could someone show me where to look for something like that? Thanks

Duki 552 Nearly a Posting Virtuoso

Sounds good - Thanks

Duki 552 Nearly a Posting Virtuoso

It's acting like it doesn't even get to my if() - maybe it's locking up or something. but I can still modify other controls on the form (e.g., the combo box with database connection).

Further investigation shows that if I put MessageBox.Show("Test") before the database query, it works fine; if I put it directly after the database query, it doesn't work.

Duki 552 Nearly a Posting Virtuoso

It's messing up again for some reason - I added a database to the project and now it doesn't check my domain for the groups. Here's the updated code:

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;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;


namespace REG_Asset_Checkout
{
    public partial class main_Form : Form
    {
        public main_Form()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            MessageBox.Show("You are a Domain Admin - Controls Unlocked!", "Authentication Notice", MessageBoxButtons.OK, MessageBoxIcon.Information);

        }

        private void main_Form_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'reg_checkoutDataSet.Laptops' table. You can move, or remove it, as needed.
            this.laptopsTableAdapter.Fill(this.reg_checkoutDataSet.Laptops);

            // Create the context for the principal object. 
            PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "REG");

            // Retrieve the group principal object for the group you need.
            GroupPrincipal groupPrincipal =
                            GroupPrincipal.FindByIdentity(ctx, "Domain Admins");

            // Check to see if this user is a member of the "Administrators" group.
            bool isMember = UserPrincipal.Current.IsMemberOf(groupPrincipal);

            if (isMember)
            {
                button1.Enabled = true;
                MessageBox.Show("You are a Domain Admin - Controls Unlocked!", "Authentication Notice", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                button1.Enabled = false;
                MessageBox.Show("You are not a Domain Admin - Controls locked!", "Authentication Notice", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }
    }
}
Duki 552 Nearly a Posting Virtuoso

Hey Guys,

Here's my code - for some reason, the message boxes aren't showing when I run the application. However, it shows up fine when I click the button on the form. Any idea why this would happen? Thanks.

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;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;


namespace REG_Asset_Checkout
{
    public partial class main_Form : Form
    {
        public main_Form()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            MessageBox.Show("You are a Domain Admin - Controls Unlocked!", "Authentication Notice", MessageBoxButtons.OK, MessageBoxIcon.Information);

        }

        private void main_Form_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'reg_checkoutDataSet.Laptops' table. You can move, or remove it, as needed.
            this.laptopsTableAdapter.Fill(this.reg_checkoutDataSet.Laptops);


            // Create the context for the principal object. 
            PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "REG");

            // Retrieve the group principal object for the group you need.
            GroupPrincipal groupPrincipal =
                            GroupPrincipal.FindByIdentity(ctx, "Domain Admins");

            // Check to see if this user is a member of the "Administrators" group.
            bool isMember = UserPrincipal.Current.IsMemberOf(groupPrincipal);

            if (isMember)
            {
                button1.Enabled = true;
                MessageBox.Show("You are a Domain Admin - Controls Unlocked!", "Authentication Notice", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                button1.Enabled = false;
                MessageBox.Show("You are not a Domain Admin - Controls locked!", "Authentication Notice", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }
    }
}
Duki 552 Nearly a Posting Virtuoso

One feature I love about other user-help forums is the ability to mark a specific post as the answer to the thread, and then have that post displayed directly under the original post. Yahoo, spiceworks, and MSDN(i think) sites use this feature a lot, and it makes finding solutions to solved threads much easier. I think for us to get the most out of solved threads, finding the "solution post" should be extremely easy. Just a thought. :)

TrustyTony commented: Sounds usefull suggestion +0
Duki 552 Nearly a Posting Virtuoso

Thank you, thank you, thank you! Working great!

Duki 552 Nearly a Posting Virtuoso

Ok, how do you check domain groups though?
Here's what I have so far:

// Create the context for the principal object. 
            PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "REG");

            // Retrieve the group principal object for the group you need.
            GroupPrincipal groupPrincipal =   
                            GroupPrincipal.FindByIdentity(ctx, "Domain Admins");

            // Find the principal object for which you wish to check membership.
            UserPrincipal userPrincipal = 
                              UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, "ctote");

            // Check to see if this user is a member of the "Administrators" group.
            bool isMember = userPrincipal.IsMemberOf(groupPrincipal);



            if (isMember)
            {
                directory_textBox.AppendText("Yeap \n");
            }
            else
            {
                directory_textBox.AppendText("Nope \n");
            }

If I could find a way to translate "ctote" to something like

System.Security.Principal.WindowsIdentity identity;
            identity = System.Security.Principal.WindowsIdentity.GetCurrent();

that would be great. I tried replacing "ctote" with identity.ToString() but no luck.

Duki 552 Nearly a Posting Virtuoso

No, not sure how to use that.

Duki 552 Nearly a Posting Virtuoso

I have this part working - but I'm not sure how to check against domain groups rather than built in groups:

namespace REG_Asset_Checkout
{
    public partial class main_Form : Form
    {
        public main_Form()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            System.Security.Principal.WindowsIdentity identity;
            identity = System.Security.Principal.WindowsIdentity.GetCurrent();

            System.Security.Principal.WindowsPrincipal principal;
            principal= new System.Security.Principal.WindowsPrincipal(identity);

//extra stuff
            DirectoryEntry de = new DirectoryEntry("WinNT://REG/REG-Pentree1", "ctote", "Lynn790*");
            foreach (DirectoryEntry child in de.Children)
            {
                directory_textBox.AppendText(child.SchemaClassName + ": " + child.Name + "\n");
                
            }           

        }
    }
}
Duki 552 Nearly a Posting Virtuoso

Hey Guys,

I'm creating an application that will require specific privileges. Users will eventually be add/removed from this group; I was wondering if there's a way I can tie in an Active Directory group to the software? Something that would let me say "if you're part of this group you can do this". That way I wouldn't have to modify the source every time a new users is added/removed from the "admin" group.

Duki 552 Nearly a Posting Virtuoso

Hey everyone,

I'm using C# ASP.NET and am trying to bind a field in my SQL database to a label. I have a combo box working OK with my database right now, and I want the label to change when the combo box changes. Could someone give me a hand? I'm completely new to ASP.NET, so all I have to work with is my knowledge of C#. :(

Duki 552 Nearly a Posting Virtuoso

Hey guys,

I just came back to ask a question after a month or so of not being here. It took me some time to find the "New Post" button at the bottom of the page - honestly, I almost gave up and went to a different site. Could be discouraging for newcomers?

Duki 552 Nearly a Posting Virtuoso

Someone from IRC->#BOOST was able to give me a hand... my problem was I was creating a CLR Empty Project rather than a regular General->Empty Project. Working great now.