public static void ConnectionState()
        {
            string            msg   = "Connection state: " + "The connection is ";
            string            title = SqlConn.myApp();
            MessageBoxButtons btn   = MessageBoxButtons.OK;
            MessageBoxIcon    icon  = MessageBoxIcon.Information;

            MessageBox.Show(msg + connection.State.ToString(), title, btn, icon);
        }
Exemple #2
0
        private void Form2_Load(object sender, EventArgs e)
        {
            SqlConn.sqlQuery = "SELECT * FROM Car";
            SqlConn.OpenConn();
            SqlConn.command = new SqlCommand(SqlConn.sqlQuery, SqlConn.connection);

            SqlConn.dataAdapter   = new SqlDataAdapter(SqlConn.command);
            SqlConn.dataSet       = new DataSet();
            SqlConn.bindingSource = new BindingSource();
            SqlConn.dataAdapter.Fill(SqlConn.dataSet, "myCars");

            foreach (DataRow r in SqlConn.dataSet.Tables["myCars"].Rows)
            {
                //listBox1.Items.Add(r["Manufacturer"].ToString());
                listBox1.Items.Add(string.Format("{0} {1}", r["Manufacturer"].ToString(), r["Model"].ToString()));
            }
            listBox1.ValueMember = "CarID";

            SqlConn.bindingSource.DataSource = SqlConn.dataSet.Tables["myCars"];

            textBox1.DataBindings.Add("Text", SqlConn.bindingSource, "CarID");
            textBox2.DataBindings.Add("Text", SqlConn.bindingSource, "Manufacturer");
            textBox3.DataBindings.Add("Text", SqlConn.bindingSource, "Model");
            textBox4.DataBindings.Add("Text", SqlConn.bindingSource, "Color");
            textBox5.DataBindings.Add("Text", SqlConn.bindingSource, "SUV");
            textBox6.DataBindings.Add("Text", SqlConn.bindingSource, "Convertible");
            textBox7.DataBindings.Add("Text", SqlConn.bindingSource, "YearOfFabrication");
            textBox8.DataBindings.Add("Text", SqlConn.bindingSource, "ShowRoomID");

            listBox1.SelectedIndex = 0;

            var link = new DataGridViewLinkColumn();

            link.DisplayIndex = 0;
            link.DefaultCellStyle.NullValue = "SELECT";
            link.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

            link.Width = 60;

            link.ActiveLinkColor   = Color.White;
            link.LinkBehavior      = LinkBehavior.HoverUnderline;
            link.LinkColor         = Color.Crimson;
            link.TrackVisitedState = true;
            link.VisitedLinkColor  = Color.YellowGreen;

            dataGridView1.Columns.Add(link);
            dataGridView1.AllowUserToAddRows = false;

            ShowItems();
        }
 public static void OpenConn()
 {
     connection.Close();
     try
     {
         connection.ConnectionString = SqlConn.GetConnectionString();
         connection.Open();
     }
     catch (Exception e)
     {
         MessageBox.Show("The sysyem failed to establish a connection." + Environment.NewLine + e);
     }
     //finally
     //{
     //    ConnectionState();
     //}
 }
Exemple #4
0
        private void Form1_Load(object sender, EventArgs e)
        {
            SqlConn.sqlQuery = "SELECT * FROM Service";
            SqlConn.OpenConn();
            SqlConn.command = new SqlCommand(SqlConn.sqlQuery, SqlConn.connection);

            SqlConn.dataAdapter   = new SqlDataAdapter(SqlConn.command);
            SqlConn.dataSet       = new DataSet();
            SqlConn.bindingSource = new BindingSource();
            SqlConn.dataAdapter.Fill(SqlConn.dataSet, "Services");

            foreach (DataRow r in SqlConn.dataSet.Tables["Services"].Rows)
            {
                listBox1.Items.Add(r["Name"].ToString());
            }
            listBox1.ValueMember = "ServiceID";

            SqlConn.bindingSource.DataSource = SqlConn.dataSet.Tables["Services"];

            textBox1.DataBindings.Add("Text", SqlConn.bindingSource, "ServiceID");
            textBox2.DataBindings.Add("Text", SqlConn.bindingSource, "Name");
            textBox3.DataBindings.Add("Text", SqlConn.bindingSource, "Address");
            textBox4.DataBindings.Add("Text", SqlConn.bindingSource, "Service_TickID");

            listBox1.SelectedIndex = 0;

            var link = new DataGridViewLinkColumn();

            link.DisplayIndex = 0;
            link.DefaultCellStyle.NullValue = "SELECT";
            link.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

            link.Width = 60;

            link.ActiveLinkColor   = Color.White;
            link.LinkBehavior      = LinkBehavior.HoverUnderline;
            link.LinkColor         = Color.Crimson;
            link.TrackVisitedState = true;
            link.VisitedLinkColor  = Color.YellowGreen;

            dataGridView1.Columns.Add(link);
            dataGridView1.AllowUserToAddRows = false;

            ShowItems();
        }
Exemple #5
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     SqlConn.CloseConn();
 }
Exemple #6
0
 public Form1()
 {
     InitializeComponent();
     this.Text = SqlConn.myApp();
 }