⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iplock1.cs

📁 动易SiteFactory&#8482 网上商店系统1.0源代码
💻 CS
字号:
namespace PowerEasy.WebSite.Controls
{
    using PowerEasy.Common;
    using PowerEasy.Controls;
    using PowerEasy.Web.UI;
    using System;
    using System.Data;
    using System.Text;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class IPLock1 : BaseUserControl
    {
        protected Button BtnSave;
        protected ExtendedGridView EgvIPLock;
        private static int m_Index;
        private static bool m_IsEdit;
        protected TextBox TxtFrom;
        protected TextBox TxtTo;
        protected System.Web.UI.UpdatePanel UpdatePanel1;
        protected RegularExpressionValidator ValeIPFrom;
        protected RegularExpressionValidator ValeIPTo;
        protected PowerEasy.Controls.RequiredFieldValidator ValrIPFrom;
        protected PowerEasy.Controls.RequiredFieldValidator ValrIPTo;

        protected void BtnSave_Click(object sender, EventArgs e)
        {
            DataTable iPTable = this.IPTable;
            if (m_IsEdit)
            {
                if (StringHelper.EncodeIP(this.TxtTo.Text) < StringHelper.EncodeIP(this.TxtFrom.Text))
                {
                    iPTable.Rows[m_Index]["IPFrom"] = this.TxtTo.Text;
                    iPTable.Rows[m_Index]["IPTo"] = this.TxtFrom.Text;
                }
                else
                {
                    iPTable.Rows[m_Index]["IPFrom"] = this.TxtFrom.Text;
                    iPTable.Rows[m_Index]["IPTo"] = this.TxtTo.Text;
                }
                m_IsEdit = false;
                this.BtnSave.Text = "添加";
            }
            else
            {
                DataRow row = iPTable.NewRow();
                if (StringHelper.EncodeIP(this.TxtTo.Text) < StringHelper.EncodeIP(this.TxtFrom.Text))
                {
                    row["IPFrom"] = this.TxtTo.Text;
                    row["IPTo"] = this.TxtFrom.Text;
                }
                else
                {
                    row["IPFrom"] = this.TxtFrom.Text;
                    row["IPTo"] = this.TxtTo.Text;
                }
                iPTable.Rows.Add(row);
            }
            this.IPTable = iPTable;
            this.TxtFrom.Text = this.TxtTo.Text = string.Empty;
            this.EgvIPLock.DataSource = iPTable;
            this.EgvIPLock.DataBind();
        }

        protected void EgvIPLock_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            DataTable iPTable = this.IPTable;
            iPTable.Rows.RemoveAt(e.RowIndex);
            this.IPTable = iPTable;
            this.TxtFrom.Text = this.TxtTo.Text = string.Empty;
            m_IsEdit = false;
            this.EgvIPLock.DataSource = iPTable;
            this.EgvIPLock.DataBind();
            this.BtnSave.Text = "添加";
        }

        protected void EgvIPLock_RowEditing(object sender, GridViewEditEventArgs e)
        {
            m_IsEdit = true;
            this.BtnSave.Text = "保存";
            m_Index = e.NewEditIndex;
            this.TxtFrom.Text = this.EgvIPLock.Rows[m_Index].Cells[0].Text;
            this.TxtTo.Text = this.EgvIPLock.Rows[m_Index].Cells[1].Text;
            this.TxtFrom.Focus();
        }

        protected override void OnInit(EventArgs e)
        {
            this.BtnSave.ValidationGroup = this.ID;
            this.TxtFrom.ValidationGroup = this.ID;
            this.TxtTo.ValidationGroup = this.ID;
            this.ValeIPFrom.ValidationGroup = this.ID;
            this.ValeIPTo.ValidationGroup = this.ID;
            this.ValrIPFrom.ValidationGroup = this.ID;
            this.ValrIPTo.ValidationGroup = this.ID;
            this.EgvIPLock.EmptyDataText = string.Empty;
            base.OnInit(e);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        private DataTable IPTable
        {
            get
            {
                if (this.ViewState["IPTable"] == null)
                {
                    DataTable table = new DataTable();
                    table.Columns.Add("IPTo", typeof(string));
                    table.Columns.Add("IPFrom", typeof(string));
                    this.ViewState["IPTable"] = table;
                }
                return (this.ViewState["IPTable"] as DataTable);
            }
            set
            {
                this.ViewState["IPTable"] = value;
            }
        }

        public string Value
        {
            get
            {
                StringBuilder builder = new StringBuilder();
                foreach (GridViewRow row in this.EgvIPLock.Rows)
                {
                    if (row.RowType == DataControlRowType.DataRow)
                    {
                        builder.Append(StringHelper.EncodeIP(row.Cells[0].Text).ToString() + "----" + StringHelper.EncodeIP(row.Cells[1].Text).ToString());
                        builder.Append("$$$");
                    }
                }
                return builder.ToString().TrimEnd(new char[] { '$' });
            }
            set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    DataTable table = new DataTable();
                    table.Columns.Add("IPTo", typeof(string));
                    table.Columns.Add("IPFrom", typeof(string));
                    foreach (string str in value.Split(new string[] { "$$$" }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        string[] field = str.Split(new string[] { "----" }, StringSplitOptions.None);
                        DataRow row = table.NewRow();
                        row["IPFrom"] = StringHelper.DecodeIP(Convert.ToInt64(DataSecurity.GetArrayValue(0, field)));
                        row["IPTo"] = StringHelper.DecodeIP(Convert.ToInt64(DataSecurity.GetArrayValue(1, field)));
                        table.Rows.Add(row);
                    }
                    this.IPTable = table;
                    this.EgvIPLock.DataSource = table;
                    this.EgvIPLock.DataBind();
                }
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -