Beispiel #1
0
        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 (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);
            }
        }
Beispiel #3
0
        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.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 = _condPagoProveed;                                     // CONDICIOND DE PAGO
                //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;
                if (this.comboBoxLugarEntrega.SelectedIndex > 0)
                {
                    _OCCabecera.SECTORENTREGA_ID = Convert.ToInt32(this.comboBoxLugarEntrega.SelectedValue);//SECTOR DE ENTREGA
                }
                //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

                //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_Detalle.CANTIDAD].Value != string.Empty && dataGridViewDetalleOC.Rows[i].Cells[(int)Col_Detalle.CANTIDAD].Value != null && dataGridViewDetalleOC.Rows[i].Cells[(int)Col_Detalle.PRECIO].Value != string.Empty && dataGridViewDetalleOC.Rows[i].Cells[(int)Col_Detalle.PRECIO].Value != null && dataGridViewDetalleOC.Rows[i].Cells[(int)Col_Detalle.DETALLE].Value != null && dataGridViewDetalleOC.Rows[i].Cells[(int)Col_Detalle.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.DETALLE      = dataGridViewDetalleOC.Rows[i].Cells[(int)Col_Detalle.DETALLE].Value.ToString();                           //this.textBoxDetalle.Text.Trim();
                        _OCDetalle.NIVELAUTO_ID = 1;                                                                                                        //LA AUTORIZA SERGIO !!!!
                        _OCDetalle.IMPORTE      = Convert.ToDouble(dataGridViewDetalleOC.Rows[i].Cells[(int)Col_Detalle.PRECIO].Value.ToString(), culture); //Convert.ToDouble(this.textBoxImporte.Text.ToString(), culture);
                        _OCDetalle.CANTIDAD     = Convert.ToDecimal(dataGridViewDetalleOC.Rows[i].Cells[(int)Col_Detalle.CANTIDAD].Value.ToString(), culture);
                        _OCDetalle.NROITEM      = i + 1;

                        _listDetalle.Add(_OCDetalle);
                    }
                }

                int _NroOC;
                _NroOC = _OCCab.AddItem(_OCCabecera, _listDetalle);
                if (_NroOC > 0)
                {
                    MessageBox.Show("Se generó la orden de compra Nro:" + " " + _NroOC, "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    this.textBoxObs.Text                    = "";
                    this.textBoxDetalle.Text                = string.Empty;
                    this.textBoxImporte.Text                = string.Empty;
                    this.comboBoxProveed.SelectedIndex      = 0;
                    this.comboBoxLugarEntrega.SelectedIndex = 0;
                    dataGridViewDetalleOC.Rows.Clear();
                }
                else
                {
                    MessageBox.Show("Error al grabar Orden de Compra", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }