예제 #1
0
파일: GridView.cs 프로젝트: magogoba/mixerp
        private void LoadGrid()
        {
            var showAll = (Conversion.TryCastString(this.Page.Request.QueryString["show"]).Equals("all"));

            this.BindGridView();
            this.formGridView.Width = this.GetWidth();
            this.pager.RecordCount  = FormHelper.GetTotalRecords(this.ViewSchema, this.View);
            this.pager.PageSize     = 10;

            if (this.PageSize != 0)
            {
                this.pager.PageSize = this.PageSize;
            }

            if (showAll)
            {
                this.pager.PageSize = 1000;
            }

            var userNameSessionKey   = ConfigurationHelper.GetScrudParameter("UserNameSessionKey");
            var officeCodeSessionKey = ConfigurationHelper.GetScrudParameter("OfficeCodeSessionKey");

            this.userIdHidden.Value     = SessionHelper.GetSessionValueByKey(userNameSessionKey);
            this.officeCodeHidden.Value = SessionHelper.GetSessionValueByKey(officeCodeSessionKey);
        }
예제 #2
0
파일: GridView.cs 프로젝트: magogoba/mixerp
        private void BindGridView()
        {
            var showAll = (Conversion.TryCastString(this.Page.Request.QueryString["show"]).Equals("all"));

            var limit  = 10;
            var offset = 0;

            if (this.PageSize != 0)
            {
                limit = this.PageSize;
            }

            if (showAll)
            {
                limit = 1000;
            }

            if (this.Page.Request["page"] != null)
            {
                offset = (Conversion.TryCastInteger(this.Page.Request["page"]) - 1) * limit;
            }

            using (var table = FormHelper.GetView(this.ViewSchema, this.View, this.KeyColumn, limit, offset))
            {
                this.formGridView.DataSource = table;
                this.formGridView.DataBind();
            }
        }
예제 #3
0
        protected void DeleteButton_Click(object sender, EventArgs e)
        {
            var id = this.GetSelectedValue();

            if (string.IsNullOrWhiteSpace(id))
            {
                return;
            }

            if (this.DenyDelete)
            {
                this.messageLabel.CssClass = this.GetFailureCssClass();
                this.messageLabel.Text     = Titles.AccessDenied;
                return;
            }

            try
            {
                if (FormHelper.DeleteRecord(this.TableSchema, this.Table, this.KeyColumn, id))
                {
                    //Refresh the grid.
                    this.BindGridView();

                    this.DisplaySuccess();
                }
            }
            catch (MixERPException ex)
            {
                this.DisplayError(ex);
                //Swallow
            }
        }
예제 #4
0
        protected void GoButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(this.GetSchema()))
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(this.GetView()))
            {
                return;
            }

            using (var table = FormHelper.GetTable(this.GetSchema(), this.GetView(), this.filterDropDownList.SelectedItem.Value, this.filterTextBox.Text, 10))
            {
                this.searchGridView.DataSource = table;
                this.searchGridView.DataBind();
            }
        }
예제 #5
0
        protected void DeleteButton_Click(object sender, EventArgs e)
        {
            var id = this.GetSelectedValue();

            if (string.IsNullOrWhiteSpace(id))
            {
                return;
            }

            if (this.DenyDelete)
            {
                this.messageLabel.CssClass = "failure";
                this.messageLabel.Text     = ScrudResource.AccessDenied;
                return;
            }

            if (FormHelper.DeleteRecord(this.TableSchema, this.Table, this.KeyColumn, id))
            {
                //Refresh the grid.
                this.BindGridView();

                this.DisplaySuccess();
            }
        }
예제 #6
0
        protected void EditButton_Click(object sender, EventArgs e)
        {
            var id = this.GetSelectedValue();

            if (string.IsNullOrWhiteSpace(id))
            {
                return;
            }

            using (var table = FormHelper.GetTable(this.TableSchema, this.Table, this.KeyColumn, id))
            {
                if (table.Rows.Count.Equals(1))
                {
                    //Clear the form container.
                    this.formContainer.Controls.Clear();

                    //Load the form again in the container with values
                    //retrieved from database.
                    this.LoadForm(this.formContainer, table);
                    this.gridPanel.Attributes["style"] = "display:none;";
                    this.formPanel.Attributes["style"] = "display:block;";
                }
            }
        }
예제 #7
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;
                    }
                }
            }
        }
예제 #8
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;
                    }
                }
            }
        }