📄 introductionupdate.aspx.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 IntroductionList : System.Web.UI.Page
{
private string listUrl = "IntroductionList.aspx";
private string categoryModule = "Introduction";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string title = Request["Title"];
if (!string.IsNullOrEmpty(title))
{
BindCategory();
BindDate(title.Trim());
ViewState["Title"] = title.Trim();
}
}
}
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();
}
}
private void BindDate(string title)
{
IObjectContainer db = DB4OHelper.DB;
try
{
Introduction intro = new Introduction(db);
Introduction target = intro.GetOne(title);
txtTitle.Text = target.Title;
txtContent.Text = target.Content;
ddlCategory.SelectedValue = target.Category;
Calendar1.Text = target.CreateTime.ToString();
txtHit.Text = target.Hit.ToString();
}
catch
{
}
finally
{
db.Close();
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
if (Valid())
{
IObjectContainer db = DB4OHelper.DB;
try
{
Introduction intro = new Introduction(db);
Introduction target = intro.GetOne(ViewState["Title"].ToString());
target.Title = txtTitle.Text.Trim();
target.Category = ddlCategory.SelectedValue.Trim();
target.Content = txtContent.Text.Trim();
target.Hit = Convert.ToInt32(txtHit.Text.Trim());
target.CreateTime = Convert.ToDateTime(Calendar1.Text.Trim());
//target.
intro.Update(target);
Message.Show("Update Success!");
}
catch
{
Message.Show("Update 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(txtHit.Text.Trim()))
{
result = false;
Message.Show("Hit is not empty!");
}
else
{
result = true;
}
}
if (result)
{
try
{
Convert.ToInt32(txtHit.Text.Trim());
result = true;
}
catch
{
Message.Show("Hit format not right!");
result = false;
}
}
if (result)
{
if (string.IsNullOrEmpty(Calendar1.Text.Trim()))
{
result = false;
Message.Show("CreateTime is not empty!");
}
else
{
result = true;
}
}
if (result)
{
try
{
Convert.ToDateTime(Calendar1.Text.Trim());
result = true;
}
catch
{
Message.Show("CreateTime format not right!");
result = false;
}
}
if (result)
{
if (string.IsNullOrEmpty(txtContent.Text.Trim()))
{
result = false;
Message.Show("Content is not empty!");
}
else
{
result = true;
}
}
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -