Ejemplo n.º 1
0
        // ReSharper disable once UnusedParameter.Local
        private void Save(bool closeForm)
        {
            var userIdSessionKey = ConfigurationHelper.GetScrudParameter("UserIdSessionKey");

            if (!(Conversion.TryCastInteger(SessionHelper.GetSessionValueByKey(userIdSessionKey)) > 0))
            {
                throw new InvalidOperationException("The user id session key is invalid or incorrectly configured.");
            }

            var list = this.GetFormCollection(true);
            var id   = this.GetSelectedValue();

            lastValueHiddenTextBox.Text = id;

            var userId = Conversion.TryCastInteger(this.Page.Session[userIdSessionKey]);

            if (string.IsNullOrWhiteSpace(id))
            {
                if (this.DenyAdd)
                {
                    this.messageLabel.CssClass = "failure";
                    this.messageLabel.Text     = ScrudResource.AccessDenied;
                }
                else
                {
                    var lastValue = FormHelper.InsertRecord(userId, this.TableSchema, this.Table, list, this.imageColumn);

                    if (lastValue > 0)
                    {
                        lastValueHiddenTextBox.Text = lastValue.ToString(CultureInfo.InvariantCulture);
                        //Clear the form container.
                        this.formContainer.Controls.Clear();

                        using (var table = new DataTable())
                        {
                            //Load the form again.
                            this.LoadForm(this.formContainer, table);
                        }

                        //Refresh the grid.
                        this.BindGridView();
                        this.DisplaySuccess();
                    }
                }
            }
            else
            {
                if (this.DenyEdit)
                {
                    this.messageLabel.CssClass = "failure";
                    this.messageLabel.Text     = ScrudResource.AccessDenied;
                }
                else
                {
                    if (FormHelper.UpdateRecord(userId, this.TableSchema, this.Table, list, this.KeyColumn, id, this.imageColumn))
                    {
                        //Clear the form container.
                        this.formContainer.Controls.Clear();

                        //Load the form again.
                        using (var table = new DataTable())
                        {
                            table.Locale = Thread.CurrentThread.CurrentCulture;

                            this.LoadForm(this.formContainer, table);
                        }

                        //Refresh the grid.
                        this.BindGridView();

                        this.DisplaySuccess();
                    }
                    else
                    {
                        this.messageLabel.CssClass = "failure";
                        this.messageLabel.Text     = ScrudResource.UnknownError;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            this.Page.Validate();
            if (!this.Page.IsValid)
            {
                return;
            }

            if (this.SaveButtonClick != null)
            {
                this.SaveButtonClick(sender, e);
                return;
            }

            var userIdSessionKey = ConfigurationHelper.GetScrudParameter("UserIdSessionKey");

            if (!(Conversion.TryCastInteger(SessionHelper.GetSessionValueByKey(userIdSessionKey)) > 0))
            {
                throw new InvalidOperationException("The user id session key is invalid or incorrectly configured.");
            }

            var list = this.GetFormCollection(true);
            var id   = this.GetSelectedValue();

            var userId = Conversion.TryCastInteger(this.Page.Session[userIdSessionKey]);

            if (string.IsNullOrWhiteSpace(id))
            {
                if (this.DenyAdd)
                {
                    this.messageLabel.CssClass = "failure";
                    this.messageLabel.Text     = ScrudResource.AccessDenied;
                }
                else
                {
                    if (FormHelper.InsertRecord(userId, this.TableSchema, this.Table, list, this.imageColumn))
                    {
                        //Clear the form container.
                        this.formContainer.Controls.Clear();

                        using (var table = new DataTable())
                        {
                            //Load the form again.
                            this.LoadForm(this.formContainer, table);
                        }

                        //Refresh the grid.
                        this.BindGridView();
                        this.DisplaySuccess();
                    }
                }
            }
            else
            {
                if (this.DenyEdit)
                {
                    this.messageLabel.CssClass = "failure";
                    this.messageLabel.Text     = ScrudResource.AccessDenied;
                }
                else
                {
                    if (FormHelper.UpdateRecord(userId, this.TableSchema, this.Table, list, this.KeyColumn, id, this.imageColumn))
                    {
                        //Clear the form container.
                        this.formContainer.Controls.Clear();

                        //Load the form again.
                        using (var table = new DataTable())
                        {
                            table.Locale = Thread.CurrentThread.CurrentCulture;

                            this.LoadForm(this.formContainer, table);
                        }

                        //Refresh the grid.
                        this.BindGridView();

                        this.DisplaySuccess();
                    }
                    else
                    {
                        this.messageLabel.CssClass = "failure";
                        this.messageLabel.Text     = ScrudResource.UnknownError;
                    }
                }
            }
        }