When I enter the system Choose a company to work for

Asked

Viewed 95 times

0

Good Morning staff I need a help from you in my college project I am doing a stock system with 4 layers, I have a form that is registration company where user company that the user wishes to work, when I enter the system I choose the company that the user wants to work at the moment, as I do for the data to be of that company, for example company A I will have the stock movements of company A, when choosing company B I will have the movements of company B made the screen

Tela para selecionar a empresa usuária

code

Form

    public frmSelEmpUsuaria()
    {
        InitializeComponent();
    }

    private void frmSelEmpUsuaria_Load(object sender, EventArgs e)
    {
        CarregaEmpresaUsuaria();
    }

    private void CarregaEmpresaUsuaria()
    {
        try
        {
            IList<EmpresaUsuariaDTO> listaEmpresaUsuaria = new List<EmpresaUsuariaDTO>();
            listaEmpresaUsuaria = new EmpresaUsuariaModel().ListaEmpresa();
            dgvEmpresaUsuaria.AutoGenerateColumns = false;
            dgvEmpresaUsuaria.DataSource = listaEmpresaUsuaria;


        }
        catch (Exception erro)
        {

            MessageBox.Show(erro.Message);
        }
    }

    private void btnConfirmar_Click(object sender, EventArgs e)
    {
        // Não sei o codigo que vai no botão
    }

    private void btnCancelar_Click(object sender, EventArgs e)
    {
        this.Close();
    }
}

LAYER DAO

   public IList<EmpresaUsuariaDTO> ListaEmpresa()
    {


        try
        {
            SqlConnection CON = new SqlConnection();
            CON.ConnectionString = Properties.Settings.Default.csSistemaEstoque;
            SqlCommand CM = new SqlCommand();
            CM.CommandType = System.Data.CommandType.Text;
            CM.CommandText = "SELECT * FROM tbEmpresaUsuaria";

            CM.Connection = CON;

            SqlDataReader ER;

            IList<EmpresaUsuariaDTO> ListaEmpresa = new List<EmpresaUsuariaDTO>();
            CON.Open();

            ER = CM.ExecuteReader();

            if (ER.HasRows)
            {
                while (ER.Read())
                {
                    EmpresaUsuariaDTO empresaUsu = new EmpresaUsuariaDTO();

                    empresaUsu.Codigo = Convert.ToInt32(ER["cod_emp"]);
                    empresaUsu.DataCadastro = Convert.ToDateTime(ER["dtInclusao_emp"]);
                    empresaUsu.NomeRazao = Convert.ToString(ER["razao_emp"]);
                    empresaUsu.NomeFantasia = Convert.ToString(ER["nomeFant_emp"]);
                    empresaUsu.CpfCnpj = Convert.ToString(ER["cnpj_emp"]);
                    empresaUsu.RgInscricao = Convert.ToString(ER["inscEst_emp"]);
                    empresaUsu.Endereco = Convert.ToString(ER["endereco_emp"]);
                    empresaUsu.Numero = Convert.ToString(ER["numero_emp"]);
                    empresaUsu.Complemento = Convert.ToString(ER["compl_emp"]);
                    empresaUsu.Bairro = Convert.ToString(ER["bairro_emp"]);
                    empresaUsu.Cidade = Convert.ToString(ER["cidade_emp"]);
                    empresaUsu.Uf = Convert.ToString(ER["uf_emp"]);
                    empresaUsu.Cep = Convert.ToString(ER["cep_emp"]);
                    empresaUsu.Telefone = Convert.ToString(ER["tel_emp"]);
                    empresaUsu.Tel2 = Convert.ToString(ER["tel2_emp"]);
                    empresaUsu.Email = Convert.ToString(ER["email_emp"]);
                    empresaUsu.Site = Convert.ToString(ER["site_emp"]);
                    empresaUsu.EndLogo = Convert.ToString(ER["endLogo_emp"]);


                    ListaEmpresa.Add(empresaUsu);
                }
            }

            return ListaEmpresa;


        }
        catch (Exception ex)
        {

            throw ex;
        }
    }

Someone could give me a boost?

  • One option is to have a database for each company. When to choose empresa A connects with the banco A the same with the empresa B

1 answer

1

One way would be to create a global variable in the system, type Gemp, and when the user logs to write in this variable the id/company code.

And adjust all your sqls/querys to accept as filter this id/company code. And all your tables should also have the column that references the company.

guy;

CM.CommandText = "SELECT * FROM tbEmpresaUsuaria WHERE idEmpresa=" & GEmp;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.