Ejemplo n.º 1
0
        public static bool DeleteCompanyAccounts(RequestCompany request)
        {
            using (SqlConnection con = new SqlConnection(connectionstring)) {
                using (SqlCommand proc = new SqlCommand("spDeleteCompanyAccounts", con)
                {
                    CommandType = CommandType.StoredProcedure
                }) {
                    proc.Parameters.Add("@company_id", SqlDbType.Int).Value = request.Id;

                    try {
                        con.Open();
                        Console.WriteLine("Connection Success!");

                        try {
                            proc.ExecuteNonQuery(); // this is where I run my stored procedure
                        } catch (Exception e) {
                            Console.WriteLine("-------------");
                            Console.WriteLine("Procedure Error on spDeleteCompanyAccounts : {0}", e.ToString());
                            Console.WriteLine("-------------");

                            return(false);
                        }

                        Console.WriteLine("-------------");
                        Console.WriteLine("Procedure Success on spDeleteCompanyAccounts!");
                        Console.WriteLine("-------------");

                        return(true);
                    } catch (SqlException) {
                        Console.WriteLine("Connection Failure!");
                        return(false);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void LoadCompanyAndBind()
        {
            RequestCompany req = new RequestCompany(User.Id);

            Companies = Connect.ListCompany(req);

            companyComboBox.ValueMember   = "Id";
            companyComboBox.DisplayMember = "Name";
            companyComboBox.DataSource    = Companies;
        }
Ejemplo n.º 3
0
        private void deleteCompanyButton_Click(object sender, EventArgs e)
        {
            using (var form = new Confirm()) {
                var    confirmDelete = form.ShowDialog();
                string delete        = confirmDelete.ToString();

                if (delete == "OK")
                {
                    RequestCompany request = new RequestCompany(CompanySelected, User.Id);

                    Connect.DeleteCompanyAccounts(request);
                    Connect.DeleteCompany(request);

                    LoadCompanyAndBind();
                }
            }
        }
Ejemplo n.º 4
0
        public static List <RequestCompany> ListCompany(RequestCompany request)
        {
            List <RequestCompany> response = new List <RequestCompany>();

            using (SqlConnection con = new SqlConnection(connectionstring)) {
                using (SqlCommand proc = new SqlCommand("spListCompany", con)
                {
                    CommandType = CommandType.StoredProcedure
                }) {
                    proc.Parameters.Add("@user_id", SqlDbType.Int).Value = request.UserId;

                    try {
                        con.Open();
                        Console.WriteLine("Connection Success!");

                        SqlDataReader dr = proc.ExecuteReader();

                        while (dr.Read())
                        {
                            int    dbCompanyId   = Convert.ToInt32(dr["Id"]);
                            string dbCompanyName = Convert.ToString(dr["Name"]);

                            Console.WriteLine("Company Id : {0}", dbCompanyId);
                            Console.WriteLine("Company Name : {0}", dbCompanyName);

                            RequestCompany company = new RequestCompany(dbCompanyId, User.Id, dbCompanyName);
                            response.Add(company);
                        }

                        return(response);
                    } catch (SqlException) {
                        Console.WriteLine("Connection Failure!");
                        return(response);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void addCompanyFormButton_Click(object sender, EventArgs e)
        {
            string companyName = addCompanyFormTextBox.Text;

            if (String.IsNullOrEmpty(companyName))
            {
                MessageBox.Show("Please, insert a valid value for the new company name!");
            }
            else
            {
                RequestCompany request      = new RequestCompany(User.Id, companyName);
                bool           companyAdded = Connect.AddCompany(request);

                if (companyAdded)
                {
                    this.Close();
                }
                else
                {
                    MessageBox.Show("There was an error while adding the new company. Check the console for errors.");
                    this.Close();
                }
            }
        }