示例#1
0
        private void btnEliminar_ItemClick_1(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (currentRow != null)
            {
                if (MessageBox.Show("Esta seguro que desea eliminar el elemento: " + currentRow["NumSolicitud"].ToString(), _tituloVentana, MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                {
                    string msg           = currentRow["NumSolicitud"] + " eliminado..";
                    string sNumSolicitud = currentRow["NumSolicitud"].ToString();
                    currentRow.Delete();

                    try
                    {
                        ConnectionManager.BeginTran();
                        SolicitudDAC.SetTransactionToAdaptador(true);


                        System.Data.SqlClient.SqlCommand oCmd = new System.Data.SqlClient.SqlCommand("Delete from fnica.solSolicituddetalle where numsolicitud=@Solicitud", ConnectionManager.GetConnection(), ConnectionManager.Tran);
                        oCmd.Parameters.Add("@Solicitud", SqlDbType.NVarChar).Value = sNumSolicitud;
                        int i = oCmd.ExecuteNonQuery();

                        SolicitudDAC.oAdaptador.Update(_dsSolicitud, "Data");
                        _dsSolicitud.AcceptChanges();


                        ConnectionManager.CommitTran();
                        SolicitudDAC.SetTransactionToAdaptador(false);


                        PopulateGrid();
                        //this.lblStatusBar.Caption = msg;
                        Application.DoEvents();
                    }
                    catch (System.Data.SqlClient.SqlException ex)
                    {
                        ConnectionManager.RollBackTran();
                        _dsSolicitud.RejectChanges();
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }
示例#2
0
        private void btnGuardar_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (Accion == "Edit")
            {
                lblStatusBar.Caption = "Actualizando : " + _currentRow["NumSolicitud"].ToString();

                Application.DoEvents();
                _currentRow.BeginEdit();
                _currentRow["NumSolicitud"]     = this.txtNumSolicitud.Text.Trim();
                _currentRow["CodSucursal"]      = this.txtCodSucursal.Text.Trim();
                _currentRow["CodCategoria"]     = this.slkupCategoria.EditValue;
                _currentRow["Descripcion"]      = this.txtDescr.Text.Trim();
                _currentRow["Estado"]           = this.txtEstado.Text.Trim();
                _currentRow["UsuarioSolicitud"] = this.txtUsuario.Text.Trim();
                _currentRow["FechaSolicitud"]   = this.txtFecha.Text.Trim();

                _currentRow.EndEdit();

                DataSet _dsChanged = _dsSolicitud.GetChanges(DataRowState.Modified | DataRowState.Added);

                bool okFlag = true;
                if (_dsChanged != null && _dsChanged.HasErrors)
                {
                    okFlag = false;
                    string msg = "Error en la fila con el tipo Id";

                    foreach (DataTable tb in _dsChanged.Tables)
                    {
                        if (tb.HasErrors)
                        {
                            DataRow[] errosRow = tb.GetErrors();

                            foreach (DataRow dr in errosRow)
                            {
                                msg = msg + dr["NumSolicitud"].ToString();
                            }
                        }
                    }

                    this.lblStatusBar.Caption = msg;
                }



                //Si no hay errores

                if (okFlag)
                {
                    ConnectionManager.BeginTran();
                    SolicitudDAC.SetTransactionToAdaptador(true);
                    SolicitudDetalleDAC.SetTransactionToAdaptador(true);

                    SolicitudDAC.oAdaptador.Update(_dsChanged, "Data");
                    SolicitudDetalleDAC.oAdaptador.Update(_dsDetalle, "Data");

                    this.lblStatusBar.Caption = "Actualizado " + _currentRow["Numsolicitud"].ToString();
                    Application.DoEvents();

                    _dsSolicitud.AcceptChanges();
                    _dsDetalle.AcceptChanges();

                    ConnectionManager.CommitTran();
                    SolicitudDAC.SetTransactionToAdaptador(false);
                    SolicitudDetalleDAC.SetTransactionToAdaptador(false);

                    PopulateGrid();
                    HabilitarControles(false);
                }
                else
                {
                    _dsSolicitud.RejectChanges();
                }
            }
            else
            {
                //nuevo registro

                _currentRow["NumSolicitud"]     = this.txtNumSolicitud.Text.Trim();
                _currentRow["CodSucursal"]      = this.txtCodSucursal.Text.Trim();
                _currentRow["CodCategoria"]     = this.slkupCategoria.EditValue;
                _currentRow["Descripcion"]      = this.txtDescr.Text.Trim();
                _currentRow["Estado"]           = this.txtEstado.Text.Trim();
                _currentRow["UsuarioSolicitud"] = this.txtUsuario.Text.Trim();
                _currentRow["FechaSolicitud"]   = this.txtFecha.Text.Trim();

                _dtSolicitud.Rows.Add(_currentRow);
                try
                {
                    ConnectionManager.BeginTran();
                    SolicitudDAC.SetTransactionToAdaptador(true);
                    SolicitudDetalleDAC.SetTransactionToAdaptador(true);

                    SolicitudDAC.oAdaptador.Update(_dsSolicitud, "Data");
                    _dsSolicitud.AcceptChanges();

                    //Agregar el detalle
                    SolicitudDetalleDAC.oAdaptador.Update(_dsDetalle, "Data");
                    _dsDetalle.AcceptChanges();

                    ConnectionManager.CommitTran();
                    SolicitudDAC.SetTransactionToAdaptador(false);
                    SolicitudDetalleDAC.SetTransactionToAdaptador(false);

                    this.lblStatusBar.Caption = "Se ha ingresado un nuevo registro";
                    Application.DoEvents();
                    PopulateGrid();
                    HabilitarControles(false);
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    _dsSolicitud.RejectChanges();
                    _dsDetalle.RejectChanges();
                    ConnectionManager.RollBackTran();
                    MessageBox.Show(ex.Message);
                }
            }
        }