Files
SIG/CRM/Acercamiento.aspx.cs

2094 lines
82 KiB
C#

using ADSNetLibrary.SIGAPI.Models.CRM.Request;
using ADSNetLibrary.SIGAPI.Models.CRM.Response;
using ADSNetLibrary.SIGAPI.Models.Encuestas.Request;
using ADSNetLibrary.SIGAPI.Models.Ventas.Request;
using ADSNetLibrary.SIGAPI.Services;
using ADSNetLibrary.SIGAPI.Services.CRM;
using ADSNetLibrary.SIGAPI.Services.Encuestas;
using DocumentFormat.OpenXml.Drawing.Diagrams;
using Extensiones;
using FormulaEvaluator;
using MoreLinq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.IO.Packaging;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public partial class CRM_Acercamiento : ClsPaginas
{
#region "PROPIEDADES"
private int CveAcercamiento
{
get
{
return ViewState["CveAcercamiento"].ToString().ToEntero();
}
set
{
ViewState["CveAcercamiento"] = value;
}
}
private int CveEmpresaCRM
{
get
{
return ViewState["CveEmpresaCRM"].ToString().ToEntero();
}
set
{
ViewState["CveEmpresaCRM"] = value;
}
}
private int CveVendedorAsignado
{
get
{
return ViewState["CveVendedorAsignado"].ToString().ToEntero();
}
set
{
ViewState["CveVendedorAsignado"] = value;
}
}
protected int NumeroEtapasProceso
{
get
{
return ViewState["NumeroEtapasProceso"].ToString().ToEntero();
}
set
{
ViewState["NumeroEtapasProceso"] = value;
}
}
protected int CveEtapaActual
{
get
{
return ViewState["CveEtapaActual"].ToString().ToEntero();
}
set
{
ViewState["CveEtapaActual"] = value;
}
}
protected int OrdenEtapaActual
{
get
{
return ViewState["OrdenEtapaActual"].ToString().ToEntero();
}
set
{
ViewState["OrdenEtapaActual"] = value;
}
}
protected int CveContactoPrincipal
{
get
{
return ViewState["CveContactoPrincipal"].ToString().ToEntero();
}
set
{
ViewState["CveContactoPrincipal"] = value;
}
}
protected int CveTipoProceso
{
get
{
return ViewState["CveTipoProceso"].ToString().ToEntero();
}
set
{
ViewState["CveTipoProceso"] = value;
}
}
private String TipoProceso
{
get
{
return ViewState["TipoProceso"].ToString();
}
set
{
ViewState["TipoProceso"] = value;
}
}
private String NombreAcercamiento
{
get
{
return ViewState["NombreAcercamiento"].ToString();
}
set
{
ViewState["NombreAcercamiento"] = value;
}
}
private DataTable DTEventosBitacora
{
get
{
return (DataTable)ViewState["DTEventosBitacora"];
}
set
{
ViewState["DTEventosBitacora"] = value;
}
}
private DataTable DTEtapasProceso
{
get
{
return (DataTable)ViewState["DTEtapasProceso"];
}
set
{
ViewState["DTEtapasProceso"] = value;
}
}
private int CveEncuestaProcesoCRM
{
get
{
return ViewState["CveEncuestaProcesoCRM"].ToString().ToEntero();
}
set
{
ViewState["CveEncuestaProcesoCRM"] = value;
}
}
private int CveEncuestaAplicadaProceso
{
get
{
return ViewState["CveEncuestaAplicadaProceso"].ToString().ToEntero();
}
set
{
ViewState["CveEncuestaAplicadaProceso"] = value;
}
}
private DataTable DTRespuestasDatosTecnicos
{
get
{
return (DataTable)ViewState["DTRespuestasDatosTecnicos"];
}
set
{
ViewState["DTRespuestasDatosTecnicos"] = value;
}
}
public string UrlIMGEncriptada(string param)
{
return ModExtensiones.Encripta(param);
}
private Boolean Actualizar
{
get
{
return (Boolean)ViewState["Actualizar"];
}
set
{
ViewState["Actualizar"] = value;
}
}
private int CveAcercamientoGasto
{
get
{
return ViewState["CveAcercamientoGasto"].ToString().ToEntero();
}
set
{
ViewState["CveAcercamientoGasto"] = value;
}
}
private int CvePS
{
get
{
return ViewState["CvePS"] == null ? -1 : ViewState["CvePS"].ToString().ToEntero();
}
set
{
ViewState["CvePS"] = value;
}
}
private Boolean TieneCotizacion
{
get
{
return (Boolean)ViewState["TieneCotizacion"];
}
set
{
ViewState["TieneCotizacion"] = value;
}
}
//public int RCveEvento { get { return ViewState["RCveEvento"] != null ? ViewState["RCveEvento"].ToString().ToEntero() : 0; } set { ViewState["RCveEvento"] = value; } }
public System.Data.DataTable CheckListNew { get { return ViewState["CheckListNew"] != null ? (System.Data.DataTable)ViewState["CheckListNew"] : null; } set { ViewState["CheckListNew"] = value; } }
public int chklistitemindex { get { return ViewState["chklistitemindex"] != null ? ViewState["chklistitemindex"].ToString().ToEntero() : 0; } set { ViewState["chklistitemindex"] = value; } }
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
InicializaDatos();
CargaDatos();
CargaCotizaciones();
CargaGastos();
CargaRechazosMotivos();
if (UsuarioActual.CveEmpresa == 72)
{
TabDatosTecnicos.Visible = false;
TabImagenes.Visible = false;
}
if (CveAcercamiento > 0)
{
CargaEtapasBitacora();
CargarTiposEventosBitacora();
ActivaOpcionCierreCancelacion();
ActivaFechaCierre(CveEtapaActual);
VerificaPermisosEdicion();
if (CveEncuestaProcesoCRM > 0)
{
CargaDatosTecnicos();
if (DTRespuestasDatosTecnicos.Rows.Count > 0)
{
DivMensajeDatosTecnicos.Visible = false;
}
}
CargaCheckLis();
}
CargarPS();
//BtnGuardarAcercamiento.Visible = true;
}
}
#region "CARGA DATOS - TAB INFO"
protected void CargaDatos()
{
if (CveAcercamiento > 0)
{
ICRMService cRMService = new CRMService(System.Configuration.ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString);
RequestAcercamiento AcercamientoModel = new RequestAcercamiento(UsuarioActual.CveEmpresa, CveAcercamiento);
var objAcercamiento = cRMService.GetAceracamientoCRM(AcercamientoModel);
if (objAcercamiento.Result.Count > 0)
{
LblEncabezadoAcercamiento.Text = String.Format("<span class='bold' style='color: #32c5d2;'>{0}:</span> {1}", objAcercamiento.Result[0].TipoProceso.ToUpper(), objAcercamiento.Result[0].NombreAcercamiento.ToUpper());
CveTipoProceso = objAcercamiento.Result[0].CveTipoProceso.ToEntero();
RequestTipoProceso tipoProceso = new RequestTipoProceso(UsuarioActual.CveEmpresa, 1, CveTipoProceso);
var ObjTipoProceso = cRMService.GetTipoProcesoCRM(tipoProceso);
var responsetipoProceso = ObjTipoProceso.Result.FirstOrDefault();
if (responsetipoProceso != null)
{
DivComision.Visible = responsetipoProceso.RequiereComision;
DivMedioCaptacion.Visible = responsetipoProceso.RequiereMedioCaptacion;
DivImporte.Visible = responsetipoProceso.RequiereImporte;
DivProbabilidadAcercamiento.Visible = responsetipoProceso.RequiereProbabilidadAcercamiento;
DivPS.Visible = responsetipoProceso.RequierePS;
}
//SECCION DATOS DEL ACERCAMIENTO
TxtNombreAcercamiento.Text = objAcercamiento.Result[0].NombreAcercamiento;
TxtDescripcion.Text = objAcercamiento.Result[0].Descripcion;
TxtFechaApertura.Text = objAcercamiento.Result[0].FechaApertura.ToDateTime().ToShortDateString();
TxtFechaCierre.Text = (objAcercamiento.Result[0].FechaCierre.ToString() == "") || objAcercamiento.Result[0].FechaCierre.ToString().ToDate() == ModExtensiones.MinFecha ? "" : objAcercamiento.Result[0].FechaCierre.ToDateTime().ToShortDateString();
TxtImporte.Text = String.Format("{0:C2}", objAcercamiento.Result[0].Importe.ToEntero());
TxtComision.Text = String.Format("{0:C2}", objAcercamiento.Result[0].Comision.ToEntero());
DdlProbabilidadAcercamiento.SelectedValueExist(objAcercamiento.Result[0].CveProbabilidadAcercamiento);
DdlPrioridad.SelectedValueExist(objAcercamiento.Result[0].Prioridad);
ChkePausa.Checked = objAcercamiento.Result[0].EnPausa;
CargaDdl();
//SECCION DATOS DE LA EMPRESA
DdlEmpresaCRM.SelectedValueExist(objAcercamiento.Result[0].CveEmpresaCRM);
//SECCION DATOS DEL PROCESO
DdlEtapaProceso.SelectedValueExist(objAcercamiento.Result[0].CveEtapaProcesoActual);
DdlVendedor.SelectedValueExist(objAcercamiento.Result[0].CveVendedor);
DdlMedioCaptacion.SelectedValueExist(objAcercamiento.Result[0].CveMedioCaptacion);
//CARGA MODAL CIERRE-CANCELACION
TxtFechaCierreRechazo.Text = (objAcercamiento.Result[0].FechaCierre.ToString() == "") ? DateTime.Now.ToShortDateString() : objAcercamiento.Result[0].FechaCierre.ToDateTime().ToShortDateString();
DdlRechazoMotivo.SelectedValueExist(objAcercamiento.Result[0].CveRechazoMotivo);
TxtObservacionRechazo.Text = objAcercamiento.Result[0].ObservacionRechazo;
//CARGAMOS PARAMETROS
NombreAcercamiento = objAcercamiento.Result[0].NombreAcercamiento.ToUpper();
CveEmpresaCRM = objAcercamiento.Result[0].CveEmpresaCRM.ToEntero();
CveVendedorAsignado = objAcercamiento.Result[0].CveVendedor.ToEntero();
CveContactoPrincipal = (objAcercamiento.Result[0].CveTipoProceso.ToEntero() > 0) ? objAcercamiento.Result[0].CveContactoPrincipal.ToEntero() : -1;
CveEtapaActual = objAcercamiento.Result[0].CveEtapaProcesoActual.ToEntero();
CveEncuestaProcesoCRM = (objAcercamiento.Result[0].CveEncuestaProcesoCRM.ToEntero() > 0) ? objAcercamiento.Result[0].CveEncuestaProcesoCRM.ToEntero() : -1;
CveEncuestaAplicadaProceso = (objAcercamiento.Result[0].CveEncuestaAplicadaProceso.ToEntero() > 0) ? objAcercamiento.Result[0].CveEncuestaAplicadaProceso.ToEntero() : -1;
CvePS = objAcercamiento.Result[0].CvePS.ToEntero();
HdfEtapaSeleccionada.Value = CveEtapaActual.ToString();
//INHABILITAMOS CAMPOS QUE NO SE PUEDEN EDITAR
DdlEmpresaCRM.Enabled = false;
//MOSTRAMOS BOTONES
BtnGuardarAcercamiento.Text = "Actualizar";
BtnGuardarAcercamiento.Visible = true;
BtnEliminarAcercamiento.Visible = true;
}
else
{
Alert("La Empresa solicitada no existe, por favor revise su búsqueda.", ModExtensiones.TipoMensaje.MsgAdvertencia);
BtnGuardarAcercamiento.Enabled = false;
BtnEliminarAcercamiento.Enabled = false;
CveAcercamiento = -1;
CveEmpresaCRM = -1;
CveEtapaActual = -1;
CveTipoProceso = -1;
CveEncuestaProcesoCRM = -1;
CveEncuestaAplicadaProceso = -1;
}
if (CveAcercamiento > 0)
{
//CARGAMOS Y SELECCIONAMOS CONTACTO PRINCIPAL Y ETAPA ACTUAL
CargaContactos(CveEmpresaCRM);
CargaEtapasProceso(CveTipoProceso);
DdlContactoPrincipal.SelectedValueExist(CveContactoPrincipal);
DdlEtapaProceso.SelectedValueExist(CveEtapaActual);
DesactivaEdicion();
if (UsuarioActual.TienePermisoProceso(336)) //permiso para editar vendedor
{
DdlVendedor.Enabled = true;
}
if (CveEtapaActual > 0)
{
//CARGAMOS BITACORA
DivBitacora.Visible = true;
CargaEventoBitacora(HdfEtapaSeleccionada.Value.ToEntero());
}
else
{
CargaEventoBitacora(-1);
}
}
CargaImagenes();
UpEncabezado.Update();
UPAcercamiento.Update();
UPBitacoraEtapas.Update();
UPBitacora.Update();
UpGuardar.Update();
UpGaleria.Update();
}
}
protected void DesactivaEdicion()
{
TxtNombreAcercamiento.Enabled = false;
TxtDescripcion.Enabled = false;
TxtFechaApertura.Enabled = false;
CETxtFechaApertura.EnabledOnClient = false;
DdlVendedor.Enabled = false;
}
protected void InicializaDatos()
{
NumeroEtapasProceso = -1;
CveEtapaActual = -1;
CveAcercamiento = -1;
CveEmpresaCRM = -1;
CveTipoProceso = -1;
CveEncuestaProcesoCRM = -1;
CveEncuestaAplicadaProceso = -1;
RecuperaCve();
TxtFechaApertura.Text = DateTime.Now.ToShortDateString();
}
protected void RecuperaCve()
{
if (Request["CveAcercamiento"] != null && !Request["CveAcercamiento"].ToString().Equals("") && Request["CveAcercamiento"].ToEntero() > 0)
{
ViewState["CveAcercamiento"] = Request["CveAcercamiento"];
}
else
{
ViewState["CveAcercamiento"] = -1;
}
}
protected void CargaDdl()
{
ICRMService cRMService = new CRMService(System.Configuration.ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString);
RequestProbalidadAcercamiento ProbalidadAcercamiento = new RequestProbalidadAcercamiento(UsuarioActual.CveEmpresa, 1);
var ObjProbalidadAcercamiento = cRMService.GetProbabilidadAceracamientoCRM(ProbalidadAcercamiento);
RequestEmpresasCRM EmpresaCRM = new RequestEmpresasCRM(UsuarioActual.CveEmpresa, -1);
var objEmpresaCRM = cRMService.GetEmpresasCRM(EmpresaCRM);
RequestMedioCaptacion MedioCaptacion = new RequestMedioCaptacion(UsuarioActual.CveEmpresa);
var ObjMedioCaptacion = cRMService.GetMedioCaptacionCRM(MedioCaptacion);
if (ObjProbalidadAcercamiento.Result.Count > 0)
{
DataTable DtProbabilidadAcercamiento = ObjProbalidadAcercamiento.Result.ToDataTable();
DdlProbabilidadAcercamiento.DataSource = DtProbabilidadAcercamiento.FiltraParametros(String.Format("CveTipoProceso = {0}", CveTipoProceso));
}
if (objEmpresaCRM.Result.Count > 0)
{
DdlEmpresaCRM.DataSource = objEmpresaCRM.Result;
DdlEmpresaCRM.Items.Insert(0, new ListItem("Seleccione ", "-1"));
}
if (ObjMedioCaptacion.Result.Count > 0)
{
DataTable DTMedioCaptacion = ObjMedioCaptacion.Result.ToDataTable();
DdlMedioCaptacion.DataSource = DTMedioCaptacion.FiltraParametros(String.Format("CveTipoProceso = {0}", CveTipoProceso));
DdlMedioCaptacion.Items.Insert(0, new ListItem("Seleccione ", "-1"));
}
DdlVendedor.DataSource = get_GlobalDTVendedores(UsuarioActual.CveEmpresa);
DdlProbabilidadAcercamiento.DataBind();
DdlEmpresaCRM.DataBind();
DdlVendedor.DataBind();
DdlMedioCaptacion.DataBind();
}
protected void CargaRechazosMotivos()
{
ICRMService cRMService = new CRMService(System.Configuration.ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString);
RequestRechazoMotivo RequestRechazoMotivo = new RequestRechazoMotivo(UsuarioActual.CveEmpresa, 1, CveTipoProceso);
var objRequestRechazoMotivo = cRMService.GetRechazoMotivoCRM(RequestRechazoMotivo);
if (objRequestRechazoMotivo.Result.Count > 0)
{
DdlRechazoMotivo.DataSource = objRequestRechazoMotivo.Result;
DdlRechazoMotivo.Items.Insert(0, new ListItem("Seleccione ", "-1"));
}
DdlRechazoMotivo.DataBind();
}
protected void CargarTiposEventosBitacora()
{
ClsOIEventos ObjEventos = new ClsOIEventos();
if (ObjEventos.GetAgendaTipo())
{
DdlTipoAgenda.DataSource = ObjEventos.DtResultados;
DdlTipoAgenda.DataBind();
}
ObjEventos.Dispose();
limpiarModalAgendar();
}
protected void DdlEmpresaCRM_SelectedIndexChanged(object sender, EventArgs e)
{
if (DdlEmpresaCRM.SelectedValue.ToEntero() > 0)
{
CargaContactos(DdlEmpresaCRM.SelectedValue.ToEntero());
UPAcercamiento.Update();
}
}
protected void CargaContactos(int CveEmpresaCRM)
{
DdlContactoPrincipal.Items.Clear();
ICRMService cRMService = new CRMService(System.Configuration.ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString);
RequestContactoEmpresaCRM contactoEmpresaCRM = new RequestContactoEmpresaCRM(CveEmpresaCRM, UsuarioActual.CveEmpresa);
var objcontactoEmpresa = cRMService.GetContactosEmpresasCRM(contactoEmpresaCRM);
if (objcontactoEmpresa.Result.Count > 0)
{
DdlContactoPrincipal.DataSource = objcontactoEmpresa.Result;
DdlContactoAgenda.DataSource = objcontactoEmpresa.Result;
}
DdlContactoPrincipal.Items.Insert(0, new ListItem("Seleccione ", "-1"));
DdlContactoAgenda.Items.Insert(0, new ListItem("Seleccione ", "-1"));
//ObjCRM.Dispose();
DdlContactoPrincipal.DataBind();
DdlContactoAgenda.DataBind();
DdlContactoAgenda.SelectedValueExist(CveContactoPrincipal);
}
//protected void DdlTipoProceso_SelectedIndexChanged(object sender, EventArgs e)
//{
// if (DdlTipoProceso.SelectedValue.ToEntero() > 0)
// {
// CargaEtapasProceso(DdlTipoProceso.SelectedValue.ToEntero());
// UPAcercamiento.Update();
// }
//}
protected void CargaEtapasProceso(int CveTipoProceso)
{
//DDLs
DdlEtapaProceso.Items.Clear();
ICRMService cRMService = new CRMService(System.Configuration.ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString);
RequestEtapaProceso EtapaProceso = new RequestEtapaProceso(UsuarioActual.CveEmpresa, 1, CveTipoProceso);
var ObjEtapaProceso = cRMService.GetEtapaProcesoCRM(EtapaProceso);
if (ObjEtapaProceso.Result.Count > 0)
{
DTEtapasProceso = ObjEtapaProceso.Result.ToDataTable();
OrdenEtapaActual = DTEtapasProceso.FiltroPrimeroValor("Orden", String.Format("CveEtapaProceso = {0}", CveEtapaActual)).ToEntero();
//SI LA ETAPA ES CANCELACION HABILITA MOSTRAR LAS DOS ETAPAS ANTERIORES
if (DTEtapasProceso.FiltroPrimeroValor("CveEtapaProceso", String.Format("CveEtapaProceso = {0} AND CveTipoEtapa = 4", CveEtapaActual)).ToEntero() > 0)
{
DdlEtapaProceso.DataSource = DTEtapasProceso.FiltraParametros(String.Format("( Orden >= {0} ) AND ( Orden <= {1} )", (OrdenEtapaActual - 2), (OrdenEtapaActual + 1)));
}
else
{
DdlEtapaProceso.DataSource = DTEtapasProceso.FiltraParametros(String.Format("(( Orden >= {0} ) AND ( Orden <= {1} )) OR (CveTipoEtapa = 4)", (OrdenEtapaActual - 1), (OrdenEtapaActual + 1)));
}
}
DdlEtapaProceso.DataBind();
}
protected void DdlEtapaProceso_SelectedIndexChanged(object sender, EventArgs e)
{
if (ActivaFechaCierre(DdlEtapaProceso.SelectedValue.ToEntero()))
{
TxtFechaCierre.Text = DateTime.Now.ToShortDateString();
}
else
{
TxtFechaCierre.Text = "";
if (DTEtapasProceso.FiltraParametros(String.Format("CveEtapaProceso = {0} AND CveTipoEtapa = 4", DdlEtapaProceso.SelectedValue.ToEntero())).Rows.Count > 0)
{
LnkCerrarAcercamiento_Click(null, null);
}
}
//AUTOGUARDADO DE CAMBIO DE ETAPA
if (DTEtapasProceso.FiltroPrimeroValor("CveTipoEtapa", String.Format("CveEtapaProceso = {0}", DdlEtapaProceso.SelectedValue.ToEntero())).Contiene("1", "2", "3"))
GuardarCambioEtapa();
}
private void CargarPS()
{
DdlPS.setEsWebService(true);
if (CvePS > 0)
{
string productoAsignado = get_GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CvePS: CvePS).FiltroPrimeroValor("PSCodigo");
DdlPS.SelectedValue = CvePS.ToString();
DdlPS.SelectedText = productoAsignado;
}
}
#endregion
#region "GUARDAR"
protected void BtnGuardarAcercamiento_Click(object sender, EventArgs e)
{
if (CveAcercamiento > 0)
{
ClsCRM ObjCRM = new ClsCRM();
ICRMService cRMService = new CRMService(System.Configuration.ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString);
AcercaminetoModel AcercaminetoModel = new AcercaminetoModel();
ClsEncuestas ObjDatosTecnicos = new ClsEncuestas(ObjCRM.IniciaTransacSQL());
//ClsOIEventos ObjBitacora = new ClsOIEventos(ObjCRM.IniciaTransacSQL());
Boolean HuboError = true;
String NombreAcercamiento = TxtNombreAcercamiento.Text;
String Descripcion = TxtDescripcion.Text == "" ? "-1" : TxtDescripcion.Text;
int CveEtapaProcesoActualActualizar = DdlEtapaProceso.SelectedValue.ToEntero();
int CveContactoPrincipal = DdlContactoPrincipal.SelectedValue.ToEntero();
int CveVendedor = DdlVendedor.SelectedValue.ToEntero();
int CveMedioCaptacion = DdlMedioCaptacion.SelectedValue.ToEntero();
int CveProbabilidadAcercamiento = DdlProbabilidadAcercamiento.SelectedValue.ToEntero();
//SE ACTUALIZARA CUANDO SE ACTUALIZE A FIN PROCESO CON ETAPA 4
//int CveRechazoMotivo = -1;
DateTime FechaApertura = TxtFechaApertura.Text.ToDateTime();
//FECHA CIERRE SE ENVIARA HASTA QUE LA ETAPA SEA ETAPA TIPO 3 O 4
DateTime? FechaCierre = null;
if (DTEtapasProceso.FiltraParametros(String.Format("CveEtapaProceso = {0} AND CveTipoEtapa IN(3, 4)", CveEtapaProcesoActualActualizar)).Rows.Count > 0)
{
FechaCierre = TxtFechaCierre.Text != "" ? TxtFechaCierre.Text.ToDateTime() : DateTime.Now;
}
Double Importe = TxtImporte.Text.ToDouble();
Double Comision = TxtComision.Text.ToDouble();
int Prioridad = DdlPrioridad.SelectedValue.ToEntero();
int CveRechazoMotivo = DdlRechazoMotivo.SelectedValue.ToEntero();
int CveUsuarioIng = UsuarioActual.CveUsuario;
if (CveEncuestaProcesoCRM > 0)
{
CveEncuestaAplicadaProceso = GuardaDatosTecnicos(ObjDatosTecnicos, CveEncuestaAplicadaProceso);
}
AcercaminetoModel.CveAcercamiento = CveAcercamiento;
AcercaminetoModel.CveContactoPrincipal = CveContactoPrincipal;
AcercaminetoModel.CveTipoProceso = CveTipoProceso;
AcercaminetoModel.CveEtapaProcesoActual = CveEtapaProcesoActualActualizar;
AcercaminetoModel.CveVendedor = CveVendedor;
AcercaminetoModel.CveMedioCaptacion = CveMedioCaptacion;
AcercaminetoModel.CveProbabilidadAcercamiento = CveProbabilidadAcercamiento;
AcercaminetoModel.NombreAcercamiento = NombreAcercamiento;
AcercaminetoModel.Descripcion = Descripcion;
AcercaminetoModel.Importe = Importe;
AcercaminetoModel.Comision = Comision;
AcercaminetoModel.Prioridad = Prioridad;
AcercaminetoModel.CveUsuarioIng = UsuarioActual.CveUsuario;
AcercaminetoModel.CveEncuestaAplicadaProceso = CveEncuestaAplicadaProceso;
AcercaminetoModel.FechaApertura = FechaApertura;
AcercaminetoModel.FechaCierre = FechaCierre != null ? (DateTime)FechaCierre : ModExtensiones.MinFecha;
AcercaminetoModel.CvePS = DdlPS.SelectedValue.ToEntero();
AcercaminetoModel.CveRechazoMotivo = CveRechazoMotivo;
AcercaminetoModel.EnPausa = ChkePausa.Checked;
if (cRMService.AcercamientoUpdate(AcercaminetoModel))
{
//String MensajeBitacora = (CveEtapaProcesoActualActualizar != CveEtapaActual) ? String.Format("Se actualizó la etapa del acercamiento a {0}.", DTEtapasProceso.FiltroPrimeroValor("EtapaProceso", "CveEtapaProceso = " + CveEtapaProcesoActualActualizar)) : String.Format("Se actualizó el Acercamiento {0} con Vendedor {2} y Contacto Principal {3}.", NombreAcercamiento, DdlTipoProceso.SelectedItem, DdlVendedor.SelectedItem, DdlContactoPrincipal.SelectedValue == "-1" ? "aun no asignado" : DdlContactoPrincipal.SelectedItem.Text);
//if (ObjBitacora.AddEventoBitacora(MensajeBitacora, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveTipoProcesoCRM: CveTipoProceso, CveAcercamientoCRM: CveAcercamiento, CveContactoCRM: CveContactoPrincipal, CveEtapaProcesoCRM: CveEtapaProcesoActualActualizar))
//{
HuboError = false;
CveEtapaActual = CveEtapaProcesoActualActualizar;
HdfEtapaSeleccionada.Value = CveEtapaProcesoActualActualizar.ToString();
Alert(String.Format("Se actualizó el acercamiento {0} de tipo {1}.", NombreAcercamiento, TipoProceso), ModExtensiones.TipoMensaje.MsgInformacion);
//}
}
ObjDatosTecnicos.Dispose();
//CARGA BITACORA
if (!HuboError)
{
LblEncabezadoAcercamiento.Text = String.Format("<span class='bold' style='color: #32c5d2;'>{0}:</span> {1}", TipoProceso.ToUpper(), NombreAcercamiento.ToUpper());
CargaEtapasProceso(CveTipoProceso);
CargaEtapasBitacora();
CargaEventoBitacora(CveEtapaProcesoActualActualizar);
UpEncabezado.Update();
UPAcercamiento.Update();
UPBitacoraEtapas.Update();
UPBitacora.Update();
DdlEtapaProceso.SelectedValueExist(CveEtapaActual);
}
}
}
protected void GuardarCambioEtapa()
{
ICRMService cRMService = new CRMService(System.Configuration.ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString);
AcercaminetoModel AcercaminetoModel = new AcercaminetoModel();
String NombreAcercamiento = TxtNombreAcercamiento.Text;
String Descripcion = TxtDescripcion.Text == "" ? "-1" : TxtDescripcion.Text;
int CveEtapaProcesoActualActualizar = DdlEtapaProceso.SelectedValue.ToEntero();
int CveContactoPrincipal = DdlContactoPrincipal.SelectedValue.ToEntero();
int CveVendedor = DdlVendedor.SelectedValue.ToEntero();
int CveMedioCaptacion = DdlMedioCaptacion.SelectedValue.ToEntero();
int CveProbabilidadAcercamiento = DdlProbabilidadAcercamiento.SelectedValue.ToEntero();
DateTime FechaApertura = TxtFechaApertura.Text.ToDateTime();
DateTime? FechaCierre = null;
if (DTEtapasProceso.FiltraParametros(String.Format("CveEtapaProceso = {0} AND CveTipoEtapa IN(3, 4)", CveEtapaProcesoActualActualizar)).Rows.Count > 0)
{
FechaCierre = TxtFechaCierre.Text != "" ? TxtFechaCierre.Text.ToDateTime() : DateTime.Now;
}
Double Importe = TxtImporte.Text.ToDouble();
Double Comision = TxtComision.Text.ToDouble();
int Prioridad = DdlPrioridad.SelectedValue.ToEntero();
int CveRechazoMotivo = DdlRechazoMotivo.SelectedValue.ToEntero();
int CveUsuarioIng = UsuarioActual.CveUsuario;
AcercaminetoModel.CveAcercamiento = CveAcercamiento;
AcercaminetoModel.CveContactoPrincipal = CveContactoPrincipal;
AcercaminetoModel.CveTipoProceso = CveTipoProceso;
AcercaminetoModel.CveEtapaProcesoActual = CveEtapaProcesoActualActualizar;
AcercaminetoModel.CveVendedor = CveVendedor;
AcercaminetoModel.CveMedioCaptacion = CveMedioCaptacion;
AcercaminetoModel.CveProbabilidadAcercamiento = CveProbabilidadAcercamiento;
AcercaminetoModel.NombreAcercamiento = NombreAcercamiento;
AcercaminetoModel.Descripcion = Descripcion;
AcercaminetoModel.Importe = Importe;
AcercaminetoModel.Comision = Comision;
AcercaminetoModel.Prioridad = Prioridad;
AcercaminetoModel.CveUsuarioIng = UsuarioActual.CveUsuario;
AcercaminetoModel.CveEncuestaAplicadaProceso = CveEncuestaAplicadaProceso;
AcercaminetoModel.FechaApertura = FechaApertura;
AcercaminetoModel.FechaCierre = FechaCierre != null ? (DateTime)FechaCierre : ModExtensiones.MinFecha;
AcercaminetoModel.CvePS = DdlPS.SelectedValue.ToEntero();
AcercaminetoModel.CveRechazoMotivo = CveRechazoMotivo;
if (cRMService.AcercamientoUpdate(AcercaminetoModel))
{
CveEtapaActual = CveEtapaProcesoActualActualizar;
HdfEtapaSeleccionada.Value = CveEtapaProcesoActualActualizar.ToString();
}
else
{
Alert("No se actualizó el acercamiento.", ModExtensiones.TipoMensaje.ToastError);
}
//CARGA BITACORA
CargaEtapasProceso(CveTipoProceso);
CargaEtapasBitacora();
CargaEventoBitacora(CveEtapaProcesoActualActualizar);
DdlEtapaProceso.SelectedValueExist(CveEtapaProcesoActualActualizar);
UPAcercamiento.Update();
UPBitacoraEtapas.Update();
UPBitacora.Update();
}
#endregion
#region "ELIMINAR ACERCAMIENTO"
protected void BtnEliminarAcercamiento_Click(object sender, EventArgs e)
{
EliminarAcercamiento();
}
protected void EliminarAcercamiento()
{
Boolean HuboError = true;
ClsCRM ObjCRM = new ClsCRM();
ClsOIEventos objBitacora = new ClsOIEventos(ObjCRM.IniciaTransacSQL());
ICRMService cRMService = new CRMService(System.Configuration.ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString);
RequestAcercamiento acercamiento = new RequestAcercamiento(UsuarioActual.CveEmpresa, CveAcercamiento);
if (TieneCotizacion)
{
if (cRMService.AcercamientoDelete(acercamiento))
{
if (objBitacora.AddEventoBitacora(String.Format("Se eliminó el Acercamiento {0} de tipo {1}", NombreAcercamiento, TipoProceso), "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveEmpresaCRM: CveEmpresaCRM))
{
HuboError = false;
}
}
if (!HuboError)
{
Alert("El Acercamiento ha sido eliminado.", ModExtensiones.TipoMensaje.MsgInformacion, String.Format("document.location.href=\"/CRM/EmpresaCRM.aspx?CveEmpresaCRM={0}\"", CveEmpresaCRM));
}
}
else
{
Alert("No se puede eliminar el acercamiento porque el prospecto cuenta con cotizaciones/facturaciones previas.", ModExtensiones.TipoMensaje.MsgError);
}
objBitacora.Dispose();
}
#endregion
#region "FINALIZACION DE ACERCAMIENTO"
protected void ActivaOpcionCierreCancelacion()
{
// ACTIVAMOS OPCION CIERRE POR CANCELACION SI SE CREO ESTA ETAPA EN EL PROCESO
if (DTEtapasProceso.FiltraParametros("CveTipoEtapa = 4").Rows.Count > 0)
{
String TituloCierre = DTEtapasProceso.FiltroPrimeroValor("EtapaProceso", "CveTipoEtapa = 4");
LnkCerrarAcercamiento.Visible = true;
SpanTituloCierre.InnerText = TituloCierre;
}
else
{
LnkCerrarAcercamiento.Visible = false;
}
//UpAcciones.Update();
}
protected Boolean ActivaFechaCierre(int CveEtapaProceso)
{
Boolean activar = DTEtapasProceso.FiltraParametros(String.Format("CveEtapaProceso = {0} AND CveTipoEtapa = 3", CveEtapaProceso)).Rows.Count > 0;
if (activar)
{
TxtFechaCierre.Enabled = true;
CETxtFechaCierre.EnabledOnClient = true;
}
else
{
TxtFechaCierre.Enabled = false;
CETxtFechaCierre.EnabledOnClient = false;
}
return activar;
}
protected void LnkCerrarAcercamiento_Click(object sender, EventArgs e)
{
String TituloCierre = DTEtapasProceso.FiltroPrimeroValor("EtapaProceso", "CveTipoEtapa = 4");
int CveEtapaCierre = DTEtapasProceso.FiltroPrimeroValor("CveEtapaProceso", String.Format("CveTipoEtapa = 4", CveEtapaActual)).ToEntero();
if (CveEtapaCierre != CveEtapaActual)
{
TituloModalCierreMotivoRechazo.InnerText = String.Format("Registro de {0}", TituloCierre);
BtnRegistrarCierreCancelacion.Text = "Guardar";
}
else
{
TituloModalCierreMotivoRechazo.InnerText = String.Format("Editar {0}", TituloCierre);
BtnRegistrarCierreCancelacion.Text = "Actualizar";
}
this.RegistraScript("$('#ModalCierreMotivoRechazo').modal();");
UpCierreMotivoRechazo.Update();
}
protected void EliminarFile(object sender, EventArgs e)
{
}
protected void BtnRegistrarCierreCancelacion_Click(object sender, EventArgs e)
{
//ClsCRM ObjCRM = new ClsCRM();
ICRMService cRMService = new CRMService(System.Configuration.ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString);
//ClsOIEventos ObjBitacora = new ClsOIEventos(ObjCRM.IniciaTransacSQL());
//Boolean HuboError = true;
int CveEtapaCierre = DTEtapasProceso.FiltroPrimeroValor("CveEtapaProceso", "CveTipoEtapa = 4").ToEntero();
int CveRechazoMotivo = DdlRechazoMotivo.SelectedValue.ToEntero();
DateTime FechaCierre = TxtFechaCierreRechazo.Text.ToDateTime();
string Observacion = TxtObservacionRechazo.Text;
String TituloCierre = DTEtapasProceso.FiltroPrimeroValor("EtapaProceso", "CveTipoEtapa = 4");
AcercaminetoModel acercamiento = new AcercaminetoModel();
acercamiento.CveAcercamiento = CveAcercamiento;
acercamiento.CveEtapaProcesoActual = CveEtapaCierre;
acercamiento.CveRechazoMotivo = CveRechazoMotivo;
acercamiento.CveUsuarioIng = UsuarioActual.CveUsuario;
acercamiento.FechaCierre = FechaCierre;
acercamiento.ObservacionRechazo = Observacion;
if (cRMService.AcercamientoCierreUpdate(acercamiento))
{
String MensajeBitacora = "";
if (CveEtapaActual == CveEtapaCierre)
MensajeBitacora = String.Format("Se actualizó el cierre del acercamiento, con motivo {1} y fecha de {0} al {2}.", TituloCierre, DdlRechazoMotivo.SelectedItem.Text, TxtFechaCierreRechazo.Text);
else
MensajeBitacora = String.Format("Se Cerró el acercamiento, con motivo {1} y fecha de {0} al {2}.", TituloCierre, DdlRechazoMotivo.SelectedItem.Text, TxtFechaCierreRechazo.Text);
//if (ObjBitacora.AddEventoBitacora(MensajeBitacora, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveTipoProcesoCRM: CveTipoProceso, CveAcercamientoCRM: CveAcercamiento, CveEtapaProcesoCRM: CveEtapaCierre))
//{
//HuboError = false;
Alert(MensajeBitacora, ModExtensiones.TipoMensaje.MsgInformacion);
//}
}
//if (!HuboError) { ObjCRM.Commit(); } else { ObjCRM.RollBack(); }
//ObjCRM.Dispose();
//ObjBitacora.Dispose();
CveEtapaActual = CveEtapaCierre;
CargaDatos();
CargaEtapasBitacora();
this.RegistraScript("$('#ModalCierreMotivoRechazo').modal('hide');");
}
#endregion
#region "STEPS - ETAPAS DE PROCESO PARA BITACORA "
protected void CargaEtapasBitacora()
{
//CARGA STEP DE PASOS
//ClsCRM ObjCRM = new ClsCRM();
ICRMService cRMService = new CRMService(System.Configuration.ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString);
RequestEtapaProceso EtapaProceso = new RequestEtapaProceso(UsuarioActual.CveEmpresa, 1, CveTipoProceso);
var ObjEtapaProceso = cRMService.GetEtapaProcesoCRM(EtapaProceso);
if (ObjEtapaProceso.Result.Count > 0)
{
DataTable DTTemp = ObjEtapaProceso.Result.ToDataTable();
TipoProceso = DTTemp.FiltroPrimeroValor("TipoProceso").ToUpper();
int CveEtapaCierreCancelacion = DTEtapasProceso.FiltroPrimeroValor("CveEtapaProceso", "CveTipoEtapa = 4").ToEntero();
NumeroEtapasProceso = DTTemp.FiltraParametros("CveTipoEtapa IN(1,2,3)").Rows.Count;
//RptTabsEtapasProcesos.DataSource = ObjCRM.DtResultados.FiltraParametros("CveTipoEtapa IN(1,2,3)");
if (CveEtapaCierreCancelacion == CveEtapaActual)
RptStepsEtapasProceso.DataSource = DTTemp.FiltraParametros("CveTipoEtapa IN(1,2,4)");
else
RptStepsEtapasProceso.DataSource = DTTemp.FiltraParametros("CveTipoEtapa IN(1,2,3)");
}
//ObjCRM.Dispose();
//RptTabsEtapasProcesos.DataBind();
RptStepsEtapasProceso.DataBind();
//SpanProceso.InnerText = TipoProceso + ":";
}
protected void RptStepsEtapasProceso_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView row = (DataRowView)e.Item.DataItem;
//VALIDACION DE CLASES DE COMPONENTE DIVETAPARPT
//- CLASES OBLIGATORIAS: col-md-n, mt-step-col , SIENDO N EL NUMERO DE ETAPAS.
// MAS DE 6 ETAPAS NO SE RECOMIENDA POR ESTETICA PERO ES FUNCIONAL.MAS DE 12 DISTORCIONAN LA DISTRUBUCION DEL COMPONENTE,
//- CLASES OPCIONALES APARIENCIA Y COMPORTAMIENTO DEL STEP: first, last, error, done, active, enabled, disabled, active, etapaactual
//ASIGNACION CLASES OBLIGATORIAS
String DivStepClases = String.Format("col-md-{0} mt-step-col", (12 / NumeroEtapasProceso) == 0 ? 1 : (12 / NumeroEtapasProceso));
// CALCULO DE ESPACIOS PARA CENTRADO
if (NumeroEtapasProceso.Contiene(5, 9, 10) && row["CveTipoEtapa"].ToEntero() == 1)
DivStepClases += " col-md-offset-1";
else if (NumeroEtapasProceso.Contiene(7, 8) && row["CveTipoEtapa"].ToEntero() == 1)
DivStepClases += " col-md-offset-2";
//VERIFICA SI ES ETAPA DE TIPO INICIAL o CIERRE
if (row["CveTipoEtapa"].ToEntero() == 1)
{
DivStepClases += " first";
}
else if (row["CveTipoEtapa"].ToEntero().Contiene(3, 4))
{
DivStepClases += " last";
//VERIFICA SI ES ETAPA DE TIPO CIERRE CANCELADO
if (row["CveTipoEtapa"].ToEntero() == 4)
DivStepClases += " error";
}
//VERIFICA SI ES UNA ETAPA YA REALIZADA
if (OrdenEtapaActual > row["Orden"].ToEntero())
DivStepClases += " done";
//VERIFICA EL ORDEN DE LA ETAPA PARA PERMITIR SU SELECCION
if (OrdenEtapaActual < row["Orden"].ToEntero())
DivStepClases += " disabled";
else
DivStepClases += " enabled";
//ESTABLE SI LA ETAPA ACTUAL ES LA SELECCIONADA
if (HdfEtapaSeleccionada.Value.ToEntero() == row["CveEtapaProceso"].ToEntero())
DivStepClases += " active";
//PINTA LA ETAPA SI ES LA ETAPA ACTUAL
if (CveEtapaActual == row["CveEtapaProceso"].ToEntero())
DivStepClases += " etapaactual";
//SE LE ASIGNAN LAS CLASES AL DIV DIVETAPARPT
((HtmlGenericControl)(e.Item.FindControl("DivEtapaRpt"))).Attributes["class"] += DivStepClases;
}
}
#endregion
#region "BITACORA - ARCHIVOS"
protected void BtnCambiaEtapaBitacora_Click(object sender, EventArgs e)
{
GVEventoBitacora.Columns[0].Visible = false;
CargaEventoBitacora(HdfEtapaSeleccionada.Value.ToEntero());
}
protected void LbtVerBitacoraCompleta_Click(object sender, EventArgs e)
{
GVEventoBitacora.Columns[0].Visible = true;
CargaEventoBitacora(-1);
HdfEtapaSeleccionada.Value = "-1";
CargaEtapasBitacora();
UPBitacoraEtapas.Update();
UPBitacora.Update();
}
private void CargaEventoBitacora(int CveEtapa)
{
ClsOIEventos ObjEventoBitacora = new ClsOIEventos();
string EtapaSeleccionada = CveEtapa > 0 ? DTEtapasProceso.FiltroPrimeroValor("EtapaProceso", "CveEtapaProceso = " + CveEtapa) : "";
TituloBitacora.InnerText = String.Format("Bitacora {0}", (CveEtapa > 0 ? (String.Format(" ({0})", EtapaSeleccionada)) : ""));
if (ObjEventoBitacora.GetAgendaBitacora(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveAcercamientoCRM: CveAcercamiento))
{
DTEventosBitacora = ObjEventoBitacora.DtResultados.FiltraParametros("[CveTipoEvento] = 6 OR [CveTipoEvento] = 2");
if (CveEtapa == -1)
{
GVEventoBitacora.DataSource = DTEventosBitacora.FiltraParametros(String.Format("[Archivo] = '' OR [Archivo] IS NULL OR CONVERT([Descripcion],System.String) LIKE 'Check List%'", CveEtapa));
RptArchivosBitacora.DataSource = DTEventosBitacora.FiltraParametros(String.Format("[Archivo] <> '' AND CONVERT([Descripcion],System.String) NOT LIKE 'Check List%'", CveEtapa));
}
else
{
GVEventoBitacora.DataSource = DTEventosBitacora.FiltraParametros(String.Format("[CveEtapaProcesoCRM] = {0} AND ( [Archivo] = '' OR [Archivo] IS NULL ) OR CONVERT([Descripcion],System.String) LIKE 'Check List%'", CveEtapa));
RptArchivosBitacora.DataSource = DTEventosBitacora.FiltraParametros(String.Format("[CveEtapaProcesoCRM] = {0} AND [Archivo] <> '' AND CONVERT([Descripcion],System.String) NOT LIKE 'Check List%'", CveEtapa));
}
}
else
{
GVEventoBitacora.DataSource = null;
}
ObjEventoBitacora.Dispose();
GVEventoBitacora.DataBind();
RptArchivosBitacora.DataBind();
UPBitacora.Update();
}
protected void GVEventoBitacora_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowIndex == 0)
{
e.Row.Cells[1].Width = Unit.Pixel(150);
e.Row.Cells[2].Width = Unit.Pixel(150);
}
if (e.Row.DataKey("CveEtapaProcesoCRM").ToString().ToEntero() > 0)
{
e.Row.FCLabel("LblEtapa").Text = DTEtapasProceso.FiltroPrimeroValor("EtapaProceso", String.Format("CveEtapaProceso = {0}", e.Row.DataKey("CveEtapaProcesoCRM")));
}
if ((e.Row.DataKey("PosicionGPS").ToString() != ""))
{
e.Row.FCLinkButton("LnkVerUbicacion").Visible = true;
}
}
}
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;
}
protected void BtnGuardarEventoBitacora_Click(object sender, EventArgs e)
{
ClsOIEventos ObjEventoBitacora = new ClsOIEventos();
string FileExtension = "-1";
List<Archivo> filesgral = Anexo.getfiles().Archivos;
string filemove = "";
int CveEtapa = HdfEtapaSeleccionada.Value.ToEntero() == -1 ? CveEtapaActual : HdfEtapaSeleccionada.Value.ToEntero();
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, CveTipoProcesoCRM: CveTipoProceso, CveAcercamientoCRM: CveAcercamiento, CveEtapaProcesoCRM: CveEtapa))
{
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();
UPAddEventoBitacora.Update();
//RECARGAMOS GRID BITACORA
CargaEventoBitacora(HdfEtapaSeleccionada.Value.ToEntero());
UPBitacora.Update();
}
protected void BtnGuardarAgenda_Click(object sender, EventArgs e)
{
ClsOIEventos ObjEventos = new ClsOIEventos();
DateTime FechaInicio = TxtFechaInicioAgenda.Text.ToDateTime();
int CveContactoAgendar = DdlContactoAgenda.SelectedValue.ToEntero();
int CveEmpresaCRM = DdlEmpresaCRM.SelectedValue.ToEntero();
int CveEtapa = HdfEtapaSeleccionada.Value.ToEntero() == -1 ? CveEtapaActual : HdfEtapaSeleccionada.Value.ToEntero();
string AgendaDescripcion = $"<a class='Texto' href='/CRM/Acercamiento.aspx?CveAcercamiento={CveAcercamiento}' target='_blank' >{ TxtNombreAcercamiento.Text.Trim()}</a> {TxtDescripcionAgenda.Text.Trim()}";
if (ObjEventos.AddEventoAgenda(DdlTipoAgenda.SelectedValue.ToEntero(), TxtAsuntoAgenda.Text, AgendaDescripcion, DdlPrioridadAgenda.SelectedValue.ToEntero(), FechaInicio, FechaInicio, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveTipoProcesoCRM: CveTipoProceso, CveAcercamientoCRM: CveAcercamiento, CveContactoCRM: CveContactoAgendar, CveEtapaProcesoCRM: CveEtapa, CveEmpresaCRM: CveEmpresaCRM))
{
limpiarModalAgendar();
RegistraScript("$('#ModalAgenda').modal('hide')");
Alert("El Evento se agendó correctamente", ModExtensiones.TipoMensaje.MsgInformacion);
}
ObjEventos.Dispose();
//RECARGAMOS GRID BITACORA
CargaEventoBitacora(HdfEtapaSeleccionada.Value.ToEntero());
UPBitacora.Update();
}
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 RptArchivosBitacora_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView row = (DataRowView)e.Item.DataItem;
if (row["Archivo"].ToString() != "")
{
e.Item.FindControl("LinkArchivo").Visible = true;
((LinkButton)e.Item.FindControl("LinkArchivo")).CommandArgument = string.Format(@"OI\{0}", row["Archivo"].ToString());
ScriptManager.GetCurrent(this).RegisterPostBackControl(e.Item.FindControl("LinkArchivo")); // Registro un evento Postbacktrigger, que recargue toda la pagina para que funcione
((Label)e.Item.FindControl("LblTipoArchivo")).Text = row["Archivo"].ToString().Split('.')[1].ToUpper();
}
}
// VALIDAMOS PARA MOSTRAR EL FOOTER CON EL TEXT DE DATOS NO ENCONTRADOS
Repeater rptDemo = sender as Repeater;
if (RptArchivosBitacora != null && RptArchivosBitacora.Items.Count < 1)
{
if (e.Item.ItemType == ListItemType.Footer)
{
Label LblEmptyRpt = e.Item.FindControl("LblEmptyRpt") as Label;
if (LblEmptyRpt != null)
{
e.Item.FindControl("DivRptArchivoBitacoraEmpty").Visible = true;
}
}
}
}
#endregion
#region "PERMISOS"
protected void VerificaPermisosEdicion()
{
if (!UsuarioActual.TienePermisoProceso(252))
{
BtnEliminarAcercamiento.Visible = false;
}
//SOLO VENDEDOR ASIGNADO PUEDE EDITAR
if (CveVendedorAsignado != UsuarioActual.CveVendedor)
{
BtnGuardarAcercamiento.Visible = false;
BtnEliminarAcercamiento.Visible = false;
DivAccionesBitacoraActividades.Visible = false;
DivAccionesBitacoraArchivos.Visible = false;
LnkCerrarAcercamiento.Visible = false;
HplAgregarCotizacion.Visible = false;
UpAddCotizacion.Update();
}
}
#endregion
#region "TAB DATOS TECNICOS"
protected void CargaDatosTecnicos()
{
var encuestaService = new EncuestaService(System.Configuration.ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString);
var responseGenericGetRespuestas = encuestaService.GetRespuestas(CveEncuestaProcesoCRM);
if (responseGenericGetRespuestas.IsSuccess)
{
DTRespuestasDatosTecnicos = responseGenericGetRespuestas.Result.ToDataTable();
}
var responseGenericGetDatosTecnicosEmpresaCRM = encuestaService.GetDatosTecnicosEmpresaCRM(new RequestDatosTecnicosEmpresaCRMGet() { CveEmpresa = UsuarioActual.Empresa.CveEmpresa, CveEncuesta = CveEncuestaProcesoCRM, CveEncuestaAplicada = CveEncuestaAplicadaProceso, CvePregunta = -1 });
if (responseGenericGetDatosTecnicosEmpresaCRM.IsSuccess)
{
GvDatosTecnicos.DataSource = responseGenericGetDatosTecnicosEmpresaCRM.Result.ToDataTable() ;
if (responseGenericGetDatosTecnicosEmpresaCRM.Result.Count > 0)
{
GvDatosTecnicos.Visible = true;
}
}
//ClsEncuestas objEncuesta = new ClsEncuestas();
//if (objEncuesta.GetRespuestas(CveEncuestaProcesoCRM))
// DTRespuestasDatosTecnicos = objEncuesta.DtResultados;
//if (objEncuesta.GetDatosTecnicosEmpresaCRM(CveEncuestaProcesoCRM, CveEncuestaAplicadaProceso, 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() != "")
{
try
{
e.Row.FCRadioButtonList("RdlRespuestaDinamica").SelectedValue = e.Row.FCRadioButtonList("RdlRespuestaDinamica").Items.FindByText(e.Row.DataKey("Valor").ToString()).Value;
}
catch { }
}
//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;
}
}
}
}
protected int GuardaDatosTecnicos(ClsEncuestas ObjDatosTecnicos, int CveEncuestaAplicada = -1)
{
int _CveEncuestaAplicada = CveEncuestaAplicada;
int CveRespuesta = -1;
string Respuesta = "-1";
int CveEncuestaAplicadaDetalle = -1;
Boolean ExisteRegistro = true;
DataTable dtRespuesta;
var encuestaService = new EncuestaService(System.Configuration.ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString);
//NUEVA CAPTURA DE DATOS TECNICOS
if (_CveEncuestaAplicada == -1)
{
var responseModelAddEncuestaAplicada = encuestaService.AddEncuestaAplicada(new RequestEncuestaAplicadaAdd() { CveEncuesta = CveEncuestaProcesoCRM, CveCliente = -1, CvePersonal = -1, CveUsuario = UsuarioActual.CveUsuario, CveEmpresa = UsuarioActual.CveEmpresa });
if (responseModelAddEncuestaAplicada.Result > 0)
{
_CveEncuestaAplicada = responseModelAddEncuestaAplicada.Result.ToEntero();
}
// if (ObjDatosTecnicos.AddEncuestaAplicada(CveEncuestaProcesoCRM, -1, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa))
//{
// _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();
CveEncuestaAplicadaDetalle = drow.DataKey("CveEncuestaAplicadaDetalle").ToEntero();
ExisteRegistro = CveEncuestaAplicadaDetalle > 0;
CveRespuesta = -1;
Respuesta = "-1";
dtRespuesta = DTRespuestasDatosTecnicos.FiltraParametros(string.Format(" CvePregunta = {0} ", CvePregunta));
switch (EsOpcion)
{
case 1: // TEXTO - RESPUESTA BIERTA
{
if (dtRespuesta.Rows.Count == 0) CveRespuesta = -1; else CveRespuesta = dtRespuesta.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 (dtRespuesta.Rows.Count == 0) CveRespuesta = -1; else CveRespuesta = dtRespuesta.FiltroPrimeroValor("CveRespuesta").ToString().ToEntero();
Respuesta = drow.FCTextBox("TxtRespuestaDinamicaMultilinea").Text;
break;
}
case 7: // FECHA
{
if (dtRespuesta.Rows.Count == 0) CveRespuesta = -1; else CveRespuesta = dtRespuesta.FiltroPrimeroValor("CveRespuesta").ToString().ToEntero();
Respuesta = drow.FCTextBox("TxtRespuestaFechaDinamica").Text;
break;
}
}
//ACTUALIZAMOS LOS DATOS TECNICOS
if (CveEncuestaAplicadaDetalle > 0)
{
var responnseModelUpdateDatosTecnicosCRM = encuestaService.UpdateDatosTecnicosCRM(new RequestDatosTecnicosCRMUpdate() { CveEncuestaAplicadaDetalle = CveEncuestaAplicadaDetalle, CveEncuestaAplicada = CveEncuestaAplicada, CvePregunta = CvePregunta, CveRespuesta = CveRespuesta, Respuesta = Respuesta });
if (ExisteRegistro && !responnseModelUpdateDatosTecnicosCRM.IsSuccess)
{
//SI HAY ERROR REGRESA 0
_CveEncuestaAplicada = 0;
}
}
else
{
var responnseModelAddEncuestaAplicadaDetalle = encuestaService.AddEncuestaAplicadaDetalle(new RequestEncuestaAplicadaDetalleAdd() { CveEncuestaAplicada = _CveEncuestaAplicada, CvePregunta = CvePregunta, CveRespuesta = CveRespuesta, Valor = Respuesta });
if (!ExisteRegistro && !responnseModelAddEncuestaAplicadaDetalle.IsSuccess)
{
//SI HAY ERROR REGRESA 0
_CveEncuestaAplicada = 0;
}
}
////ACTUALIZAMOS LOS DATOS TECNICOS
//if (ExisteRegistro && !responnseModelUpdateDatosTecnicosCRM.IsSuccess)
//{
// //SI HAY ERROR REGRESA 0
// _CveEncuestaAplicada = 0;
//}
//else if (!ExisteRegistro && !responnseModelAddEncuestaAplicadaDetalle.IsSuccess)
//{
// //SI HAY ERROR REGRESA 0
// _CveEncuestaAplicada = 0;
//}
////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;
//}
dtRespuesta.Dispose();
}
// SI REGRESA _CveEncuestaAplicada = 0 HUBO ERROR
return _CveEncuestaAplicada;
}
#endregion
#region "MUESTRA UBICACION GEOGRAFICA"
protected void LnkVerUbicacion_Click(object sender, EventArgs e)
{
GridViewRow GvRow = (GridViewRow)(((LinkButton)sender).NamingContainer);
string Lat = GvRow.DataKey("Lat");
string Long = GvRow.DataKey("Long");
this.RegistraScript(String.Format("initMap(); CreaMarcador({0}, {1}, '{2}', '{3}'); $('#ModalVerUbicacion').modal();", Lat, Long, "0", "Info"));
}
#endregion
#region "TAB IMAGENES"
protected void CargaImagenes()
{
var ObjCRM = new ClsCRM();
ICRMService cRMService = new CRMService(System.Configuration.ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString);
RequestImagenesAcercamiento ImagenesAcercamiento = new RequestImagenesAcercamiento(CveAcercamiento);
var objImagenesAcercamiento = cRMService.ImagenesAcercamientoGet(ImagenesAcercamiento);
if (objImagenesAcercamiento.Result.Count > 0)
{
RptFotos.DataSource = objImagenesAcercamiento.Result;
}
ObjCRM.Dispose();
RptFotos.DataBind();
}
protected void BtnUpFotos_Click(object sender, EventArgs e)
{
bool TieneError = false;
var ObjCRM = new ClsCRM();
ObjCRM.IniciaTransacSQL();
ICRMService cRMService = new CRMService(System.Configuration.ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString);
RequestImagenesAcercamiento ImagenesAcercamiento = new RequestImagenesAcercamiento(CveAcercamiento, UsuarioActual.CveEmpresa, CveEmpresaCRM, -1, "", TxtTituloImagen.Text, TxtDescripcionImagen.Text, "-1", UsuarioActual.CveUsuario);
try
{
foreach (var item in TxtUpFotos.getfiles().Archivos)
{
var FileExtension = "";
if (!string.IsNullOrEmpty(item.filename))
{
FileExtension = System.IO.Path.GetExtension(item.filename);
}
if (string.IsNullOrEmpty(FileExtension))
{
TieneError = true;
break;
}
int CveArchivo = cRMService.ImagenesAcercamientoAdd(ImagenesAcercamiento).ToEntero();
if ((CveArchivo > 0))
{
string NombreNuevo = string.Format("{0}{1}", CveArchivo, FileExtension);
string DirectorioNuevo = string.Format("{0}\\Empresas\\{1}\\Acercamientos\\{2}\\Imagenes\\", ModExtensiones.DirectorioBaseEmpresas, UsuarioActual.CveEmpresa, CveAcercamiento);
if (!Directory.Exists(DirectorioNuevo))
{
Directory.CreateDirectory(DirectorioNuevo);
}
DirectorioNuevo = DirectorioNuevo + NombreNuevo;
var DirectorioViejo = string.Format("{0}Temp\\{1}", AppDomain.CurrentDomain.BaseDirectory, item.filename);
RequestImagenesAcercamiento ImagenesAcercamientoUpdate = new RequestImagenesAcercamiento(CveAcercamiento, UsuarioActual.CveEmpresa, CveEmpresaCRM, CveArchivo, NombreNuevo, TxtTituloImagen.Text, TxtDescripcionImagen.Text);
if (cRMService.ImagenesAcercamientoUpdate(ImagenesAcercamientoUpdate))
{
File.Move(DirectorioViejo, DirectorioNuevo);
}
else
{
TieneError = true;
break;
}
}
else
{
TieneError = true;
break;
}
}
}
catch (Exception ex)
{
this.OnError("Ocurrió un error al agregar una imagen", ex);
TieneError = true;
}
finally
{
if (TieneError)
{
ObjCRM.RollBack();
Alert("El archivo el eliminó correctamente.", ModExtensiones.TipoMensaje.MsgError);
}
else
{
ObjCRM.Commit();
Alert("El archivo se agregó correctamente");
}
ObjCRM.Dispose();
CargaImagenes();
UpGaleria.Update();
RegistraScript("$('#Modalupfotos').modal('hide');clickgaleria();");
}
}
protected void BtnEliminarFoto_Click(object sender, EventArgs e)
{
int CveArchivo = (sender as Button).CommandArgument.ToEntero();
if (CveArchivo > 0)
{
var ObjCRM = new ClsCRM();
ICRMService cRMService = new CRMService(System.Configuration.ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString);
RequestImagenesAcercamiento ImagenesAcercamiento = new RequestImagenesAcercamiento(-1, CveArchivo: CveArchivo);
bool Elimino = cRMService.ImagenesAcercamientoDelete(ImagenesAcercamiento);
ObjCRM.Dispose();
if (Elimino)
{
Alert("El archivo se eliminó correctamente.");
CargaImagenes();
UpGaleria.Update();
RegistraScript("clickgaleria();");
}
}
}
#endregion
#region "TAB COTIZACIONES"
protected void CargaCotizaciones()
{
ClsVentas ObjVentas = new ClsVentas();
IVentaService ventaService = new VentaService(System.Configuration.ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString);
RequestVentas requestVentas = new RequestVentas(UsuarioActual.CveEmpresa, TipoDocto: "Cot", CveEmpresaCRM: CveEmpresaCRM, CveUsuarioConsulta: UsuarioActual.CveUsuario, CveAcercamientoCRM: CveAcercamiento);
var objVentas = ventaService.GetVentas(requestVentas);
if (objVentas.IsSuccess)
{
GvCotizacion.DataSource = objVentas.Result;
TieneCotizacion = objVentas.Result.Count > 0;
}
ObjVentas.Dispose();
GvCotizacion.DataBind();
UpCotizacion.Update();
HplAgregarCotizacion.NavigateUrl = String.Format("/Ventas/Ventas.aspx?CveEmpresaCRM={0}&CveAcercamientoCRM={1}&Op=Cot", CveEmpresaCRM, CveAcercamiento);
}
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
#region "TAB GASTOS"
protected void CargaGastos()
{
ClsCRM ObjCRM = new ClsCRM();
ICRMService cRMService = new CRMService(System.Configuration.ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString);
RequestAcermientoGastos AcermientoGastos = new RequestAcermientoGastos(CveAcercamiento);
var objAcermientoGastos = cRMService.AcercamientosGastosGet(AcermientoGastos);
if (objAcermientoGastos.Result.Count > 0)
{
GvGastos.DataSource = objAcermientoGastos.Result;
}
ObjCRM.Dispose();
GvGastos.DataBind();
UpGastos.Update();
}
protected void LbAddGastos_Click(object sender, EventArgs e)
{
LtlTituloModalGasto.Text = "Agregar Gasto";
BtnAgregarGastoModal.Text = "Agregar";
UpModalGastos.Update();
TxtDescripcionGasto.Text = "";
TxtImporteGasto.Text = "";
Actualizar = false;
RegistraScript(String.Format("$('#{0}').modal();", "DivAgregarGasto"));
}
protected void BtnAgregarGastoModal_Click(object sender, EventArgs e)
{
ClsCRM ObjCRM = new ClsCRM();
ICRMService cRMService = new CRMService(System.Configuration.ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString);
RequestAcermientoGastos AcermientoGastos = new RequestAcermientoGastos(CveAcercamiento, -1, TxtDescripcionGasto.Text, TxtImporteGasto.Text.ToDecimal(), UsuarioActual.CveUsuario);
if (!Actualizar)
{
if (cRMService.AcercamientosGastosAdd(AcermientoGastos))
{
CargaGastos();
RegistraScript(String.Format("$('#{0}').modal('hide');", "DivAgregarGasto"), "jsHideModalFolioGarantia");
Alert("Gasto Agregado Correctamente", ModExtensiones.TipoMensaje.MsgInformacion);
}
else
{
Alert("Ocurrió un error al guardar el Gasto", ModExtensiones.TipoMensaje.MsgError);
}
}
else
{
if (cRMService.AcercamientosGastosUpdate(AcermientoGastos))
{
CargaGastos();
RegistraScript(String.Format("$('#{0}').modal('hide');", "DivAgregarGasto"), "jsHideModalFolioGarantia");
Alert("Gasto Actualizado Correctamente", ModExtensiones.TipoMensaje.MsgInformacion);
}
else
{
Alert("Ocurrió un error al actualizar el Gasto", ModExtensiones.TipoMensaje.MsgError);
}
}
Actualizar = false;
CveAcercamientoGasto = -1;
ObjCRM.Dispose();
}
protected void GvGastos_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.DBCampo("CveAcercamiento").ToEntero() < 1)
{
e.Row.CssClass = "Totales";
e.Row.Cells[0].Text = "Total";
e.Row.FCLinkButton("ImgE").Visible = false;
e.Row.FCLinkButton("imgD").Visible = false;
}
}
}
protected void ImgE_Click(object sender, EventArgs e)
{
GridViewRow GvRow = (GridViewRow)((LinkButton)sender).NamingContainer;
LtlTituloModalGasto.Text = "Editar Gasto";
BtnAgregarGastoModal.Text = "Actualizar";
Actualizar = true;
CveAcercamientoGasto = GvRow.DataKey("CveAcercamientoGasto").ToEntero();
TxtDescripcionGasto.Text = GvRow.DataKey("Descripcion");
TxtImporteGasto.Text = GvRow.DataKey("Importe");
UpModalGastos.Update();
RegistraScript(String.Format("$('#{0}').modal();", "DivAgregarGasto"));
}
protected void imgD_Click(object sender, EventArgs e)
{
ClsCRM ObjCRM = new ClsCRM();
ICRMService cRMService = new CRMService(System.Configuration.ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString);
GridViewRow GvRow = (GridViewRow)((LinkButton)sender).NamingContainer;
CveAcercamientoGasto = GvRow.DataKey("CveAcercamientoGasto").ToEntero();
RequestAcermientoGastos AcermientoGastos = new RequestAcermientoGastos(CveAcercamiento, CveAcercamientoGasto: CveAcercamientoGasto);
if (cRMService.AcercamientosGastosDelete(AcermientoGastos))
{
CargaGastos();
Alert("Gasto eliminado Correctamente", ModExtensiones.TipoMensaje.MsgInformacion);
}
else
{
Alert("Ocurrió un error al eliminar el Gasto", ModExtensiones.TipoMensaje.MsgError);
}
ObjCRM.Dispose();
CveAcercamientoGasto = -1;
}
#endregion
#region "CHECK LIST"
private void CargaCheckLis()
{
using (ClsOIEventos objOI = new ClsOIEventos())
{
if (objOI.Getcheklist(-1, CveAcercamiento: CveAcercamiento))
{
GVcheklist.DataSource = objOI.DtResultados;
GVcheklist.DataBind();
}
}
UpChkList.Update();
}
protected void LnkAgregarchklistitem_Click(object sender, EventArgs e)
{
bool procesoOk = false;
if (TxtActividad.Text.Trim().Length > 0)
{
if (CveAcercamiento > 0)
{
using (ClsOIEventos objOI = new ClsOIEventos())
{
objOI.IniciaTransacSQL();
if (objOI.Addcheklist(-1, TxtActividad.Text, UsuarioActual.CveUsuario, CveAcercamiento: CveAcercamiento))
{
Alert("Se agregó la actividad", ModExtensiones.TipoMensaje.ToastInformacion);
if (objOI.Getcheklist(-1, CveAcercamiento: CveAcercamiento))
{
GVcheklist.DataSource = objOI.DtResultados;
GVcheklist.DataBind();
if (BitacoraCheckList(objOI.IniciaTransacSQL(), $"Check List se agrega actividad {TxtActividad.Text}", CveAcercamiento))
{
procesoOk = true;
}
}
}
if (procesoOk)
{
objOI.Commit();
CargaEventoBitacora((CveEtapaActual > 0 ? HdfEtapaSeleccionada.Value.ToEntero() : -1));
}
else
{
objOI.RollBack();
}
}
}
else
{
System.Data.DataRow drow = CheckListNew.NewRow();
drow["CveEventoCheckList"] = chklistitemindex++;
drow["EventoComentario"] = TxtActividad.Text;
drow["Estatus"] = false;
//CveEventoCheckList,CveEvento,CveTipoEvento,EventoComentario,Estatus,CveUsuario,Usuario,FechaIng
CheckListNew.Rows.Add(drow);
GVcheklist.DataSource = CheckListNew;
GVcheklist.DataBind();
}
}
TxtActividad.Focus();
TxtActividad.Text = "";
}
protected void ChkEstatus_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)sender;
GridViewRow gvrow = (GridViewRow)chk.NamingContainer;
bool procesoOk = false;
using (ClsOIEventos objOI = new ClsOIEventos())
{
string EventoComentario = gvrow.DataKey("EventoComentario");
objOI.IniciaTransacSQL();
if (objOI.Upcheklist(gvrow.DataKey("CveEventoCheckList").ToEntero(), gvrow.DataKey("CveEvento").ToEntero(), gvrow.DataKey("EventoComentario"), chk.Checked, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa,
CveAcercamiento: CveAcercamiento))
{
Alert("Se actualizó el estatus de la actividad", ModExtensiones.TipoMensaje.ToastInformacion);
if (objOI.Getcheklist(-1, CveAcercamiento: CveAcercamiento))
{
GVcheklist.DataSource = objOI.DtResultados;
GVcheklist.DataBind();
if (BitacoraCheckList(objOI.IniciaTransacSQL(), $"Check List {(chk.Checked == true ? "Se termina actividad ":" se retorna actividad") } {EventoComentario}", CveAcercamiento))
{
procesoOk = true;
}
}
}
if (procesoOk)
{
objOI.Commit();
CargaEventoBitacora((CveEtapaActual > 0 ? HdfEtapaSeleccionada.Value.ToEntero() : -1));
}
else
{
objOI.RollBack();
}
}
}
protected void LnkEliminarchek_Click(object sender, EventArgs e)
{
bool procesoOk = false;
GridViewRow gvrow = (GridViewRow)((LinkButton)sender).NamingContainer;
if(!(CveAcercamiento > 0))
{
CheckListNew = CheckListNew.FiltraParametros(string.Format("CveEventoCheckList <> {0}", gvrow.DataKey("CveEventoCheckList")));
GVcheklist.DataSource = CheckListNew;
GVcheklist.DataBind();
}
else
{
using (ClsOIEventos objOI = new ClsOIEventos())
{
objOI.IniciaTransacSQL();
string EventoComentario = gvrow.DataKey("EventoComentario");
if (objOI.Removecheklist(gvrow.DataKey("CveEventoCheckList").ToEntero(), gvrow.DataKey("CveEvento").ToEntero(), UsuarioActual.CveUsuario, CveAcercamiento: CveAcercamiento))
{
Alert("Se ha eliminadó la actividad", ModExtensiones.TipoMensaje.ToastInformacion);
if (objOI.Getcheklist(-1, CveAcercamiento))
{
GVcheklist.DataSource = objOI.DtResultados;
GVcheklist.DataBind();
if (BitacoraCheckList(objOI.IniciaTransacSQL(), $"Check List se elimina actividad {EventoComentario}", CveAcercamiento))
{
procesoOk = true;
}
}
}
if(procesoOk)
{
objOI.Commit();
CargaEventoBitacora((CveEtapaActual > 0? HdfEtapaSeleccionada.Value.ToEntero():-1));
}
else
{
objOI.RollBack();
}
}
}
}
private bool BitacoraCheckList(SqlTransaction sqlTransaction, string TextoRegistroBitacora, int CveAcercamientoBitacora)
{
bool respuesta = false;
ClsOIEventos objBitacora = new ClsOIEventos(sqlTransaction);
if (objBitacora.AddEventoBitacora(TextoRegistroBitacora, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveAcercamientoCRM: CveAcercamientoBitacora))
{
respuesta = true;
}
return respuesta;
}
protected void LnkSinfuncion_Click(object sender, EventArgs e)
{
// es para mandar llamar el ChkEstatus_CheckedChanged
}
//private bool GuardaCheckList(SqlTransaction transaction, int CveAcercamientoNuevo)
//{
// bool respuesta = true;
// ClsOIEventos objOI = new ClsOIEventos(transaction);
// foreach (GridViewRow GvRow in GVcheklist.Rows)
// {
// if (!objOI.Addcheklist(-1, TxtActividad.Text, UsuarioActual.CveUsuario, CveAcercamiento: CveAcercamiento))
// {
// respuesta = false;
// break;
// }
// }
// return respuesta;
//}
#endregion
protected void GVcheklist_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow) {
var Estatus = Boolean.Parse(e.Row.DataKey("Estatus"));
CheckBox chk = e.Row.FCCheckBox("");
if (Estatus)
{
e.Row.FCLabel("lbleventoComentario").Attributes.Add("class", "listTerminado");
}
}
}
}