private void Set_Operation(int index) { try { if (index == 0) { gdvDetail.CloseEditor(); gdvDetail.RefreshData(); var olst = (List<BEPriceListDetail>)gdvDetail.DataSource; var i = 1; olst.ForEach(obej => { var context = new ValidationContext(obej, null, null); var errors = new List<ValidationResult>(); if (!Validator.TryValidateObject(obej, context, errors, true)) { foreach (ValidationResult result in errors) throw new ArgumentException(string.Format("{0}\nFila: {1}", result.ErrorMessage, i)); } i++; }); var obj = new BEPriceListDetail() { COD_USUA_CREA = SESSION_USER, IND_MNTN = 1 }; olst.Add(obj); gdvDetail.RefreshData(); gdvDetail.MoveLast(); gdvDetail.FocusedColumn = gcALF_CODI_ARTI; gdvDetail.ShowEditor(); } else { var row = (BEPriceListDetail)gdvDetail.GetRow(gdvDetail.FocusedRowHandle); if (row.IND_MNTN != 1) row.IND_MNTN = 3; else gdvDetail.DeleteRow(gdvDetail.FocusedRowHandle); gdvDetail.RefreshData(); } } catch (Exception ex) { XtraMessageBox.Show(ex.Message, WhMessage.MsgInsCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void ribALF_ARTI_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { var oxf = new xfSearchArticle(); if (oxf.ShowDialog() == DialogResult.OK) { var olst = (List<BEPriceListDetail>)gdvDetail.DataSource; var exist = olst.Exists(item => item.COD_ARTI == oxf.rowsel.COD_ARTI); if (!exist) { var row = new BEPriceListDetail() { COD_ARTI = oxf.rowsel.COD_ARTI, ALF_CODI_ARTI = oxf.rowsel.ALF_CODI_ARTI, ALF_ARTI = oxf.rowsel.ALF_ARTI, COD_USUA_CREA = SESSION_USER, IND_MNTN = 1 }; gdvDetail.DeleteRow(gdvDetail.FocusedRowHandle); olst.Add(row); gdvDetail.RefreshData(); gdvDetail.MoveLast(); gdvDetail.FocusedColumn = gcNUM_PREC; gdvDetail.ShowEditor(); } else { XtraMessageBox.Show(_Message.MsgExistArticle, _Message.MsgInsCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }