📄 liveexperiencenew.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;
using System.IO;
public partial class Back_LiveExperienceNew : System.Web.UI.Page
{
private string listUrl = "LiveExperienceList.aspx";
private string categoryModule = "LiveExperience";
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;
LiveExperience2 item = new LiveExperience2(db);
string title = txtTitle.Text.Trim();
string content = txtContent.Text.Trim();
string cateogry = ddlCategory.SelectedValue.Trim();
string url = txtUrl.Text.Trim();
//string picture = "";
try
{
item.Title = title;
item.Content = content;
item.CreateTime = DateTime.Now;
item.Hit = 0;
item.Category = cateogry;
item.Url = url;
if (FileUpload1.HasFile)
{
//item.Picture = FileUpload1.FileName;
//string path = Tools.GetPictureSavePath() + FileUpload1.FileName;
string picture = Tools.GetPictureName() + Path.GetExtension(FileUpload1.PostedFile.FileName);
item.Picture = picture;
string path = Tools.GetPictureSavePath() + picture;
FileUpload1.SaveAs(path);
}
else
{
item.Picture = Tools.GetDefaultPicture();
}
//item.Add(item);
item.Add();
Message.Show("Add Success!");
}
catch(Exception e1)
{
Response.Write(e1.ToString());
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 + -