private void toolStripButtonSave_Click(object sender, EventArgs e) { try { Entities.Tables.COMREQUERIMIENTOINTERNOITEM _itemRequerimiento = new Entities.Tables.COMREQUERIMIENTOINTERNOITEM(); List <Entities.Tables.COMREQUERIMIENTOINTERNOITEM> _items = new List <Entities.Tables.COMREQUERIMIENTOINTERNOITEM>(); Entities.Tables.COMREQUERIMIENTOINTERNO _itemCab = new Entities.Tables.COMREQUERIMIENTOINTERNO(); BLL.Tables.COMREQUERIMIENTOINTERNO _auto = new BLL.Tables.COMREQUERIMIENTOINTERNO(); Boolean _selecciono = false; for (int i = 0; i < this.dataGridViewReqInternoItem.Rows.Count; i++) { _itemRequerimiento = new Entities.Tables.COMREQUERIMIENTOINTERNOITEM(); DataGridViewCheckBoxCell cellSelecion = dataGridViewReqInternoItem.Rows[i].Cells[(int)Col_RequerimientoItem.AUTORIZA] as DataGridViewCheckBoxCell; DataGridViewCheckBoxCell cellSelecionNoAuto = dataGridViewReqInternoItem.Rows[i].Cells[(int)Col_RequerimientoItem.NO_AUTORIZA] as DataGridViewCheckBoxCell; if (Convert.ToBoolean(cellSelecion.Value) || Convert.ToBoolean(cellSelecionNoAuto.Value)) { _itemRequerimiento.CODEMP = dataGridViewReqInternoItem.Rows[i].Cells[(int)Col_RequerimientoItem.CODEMPRESA].Value.ToString(); //Clases.Usuario.EmpresaLogeada.EmpresaIngresada; _itemRequerimiento.REQUERIMIENTO_ID = Convert.ToInt32(dataGridViewReqInternoItem.Rows[i].Cells[(int)Col_RequerimientoItem.NRO_REQUERIMIENTO].Value); _itemRequerimiento.NROITEM = Convert.ToInt32(dataGridViewReqInternoItem.Rows[i].Cells[(int)Col_RequerimientoItem.NRO_ITEM].Value); _itemRequerimiento.ARTICULO_ID = dataGridViewReqInternoItem.Rows[i].Cells[(int)Col_RequerimientoItem.ARTICULO_ID].Value.ToString(); _itemRequerimiento.UNIMED = dataGridViewReqInternoItem.Rows[i].Cells[(int)Col_RequerimientoItem.UNIDAD_DE_MEDIDA].Value.ToString(); _itemRequerimiento.CANTIDAD = Convert.ToDecimal(dataGridViewReqInternoItem.Rows[i].Cells[(int)Col_RequerimientoItem.CANTIDAD].Value.ToString(), culture); _itemRequerimiento.FECHAENTREGA = Convert.ToDateTime(dataGridViewReqInternoItem.Rows[i].Cells[(int)Col_RequerimientoItem.FECHA_DE_ENTREGA].Value.ToString()); _itemRequerimiento.MARCA = (dataGridViewReqInternoItem.Rows[i].Cells[(int)Col_RequerimientoItem.MARCA].Value == null) ? string.Empty : dataGridViewReqInternoItem.Rows[i].Cells[(int)Col_RequerimientoItem.MARCA].Value.ToString(); //DATOS PARA LA CABECERA _itemCab.REQUERIMIENTO_ID = Convert.ToInt32(dataGridViewReqInternoItem.Rows[i].Cells[(int)Col_RequerimientoItem.NRO_REQUERIMIENTO].Value); _itemCab.CODEMP = dataGridViewReqInternoItem.Rows[i].Cells[(int)Col_RequerimientoItem.CODEMPRESA].Value.ToString(); //VERIFICA SI ESTA AUTORIZADO if (Convert.ToBoolean(cellSelecion.Value)) { _selecciono = true; _itemRequerimiento.NIVELAUT_ID = 2; } //VERIFICA SI LO ESTA RECHAZANDO if (Convert.ToBoolean(cellSelecionNoAuto.Value)) { _selecciono = true; _itemRequerimiento.NIVELAUT_ID = 3; } _items.Add(_itemRequerimiento); } } //PASO EL USAURIO LOGEADO _itemCab.USUARIOAUTORIZA = Clases.Usuario.UsuarioLogeado.usuario_Logeado.ToString(); if (_selecciono) { _auto.AutorizaRequerimiento(_items, _itemCab); MessageBox.Show("Se Guardó correctamente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); TraeRequerimientosPendientes(); dataGridViewReqInternoItem.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); } }
private void toolStripButtonSave_Click(object sender, EventArgs e) { try { if (VerificaIngreso()) { if (comboBoxrubro.SelectedIndex == 0 && comboBoxRubro2.SelectedIndex == 0) { MessageBox.Show("Debe seleccionar un Rubro o un Subrubro ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Entities.Tables.COMREQUERIMIENTOINTERNO _ReqCabecera = new Entities.Tables.COMREQUERIMIENTOINTERNO(); BLL.Tables.COMREQUERIMIENTOINTERNO _ReqCab = new BLL.Tables.COMREQUERIMIENTOINTERNO(); Entities.Tables.COMREQUERIMIENTOINTERNOITEM _ReqItem = new Entities.Tables.COMREQUERIMIENTOINTERNOITEM(); List <Entities.Tables.COMREQUERIMIENTOINTERNOITEM> _ItemsReq = new List <Entities.Tables.COMREQUERIMIENTOINTERNOITEM>(); //CultureInfo culture = new CultureInfo("en-US"); string _empresa = Clases.Usuario.EmpresaLogeada.EmpresaIngresada.ToString(); _ReqCabecera.FECHA = Convert.ToDateTime(DateTime.Now.ToShortDateString()); _ReqCabecera.ESTADO_ID = 1; //Ojo ver que valor se envia despues _ReqCabecera.OBS = this.textBoxObs.Text.Trim(); _ReqCabecera.USUARIO = Clases.Usuario.UsuarioLogeado.usuario_Logeado; _ReqCabecera.SECTORREQUERIMIENTO_ID = Clases.Usuario.UsuarioLogeado.Id_Sector; // Ojo ver como se envia Despues _ReqCabecera.DEPOSITODESTINO_ID = Convert.ToInt32(comboBoxDepositoDestino.SelectedValue); // A QUE DEPOSITO LE HAGO ELPEDIDO _ReqCabecera.SECTORDEPOSITODESTINO_ID = Convert.ToInt32(comboBoxSectorDestino.SelectedValue); // A QUE SECTOR DEL DEPPOSITO LE HAGO EL PEDIDO _ReqCabecera.DEPOSITOORIGEN_ID = Convert.ToInt32(comboBoxDepositoOrigen.SelectedValue); // EN QUE DEPOSITO DEBE ENTREGAR EL PEDIDO _ReqCabecera.SECTORDEPOSITOORIGEN_ID = Convert.ToInt32(comboBoxSectorOrigen.SelectedValue); // EN QUE SECTOR DEL DEPOSITO DEBE ENTREGAR LA MERCADERIA for (int i = 0; i < this.dataGridViewReqInerno.Rows.Count; i++) { if (dataGridViewReqInerno.Rows[i].Cells[(int)Col_Detalle.CANTIDAD].Value != string.Empty && dataGridViewReqInerno.Rows[i].Cells[(int)Col_Detalle.CANTIDAD].Value != null) { _ReqItem = new Entities.Tables.COMREQUERIMIENTOINTERNOITEM(); //_ReqItem.COMEMP = Clases.Usuario.EmpresaLogeada.EmpresaIngresada; _ReqItem.ARTICULO_ID = dataGridViewReqInerno.Rows[i].Cells[(int)Col_Detalle.CODIGO].Value.ToString(); _ReqItem.UNIMED = dataGridViewReqInerno.Rows[i].Cells[(int)Col_Detalle.UNIDAD].Value.ToString(); _ReqItem.CANTIDAD = Convert.ToDecimal(dataGridViewReqInerno.Rows[i].Cells[(int)Col_Detalle.CANTIDAD].Value.ToString(), culture); _ReqItem.FECHAENTREGA = Convert.ToDateTime(DateTime.Now.ToShortDateString()); // por defaul... porque lo requiere la table _ReqItem.NIVELAUT_ID = 1; // //SI LA CANTIDAD ES CERO.. NO LO GRABO. if (_ReqItem.CANTIDAD > 0) { _ItemsReq.Add(_ReqItem); //Meto en la coleccion todos los elementos de la grilla } } } //PUEDE SER QUE SOLO SE CARGUE ARTICULOS PROVISORIOS.... SE ENVIA LA CABECERA DEL REQUERIMIENTO Y LOS ITEMS DE PROVISORIOS if (_ItemsReq.Count > 0) { int _nroReqGenerado = 0; //LLAMO A LA FUNCION QUE GUARDA CABECERA E ITEMS if (_ReqCab.AddItem(_ReqCabecera, _ItemsReq, _empresa, ref _nroReqGenerado)) { MessageBox.Show("Se generó el Requerimiento Nro.: " + _nroReqGenerado, "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); NuevoIngreso(); } else { MessageBox.Show("Error al grabar Requerimiento", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Debe ingresar al menos una cantidad", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }