Example #1
0
        //{

        /*
         * if (busProc.dbSession.activeConn.State == ConnectionState.Closed)
         * {
         *  busProc.dbSession.activeConn.Open();
         * }
         * SqlCommand command = new SqlCommand();
         * command.Connection.ConnectionString = LoginForm.busProc.dbSession.activeConn.ConnectionString;
         * //command.Connection.Open();
         * command.CommandText = "SELECT COUNT(*) FROM customers";
         * int count = (int)command.ExecuteScalar();
         * //command.Connection.Close();
         * return count;
         */
        //}
        public DataTable getRecords(BusinessLayer busProc, string tableName)
        {
            try
            {
                SqlCommand    command    = new SqlCommand();
                SqlConnection connection = new SqlConnection(Program.connString);
                command.Connection  = connection;
                command.CommandText = "SELECT * FROM " + tableName;
                SqlDataAdapter da = new SqlDataAdapter(command);
                DataTable      dt = new DataTable();
                da.Fill(dt);
                //command.Connection.Close();
                return(dt);
            }
            catch (SqlException ex)
            {
                string            message = "You do not have permission to view this table.";
                string            caption = "Access Denied";
                MessageBoxButtons button  = MessageBoxButtons.OK;
                DialogResult      messageBox;
                messageBox = MessageBox.Show(message, caption, button);
                Console.WriteLine("Error " + ex);
                return(null);
            }
        }
Example #2
0
 public int CountRecords(BusinessLayer busProc, string tableName)
 {
     try
     {
         SqlCommand    command    = new SqlCommand();
         SqlConnection connection = new SqlConnection(Program.connString);
         command.Connection = connection;
         command.Connection.Open();
         command.CommandText = "SELECT COUNT(*) FROM " + tableName;
         int count = (int)command.ExecuteScalar();
         command.Connection.Close();
         //busProc.dbSession.activeConn.Close();
         return(count);
     }
     catch (SqlException ex)
     {
         string            message = "You do not have permission to view this table.";
         string            caption = "Access Denied";
         MessageBoxButtons button  = MessageBoxButtons.OK;
         DialogResult      messageBox;
         messageBox = MessageBox.Show(message, caption, button);
         Console.WriteLine("Error " + ex);
         return(0);
     }
 }
 private void btnLogin_Click(object sender, EventArgs e)
 {
     {
         string datasource = boxServerList.Text;
         string database   = boxDatabaseList.Text;
         string username   = txtUserName.Text;
         string password   = txtPassword.Text;
         LoginForm.busProc  = new BusinessLayer(datasource, database, username, password);
         Program.connString = busProc.generateConnString(datasource, database, username, password);
         if (LoginForm.busProc.isLoggedIn == true)
         {
             this.Hide();
             Form1 mainForm = new Form1();
             mainForm.MdiParent = this.MdiParent;
             mainForm.Show();
         }
         else
         {
             Console.WriteLine("Unable to login.");
         }
     }
 }
 public int CountRecords(BusinessLayer busProc, string tableName)
 {
     return(busProc.dbSession.CountRecords(busProc, tableName));
 }
 public DataTable getRecords(BusinessLayer busProc, string tableName)
 {
     return(busProc.dbSession.getRecords(busProc, tableName));
 }