Beispiel #1
0
        //Deletes a company from the DB provided its id
        public DataSet deleteCompany(CompanyEN com, int i) // It will delete the index passed in the view
        {
            string s;

            s = ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString(); //String where it's stored the instructions for the connecton for the DB
            SqlConnection c      = new SqlConnection(s);                                //The connection is effectuated
            DataSet       virtdb = new DataSet();                                       //Created the DataSet that is going to be returned with the information asked

            try
            {                                                           //The select in SQL language that is processed in the DB which will return all the rows from the table "Flight"
                SqlDataAdapter da = new SqlDataAdapter();               //  **  Will be implemented soon  **  //
                da.Fill(virtdb, "company");                             //It introduces the information returned from the select into this virtual DB
                DataTable t = new DataTable();                          //Creates a tble
                t = virtdb.Tables["company"];                           //Fils it with the select

                t.Rows[i].Delete();                                     //delete row

                SqlCommandBuilder cbuilder = new SqlCommandBuilder(da); //Elaborates the SQL command needed to make the changes
                da.Update(virtdb, "company");                           //Updates the DB with the new information added
            }
            catch (Exception ex)
            {
                ex.ToString();      //In case of an error it is printed here
                Console.WriteLine("ERROR: Delete company");
            }
            finally
            {
                c.Close();      //Closes the connection to the DB
            }
            return(virtdb);     //It returns the virtual DB with all the information asked inside
        }
Beispiel #2
0
        public void deleteCompany(CompanyEN co)
        {
            string        s = ConfigurationManager.ConnectionStrings["DatabaseConnection"].ToString();
            SqlConnection c = new SqlConnection(s);

            try
            {
                c.Open();
                SqlCommand com = new SqlCommand("Delete From Company Where id = " + co.ID, c);
                com.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ex.ToString();
                Console.WriteLine("ERROR: Delete company");
            }
            finally
            {
                c.Close();
            }
        }
Beispiel #3
0
        public void updateCompany(CompanyEN co)
        {
            string        s = ConfigurationManager.ConnectionStrings["DatabaseConnection"].ToString();
            SqlConnection c = new SqlConnection(s);

            try
            {
                c.Open();
                SqlCommand com = new SqlCommand("Update Company Set Name = '" + co.Name + "', Type = '" + co.Type + "', Phone ='" +
                                                co.Phone + "', Email = '" + co.Email + "', County = '" + co.Country + "', Website = '" + co.Website + "', Description = '" +
                                                co.Description + "' Where ID = " + co.ID, c);
                com.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ex.ToString();
                Console.WriteLine("ERROR: Update company");
            }
            finally
            {
                c.Close();
            }
        }
Beispiel #4
0
        public void addCompany(CompanyEN co)
        {
            string        s = ConfigurationManager.ConnectionStrings["DatabaseConnection"].ToString();
            SqlConnection c = new SqlConnection(s);

            try
            {
                c.Open();
                SqlCommand com = new SqlCommand("Insert Into Company (ID,Name,Type,Phone,Email,Country,Website,Description) VALUES ('" + co.ID + "','" + co.Name + "','" + co.Type + "','" +
                                                co.Phone + "','" + co.Email + "','" + co.Country + "','" + co.Website + "','" + co.Description + "')", c);

                com.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ex.ToString();
                Console.WriteLine("ERROR: Add company");
            }
            finally
            {
                c.Close();
            }
        }
Beispiel #5
0
        //Adds a new company to the DB
        public void addCompany(CompanyEN com)
        {
            string s;

            s = ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString(); //String where it's stored the instructions for the connecton for the DB
            SqlConnection c      = new SqlConnection(s);                                //The connection is effectuated
            DataSet       virtdb = new DataSet();                                       //Created the DataSet that is going to be returned with the information asked

            try
            {                                             //The select in SQL language that is processed in the DB which will return all the rows from the table "Flight"
                SqlDataAdapter da = new SqlDataAdapter(); //  **  Will be implemented soon  **  //
                da.Fill(virtdb, "company");               //It introduces the information returned from the select into this virtual DB
                DataTable dt = new DataTable();           //Creates a table
                dt = virtdb.Tables["company"];            //Fills it with the select
                DataRow newRow = dt.NewRow();             //insert new values in a new row
                newRow[0] = com.Id;
                newRow[1] = com.name;
                newRow[2] = com.type;
                newRow[3] = com.phone;
                newRow[4] = com.email;
                newRow[5] = com.country;
                newRow[5] = com.website;
                newRow[5] = com.description;
                dt.Rows.Add(newRow);
                SqlCommandBuilder cbuilder = new SqlCommandBuilder(da); //Elaborates the SQL command needed to make the changes
                da.Update(virtdb, "company");                           //Updates the DB with the new information added
            }
            catch (Exception ex)
            {
                ex.ToString();      //In case of an error it is printed here
                Console.WriteLine("ERROR: Add company");
            }
            finally
            {
                c.Close();      //Closes the connection to the DB
            }
        }
Beispiel #6
0
        // Shows the information of all the companies in the DB
        public DataSet showCompanies(CompanyEN b)
        {
            string s;

            s = ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString(); //String where it's stored the instructions for the connecton for the DB
            SqlConnection c      = new SqlConnection(s);                                //The connection is effectuated
            DataSet       virtdb = new DataSet();                                       //Created the DataSet that is going to be returned with the information asked

            try
            {                                                                       //The select in SQL language that is processed in the DB which will return all the rows from the table "Flight"
                SqlDataAdapter da = new SqlDataAdapter("select * from Company", c); //The select in SQL language that is processed in the DB which will return all the rows from the table
                da.Fill(virtdb, "company");                                         //It introduces the information returned from the select into this virtual DB
            }
            catch (Exception ex)
            {
                ex.ToString();      //In case of an error it is printed here
                Console.WriteLine("ERROR: show company");
            }
            finally
            {
                c.Close();      //Closes the connection to the DB
            }
            return(virtdb);     //It returns the virtual DB with all the information asked inside
        }