This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
@@ -9,13 +12,78 @@ using Extensiones;
|
||||
public partial class OI_CircularDetalleB : ClsPaginas
|
||||
{
|
||||
public const string iddivAgregarPara = "iddivAgregarPara";
|
||||
private DataTable DtUsuarios
|
||||
{
|
||||
get
|
||||
{
|
||||
return (ViewState["DtUsuarios"]== null) ? null : (DataTable)ViewState["DtUsuarios"];
|
||||
}
|
||||
set
|
||||
{
|
||||
ViewState["DtUsuarios"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
private int CveCircular
|
||||
{
|
||||
get
|
||||
{
|
||||
return ViewState["CveCircular"].ToString().ToEntero();
|
||||
}
|
||||
set
|
||||
{
|
||||
ViewState["CveCircular"] = value;
|
||||
}
|
||||
}
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsPostBack)
|
||||
{
|
||||
if(Request["CveCircular"] != null)
|
||||
{
|
||||
CveCircular = Request["CveCircular"].ToString().ToEntero();
|
||||
}
|
||||
|
||||
if (CveCircular > 0)
|
||||
{
|
||||
BtnGuardar.Text = "Actualizar";
|
||||
BtnEliminar.Visible = true;
|
||||
CargaDatos();
|
||||
}
|
||||
else
|
||||
{
|
||||
BtnGuardar.Text = "Guardar";
|
||||
}
|
||||
cargarFiltroUsuarios();
|
||||
}
|
||||
}
|
||||
|
||||
private void CargaDatos()
|
||||
{
|
||||
if (CveCircular > 0)
|
||||
{
|
||||
ClsOIEventos ObjOI = new ClsOIEventos();
|
||||
if (ObjOI.GetCircular(UsuarioActual.CveEmpresa, CveCircular))
|
||||
{
|
||||
DataRow Circular = ObjOI.DtResultados.Rows[0];
|
||||
|
||||
TxtAsunto.Text = Circular["Asunto"].ToString();
|
||||
TxtCorreo.Text = Circular["CorreosInternos"].ToString();
|
||||
TxtCorreoAdicional.Text = Circular["CorreosExternos"].ToString();
|
||||
TxtCircular.Text = Circular["Circular"].ToString().Replace("<","< ");
|
||||
|
||||
if (Circular["ArchivoAdjunto"].ToString() != "")
|
||||
{
|
||||
archivosDiv.Visible = true;
|
||||
HkArchivo.NavigateUrl = $"~/Empresas/{UsuarioActual.CveEmpresa}/Formatos/{Circular["ArchivoAdjunto"].ToString()}";
|
||||
HkArchivo.Text = Circular["ArchivoAdjunto"].ToString();
|
||||
}
|
||||
|
||||
UpContenido.Update();
|
||||
}
|
||||
ObjOI.Dispose();
|
||||
}
|
||||
}
|
||||
private void cargarFiltroUsuarios()
|
||||
{
|
||||
DdlRoles.DataSource = get_GlobalDTRoles(UsuarioActual.CveEmpresa);
|
||||
@@ -49,14 +117,211 @@ public partial class OI_CircularDetalleB : ClsPaginas
|
||||
{
|
||||
this.RegistraScript(string.Format("$('#{0}').modal()", iddivAgregarPara));
|
||||
}
|
||||
|
||||
protected void BtnUpPara_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected void BtnUpMiembros_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
string UsuariosCorreos = "";
|
||||
foreach (GridViewRow gvuser in GVUsuarios.Rows)
|
||||
{
|
||||
CheckBox ChkOk =gvuser.FCCheckBox("ChkOk");
|
||||
string Correo = gvuser.DataKey("Correo");
|
||||
if (ChkOk.Checked && Correo.Length >0)
|
||||
{
|
||||
UsuariosCorreos = string.Format("{1}{0}" + ";", UsuariosCorreos, Correo);
|
||||
}
|
||||
}
|
||||
TxtCorreo.Text = UsuariosCorreos;
|
||||
RegistraScript("$('#ModalDescuento').modal('hide')");
|
||||
UpContenido.Update();
|
||||
}
|
||||
|
||||
protected void BtnGuardar_Click(object sender, EventArgs e)
|
||||
{
|
||||
ClsOIEventos ObjOI = new ClsOIEventos();
|
||||
if (CveCircular > 0)
|
||||
{
|
||||
string AdjuntoValidate = NombreArchivo().Split('-')[1];
|
||||
|
||||
if (ObjOI.UpdateCircular(CveCircular, TxtAsunto.Text, TxtCircular.Text.Replace("< ","<"), TxtCorreo.Text, TxtCorreoAdicional.Text, AdjuntoValidate))
|
||||
{
|
||||
GuardarArchivo(CveCircular);
|
||||
Alert("Actualizado correctamente");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string CorreoExtra = TxtCorreoAdicional.Text == "" ? "-1" : TxtCorreoAdicional.Text;
|
||||
|
||||
string AdjuntoValidate = NombreArchivo().Split('-')[1];
|
||||
int CircularInsertado = ObjOI.AddCircular(TxtAsunto.Text, TxtCircular.Text.Replace("< ", "<"), TxtCorreo.Text, DateTime.Today.ToString(), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CorreoExtra, AdjuntoValidate);
|
||||
if (CircularInsertado > 0)
|
||||
{
|
||||
GuardarArchivo(CircularInsertado);
|
||||
Alert("Ingresado correctamente");
|
||||
CveCircular = CircularInsertado;
|
||||
if (CveCircular > 0)
|
||||
{
|
||||
BtnGuardar.Text = "Actualizar";
|
||||
BtnEliminar.Visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
BtnGuardar.Text = "Guardar";
|
||||
}
|
||||
}
|
||||
}
|
||||
CargaDatos();
|
||||
}
|
||||
#region "Guardar"
|
||||
private string NombreArchivo()
|
||||
{
|
||||
List<Archivo> Filesgral = TxtArchivo.getfiles().Archivos;
|
||||
string Filename = "-1";
|
||||
foreach (Archivo fileItem in Filesgral)
|
||||
{
|
||||
try
|
||||
{
|
||||
Filename = fileItem.filename;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Filename = "-1";
|
||||
}
|
||||
}
|
||||
return Filename;
|
||||
}
|
||||
|
||||
private string TituloAnterior()
|
||||
{
|
||||
System.IO.DirectoryInfo Directorio = new System.IO.DirectoryInfo(string.Format("{0}Empresas/{1}/Formatos/", AppDomain.CurrentDomain.BaseDirectory, UsuarioActual.CveEmpresa));
|
||||
System.IO.FileInfo[] ArchivosArreglo = Directorio.GetFiles();
|
||||
string patronRegEx = string.Format("^{0}_.*", CveCircular);
|
||||
string archivoEncontrado = "";
|
||||
foreach (System.IO.FileInfo file in ArchivosArreglo)
|
||||
{
|
||||
if (Regex.IsMatch(file.Name, patronRegEx))
|
||||
archivoEncontrado = file.Name;
|
||||
}
|
||||
return archivoEncontrado;
|
||||
}
|
||||
|
||||
private string GuardarArchivo(int CircularInsertado)
|
||||
{
|
||||
string respuesta = "";
|
||||
string FileExtension = "-1";
|
||||
List<Archivo> Filesgral = TxtArchivo.getfiles().Archivos;
|
||||
string Filename = "";
|
||||
|
||||
foreach (Archivo fileItem in Filesgral)
|
||||
{
|
||||
try
|
||||
{
|
||||
respuesta = fileItem.filenameO;
|
||||
FileExtension = System.IO.Path.GetExtension(string.Format(@"{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "");
|
||||
string[] tempArray;
|
||||
tempArray = fileItem.filename.ToString().Split("-".ToCharArray());
|
||||
|
||||
string rutaDestino = UsuarioActual.Empresa.Ruta + @"Formatos\" + CircularInsertado + "_" + fileItem.filenameO;
|
||||
|
||||
string ArchivoAnterior = TituloAnterior();
|
||||
|
||||
if (ArchivoAnterior.Length > 0)
|
||||
{
|
||||
string docAnterior = string.Format(@"{0}Formatos\{1}", UsuarioActual.Empresa.Ruta, ArchivoAnterior);
|
||||
if (File.Exists(docAnterior))
|
||||
File.Delete(docAnterior);
|
||||
}
|
||||
|
||||
if (!Directory.Exists(UsuarioActual.Empresa.Ruta + @"\Formatos"))
|
||||
Directory.CreateDirectory(UsuarioActual.Empresa.Ruta + @"\Formatos");
|
||||
|
||||
if (System.IO.File.Exists(rutaDestino))
|
||||
System.IO.File.Delete(rutaDestino);
|
||||
|
||||
System.IO.File.Move(fileItem.FileUrl, rutaDestino);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.OnError("Error al cargar archivo", ex);
|
||||
}
|
||||
TxtArchivo.Text = "";
|
||||
}
|
||||
|
||||
|
||||
return respuesta;
|
||||
}
|
||||
#endregion
|
||||
protected void BtnEliminar_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
using (ClsOIEventos ObjOI = new ClsOIEventos())
|
||||
{
|
||||
if (ObjOI.DeleteCircular(CveCircular)) { Response.Redirect("~/OI/CircularDetalle.aspx?CveCircular=-1"); }
|
||||
}
|
||||
}
|
||||
|
||||
protected void LnkMandarCorreo_Click(object sender, EventArgs e)
|
||||
{
|
||||
string[] correos;
|
||||
correos = TxtCorreo.Text.Split(';');
|
||||
byte[] ArchivoBytes = ArchivoBytesArrya(HkArchivo.Text);
|
||||
|
||||
int Contador = 0;
|
||||
try
|
||||
{
|
||||
foreach (string Correo in correos)
|
||||
{
|
||||
MandaCorreo(TxtAsunto.Text, Correo, Contador > 0 ? "" : TxtCorreoAdicional.Text, TxtCircular.Text, ArchivoBytes, HkArchivo.Text);
|
||||
Contador += 1;
|
||||
}
|
||||
Alert("El correo se envió correctamente");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Alert("Error al enviar correo", ModExtensiones.TipoMensaje.MsgError);
|
||||
}
|
||||
}
|
||||
|
||||
private void MandaCorreo(string Asunto, string Para, string ArrayCC, string body, byte[] ArchivoBinario, string NombreArchivo)
|
||||
{
|
||||
string a = string.Format("{0} -- {1} --- {2}", Asunto, Para, ArrayCC);
|
||||
a.GuardaLog();
|
||||
|
||||
ClsSisMail Mail = new ClsSisMail();
|
||||
List<ClsSisMail.ArchivoMail> LSRutasMail = new List<ClsSisMail.ArchivoMail>();
|
||||
ClsSisMail.ArchivoMail itemMail = new ClsSisMail.ArchivoMail();
|
||||
|
||||
{
|
||||
var withBlock = itemMail;
|
||||
itemMail.ArchivoBinario = ArchivoBinario;
|
||||
itemMail.NombreArchivo = NombreArchivo;
|
||||
}
|
||||
|
||||
LSRutasMail.Add(itemMail);
|
||||
|
||||
|
||||
Mail.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, body, ArrayCC, LSRutasMail);
|
||||
Mail = null/* TODO Change to default(_) if this is not a reference type */;
|
||||
}
|
||||
|
||||
private byte[] ArchivoBytesArrya(string ArchivoNombre)
|
||||
{
|
||||
string ArchivoEnviar = string.Format(@"{0}Formatos\{1}", UsuarioActual.Empresa.Ruta, ArchivoNombre);
|
||||
if (File.Exists(ArchivoEnviar))
|
||||
{
|
||||
System.IO.FileStream fs = System.IO.File.Open(ArchivoEnviar, System.IO.FileMode.Open, System.IO.FileAccess.Read);
|
||||
byte[] buff = new byte[fs.Length + 1];
|
||||
if (fs.Length > 0)
|
||||
{
|
||||
fs.Read(buff, 0, (fs.Length.ToString().ToEntero() - 1));
|
||||
fs.Close();
|
||||
}
|
||||
return buff;
|
||||
}
|
||||
|
||||
return new byte[] { };
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user