/// <summary> /// 更新一条数据 /// </summary> public int UpdateProductField(ProductFieldInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tbProductFieldInfo set "); strSql.Append("ProductClassID=@ProductClassID,"); strSql.Append("pfName=@pfName,"); strSql.Append("pfType=@pfType,"); strSql.Append("pfOrder=@pfOrder,"); strSql.Append("pfState=@pfState,"); strSql.Append("pfAppendTime=@pfAppendTime"); strSql.Append(" where ProductFieldID=@ProductFieldID "); SqlParameter[] parameters = { new SqlParameter("@ProductFieldID", SqlDbType.Int, 4), new SqlParameter("@ProductClassID", SqlDbType.Int, 4), new SqlParameter("@pfName", SqlDbType.VarChar, 128), new SqlParameter("@pfType", SqlDbType.Int, 4), new SqlParameter("@pfOrder", SqlDbType.Int, 4), new SqlParameter("@pfState", SqlDbType.Int, 4), new SqlParameter("@pfAppendTime", SqlDbType.DateTime) }; parameters[0].Value = model.ProductFieldID; parameters[1].Value = model.ProductClassID; parameters[2].Value = model.pfName; parameters[3].Value = model.pfType; parameters[4].Value = model.pfOrder; parameters[5].Value = model.pfState; parameters[6].Value = model.pfAppendTime; return(DbHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), parameters)); }
protected void rptDetail_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { ProductFieldInfo productFieldInfo = e.Item.DataItem as ProductFieldInfo; FieldControl fieldControl = e.Item.FindControl("field") as FieldControl; if (fieldControl != null) { fieldControl.ControlType = (FieldType)productFieldInfo.FieldType; fieldControl.ControlPath = "~/Platform/h5/FieldControls/"; fieldControl.LoadControlId = ((FieldType)productFieldInfo.FieldType).ToString(); fieldControl.FieldName = productFieldInfo.FieldName; fieldControl.FieldAlias = productFieldInfo.Alias; fieldControl.FieldId = productFieldInfo.AutoID; fieldControl.Settings = XmlSerializerUtils.Deserialize <SinGooCMS.Control.FieldSetting>(productFieldInfo.Setting); fieldControl.DataLength = productFieldInfo.DataLength; fieldControl.EnableNull = productFieldInfo.EnableNull; if (!string.IsNullOrEmpty(productFieldInfo.Value)) { fieldControl.Value = productFieldInfo.Value; } else { fieldControl.Value = (productFieldInfo.DefaultValue ?? string.Empty); } } } }
protected void lnk_Delete_Click(object sender, System.EventArgs e) { if (!base.IsAuthorizedOp(ActionType.Delete.ToString())) { base.ShowAjaxMsg(this.UpdatePanel1, "Không có thẩm quyền"); } else { int @int = WebUtils.GetInt((sender as LinkButton).CommandArgument); ProductFieldInfo dataById = ProductField.GetDataById(@int); if (dataById == null) { base.ShowAjaxMsg(this.UpdatePanel1, "Những thông tin này không được tìm thấy, các dữ liệu không tồn tại hoặc đã bị xóa"); } else if (dataById.IsSystem) { base.ShowAjaxMsg(this.UpdatePanel1, "Lĩnh vực thuộc hệ thống không thể bị xóa"); } else if (ProductField.Delete(@int)) { this.BindData(); PageBase.log.AddEvent(base.LoginAccount.AccountName, "Xóa trường [" + dataById.FieldName + "] thành công"); base.ShowAjaxMsg(this.UpdatePanel1, "Thao tác thành công"); } else { base.ShowAjaxMsg(this.UpdatePanel1, "Thao tác thất bại"); } } }
public static FieldAddState Add(ProductFieldInfo field) { ProductModelInfo dataById = ProductModel.GetDataById(field.ModelID); FieldAddState result; if (dataById == null) { result = FieldAddState.ModelNotExists; } else { int value = BizBase.dbo.GetValue <int>(string.Concat(new object[] { "SELECT COUNT(*) FROM shop_ProductField WHERE ModelID=", field.ModelID, " AND FieldName='", field.FieldName, "'" })); if (value > 0) { result = FieldAddState.FieldNameExists; } else { if (BizBase.dbo.InsertModel <ProductFieldInfo>(field) > 0) { try { string text = field.DataType; if (string.Compare(text, "nvarchar", true) == 0) { object obj = text; text = string.Concat(new object[] { obj, "(", field.DataLength, ")" }); } TableManager.AddTableColumn(dataById.TableName, field.FieldName, text, true, field.DefaultValue); } catch { result = FieldAddState.CreateColumnError; return(result); } } CacheUtils.Del("JsonLeeCMS_CacheForGetUserGroup"); result = FieldAddState.Success; } } return(result); }
public static bool Delete(int fieldID) { ProductFieldInfo dataById = ProductField.GetDataById(fieldID); ProductModelInfo dataById2 = ProductModel.GetDataById(dataById.ModelID); if (BizBase.dbo.DeleteModel <ProductFieldInfo>(dataById)) { TableManager.DropTableColumn(dataById2.TableName, dataById.FieldName); } CacheUtils.Del("JsonLeeCMS_CacheForPROMODEL"); return(true); }
/// <summary> /// 得到一个对象实体 /// </summary> public ProductFieldInfo GetProductFieldModel(int ProductFieldID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ProductFieldID,ProductClassID,pfName,pfType,pfOrder,pfState,pfAppendTime,(select pClassName from tbProductClassInfo where tbProductClassInfo.ProductClassID=tbProductFieldInfo.ProductClassID) as ProductClassName from tbProductFieldInfo "); strSql.Append(" where ProductFieldID=@ProductFieldID "); SqlParameter[] parameters = { new SqlParameter("@ProductFieldID", SqlDbType.Int, 4) }; parameters[0].Value = ProductFieldID; ProductFieldInfo model = new ProductFieldInfo(); DataSet ds = DbHelper.ExecuteDataset(CommandType.Text, strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { model.ProductClassName = ds.Tables[0].Rows[0]["ProductClassName"].ToString(); model.pfName = ds.Tables[0].Rows[0]["pfName"].ToString(); if (ds.Tables[0].Rows[0]["ProductFieldID"].ToString() != "") { model.ProductFieldID = int.Parse(ds.Tables[0].Rows[0]["ProductFieldID"].ToString()); } if (ds.Tables[0].Rows[0]["ProductClassID"].ToString() != "") { model.ProductClassID = int.Parse(ds.Tables[0].Rows[0]["ProductClassID"].ToString()); } if (ds.Tables[0].Rows[0]["pfType"].ToString() != "") { model.pfType = int.Parse(ds.Tables[0].Rows[0]["pfType"].ToString()); } if (ds.Tables[0].Rows[0]["pfOrder"].ToString() != "") { model.pfOrder = int.Parse(ds.Tables[0].Rows[0]["pfOrder"].ToString()); } if (ds.Tables[0].Rows[0]["pfState"].ToString() != "") { model.pfState = int.Parse(ds.Tables[0].Rows[0]["pfState"].ToString()); } if (ds.Tables[0].Rows[0]["pfAppendTime"].ToString() != "") { model.pfAppendTime = DateTime.Parse(ds.Tables[0].Rows[0]["pfAppendTime"].ToString()); } return(model); } else { return(null); } }
private System.Collections.Generic.Dictionary <string, ProductFieldInfo> GetFieldDicWithValues() { System.Collections.Generic.Dictionary <string, ProductFieldInfo> dictionary = new System.Collections.Generic.Dictionary <string, ProductFieldInfo>(); foreach (RepeaterItem repeaterItem in this.rptDetail.Items) { FieldControl fieldControl = repeaterItem.FindControl("field") as FieldControl; if (fieldControl != null) { ProductFieldInfo dataById = ProductField.GetDataById(fieldControl.FieldId); if (dataById != null) { dataById.Value = fieldControl.Value; dictionary.Add(dataById.FieldName, dataById); } } } return(dictionary); }
public static bool Update(ProductFieldInfo field) { ProductModelInfo dataById = ProductModel.GetDataById(field.ModelID); ProductFieldInfo dataById2 = ProductField.GetDataById(field.AutoID); bool result; if (BizBase.dbo.UpdateModel <ProductFieldInfo>(field)) { if (!dataById2.IsSystem) { try { string text = field.DataType; if (string.Compare(text, "nvarchar", true) == 0) { object obj = text; text = string.Concat(new object[] { obj, "(", field.DataLength, ")" }); } TableManager.AlterTableColumn(dataById.TableName, dataById2.FieldName, field.FieldName, text, true, field.DefaultValue); } catch (Exception ex) { throw ex; } } CacheUtils.Del("JsonLeeCMS_CacheForPROMODEL"); result = true; } else { result = false; } return(result); }
/// <summary> /// 增加一条数据 /// </summary> public int AddProductField(ProductFieldInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tbProductFieldInfo("); strSql.Append("ProductClassID,pfName,pfType,pfOrder,pfState,pfAppendTime)"); strSql.Append(" values ("); strSql.Append("@ProductClassID,@pfName,@pfType,@pfOrder,@pfState,@pfAppendTime)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@ProductClassID", SqlDbType.Int, 4), new SqlParameter("@pfName", SqlDbType.VarChar, 128), new SqlParameter("@pfType", SqlDbType.Int, 4), new SqlParameter("@pfOrder", SqlDbType.Int, 4), new SqlParameter("@pfState", SqlDbType.Int, 4), new SqlParameter("@pfAppendTime", SqlDbType.DateTime) }; parameters[0].Value = model.ProductClassID; parameters[1].Value = model.pfName; parameters[2].Value = model.pfType; parameters[3].Value = model.pfOrder; parameters[4].Value = model.pfState; parameters[5].Value = model.pfAppendTime; object obj = DbHelper.ExecuteScalar(CommandType.Text, strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
protected virtual void Page_Load(object sender, EventArgs e) { if (this.userid > 0) { if (CheckUserPopedoms("X") || CheckUserPopedoms("2-1-8")) { Act = HTTPRequest.GetString("Act"); ProductFieldID = HTTPRequest.GetInt("ProductFieldID", 0); ProductClassID = HTTPRequest.GetInt("ProductClassID", 0); pfName = Utils.ChkSQL(HTTPRequest.GetString("pfName").Trim()); pfType = HTTPRequest.GetInt("pfType", 0); pfOrder = HTTPRequest.GetInt("pfOrder", 0); pfState = HTTPRequest.GetInt("pfState", 0); if (ProductFieldID > 0) { pf = tbProductFieldInfo.GetProductFieldModel(ProductFieldID); } if (ispost) { //添加 if (Act.IndexOf("add") > -1) { if (pfName.Trim() != "") { if (!tbProductFieldInfo.ExistsProductField(ProductClassID, pfName)) { pf.pfName = pfName.Trim(); pf.pfOrder = pfOrder; pf.pfState = pfState; pf.pfType = pfType; pf.ProductClassID = ProductClassID; pf.pfAppendTime = pfAppendTime; int pfID = tbProductFieldInfo.AddProductField(pf); if (pfID > 0) { Logs.AddEventLog(this.userid, "添加" + pfName + "(" + pfID + ")商品字段"); AddMsgLine("操作成功!"); AddScript("window.setTimeout('window.parent.HidBox();',1000);"); } } else { AddErrLine("操作失败,该商品字段当前分类下已经存在,请核对后重新添加!"); } } else { AddErrLine("操作失败,商品字段不能为空,请核对后重新添加!"); } } //修改 if (Act.IndexOf("update") > -1) { bool isOK = true; string error_str = ""; if (pf.pfName.Trim() != pfName.Trim()) { if (!tbProductFieldInfo.ExistsProductField(ProductClassID, pfName)) { isOK = true; } else { isOK = false; AddErrLine("操作失败,该商品字段当前分类下已经存在,请核对后重新添加!"); } } if (isOK) { if (pfName.Trim() != "") { string lastName = pf.pfName; pf.pfName = pfName.Trim(); pf.pfOrder = pfOrder; pf.pfState = pfState; pf.pfType = pfType; pf.ProductClassID = ProductClassID; int count = tbProductFieldInfo.UpdateProductField(pf); if (count > 0) { //记录修改操作 Logs.AddEventLog(this.userid, "将" + lastName + "商品字段修改为" + pfName); AddMsgLine("修改成功!"); AddScript("window.setTimeout('window.parent.HidBox();',1000);"); } else { AddErrLine("修改失败!"); } } else { AddErrLine("商品字段不能为空!"); } } } } else { ProductFieldTypeList = tbProductFieldInfo.GetProductFieldTypes(); ProductClassStr = DataClass.GetProductClassInfoToHTML(); } } else { AddErrLine("权限不足!"); AddScript("window.parent.HidBox();"); } } else { AddErrLine("请先登录!"); SetBackLink("login.aspx?referer=" + Utils.UrlEncode(Utils.GetUrlReferrer())); SetMetaRefresh(1, "login.aspx?referer=" + Utils.UrlEncode(Utils.GetUrlReferrer())); } }
private void InitForModify() { ProductFieldInfo dataById = ProductField.GetDataById(base.OpID); if (dataById != null) { this.TextBox2.Text = dataById.FieldName; this.TextBox2.Enabled = false; this.TextBox3.Text = dataById.Alias; this.TextBox4.Text = dataById.Tip; ListItem listItem = this.DropDownList5.Items.FindByValue(((FieldType)dataById.FieldType).ToString()); if (listItem != null) { listItem.Selected = true; } if (dataById.IsSystem) { this.DropDownList5.Enabled = false; } switch (dataById.FieldType) { case 0: this.ShowGroup = "group1"; break; case 1: this.ShowGroup = "group2"; break; case 2: this.ShowGroup = "group7"; break; case 4: case 5: case 6: this.ShowGroup = "group3"; break; case 7: this.ShowGroup = "group6"; break; case 8: case 10: this.ShowGroup = "group4"; break; case 9: case 11: this.ShowGroup = "group5"; break; } this.TextBox6.Text = dataById.DefaultValue; this.CheckBox7.Checked = dataById.IsUsing; this.CheckBox9.Checked = dataById.EnableNull; this.ExtTextBox5.Text = dataById.DataLength.ToString(); if (dataById.IsSystem) { this.ExtTextBox5.Enabled = false; } SinGooCMS.Control.FieldSetting fieldSetting = XmlSerializerUtils.Deserialize <SinGooCMS.Control.FieldSetting>(dataById.Setting); if (fieldSetting != null) { this.ExtTextBox1.Text = fieldSetting.ControlWidth.ToString(); this.ExtTextBox2.Text = fieldSetting.ControlHeight.ToString(); ListItem listItem2 = this.ExtRadioButtonList3.Items.FindByValue(fieldSetting.TextMode); if (listItem2 != null) { listItem2.Selected = true; } this.ExtTextBox4.Text = fieldSetting.DataFormat; ListItem listItem3 = this.ExtDropDownList6.Items.FindByValue(fieldSetting.DataFrom); if (listItem3 != null) { listItem3.Selected = true; } string dataFrom = fieldSetting.DataFrom; if (dataFrom != null) { if (!(dataFrom == "Text")) { if (!(dataFrom == "DataDictionary")) { if (!(dataFrom == "SQLQuery")) { if (dataFrom == "AjaxData") { this.ExtTextBox11.Text = fieldSetting.DataSource; this.DataSource = "AjaxData"; } } else { this.ExtTextBox9.Text = fieldSetting.DataSource; this.DataSource = "SQLQuery"; } } else { this.ExtTextBox8.Text = fieldSetting.DataSource; this.DataSource = "DataDictionary"; } } else { this.ExtTextBox7.Text = fieldSetting.DataSource; this.DataSource = "Text"; } } } } }
protected void btnok_Click(object sender, System.EventArgs e) { if (base.Action.Equals(ActionType.Add.ToString()) && !base.IsAuthorizedOp(ActionType.Add.ToString())) { base.ShowMsg("Không có thẩm quyền"); } else if (base.Action.Equals(ActionType.Modify.ToString()) && !base.IsAuthorizedOp(ActionType.Modify.ToString())) { base.ShowMsg("Không có thẩm quyền"); } else { ProductFieldInfo productFieldInfo = new ProductFieldInfo(); if (base.IsEdit) { productFieldInfo = ProductField.GetDataById(base.OpID); } productFieldInfo.ModelID = this.modelParent.AutoID; productFieldInfo.FieldName = WebUtils.GetString(this.TextBox2.Text); productFieldInfo.Alias = WebUtils.GetString(this.TextBox3.Text); productFieldInfo.Tip = WebUtils.GetString(this.TextBox4.Text); productFieldInfo.FieldType = (int)((FieldType)System.Enum.Parse(typeof(FieldType), this.DropDownList5.SelectedValue)); productFieldInfo.DataLength = 50; if (string.IsNullOrEmpty(productFieldInfo.FieldName) || string.IsNullOrEmpty(productFieldInfo.Alias)) { base.ShowMsg("Tên trường/Tên hiển thị không thể để trống"); } else { productFieldInfo.DefaultValue = WebUtils.GetString(this.TextBox6.Text); SinGooCMS.Control.FieldSetting fieldSetting = new SinGooCMS.Control.FieldSetting(); fieldSetting.ControlWidth = WebUtils.GetInt(this.ExtTextBox1.Text); fieldSetting.ControlHeight = WebUtils.GetInt(this.ExtTextBox2.Text); fieldSetting.TextMode = this.ExtRadioButtonList3.SelectedValue; fieldSetting.IsDataType = productFieldInfo.FieldType.Equals(FieldType.DateTimeType); fieldSetting.DataFormat = WebUtils.GetString(this.ExtTextBox4.Text); FieldType fieldType = (FieldType)productFieldInfo.FieldType; if (fieldType != FieldType.MultipleHtmlType) { if (fieldType != FieldType.DateTimeType) { productFieldInfo.DataType = "nvarchar"; productFieldInfo.DataLength = WebUtils.GetInt(this.ExtTextBox5.Text, 50); } else { productFieldInfo.DataType = "datetime"; } } else { productFieldInfo.DataType = "ntext"; } fieldSetting.DataFrom = this.ExtDropDownList6.SelectedValue; string dataFrom = fieldSetting.DataFrom; if (dataFrom != null) { if (!(dataFrom == "Text")) { if (!(dataFrom == "DataDictionary")) { if (!(dataFrom == "SQLQuery")) { if (dataFrom == "AjaxData") { fieldSetting.DataSource = WebUtils.GetString(this.ExtTextBox11.Text); } } else { fieldSetting.DataSource = WebUtils.GetString(this.ExtTextBox9.Text); } } else { fieldSetting.DataSource = WebUtils.GetString(this.ExtTextBox8.Text); } } else { fieldSetting.DataSource = this.ExtTextBox7.Text; } } productFieldInfo.Setting = XmlSerializerUtils.Serialize <SinGooCMS.Control.FieldSetting>(fieldSetting); productFieldInfo.IsUsing = this.CheckBox7.Checked; productFieldInfo.EnableNull = this.CheckBox9.Checked; productFieldInfo.EnableSearch = false; if (base.Action.Equals(ActionType.Add.ToString())) { productFieldInfo.AutoTimeStamp = System.DateTime.Now; productFieldInfo.Sort = ProductField.MaxSort + 1; productFieldInfo.IsSystem = false; FieldAddState fieldAddState = ProductField.Add(productFieldInfo); FieldAddState fieldAddState2 = fieldAddState; switch (fieldAddState2) { case FieldAddState.Error: base.ShowMsg("Tạo trường thất bại"); break; case FieldAddState.FieldNameIsUsing: base.ShowMsg("Tên trường đã được sử dụng"); break; case FieldAddState.FieldNameExists: base.ShowMsg("Tên trường đã tồn tại"); break; case FieldAddState.ModelNotExists: base.ShowMsg("Không tìm thấy kiểu dữ liệu"); break; case FieldAddState.CreateColumnError: base.ShowMsg("Tạo cột dữ liệu thất bại"); break; default: if (fieldAddState2 != FieldAddState.Success) { base.ShowMsg("Lỗi Unknown"); } else { PageBase.log.AddEvent(base.LoginAccount.AccountName, "Thêm trường [" + productFieldInfo.FieldName + "] thành công"); base.Response.Redirect(string.Concat(new object[] { "ProField.aspx?CatalogID=", base.CurrentCatalogID, "&Module=", base.CurrentModuleCode, "&ModelID=", this.intModelID, "&action=View" })); } break; } } if (base.Action.Equals(ActionType.Modify.ToString())) { if (ProductField.Update(productFieldInfo)) { PageBase.log.AddEvent(base.LoginAccount.AccountName, "Sửa trường [" + productFieldInfo.FieldName + "] thành công"); base.Response.Redirect(string.Concat(new object[] { "ProField.aspx?CatalogID=", base.CurrentCatalogID, "&Module=", base.CurrentModuleCode, "&ModelID=", this.intModelID, "&action=View" })); } else { base.ShowMsg("Sửa trường thất bại"); } } } } }
public static int UpdateProductField(ProductFieldInfo model) { return(DatabaseProvider.GetInstance().UpdateProductField(model)); }