예제 #1
0
        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);
            }
        }
예제 #2
0
        private void toolStripButtonSave_Click(object sender, EventArgs e)
        {
            try
            {
                int  _cantidaditems     = this.dataGridViewOCItem.Rows.Count;
                int  _cantExcluidos     = 0;
                bool _excluyoAlMenosUno = false;
                Entities.Tables.COMORDENCOMPRAITEM        _item    = new Entities.Tables.COMORDENCOMPRAITEM();
                List <Entities.Tables.COMORDENCOMPRAITEM> _Items   = new List <Entities.Tables.COMORDENCOMPRAITEM>();
                BLL.Procedures.EXCLUYEITEMSOC             _excluye = new BLL.Procedures.EXCLUYEITEMSOC();

                for (int i = 0; i < this.dataGridViewOCItem.Rows.Count; i++)
                {
                    DataGridViewCheckBoxCell cellSelecion = dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.EXCLUIDO] as DataGridViewCheckBoxCell;

                    _item                = new Entities.Tables.COMORDENCOMPRAITEM();
                    _item.CODEMP         = _codEmp;
                    _item.ORDENCOMPRA_ID = OC_ID;
                    _item.NROITEM        = Convert.ToInt32(dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.NROITEM].Value);
                    if (dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.MOTIVO].Value == null)
                    {
                        _item.MOTIVOEXCLUSION = "";
                    }
                    else
                    {
                        _item.MOTIVOEXCLUSION = dataGridViewOCItem.Rows[i].Cells[(int)Col_OCItem.MOTIVO].Value.ToString().ToUpper();
                    }
                    _item.USUARIOEXCLUYE = Clases.Usuario.UsuarioLogeado.usuario_Logeado.ToString();

                    if (Convert.ToBoolean(cellSelecion.Value))
                    {
                        _item.EXCLUIDO = true;
                        _cantExcluidos++;
                        _Items.Add(_item);
                        _excluyoAlMenosUno = true;
                    }
                    else  //ESTO PORQUE PUEDE VOLVER A TRAS UN ARTICULO EXLUIDO... ES DECIR LO PUEDO INCLUR DE NUEVO
                    {
                        _item.EXCLUIDO        = false;
                        _item.MOTIVOEXCLUSION = "";
                        _item.USUARIOEXCLUYE  = "";
                        _Items.Add(_item);
                    }
                }

                if (_Items.Count > 0)
                {
                    if (_cantExcluidos == _cantidaditems)
                    {
                        MessageBox.Show("No se puede excluir la totalidad de Items de la O.C.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        _excluye.ExcluyeItem(_Items);
                    }
                }
                //ACA PREGUNTAR SI SE HACE UN REQUERIMIENTO NUEVO


                if (_excluyoAlMenosUno)
                {
                    // ****** PREGUNTO SI QUIERE VOLVER A GENERAR NUEVOS REQ
                    BLL.Tables.COMREQUERIMIENTO _genera = new BLL.Tables.COMREQUERIMIENTO();
                    DialogResult _result = MessageBox.Show("Desea generar un nuevo requerimiento para la orden de compra: " + _Items.First().ORDENCOMPRA_ID + " ?", "Mensaje", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (_result == System.Windows.Forms.DialogResult.OK)
                    {
                        if (_genera.GeneraNuevosRequerimientos(_codEmp, OC_ID, "EXC"))      //Fuerzo el tipo EXC porque estoy excluyendo items y genero un nuevo Requerimiento
                        {
                            MessageBox.Show("Requerimiento generado correctamente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }      // ***** FIN GENERA NUEVOS REQ
                    else   // no quiere generar un nuevo req
                    {
                        MessageBox.Show("Items excluidos correctamente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    dataGridViewOCItem.Rows.Clear();
                    OC_ID   = 0;
                    _codEmp = string.Empty;
                }
                else
                {
                    MessageBox.Show("Items incluidos correctamente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }