示例#1
0
        public static List <FacturasEntity> GetAllQuery(string pConnection, string pQuery)
        {
            List <FacturasEntity> lReturnList = new List <FacturasEntity>();

            using (SqlConnection lConnection = new SqlConnection(pConnection))
            {
                using (SqlDataAdapter lDataAdapter = new SqlDataAdapter(pQuery, lConnection))
                {
                    lDataAdapter.SelectCommand.CommandType = CommandType.Text;
                    DataTable lDataTable = new DataTable();
                    lDataAdapter.Fill(lDataTable);
                    if (lDataTable != null && lDataTable.Rows.Count > 0)
                    {
                        foreach (DataRow lRow in lDataTable.Rows)
                        {
                            FacturasEntity lFacturas = new FacturasEntity();
                            lFacturas.id         = Convert.ToString(lRow["id"]);
                            lFacturas.num        = Convert.ToInt32(lRow["num"]);
                            lFacturas.serie      = Convert.ToString(lRow["serie"]);
                            lFacturas.fecha      = Convert.ToDateTime(lRow["fecha"]);
                            lFacturas.id_cliente = Convert.ToInt32(lRow["id_cliente"]);
                            lReturnList.Add(lFacturas);
                        }
                    }
                }
            }
            return(lReturnList);
        }
示例#2
0
 public static FacturasEntity GetSingle(string pConnection, FacturasEntity pFacturas)
 {
     using (SqlConnection lConnection = new SqlConnection(pConnection))
     {
         using (SqlDataAdapter lDataAdapter = new SqlDataAdapter("SELECT TOP 1 * FROM tb_facturas WHERE id=@id", lConnection))
         {
             lDataAdapter.SelectCommand.CommandType = CommandType.Text;
             lDataAdapter.SelectCommand.Parameters.AddWithValue("@id", pFacturas.id);
             DataTable lDataTable = new DataTable();
             lDataAdapter.Fill(lDataTable);
             if (lDataTable != null && lDataTable.Rows.Count > 0)
             {
                 DataRow        lRow      = lDataTable.Rows[0];
                 FacturasEntity lFacturas = new FacturasEntity();
                 lFacturas.id         = Convert.ToString(lRow["id"]);
                 lFacturas.num        = Convert.ToInt32(lRow["num"]);
                 lFacturas.serie      = Convert.ToString(lRow["serie"]);
                 lFacturas.fecha      = Convert.ToDateTime(lRow["fecha"]);
                 lFacturas.id_cliente = Convert.ToInt32(lRow["id_cliente"]);
                 return(lFacturas);
             }
         }
     }
     return(null);
 }
示例#3
0
        public void Delete(string pConnection)
        {
            FacturasEntity pFacturas = new FacturasEntity();

            pFacturas.id = id;
            FacturasDAL.Delete(pConnection, pFacturas);
        }
示例#4
0
        public void DeleteTransaction(SqlConnection pConnection, SqlTransaction pTransaction)
        {
            FacturasEntity pFacturas = new FacturasEntity();

            pFacturas.id = id;

            FacturasDAL.DeleteTransaction(pConnection, pTransaction, pFacturas);
        }
示例#5
0
        public static bool Exists(string pConnection, string pId)
        {
            FacturasEntity pFacturas = new FacturasEntity();

            pFacturas.id = pId;

            return(FacturasDAL.Exists(pConnection, pFacturas));
        }
示例#6
0
 public FacturasBO(FacturasEntity pFacturas)
 {
     try
     {
         this.FillEntity(pFacturas);
     }
     catch
     {
         this.FillEntity();
     }
 }
示例#7
0
 public static void Delete(string pConnection, FacturasEntity pFacturas)
 {
     using (SqlConnection lConnection = new SqlConnection(pConnection))
     {
         using (SqlCommand lCommand = new SqlCommand("DELETE FROM tb_facturas WHERE id=@id", lConnection))
         {
             lCommand.CommandType = CommandType.Text;
             lCommand.Parameters.AddWithValue("@id", pFacturas.id);
             lConnection.Open();
             lCommand.ExecuteNonQuery();
             lConnection.Close();
         }
     }
 }
示例#8
0
        public FacturasBO(string pConnection, string pId)
        {
            FacturasEntity pFacturas = new FacturasEntity();

            pFacturas.id = pId;

            try
            {
                this.FillEntity(FacturasDAL.GetSingle(pConnection, pFacturas));
            }
            catch (Exception e)
            {
                this.FillEntity();
            }
        }
示例#9
0
 private void FillEntity(FacturasEntity pFacturas)
 {
     try
     {
         id         = pFacturas.id;
         num        = pFacturas.num;
         serie      = pFacturas.serie;
         fecha      = pFacturas.fecha;
         id_cliente = pFacturas.id_cliente;
         IsNew      = false;
     }
     catch
     {
         this.FillEntity();
     }
 }
示例#10
0
 public static void Add(string pConnection, FacturasEntity pFacturas)
 {
     using (SqlConnection lConnection = new SqlConnection(pConnection))
     {
         using (SqlCommand lCommand = new SqlCommand("INSERT INTO tb_facturas (num,serie,fecha,id_cliente) VALUES (@num,@serie,@fecha,@id_cliente)", lConnection))
         {
             lCommand.CommandType = CommandType.Text;
             lCommand.Parameters.AddWithValue("@num", pFacturas.num);
             lCommand.Parameters.AddWithValue("@serie", pFacturas.serie);
             lCommand.Parameters.AddWithValue("@fecha", pFacturas.fecha);
             lCommand.Parameters.AddWithValue("@id_cliente", pFacturas.id_cliente);
             lConnection.Open();
             lCommand.ExecuteNonQuery();
             lConnection.Close();
         }
     }
 }
示例#11
0
 public static void Update(string pConnection, FacturasEntity pFacturas)
 {
     using (SqlConnection lConnection = new SqlConnection(pConnection))
     {
         using (SqlCommand lCommand = new SqlCommand("UPDATE tb_facturas SET num=@num,serie=@serie,fecha=@fecha,id_cliente=@id_cliente WHERE id=@id", lConnection))
         {
             lCommand.CommandType = CommandType.Text;
             lCommand.Parameters.AddWithValue("@id", pFacturas.id);
             lCommand.Parameters.AddWithValue("@num", pFacturas.num);
             lCommand.Parameters.AddWithValue("@serie", pFacturas.serie);
             lCommand.Parameters.AddWithValue("@fecha", pFacturas.fecha);
             lCommand.Parameters.AddWithValue("@id_cliente", pFacturas.id_cliente);
             lConnection.Open();
             lCommand.ExecuteNonQuery();
             lConnection.Close();
         }
     }
 }
示例#12
0
        public void Save(string pConnection)
        {
            FacturasEntity pFacturas = new FacturasEntity();

            pFacturas.id         = id;
            pFacturas.num        = num;
            pFacturas.fecha      = fecha;
            pFacturas.serie      = serie;
            pFacturas.id_cliente = id_cliente;
            if (IsNew == false)
            {
                FacturasDAL.Update(pConnection, pFacturas);
            }
            else
            {
                FacturasDAL.Add(pConnection, pFacturas);
            }
        }
示例#13
0
        public void SaveTransaction(SqlConnection pConnection, SqlTransaction pTransaction)
        {
            FacturasEntity pFacturas = new FacturasEntity();

            pFacturas.id         = id;
            pFacturas.num        = num;
            pFacturas.serie      = serie;
            pFacturas.fecha      = fecha;
            pFacturas.id_cliente = id_cliente;

            if (IsNew == false)
            {
                FacturasDAL.UpdateTransaction(pConnection, pTransaction, pFacturas);
            }
            else
            {
                FacturasDAL.AddTransaction(pConnection, pTransaction, pFacturas);
            }
        }
示例#14
0
        public static bool Exists(string pConnection, FacturasEntity pFacturas)
        {
            bool lExists = false;

            using (SqlConnection lConnection = new SqlConnection(pConnection))
            {
                using (SqlCommand lCommand = new SqlCommand("SELECT COUNT(*) FROM tb_facturas WHERE id=@id", lConnection))
                {
                    lCommand.CommandType = CommandType.Text;
                    lCommand.Parameters.AddWithValue("@id", pFacturas.id);
                    lConnection.Open();
                    object lReturnValue = lCommand.ExecuteScalar();
                    lConnection.Close();
                    if (!object.ReferenceEquals(lReturnValue, DBNull.Value) && lReturnValue != null)
                    {
                        lExists = Convert.ToInt32(lReturnValue) > 0;
                    }
                }
            }

            return(lExists);
        }
示例#15
0
 public static void DeleteTransaction(SqlConnection pConnection, SqlTransaction pTransaction, FacturasEntity pFacturas)
 {
     using (SqlCommand lCommand = new SqlCommand("DELETE FFROM tb_facturas WHERE id=@id", pConnection))
     {
         lCommand.Transaction = pTransaction;
         lCommand.CommandType = CommandType.Text;
         lCommand.Parameters.AddWithValue("@id", pFacturas.id);
         lCommand.ExecuteNonQuery();
     }
 }
示例#16
0
 public static FacturasBO GetSingle(string pConnection, FacturasEntity pFacturas)
 {
     pFacturas = FacturasDAL.GetSingle(pConnection, pFacturas);
     return(new FacturasBO(pFacturas));
 }
示例#17
0
 public static void AddTransaction(SqlConnection pConnection, SqlTransaction pTransaction, FacturasEntity pFacturas)
 {
     using (SqlCommand lCommand = new SqlCommand("INSERT INTO tb_facturas (id,num,serie,fecha,id_cliente) VALUES (@id,@num,@serie,@fecha,@id_cliente)", pConnection))
     {
         lCommand.Transaction = pTransaction;
         lCommand.CommandType = CommandType.Text;
         lCommand.Parameters.AddWithValue("@id", pFacturas.id);
         lCommand.Parameters.AddWithValue("@num", pFacturas.num);
         lCommand.Parameters.AddWithValue("@serie", pFacturas.serie);
         lCommand.Parameters.AddWithValue("@fecha", pFacturas.fecha);
         lCommand.Parameters.AddWithValue("@id_cliente", pFacturas.id_cliente);
         lCommand.ExecuteNonQuery();
     }
 }