public void CargarDatos()
        {
            Controller_EstadoOT eo = new Controller_EstadoOT();

            lblOT.Text = Request.QueryString["OT"];
            Intranet.ModuloDespacho.Model.Estado_OT et = eo.BuscarOTLiquidar(Request.QueryString["OT"], 1);
            lblNombreOT.Text = et.NombreOT;
            lblCliente.Text  = et.Cliente;
            if (et.FechaMaxima != "")
            {
                lblFechaLiqui.Text = Convert.ToDateTime(et.FechaMaxima).ToString("dd-MM-yyyy");
            }

            Controller_Liquidacion controlliqui = new Controller_Liquidacion();

            RadGrid1.DataSource = controlliqui.ListarHistorialLiquidacion(Request.QueryString["OT"]);
            RadGrid1.DataBind();
            RadGrid3.DataSource = controlliqui.ListarHistorialNotas(Request.QueryString["OT"]);
            RadGrid3.DataBind();
            RadGridfacturacion.DataSource = controlliqui.ListarDetalleFacturacion(Request.QueryString["OT"]);
            RadGridfacturacion.DataBind();

            ddlProblema.DataSource     = controlliqui.ListarDetalle();
            ddlProblema.DataTextField  = "OT";
            ddlProblema.DataValueField = "TotalDesp";
            ddlProblema.DataBind();
            ddlProblema.Items.Insert(0, new ListItem("Seleccionar", "Seleccionar"));
            ddlProblema.Attributes.Add("disabled", "disabled");

            RadGrid2.DataSource = controlliqui.ListarDespachos(Request.QueryString["OT"], 0);
            RadGrid2.DataBind();

            lblTabla.Text = controlliqui.ListaDetalleDespachos(Request.QueryString["OT"], 1);
            //string CSR = de.NombreOT;
        }
        protected void btnGrabar_Click(object sender, EventArgs e)
        {
            Liquidar liqui = new Liquidar();
            Controller_Liquidacion controlliqui = new Controller_Liquidacion();

            liqui.VerMas   = txtObservacion.Text;
            liqui.OT       = lblOT.Text;
            liqui.NombreOT = lblNombreOT.Text;
            liqui.Cliente  = lblCliente.Text;
            string          Responsable = "";
            List <Liquidar> lista       = controlliqui.CorreosResposable(ddlProblema.SelectedItem.Text, lblOT.Text);
            int             contador    = 0;

            foreach (Liquidar li in lista)
            {
                contador++;
                Responsable += li.Accion + ", ";
            }
            if (contador > 0)
            {
                if (TextBox2.Text != "")
                {
                    liqui.Tiraje = TextBox2.Text;
                }
                else
                {
                    liqui.Tiraje = Responsable.Substring(0, Responsable.Length - 2);//responsable
                }
            }
            else
            {
                liqui.Tiraje = Responsable;
            }
            liqui.Accion       = ddlProblema.SelectedItem.Text;                          //Asunto
            liqui.EstadoOT     = Session["Usuario"].ToString();
            liqui.FechaFactura = lblAsunto.Text.Substring(0, lblAsunto.Text.Length - 1); //TipoNota

            if (liqui.Tiraje != "" && liqui.Accion != "Seleccionar" & liqui.VerMas != "")
            {
                int id = controlliqui.AgregarNota(liqui);
                if (id != 0)
                {
                    GenerarCorreo(liqui.Accion, liqui.VerMas, liqui.OT, liqui.NombreOT, liqui.Cliente, lblFechaLiqui.Text, id);
                    Response.Redirect("Historial_Notas.aspx?OT=" + liqui.OT + "&Mens=OK");
                }
            }
            else
            {
                string popupScript = "<script language='JavaScript'>Alert('Error al Ingresar nota, todos los campos son Obligatorios.');</script>";
                Page.RegisterStartupScript("PopupScript", popupScript);
            }
        }
        public void cargarDatos(int procedimiento)
        {
            Controller_Liquidacion controlliqui = new Controller_Liquidacion();
            string OT           = txtOT.Text.ToString();
            string NombreOT     = txtNombreOT.Text.ToString();
            string Cliente      = txtCliente.Text.ToString();
            string FechaInicio  = "";
            string FechaTermino = "";

            if (txtFechaInicio.Text.Trim() != "" && txtFechaTermino.Text.Trim() != "")
            {
                string[] str = txtFechaInicio.Text.Split('-');
                FechaInicio = str[2] + str[1] + str[0];

                string[] str2 = txtFechaTermino.Text.Split('-');
                FechaTermino = str2[2] + "-" + str2[1] + "-" + str2[0] + " 23:59:59";
                string MesInicio = "";
                if (str[1].Length == 1)
                {
                    MesInicio = "0" + str[1];
                }
                else
                {
                    MesInicio = str[1];
                }
                string NombreMes = "";
                try { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(Request.UserLanguages[0]); }
                catch { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("es-CL"); }
                NombreMes = Convert.ToDateTime(txtFechaInicio.Text).ToString("MMMM");;


                lblTotal.Text = controlliqui.TotalNetoFacturamesActual(MesInicio, str[2], NombreMes);
            }
            int EstadoOT = 2;

            if (CheckBox1.Checked)
            {
                EstadoOT      -= 1;
                procedimiento += 2;
            }
            RadGrid1.DataSource = controlliqui.ListarOTLiquidadas(OT, NombreOT, Cliente, FechaInicio, FechaTermino, EstadoOT, procedimiento);
            RadGrid1.DataBind();
        }
        public static string CorreosResponsable(string Problema, string OT)
        {
            Controller_Liquidacion controlliqui = new Controller_Liquidacion();
            List <Liquidar>        lista        = controlliqui.CorreosResposable(Problema, OT);
            string Correos  = "";
            int    contador = 0;

            foreach (Liquidar li in lista)
            {
                contador++;
                Correos += li.Accion + ", ";
            }
            if (contador > 0)
            {
                return(Correos.Substring(0, Correos.Length - 2));
            }
            else
            {
                return(Correos);
            }
        }
        public bool GenerarCorreo(string Asunto, string comentario, string OT, string NombreOT, string Cliente, string FechaLi, int id)
        {
            /*-------------------------MENSAJE DE CORREO----------------------*/

            //Creamos un nuevo Objeto de mensaje
            System.Net.Mail.MailMessage mmsg = new System.Net.Mail.MailMessage();

            //Direccion de correo electronico a la que queremos enviar el mensaje
            Controller_Liquidacion controlliqui = new Controller_Liquidacion();

            if (TextBox2.Text == "")
            {
                List <Liquidar> lista = controlliqui.CorreosResposable(ddlProblema.SelectedItem.Text, lblOT.Text);

                foreach (Liquidar li in lista)
                {
                    mmsg.To.Add(li.Accion);
                }
            }
            else
            {
                try
                {
                    string[] str = TextBox2.Text.Split(',');
                    foreach (string correos in str)
                    {
                        mmsg.To.Add(correos);
                    }
                }
                catch
                {
                    mmsg.To.Add(TextBox2.Text);
                }
            }
            //mmsg.To.Add("*****@*****.**");
            //Nota: La propiedad To es una colección que permite enviar el mensaje a más de un destinatar

            //Asunto
            mmsg.Subject         = Asunto;
            mmsg.SubjectEncoding = System.Text.Encoding.UTF8;

            //Direccion de correo electronico que queremos que reciba una copia del mensaje
            //mmsg.Bcc.Add("*****@*****.**"); //Opcional

            //Cuerpo del Mensaje
            //mmsg.Body = "asdasd redireccion: algo.aspx?c="+Codigo2+"&i=" + idUsu.ToString() + "&co=" + Codigo;
            mmsg.Body = "<table style='width:100%;'>" +
                        "<tr>" +
                        "<td>" +
                        "<img src='http://intranet.qgchile.cl/images/Logo color lateral.jpg' width='267px'  height='67px' />" +
                        //"<img src='http://www.qg.com/la/es/images/QG_Tagline_sp.jpg' />" +
                        "</td>" +
                        "</tr>" +
                        "<tr>" +
                        "<td>" +
                        "&nbsp;</td>" +
                        "</tr>" +
                        "<tr>" +
                        "<td>" +
                        "Estimado(a):" +
                        "<br />" +
                        "<br />" +
                        "<br />" +
                        "Existe un requerimiento desde el area de Facturación," +
                        "<br />" +
                        "<div><div style='background: linear-gradient(top, #D3D7DA 0%, #E2EBF4 100%);background: -moz-linear-gradient(top, #D3D7DA 0%, #E2EBF4 100%);" +
                        "background: -webkit-linear-gradient(top, #D3D7DA 0%,#E2EBF4 100%);font-weight: bold;padding: 5px;border: 1px solid #959595;text-align: left;'>Detalle OP</div>" +
                        "<div style='padding: 10px;border: 1px solid #959595;border-top: 0px;margin-bottom: 2px;'>" +
                        "<table style='width: 100%;'>" +
                        "<tbody><tr>" +
                        "<td>&nbsp;</td>" +
                        "<td style='width:140px;font-weight:bold;'>Numero OT:</td>" +
                        "<td>" + OT + "</td>" +
                        "<td style='width:100px;font-weight:bold;'>Nombre OT:</td>" +
                        "<td>" + NombreOT + "</td>" +
                        "<td>&nbsp;</td>" +
                        "</tr><tr><td>&nbsp;</td><td style='font-weight:bold;'>Fecha Liquidación:</td>" +
                        "<td>" + FechaLi + "</td></tr></tbody></table></div>" +

                        "<div style='background: linear-gradient(top, #D3D7DA 0%, #E2EBF4 100%);background: -moz-linear-gradient(top, #D3D7DA 0%, #E2EBF4 100%);" +
                        "background: -webkit-linear-gradient(top, #D3D7DA 0%,#E2EBF4 100%);font-weight: bold;padding: 5px;border: 1px solid #959595;text-align: left;'>Detalle Problema</div>" +
                        "<div style='padding: 10px;border: 1px solid #959595;border-top: 0px;margin-bottom: 2px;'>" +
                        "<table style='width: 100%;'>" +
                        "<tbody><tr><td style='width:140px;font-weight:bold;'>Observación:</td><td>" + comentario + "</td></tr>" +
                        "<tr><td colspan='2' style='width:140px;font-weight:bold;'>Para Responder Acceda al siguiente link: http://resp_fact.qgchile.cl/index.aspx?soli=" + id + " </td></tr></tbody></table></div>" +

                        "<br />" +
                        "Atentamente," +
                        "<br />" +
                        "Equipo de desarrollo A Impresores S.A" +
                        "</td>" +
                        "</tr>" +
                        "</table>";

            mmsg.BodyEncoding = System.Text.Encoding.UTF8;
            mmsg.IsBodyHtml   = true; //Si no queremos que se envíe como HTML

            //Correo electronico desde la que enviamos el mensaje
            mmsg.From = new System.Net.Mail.MailAddress("*****@*****.**");


            /*-------------------------CLIENTE DE CORREO----------------------*/

            //Creamos un objeto de cliente de correo
            System.Net.Mail.SmtpClient cliente = new System.Net.Mail.SmtpClient();

            //Hay que crear las credenciales del correo emisor
            cliente.Credentials =
                new System.Net.NetworkCredential("*****@*****.**", "SI2013.");

            cliente.Host = "mail.aimpresores.cl";


            /*-------------------------ENVIO DE CORREO----------------------*/

            try
            {
                //Enviamos el mensaje
                cliente.Send(mmsg);
                return(true);
                //lblaglo.Text = "enviado correctamente";
            }
            catch (System.Net.Mail.SmtpException ex)
            {
                return(false);
                //Aquí gestionamos los errores al intentar enviar el correo
                //lblaglo.Text = "error al enviar el correo";
            }
        }