You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Attributes/AttributeEdit.aspx.cs

220 lines
8.5 KiB
C#

3 years ago
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using DSWeb.Models;
using DSWeb.EntityDA;
using System.Collections.Generic;
namespace DSWeb.Attributes
{
public partial class AttributeEdit : System.Web.UI.Page
{
private string strAttriubteID;
private string strUserID;
private string strShowName;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USERID"] != null)
{
strUserID = Session["USERID"].ToString();
}
if (Session["SHOWNAME"] != null)
{
strShowName = Session["SHOWNAME"].ToString();
}
if (Request.QueryString["id"] != null)
{
strAttriubteID = Request.QueryString["id"].ToString();
h_attrid.Value = strAttriubteID;
}
if (!IsPostBack)
{
AttributeTypeDA attributeTypeDA = new AttributeTypeDA();
IList<AttributeTypeEntity> attributeTypeEntities = new List<AttributeTypeEntity>();
attributeTypeEntities = attributeTypeDA.GetAttributeTypeAll();
if (attributeTypeEntities.Count > 0)
{
if (sel_type.Items.Count > 0)
{
sel_type.Items.Clear();//清除所有参数类型
}
foreach (AttributeTypeEntity attrTypeEntity in attributeTypeEntities)
{
this.sel_type.Items.Add(new ListItem(attrTypeEntity.Name, attrTypeEntity.GID));
}
}
}
if (strAttriubteID != null)
{
AttributeEntity attributeEntity = new AttributeEntity();
AttributeDA attributeDA = new AttributeDA();
attributeEntity = attributeDA.GetAttributeByID(strAttriubteID);
if (attributeEntity != null)
{
if (attributeEntity.GID != null)
{
this.txt_name.Value = attributeEntity.Name;
this.txt_description.Value = attributeEntity.Description;
this.txt_sort.Value = attributeEntity.Sort.ToString();
this.sel_type.Value = attributeEntity.TypeID;
this.txt_defaultval.Value = attributeEntity.DefaultValue;
UserEntity userEntity = new UserDA().GetUserSignByID(attributeEntity.CreateUser);
if (userEntity != null)
{
if (userEntity.Gid != null)
{
this.txt_createuser.InnerHtml = userEntity.ShowName;
}
}
this.txt_createtime.InnerHtml = attributeEntity.CreateTime.ToString("yyyy-MM-dd HH:mm:ss");
}
}
}
}
protected void btn_enter_Click(object sender, EventArgs e)
{
int iResult = 0;
string tempName = "";
if (!Request.Form["txt_name"].ToString().Trim().Equals(""))
{
tempName = Request.Form["txt_name"].ToString().Trim();
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('参数不能为空');</script>");
}
string tempDescription = "";
if (!Request.Form["txt_description"].ToString().Trim().Equals(""))
{
tempDescription = Request.Form["txt_description"].ToString().Trim();
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('参数描述信息不能为空');</script>");
}
int tempSort = 0;
if (!Request.Form["txt_sort"].ToString().Trim().Equals(""))
{
tempSort = int.Parse(Request.Form["txt_sort"].ToString().Trim());
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key3", "<script>alert('参数排序值不能为空');</script>");
}
string tempDefaultValue = "";
if (!Request.Form["txt_defaultval"].ToString().Trim().Equals(""))
{
tempDefaultValue = Request.Form["txt_defaultval"].ToString().Trim();
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key3", "<script>alert('参数默认值不能为空');</script>");
}
string tempTypeID = "";
if (!Request.Form["sel_type"].ToString().Trim().Equals(""))
{
tempTypeID = Request.Form["sel_type"].ToString().Trim();
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key3", "<script>alert('参数类型不能为空');</script>");
}
if (h_attrid.Value.Trim() != "")
{
string tempAttributeID = h_attrid.Value.Trim();
AttributeEntity attributeEntity = new AttributeEntity();
AttributeDA attributeDA = new AttributeDA();
attributeEntity = attributeDA.GetAttributeByID(tempAttributeID);
if (attributeEntity != null)
{
if (attributeEntity.GID != null)
{
attributeEntity.Name = tempName;
attributeEntity.Description = tempDescription;
attributeEntity.Sort = tempSort;
attributeEntity.State = 1;
attributeEntity.TypeID = tempTypeID;
attributeEntity.ModifiedUser = strUserID;
attributeEntity.DefaultValue = tempDefaultValue;
iResult = attributeDA.UpdateAttribute(attributeEntity);
if (iResult == 1)
{
this.sel_type.Value = attributeEntity.TypeID;
Page.ClientScript.RegisterStartupScript(this.GetType(), "key3", "<script>alert('保存成功');window.opener.location.href=window.opener.location.href;</script>");
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key4", "<script>alert('保存失败');</script>");
}
}
}
}
else
{
AttributeEntity attributeEntity = new AttributeEntity();
AttributeDA attributeDA = new AttributeDA();
attributeEntity.GID = Guid.NewGuid().ToString();
attributeEntity.Name = tempName;
attributeEntity.Description = tempDescription;
attributeEntity.Sort = tempSort;
attributeEntity.State = 1;
attributeEntity.CreateUser = strUserID;
attributeEntity.TypeID = this.sel_type.Value.Trim();
attributeEntity.DefaultValue = tempDefaultValue;
iResult = attributeDA.InsertAttribute(attributeEntity);
if (iResult == 1)
{
h_attrid.Value = attributeEntity.GID;
this.dvCreateUser.InnerHtml = strShowName;
attributeEntity = attributeDA.GetAttributeByID(h_attrid.Value.Trim());
if (attributeEntity != null)
{
if (attributeEntity.GID != null)
{
this.dvCreateTime.InnerHtml = attributeEntity.CreateTime.ToString("yyyy-MM-dd hh:mm:ss");
}
}
Page.ClientScript.RegisterStartupScript(this.GetType(), "key5", "<script>alert('保存成功');window.opener.location.href=window.opener.location.href;</script>");
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key6", "<script>alert('保存失败');</script>");
}
}
}
}
}