Exemplo n.º 1
0
        public void Set_Save()
        {
            MessageBoxIcon msgIcon = MessageBoxIcon.Warning;
            try
            {
                var obpc = new BEPriceList()
                {
                    COD_LIST_PREC = (string.IsNullOrWhiteSpace(txtCOD_LIST_PREC.Text)) ? 0 : Convert.ToInt32(txtCOD_LIST_PREC.Text),
                    ALF_LIST_PREC = txtALF_LIST_PREC.Text.Trim(),
                    IND_TIPO_LIST = (int?)rdgIND_TIPO_LIST.EditValue,
                    COD_COMP = SESSION_COMP,
                    COD_USUA_CREA = SESSION_USER,
                    COD_USUA_MODI = SESSION_USER,
                    IND_MNTN = (string.IsNullOrWhiteSpace(txtCOD_LIST_PREC.Text)) ? 1 : 2
                };

                var context = new ValidationContext(obpc, null, null);
                var errors = new List<ValidationResult>();
                if (!Validator.TryValidateObject(obpc, context, errors, true))
                {
                    foreach (ValidationResult result in errors)
                    {
                        msgIcon = MessageBoxIcon.Warning;
                        throw new ArgumentException(result.ErrorMessage);
                    }
                }

                gdvDetail.CloseEditor();
                gdvDetail.RefreshData();
                var olst = (List<BEPriceListDetail>)gdvDetail.DataSource;
                if (olst.Count == 0)
                {
                    msgIcon = MessageBoxIcon.Warning;
                    throw new ArgumentException(WhMessage.MsgManyRows);
                }

                var i = 1;
                olst.ForEach(item =>
                {
                    context = new ValidationContext(item, null, null);
                    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 BRArticle();
                obr.Set_PSCP_SPMT_SVMC_LIST_PREC(obpc, olst);
                if (!string.IsNullOrWhiteSpace(obpc.MSG_MNTN))
                {
                    msgIcon = MessageBoxIcon.Error;
                    throw new ArgumentException(obpc.MSG_MNTN);
                }
                txtCOD_LIST_PREC.Text = obpc.COD_LIST_PREC.ToString();
                olst.RemoveAll(item => item.IND_MNTN == 3);
                olst.ForEach(item => { item.IND_MNTN = 0; });
                gdvDetail.RefreshData();
                StateControls(true);
                XtraMessageBox.Show(WhMessage.MsgSuccessfully, WhMessage.MsgInsCaption,
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message,
                                    WhMessage.MsgInsCaption,
                                    MessageBoxButtons.OK,
                                    msgIcon);
            }
        }