Пример #1
0
        private void Set_Save()
        {
            MessageBoxIcon msgIcon = MessageBoxIcon.Warning;
            try
            {
                gdvGeneric.CloseEditor();
                gdvGeneric.RefreshData();
                var olst = (List<BETypeReason>)gdvGeneric.DataSource;
                var i = 1;
                olst.ForEach(item =>
                {
                    var context = new ValidationContext(item, null, null);
                    var errors = new List<ValidationResult>();
                    if (!Validator.TryValidateObject(item, context, errors, true))
                    {
                        foreach (ValidationResult result in errors)
                        {
                            msgIcon = MessageBoxIcon.Warning;
                            throw new ArgumentException(string.Format("{0}\nFila: {1}", result.ErrorMessage, i));
                        }
                    }
                    i++;
                });

                var obr = new BRTypeReason();
                var obej = new BETypeReason();
                obr.Set_PSGN_SPMT_SVMC_TIPO_MOTI(obej, olst);
                if (!string.IsNullOrWhiteSpace(obej.MSG_MNTN))
                {
                    msgIcon = MessageBoxIcon.Error;
                    throw new ArgumentException(obej.MSG_MNTN);
                }

                olst.RemoveAll(item => item.IND_MNTN == 3);
                olst.ForEach(item => item.IND_MNTN = 0);
                gdvGeneric.RefreshData();
                XtraMessageBox.Show(WhMessage.MsgSuccessfully,
                                    WhMessage.MsgInsCaption,
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message,
                                    WhMessage.MsgInsCaption,
                                    MessageBoxButtons.OK,
                                    msgIcon);
            }
        }