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

📄 recommendnew.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;
using System.IO;

public partial class Back_RecommendNew : System.Web.UI.Page
{
    private string listUrl = "RecommendList.aspx";
    private string categoryModule = "Recommend";
    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;

            //string picture = "";
            try
            {

                Recommend item = this.GetFromControls();
                item.Db = db;


                item.Add();
                Message.Show("Add Success!");
            }
            catch (Exception e1)
            {
                Response.Write(e1.ToString());
                Message.Show("Add Fail!");
            }
            finally
            {
                db.Close();
            }
        }
    }
    private Recommend GetFromControls()
    {
        Recommend item = new Recommend();
        string title = txtTitle.Text.Trim();
        string content = txtContent.Text.Trim();
        string cateogry = ddlCategory.SelectedValue.Trim();
        
        item.Title = title;
        item.Content = content;
        item.CreateTime = DateTime.Now;
        item.Hit = int.Parse(txtHit.Text);
        item.Category = cateogry;
       
        return item;
    }
    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 + -