Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Data;
- using System.Data.SqlClient;
- namespace Seguros_Sociales
- {
- public class SelectBD
- {
- DataSet m_Dataset;
- SqlDataAdapter m_DataAdapter;
- DataRow m_dr;
- private int m_indice;
- private int m_PageSize;
- public SelectBD()
- {
- m_Dataset = null;
- m_dr = null;
- m_indice = 0;
- m_PageSize = 0;
- }
- public SelectBD(SqlConnection conex, string SQL)
- : this()
- {
- Open(conex, SQL);
- }
- public SelectBD(SqlConnection conex, string SQL, string tabla)
- : this()
- {
- Open(conex, SQL, tabla);
- }
- ~SelectBD()
- {
- if (m_Dataset != null)
- m_Dataset.Clear();
- m_Dataset = null;
- }
- public int PageSize
- {
- get
- {
- return m_PageSize;
- }
- set
- {
- m_PageSize = value;
- }
- }
- public bool Open(SqlConnection conex, string SQL)
- {
- return this.Open(conex, SQL, "");
- }
- public bool Open(SqlConnection conex, string SQL, string tabla)
- {
- m_Dataset = new DataSet();
- m_DataAdapter = new SqlDataAdapter(SQL, conex);
- SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(m_DataAdapter);
- if (tabla != "") // si llega el nombre de una tabla
- m_DataAdapter.Fill(m_Dataset, tabla);
- else
- m_DataAdapter.Fill(m_Dataset);
- if (m_Dataset == null)
- return false;
- if (m_Dataset.Tables.Count == 0)
- m_indice = 0;
- m_indice = 1;
- return true;
- }
- public object Campo(string indice)
- {
- return m_Dataset.Tables[0].Rows[m_indice - 1][indice];
- }
- public string CampoString(string indice)
- {
- return Campo(indice).Equals(DBNull.Value) ? "" : Campo(indice).ToString();
- }
- public DataRow GetCurrentDataRow()
- {
- return m_Dataset.Tables[0].Rows[m_indice - 1];
- }
- public object Campo(int indice)
- {
- return m_Dataset.Tables[0].Rows[m_indice - 1][indice];
- }
- public string CampoString(int indice)
- {
- return Campo(indice).Equals(DBNull.Value) ? "" : Campo(indice).ToString();
- }
- public void NuevoRegistro(string tabla)
- {
- m_dr = m_Dataset.Tables[tabla].NewRow();
- }
- public void InsertaRegistro(string tabla)
- {
- m_Dataset.Tables[tabla].Rows.Add(m_dr);
- m_DataAdapter.Update(m_Dataset, tabla);
- m_Dataset.AcceptChanges();
- m_dr = null;
- }
- public void SetCampo(string indice, object valor)
- {
- if (m_dr != null)
- m_dr[indice] = valor;
- else
- m_Dataset.Tables[0].Rows[m_indice - 1][indice] = valor;
- }
- public void SetCampo(int indice, object valor)
- {
- if (m_dr != null)
- m_dr[indice] = valor;
- else
- m_Dataset.Tables[0].Rows[m_indice][indice] = valor;
- }
- public void SetCampo(int indice, byte[] valor)
- {
- if (m_dr != null)
- m_dr[indice] = valor;
- else
- m_Dataset.Tables[0].Rows[m_indice][indice] = valor;
- }
- public void AcceptChanges()
- {
- m_DataAdapter.Update(m_Dataset);
- }
- public void AcceptChanges(string tabla)
- {
- m_DataAdapter.Update(m_Dataset, tabla);
- }
- public void MoveFirst()
- {
- m_indice = 1;
- }
- public void MoveLast()
- {
- m_indice = m_Dataset.Tables[0].Rows.Count;
- }
- public void MoveNext()
- {
- if (!EOF)
- m_indice = m_indice + 1;
- }
- public bool EOF
- {
- get
- {
- if (m_Dataset.Tables[0].Rows.Count <= 0)
- return true;
- if (m_indice > m_Dataset.Tables[0].Rows.Count)
- return true;
- return false;
- }
- }
- public int Count
- {
- get
- {
- return m_Dataset.Tables[0].Rows.Count;
- }
- }
- public int PageCount
- {
- get
- {
- if (m_PageSize > 0)
- return (Count / m_PageSize) + (Count % m_PageSize > 0 ? 1 : 0);
- return Count;
- }
- }
- public int AbsolutePage
- {
- get
- {
- if (m_PageSize > 0)
- return (m_indice / m_PageSize) + 1;
- return 1;
- }
- set
- {
- if (value <= 0)
- m_indice = 0;
- else if (value > Count)
- m_indice = (int)Count;
- else
- {
- if (m_PageSize > 0)
- m_indice = (m_PageSize * (value - 1)) + 1;
- else
- m_indice = 1;
- }
- }
- }
- public SqlDataAdapter DataAdapter
- {
- get
- {
- return m_DataAdapter;
- }
- }
- public DataSet DataSet
- {
- get
- {
- return m_Dataset;
- }
- }
- public DataTable DataTable
- {
- get
- {
- return m_Dataset.Tables[0];
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement