235 lines
		
	
	
		
			9.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			235 lines
		
	
	
		
			9.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using System;
 | 
						|
using System.Collections.Generic;
 | 
						|
using System.Data;
 | 
						|
using System.Data.SqlClient;
 | 
						|
 | 
						|
namespace CSharpLibrary.SqlTypes
 | 
						|
{
 | 
						|
    public class Funcionario : Pessoa
 | 
						|
    {
 | 
						|
        public string user;
 | 
						|
        public string senha;
 | 
						|
        
 | 
						|
        public Funcionario(int? id, string nome, string rg, string cpf, 
 | 
						|
            string tel, string cel, string rua, string num, string cidade, 
 | 
						|
            string STATUS_PESSOA, string user, string senha): 
 | 
						|
 | 
						|
            base(id, nome,  rg,  cpf, 
 | 
						|
                 tel,  cel,  rua, 
 | 
						|
                 num,  cidade, 
 | 
						|
                 STATUS_PESSOA)
 | 
						|
           
 | 
						|
        {
 | 
						|
            this.user = checkLen(user.Length, 15) ? user : throw new Exception();
 | 
						|
            this.senha = checkLen(senha.Length, 15) ? senha : throw new Exception();
 | 
						|
 | 
						|
        }
 | 
						|
 | 
						|
        public override void Add()
 | 
						|
        {
 | 
						|
            using (con)
 | 
						|
            {
 | 
						|
                con.Open();
 | 
						|
                insert = new SqlCommand("INSERT INTO tbFuncionario(nomeFunc,rgFunc,cpfFunc,telFunc,celFunc,ruaFunc,numeroFunc,cidadeFunc,statusFunc,usuarioFunc,senhaFunc) " +
 | 
						|
                    "VALUES (@nomeFunc,@rgFunc,@cpfFunc,@telFunc,@celFunc,@ruaFunc,@numeroFunc,@cidadeFunc,@statusFunc,@usuarioFunc,@senhaFunc)", con);
 | 
						|
 | 
						|
                insert.Parameters.Add("@nomeFunc", SqlDbType.NVarChar, 50).Value = nome;
 | 
						|
                insert.Parameters.Add("@rgFunc", SqlDbType.NVarChar, 12).Value = rg;
 | 
						|
                insert.Parameters.Add("@cpfFunc", SqlDbType.NVarChar, 11).Value = cpf;
 | 
						|
                insert.Parameters.Add("@telFunc", SqlDbType.NVarChar, 10).Value = tel;
 | 
						|
                insert.Parameters.Add("@celFunc", SqlDbType.NVarChar, 11).Value = cel;
 | 
						|
                insert.Parameters.Add("@ruaFunc", SqlDbType.NVarChar, 100).Value = rua;
 | 
						|
                insert.Parameters.Add("@numeroFunc", SqlDbType.NVarChar, 4).Value = num;
 | 
						|
                insert.Parameters.Add("@cidadeFunc", SqlDbType.NVarChar, 30).Value = cidade;
 | 
						|
                insert.Parameters.Add("@statusFunc", SqlDbType.NVarChar, 10).Value = STATUS_PESSOA;
 | 
						|
                insert.Parameters.Add("@usuarioFunc", SqlDbType.NVarChar, 15).Value = user;
 | 
						|
                insert.Parameters.Add("@senhaFunc", SqlDbType.NVarChar, 15).Value = senha;
 | 
						|
 | 
						|
                insert.Prepare();
 | 
						|
                insert.ExecuteNonQuery();
 | 
						|
                con.Close();
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        public override void Edit(int id, List<string> vlr)
 | 
						|
        {
 | 
						|
            this.id = id;
 | 
						|
            nome = vlr[0];
 | 
						|
            rg = vlr[1];
 | 
						|
            cpf = vlr[2];
 | 
						|
            tel = vlr[3];
 | 
						|
            cel = vlr[4];
 | 
						|
            rua = vlr[5];
 | 
						|
            num = vlr[6];
 | 
						|
            cidade = vlr[7];
 | 
						|
            STATUS_PESSOA = vlr[8];
 | 
						|
            user = vlr[9];
 | 
						|
            senha = vlr[10];
 | 
						|
 | 
						|
            using (con)
 | 
						|
            {
 | 
						|
                con.Open();
 | 
						|
                update = new SqlCommand("UPDATE tbFuncionario SET nomeFunc = @nomeFunc, " +
 | 
						|
                "rgFunc = @rgFunc, " +
 | 
						|
                "cpfFunc = @cpfFunc, " +
 | 
						|
                "telFunc = @telFunc, " +
 | 
						|
                "celFunc = @celFunc, " +
 | 
						|
                "ruaFunc = @ruaFunc, " +
 | 
						|
                "numeroFunc = @numeroFunc, " +
 | 
						|
                "cidadeFunc = @cidadeFunc, " +
 | 
						|
                "statusFunc = @statusFunc, " +
 | 
						|
                "usuarioFunc = @usuarioFunc, " +
 | 
						|
                "senhaFunc = @senhaFunc " +
 | 
						|
                "WHERE idFunc = @idFunc", con);
 | 
						|
 | 
						|
                update.Parameters.Add("@idFunc", SqlDbType.Int).Value = this.id;
 | 
						|
                update.Parameters.Add("@nomeFunc", SqlDbType.NVarChar, 50).Value = nome;
 | 
						|
                update.Parameters.Add("@rgFunc", SqlDbType.NVarChar, 12).Value = rg;
 | 
						|
                update.Parameters.Add("@cpfFunc", SqlDbType.NVarChar, 11).Value = cpf;
 | 
						|
                update.Parameters.Add("@telFunc", SqlDbType.NVarChar, 10).Value = tel;
 | 
						|
                update.Parameters.Add("@celFunc", SqlDbType.NVarChar, 11).Value = cel;
 | 
						|
                update.Parameters.Add("@ruaFunc", SqlDbType.NVarChar, 100).Value = rua;
 | 
						|
                update.Parameters.Add("@numeroFunc", SqlDbType.NVarChar, 4).Value = num;
 | 
						|
                update.Parameters.Add("@cidadeFunc", SqlDbType.NVarChar, 30).Value = cidade;
 | 
						|
                update.Parameters.Add("@statusFunc", SqlDbType.NVarChar, 10).Value = STATUS_PESSOA;
 | 
						|
                update.Parameters.Add("@usuarioFunc", SqlDbType.NVarChar, 15).Value = user;
 | 
						|
                update.Parameters.Add("@senhaFunc", SqlDbType.NVarChar, 15).Value = senha;
 | 
						|
 | 
						|
                update.Prepare();
 | 
						|
                update.ExecuteNonQuery();
 | 
						|
 | 
						|
                con.Close();
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        public override bool Remove(int id)
 | 
						|
        {
 | 
						|
            try
 | 
						|
            {
 | 
						|
                con.Open();
 | 
						|
                delete = new SqlCommand(
 | 
						|
                    "UPDATE tbFuncionario " +
 | 
						|
                    "SET statusFuncionario = 'DESATIVADO' " +
 | 
						|
                    "WHERE idFunc = @idFunc", con
 | 
						|
                    );
 | 
						|
                delete.Parameters.Add("@idFunc", SqlDbType.Int).Value = id;
 | 
						|
                delete.Prepare();
 | 
						|
                delete.ExecuteNonQuery();
 | 
						|
                con.Close();
 | 
						|
            }
 | 
						|
            catch (SqlException)
 | 
						|
            {
 | 
						|
                throw new Exception();
 | 
						|
            }
 | 
						|
            return true;
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    public class Cliente : Pessoa
 | 
						|
    {
 | 
						|
 | 
						|
        public Cliente(int? id, string nome, string rg, string cpf,
 | 
						|
            string tel, string cel, string rua, string num, string cidade,
 | 
						|
            string STATUS_PESSOA) :
 | 
						|
 | 
						|
            base(id, nome, rg, cpf,
 | 
						|
                 tel, cel, rua,
 | 
						|
                 num, cidade,
 | 
						|
                 STATUS_PESSOA)
 | 
						|
 | 
						|
        {
 | 
						|
        }
 | 
						|
 | 
						|
        public override void Add()
 | 
						|
        {
 | 
						|
            using (con)
 | 
						|
            {
 | 
						|
                con.Open();
 | 
						|
                insert = new SqlCommand("INSERT INTO tbCliente(nomeCliente,rgCliente,cpfCliente,telCliente,celCliente,ruaCliente,numeroCliente,cidadeCliente,statusCliente) " +
 | 
						|
                    "VALUES (@nomeCliente,@rgCliente,@cpfCliente,@telCliente,@celCliente,@ruaCliente,@numeroCliente,@cidadeCliente,@statusCliente)", con);
 | 
						|
 | 
						|
                insert.Parameters.Add("@nomeCliente", SqlDbType.NVarChar, 50).Value = nome;
 | 
						|
                insert.Parameters.Add("@rgCliente", SqlDbType.NVarChar, 12).Value = rg;
 | 
						|
                insert.Parameters.Add("@cpfCliente", SqlDbType.NVarChar, 11).Value = cpf;
 | 
						|
                insert.Parameters.Add("@telCliente", SqlDbType.NVarChar, 10).Value = tel;
 | 
						|
                insert.Parameters.Add("@celCliente", SqlDbType.NVarChar, 11).Value = cel;
 | 
						|
                insert.Parameters.Add("@ruaCliente", SqlDbType.NVarChar, 100).Value = rua;
 | 
						|
                insert.Parameters.Add("@numeroCliente", SqlDbType.NVarChar, 4).Value = num;
 | 
						|
                insert.Parameters.Add("@cidadeCliente", SqlDbType.NVarChar, 30).Value = cidade;
 | 
						|
                insert.Parameters.Add("@statusCliente", SqlDbType.NVarChar, 10).Value = STATUS_PESSOA;
 | 
						|
 | 
						|
                insert.Prepare();
 | 
						|
                insert.ExecuteNonQuery();
 | 
						|
                con.Close();
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        public override void Edit(int id, List<string> vlr)
 | 
						|
        {
 | 
						|
            this.id = id;
 | 
						|
            nome = vlr[0];
 | 
						|
            rg = vlr[1];
 | 
						|
            cpf = vlr[2];
 | 
						|
            tel = vlr[3];
 | 
						|
            cel = vlr[4];
 | 
						|
            rua = vlr[5];
 | 
						|
            num = vlr[6];
 | 
						|
            cidade = vlr[7];
 | 
						|
            STATUS_PESSOA = vlr[8];
 | 
						|
            using(con)
 | 
						|
            {
 | 
						|
                con.Open();
 | 
						|
                update = new SqlCommand("UPDATE tbCliente SET nomeCliente = @nomeCliente, " +
 | 
						|
                "rgCliente = @rgCliente, " +
 | 
						|
                "cpfCliente = @cpfCliente, " +
 | 
						|
                "telCliente = @telCliente, " +
 | 
						|
                "celCliente = @celCliente, " +
 | 
						|
                "ruaCliente = @ruaCliente, " +
 | 
						|
                "numeroCliente = @numeroCliente, " +
 | 
						|
                "cidadeCliente = @cidadeCliente, " +
 | 
						|
                "statusCliente = @statusCliente " +
 | 
						|
                "WHERE idCliente = @idCliente", con);
 | 
						|
 | 
						|
                update.Parameters.Add("@idCliente", SqlDbType.Int).Value = (int)this.id;
 | 
						|
                update.Parameters.Add("@nomeCliente", SqlDbType.NVarChar,50).Value = nome;
 | 
						|
                update.Parameters.Add("@rgCliente", SqlDbType.NVarChar,12).Value = rg;
 | 
						|
                update.Parameters.Add("@cpfCliente", SqlDbType.NVarChar,11).Value = cpf;
 | 
						|
                update.Parameters.Add("@telCliente", SqlDbType.NVarChar,10).Value = tel;
 | 
						|
                update.Parameters.Add("@celCliente", SqlDbType.NVarChar,11).Value = cel;
 | 
						|
                update.Parameters.Add("@ruaCliente", SqlDbType.NVarChar,100).Value = rua;
 | 
						|
                update.Parameters.Add("@numeroCliente", SqlDbType.NVarChar,4).Value = num;
 | 
						|
                update.Parameters.Add("@cidadeCliente", SqlDbType.NVarChar,30).Value = cidade;
 | 
						|
                update.Parameters.Add("@statusCliente", SqlDbType.NVarChar,10).Value = STATUS_PESSOA;
 | 
						|
 | 
						|
                update.Prepare();
 | 
						|
                update.ExecuteNonQuery();
 | 
						|
 | 
						|
                con.Close();
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        public override bool Remove(int id)
 | 
						|
        {
 | 
						|
            try
 | 
						|
            {
 | 
						|
                con.Open();
 | 
						|
                delete = new SqlCommand(
 | 
						|
                    "UPDATE tbCliente " +
 | 
						|
                    "SET statusCliente = 'DESATIVADO' " +
 | 
						|
                    "WHERE idCliente = @idCliente", con
 | 
						|
                    );
 | 
						|
                delete.Parameters.Add("@idCliente", SqlDbType.Int).Value = id;
 | 
						|
                delete.Prepare();
 | 
						|
                delete.ExecuteNonQuery();
 | 
						|
                con.Close();
 | 
						|
            }
 | 
						|
            catch (SqlException)
 | 
						|
            {
 | 
						|
                throw new Exception();
 | 
						|
            }
 | 
						|
            return true;
 | 
						|
        }
 | 
						|
 | 
						|
    }
 | 
						|
}
 |