コード例 #1
0
ファイル: frmPlanilla.cs プロジェクト: yovannyZ/Prueba-HH
 private void FinalizarEdicionCeldaEnGrid(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         int    columna = e.ColumnIndex;
         object dato    = this.dgvAsignacion.Rows[e.RowIndex].Cells[columna].Value;
         if (dato != null)
         {
             if (columna == 2)
             {
                 int posGuion = dato.ToString().IndexOf("-");
                 if (posGuion != -1 && posGuion == 6)
                 {
                     dato = dato.ToString().Substring(8);
                 }
                 Persona p = this.BuscarPersona(dato.ToString());
                 if (p != null)
                 {
                     this.dgvAsignacion.Rows[e.RowIndex].Cells[columna].Value = p;
                 }
                 else
                 {
                     this.dgvAsignacion.Rows[e.RowIndex].Cells[columna].Value = "";
                 }
             }
             else if (columna == 3)
             {
                 int posGuion = dato.ToString().IndexOf("-");
                 if (posGuion != -1 && posGuion == 3)
                 {
                     dato = dato.ToString().Substring(5);
                 }
                 Novedad n = this.BuscarNovedad(dato.ToString());
                 if (n != null)
                 {
                     this.dgvAsignacion.Rows[e.RowIndex].Cells[columna].Value = n;
                     if (novedadAnterior != n.ToString())
                     {
                         this.dgvAsignacion.Rows[e.RowIndex].Cells[6].Value = "";
                         this.dgvAsignacion.Rows[e.RowIndex].Cells[7].Value = "";
                         this.dgvAsignacion.Rows[e.RowIndex].Cells[8].Value = "";
                     }
                     if (n.TipoDistribucion == TipoDistribucion.Directa)
                     {
                         this.dgvAsignacion.Rows[e.RowIndex].Cells[6].ReadOnly = false;
                         this.dgvAsignacion.Rows[e.RowIndex].Cells[7].ReadOnly = false;
                         this.dgvAsignacion.Rows[e.RowIndex].Cells[8].ReadOnly = true;
                     }
                     else if (n.TipoDistribucion == TipoDistribucion.Indirecta)
                     {
                         this.dgvAsignacion.Rows[e.RowIndex].Cells[6].ReadOnly = true;
                         this.dgvAsignacion.Rows[e.RowIndex].Cells[7].ReadOnly = true;
                         this.dgvAsignacion.Rows[e.RowIndex].Cells[8].ReadOnly = false;
                     }
                     else if (n.TipoDistribucion == TipoDistribucion.IndirectaSinCentroCosto)
                     {
                         this.dgvAsignacion.Rows[e.RowIndex].Cells[6].ReadOnly = true;
                         this.dgvAsignacion.Rows[e.RowIndex].Cells[7].ReadOnly = true;
                         this.dgvAsignacion.Rows[e.RowIndex].Cells[8].ReadOnly = true;
                     }
                 }
                 else
                 {
                     this.dgvAsignacion.Rows[e.RowIndex].Cells[columna].Value = "";
                 }
             }
             else if (columna == 6)
             {
                 if (string.IsNullOrEmpty(dato.ToString()))
                 {
                     return;
                 }
                 OrdenProduccion o = this.BuscarOrden(dato.ToString());
                 if (o != null)
                 {
                     this.dgvAsignacion.Rows[e.RowIndex].Cells[columna].Value = o;
                     if (ordenAnterior != o.NumeroOrden)
                     {
                         this.dgvAsignacion.Rows[e.RowIndex].Cells[7].Value = "";
                     }
                     this.dgvAsignacion.Rows[e.RowIndex].Cells[8].Value = "";
                 }
                 else
                 {
                     this.dgvAsignacion.Rows[e.RowIndex].Cells[columna].Value = "";
                     this.dgvAsignacion.Rows[e.RowIndex].Cells[7].Value       = "";
                     this.dgvAsignacion.Rows[e.RowIndex].Cells[8].Value       = "";
                 }
                 if (this.SelectOrden != null)
                 {
                     SelectOrden(sender, EventArgs.Empty);
                 }
             }
             else if (columna == 7)
             {
                 if (string.IsNullOrEmpty(dato.ToString()))
                 {
                     return;
                 }
                 int posGuion = dato.ToString().IndexOf("-");
                 if (posGuion != -1 && posGuion == 6)
                 {
                     dato = dato.ToString().Substring(8);
                 }
                 Actividad a = this.BuscarActividad(dato.ToString());
                 if (a != null)
                 {
                     this.dgvAsignacion.Rows[e.RowIndex].Cells[columna].Value = a;
                 }
                 else
                 {
                     this.dgvAsignacion.Rows[e.RowIndex].Cells[columna].Value = "";
                 }
             }
             else if (columna == 8)
             {
                 if (string.IsNullOrEmpty(dato.ToString()))
                 {
                     return;
                 }
                 int posGuion = dato.ToString().IndexOf("-");
                 if (posGuion != -1 && posGuion == 6)
                 {
                     dato = dato.ToString().Substring(0, posGuion - 1);
                 }
                 CentroCosto c = this.BuscarCentroCosto(dato.ToString());
                 if (c != null)
                 {
                     this.dgvAsignacion.Rows[e.RowIndex].Cells[columna].Value = c;
                     this.dgvAsignacion.Rows[e.RowIndex].Cells[6].Value       = "";
                     this.dgvAsignacion.Rows[e.RowIndex].Cells[7].Value       = "";
                 }
                 else
                 {
                     this.dgvAsignacion.Rows[e.RowIndex].Cells[columna].Value = "";
                     this.dgvAsignacion.Rows[e.RowIndex].Cells[6].Value       = "";
                     this.dgvAsignacion.Rows[e.RowIndex].Cells[7].Value       = "";
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ErrorHandler.ObtenerMensajeError(ex, ModuloLog.HorasHombre, TipoObjeto.Planilla),
                         AppInfo.Tittle, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }