Exemplo n.º 1
0
        /// <summary>
        /// Envia los cambios del sy_EmpresasDataset.sy_EmpresasDataTable a la base de datos.
        /// </summary>
        public static void Update(sy_EmpresasDataset.sy_EmpresasDataTable dataTable)
        {
            ApplicationAssert.Check(dataTable != null, "El argumento dataTable no debe ser nulo.", ApplicationAssert.LineNumber);
            ApplicationAssert.Check(dataTable.Rows.Count > 0, "El argumento dataTable debe poseer alguna fila.", ApplicationAssert.LineNumber);

            if (IsValidTable(dataTable))
            {
                mz.erp.dataaccess.sy_Empresas.Update(dataTable);
            }
        }
Exemplo n.º 2
0
        private static bool IsValidTable(sy_EmpresasDataset.sy_EmpresasDataTable dataTable)
        {
            bool ok = true;

            foreach (sy_EmpresasDataset.sy_EmpresasRow row in dataTable.Rows)
            {
                if (row.RowState.Equals(DataRowState.Deleted))
                {
                    row.RowError = "No se puede borrar una empresa";
                    return(false);
                }
                else
                {
                    ok = ok && RowIsValid(row);
                }
            }
            return(ok);
        }
Exemplo n.º 3
0
        public virtual DataTable GetList()
        {
            DataSet data = new DataSet();

            SqlCommand     cmd    = new SqlCommand();
            SqlConnection  connec = dbhelper.Connection.GetConnection();
            SqlDataAdapter da     = new SqlDataAdapter();

            cmd.Connection  = connec;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "Exec sp_helpdb";

            da.SelectCommand = cmd;
            da.Fill(data);

            string    metodo = Variables.GetValueString("Sistema.BasesDeDatos.MetodoDeComparacion", "E");
            string    bases  = Variables.GetValueString("Sistema.BasesDeDatos");
            ArrayList arrayBases;

            arrayBases = mz.erp.systemframework.Util.Parse(bases, ",");

            sy_EmpresasDataset.sy_EmpresasDataTable table = new sy_EmpresasDataset.sy_EmpresasDataTable();
            foreach (DataRow row in data.Tables[0].Rows)
            {
                string nombre = row["Name"].ToString();
                if (((metodo.Equals("E")) && (!arrayBases.Contains(nombre))) ||
                    ((metodo.Equals("I")) && (arrayBases.Contains(nombre))))
                {
                    sy_EmpresasDataset.sy_EmpresasRow r = table.Newsy_EmpresasRow();
                    r.Descripcion        = string.Empty;
                    r.Conexion           = string.Empty;
                    r.BaseDeDatos        = nombre;
                    r.Usuario            = string.Empty;
                    r.Password           = string.Empty;
                    r.IdConexionCreacion = 1;
                    r.FechaCreacion      = Sistema.DateTime.Now;
                    r.IdEmpresa          = Convert.ToInt16(row["dbid"]);
                    table.Rows.Add(r);
                }
            }
            return(table);
        }
Exemplo n.º 4
0
        public static void Update(sy_EmpresasDataset.sy_EmpresasDataTable dataTable, SqlTransaction trx)
        {
            SqlDataAdapter adapter = new SqlDataAdapter();

            adapter.TableMappings.AddRange(
                new System.Data.Common.DataTableMapping[] {
                new System.Data.Common.DataTableMapping("Table", "sy_Empresas",
                                                        new System.Data.Common.DataColumnMapping[] {
                    new System.Data.Common.DataColumnMapping("IdEmpresa", "IdEmpresa"),
                    new System.Data.Common.DataColumnMapping("Descripcion", "Descripcion"),
                    new System.Data.Common.DataColumnMapping("Conexion", "Conexion"),
                    new System.Data.Common.DataColumnMapping("BaseDeDatos", "BaseDeDatos"),
                    new System.Data.Common.DataColumnMapping("Usuario", "Usuario"),
                    new System.Data.Common.DataColumnMapping("Password", "Password"),
                    new System.Data.Common.DataColumnMapping("Activo", "Activo"),
                    new System.Data.Common.DataColumnMapping("FechaCreacion", "FechaCreacion"),
                    new System.Data.Common.DataColumnMapping("IdConexionCreacion", "IdConexionCreacion"),
                    new System.Data.Common.DataColumnMapping("UltimaModificacion", "UltimaModificacion"),
                    new System.Data.Common.DataColumnMapping("IdConexionUltimaModificacion", "IdConexionUltimaModificacion"),
                    new System.Data.Common.DataColumnMapping("RowId", "RowId")
                }
                                                        )
            }
                );

            SqlCommand sqlCommandUpdate = new SqlCommand("Pr_sy_Empresas_Update", trx.Connection);

            sqlCommandUpdate.Transaction = trx;
            sqlCommandUpdate.CommandType = CommandType.StoredProcedure;
            sqlCommandUpdate.Parameters.Add(new SqlParameter("@IdEmpresa", SqlDbType.BigInt, 0, ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "IdEmpresa", DataRowVersion.Current, null));
            sqlCommandUpdate.Parameters.Add(new SqlParameter("@Descripcion", SqlDbType.VarChar, 100, ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Descripcion", DataRowVersion.Current, null));
            sqlCommandUpdate.Parameters.Add(new SqlParameter("@Conexion", SqlDbType.VarChar, 100, ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Conexion", DataRowVersion.Current, null));
            sqlCommandUpdate.Parameters.Add(new SqlParameter("@BaseDeDatos", SqlDbType.VarChar, 100, ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "BaseDeDatos", DataRowVersion.Current, null));
            sqlCommandUpdate.Parameters.Add(new SqlParameter("@Usuario", SqlDbType.VarChar, 250, ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Usuario", DataRowVersion.Current, null));
            sqlCommandUpdate.Parameters.Add(new SqlParameter("@Password", SqlDbType.VarChar, 250, ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Password", DataRowVersion.Current, null));
            sqlCommandUpdate.Parameters.Add(new SqlParameter("@Activo", SqlDbType.Char, 1, ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Activo", DataRowVersion.Current, null));
            sqlCommandUpdate.Parameters.Add(new SqlParameter("@UltimaModificacion", SqlDbType.Timestamp, 8, ParameterDirection.InputOutput, false, ((System.Byte)(0)), ((System.Byte)(0)), "UltimaModificacion", DataRowVersion.Current, null));
            sqlCommandUpdate.Parameters.Add(new SqlParameter("@IdConexionUltimaModificacion", SqlDbType.BigInt, 0, ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "IdConexionUltimaModificacion", DataRowVersion.Current, null));
            sqlCommandUpdate.Parameters.Add(new SqlParameter("@OldIdEmpresa", SqlDbType.BigInt, 0, ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "IdEmpresa", DataRowVersion.Original, null));

            SqlCommand sqlCommandDelete = new SqlCommand("Pr_sy_Empresas_Delete", trx.Connection);

            sqlCommandDelete.Transaction = trx;
            sqlCommandDelete.CommandType = CommandType.StoredProcedure;
            sqlCommandDelete.Parameters.Add(new SqlParameter("@IdEmpresa", SqlDbType.BigInt, 0, ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "IdEmpresa", DataRowVersion.Original, null));
            sqlCommandDelete.Parameters.Add(new SqlParameter("@UltimaModificacion", SqlDbType.Timestamp, 8, ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "UltimaModificacion", DataRowVersion.Original, null));

            SqlCommand sqlCommandInsert = new SqlCommand("Pr_sy_Empresas_Insert", trx.Connection);

            sqlCommandInsert.Transaction = trx;
            sqlCommandInsert.CommandType = CommandType.StoredProcedure;
            sqlCommandInsert.Parameters.Add(new SqlParameter("@Descripcion", SqlDbType.VarChar, 100, ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Descripcion", DataRowVersion.Current, null));
            sqlCommandInsert.Parameters.Add(new SqlParameter("@Conexion", SqlDbType.VarChar, 100, ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Conexion", DataRowVersion.Current, null));
            sqlCommandInsert.Parameters.Add(new SqlParameter("@BaseDeDatos", SqlDbType.VarChar, 100, ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "BaseDeDatos", DataRowVersion.Current, null));
            sqlCommandInsert.Parameters.Add(new SqlParameter("@Usuario", SqlDbType.VarChar, 250, ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Usuario", DataRowVersion.Current, null));
            sqlCommandInsert.Parameters.Add(new SqlParameter("@Password", SqlDbType.VarChar, 250, ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Password", DataRowVersion.Current, null));
            sqlCommandInsert.Parameters.Add(new SqlParameter("@Activo", SqlDbType.Char, 1, ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Activo", DataRowVersion.Current, null));
            sqlCommandInsert.Parameters.Add(new SqlParameter("@FechaCreacion", SqlDbType.DateTime, 0, ParameterDirection.InputOutput, false, ((System.Byte)(0)), ((System.Byte)(0)), "FechaCreacion", DataRowVersion.Current, null));
            sqlCommandInsert.Parameters.Add(new SqlParameter("@IdConexionCreacion", SqlDbType.BigInt, 0, ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "IdConexionCreacion", DataRowVersion.Current, null));
            sqlCommandInsert.Parameters.Add(new SqlParameter("@IdEmpresa", SqlDbType.BigInt, 0, ParameterDirection.InputOutput, false, ((System.Byte)(0)), ((System.Byte)(0)), "IdEmpresa", DataRowVersion.Current, null));

            adapter.UpdateCommand = sqlCommandUpdate;
            adapter.DeleteCommand = sqlCommandDelete;
            adapter.InsertCommand = sqlCommandInsert;
            adapter.Update(dataTable);
        }