Crm terminado

This commit is contained in:
Antonio Gonzalez
2021-01-22 20:53:26 -07:00
parent e1d793ac73
commit 17b0f4824f
4 changed files with 225 additions and 15 deletions

View File

@@ -1,11 +1,12 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using GemBox.Spreadsheet;
using Extensiones;
public partial class CRM_CatEmpresasCRM : ClsPaginas
@@ -124,4 +125,172 @@ public partial class CRM_CatEmpresasCRM : ClsPaginas
CargaMediosCaptacion();
UPFiltros.Update();
}
protected void LnkCargaProspectos_Click(object sender, EventArgs e)
{
RegistraScript(String.Format("$('#{0}').modal();", "DivCargasMasivas"));
}
protected void BtnDescargar_Click(object sender, EventArgs e)
{
string Directorio = ModExtensiones.DirectorioBaseEmpresas + "Empresas\\Grales\\Formatos\\FormatoDeProspectos.xlsx";
FileInfo Archivo = new FileInfo(Directorio);
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment; filename=" + Archivo.Name);
Response.AddHeader("Content-Length", Archivo.Length.ToString());
Response.ContentType = "text/plain";
Response.Flush();
Response.TransmitFile(Archivo.FullName);
Response.End();
}
protected void BtnAgregarProspectos_Click(object sender, EventArgs e)
{
if( TxtExcel.getfiles().Archivos.Count > 0 )
{
Archivo file = TxtExcel.getfiles().Archivos[0];
string Directorio = Server.MapPath("~") + file.patch;
DataTable dt = ReadExcelFile(Directorio + file.filename, true);
DataRowCollection Rows = dt.Rows;
ClsCRM ObjCRM = new ClsCRM();
ObjCRM.IniciaTransacSQL();
bool TieneError = false;
foreach (DataRow row in Rows)
{
string Proceso = row["Proceso"].ToString();
string NombreEmpresa = row["Nombre de la empresa"].ToString();
string RFC = row["RFC"].ToString();
string Mail = row["Mail"].ToString();
string MedioCaptacion = row["Medio de Captación"].ToString();
string Agente = row["Agente"].ToString();
string Sucursal = row["Sucursal"].ToString();
string Giro = row["Giro"].ToString();
string ContactoPrincipal = row["Contacto Principal"].ToString();
string TelOficina = row["Teléfono de Oficina"].ToString();
string Celular = row["Celular"].ToString();
string Correo = row["Correo"].ToString();
int CveMedioCaptacion = -1;
if (ObjCRM.GetMedioCaptacion(UsuarioActual.CveEmpresa))
{
DataRow MediosCaptacion = ObjCRM.DtResultados.FiltroPrimero(String.Format("MedioCaptacion = '{0}'",MedioCaptacion));
if(MediosCaptacion != null)
{
CveMedioCaptacion = MediosCaptacion["CveMedioCaptacion"].ToString().ToEntero();
}else
{
Alert(String.Format("El medio de captación '{0}' no fue encontrado", MedioCaptacion), ModExtensiones.TipoMensaje.MsgAdvertencia);
TieneError = true;
break;
}
}
int CveVendedor = -1;
DataRow Vendedor = get_GlobalDTVendedores(UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("Vendedor = '{0}'",Agente));
if (Vendedor != null)
{
CveVendedor = Vendedor["CveVendedor"].ToString().ToEntero();
}else
{
Alert(String.Format("El vendedor '{0}' no fue encontrado", MedioCaptacion), ModExtensiones.TipoMensaje.MsgAdvertencia);
TieneError = true;
break;
}
int CveSubProyecto = -1;
DataRow SubProyecto = get_GlobalDTSubProyectos(-1,CveEmpresa:UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("SubProyecto = '{0}'",Sucursal));
if(SubProyecto != null)
{
CveSubProyecto = SubProyecto["CveSubProyecto"].ToString().ToEntero();
}else
{
Alert(String.Format("El SubProyecto '{0}'", Sucursal), ModExtensiones.TipoMensaje.MsgAdvertencia);
TieneError = true;
break;
}
int CveGiro = -1;
DataRow GiroDt = get_GlobalDTClienteClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("ClienteClasificacion = '{0}'", Giro));
if (GiroDt != null)
{
CveGiro = GiroDt["CveClienteClasificacion"].ToString().ToEntero();
}
else
{
Alert(String.Format("El Giro de Empresa '{0}'", Giro), ModExtensiones.TipoMensaje.MsgAdvertencia);
TieneError = true;
break;
}
TieneError = (!(ObjCRM.AddEmpresaCRM(NombreEmpresa, RFC, CveMedioCaptacion, UsuarioActual.CveEmpresa, UsuarioActual.CveUsuario, -1, CveVendedor, CveSubProyecto, Mail, CveGiro) > 0));
}
if (TieneError)
{
ObjCRM.RollBack();
}else
{
ObjCRM.Commit();
Alert("Prospectos agregados correctamente");
TxtExcel.Text = "";
RegistraScript(String.Format("$('#{0}').modal('hide');", "DivCargasMasivas"));
}
ObjCRM.Dispose();
}
}
private DataTable ReadExcelFile(string flatFilePath, bool firstRowHasHeaders)
{
SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet());
ExcelFile excelFile = ExcelFile.Load(flatFilePath);
int unnamed = 0;
int cols;
string[] columns;
int curRow = 0;
int curCol = 0;
DataTable dataTable = new DataTable();
ExcelWorksheet worksheet = excelFile.Worksheets[0];
for (cols = 0; cols <= worksheet.Rows[0].AllocatedCells.Count - 1; cols++)
{
if (firstRowHasHeaders)
{
if (worksheet.Rows[0].Cells[cols].Value != null)
dataTable.Columns.Add(worksheet.Rows[0].Cells[cols].Value.ToString().Trim());
else
dataTable.Columns.Add("Unnamed Column " + (System.Threading.Interlocked.Increment(ref unnamed)));
curRow = 1;
}
else
dataTable.Columns.Add("Column " + (cols + 1));
}
while (curRow < worksheet.Rows.Count)
{
columns = new string[cols - 1 + 1];
for (curCol = 0; curCol <= cols - 1; curCol++)
{
if (worksheet.Rows[curRow].Cells[curCol].Value == null)
columns[curCol] = "";
else
columns[curCol] = worksheet.Rows[curRow].Cells[curCol].Value.ToString();
}
dataTable.Rows.Add(columns);
curRow += 1;
}
return dataTable;
}
}