📄 productmodel.aspx.cs
字号:
namespace PowerEasy.WebSite.Admin.Shop
{
using PowerEasy.Common;
using PowerEasy.CommonModel;
using PowerEasy.Controls;
using PowerEasy.Enumerations;
using PowerEasy.ExtendedControls;
using PowerEasy.Model.CommonModel;
using PowerEasy.ModelControls;
using PowerEasy.Shop;
using PowerEasy.Web.UI;
using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class ProductModel : AdminPage
{
protected AlternateLiteral AltrTitle;
protected CheckBoxList ChklCharacter;
protected DropDownList DropModelTemplate;
protected DropDownList DrpItemIcon;
protected ExtendedButton EBtnSubmit;
protected TemplateSelectControl FileCTemplate;
protected HiddenField HdnModelId;
protected HiddenField HdnModelName;
protected HiddenField HdnTableName;
protected Image ImgItemIcon;
protected Label LblTablePrefix;
protected RadioButtonList RadioDisabled;
protected RadioButtonList RadioIsCountHits;
protected ExtendedSiteMapPath SmpNavigator;
protected AlternateLiteral TableNameText;
protected HtmlTableRow trModelTemmpalteId;
protected TemplateSelectControl TscAdvanceSearchFormTemplate;
protected TemplateSelectControl TscAdvanceSearchTemplate;
protected TemplateSelectControl TscPrintTemplate;
protected TemplateSelectControl TscSearchTemplate;
protected TextBox TxtAddInfoFilePath;
protected TextBox TxtBatchInfoFilePath;
protected TextBox TxtDescription;
protected TextBox TxtItemIcon;
protected TextBox TxtItemName;
protected TextBox TxtItemUnit;
protected TextBox TxtManageInfoFilePath;
protected TextBox TxtModelName;
protected TextBox TxtPreviewInfoFilePath;
protected TextBox TxtTableName;
protected RegularExpressionValidator ValeTableName;
protected PowerEasy.Controls.RequiredFieldValidator ValrAddInfoFilePath;
protected PowerEasy.Controls.RequiredFieldValidator ValrBatchInfoFilePath;
protected PowerEasy.Controls.RequiredFieldValidator ValrItemName;
protected PowerEasy.Controls.RequiredFieldValidator ValrItemUnit;
protected PowerEasy.Controls.RequiredFieldValidator ValrManageInfoFilePath;
protected PowerEasy.Controls.RequiredFieldValidator ValrModelName;
protected PowerEasy.Controls.RequiredFieldValidator ValrPreviewInfoFilePath;
protected PowerEasy.Controls.RequiredFieldValidator ValrTableName;
protected void EBtnSubmit_Click(object sender, EventArgs e)
{
if (base.IsValid)
{
int modelTemplateId = DataConverter.CLng(this.DropModelTemplate.SelectedValue);
ModelInfo modelInfo = new ModelInfo();
modelInfo.IsEshop = true;
modelInfo.ModelName = this.TxtModelName.Text.Trim();
modelInfo.Description = this.TxtDescription.Text;
modelInfo.ItemName = this.TxtItemName.Text.Trim();
modelInfo.ItemUnit = this.TxtItemUnit.Text.Trim();
modelInfo.ItemIcon = this.TxtItemIcon.Text;
modelInfo.TableName = "PE_U_" + this.TxtTableName.Text.Trim();
modelInfo.IsCountHits = DataConverter.CBool(this.RadioIsCountHits.SelectedValue);
modelInfo.Disabled = DataConverter.CBool(this.RadioDisabled.SelectedValue);
modelInfo.DefaultTemplateFile = this.FileCTemplate.Text;
modelInfo.PrintTemplate = this.TscPrintTemplate.Text;
modelInfo.SearchTemplate = this.TscSearchTemplate.Text;
modelInfo.AdvanceSearchFormTemplate = this.TscAdvanceSearchFormTemplate.Text;
modelInfo.AdvanceSearchTemplate = this.TscAdvanceSearchTemplate.Text;
modelInfo.AddInfoFilePath = this.TxtAddInfoFilePath.Text.Trim();
modelInfo.ManageInfoFilePath = this.TxtManageInfoFilePath.Text.Trim();
modelInfo.PreviewInfoFilePath = this.TxtPreviewInfoFilePath.Text.Trim();
modelInfo.BatchInfoFilePath = this.TxtBatchInfoFilePath.Text.Trim();
ProductCharacter none = ProductCharacter.None;
foreach (ListItem item in this.ChklCharacter.Items)
{
if (item.Selected)
{
none |= DataConverter.CLng(item.Value);
}
}
modelInfo.Character = none;
if (this.ViewState["action"].ToString() == "Add")
{
if (ModelManager.ModelNameExists(modelInfo.ModelName))
{
AdminPage.WriteErrMsg("<li>数据库中已经存在此模型名称!</li>");
}
else if (ModelManager.TableNameExists(modelInfo.TableName))
{
AdminPage.WriteErrMsg("<li>数据库中已经存在要创建的表名请返回换一个表名!</li>");
}
else if (ModelManager.Add(modelInfo, modelTemplateId, ModelType.Shop))
{
base.Response.Write("<script type='text/javascript'>parent.frames[\"left\"].location.reload();</script>");
AdminPage.WriteSuccessMsg("<li>添加商品模型成功,已经将字段分别保存到模型下的字段和字段表中!</li>", "ProductModelManage.aspx");
}
else
{
AdminPage.WriteErrMsg("<li>添加商品模型操作失败!</li>");
}
}
else
{
bool flag;
modelInfo.ModelId = DataConverter.CLng(this.HdnModelId.Value);
modelInfo.TableName = this.HdnTableName.Value;
string modelName = this.TxtModelName.Text.Trim();
if (modelName == this.HdnModelName.Value)
{
flag = false;
}
else
{
flag = ModelManager.ModelNameExists(modelName);
}
if (!flag)
{
if (ModelManager.Update(modelInfo))
{
base.Response.Write("<script type='text/javascript'>parent.frames[\"left\"].location.reload();</script>");
AdminPage.WriteSuccessMsg("<li>修改商品模型成功!</li>", "ProductModelManage.aspx");
}
else
{
AdminPage.WriteErrMsg("<li>修改商品模型操作失败!</li>");
}
}
else
{
AdminPage.WriteErrMsg("<li>数据库中已经存在此商品模型名称!</li>");
}
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
foreach (DataRow row in FileSystemObject.GetDirectoryInfos(HttpContext.Current.Server.MapPath("~/Images/ModelIcon/"), FsoMethod.File).Rows)
{
this.DrpItemIcon.Items.Add(new ListItem(row["name"].ToString(), row["name"].ToString()));
}
this.DrpItemIcon.Attributes.Add("onchange", "ChangeImgItemIcon(this.value);ChangeTxtItemIcon(this.value);");
this.TxtItemIcon.Attributes.Add("onchange", "ChangeImgItemIcon(this.value);");
if (!base.IsPostBack)
{
string str = BasePage.RequestString("Action", "Add");
this.ViewState["action"] = str;
if (str == "Modify")
{
ModelInfo modelInfoById = ModelManager.GetModelInfoById(BasePage.RequestInt32("ModelID"));
this.TxtModelName.Text = modelInfoById.ModelName.ToString();
this.TxtDescription.Text = modelInfoById.Description;
this.TxtItemName.Text = modelInfoById.ItemName;
this.TxtItemUnit.Text = modelInfoById.ItemUnit;
string selectValue = string.IsNullOrEmpty(modelInfoById.ItemIcon) ? "Product.gif" : modelInfoById.ItemIcon;
this.ImgItemIcon.ImageUrl = "~/Images/ModelIcon/" + selectValue;
BasePage.SetSelectedIndexByValue(this.DrpItemIcon, selectValue);
this.TxtItemIcon.Text = selectValue;
this.TxtTableName.Text = modelInfoById.TableName;
this.FileCTemplate.Text = modelInfoById.DefaultTemplateFile;
this.TscPrintTemplate.Text = modelInfoById.PrintTemplate;
this.TscSearchTemplate.Text = modelInfoById.SearchTemplate;
this.TscAdvanceSearchFormTemplate.Text = modelInfoById.AdvanceSearchFormTemplate;
this.TscAdvanceSearchTemplate.Text = modelInfoById.AdvanceSearchTemplate;
this.TxtTableName.Enabled = false;
this.RadioIsCountHits.SelectedValue = modelInfoById.IsCountHits.ToString();
this.RadioDisabled.SelectedValue = modelInfoById.Disabled.ToString();
this.HdnModelId.Value = modelInfoById.ModelId.ToString();
this.HdnModelName.Value = modelInfoById.ModelName;
this.HdnTableName.Value = modelInfoById.TableName;
this.LblTablePrefix.Visible = false;
this.TxtAddInfoFilePath.Text = modelInfoById.AddInfoFilePath;
this.TxtManageInfoFilePath.Text = modelInfoById.ManageInfoFilePath;
this.TxtPreviewInfoFilePath.Text = modelInfoById.PreviewInfoFilePath;
this.TxtBatchInfoFilePath.Text = modelInfoById.BatchInfoFilePath;
foreach (ListItem item in this.ChklCharacter.Items)
{
item.Selected = Product.CharacterIsExists(modelInfoById.Character, (ProductCharacter) DataConverter.CLng(item.Value));
}
this.ChklCharacter.Enabled = false;
this.trModelTemmpalteId.Visible = false;
}
else
{
this.ShowFieldModelList();
}
}
}
protected void ShowFieldModelList()
{
IList<ModelTemplatesInfo> list = ModelTemplate.GetModelTemplateInfoList(0, 0, ModelType.Shop);
this.DropModelTemplate.Items.Clear();
ListItem item = new ListItem("空白商品模型模板", "0");
this.DropModelTemplate.Items.Add(item);
if (list.Count > 0)
{
item.Selected = true;
this.DropModelTemplate.AppendDataBoundItems = true;
this.DropModelTemplate.DataSource = list;
this.DropModelTemplate.DataTextField = "TemplateName";
this.DropModelTemplate.DataValueField = "TemplateId";
}
this.DropModelTemplate.DataBind();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -