コード例 #1
0
    protected void btnAdd_Click(object sender, System.EventArgs e)
    {
        string Title = tbTitle.Text.Trim();

        if (Title == "")
        {
            Shove._Web.JavaScript.Alert(this.Page, "请输入标题。");

            return;
        }

        string UC = tbContent.Text.Trim();

        Regex regex = new Regex(@"([\w-]+\.)+[\w-]+.([^a-z])(/[\w- ./?%&=]*)?|[a-zA-Z0-9\-\.][\w-]+.([^a-z])(/[\w- ./?%&=]*)?", RegexOptions.IgnoreCase | RegexOptions.Compiled);
        Match m     = regex.Match(UC);

        if (!m.Success)
        {
            Shove._Web.JavaScript.Alert(this, "地址格式错误,请仔细检查。");

            return;
        }

        short order = Shove._Convert.StrToShort(tbOrder.Text.Trim(), 0);

        if (order < 1)
        {
            Shove._Web.JavaScript.Alert(this.Page, "排序只能是整数!");

            return;
        }

        DAL.Tables.T_FocusNews f = new DAL.Tables.T_FocusNews();

        f.Title.Value    = Title;
        f.Url.Value      = UC;
        f.Order.Value    = tbOrder.Text;
        f.IsMaster.Value = cbIsMaster.Checked;
        long count = 0;

        if (hID.Value == "")
        {
            count = f.GetCount("IsMaster=1");

            if ((!cbIsMaster.Checked && count < 1) || (cbIsMaster.Checked && count > 0))
            {
                Shove._Web.JavaScript.Alert(this.Page, "有且只能有一个主标题!");

                return;
            }

            f.Insert();
        }
        else
        {
            count = f.GetCount("IsMaster=1 and ID<>" + hID.Value + "");

            if ((!cbIsMaster.Checked && count < 1) || (cbIsMaster.Checked && count > 0))
            {
                Shove._Web.JavaScript.Alert(this.Page, "有且只能有一个主标题!");

                return;
            }

            f.Update("ID=" + hID.Value);
        }

        Shove._Web.Cache.ClearCache("Default_GetFocusNews");

        this.Response.Redirect("FocusNews.aspx", true);
    }