private void toolStripButtonSave_Click(object sender, EventArgs e) { try { Entities.Tables.COMORDENCOMPRA _OCCabecera = new Entities.Tables.COMORDENCOMPRA(); BLL.Tables.COMORDENCOMPRA _OCCab = new BLL.Tables.COMORDENCOMPRA(); Entities.Tables.COMORDENCOMPRAITEM _OCItem = new Entities.Tables.COMORDENCOMPRAITEM(); List <Entities.Tables.COMORDENCOMPRAITEM> _ItemsCab = new List <Entities.Tables.COMORDENCOMPRAITEM>(); Boolean _selecciono = false; if (this.dataGridViewDetalleReqCotizados.Rows.Count > 0) { //cabecera _OCCabecera.FECHA = Convert.ToDateTime(DateTime.Now.ToShortDateString()); //FECHA _OCCabecera.PROVEED_ID = dataGridViewProveedorCotizado.Rows[dataGridViewProveedorCotizado.CurrentRow.Index].Cells[(int)Col_Proveedores.PROVEEDOR_ID].Value.ToString(); // PROVEEDOR _OCCabecera.ESTADO_ID = 1; //Ojo ver que valor se envia despues //ESTADO _OCCabecera.TIPOOC_ID = 3; //OJO COLOCAR EL VALOR REAL DE ORDEN DE COMPRA SEGUN REQUERIMIENTO _OCCabecera.MODIFICACOSTO = 0; //MODIFICA COSTO string _codEmp = this.comboBoxEmpresa.SelectedValue.ToString(); _OCCabecera.CODEMP = _codEmp; _OCCabecera.CONDICIONPAGO_ID = "0"; // CONDICIOND DE PAGO _OCCabecera.OBS = this.textBoxObs.Text.Trim(); //OBS _OCCabecera.USUARIO = Clases.Usuario.UsuarioLogeado.usuario_Logeado; int _nroCotizacion = Convert.ToInt32(dataGridViewProveedorCotizado.Rows[dataGridViewProveedorCotizado.CurrentRow.Index].Cells[(int)Col_Proveedores.NROCOTIZACION].Value.ToString()); for (int i = 0; i < this.dataGridViewDetalleReqCotizados.Rows.Count; i++) { _OCItem = new Entities.Tables.COMORDENCOMPRAITEM(); //RECUPERO LOS ITEMS DE ESTA COTIZACION DataGridViewCheckBoxCell cellSelecion = dataGridViewDetalleReqCotizados.Rows[i].Cells[(int)Col_items.INCLUIR] as DataGridViewCheckBoxCell; if (Convert.ToBoolean(cellSelecion.Value)) { //VOY GUARDANSDO LOS ITEMS DE LA ORDEN DE COMPRA _selecciono = true; _OCItem.ARTICULO_ID = dataGridViewDetalleReqCotizados.Rows[i].Cells[(int)Col_items.ARTICULO_ID].Value.ToString(); _OCItem.UNIMED = dataGridViewDetalleReqCotizados.Rows[i].Cells[(int)Col_items.UNIMED].Value.ToString(); _OCItem.PRECIO = Convert.ToDecimal(dataGridViewDetalleReqCotizados.Rows[i].Cells[(int)Col_items.PRECIO].Value.ToString(), culture); _OCItem.CANTIDAD = Convert.ToDecimal(dataGridViewDetalleReqCotizados.Rows[i].Cells[(int)Col_items.CANTIDAD].Value.ToString(), culture); _OCItem.FECHAENTREGA = Convert.ToDateTime(this.dateTimePickerFechaEntrega.Value.ToShortDateString()); _OCItem.NIVELAUT_ID = 1; //ojo ver como se envia despues _OCItem.CODEMPREQUERIMIENTO = _codEmp; //VOY AGREGANDO A LA COLECCION _ItemsCab.Add(_OCItem); } } if (!_selecciono) { MessageBox.Show("Para generar una Orden de Compra, debe seleccionar al menos un artículo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //LLAMO A LA FUNCION QUE GUARDA CABECERA E ITEMS int _NroOC; _NroOC = _OCCab.GeneraOrdenDeCompraSegunCotizacion(_OCCabecera, _ItemsCab, _nroCotizacion); if (_NroOC > 0) { MessageBox.Show("Se generó la orden de compra Nro:" + " " + _NroOC, "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); dataGridViewDetalleReqCotizados.Rows.Clear(); this.dateTimePickerFechaEntrega.Value = Convert.ToDateTime(DateTime.Now.ToShortDateString()); string _empresa = this.comboBoxEmpresa.SelectedValue.ToString(); TraeProveedoresCotizados(_empresa); } else { MessageBox.Show("Error al grabar Orden de Compra", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void toolStripButtonSave_Click(object sender, EventArgs e) { try { BLL.Procedures.ANULA_OC _OrdenCompra = new BLL.Procedures.ANULA_OC(); //** objetos de OC para volver a generar el nuevo requerimiento Entities.Tables.COMORDENCOMPRA _ocAnulada = new Entities.Tables.COMORDENCOMPRA(); List <Entities.Tables.COMORDENCOMPRA> _listOcAnulada = new List <Entities.Tables.COMORDENCOMPRA>(); // *** string _codEmp; Int32 _nroOC; string _motivo; Boolean _selecciono = false; for (int i = 0; i < this.dataGridViewOC.Rows.Count; i++) { DataGridViewCheckBoxCell cellSelecion = dataGridViewOC.Rows[i].Cells[(int)Col_OC.ANULAR] as DataGridViewCheckBoxCell; _nroOC = Convert.ToInt32(dataGridViewOC.Rows[i].Cells[(int)Col_OC.NRO_ORDEN_COMPRA].Value); _codEmp = dataGridViewOC.Rows[i].Cells[(int)Col_OC.CODEMP].Value.ToString(); if (Convert.ToBoolean(cellSelecion.Value)) { _selecciono = true; if (dataGridViewOC.Rows[i].Cells[(int)Col_OC.MOTIVO].Value == null || dataGridViewOC.Rows[i].Cells[(int)Col_OC.MOTIVO].Value == string.Empty) { MessageBox.Show("Debe ingresar un Motivo de Anulación", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _motivo = dataGridViewOC.Rows[i].Cells[(int)Col_OC.MOTIVO].Value.ToString(); _OrdenCompra.AnulaOrdenDeCompra(_codEmp, _nroOC, Convert.ToDateTime(DateTime.Now.ToShortTimeString()), _motivo); //creo los objetos por si el usuario quiere generar nuevos requerimientos, SOLO LAS O.C. QUE SEAN POR REQUERIMIENTO O BIONEXO if (dataGridViewOC.Rows[i].Cells[(int)Col_OC.TIPOOC].Value.ToString() == "2" || dataGridViewOC.Rows[i].Cells[(int)Col_OC.TIPOOC].Value.ToString() == "3") { _ocAnulada = new Entities.Tables.COMORDENCOMPRA(); _ocAnulada.CODEMP = _codEmp; _ocAnulada.ORDENCOMPRA_ID = _nroOC; _listOcAnulada.Add(_ocAnulada); //fin crea objetos OC anuladas } } } if (_selecciono) { MessageBox.Show("La orden de compra se anuló correctamente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); dataGridViewOC.Rows.Clear(); // ****** PREGUNTO SI QUIERE VOLVER A GENERAR NUEVOS REQ List <Entities.Tables.COMORDENCOMPRA> _ItemsnewOC = new List <Entities.Tables.COMORDENCOMPRA>(); Entities.Tables.COMORDENCOMPRA _newOC = new Entities.Tables.COMORDENCOMPRA(); BLL.Tables.COMREQUERIMIENTO _genera = new BLL.Tables.COMREQUERIMIENTO(); foreach (Entities.Tables.COMORDENCOMPRA item in _listOcAnulada) { DialogResult _result = MessageBox.Show("Desea generar un nuevo requerimiento para la orden de compra: " + item.ORDENCOMPRA_ID + " ?", "Mensaje", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (_result == System.Windows.Forms.DialogResult.OK) { _newOC = new Entities.Tables.COMORDENCOMPRA(); //VOY GUARDANDO LAS OC PARA GENERAR LOS REQ _newOC.CODEMP = item.CODEMP; _newOC.ORDENCOMPRA_ID = item.ORDENCOMPRA_ID; _ItemsnewOC.Add(_newOC); } } if (_ItemsnewOC.Count > 0) { if (_genera.GeneraNuevosRequerimientos(_ItemsnewOC, "ANU"))//Fuerzo el ANU porque es una anulacion de la O.C genero todos los Items como nuevo Req. { MessageBox.Show("Requerimiento generado correctamente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); } } // ***** FIN GENERA NUEVOS REQ TraeOCPendientes(); } else { MessageBox.Show("Debe seleccionar al menos una OC", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void toolStripButtonSave_Click(object sender, EventArgs e) { try { if (VerificaIngreso()) { Entities.Tables.COMORDENCOMPRA _OCCabecera = new Entities.Tables.COMORDENCOMPRA(); BLL.Tables.COMORDENCOMPRA _OCCab = new BLL.Tables.COMORDENCOMPRA(); Entities.Tables.COMORDENCOMPRAITEM _OCItem = new Entities.Tables.COMORDENCOMPRAITEM(); // BLL.Tables.COMORDENCOMPRAITEM _OCIte = new BLL.Tables.COMORDENCOMPRAITEM(); List <Entities.Tables.COMORDENCOMPRAITEM> _ItemsCab = new List <Entities.Tables.COMORDENCOMPRAITEM>(); CultureInfo culture = new CultureInfo("en-US"); _OCCabecera.FECHA = Convert.ToDateTime(DateTime.Now.ToShortDateString()); //FECHA _OCCabecera.PROVEED_ID = this.comboBoxProveed.SelectedValue.ToString(); // PROVEEDOR _OCCabecera.ESTADO_ID = 1; //Ojo ver que valor se envia despues //ESTADO _OCCabecera.TIPOOC_ID = 1; //OJO COLOCAR EL VALOR REAL DE ORDEN DE COMPRA DIRECTA _OCCabecera.MODIFICACOSTO = (this.radioButtonNo.Checked) ? 0 : 1; //MODIFICA COSTO _OCCabecera.CODEMP = this.comboBoxcodEmp.SelectedValue.ToString(); //EMPRESA PARA LA CUAL SE HACE LA OC _OCCabecera.CONDICIONPAGO_ID = _condPagoProveed; // CONDICIOND DE PAGO _OCCabecera.OBS = this.textBoxObs.Text.Trim(); _OCCabecera.USUARIO = Clases.Usuario.UsuarioLogeado.usuario_Logeado; _OCCabecera.PEDIDODIARIO = (this.checkBoxdiaria.Checked) ? true : false; if (this.comboBoxLugarEntrega.SelectedIndex > 0) { _OCCabecera.SECTORENTREGA_ID = Convert.ToInt32(this.comboBoxLugarEntrega.SelectedValue); //SECTOR DE ENTREGA } DateTime _fechaEntrega; for (int i = 0; i < this.dataGridViewOCDirecta.Rows.Count; i++) { if (dataGridViewOCDirecta.Rows[i].Cells[(int)Col_Detalle.CANTIDAD].Value != string.Empty && dataGridViewOCDirecta.Rows[i].Cells[(int)Col_Detalle.CANTIDAD].Value != null && dataGridViewOCDirecta.Rows[i].Cells[(int)Col_Detalle.PRECIO].Value != string.Empty && dataGridViewOCDirecta.Rows[i].Cells[(int)Col_Detalle.PRECIO].Value != null) { _OCItem = new Entities.Tables.COMORDENCOMPRAITEM(); //_ReqItem.COMEMP = Clases.Usuario.EmpresaLogeada.EmpresaIngresada; _OCItem.ARTICULO_ID = dataGridViewOCDirecta.Rows[i].Cells[(int)Col_Detalle.CODIGO].Value.ToString(); _OCItem.UNIMED = dataGridViewOCDirecta.Rows[i].Cells[(int)Col_Detalle.UNIDAD].Value.ToString(); _OCItem.PRECIO = Convert.ToDecimal(dataGridViewOCDirecta.Rows[i].Cells[(int)Col_Detalle.PRECIO].Value.ToString(), culture); _OCItem.CANTIDAD = Convert.ToDecimal(dataGridViewOCDirecta.Rows[i].Cells[(int)Col_Detalle.CANTIDAD].Value.ToString(), culture); _fechaEntrega = Convert.ToDateTime(Convert.ToDateTime(dataGridViewOCDirecta.Rows[i].Cells[(int)Col_Detalle.FENTREGA].Value)); if (_fechaEntrega == DateTime.MinValue) { _OCItem.FECHAENTREGA = Convert.ToDateTime(DateTime.Now.ToShortDateString()); } else { _OCItem.FECHAENTREGA = Convert.ToDateTime(Convert.ToDateTime(dataGridViewOCDirecta.Rows[i].Cells[(int)Col_Detalle.FENTREGA].Value)); } _OCItem.NIVELAUT_ID = 1; //ojo ver como se envia despues _OCItem.CODEMP = this.comboBoxcodEmp.SelectedValue.ToString(); //EMPRESA PARA LA CUAL SE HACE LA OC //VERIFICO SI SELECCIONO UNA MARCA if (dataGridViewOCDirecta.Rows[i].Cells[(int)Col_Detalle.MARCA].EditedFormattedValue != null && dataGridViewOCDirecta.Rows[i].Cells[(int)Col_Detalle.MARCA].Value != "0" && dataGridViewOCDirecta.Rows[i].Cells[(int)Col_Detalle.MARCA].Value != "<Sin Definir>") { _OCItem.MARCA = dataGridViewOCDirecta.Rows[i].Cells[(int)Col_Detalle.MARCA].EditedFormattedValue.ToString(); } _ItemsCab.Add(_OCItem); //Meto en la coleccion todos los elementos de la grilla } } if (_ItemsCab.Count > 0) { //LLAMO A LA FUNCION QUE GUARDA CABECERA E ITEMS int _NroOC; _NroOC = _OCCab.AddItem(_OCCabecera, _ItemsCab); if (_NroOC > 0) { MessageBox.Show("Se generó la orden de compra Nro:" + " " + _NroOC, "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); dataGridViewOCDirecta.Rows.Clear(); this.textBoxObs.Text = ""; this.comboBoxProveed.SelectedIndex = 0; this.comboBoxrubro.SelectedIndex = 0; } else { MessageBox.Show("Error al grabar Orden de Compra", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Para todos los items seleccionados, debe ingresar un precio y cantidad", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { MessageBox.Show("Debe completar todos los datos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void toolStripButtonSave_Click(object sender, EventArgs e) { if (VerificaIngreso()) { Entities.Tables.COMORDENCOMPRA _OCCabecera = new Entities.Tables.COMORDENCOMPRA(); BLL.Tables.COMORDENCOMPRA _OCCab = new BLL.Tables.COMORDENCOMPRA(); //Entities.Tables.COMORDENCOMPRADETALLE _OCDetalle = new Entities.Tables.COMORDENCOMPRADETALLE(); List <Entities.Tables.COMORDENCOMPRADETALLE> _listDetalle = new List <Entities.Tables.COMORDENCOMPRADETALLE>(); CultureInfo culture = new CultureInfo("en-US"); _OCCabecera.ORDENCOMPRA_ID = _OrdenCompraModifica; _OCCabecera.FECHA = Convert.ToDateTime(DateTime.Now.ToShortDateString()); //FECHA _OCCabecera.PROVEED_ID = this.comboBoxProveed.SelectedValue.ToString(); // PROVEEDOR _OCCabecera.ESTADO_ID = 1; //Ojo ver que valor se envia despues //ESTADO _OCCabecera.TIPOOC_ID = 4; //ORDEN DE COMPRA DE SERVICIO, SIN STOCK _OCCabecera.MODIFICACOSTO = 0; //MODIFICA COSTO _OCCabecera.CODEMP = this.comboBoxcodEmp.SelectedValue.ToString(); //EMPRESA PARA LA CUAL SE HACE LA OC _OCCabecera.CONDICIONPAGO_ID = ""; // CONDICIOND DE PAGO NO ENVIO NADA //ya la dejo autorizada //_OCCabecera.FECHAAUTORIZACION = Convert.ToDateTime(DateTime.Now.ToShortDateString()); //FECHA //_OCCabecera.USUARIOAUTORIZA = Clases.Usuario.UsuarioLogeado.usuario_Logeado; _OCCabecera.OBS = this.textBoxObs.Text.Trim(); _OCCabecera.USUARIO = Clases.Usuario.UsuarioLogeado.usuario_Logeado; _OCCabecera.PEDIDODIARIO = false; //PRORRATEO EMPRESA- CUOTAS if (!checkBoxCuotas.Checked && !checkBoxEmpresa.Checked) { _OCCabecera.TIPOPRORRATEO = 1; //SIN PRORRATEO } if (checkBoxEmpresa.Checked && !checkBoxCuotas.Checked) { _OCCabecera.TIPOPRORRATEO = 2; //SOLO EMPRESA } if (checkBoxCuotas.Checked && !checkBoxEmpresa.Checked) { _OCCabecera.TIPOPRORRATEO = 3; //SOLO CUOTAS } if (checkBoxCuotas.Checked && checkBoxEmpresa.Checked) { _OCCabecera.TIPOPRORRATEO = 4; //AMBOS } //FIN PRORRATEO if (this.comboBoxLugarEntrega.SelectedIndex > 0) { _OCCabecera.SECTORENTREGA_ID = Convert.ToInt32(this.comboBoxLugarEntrega.SelectedValue);//SECTOR DE ENTREGA } bool _hayItems = false; //AHORA LOS OBJETOS DE LA TABLA COMORDENCOMPRADETALLE for (int i = 0; i < this.dataGridViewDetalleOC.Rows.Count - 1; i++) { if (dataGridViewDetalleOC.Rows[i].Cells[(int)Col_OCDetalle.CANTIDAD].Value != string.Empty && dataGridViewDetalleOC.Rows[i].Cells[(int)Col_OCDetalle.CANTIDAD].Value != null && dataGridViewDetalleOC.Rows[i].Cells[(int)Col_OCDetalle.PRECIO].Value != string.Empty && dataGridViewDetalleOC.Rows[i].Cells[(int)Col_OCDetalle.PRECIO].Value != null && dataGridViewDetalleOC.Rows[i].Cells[(int)Col_OCDetalle.DETALLE].Value != null && dataGridViewDetalleOC.Rows[i].Cells[(int)Col_OCDetalle.DETALLE].Value != string.Empty) { Entities.Tables.COMORDENCOMPRADETALLE _OCDetalle = new Entities.Tables.COMORDENCOMPRADETALLE(); _OCDetalle.CODEMP = this.comboBoxcodEmp.SelectedValue.ToString(); //EMPRESA PARA LA CUAL SE HACE LA OC _OCDetalle.ORDENCOMPRA_ID = _OrdenCompraModifica; _OCDetalle.DETALLE = dataGridViewDetalleOC.Rows[i].Cells[(int)Col_OCDetalle.DETALLE].Value.ToString(); //this.textBoxDetalle.Text.Trim(); _OCDetalle.NIVELAUTO_ID = 1; //LA AUTORIZA SERGIO !!!! _OCDetalle.IMPORTE = Convert.ToDouble(dataGridViewDetalleOC.Rows[i].Cells[(int)Col_OCDetalle.PRECIO].Value.ToString(), culture); //Convert.ToDouble(this.textBoxImporte.Text.ToString(), culture); _OCDetalle.CANTIDAD = Convert.ToDecimal(dataGridViewDetalleOC.Rows[i].Cells[(int)Col_OCDetalle.CANTIDAD].Value.ToString(), culture); _OCDetalle.NROITEM = i + 1; _listDetalle.Add(_OCDetalle); _hayItems = true; } } if (_hayItems) { if (_OCCab.ModificaOCSinStock(_OCCabecera, _listDetalle)) { MessageBox.Show("La orden de compra se modificó correctamente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); this.textBoxObs.Text = ""; this.textBoxImporte.Text = string.Empty; this.comboBoxProveed.SelectedIndex = 0; this.comboBoxLugarEntrega.SelectedIndex = 0; dataGridViewDetalleOC.Rows.Clear(); } else { MessageBox.Show("Error al modificar la Orden de Compra", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("No se puede modificar la orden de compra porque no tiene detalle", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void toolStripButtonSave_Click(object sender, EventArgs e) { try { Boolean _selecciono = false; bool _finaliza = false; Entities.Tables.COMORDENCOMPRA _itemCab = new Entities.Tables.COMORDENCOMPRA(); BLL.Procedures.FINALIZA_ANULA_OC _Actu = new BLL.Procedures.FINALIZA_ANULA_OC(); for (int i = 0; i < this.dataGridViewOCCab.Rows.Count; i++) { _itemCab = new Entities.Tables.COMORDENCOMPRA(); DataGridViewCheckBoxCell cellSelecion = dataGridViewOCCab.Rows[i].Cells[(int)Col_OCCab.COMPLETA] as DataGridViewCheckBoxCell; //FINALIZAR DataGridViewCheckBoxCell cellSelecionAnular = dataGridViewOCCab.Rows[i].Cells[(int)Col_OCCab.ANULAR] as DataGridViewCheckBoxCell; //ANULAR string _motivo = string.Empty; //VERIFICA SI ESTA FINALIZANDO LA OC if (Convert.ToBoolean(cellSelecion.Value)) { if (this.textBoxObs.Text == string.Empty) { MessageBox.Show("Debe ingresar un Motivo por el cual está finalizando esta Orden de Compra", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } _itemCab.CODEMP = dataGridViewOCCab.Rows[i].Cells[(int)Col_OCCab.CODEMP].Value.ToString(); _itemCab.ORDENCOMPRA_ID = Convert.ToInt32(dataGridViewOCCab.Rows[i].Cells[(int)Col_OCCab.NRO_OC].Value); //EL SECTOR LO NECESITO PARA CREAR UN NUEVO REQUERIMIENTO _itemCab.SECTORENTREGA_ID = (dataGridViewOCCab.Rows[i].Cells[(int)Col_OCCab.SECTOR_ENTREGA_ID].Value != null) ? Convert.ToInt32(dataGridViewOCCab.Rows[i].Cells[(int)Col_OCCab.SECTOR_ENTREGA_ID].Value.ToString()): 0; _motivo = this.textBoxObs.Text.Trim(); _Actu.Items("F", _itemCab.CODEMP, _itemCab.ORDENCOMPRA_ID, _motivo); _selecciono = true; _finaliza = true; } //VERIFICA SI ESTA ANULANDO LA OC *************** NO SE UTILIZA MAS.. HAY OTRO FORMULARIO PARA ANULAR LAS OC ***************************** //if (Convert.ToBoolean(cellSelecionAnular.Value)) //{ // if (this.textBoxObs.Text == string.Empty) // { // MessageBox.Show("Debe ingresar un Motivo por el cual está anulando esta Orden de Compra", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); // return; // } // _itemCab.CODEMP = dataGridViewOCCab.Rows[i].Cells[(int)Col_OCCab.CODEMP].Value.ToString(); //Clases.Usuario.EmpresaLogeada.EmpresaIngresada; // _itemCab.ORDENCOMPRA_ID = Convert.ToInt32(dataGridViewOCCab.Rows[i].Cells[(int)Col_OCCab.NRO_OC].Value); // _motivo = this.textBoxObs.Text.Trim(); // _Actu.Items("A", _itemCab.CODEMP, _itemCab.ORDENCOMPRA_ID, _motivo); // _selecciono = true; //} } if (_selecciono) { MessageBox.Show("Orden de Compra Finalizada correctamente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); // **** LUEGO DE FINALIZAR LA ORDE DE COMPRA... VERIFICO SI TIENE ARTICULOS PENDIENTES DE ENTREGAR, DE TAL MANERA DE PROPONER AL USUARIO // SI QUIERE HACER UN NUEVO REQUERIMIENTO if (_finaliza) { List <Frm_ArticulosParaNuevoRequerimiento.nuevosArticulos> _articulos = new List <Frm_ArticulosParaNuevoRequerimiento.nuevosArticulos>(); Frm_ArticulosParaNuevoRequerimiento.nuevosArticulos _itemNew = new Frm_ArticulosParaNuevoRequerimiento.nuevosArticulos(); CultureInfo culture = new CultureInfo("en-US"); bool _existenArticulos = false; for (int i = 0; i < this.dataGridViewOCItem.Rows.Count; i++) { //SOLO LOS QUE TIENEN DIFERENCIAS DE ENTREGA... ES DECIR ENTREGARON DE MENOS O NO ENTREGARON NADA Y TIENEN EL TILDE DE GENERA NUEVO REQ if (Convert.ToDecimal(dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.CANTIDADADEUDADA].Value.ToString(), culture) > 0) { _itemNew = new Frm_ArticulosParaNuevoRequerimiento.nuevosArticulos(); _existenArticulos = true; _itemNew.CodEmp = dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.CODEMP].Value.ToString(); _itemNew.Articulo = dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.ARTICULO_ID].Value.ToString(); _itemNew.Cantidad = Convert.ToDecimal(dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.CANTIDADADEUDADA].Value.ToString(), culture); _itemNew.UniMed = dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.UNIDAD_DE_MEDIDA].Value.ToString(); _itemNew.Marca = (dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.MARCA].Value != null) ? dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.MARCA].Value.ToString(): string.Empty; _itemNew.Descripcion = dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.ARTICULO].Value.ToString(); //DESCRIPCION ARTICULO _articulos.Add(_itemNew); //AGREGO A LA COLECCIÓN } } if (_existenArticulos) { DialogResult _result = MessageBox.Show("Desea generar un nuevo requerimiento con los artículos pendientes de entrega ?", "Mensaje", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (_result == DialogResult.OK) { //GENERO OBJETOS PARA EL NUEVO REQUERIMIENTO Frm_ArticulosParaNuevoRequerimiento _newReq = new Frm_ArticulosParaNuevoRequerimiento(); _newReq._itemReq = _articulos; //PASO EL OBJETO COMPLETO AL FORMULARIO QUE CREA EL REQUERIMIENOT _newReq._OrdenCompra = _itemCab; //TAMBIEN PASO LA CABECERA DE LA OC PORQUE NECESITO ALGUNOS DATOS.. COMO SER EL SECTOR DE ENTREGA _newReq.ShowDialog(); } } } dataGridViewOCItem.Rows.Clear(); TraeOCPendientes(); this.textBoxObs.Text = string.Empty; //FIN ARTICULO PARA NUEVO REQUERIMIENTO } else { MessageBox.Show("Debe seleccionar al menos una O.C", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void toolStripButtonSave_Click(object sender, EventArgs e) { try { if (VerificaIngreso()) { Entities.Tables.COMORDENCOMPRA _OCCabecera = new Entities.Tables.COMORDENCOMPRA(); BLL.Tables.COMORDENCOMPRA _OCCab = new BLL.Tables.COMORDENCOMPRA(); Entities.Tables.COMORDENCOMPRAITEM _OCItem = new Entities.Tables.COMORDENCOMPRAITEM(); List <Entities.Tables.COMORDENCOMPRAITEM> _ItemsCab = new List <Entities.Tables.COMORDENCOMPRAITEM>(); // List<Entities.Tables.COMREQUERIMIENTOORDENCOMPRA> _ItemsRequerimiento = new List<Entities.Tables.COMREQUERIMIENTOORDENCOMPRA>(); //Entities.Tables.COMREQUERIMIENTOORDENCOMPRA _OCReqIem = new Entities.Tables.COMREQUERIMIENTOORDENCOMPRA(); List <Entities.UserObJ.ReqOrdenCompra> _ItemsRequerimiento = new List <Entities.UserObJ.ReqOrdenCompra>(); Entities.UserObJ.ReqOrdenCompra _OCReqItem; _OCCabecera.FECHA = Convert.ToDateTime(this.dateTimePickerFecha.Value.ToShortDateString()); //FECHA _OCCabecera.PROVEED_ID = this.comboBoxProveed.SelectedValue.ToString(); // PROVEEDOR _OCCabecera.ESTADO_ID = 1; //Ojo ver que valor se envia despues //ESTADO _OCCabecera.TIPOOC_ID = 3; //OJO COLOCAR EL VALOR REAL DE ORDEN DE COMPRA SEGUN REQUERIMIENTO _OCCabecera.MODIFICACOSTO = (this.radioButtonNo.Checked) ? 0 : 1; //MODIFICA COSTO _OCCabecera.CODEMP = Clases.Usuario.EmpresaLogeada.EmpresaIngresada; //EMPRESA PARA LA CUAL SE HACE LA OC _OCCabecera.CONDICIONPAGO_ID = _condPagoProveed; // CONDICIOND DE PAGO _OCCabecera.OBS = this.textBoxObs.Text.Trim(); //OBS _OCCabecera.USUARIO = Clases.Usuario.UsuarioLogeado.usuario_Logeado; _OCCabecera.PEDIDODIARIO = (_pedidoDiario) ? true : false; Boolean _selecciono = false; Int32 posicion = -1; for (int i = 0; i < this.dataGridViewDetalleReqDisponibles.Rows.Count; i++) { _OCItem = new Entities.Tables.COMORDENCOMPRAITEM(); _OCReqItem = new Entities.UserObJ.ReqOrdenCompra(); DataGridViewCheckBoxCell cellSelecion = dataGridViewDetalleReqDisponibles.Rows[i].Cells[(int)Col_RequerimientoItem.INCLUIR] as DataGridViewCheckBoxCell; //SOLO GENERO LA ORDEN DE COMPRA CON LOS ITEMS SELECCIONADOS if (Convert.ToBoolean(cellSelecion.Value)) { _selecciono = true; _OCItem.ARTICULO_ID = dataGridViewDetalleReqDisponibles.Rows[i].Cells[(int)Col_RequerimientoItem.ARTICULO_ID].Value.ToString(); _OCItem.UNIMED = dataGridViewDetalleReqDisponibles.Rows[i].Cells[(int)Col_RequerimientoItem.UNIDAD_DE_MEDIDA].Value.ToString(); _OCItem.PRECIO = Convert.ToDecimal(dataGridViewDetalleReqDisponibles.Rows[i].Cells[(int)Col_RequerimientoItem.PRECIO].Value.ToString(), culture); _OCItem.CANTIDAD = Convert.ToDecimal(dataGridViewDetalleReqDisponibles.Rows[i].Cells[(int)Col_RequerimientoItem.CANTIDAD].Value.ToString(), culture); if (dataGridViewDetalleReqDisponibles.Rows[i].Cells[(int)Col_RequerimientoItem.MARCA].EditedFormattedValue != null && dataGridViewDetalleReqDisponibles.Rows[i].Cells[(int)Col_RequerimientoItem.MARCA].Value != "0" && dataGridViewDetalleReqDisponibles.Rows[i].Cells[(int)Col_RequerimientoItem.MARCA].Value != "<Sin Definir>") { _OCItem.MARCA = dataGridViewDetalleReqDisponibles.Rows[i].Cells[(int)Col_RequerimientoItem.MARCA].EditedFormattedValue.ToString(); } _OCItem.FECHAENTREGA = Convert.ToDateTime(Convert.ToDateTime(dataGridViewDetalleReqDisponibles.Rows[i].Cells[(int)Col_RequerimientoItem.FECHA_DE_ENTREGA].Value)); _OCItem.NIVELAUT_ID = 1; //ojo ver como se envia despues //VARIABLES PARA LA TABLA comRequerimientoOrdenCompra _OCItem.CODEMPREQUERIMIENTO = dataGridViewDetalleReqDisponibles.Rows[i].Cells[(int)Col_RequerimientoItem.CODEMPRESA].Value.ToString(); //EMPRESA DEL REQUERIMIENTO _OCItem.NROITEM = Convert.ToInt32(dataGridViewDetalleReqDisponibles.Rows[i].Cells[(int)Col_RequerimientoItem.NRO_ITEM].Value); //ES EL NRO DE ITEM ORIGINAL QUE LO NECESITO PARA GUARDAR EN LA TABLA comRequerimientoOrdenCompra _OCItem.REQUERIMIENTO_ID = Convert.ToInt32(dataGridViewDetalleReqDisponibles.Rows[i].Cells[(int)Col_RequerimientoItem.NRO_REQUERIMIENTO].Value); //VARIABLES PARA LA TABLA COMREQUERIMIENTOORDENCOMPRA, ESTO PORQUE PUEDO ELEGIR VARIOS REQUERIMIENTOS INCLUSIVE ELEGIR EL MISMO ARTICULO, //ES PARA NO PERDER LA TRAZABILIDAD DEL REQUERIMIENTO _OCReqItem.CodEmp = Clases.Usuario.EmpresaLogeada.EmpresaIngresada; _OCReqItem.NroItem = Convert.ToInt32(dataGridViewDetalleReqDisponibles.Rows[i].Cells[(int)Col_RequerimientoItem.NRO_ITEM].Value); //ES EL NRO DE ITEM ORIGINAL QUE LO NECESITO PARA GUARDAR EN LA TABLA comRequerimientoOrdenCompra _OCReqItem.Requerimiento_Id = Convert.ToInt32(dataGridViewDetalleReqDisponibles.Rows[i].Cells[(int)Col_RequerimientoItem.NRO_REQUERIMIENTO].Value); _OCReqItem.Articulo_id = dataGridViewDetalleReqDisponibles.Rows[i].Cells[(int)Col_RequerimientoItem.ARTICULO_ID].Value.ToString(); _ItemsRequerimiento.Add(_OCReqItem); //AGREGO A LA COLECCION //ANTES DE GUARDAR RECORRO LA COLECCION VERIFICANDO SI YA EXISTE ESTE ARTICULO, DE SER ASÍ SUMO LA CANTIDAD posicion = _ItemsCab.FindIndex((Entities.Tables.COMORDENCOMPRAITEM _miArticulo) => _miArticulo.ARTICULO_ID.Trim() == _OCItem.ARTICULO_ID.Trim()); if (posicion == -1) { _ItemsCab.Add(_OCItem); //EL ARTICULO NO ESTÁ, ENTONCES AGREGO A LA COLECCION } else { //COMO YA EXISTE, ACTUALIZO LA CANTIDAD... SUMO LO QUE YA TIENE Entities.Tables.COMORDENCOMPRAITEM query = (from ItemOC in _ItemsCab where ItemOC.ARTICULO_ID.Trim() == _OCItem.ARTICULO_ID.Trim() select ItemOC).Single(); query.CANTIDAD = query.CANTIDAD + _OCItem.CANTIDAD; } } } if (!_selecciono) { MessageBox.Show("Para generar una Orden de Compra, debe seleccionar al menos un artículo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //LLAMO A LA FUNCION QUE GUARDA CABECERA E ITEMS int _NroOC; _NroOC = _OCCab.AddItem(_OCCabecera, _ItemsCab, _ItemsRequerimiento); if (_NroOC > 0) { MessageBox.Show("Se generó la orden de compra Nro:" + " " + _NroOC, "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); dataGridViewDetalleReqDisponibles.Rows.Clear(); this.comboBoxProveed.SelectedIndex = 0; _pedidoDiario = false; // this.labelDiario.Visible = false; TraeRequerimientosPendientes(); } else { MessageBox.Show("Error al grabar Orden de Compra", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Debe completar todos los datos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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); } }