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

📄 freetoolsupdate.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_FreeToolsUpdate : System.Web.UI.Page
{
    private string listUrl = "FreeToolsList.aspx";
    private string categoryModule = "FreeTools";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            string title = Request["Title"];
            if (!string.IsNullOrEmpty(title))
            {
                BindCategory();
                BindData(title.Trim());
                ViewState["Title"] = title.Trim();
            }
        }
    }
    private void BindData(string title)
    {
        IObjectContainer db = DB4OHelper.DB;
        try
        {
            FreeTools item = new FreeTools(db);
            FreeTools target = (FreeTools)item.GetOne(title);
            txtTitle.Text = target.Title;
            txtContent.Text = target.Content;
            ddlCategory.SelectedValue = target.Category;
            Calendar1.Text = target.CreateTime.ToString();
            txtHit.Text = target.Hit.ToString();

            txtUrl.Text = item.URL;
            txtSize.Text = item.Size.ToString();

        }
        catch
        {
        }
        finally
        {
            db.Close();
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Valid())
        {
            IObjectContainer db = DB4OHelper.DB;

            //string picture = "";
            try
            {


                FreeTools item = new FreeTools();
                item.Db = db;

                item = (FreeTools)item.GetOne(ViewState["Title"].ToString());
                item.Db = db;
                this.GetFromControls(item);
                item.Update();
                Message.Show("Update Success!");
            }
            catch (Exception e1)
            {
                Response.Write(e1.ToString());
                Message.Show("Update Fail!");
            }
            finally
            {
                db.Close();
            }
        }
    }
    private FreeTools GetFromControls(FreeTools item)
    {

        string title = txtTitle.Text.Trim();
        string content = txtContent.Text.Trim();
        string cateogry = ddlCategory.SelectedValue.Trim();

        item.Title = title;
        item.Content = content;
        item.CreateTime = DateTime.Parse(Calendar1.Text);
        item.Hit = int.Parse(txtHit.Text);
        item.Category = cateogry;

        item.Size = int.Parse(txtSize.Text);
        item.URL = txtUrl.Text;


        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 + -