Ejemplo n.º 1
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            if (!ValidarDatos()) return;

            try
            {
                if (DataExtensionHead == null)
                {
                    DataExtensionHead = new DataExtensionHead();
                }

                DataExtensionHead.Nombre = txtNombre.Text;
                DataExtensionHead.Descripcion = txtDescripcion.Text;
                DataExtensionHead.EsUsadaComoBase = chkIsSendable.Checked;
                DataExtensionHead.NombreBaseFuente = txtNombreBaseFuente.Text;
                DataExtensionHead.NombreBaseMostrar = txtNombreBaseMostrar.Text;
                DataExtensionHead.Estado = Convert.ToInt32(cmbEstado.SelectedValue);
                DataExtensionHead.DataExtensionDetalleList = new List<DataExtensionDetalle>();

                foreach (DataGridViewRow row in dgvDataExtensionDetalle.DataGridView.Rows)
                {
                    if (!ValidarDetalle(row.Index)) continue;

                    int idDetalle = 0;
                    if (row.Cells[(int)TipoColumnaDEDetalle.Id].Value != null)
                        idDetalle = Convert.ToInt32(row.Cells[(int)TipoColumnaDEDetalle.Id].Value.ToString());

                    var campo = row.Cells[(int)TipoColumnaDEDetalle.Campo].Value.ToString();
                    var tipo = (int)Enum.Parse(typeof(TipoDato), row.Cells[(int)TipoColumnaDEDetalle.Tipo].Value.ToString());
                    var tipoNombre = row.Cells[(int)TipoColumnaDEDetalle.Tipo].Value.ToString();
                    var tamanio = Convert.ToInt32(row.Cells[(int)TipoColumnaDEDetalle.Tamanio].Value);
                    var esClave = Convert.ToBoolean(row.Cells[(int)TipoColumnaDEDetalle.EsClave].Value);
                    var esNulo = Convert.ToBoolean(row.Cells[(int)TipoColumnaDEDetalle.EsNulo].Value);
                    var porDefecto  = row.Cells[(int)TipoColumnaDEDetalle.PorDefecto].Value;
                    var estado = (int)Enum.Parse(typeof(TipoEstado), row.Cells[(int)TipoColumnaDEDetalle.Estado].Value.ToString());
                    var estadoNombre = row.Cells[(int)TipoColumnaDEDetalle.Estado].Value.ToString();

                    DataExtensionHead.DataExtensionDetalleList.Add(new DataExtensionDetalle
                    {
                        Id = idDetalle,
                        Campo = campo,
                        Tipo = tipo,
                        TipoNombre = tipoNombre,
                        Tamanio = tamanio,
                        EsClavePrimaria = esClave,
                        EsNulo = esNulo,
                        ValorPorDefecto = porDefecto.ToString(),
                        Estado = estado,
                        EstadoNombre = estadoNombre
                    });
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Constantes.Mensaje, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            this.Close();
        }
Ejemplo n.º 2
0
        public Response AddColumns(DataExtensionHead dataExtensionHead)
        {
            var response = new Response { Success = true, Warning = false };
            try
            {
                var dataExtensionBase = new ET_DataExtension
                {
                    AuthStub = conexion.ETCliente,
                    Name = dataExtensionHead.Nombre,
                    CustomerKey = dataExtensionHead.Nombre
                };

                List<ET_DataExtensionColumn> fields = new List<ET_DataExtensionColumn>();

                foreach (var detalle in dataExtensionHead.DataExtensionDetalleList)
                {
                    //Create the field
                    ET_DataExtensionColumn field = new ET_DataExtensionColumn();
                    field.Name = detalle.Campo;
                    field.FieldType = GetTypeDataExtension(detalle.Tipo);
                    field.FieldTypeSpecified = true;
                    field.IsRequired = !detalle.EsNulo;
                    field.IsRequiredSpecified = !detalle.EsNulo;
                    field.IsPrimaryKey = detalle.EsClavePrimaria;
                    field.IsPrimaryKeySpecified = detalle.EsClavePrimaria;
                    if (field.IsPrimaryKey || detalle.Tamanio > 0)
                    {
                        field.MaxLength = detalle.Tamanio;
                        field.MaxLengthSpecified = true;
                    }
                    fields.Add(field);
                }

                dataExtensionBase.Columns = fields.ToArray();

                try
                {
                    var patchResponse = dataExtensionBase.Patch();
                    response.Success = patchResponse.Status;
                    response.Message = patchResponse.Message;
                    response.Code = patchResponse.Code;
                    response.Data = patchResponse.Results;
                }
                catch (Exception exCreate)
                {
                    response.Success = false;
                    response.Message = exCreate.Message;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return response;
        }
        public Response AddColumns(DataExtensionHead dataExtensionHead)
        {
            var jsonResponse = new Response { Success = false };
            DataExtensionHelper deHelper = new DataExtensionHelper();

            try
            {
                jsonResponse = deHelper.AddColumns(dataExtensionHead);
            }
            catch (Exception ex)
            {
                LogError(ex);
            }

            return jsonResponse;
        }
Ejemplo n.º 4
0
        public Response Create(DataExtensionHead dataExtensionHead)
        {
            var response = new Response { Success = true, Warning = false };
            try
            {
                var dataExtensionBase = new ET_DataExtension
                {
                    AuthStub = conexion.ETCliente,
                    Name = dataExtensionHead.Nombre,
                    CustomerKey = dataExtensionHead.Nombre,
                    Description = dataExtensionHead.Descripcion,
                    IsSendable = dataExtensionHead.EsUsadaComoBase,
                    IsSendableSpecified = dataExtensionHead.EsUsadaComoBase
                };

                if (dataExtensionHead.EsUsadaComoBase)
                {
                    //Is this data base table going to house Subscribers?
                    //de.IsSendable = true;
                    //de.IsSendableSpecified = true;
                    dataExtensionBase.IsSendable = dataExtensionHead.EsUsadaComoBase;
                    dataExtensionBase.IsSendableSpecified = dataExtensionHead.EsUsadaComoBase;

                    //The Name of the Column in the DE to map to ET
                    dataExtensionBase.SendableDataExtensionField = new DataExtensionField();
                    dataExtensionBase.SendableDataExtensionField.FieldType = DataExtensionFieldType.Text;
                    dataExtensionBase.SendableDataExtensionField.Name = dataExtensionHead.NombreBaseFuente;
                    //The Name of the Attribute in ET to Send to
                    dataExtensionBase.SendableSubscriberField = new FuelSDK.Attribute();
                    dataExtensionBase.SendableSubscriberField.Name = dataExtensionHead.NombreBaseMostrar;//If Subscriber Key is turned on this must be Subscriber Key
                }

                List<ET_DataExtensionColumn> fields = new List<ET_DataExtensionColumn>();

                foreach (var detalle in dataExtensionHead.DataExtensionDetalleList)
                {
                    //Create the field
                    ET_DataExtensionColumn field = new ET_DataExtensionColumn();
                    field.Name = detalle.Campo;
                    field.FieldType = GetTypeDataExtension(detalle.Tipo);
                    field.FieldTypeSpecified = true;
                    field.IsRequired = !detalle.EsNulo;
                    field.IsRequiredSpecified = !detalle.EsNulo;
                    field.IsPrimaryKey = detalle.EsClavePrimaria;
                    field.IsPrimaryKeySpecified = detalle.EsClavePrimaria;
                    if (field.IsPrimaryKey || detalle.Tamanio > 0)
                    {
                        field.MaxLength = detalle.Tamanio;
                        field.MaxLengthSpecified = true;
                    }
                    fields.Add(field);
                }

                dataExtensionBase.Columns = fields.ToArray();

                try
                {
                    var postResponse = dataExtensionBase.Post();
                    response.Success = postResponse.Status;
                    response.Message = postResponse.Message;
                    response.Code = postResponse.Code;
                    response.Data = postResponse.Results;
                }
                catch (Exception exCreate)
                {
                    response.Success = false;
                    response.Message = exCreate.Message;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return response;
        }
Ejemplo n.º 5
0
        private void CargarDatos(DataExtensionHead dataExtensionHead)
        {
            if (dataExtensionHead != null)
            {
                txtNombre.Text = dataExtensionHead.Nombre;
                txtDescripcion.Text = DataExtensionHead.Descripcion;
                chkIsSendable.Checked = dataExtensionHead.EsUsadaComoBase;
                txtNombreBaseFuente.Text = dataExtensionHead.NombreBaseFuente;
                txtNombreBaseMostrar.Text = dataExtensionHead.NombreBaseMostrar;
                cmbEstado.SelectedValue = dataExtensionHead.Estado;

                dgvDataExtensionDetalle.DataGridView.Rows.Clear();

                foreach (var detalle in dataExtensionHead.DataExtensionDetalleList)
                {
                    var index = dgvDataExtensionDetalle.DataGridView.Rows.Add();
                    dgvDataExtensionDetalle.DataGridView.Rows[index].Cells[(int)TipoColumnaDEDetalle.Id].Value = detalle.Id;
                    dgvDataExtensionDetalle.DataGridView.Rows[index].Cells[(int)TipoColumnaDEDetalle.Campo].Value = detalle.Campo;
                    dgvDataExtensionDetalle.DataGridView.Rows[index].Cells[(int)TipoColumnaDEDetalle.Tipo].Value = detalle.TipoNombre;
                    dgvDataExtensionDetalle.DataGridView.Rows[index].Cells[(int)TipoColumnaDEDetalle.Tamanio].Value = detalle.Tamanio;
                    dgvDataExtensionDetalle.DataGridView.Rows[index].Cells[(int)TipoColumnaDEDetalle.EsClave].Value = detalle.EsClavePrimaria;
                    dgvDataExtensionDetalle.DataGridView.Rows[index].Cells[(int)TipoColumnaDEDetalle.EsNulo].Value = detalle.EsNulo;
                    dgvDataExtensionDetalle.DataGridView.Rows[index].Cells[(int)TipoColumnaDEDetalle.PorDefecto].Value = detalle.ValorPorDefecto;
                    dgvDataExtensionDetalle.DataGridView.Rows[index].Cells[(int)TipoColumnaDEDetalle.Estado].Value = detalle.EstadoNombre;
                }
            }
        }
Ejemplo n.º 6
0
 private void LoadDataExtension(DataExtensionHead dataExtension)
 {
     this.dataExtensionIDLabel.Text = dataExtension.Id.ToString();
     this.txtNombre.Text = dataExtension.Nombre;
     this.txtDescripcion.Text = dataExtension.Descripcion;
     this.chkIsSendable.Checked = dataExtension.EsUsadaComoBase;
     this.cmbEstado.SelectedValue = dataExtension.Estado;
     this.txtNombreBaseFuente.Text = dataExtension.NombreBaseFuente;
     this.txtNombreBaseMostrar.Text = dataExtension.NombreBaseMostrar;
 }
Ejemplo n.º 7
0
        public Response Crear(DataExtensionHead dataExtensionHead)
        {
            var response = new Response { Success = true, Warning = false };
            try
            {
                //Create DataExtension object [Subscribers > Data Extensions > Data Extensions]
                DataExtension de = new DataExtension();
                de.CustomerKey = dataExtensionHead.Nombre;
                de.Name = dataExtensionHead.Nombre;
                de.Description = dataExtensionHead.Descripcion;

                //Is this data base table going to house Subscribers?
                if (dataExtensionHead.EsUsadaComoBase)
                {
                    //Is this data base table going to house Subscribers?
                    //de.IsSendable = true;
                    //de.IsSendableSpecified = true;
                    de.IsSendable = dataExtensionHead.EsUsadaComoBase;
                    de.IsSendableSpecified = dataExtensionHead.EsUsadaComoBase;

                    //The Name of the Column in the DE to map to ET
                    de.SendableDataExtensionField = new DataExtensionField();
                    de.SendableDataExtensionField.FieldType = DataExtensionFieldType.Text;
                    de.SendableDataExtensionField.Name = dataExtensionHead.NombreBaseFuente;
                    //The Name of the Attribute in ET to Send to
                    de.SendableSubscriberField = new PartnerAPI.Attribute();
                    de.SendableSubscriberField.Name = dataExtensionHead.NombreBaseMostrar;//If Subscriber Key is turned on this must be Subscriber Key
                }

                List<DataExtensionField> fields = new List<DataExtensionField>();

                foreach (var detalle in dataExtensionHead.DataExtensionDetalleList)
                {
                    //Create the field
                    DataExtensionField field = new DataExtensionField();
                    field.Name = detalle.Campo;
                    field.FieldType = GetTypeDataExtension(detalle.Tipo);
                    field.FieldTypeSpecified = true;
                    field.IsRequired = !detalle.EsNulo;
                    field.IsRequiredSpecified = !detalle.EsNulo;
                    field.IsPrimaryKey = detalle.EsClavePrimaria;
                    field.IsPrimaryKeySpecified = detalle.EsClavePrimaria;
                    if (field.IsPrimaryKey || detalle.Tamanio > 0)
                    {
                        field.MaxLength = detalle.Tamanio;
                        field.MaxLengthSpecified = true;
                    }
                    fields.Add(field);
                }

                de.Fields = fields.ToArray();

                try
                {
                    string cRequestID = String.Empty;
                    string cStatus = String.Empty;

                    //Call the Create method on the Subscriber object
                    CreateResult[] cResults = conexion.ETCliente.Create(new CreateOptions(), new APIObject[] { de }, out cRequestID, out cStatus);

                    if (Constantes.Error == cStatus)
                    {
                        response.Success = false;
                        foreach (CreateResult cr in cResults)
                        {
                            response.Message += "DataExtensionKey: " + dataExtensionHead.Nombre + " | Status Message: " + cr.StatusMessage + "| ";
                        }
                    }

                }
                catch (Exception exCreate)
                {
                    response.Success = false;
                    response.Message = exCreate.Message;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return response;
        }