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

📄 introductionnew.aspx.cs

📁 一个简单的Demo
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Surance.DB4ODAL;
using Surance.DBUtility;
using Db4objects.Db4o;
using Surance.Utility;

public partial class IntroductionNew : System.Web.UI.Page
{
    private string listUrl = "IntroductionList.aspx";
    private string categoryModule = "Introduction";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindCategory();
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Valid())
        {
            IObjectContainer db = DB4OHelper.DB;
            Introduction intro = new Introduction(db);
            string title = txtTitle.Text.Trim();
            string content = txtContent.Text.Trim();
            string cateogry = ddlCategory.SelectedValue.Trim();
            try
            {
                intro.Title = title;
                intro.Content = content;
                intro.CreateTime = DateTime.Now;
                intro.Hit = 0;
                intro.Category = cateogry;
                intro.Add(intro);
                Message.Show("Add Success!");
            }
            catch
            {
                Message.Show("Add Fail!");
            }
            finally
            {
                db.Close();
            }
        }
    }
    private bool Valid()
    {
        bool result = true;
        if (result)
        {
            if (string.IsNullOrEmpty(txtTitle.Text.Trim()))
            {
                result = false;
                Message.Show("Title is not empty!");
            }
            else
            {
                result = true;
            }
        }

        if (result)
        {
            if (string.IsNullOrEmpty(txtContent.Text.Trim()))
            {
                result = false;
                Message.Show("Content is not empty!");
            }
            else
            {
                result = true;
            }
        }
        return result;
    }
    

    protected void btnList_Click(object sender, EventArgs e)
    {
        Response.Redirect(listUrl);
    }

    private void BindCategory()
    {
        IObjectContainer db = DB4OHelper.DB;
        try
        {
            Category c = new Category(db);
            ddlCategory.DataSource = c.GetByModule(categoryModule);
            ddlCategory.DataBind();
        }
        catch
        {

        }
        finally
        {
            db.Close();
        }
    }
}

⌨️ 快捷键说明

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