Got struck in the mid of the project... Please Help, very urgent!!!

Sep 15 2009 3:24 AM
Hi Friends, I am doing a project on Automating the Disk Quota Management. I was struck at a particular point and could not find a solution how to get the required output.

Here is my requirement: As soon as I type the domain name, the list of users in the Active Directory related to that Domain have to be displayed in the ListBox/ComboBox(whatever it may be) beneath it. Then I can choose the user from it.

Need a help very urgent, try to suggest me how to progress further. What the code need to be added and where it is added (or) do I have to go with event handling on the corresponding text field(where I enters the domain name).

Here my code follows:

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.Collections;

using ClassLibrary1;        //Must include this reference to fetch the dll.

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();

           
            string dom = textBox1.Text;
            Class1 c1 = new Class1();
            ArrayList a = c1.loadallusers(dom);
            listBox1.Items.Add(a);
            
           
            //UniformLookAndFeel.Format(this);          /* To change the look and feel of the form */

            /* Add the size options to the ComboBox as Items */

            comboBox1.Items.Add("KB");
            comboBox1.Items.Add("MB");
            comboBox1.Items.Add("GB");
            comboBox1.Items.Add("TB");
            comboBox1.Items.Add("PB");
            comboBox1.Items.Add("EB");

            comboBox1.SelectedItem = "MB";

            comboBox2.Items.Add("KB");
            comboBox2.Items.Add("MB");
            comboBox2.Items.Add("GB");
            comboBox2.Items.Add("TB");
            comboBox2.Items.Add("PB");
            comboBox2.Items.Add("EB");

            comboBox2.SelectedItem = "MB";

            //textBox1.Focus();


        }



        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged_1(object sender, EventArgs e)
        {
            Class1 c1 = new Class1();
            string domain = textBox1.Text;

            ArrayList al = c1.loadallusers(domain);
        }

        private void textBox2_TextChanged_1(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged_1(object sender, EventArgs e)
        {

        }

        private void textBox4_TextChanged_1(object sender, EventArgs e)
        {

        }

        /* Do not limit the user from disk usage :: Disable the text fields */

        private void radioButton1_CheckedChanged_1(object sender, EventArgs e)
        {
            if (radioButton1.Checked == true)
            {
                textBox5.Enabled = false;
                textBox6.Enabled = false;

                comboBox1.Enabled = false;
                comboBox2.Enabled = false;
            }
            return;

        }

        /* Set the Disk Quota limits to user :: Enable the radiobutton, then the fields are enabled. */

        private void radioButton2_CheckedChanged_1(object sender, EventArgs e)
        {
            if (radioButton2.Checked == true)
            {
                textBox5.Enabled = true;
                textBox6.Enabled = true;

                comboBox1.Enabled = true;
                comboBox2.Enabled = true;
            }
        }

        private void textBox5_TextChanged_1(object sender, EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged_2(object sender, EventArgs e)
        {

        }

        private void textBox6_TextChanged_1(object sender, EventArgs e)
        {

        }

        private void comboBox2_SelectedIndexChanged_1(object sender, EventArgs e)
        {

        }


        private void button1_Click_1(object sender, EventArgs e)
        {
            /* Get the values from the form and store to send them as parameters later in the UserQuota method. */
            string domain = textBox1.Text;
                      
            string username = listBox1.SelectedItem.ToString();
            string drive = textBox3.Text;
            string server = textBox4.Text;

            if (domain == "" || username == "" || drive == "" || server == "")
            {
                MessageBox.Show("Enter all the fields...!");
                return;
            }

            /* Respond when chosen radiobutton1 :: No limit to user */
            if (radioButton1.Checked == true)
            {
                MessageBox.Show("No Limit is set to User:" + username);
                textBox1.ResetText();
                //textBox2.ResetText();
                textBox3.ResetText();
                textBox4.ResetText();

                return;

            }
            UInt64 limit;
            UInt64 warning;


            /* Sets the limit in the respective given size when chosen  */

            /* Check ComboBox1 for User Limit */

            if (comboBox1.SelectedItem.ToString() == "KB")
            {
                limit = UInt64.Parse(textBox5.Text);
                limit = limit * 1024;

            }

            else if (comboBox1.SelectedItem.ToString() == "MB")
            {
                limit = UInt64.Parse(textBox5.Text);
                limit = limit * 1024 * 1024;
            }

            else if (comboBox1.SelectedItem.ToString() == "GB")
            {
                limit = UInt64.Parse(textBox5.Text);
                limit = limit * 1024 * 1024 * 1024;
            }

            else if (comboBox1.SelectedItem.ToString() == "TB")
            {
                limit = UInt64.Parse(textBox5.Text);
                limit = limit * 1024 * 1024 * 1024 * 1024;
            }

            else if (comboBox1.SelectedItem.ToString() == "PB")
            {
                limit = UInt64.Parse(textBox5.Text);
                limit = limit * 1024 * 1024 * 1024 * 1024 * 1024;
            }

            else
            {
                limit = UInt64.Parse(textBox5.Text);
                limit = limit * 1024 * 1024 * 1024 * 1024 * 1024 * 1024;
            }




            /* Check ComboBox2 for warning limit */

            if (comboBox2.SelectedItem.ToString() == "KB")
            {
                warning = UInt64.Parse(textBox6.Text);
                warning = warning * 1024;

            }

            else if (comboBox2.SelectedItem.ToString() == "MB")
            {
                warning = UInt64.Parse(textBox6.Text);
                warning = warning * 1024 * 1024;
            }

            else if (comboBox2.SelectedItem.ToString() == "GB")
            {
                warning = UInt64.Parse(textBox6.Text);
                warning = warning * 1024 * 1024 * 1024;
            }

            else if (comboBox2.SelectedItem.ToString() == "TB")
            {
                warning = UInt64.Parse(textBox6.Text);
                warning = warning * 1024 * 1024 * 1024 * 1024;
            }

            else if (comboBox2.SelectedItem.ToString() == "PB")
            {
                warning = UInt64.Parse(textBox6.Text);
                warning = warning * 1024 * 1024 * 1024 * 1024 * 1024;
            }

            else
            {
                warning = UInt64.Parse(textBox6.Text);
                warning = warning * 1024 * 1024 * 1024 * 1024 * 1024 * 1024;
            }


           Class1 c1 = new Class1();


            if (warning >= limit)
            {
                MessageBox.Show("Warning Limit is exceeded than the User Limit.");
                textBox5.ResetText();
                textBox6.ResetText();
            }
            else
            {
                /* Take the parameters supplied by the user at GUI and then call the USERQUOTA method with the
                   help of Class1 reference(c1). Store the returned string.  */

                string msg = c1.userQuota(domain, username, drive, server, limit, warning);


                /* Compare the string_msg and then reset the text fields of GUI. */
                if (msg == "Quota is set to the User.")
                {
                    MessageBox.Show("Quota Created to User:" + username);

                    textBox1.ResetText();
                    //textBox2.ResetText();
                    textBox3.ResetText();
                    textBox4.ResetText();
                    textBox5.ResetText();
                    textBox6.ResetText();

                }

                /* If the above condition is failed, display the error message stored in the string. */

                else
                {
                    MessageBox.Show(msg);
                }

            }
        }

        /* Button "Reset" to reset the fields. */
        private void button2_Click_1(object sender, EventArgs e)
        {
            textBox1.ResetText();
            //textBox2.ResetText();
            textBox3.ResetText();
            textBox4.ResetText();
            textBox5.ResetText();
            textBox6.ResetText();

        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
           


        }


      
    }
}

Answers (1)