1548 lines
56 KiB
C#
1548 lines
56 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using System.IO;
|
|
using System.Data;
|
|
|
|
using Extensiones;
|
|
|
|
public partial class CRM_EmpresaCRM : ClsPaginas
|
|
{
|
|
#region "PROPIEDADES"
|
|
private int CveEmpresaCRM
|
|
{
|
|
get
|
|
{
|
|
return ViewState["CveEmpresaCRM"].ToString().ToEntero();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["CveEmpresaCRM"] = value;
|
|
}
|
|
}
|
|
|
|
private int CveEncuestaCRM
|
|
{
|
|
get
|
|
{
|
|
return ViewState["CveEncuestaCRM"].ToString().ToEntero();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["CveEncuestaCRM"] = value;
|
|
}
|
|
}
|
|
|
|
private int CveEncuestaAplicada
|
|
{
|
|
get
|
|
{
|
|
return ViewState["CveEncuestaAplicada"].ToString().ToEntero();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["CveEncuestaAplicada"] = value;
|
|
}
|
|
}
|
|
|
|
private int CveContactoEditado
|
|
{
|
|
get
|
|
{
|
|
return ViewState["CveContactoEditado"].ToString().ToEntero();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["CveContactoEditado"] = value;
|
|
}
|
|
}
|
|
|
|
private Boolean EsEditar
|
|
{
|
|
get
|
|
{
|
|
return Convert.ToBoolean(ViewState["EsEditar"].ToString());
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["EsEditar"] = value;
|
|
}
|
|
}
|
|
|
|
private Boolean EsEditarContacto
|
|
{
|
|
get
|
|
{
|
|
return Convert.ToBoolean(ViewState["EsEditarContacto"].ToString());
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["EsEditarContacto"] = value;
|
|
}
|
|
}
|
|
|
|
private DataTable DTContactos
|
|
{
|
|
get
|
|
{
|
|
return (DataTable)ViewState["DTContactos"];
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["DTContactos"] = value;
|
|
}
|
|
}
|
|
|
|
private DataTable DTRespuestasDatosTecnicos
|
|
{
|
|
get
|
|
{
|
|
return (DataTable)ViewState["DTRespuestasDatosTecnicos"];
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["DTRespuestasDatosTecnicos"] = value;
|
|
}
|
|
}
|
|
|
|
private int CveVendedor
|
|
{
|
|
get
|
|
{
|
|
return ViewState["CveVendedor"].ToString().ToEntero();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["CveVendedor"] = value;
|
|
}
|
|
}
|
|
|
|
private int CveSubProyecto
|
|
{
|
|
get
|
|
{
|
|
return ViewState["CveSubProyecto"].ToString().ToEntero();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["CveSubProyecto"] = value;
|
|
}
|
|
}
|
|
|
|
private DataTable TempDTContactos
|
|
{
|
|
get
|
|
{
|
|
return (DataTable)ViewState["TempDTContactos"];
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["TempDTContactos"] = value;
|
|
}
|
|
}
|
|
|
|
private int IndexDTContacto
|
|
{
|
|
get
|
|
{
|
|
return ViewState["IndexDTContacto"].ToString().ToEntero();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["IndexDTContacto"] = value;
|
|
}
|
|
}
|
|
private int CveCliente
|
|
{
|
|
get
|
|
{
|
|
return ViewState["CveCliente"].ToString().ToEntero();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["CveCliente"] = value;
|
|
}
|
|
}
|
|
private Boolean CreoCliente
|
|
{
|
|
get
|
|
{
|
|
return Convert.ToBoolean(ViewState["CreoCliente"].ToString());
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["CreoCliente"] = value;
|
|
}
|
|
}
|
|
|
|
private DataTable DtMedioCaptacion
|
|
{
|
|
get
|
|
{
|
|
return (DataTable)ViewState["DtMedioCaptacion"];
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["DtMedioCaptacion"] = value;
|
|
}
|
|
}
|
|
|
|
private DataTable DtProbabilidadAcercamiento
|
|
{
|
|
get
|
|
{
|
|
return (DataTable)ViewState["DtProbabilidadAcercamiento"];
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["DtProbabilidadAcercamiento"] = value;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
CreoCliente = false;
|
|
RecuperaCve();
|
|
CargaTipoProceso();
|
|
//CargaMetodosCaptacion();
|
|
CargaVendedores();
|
|
CargaSucursales();
|
|
CargarTiposEventos();
|
|
LimitaFechasAcercamiento();
|
|
CargaDatos();
|
|
if (CveEncuestaCRM > 0)
|
|
{
|
|
CargaDatosTecnicos();
|
|
}
|
|
VerificaPermisos();
|
|
}
|
|
}
|
|
|
|
#region "GUARDAR EMPRESA"
|
|
|
|
protected void BtnGuardarEmpresa_Click(object sender, EventArgs e)
|
|
{
|
|
ClsCRM ObjCRM = new ClsCRM();
|
|
ClsOIEventos ObjBitacora = new ClsOIEventos(ObjCRM.IniciaTransacSQL());
|
|
ClsEncuestas ObjDatosTecnicos = new ClsEncuestas(ObjCRM.IniciaTransacSQL());
|
|
|
|
Boolean HuboError = false;
|
|
|
|
String NombreEmpresa = TxtNombreEmpresa.Text;
|
|
String RFC = TxtRFC.Text;
|
|
String Correo = TxtCorreoEmpresaCRM.Text.Trim();
|
|
|
|
String MedioCaptacion = DdlMedioCaptacion.SelectedValue == "-1" ? "" : DdlMedioCaptacion.SelectedItem.Text;
|
|
String Vendedor = DdlVendedorAsignado.SelectedValue == "-1" ? "" : DdlVendedorAsignado.SelectedItem.Text;
|
|
|
|
int CveMedioCaptacion = DdlMedioCaptacion.SelectedValue.ToEntero();
|
|
int CveVendedorActualizar = DdlVendedorAsignado.SelectedValue.ToEntero();
|
|
int CveSubProyecto = DdlSucursales.SelectedValue.ToEntero();
|
|
|
|
if (!EsEditar)
|
|
{
|
|
//DATOS TECNICOS - si la empresa usa datos tecnicos
|
|
if (CveEncuestaCRM > 0)
|
|
{
|
|
CveEncuestaAplicada = GuardaDatosTecnicos(ObjDatosTecnicos);
|
|
}
|
|
|
|
//SI CVEENCUESTAAPLICADA = 0 HUBO ERROR
|
|
if ((CveEncuestaAplicada != 0))
|
|
{
|
|
string Mensaje = "";
|
|
//DATOS GENERALES
|
|
CveEmpresaCRM = ObjCRM.AddEmpresaCRM(NombreEmpresa, RFC, CveMedioCaptacion, UsuarioActual.CveEmpresa, UsuarioActual.CveUsuario, CveEncuestaAplicada, CveVendedorActualizar, CveSubProyecto, Correo);
|
|
|
|
if (CveEmpresaCRM > 0)
|
|
{
|
|
Mensaje = String.Format("Se registró la empresa {0} con datos RFC: {1}, Vendedor: {2}", NombreEmpresa, RFC, Vendedor);
|
|
if (CveMedioCaptacion != -1)
|
|
Mensaje += String.Format(", Medio de Captación: {0}", MedioCaptacion);
|
|
|
|
HuboError = false;
|
|
|
|
if (TempDTContactos.Rows.Count > 0)
|
|
{
|
|
Mensaje += " y Contactos: ";
|
|
// Nombre, TelefonoOficina, Celular, Correo, CveUsuarioIng, FechaIng
|
|
int numContactos = TempDTContactos.Rows.Count;
|
|
int i = 1;
|
|
|
|
foreach (DataRow row in TempDTContactos.Rows)
|
|
{
|
|
if (!ObjCRM.AddContactoEmpresa(row["Nombre"].ToString(), row["TelefonoOficina"].ToString(), row["Celular"].ToString(), row["Correo"].ToString(), CveEmpresaCRM, UsuarioActual.CveUsuario))
|
|
HuboError = true;
|
|
else
|
|
Mensaje += row["Nombre"].ToString() + ((i == numContactos) ? "" : ", ");
|
|
|
|
i++;
|
|
}
|
|
}
|
|
|
|
if (!ObjBitacora.AddEventoBitacora(Mensaje, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveEmpresaCRM: CveEmpresaCRM))
|
|
{
|
|
HuboError = true;
|
|
}else
|
|
{
|
|
string asunto = String.Format("Se registró la empresa {0} con datos RFC: {1}, Vendedor: {2}", NombreEmpresa, RFC, Vendedor);
|
|
mandarCorreo(asunto, Mensaje);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//DATOS TECNICOS - si la empresa usa datos tecnicos
|
|
if (CveEncuestaCRM > 0)
|
|
{
|
|
CveEncuestaAplicada = GuardaDatosTecnicos(ObjDatosTecnicos, CveEncuestaAplicada);
|
|
}
|
|
|
|
if ((CveEncuestaAplicada != 0) && ObjCRM.UpdateEmpresCRM(NombreEmpresa, RFC, CveMedioCaptacion, CveEmpresaCRM, CveVendedorActualizar, UsuarioActual.CveUsuario, CveSubProyecto: CveSubProyecto, Correo: Correo))
|
|
{
|
|
if (!ObjBitacora.AddEventoBitacora(String.Format("Se actualizó la empresa {0} con RFC {1}", NombreEmpresa, RFC), "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveEmpresaCRM: CveEmpresaCRM))
|
|
{
|
|
HuboError = true;
|
|
}else
|
|
{
|
|
string asunto = String.Format("Se actualizó la empresa {0}",NombreEmpresa);
|
|
string mensaje = String.Format("Se actualizó la empresa {0} con RFC {1} por el usuario {2}", NombreEmpresa, RFC,UsuarioActual.Nombre);
|
|
mandarCorreo(asunto, mensaje);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!HuboError)
|
|
{
|
|
ObjCRM.Commit();
|
|
if (!EsEditar)
|
|
Alert(String.Format("La Empresa <b>{0}</b> fue creada correctamente.", NombreEmpresa), ModExtensiones.TipoMensaje.MsgInformacion);
|
|
else
|
|
Alert(String.Format("La Empresa <b>{0}</b> fue actualizada correctamente.", NombreEmpresa), ModExtensiones.TipoMensaje.MsgInformacion);
|
|
}
|
|
else { ObjCRM.RollBack(); }
|
|
|
|
ObjCRM.Dispose();
|
|
ObjBitacora.Dispose();
|
|
ObjDatosTecnicos.Dispose();
|
|
|
|
//RECARGAMOS DATOS GUARDADOS EN BD Y VERIFICAMOS PERMISOS
|
|
CargaDatos();
|
|
VerificaPermisos();
|
|
|
|
if (CveEncuestaCRM > 0)
|
|
{
|
|
CargaDatosTecnicos();
|
|
}
|
|
}
|
|
|
|
protected int GuardaDatosTecnicos(ClsEncuestas ObjDatosTecnicos, int CveEncuestaAplicada = -1)
|
|
{
|
|
int _CveEncuestaAplicada = CveEncuestaAplicada;
|
|
|
|
//NUEVA CAPTURA DE DATOS TECNICOS
|
|
if (!EsEditar)
|
|
{
|
|
if (ObjDatosTecnicos.AddEncuestaAplicada(CveEncuestaCRM, -1, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa))
|
|
{
|
|
DataTable dt;
|
|
_CveEncuestaAplicada = ObjDatosTecnicos.DtResultados.Rows[0][0].ToEntero();
|
|
|
|
foreach (GridViewRow drow in GvDatosTecnicos.Rows)
|
|
{
|
|
int EsOpcion = drow.DataKey("CveTipoPregunta").ToEntero();
|
|
int CvePregunta = drow.DataKey("CvePregunta").ToEntero();
|
|
|
|
int CveRespuesta = -1;
|
|
string Respuesta = "-1";
|
|
|
|
dt = DTRespuestasDatosTecnicos.FiltraParametros(string.Format(" CvePregunta = {0} ", CvePregunta));
|
|
|
|
switch (EsOpcion)
|
|
{
|
|
case 1: // Texto - RESPUESTA BIERTA
|
|
{
|
|
if (dt.Rows.Count == 0) CveRespuesta = -1; else CveRespuesta = dt.FiltroPrimeroValor("CveRespuesta").ToString().ToEntero();
|
|
|
|
Respuesta = drow.FCTextBox("TxtRespuestaDinamica").Text;
|
|
break;
|
|
}
|
|
case 2: // RADIO BUTTON - OPCION MULTIPLE
|
|
{
|
|
CveRespuesta = drow.FCRadioButtonList("RdlRespuestaDinamica").SelectedValue.ToEntero();
|
|
Respuesta = drow.FCRadioButtonList("RdlRespuestaDinamica").SelectedItem.Text;
|
|
break;
|
|
}
|
|
case 3: // DDL - SELECCION
|
|
{
|
|
CveRespuesta = drow.FCDropDownList("DdlRespuestaDinamica").SelectedValue.ToEntero();
|
|
Respuesta = drow.FCDropDownList("DdlRespuestaDinamica").SelectedItem.Text;
|
|
break;
|
|
}
|
|
case 4: // CHECKBOX - SI / NO
|
|
{
|
|
Respuesta = drow.FCCheckBox("ChkRespuestaDinamica").Checked ? "Si" : "No";
|
|
CveRespuesta = -1;
|
|
break;
|
|
}
|
|
case 5: // TEXTBOX - NUMERO
|
|
{
|
|
Respuesta = drow.FCTextBox("TxtRespuestaDinamica").Text;
|
|
break;
|
|
}
|
|
case 6: // MULTILINE - RESPUESTA BIERTA
|
|
{
|
|
if (dt.Rows.Count == 0) CveRespuesta = -1; else CveRespuesta = dt.FiltroPrimeroValor("CveRespuesta").ToString().ToEntero();
|
|
|
|
Respuesta = drow.FCTextBox("TxtRespuestaDinamicaMultilinea").Text;
|
|
break;
|
|
}
|
|
case 7: // FECHA
|
|
{
|
|
if (dt.Rows.Count == 0) CveRespuesta = -1; else CveRespuesta = dt.FiltroPrimeroValor("CveRespuesta").ToString().ToEntero();
|
|
|
|
Respuesta = drow.FCTextBox("TxtRespuestaFechaDinamica").Text;
|
|
break;
|
|
}
|
|
}
|
|
|
|
//CREAMOS REGISTRO DE LOS DATOS TECNICOS
|
|
if (!(ObjDatosTecnicos.AddEncuestaAplicadaDetalle(_CveEncuestaAplicada, CvePregunta, CveRespuesta, Respuesta)))
|
|
{
|
|
//SI HAY ERROR REGRESA 0
|
|
_CveEncuestaAplicada = 0;
|
|
}
|
|
dt.Dispose();
|
|
}
|
|
}
|
|
}
|
|
//ACTULIZACION DE DATOS TECNICOS
|
|
else
|
|
{
|
|
int CveEncuestaAplicadaDetalle = -1;
|
|
int CveRespuesta = -1;
|
|
string Respuesta = "-1";
|
|
Boolean ExisteRegistro = true;
|
|
|
|
foreach (GridViewRow drow in GvDatosTecnicos.Rows)
|
|
{
|
|
int EsOpcion = drow.DataKey("CveTipoPregunta").ToEntero();
|
|
int CvePregunta = drow.DataKey("CvePregunta").ToEntero();
|
|
|
|
CveEncuestaAplicadaDetalle = drow.DataKey("CveEncuestaAplicadaDetalle").ToEntero();
|
|
|
|
ExisteRegistro = CveEncuestaAplicadaDetalle > 0;
|
|
|
|
CveRespuesta = -1;
|
|
Respuesta = "-1";
|
|
|
|
DataTable dt = DTRespuestasDatosTecnicos.FiltraParametros(string.Format(" CvePregunta = {0} ", CvePregunta));
|
|
|
|
switch (EsOpcion)
|
|
{
|
|
case 1: // TEXTO - RESPUESTA BIERTA
|
|
{
|
|
if (dt.Rows.Count == 0) CveRespuesta = -1; else CveRespuesta = dt.FiltroPrimeroValor("CveRespuesta").ToString().ToEntero();
|
|
|
|
Respuesta = drow.FCTextBox("TxtRespuestaDinamica").Text;
|
|
break;
|
|
}
|
|
case 2: // RADIO BUTTON - OPCION MULTIPLE
|
|
{
|
|
CveRespuesta = drow.FCRadioButtonList("RdlRespuestaDinamica").SelectedValue.ToEntero();
|
|
Respuesta = drow.FCRadioButtonList("RdlRespuestaDinamica").SelectedItem.Text;
|
|
break;
|
|
}
|
|
case 3: // DDL - SELECCION
|
|
{
|
|
CveRespuesta = drow.FCDropDownList("DdlRespuestaDinamica").SelectedValue.ToEntero();
|
|
Respuesta = drow.FCDropDownList("DdlRespuestaDinamica").SelectedItem.Text;
|
|
break;
|
|
}
|
|
case 4: // CHECKBOX - SI / NO
|
|
{
|
|
Respuesta = drow.FCCheckBox("ChkRespuestaDinamica").Checked ? "Si" : "No";
|
|
CveRespuesta = -1;
|
|
break;
|
|
}
|
|
|
|
case 5: // TEXTBOX - NUMERO
|
|
{
|
|
Respuesta = drow.FCTextBox("TxtRespuestaDinamica").Text;
|
|
break;
|
|
}
|
|
case 6: // MULTILINE - RESPUESTA BIERTA
|
|
{
|
|
if (dt.Rows.Count == 0) CveRespuesta = -1; else CveRespuesta = dt.FiltroPrimeroValor("CveRespuesta").ToString().ToEntero();
|
|
|
|
Respuesta = drow.FCTextBox("TxtRespuestaDinamicaMultilinea").Text;
|
|
break;
|
|
}
|
|
case 7: // FECHA
|
|
{
|
|
if (dt.Rows.Count == 0) CveRespuesta = -1; else CveRespuesta = dt.FiltroPrimeroValor("CveRespuesta").ToString().ToEntero();
|
|
|
|
Respuesta = drow.FCTextBox("TxtRespuestaFechaDinamica").Text;
|
|
break;
|
|
}
|
|
}
|
|
|
|
//ACTUALIZAMOS LOS DATOS TECNICOS
|
|
if (ExisteRegistro && !(ObjDatosTecnicos.UpdateDatosTecnicosCRM(CveEncuestaAplicadaDetalle, CveEncuestaAplicada, CvePregunta, CveRespuesta, Respuesta)))
|
|
{
|
|
//SI HAY ERROR REGRESA 0
|
|
_CveEncuestaAplicada = 0;
|
|
}
|
|
else if (!ExisteRegistro && !(ObjDatosTecnicos.AddEncuestaAplicadaDetalle(_CveEncuestaAplicada, CvePregunta, CveRespuesta, Respuesta)))
|
|
{
|
|
//SI HAY ERROR REGRESA 0
|
|
_CveEncuestaAplicada = 0;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
// SI REGRESA _CveEncuestaAplicada = 0 HUBO ERROR
|
|
return _CveEncuestaAplicada;
|
|
}
|
|
#endregion
|
|
|
|
#region "CARGA DATOS"
|
|
protected void RecuperaCve()
|
|
{
|
|
if (Request["CveEmpresaCRM"] != null && !Request["CveEmpresaCRM"].ToString().Equals("") && Request["CveEmpresaCRM"].ToEntero() > 0)
|
|
{
|
|
ViewState["CveEmpresaCRM"] = Request["CveEmpresaCRM"];
|
|
//HplAddCotizacion.Visible = true;
|
|
//HplAddCotizacion.NavigateUrl = String.Format("/Ventas/Ventas.aspx?CveEmpresaCRM={0}&Op=Cot", CveEmpresaCRM);
|
|
UpAcciones.Update();
|
|
}
|
|
else
|
|
{
|
|
ViewState["CveEmpresaCRM"] = -1;
|
|
|
|
}
|
|
CveContactoEditado = -1;
|
|
}
|
|
|
|
protected void CargaTipoProceso()
|
|
{
|
|
ClsCRM ObjCRM = new ClsCRM();
|
|
if (ObjCRM.GetTipoProceso(UsuarioActual.CveEmpresa))
|
|
{
|
|
DdlTipoPrceso2.DataSource = ObjCRM.DtResultados;
|
|
}
|
|
DdlTipoPrceso2.DataBind();
|
|
}
|
|
|
|
protected void CargaMetodosCaptacion()
|
|
{
|
|
ClsCRM ObjCRM = new ClsCRM();
|
|
if (ObjCRM.GetMedioCaptacion(UsuarioActual.CveEmpresa, 1))
|
|
{
|
|
DdlMedioCaptacion.DataSource = ObjCRM.DtResultados.FiltraParametros(String.Format("CveTipoProceso = {0}", DdlTipoPrceso2.SelectedValue));
|
|
DdlMedioCaptacion.Items.Insert(0, new ListItem("Seleccione ", "-1"));
|
|
DdlMedioCaptacionAcercamiento.Items.Clear();
|
|
DdlMedioCaptacionAcercamiento.DataSource = ObjCRM.DtResultados;
|
|
DtMedioCaptacion = ObjCRM.DtResultados;
|
|
DdlMedioCaptacionAcercamiento.Items.Insert(0, new ListItem("Seleccione ", "-1"));
|
|
}
|
|
ObjCRM.Dispose();
|
|
DdlMedioCaptacion.DataBind();
|
|
DdlMedioCaptacionAcercamiento.DataBind();
|
|
}
|
|
|
|
protected void CargaVendedores()
|
|
{
|
|
DdlVendedorAsignado.DataSource = get_GlobalDTVendedores(UsuarioActual.CveEmpresa);
|
|
DdlVendedorAsignado.DataBind();
|
|
DdlVendedorAsignado.Items.Insert(0, new ListItem("Seleccione ", "-1"));
|
|
}
|
|
|
|
protected void CargaSucursales()
|
|
{
|
|
DdlSucursales.DataSource = get_GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1);
|
|
DdlSucursales.DataBind();
|
|
DdlSucursales.Items.Insert(0, new ListItem("Todos ", "-1"));
|
|
}
|
|
|
|
protected void CargaDatos()
|
|
{
|
|
EsEditar = false;
|
|
CveEncuestaAplicada = -1;
|
|
CveVendedor = UsuarioActual.CveVendedor;
|
|
CveSubProyecto = -1;
|
|
|
|
// AQUI DEBE VALIDAR SI LA EMPRESACRM USA DATOS TECNICOS
|
|
if (UsuarioActual.Empresa.AplicaDatosTecnicosCRM && UsuarioActual.Empresa.CveEncuestaCRM > 0)
|
|
{
|
|
CveEncuestaCRM = UsuarioActual.Empresa.CveEncuestaCRM;
|
|
}
|
|
else
|
|
{
|
|
CveEncuestaCRM = -1;
|
|
}
|
|
|
|
if (CveEmpresaCRM > 0)
|
|
{
|
|
ClsCRM ObjCRM = new ClsCRM();
|
|
|
|
if (ObjCRM.GetEmpresasCRM(UsuarioActual.CveEmpresa, CveEmpresaCRM) && ObjCRM.DtResultados.Rows.Count > 0)
|
|
{
|
|
EsEditar = true;
|
|
|
|
LblEncabezadoEmpresa.Text = String.Format("Consulta de la Empresa: {0}", ObjCRM.DtResultados.FiltroPrimeroValor("Empresa").ToUpper());
|
|
|
|
TxtNombreEmpresa.Text = ObjCRM.DtResultados.FiltroPrimeroValor("Empresa");
|
|
TxtRFC.Text = ObjCRM.DtResultados.FiltroPrimeroValor("RFC");
|
|
DdlTipoPrceso2.SelectedValue = ObjCRM.DtResultados.FiltroPrimeroValor("CveTipoProceso");
|
|
CargaMetodosCaptacion();
|
|
TxtCorreoEmpresaCRM.Text = ObjCRM.DtResultados.FiltroPrimeroValor("Correo");
|
|
DdlMedioCaptacion.SelectedValueExist(ObjCRM.DtResultados.FiltroPrimeroValor("CveMedioCaptacion"));
|
|
|
|
CveEncuestaAplicada = ObjCRM.DtResultados.FiltroPrimeroValor("CveEncuestaAplicada") != "" ? ObjCRM.DtResultados.FiltroPrimeroValor("CveEncuestaAplicada").ToEntero() : -1;
|
|
CveVendedor = ObjCRM.DtResultados.FiltroPrimeroValor("CveVendedorAsignado").ToEntero();
|
|
CveSubProyecto = ObjCRM.DtResultados.FiltroPrimeroValor("CveSubProyecto").ToEntero();
|
|
CveCliente = ObjCRM.DtResultados.FiltroPrimeroValor("CveCliente").ToEntero();
|
|
|
|
if(!(CveCliente > 0))
|
|
{
|
|
HplCrearCliente.Visible = true;
|
|
HplCrearCliente.NavigateUrl = String.Format("/Ventas/Clientes.aspx?CveEmpresaCRM={0}", CveEmpresaCRM);
|
|
}
|
|
|
|
CargaContactos(ObjCRM);
|
|
ActivaSeccionAcercamientos();
|
|
CargaAcercamientos(ObjCRM);
|
|
|
|
InicializaAcercamientos(ObjCRM);
|
|
|
|
CargaCotizaciones();
|
|
|
|
DivBitacora.Visible = true;
|
|
}
|
|
else
|
|
{
|
|
Alert("La Empresa solicitada no existe, por favor revise su búsqueda.", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
BtnGuardarEmpresa.Enabled = false;
|
|
BtnEliminarEmpresa.Enabled = false;
|
|
|
|
DivBitacora.Visible = false;
|
|
}
|
|
|
|
ObjCRM.Dispose();
|
|
UpDatos.Update();
|
|
|
|
BtnGuardarEmpresa.Text = "Actualizar";
|
|
BtnEliminarEmpresa.Visible = true;
|
|
UpGuardar.Update();
|
|
UPBitacora.Update();
|
|
}
|
|
else
|
|
{
|
|
CreaTempDTContactos();
|
|
}
|
|
|
|
DdlVendedorAsignado.SelectedValueExist(CveVendedor);
|
|
DdlSucursales.SelectedValueExist(CveSubProyecto);
|
|
ActivaSeccionContactos();
|
|
|
|
//CARGA BITACORA
|
|
if (EsEditar)
|
|
{
|
|
LnkAgregarObservaciones.Visible = true;
|
|
LnkAgregarAgenda.Visible = true;
|
|
|
|
CargaEventoBitacora();
|
|
}
|
|
}
|
|
|
|
protected void DdlTipoProceso_Change(object sender, EventArgs e)
|
|
{
|
|
DdlMedioCaptacionAcercamiento.Items.Clear();
|
|
DdlMedioCaptacionAcercamiento.DataSource = DtMedioCaptacion.FiltraParametros(String.Format("CveTipoProceso = {0}",DdlTipoProceso.SelectedValue.ToEntero()));
|
|
DdlMedioCaptacionAcercamiento.DataBind();
|
|
if (DdlTipoProceso.SelectedValue != "-1")
|
|
{
|
|
DdlMedioCaptacionAcercamiento.Enabled = true;
|
|
}else
|
|
{
|
|
DdlMedioCaptacionAcercamiento.Items.Insert(0,new ListItem("Seleccione","-1"));
|
|
DdlMedioCaptacionAcercamiento.Enabled = false;
|
|
}
|
|
|
|
DdlProbabilidadAcercamiento.Items.Clear();
|
|
DdlProbabilidadAcercamiento.DataSource = DtProbabilidadAcercamiento.FiltraParametros(String.Format("CveTipoProceso = {0}", DdlTipoProceso.SelectedValue.ToEntero()));
|
|
DdlProbabilidadAcercamiento.DataBind();
|
|
DdlProbabilidadAcercamiento.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
|
|
UpAltaAcercamiento.Update();
|
|
}
|
|
#endregion
|
|
|
|
#region "ELIMINAR EMPRESA"
|
|
protected void BtnEliminarEmpresa_Click(object sender, EventArgs e)
|
|
{
|
|
EliminarEmpresa();
|
|
}
|
|
|
|
protected void EliminarEmpresa()
|
|
{
|
|
Boolean HuboError = true;
|
|
|
|
ClsCRM ObjCRM = new ClsCRM();
|
|
|
|
ClsEncuestas objDatosTecnicos = new ClsEncuestas(ObjCRM.IniciaTransacSQL());
|
|
|
|
if (ObjCRM.RemoveContactoEmpresa(-1, CveEmpresaCRM))
|
|
{
|
|
if (ObjCRM.RemoveEmpresaCRM(CveEmpresaCRM))
|
|
{
|
|
HuboError = false;
|
|
|
|
if (CveEncuestaAplicada > 0 && !objDatosTecnicos.RemoveEncuestaAplicada(CveEncuestaAplicada, UsuarioActual.CveEmpresa))
|
|
{
|
|
HuboError = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!HuboError)
|
|
{
|
|
ObjCRM.Commit();
|
|
Alert("La Empresa ha sido eliminado.", ModExtensiones.TipoMensaje.MsgInformacion, "document.location.href=\"/CRM/CatEmpresasCRM.aspx\"");
|
|
}
|
|
else { ObjCRM.RollBack(); }
|
|
|
|
ObjCRM.Dispose();
|
|
}
|
|
#endregion
|
|
|
|
#region "TAB CONTACTOS"
|
|
protected void ActivaSeccionContactos()
|
|
{
|
|
if (CveEmpresaCRM > 0)
|
|
{
|
|
BtnAgregarContacto.Visible = true;
|
|
DivBuscadorContactos.Visible = true;
|
|
}
|
|
else
|
|
{
|
|
BtnAgregarContacto.Visible = true;
|
|
DivBuscadorContactos.Visible = true;
|
|
}
|
|
}
|
|
|
|
protected void CreaTempDTContactos()
|
|
{
|
|
TempDTContactos = new DataTable();
|
|
|
|
//CveContacto, Nombre, TelefonoOficina, Celular, Correo, CveUsuarioIng, FechaIng
|
|
|
|
TempDTContactos.Columns.Add("Nombre", typeof(string));
|
|
TempDTContactos.Columns.Add("TelefonoOficina", typeof(string));
|
|
TempDTContactos.Columns.Add("Celular", typeof(string));
|
|
TempDTContactos.Columns.Add("Correo", typeof(string));
|
|
TempDTContactos.Columns.Add("CveUsuarioIng", typeof(string));
|
|
TempDTContactos.Columns.Add("FechaIng", typeof(string));
|
|
|
|
TempDTContactos.Columns.Add("CveContacto", typeof(string));
|
|
|
|
GVContactos.DataSource = TempDTContactos;
|
|
GVContactos.DataBind();
|
|
|
|
UpContactos.Update();
|
|
}
|
|
|
|
protected void CargaGVContactosTemporales()
|
|
{
|
|
GVContactos.DataSource = TempDTContactos;
|
|
GVContactos.DataBind();
|
|
|
|
UpContactos.Update();
|
|
}
|
|
|
|
protected void CargaContactos(ClsCRM objCRM)
|
|
{
|
|
TempDTContactos = null;
|
|
|
|
if (objCRM.GetContactoEmpresa(CveEmpresaCRM))
|
|
{
|
|
DTContactos = objCRM.DtResultados;
|
|
GVContactos.DataSource = DTContactos;
|
|
GVContactos.DataBind();
|
|
|
|
DdlContactoPrincipal.Items.Clear();
|
|
DdlContactoPrincipal.DataSource = DTContactos;
|
|
|
|
if (DTContactos.Rows.Count != 1)
|
|
DdlContactoPrincipal.Items.Insert(0, new ListItem("Seleccione ", "-1"));
|
|
|
|
DdlContactoPrincipal.DataBind();
|
|
|
|
DdlContactoAgenda.Items.Clear();
|
|
DdlContactoAgenda.DataSource = DTContactos;
|
|
DdlContactoAgenda.Items.Insert(0, new ListItem("Seleccione ", "-1"));
|
|
DdlContactoAgenda.DataBind();
|
|
}
|
|
}
|
|
|
|
protected void limpiarCamposModalContato()
|
|
{
|
|
if (EsEditarContacto)
|
|
{
|
|
LtlModalTitulo.Text = "Actualizar Contacto";
|
|
BtnGuardarContacto.Text = "Actualizar";
|
|
}
|
|
else
|
|
{
|
|
LtlModalTitulo.Text = "Agregar Contacto";
|
|
BtnGuardarContacto.Text = "Guardar";
|
|
}
|
|
TxtNombreContacto.Text = "";
|
|
TxtTelefonoOficina.Text = "";
|
|
TxtCelular.Text = "";
|
|
TxtCorreo.Text = "";
|
|
}
|
|
|
|
protected void BtnAgregarContacto_Click(object sender, EventArgs e)
|
|
{
|
|
EsEditarContacto = false;
|
|
limpiarCamposModalContato();
|
|
UPModalContacto.Update();
|
|
|
|
this.RegistraScript("$('#DivModalContacto').modal();");
|
|
}
|
|
|
|
protected void LnkEditarContacto_Click(object sender, EventArgs e)
|
|
{
|
|
EsEditarContacto = true;
|
|
limpiarCamposModalContato();
|
|
|
|
GridViewRow GvRow = (GridViewRow)(((LinkButton)sender).NamingContainer);
|
|
|
|
CveContactoEditado = GvRow.DataKey("CveContacto").ToEntero();
|
|
|
|
TxtNombreContacto.Text = GvRow.DataKey("Nombre").ToString();
|
|
TxtTelefonoOficina.Text = GvRow.DataKey("TelefonoOficina").ToString();
|
|
TxtCelular.Text = GvRow.DataKey("Celular").ToString();
|
|
TxtCorreo.Text = GvRow.DataKey("Correo").ToString();
|
|
|
|
IndexDTContacto = GvRow.RowIndex;
|
|
|
|
UPModalContacto.Update();
|
|
|
|
this.RegistraScript("$('#DivModalContacto').modal();");
|
|
}
|
|
|
|
protected void BtnGuardarContacto_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
String NombreContacto = TxtNombreContacto.Text;
|
|
String TelefonoOficina = TxtTelefonoOficina.Text == "" ? "-1" : TxtTelefonoOficina.Text;
|
|
String Celular = TxtCelular.Text == "" ? "-1" : TxtCelular.Text;
|
|
String Correo = TxtCorreo.Text == "" ? "-1" : TxtCorreo.Text;
|
|
|
|
if (CveEmpresaCRM > 0)
|
|
{
|
|
|
|
ClsCRM ObjCRM = new ClsCRM();
|
|
ClsOIEventos ObjBitacora = new ClsOIEventos(ObjCRM.IniciaTransacSQL());
|
|
|
|
Boolean HuboError = true;
|
|
|
|
int CveUsuarioIng = UsuarioActual.CveUsuario;
|
|
|
|
if (!EsEditarContacto)
|
|
{
|
|
if (ObjCRM.AddContactoEmpresa(NombreContacto, TelefonoOficina, Celular, Correo, CveEmpresaCRM, CveUsuarioIng))
|
|
{
|
|
TelefonoOficina = (TelefonoOficina != "-1" ? String.Format(", Teléfono de Oficina: {0:(###) ###-####}", Convert.ToInt64(TelefonoOficina)) : "");
|
|
Celular = (Celular != "-1" ? String.Format(", Celular: {0:(###) ###-####}", Convert.ToInt64(Celular)) : "");
|
|
Correo = (Correo != "-1" ? String.Format(", Correo: {0}", Correo) : "");
|
|
|
|
if (ObjBitacora.AddEventoBitacora(String.Format("Se registró un Contacto con Nombre: {0}{1}{2}{3}", NombreContacto, TelefonoOficina, Celular, Correo), "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveEmpresaCRM: CveEmpresaCRM))
|
|
{
|
|
string asunto = "Se registró un Contacto";
|
|
string mensaje = String.Format("Se registró un Contacto con Nombre: {0}{1}{2}{3}. Realzado por el usuario {4}", NombreContacto, TelefonoOficina, Celular, Correo,UsuarioActual.Nombre);
|
|
mandarCorreo(asunto, mensaje);
|
|
HuboError = false;
|
|
Alert("El Contacto fue creado correctamente.", ModExtensiones.TipoMensaje.MsgInformacion);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (ObjCRM.UpdateContactoEmpresa(NombreContacto, TelefonoOficina, Celular, Correo, CveContactoEditado, UsuarioActual.CveUsuario))
|
|
{
|
|
//if (ObjBitacora.AddEventoBitacora(String.Format("Se actualizó el contacto {0}", NombreContacto), "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveEmpresaCRM: CveEmpresaCRM))
|
|
//{
|
|
HuboError = false;
|
|
Alert(String.Format("Se actualizó el contacto {0}.", NombreContacto), ModExtensiones.TipoMensaje.MsgInformacion);
|
|
//}
|
|
}
|
|
}
|
|
|
|
CargaContactos(ObjCRM);
|
|
|
|
if (!HuboError) { ObjCRM.Commit(); } else { ObjCRM.RollBack(); }
|
|
|
|
ObjCRM.Dispose();
|
|
ObjBitacora.Dispose();
|
|
|
|
//CARGA BITACORA
|
|
if (!HuboError)
|
|
{
|
|
CargaEventoBitacora();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//SI NO EXISTE LA EMPRESA AGREGA LOS CONTATOS A TABLA TEMPORAL
|
|
// //CveContacto, Nombre, TelefonoOficina, Celular, Correo, CveUsuarioIng, FechaIng
|
|
DataRow rowContacto;
|
|
rowContacto = TempDTContactos.NewRow();
|
|
|
|
rowContacto["CveContacto"] = "-1";
|
|
rowContacto["Nombre"] = NombreContacto;
|
|
rowContacto["TelefonoOficina"] = TxtTelefonoOficina.Text;
|
|
rowContacto["Celular"] = TxtCelular.Text;
|
|
rowContacto["Correo"] = TxtCorreo.Text;
|
|
rowContacto["CveUsuarioIng"] = UsuarioActual.CveUsuario;
|
|
rowContacto["FechaIng"] = DateTime.Now;
|
|
|
|
if (EsEditarContacto)
|
|
TempDTContactos.Rows.RemoveAt(IndexDTContacto);
|
|
|
|
TempDTContactos.Rows.Add(rowContacto);
|
|
|
|
CargaGVContactosTemporales();
|
|
}
|
|
|
|
limpiarCamposModalContato();
|
|
this.RegistraScript("$('#DivModalContacto').modal('hide');");
|
|
UpContactos.Update();
|
|
}
|
|
|
|
protected void GVContactos_RowDeleting(object sender, GridViewDeleteEventArgs e)
|
|
{
|
|
if (CveEmpresaCRM > 0)
|
|
{
|
|
CveContactoEditado = GVContactos.Rows[e.RowIndex].DataKey("CveContacto").ToEntero();
|
|
String NombreContacto = GVContactos.Rows[e.RowIndex].DataKey("Nombre").ToString();
|
|
|
|
Boolean HuboError = true;
|
|
|
|
ClsCRM ObjCRM = new ClsCRM();
|
|
ClsOIEventos ObjBitacora = new ClsOIEventos(ObjCRM.IniciaTransacSQL());
|
|
|
|
if (ObjCRM.RemoveContactoEmpresa(CveContactoEditado))
|
|
{
|
|
HuboError = false;
|
|
CargaContactos(ObjCRM);
|
|
Alert("El Contacto ha sido eliminado.", ModExtensiones.TipoMensaje.MsgInformacion);
|
|
|
|
if (ObjBitacora.AddEventoBitacora(String.Format("Se eliminó el contacto {0}", NombreContacto), "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveEmpresaCRM: CveEmpresaCRM))
|
|
{
|
|
string asunto = "Se eliminó el contacto";
|
|
string mensaje = String.Format("Se eliminó el contacto {0} por el usuario {1}", NombreContacto,UsuarioActual.Nombre);
|
|
mandarCorreo(asunto, mensaje);
|
|
ObjCRM.Commit();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ObjCRM.RollBack();
|
|
}
|
|
|
|
ObjCRM.Dispose();
|
|
ObjBitacora.Dispose();
|
|
|
|
UpContactos.Update();
|
|
|
|
//CARGA BITACORA
|
|
if (!HuboError)
|
|
{
|
|
CargaEventoBitacora();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
TempDTContactos.Rows.RemoveAt(e.RowIndex);
|
|
CargaGVContactosTemporales();
|
|
//CargaGVContactosSucursal()
|
|
}
|
|
}
|
|
|
|
protected void GVContactos_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
if (e.Row.DataKey("TelefonoOficina") != "")
|
|
e.Row.FCLabel("lblTelefonoOficina").Text = String.Format("{0:(###) ###-####}", Convert.ToInt64(e.Row.DataKey("TelefonoOficina")));
|
|
|
|
if (e.Row.DataKey("Celular") != "")
|
|
e.Row.FCLabel("lblCelular").Text = String.Format("{0:(###) ###-####}", Convert.ToInt64(e.Row.DataKey("Celular")));
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region "BITACORA"
|
|
private void CargaEventoBitacora()
|
|
{
|
|
ClsOIEventos ObjEventoBitacora = new ClsOIEventos();
|
|
|
|
if (ObjEventoBitacora.GetAgendaBitacora(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveEmpresaCRM: CveEmpresaCRM))
|
|
GVEventoBitacora.DataSource = ObjEventoBitacora.DtResultados.FiltraParametros("CveTipoEvento = 6 OR CveTipoEvento = 2");
|
|
else
|
|
GVEventoBitacora.DataSource = null;
|
|
|
|
ObjEventoBitacora.Dispose();
|
|
GVEventoBitacora.DataBind();
|
|
|
|
UPBitacora.Update();
|
|
}
|
|
|
|
protected void BtnGuardarEventoBitacora_Click(object sender, EventArgs e)
|
|
{
|
|
ClsOIEventos ObjEventoBitacora = new ClsOIEventos();
|
|
|
|
string FileExtension = "-1";
|
|
List<Archivo> filesgral = Anexo.getfiles().Archivos;
|
|
string filemove = "";
|
|
|
|
foreach (Archivo fileItem in filesgral)
|
|
{
|
|
FileExtension = System.IO.Path.GetExtension(string.Format(@"{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "");
|
|
filemove = fileItem.filename;
|
|
}
|
|
|
|
if (ObjEventoBitacora.AddEventoBitacora(TxtEventoDescripcion.Text.Trim(), string.Format(".{0}", FileExtension), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveEmpresaCRM: CveEmpresaCRM))
|
|
{
|
|
if (filemove != "")
|
|
filemove.FilesMove(string.Format("OI{0}", ObjEventoBitacora.CveEvento.ToString()), string.Format(@"Empresas\{0}\OI", UsuarioActual.CveEmpresa));
|
|
|
|
|
|
TxtEventoDescripcion.Text = "";
|
|
Anexo.Text = "[]";
|
|
|
|
RegistraScript("$('#ModalBitacora').modal('hide')");
|
|
Alert("La bitácora/observación se guardó correctamente", ModExtensiones.TipoMensaje.MsgInformacion);
|
|
}
|
|
ObjEventoBitacora.Dispose();
|
|
|
|
CargaEventoBitacora();
|
|
UPAddEventoBitacora.Update();
|
|
}
|
|
|
|
protected void GVEventoBitacora_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
if (e.Row.RowIndex == 0)
|
|
{
|
|
e.Row.Cells[0].Width = Unit.Pixel(175);
|
|
e.Row.Cells[1].Width = Unit.Pixel(175);
|
|
e.Row.Cells[2].Width = Unit.Pixel(100);
|
|
e.Row.Cells[4].Width = Unit.Pixel(30);
|
|
}
|
|
|
|
if (e.Row.DBCampo("Archivo").ToString() != "")
|
|
{
|
|
e.Row.FCLinkButton("LinkArchivo").Visible = true;
|
|
e.Row.FCLinkButton("LinkArchivo").CommandArgument = string.Format(@"OI\{0}", e.Row.DBCampo("Archivo").ToString());
|
|
ScriptManager.GetCurrent(this).RegisterPostBackControl(e.Row.FCLinkButton("LinkArchivo")); // Registro un evento Postbacktrigger, que recargue toda la pagina para que funcione
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void DownloadFile(object sender, EventArgs e)
|
|
{
|
|
string filePath = string.Format("{0}{1}", UsuarioActual.Empresa.Ruta, ((LinkButton)sender).CommandArgument);
|
|
System.IO.FileInfo Archivo = new System.IO.FileInfo(filePath);
|
|
|
|
HttpContext.Current.Response.Clear();
|
|
HttpContext.Current.Response.ClearContent();
|
|
HttpContext.Current.Response.ContentType = "application/octet-stream";
|
|
HttpContext.Current.Response.AppendHeader("Content-disposition", "attachment; filename=" + Path.GetFileName(filePath));
|
|
HttpContext.Current.Response.AddHeader("Content-Length", Archivo.Length.ToString());
|
|
HttpContext.Current.Response.TransmitFile(filePath);
|
|
HttpContext.Current.Response.Flush();
|
|
HttpContext.Current.Response.End();
|
|
|
|
Archivo = null;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region "AGENDA"
|
|
protected void limpiarModalAgendar()
|
|
{
|
|
DdlTipoAgenda.SelectedValueExist("1");
|
|
DdlPrioridadAgenda.SelectedValueExist("1");
|
|
TxtAsuntoAgenda.Text = "";
|
|
TxtDescripcionAgenda.Text = "";
|
|
TxtFechaInicioAgenda.Text = DateTime.Now.ToString("dd/MM/yyyy HH:mm");
|
|
|
|
UpModalAgenda.Update();
|
|
}
|
|
|
|
protected void BtnGuardarAgenda_Click(object sender, EventArgs e)
|
|
{
|
|
ClsOIEventos ObjEventos = new ClsOIEventos();
|
|
DateTime FechaInicio = TxtFechaInicioAgenda.Text.ToDateTime();
|
|
|
|
if (ObjEventos.AddEventoAgenda(DdlTipoAgenda.SelectedValue.ToEntero(), TxtAsuntoAgenda.Text, TxtDescripcionAgenda.Text, DdlPrioridadAgenda.SelectedValue.ToEntero(), FechaInicio, FechaInicio, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveEmpresaCRM: CveEmpresaCRM, CveContactoCRM: DdlContactoAgenda.SelectedValue.ToEntero()))
|
|
{
|
|
mandarCorreo(TxtAsuntoAgenda.Text, TxtDescripcionAgenda.Text);
|
|
limpiarModalAgendar();
|
|
RegistraScript("$('#ModalAgenda').modal('hide')");
|
|
Alert("El Evento se agendó correctamente", ModExtensiones.TipoMensaje.MsgInformacion);
|
|
|
|
}
|
|
ObjEventos.Dispose();
|
|
CargaEventoBitacora();
|
|
}
|
|
|
|
protected void CargarTiposEventos()
|
|
{
|
|
ClsOIEventos ObjEventos = new ClsOIEventos();
|
|
|
|
if (ObjEventos.GetAgendaTipo())
|
|
{
|
|
DdlTipoAgenda.DataSource = ObjEventos.DtResultados;
|
|
DdlTipoAgenda.DataBind();
|
|
}
|
|
|
|
ObjEventos.Dispose();
|
|
limpiarModalAgendar();
|
|
}
|
|
|
|
//protected void LnkAgregarEvento_Click(object sender, EventArgs e)
|
|
//{
|
|
// this.RegistraScript(String.Format("AbrirVentana('/OI/PopUpAgenda.aspx?CveTipoEvento=2&CveEmpresaCRM={0}&TB_iframe=true&height=370&width=600');", CveEmpresaCRM));
|
|
//}
|
|
#endregion
|
|
|
|
#region "CARGAR DATOS TECNICOS - ENCUESTA"
|
|
protected void CargaDatosTecnicos()
|
|
{
|
|
ClsEncuestas objEncuesta = new ClsEncuestas();
|
|
|
|
if (objEncuesta.GetRespuestas(CveEncuestaCRM))
|
|
DTRespuestasDatosTecnicos = objEncuesta.DtResultados;
|
|
|
|
if (objEncuesta.GetDatosTecnicosEmpresaCRM(CveEncuestaCRM, CveEncuestaAplicada, UsuarioActual.Empresa.CveEmpresa))
|
|
{
|
|
GvDatosTecnicos.DataSource = objEncuesta.DtResultados;
|
|
if (objEncuesta.DtResultados.Rows.Count > 0)
|
|
{
|
|
//BtnModalReferenciasVerificar.Visible = true;
|
|
GvDatosTecnicos.Visible = true;
|
|
}
|
|
}
|
|
|
|
//UpModalReferenciasBtn.Update();
|
|
objEncuesta.Dispose();
|
|
|
|
GvDatosTecnicos.DataBind();
|
|
UpDatosTecnicos.Update();
|
|
}
|
|
|
|
protected void GvDatosTecnicos_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
int EsOpcion = e.Row.DBCampo("CveTipoPregunta").ToEntero();
|
|
int CvePregunta = e.Row.DBCampo("CvePregunta").ToEntero();
|
|
|
|
DataTable dt = DTRespuestasDatosTecnicos.FiltraParametros(string.Format(" CvePregunta = {0} ", CvePregunta));
|
|
// e.Row.FCFilteredTextBoxExtender("filTxtResPuestaReferencias").Enabled = False
|
|
|
|
switch (EsOpcion)
|
|
{
|
|
case 1: // Texto Simple
|
|
{
|
|
var withBlock = e.Row.FindControl("DivTxtRespuestaDinamica");
|
|
withBlock.Visible = true;
|
|
|
|
e.Row.FCTextBox("TxtRespuestaDinamica").Text = e.Row.DataKey("Valor").ToString();
|
|
|
|
break;
|
|
}
|
|
|
|
case 2: //Radiobuttons
|
|
{
|
|
var DivwithBlock = e.Row.FindControl("DivRdlRespuestaDinamica");
|
|
DivwithBlock.Visible = true;
|
|
|
|
var withBlock = e.Row.FCRadioButtonList("RdlRespuestaDinamica");
|
|
withBlock.Visible = true;
|
|
withBlock.DataSource = dt;
|
|
withBlock.DataBind();
|
|
|
|
|
|
if (e.Row.FCRadioButtonList("RdlRespuestaDinamica").Items.Count > 0)
|
|
{
|
|
e.Row.FCRadioButtonList("RdlRespuestaDinamica").SelectedIndex = 0;
|
|
}
|
|
|
|
if (e.Row.DataKey("Valor").ToString() != "")
|
|
{
|
|
e.Row.FCRadioButtonList("RdlRespuestaDinamica").SelectedValue = e.Row.FCRadioButtonList("RdlRespuestaDinamica").Items.FindByText(e.Row.DataKey("Valor").ToString()).Value;
|
|
}
|
|
|
|
//e.Row.FCRequiredFieldValidator("RFVRdlRespuestaDinamica").ErrorMessage = string.Format("<i><span style='color: darkred;'>Campo requerido</span></i>");
|
|
break;
|
|
}
|
|
case 3: // DropDownList
|
|
{
|
|
var DivwithBlock = e.Row.FindControl("DivDdlRespuestaDinamica");
|
|
DivwithBlock.Visible = true;
|
|
|
|
var withBlock = e.Row.FCDropDownList("DdlRespuestaDinamica");
|
|
|
|
withBlock.DataSource = dt;
|
|
withBlock.DataBind();
|
|
withBlock.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
|
|
e.Row.FCDropDownList("DdlRespuestaDinamica").SelectedValueExist(e.Row.DataKey("CveRespuesta"));
|
|
break;
|
|
}
|
|
case 4: // Checks SI/NO
|
|
{
|
|
var DivwithBlock = e.Row.FindControl("DivChkRespuestaDinamica");
|
|
DivwithBlock.Visible = true;
|
|
|
|
var withBlock = e.Row.FCCheckBox("ChkRespuestaDinamica");
|
|
withBlock.Visible = true;
|
|
|
|
if (e.Row.DataKey("Valor").ToString() == "")
|
|
e.Row.FCCheckBox("ChkRespuestaDinamica").Checked = e.Row.DataKey("RespuestaDefault").ToString() == "1" ? true : false;
|
|
else
|
|
e.Row.FCCheckBox("ChkRespuestaDinamica").Checked = e.Row.DataKey("Valor").ToString() == "Si" ? true : false;
|
|
|
|
break;
|
|
}
|
|
|
|
case 5: // numerico
|
|
{
|
|
var DivwithBlock = e.Row.FindControl("DivTxtRespuestaDinamica");
|
|
DivwithBlock.Visible = true;
|
|
|
|
var withBlock = e.Row.FCTextBox("TxtRespuestaDinamica");
|
|
withBlock.Attributes.Add("onkeypress", "validate(event)");
|
|
|
|
e.Row.FCTextBox("TxtRespuestaDinamica").Text = e.Row.DataKey("Valor");
|
|
break;
|
|
}
|
|
case 6: // Multiline
|
|
{
|
|
var withBlock = e.Row.FindControl("DivTxtRespuestaDinamicaMultilinea");
|
|
withBlock.Visible = true;
|
|
|
|
e.Row.FCTextBox("TxtRespuestaDinamicaMultilinea").Text = e.Row.DataKey("Valor").ToString();
|
|
|
|
break;
|
|
}
|
|
case 7: // fecha
|
|
{
|
|
var withBlock = e.Row.FindControl("DivFechaDinamica");
|
|
withBlock.Visible = true;
|
|
|
|
e.Row.FCTextBox("TxtRespuestaFechaDinamica").Text = e.Row.DataKey("Valor");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region "TAB ACERCAMIENTOS"
|
|
protected void ActivaSeccionAcercamientos()
|
|
{
|
|
if (CveEmpresaCRM > 0)
|
|
{
|
|
LimitaFechasAcercamiento();
|
|
LnkAgregarAcercamiento.Visible = true;
|
|
DivBuscadorAcercamientos.Visible = true;
|
|
}
|
|
else
|
|
{
|
|
LnkAgregarAcercamiento.Visible = false;
|
|
DivBuscadorAcercamientos.Visible = false;
|
|
}
|
|
}
|
|
|
|
protected void LimitaFechasAcercamiento()
|
|
{
|
|
//ACTIVAMOS RANGO DE FECHAS PARA CAPTURA DE ACERCAMIENTO
|
|
CETxtFechaApertura.StartDate = DateTime.Now.AddDays(-1);
|
|
CETxtFechaApertura.EndDate = DateTime.Now;
|
|
|
|
RVFechaApertura.MinimumValue = DateTime.Now.AddDays(-1).ToShortDateString();
|
|
RVFechaApertura.MaximumValue = DateTime.Now.ToShortDateString();
|
|
}
|
|
|
|
protected void InicializaAcercamientos(ClsCRM ObjCRM)
|
|
{
|
|
DdlTipoProceso.Items.Clear();
|
|
DdlProbabilidadAcercamiento.Items.Clear();
|
|
DdlVendedor.Items.Clear();
|
|
|
|
if (ObjCRM.GetTipoProceso(UsuarioActual.CveEmpresa, 1))
|
|
{
|
|
DdlTipoProceso.DataSource = ObjCRM.DtResultados;
|
|
|
|
if (ObjCRM.DtResultados.Rows.Count > 0)
|
|
{
|
|
DdlTipoProceso.Items.Insert(0, new ListItem("Seleccione ", "-1"));
|
|
|
|
DdlMedioCaptacionAcercamiento.Enabled = false;
|
|
}
|
|
|
|
DdlTipoProceso.DataBind();
|
|
}
|
|
|
|
if (ObjCRM.GetProbabilidadAcercamiento(UsuarioActual.CveEmpresa, 1))
|
|
{
|
|
//DdlProbabilidadAcercamiento.DataSource = ObjCRM.DtResultados;
|
|
//DdlProbabilidadAcercamiento.DataBind();
|
|
DdlProbabilidadAcercamiento.Items.Insert(0, new ListItem("Seleccione ", "-1"));
|
|
|
|
DtProbabilidadAcercamiento = ObjCRM.DtResultados;
|
|
}
|
|
|
|
DdlVendedor.DataSource = get_GlobalDTVendedores(UsuarioActual.CveEmpresa);
|
|
DdlVendedor.DataBind();
|
|
DdlVendedor.Items.Insert(0, new ListItem("Seleccione ", "-1"));
|
|
DdlVendedor.SelectedValueExist(CveVendedor);
|
|
|
|
if (CveVendedor > 0)
|
|
DdlVendedor.Enabled = false;
|
|
|
|
}
|
|
|
|
protected void limpiarCamposModalAcercamiento()
|
|
{
|
|
TxtAcercamiento.Text = "";
|
|
TxtDescripcionAcercamiento.Text = "";
|
|
TxtFechaApertura.Text = DateTime.Now.ToShortDateString();
|
|
TxtImporte.Text = "0.00";
|
|
TxtComision.Text = "0.00";
|
|
|
|
DdlTipoProceso.SelectedValueExist("-1");
|
|
DdlContactoPrincipal.SelectedValueExist("-1");
|
|
DdlVendedor.SelectedValueExist(CveVendedor);
|
|
DdlMedioCaptacionAcercamiento.SelectedValueExist("-1");
|
|
DdlProbabilidadAcercamiento.SelectedValueExist("-1");
|
|
DdlPrioridadAcercamiento.SelectedValueExist("1");
|
|
}
|
|
|
|
|
|
protected void CargaAcercamientos(ClsCRM objCRM)
|
|
{
|
|
if (objCRM.GetAcercamiento(UsuarioActual.CveEmpresa, CveEmpresaCRM))
|
|
{
|
|
GVAcercamientos.DataSource = objCRM.DtResultados;
|
|
GVAcercamientos.DataBind();
|
|
}
|
|
}
|
|
|
|
protected void LnkAgregarAcercamiento_Click(object sender, EventArgs e)
|
|
{
|
|
if(DTContactos.Rows.Count == 0)
|
|
{
|
|
Alert("Para crear un nuevo acercamiento es necesario agregar al menos un Contacto.", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
}
|
|
else
|
|
{
|
|
ClsCRM ObjCRM = new ClsCRM();
|
|
CargaMetodosCaptacion();
|
|
InicializaAcercamientos(ObjCRM);
|
|
ObjCRM.Dispose();
|
|
limpiarCamposModalAcercamiento();
|
|
this.RegistraScript("$('#DivModalAltaAcercamiento').modal();");
|
|
UpAltaAcercamiento.Update();
|
|
//Confirmacion("Se le redireccionara para realizar el Registro del Acercamiento, ¿Desea continuar?", "", "document.location.href=\"/CRM/Acercamiento.aspx\"", "");
|
|
}
|
|
|
|
}
|
|
|
|
protected void BtnGuardarAcercamiento_Click(object sender, EventArgs e)
|
|
{
|
|
ClsCRM ObjCRM = new ClsCRM();
|
|
ClsOIEventos ObjBitacora = new ClsOIEventos(ObjCRM.IniciaTransacSQL());
|
|
|
|
Boolean HuboError = true;
|
|
|
|
String NombreAcercamiento = TxtAcercamiento.Text;
|
|
String Descripcion = TxtDescripcionAcercamiento.Text == "" ? "-1" : TxtDescripcionAcercamiento.Text;
|
|
|
|
int CveTipoProceso = DdlTipoProceso.SelectedValue.ToEntero();
|
|
|
|
ObjCRM.GetEtapaProceso(UsuarioActual.CveEmpresa, CveTipoProceso);
|
|
int CveEtapaProcesoActual = ObjCRM.DtResultados.FiltroPrimeroValor("CveEtapaProceso").ToEntero();
|
|
|
|
int CveContactoPrincipal = DdlContactoPrincipal.SelectedValue.ToEntero();
|
|
int CveVendedor = DdlVendedor.SelectedValue.ToEntero();
|
|
int CveMedioCaptacion = DdlMedioCaptacionAcercamiento.SelectedValue.ToEntero();
|
|
int CveProbabilidadAcercamiento = DdlProbabilidadAcercamiento.SelectedValue.ToEntero();
|
|
|
|
int CveRechazoMotivo = -1;
|
|
|
|
DateTime FechaApertura = TxtFechaApertura.Text.ToDateTime();
|
|
|
|
Double Importe = TxtImporte.Text.ToDouble();
|
|
Double Comision = TxtComision.Text.ToDouble();
|
|
|
|
int Prioridad = DdlPrioridadAcercamiento.SelectedValue.ToEntero();
|
|
|
|
int CveUsuarioIng = UsuarioActual.CveUsuario;
|
|
|
|
int CveAcercamiento = -1;
|
|
|
|
if (ObjCRM.DtResultados.Rows.Count > 0)
|
|
{
|
|
CveAcercamiento = ObjCRM.AddAcercamiento(CveEmpresaCRM, CveContactoPrincipal, CveTipoProceso, CveEtapaProcesoActual, CveVendedor, CveMedioCaptacion, CveRechazoMotivo, CveProbabilidadAcercamiento,
|
|
FechaApertura, NombreAcercamiento, Descripcion, Importe, Comision, Prioridad, UsuarioActual.CveEmpresa, CveUsuarioIng);
|
|
}else
|
|
{
|
|
Alert("No tiene 'Etapa Proceso' con el 'Proceso' seleccionado al agregar el Acercamiento",ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
}
|
|
|
|
if (CveAcercamiento > 0)
|
|
{
|
|
if (ObjBitacora.AddEventoBitacora(String.Format("Se registró el Acercamiento {0} como Proceso de Tipo {1}, con Vendedor {2} y Contacto Principal {3}.", NombreAcercamiento, DdlTipoProceso.SelectedItem, DdlVendedor.SelectedItem, DdlContactoPrincipal.SelectedValue == "-1" ? "aun no asignado" : DdlContactoPrincipal.SelectedItem.Text), "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveEmpresaCRM: CveEmpresaCRM, CveTipoProcesoCRM: CveTipoProceso, CveAcercamientoCRM: CveAcercamiento, CveContactoCRM: CveContactoPrincipal, CveEtapaProcesoCRM: CveEtapaProcesoActual))
|
|
{
|
|
string asunto = String.Format("Se registró el Acercamiento {0}",NombreAcercamiento);
|
|
string mensaje = String.Format("Se registró el Acercamiento {0} como Proceso de Tipo {1}, con Vendedor {2} y Contacto Principal {3}.", NombreAcercamiento, DdlTipoProceso.SelectedItem, DdlVendedor.SelectedItem, DdlContactoPrincipal.SelectedValue == "-1" ? "aun no asignado" : DdlContactoPrincipal.SelectedItem.Text);
|
|
mandarCorreo(asunto, mensaje);
|
|
HuboError = false;
|
|
}
|
|
}
|
|
|
|
|
|
CargaAcercamientos(ObjCRM);
|
|
|
|
if (!HuboError) { ObjCRM.Commit(); } else { ObjCRM.RollBack(); }
|
|
|
|
ObjCRM.Dispose();
|
|
ObjBitacora.Dispose();
|
|
|
|
this.RegistraScript("$('#DivModalAltaAcercamiento').modal('hide');");
|
|
|
|
UPAcercamientos.Update();
|
|
|
|
//CARGA BITACORA
|
|
if (!HuboError)
|
|
{
|
|
Alert(String.Format("Se registró el acercamiento <b>{0}</b> como proceso de tipo <b>{1}</b>.<br/><br/> Se le redireccionara al Detalle del Acercamiento.", NombreAcercamiento, DdlTipoProceso.SelectedItem), ModExtensiones.TipoMensaje.MsgInformacion, String.Format("document.location.href=\"/CRM/Acercamiento.aspx?CveAcercamiento={0}\"", CveAcercamiento));
|
|
CargaEventoBitacora();
|
|
}
|
|
limpiarCamposModalAcercamiento();
|
|
}
|
|
|
|
protected void GVAcercamientos_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
if (e.Row.DataKey("CveAcercamiento").ToEntero() > 0)
|
|
e.Row.FCHyperLink("HplNombreAcercamiento").NavigateUrl = String.Format("/CRM/Acercamiento.aspx?CveAcercamiento={0}", e.Row.DataKey("CveAcercamiento"));
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region "PERMISOS"
|
|
protected void VerificaPermisos()
|
|
{
|
|
|
|
if (CveEmpresaCRM > 0)
|
|
{
|
|
if (!UsuarioActual.TienePermisoProceso(250))
|
|
BtnEliminarEmpresa.Visible = false;
|
|
|
|
if (!UsuarioActual.TienePermisoProceso(251))
|
|
LnkAgregarAcercamiento.Visible = false;
|
|
|
|
if ((UsuarioActual.CveVendedor != CveVendedor))
|
|
{
|
|
BtnGuardarEmpresa.Visible = false;
|
|
BtnAgregarContacto.Visible = false;
|
|
//LnkAgregarAcercamiento.Visible = false;
|
|
DivAccionesBitacora.Visible = false;
|
|
GVContactos.Columns[4].Visible = false;
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region "COTIZACIONES"
|
|
protected void CargaCotizaciones()
|
|
{
|
|
ClsVentas ObjVentas = new ClsVentas();
|
|
if (ObjVentas.GetVentas(UsuarioActual.CveEmpresa, "Cot", "-1", -1, "-1", -1, -1, -1, -1, "-1", "-1", "-1", CveEmpresaCRM: CveEmpresaCRM, CveUsuarioConsulta: UsuarioActual.CveUsuario))
|
|
{
|
|
GvCotizacion.DataSource = ObjVentas.DtResultados;
|
|
}
|
|
ObjVentas.Dispose();
|
|
GvCotizacion.DataBind();
|
|
UpCotizacion.Update();
|
|
}
|
|
|
|
protected void GvCotizacion_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
if (e.Row.DataKey("CveEstatusFactura").ToEntero() > 0)
|
|
{
|
|
e.Row.FCLabel("lblEstatus").Text = String.Format("<b>{0}</b>", e.Row.DataKey("EstatusFactura"));
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
private void mandarCorreo(string Asunto, string body)
|
|
{
|
|
DataTable Usuarios = get_GlobalDTUsuarios(CveEmpresa:UsuarioActual.CveEmpresa);
|
|
int CveUsuario = Usuarios.FiltroPrimeroValor("CveUsuario",String.Format("CveVendedor = {0}",DdlVendedorAsignado.SelectedValue)).ToEntero();
|
|
if (CveUsuario != UsuarioActual.CveUsuario)
|
|
{
|
|
string correoVendedor = Usuarios.FiltroPrimeroValor("Correo", String.Format("CveUsuario = {0}", CveUsuario));
|
|
ClsSisMail Mail = new ClsSisMail();
|
|
List<ClsSisMail.ArchivoMail> LSRutasMail = new List<ClsSisMail.ArchivoMail>();
|
|
//ClsSisMail.ArchivoMail itemMail = new ClsSisMail.ArchivoMail();
|
|
Mail.SendMail(ClsPaginas.EmpresaNotificaciones, correoVendedor, Asunto,body);
|
|
}
|
|
}
|
|
|
|
protected void DdlTipoProcesos_Change(Object sender, EventArgs e)
|
|
{
|
|
DdlMedioCaptacion.Items.Clear();
|
|
CargaMetodosCaptacion();
|
|
UpDatos.Update();
|
|
}
|
|
} |