예제 #1
0
        private void CorreosNCPendientes_Load(object sender, EventArgs e)
        {
            try
            {
                this.Icon = ClasesSGUV.Propiedades.IconHalcoNET;

                this.LlenarGrid(8, dgvSucursal);
                // this.LlenarGrid(9, dgvJefaCobranza);

                List <string> ListVendedores = new List <string>();
                ListVendedores = (from item in (dgvSucursal.DataSource as DataTable).AsEnumerable()
                                  select item.Field <string>("Vendedor")).Distinct().ToList();
                try
                {
                    foreach (string item in ListVendedores)
                    {
                        DataTable table = (from row in (dgvSucursal.DataSource as DataTable).AsEnumerable()
                                           where row.Field <string>("Vendedor") == item
                                           select row).CopyToDataTable();

                        string _rutaGerentes = this.GenerPDFGerente(table, item);

                        string _mailVendedor = (from row in (dgvSucursal.DataSource as DataTable).AsEnumerable()
                                                where row.Field <string>("Vendedor") == item
                                                select row.Field <string>("MailVendedor")).FirstOrDefault();

                        string _mailGerente = (from row in (dgvSucursal.DataSource as DataTable).AsEnumerable()
                                               where row.Field <string>("Vendedor") == item
                                               select row.Field <string>("MailGerente")).FirstOrDefault();

                        string _mailJefa = (from row in (dgvSucursal.DataSource as DataTable).AsEnumerable()
                                            where row.Field <string>("Vendedor") == item
                                            select row.Field <string>("MailJefa")).FirstOrDefault();

                        SendMail mail = new SendMail();
                        /*******************/
                        if (item.Trim().Equals("Jorge Lopez Aguilar"))
                        {
                            mail.EnviarNC(_rutaGerentes, "[email protected];" + _mailGerente + ";" + _mailJefa, item, _mailVendedor, table.Rows.Count);
                        }
                        else
                        {
                            mail.EnviarNC(_rutaGerentes, _mailGerente + ";" + _mailJefa, item, _mailVendedor, table.Rows.Count);
                        }
                        //mail.EnviarNC(_rutaGerentes, "*****@*****.**", item, "*****@*****.**", table.Rows.Count);

                        foreach (DataRow factura in (dgvSucursal.DataSource as DataTable).AsEnumerable())
                        {
                            if (factura.Field <string>("Vendedor") == item)
                            {
                                using (SqlConnection connection = new SqlConnection(ClasesSGUV.Propiedades.conectionSGUV))
                                {
                                    using (SqlCommand command = new SqlCommand("Update [@PreciosCliente] SET U_EnviadoGerente = 'Y'  Where U_DocEntry = @DocEntry", connection))
                                    {
                                        connection.Open();

                                        command.Parameters.AddWithValue("@DocEntry", factura.Field <Int32>("U_Docentry"));

                                        command.ExecuteNonQuery();
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Error inesperado", "HalcoNET", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                this.Close();
            }
        }