private void toolStripButtonSave_Click(object sender, EventArgs e) { try { if (dataGridViewOCItemSinStock.Rows.Count > 0) { if (checkBoxAutoriza.Checked || checkBoxNoAutoriza.Checked) { Entities.Tables.COMORDENCOMPRADETALLE _itemOC = new Entities.Tables.COMORDENCOMPRADETALLE(); List <Entities.Tables.COMORDENCOMPRADETALLE> _items = new List <Entities.Tables.COMORDENCOMPRADETALLE>(); Entities.Tables.COMORDENCOMPRA _itemCab = new Entities.Tables.COMORDENCOMPRA(); BLL.Tables.COMORDENCOMPRA _auto = new BLL.Tables.COMORDENCOMPRA(); for (int i = 0; i < this.dataGridViewOCItemSinStock.Rows.Count; i++) { _itemOC = new Entities.Tables.COMORDENCOMPRADETALLE(); _itemOC.CODEMP = dataGridViewOCItemSinStock.Rows[i].Cells[(int)Col_OCItem.CODEMP].Value.ToString(); _itemOC.ORDENCOMPRA_ID = Convert.ToInt32(dataGridViewOCItemSinStock.Rows[i].Cells[(int)Col_OCItem.NRO_OC].Value); _itemOC.IMPORTE = Convert.ToDouble(dataGridViewOCItemSinStock.Rows[i].Cells[(int)Col_OCItem.PRECIO].Value.ToString(), culture); _itemOC.CANTIDAD = Convert.ToDecimal(dataGridViewOCItemSinStock.Rows[i].Cells[(int)Col_OCItem.CANTIDAD].Value.ToString(), culture); _itemOC.NROITEM = Convert.ToInt32(dataGridViewOCItemSinStock.Rows[i].Cells[(int)Col_OCItem.ITEM].Value); _itemOC.DETALLE = dataGridViewOCItemSinStock.Rows[i].Cells[(int)Col_OCItem.DETALLE].Value.ToString(); //VERIFICA SI ESTA AUTORIZADO if (checkBoxAutoriza.Checked) { _itemOC.NIVELAUTO_ID = 2; _items.Add(_itemOC); //VOY AGREGANDO A LA COLECCION } //VERIFICA SI LO ESTA RECHAZANDO if (checkBoxNoAutoriza.Checked) { _itemOC.NIVELAUTO_ID = 3; _items.Add(_itemOC); //VOY AGREGANDO A LA COLECCION } } //DATOS PARA LA CABECERA _itemCab.CODEMP = dataGridViewOCCabSinStock.Rows[dataGridViewOCCabSinStock.CurrentRow.Index].Cells[(int)Col_OCCab.CODEMP].Value.ToString(); _itemCab.ORDENCOMPRA_ID = Convert.ToInt32(dataGridViewOCCabSinStock.Rows[dataGridViewOCCabSinStock.CurrentRow.Index].Cells[(int)Col_OCCab.NRO_OC].Value); //PASO EL USUARIO LOGEADO _itemCab.USUARIOAUTORIZA = Clases.Usuario.UsuarioLogeado.usuario_Logeado.ToString(); //ACTUALIZO CABECERA E ITEMS _auto.AutorizaOrdenCompra(_items, _itemCab); MessageBox.Show("La autorización se guardó correctamente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); //DialogResult _result = MessageBox.Show("Desea enviar al Proveedor la Orden de Compra por mail?", "Mensaje", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); //if (_result == System.Windows.Forms.DialogResult.OK) //{ // //ENVIO POR MAIL, SOLO LOS QUE SELECCIONO Y SI ESTE PROVEEDOR TIENE UN MAIL VÁLIDO // if (dataGridViewOCCabSinStock.Rows[dataGridViewOCCabSinStock.CurrentRow.Index].Cells[(int)Col_OCCab.EMAIL].Value != null && dataGridViewOCCabSinStock.Rows[dataGridViewOCCabSinStock.CurrentRow.Index].Cells[(int)Col_OCCab.EMAIL].Value != string.Empty) // { // //ExportToMSMail(_itemCab.CODEMP, _itemCab.ORDENCOMPRA_ID); // if (GenerarPDFOC(_itemCab.CODEMP, _itemCab.ORDENCOMPRA_ID, dataGridViewOCCabSinStock.Rows[dataGridViewOCCabSinStock.CurrentRow.Index].Cells[(int)Col_OCCab.EMAIL].Value.ToString())) // { // MessageBox.Show("Mail enviado correctamente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); // } // else // { // MessageBox.Show("No se pudo enviar el mail al proveedor", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); // } // } //} TraeOCPendientes(); dataGridViewOCItemSinStock.Rows.Clear(); } else { MessageBox.Show("Debe seleccionar al menos una opción de Autorización", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { } }
private void toolStripButtonSave_Click(object sender, EventArgs e) { try { Entities.Tables.COMORDENCOMPRAITEM _itemOC = new Entities.Tables.COMORDENCOMPRAITEM(); List <Entities.Tables.COMORDENCOMPRAITEM> _items = new List <Entities.Tables.COMORDENCOMPRAITEM>(); Entities.Tables.COMORDENCOMPRA _itemCab = new Entities.Tables.COMORDENCOMPRA(); BLL.Tables.COMORDENCOMPRA _auto = new BLL.Tables.COMORDENCOMPRA(); bool _selecciono = false; for (int i = 0; i < this.dataGridViewOCItem.Rows.Count; i++) { DataGridViewCheckBoxCell cellSelecion = dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.AUTORIZA] as DataGridViewCheckBoxCell; DataGridViewCheckBoxCell cellSelecionNoAuto = dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.NO_AUTORIZA] as DataGridViewCheckBoxCell; _itemOC = new Entities.Tables.COMORDENCOMPRAITEM(); _itemOC.CODEMP = dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.CODEMP].Value.ToString(); _itemOC.ARTICULO_ID = dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.ARTICULO_ID].Value.ToString(); _itemOC.ORDENCOMPRA_ID = Convert.ToInt32(dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.NRO_OC].Value); _itemOC.NROITEM = Convert.ToInt32(dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.NRO_ITEM].Value); _itemOC.UNIMED = dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.UNIDAD_DE_MEDIDA].Value.ToString(); _itemOC.PRECIO = Convert.ToDecimal(dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.PRECIO].Value.ToString(), culture); _itemOC.CANTIDAD = Convert.ToDecimal(dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.CANTIDAD].Value.ToString(), culture); _itemOC.MARCA = (dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.MARCA].Value == null) ? string.Empty : dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.MARCA].Value.ToString(); _itemOC.FECHAENTREGA = Convert.ToDateTime(dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.FECHA_DE_ENTREGA].Value); //VERIFICA SI ESTA AUTORIZADO if (Convert.ToBoolean(cellSelecion.Value)) { _selecciono = true; _itemOC.NIVELAUT_ID = 2; _items.Add(_itemOC); //VOY AGREGANDO A LA COLECCION } //VERIFICA SI LO ESTA RECHAZANDO if (Convert.ToBoolean(cellSelecionNoAuto.Value)) { _selecciono = true; _itemOC.NIVELAUT_ID = 3; _items.Add(_itemOC); //VOY AGREGANDO A LA COLECCION } } //DATOS PARA LA CABECERA _itemCab.CODEMP = dataGridViewOCCab.Rows[dataGridViewOCCab.CurrentRow.Index].Cells[(int)Col_OCCab.CODEMP].Value.ToString(); _itemCab.ORDENCOMPRA_ID = Convert.ToInt32(dataGridViewOCCab.Rows[dataGridViewOCCab.CurrentRow.Index].Cells[(int)Col_OCCab.NRO_OC].Value); //PASO EL USUARIO LOGEADO _itemCab.USUARIOAUTORIZA = Clases.Usuario.UsuarioLogeado.usuario_Logeado.ToString(); //ACTUALIZO CABECERA E ITEMS _auto.AutorizaOrdenCompra(_items, _itemCab); if (_selecciono) { MessageBox.Show("La autorización se guardó correctamente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult _result = MessageBox.Show("Desea enviar al Proveedor la Orden de Compra por mail?", "Mensaje", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (_result == System.Windows.Forms.DialogResult.OK) { //ENVIO POR MAIL, SOLO LOS QUE SELECCIONO Y SI ESTE PROVEEDOR TIENE UN MAIL VÁLIDO if (_selecciono) { //VERIFICO QUE ESTE PROVEEDOR TENGA CARGADO AL MENOS UN MAIL if (dataGridViewOCCab.Rows[dataGridViewOCCab.CurrentRow.Index].Cells[(int)Col_OCCab.EMAIL].Value == null || dataGridViewOCCab.Rows[dataGridViewOCCab.CurrentRow.Index].Cells[(int)Col_OCCab.EMAIL].Value == string.Empty) { MessageBox.Show("Este proveedor no tiene cargado ninguna dirección de mail", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (GenerarPDFOC(_itemCab.CODEMP, _itemCab.ORDENCOMPRA_ID, dataGridViewOCCab.Rows[dataGridViewOCCab.CurrentRow.Index].Cells[(int)Col_OCCab.EMAIL].Value.ToString())) { MessageBox.Show("Mail enviado correctamente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("No se pudo enviar el mail al proveedor, verifique si tiene cargado correctamente una dirección de mail", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } TraeOCPendientes(); dataGridViewOCItem.Rows.Clear(); } else { MessageBox.Show("Debe seleccionar al menos un Articulo", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }