Пример #1
0
        public void Set_Save()
        {
            MessageBoxIcon msgIcon = MessageBoxIcon.Warning;
            try
            {
                var obar = new BEArticle();
                if (!string.IsNullOrWhiteSpace(txtCOD_ARTI.Text))
                    obar.COD_ARTI = Convert.ToInt32(txtCOD_ARTI.Text);
                obar.ALF_CODI_ARTI = txtALF_CODI_ARTI.Text.Trim();
                obar.ALF_ARTI = txtALF_ARTI.Text.Trim();
                obar.ALF_DESC = mmeALF_DESC.Text.Trim();
                obar.COD_TIPO_ARTI = Convert.ToInt32(lkeCOD_TIPO_ARTI.EditValue);
                obar.COD_MODE_ARTI = Convert.ToInt32(lkeCOD_MODE_ARTI.EditValue);
                obar.NUM_STOC_MINI = Convert.ToInt32(txtNUM_STOC_MINI.Text);
                if (pteIMG_FOTO.Image != null)
                    obar.IMG_FOTO = ImageToByteArray(pteIMG_FOTO.Image);
                obar.IND_MNTN = 1;
                if (!string.IsNullOrWhiteSpace(txtCOD_ARTI.Text))
                    obar.IND_MNTN = 2;
                obar.COD_USUA_CREA = SESSION_USER;
                obar.COD_USUA_MODI = SESSION_USER;
                obar.COD_COMP = SESSION_COMP;

                var context = new ValidationContext(obar, null, null);
                var errors = new List<ValidationResult>();
                if (!Validator.TryValidateObject(obar, context, errors, true))
                {
                    foreach (ValidationResult result in errors)
                    {
                        msgIcon = MessageBoxIcon.Warning;
                        throw new ArgumentException(result.ErrorMessage);
                    }
                }
                else
                {
                    var obr = new BRArticle();
                    obr.Set_PSWH_SPMT_SVMC_ARTI(obar);
                    if (!string.IsNullOrWhiteSpace(obar.MSG_MNTN))
                    {
                        msgIcon = MessageBoxIcon.Error;
                        throw new ArgumentException(obar.MSG_MNTN);
                    }
                    StateControls(true);
                    txtCOD_ARTI.Text = obar.COD_ARTI.ToString();
                    XtraMessageBox.Show(WhMessage.MsgSuccessfully,
                                        WhMessage.MsgInsCaption,
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                }

            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message,
                                    WhMessage.MsgInsCaption,
                                    MessageBoxButtons.OK,
                                    msgIcon);
            }
        }