public double insert(double id) { if (parentColumn == null) { throw new Exception("未指定栏目或栏目不存在"); } columnConfig = ColumnClass.getConfig(parentColumn.id); #region 标题重复处理 if (!columnConfig.titleRepeat)//标题不允许重复 { string where = "title=@title"; if (columnConfig.isModule) { where += " and moduleId=@moduleId"; } else if (columnConfig.isRoot) { where += " and rootId=@rootId"; } else { where += " and classId in (" + columnConfig.childId + ")"; } int c = int.Parse(Sql.ExecuteScalar("select count(1) from maintable where " + where, new MySqlParameter[] { new MySqlParameter("title", title), new MySqlParameter("moduleId", parentColumn.moduleId), new MySqlParameter("rootId", parentColumn.rootId) }).ToString()); if (c > 0) { throw new Exception("标题已存在"); } } #endregion //if (classId != null) size = API.getThumbnailSize(classId); string datatypeclassid = null; double dataTypeId = 0; MySqlDataReader rsv = Sql.ExecuteReader("select id,classid,tablestructure from datatype where tablename='" + tableName + "'"); if (rsv.Read()) { dataTypeId = rsv.GetDouble(0); datatypeclassid = rsv[1].ToString(); } rsv.Close(); System.Text.StringBuilder str = new System.Text.StringBuilder(); System.Text.StringBuilder str1 = new System.Text.StringBuilder(); this.addField("id", id); this.addField("createdate", System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); this.addField("updatedate", System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); this.addField("datatypeId", dataTypeId); this.addField("moduleId", parentColumn.moduleId); this.addField("rootId", parentColumn.rootId); this.addField("userId", _user.id); //this.addField("orderId",orderId); string field1_1 = "", field1_2 = "", field2_1 = "id", field2_2 = "@id"; int picFieldIndex = -1; foreach (var item in fields) { MySqlParameter p = (MySqlParameter)((DictionaryEntry)item).Value; if (p.ParameterName.IndexOf("u_") > -1) { if (field2_1 != "") { field2_1 += ","; field2_2 += ","; } field2_1 += p.ParameterName; field2_2 += "@" + p.ParameterName; } else { //if (p.ParameterName == "pic") picFieldIndex = n; if (field1_1 != "") { field1_1 += ","; field1_2 += ","; } field1_1 += p.ParameterName; field1_2 += "@" + p.ParameterName; } if (p.Value != null && p.Value.GetType().Name == "String") { string value = (string)p.Value; verificationWord(ref value); downFiles(ref value); p.Value = value; } } if (fields["pic"] == null) //没有添加缩略图字段时 { field1_1 += ",pic"; field1_2 += ",@pic"; addField("pic", defaultPic); } else { if ((string)((MySqlParameter)fields["pic"]).Value == "") { ((MySqlParameter)fields["pic"]).Value = defaultPic; } setThumbnail((string)((MySqlParameter)fields["pic"]).Value, (string)((MySqlParameter)fields["pic"]).Value); } int count = Sql.ExecuteNonQuery("insert into maintable (" + field1_1 + ")values(" + field1_2 + ")", fields); count = Sql.ExecuteNonQuery("insert into " + tableName + " (" + field2_1 + ")values(" + field2_2 + ")", fields); if (count > 0) { resetUrl(parentColumn.id, id); } return(id); }
public double update(double id) { if (parentColumn == null) { throw new Exception("未指定栏目或栏目不存在"); } columnConfig = ColumnClass.getConfig(parentColumn.id); if (!columnConfig.titleRepeat)//标题不允许重复 { string where = "id<>@id and title=@title"; if (columnConfig.isModule) { where += " and moduleId=@moduleId"; } else if (columnConfig.isRoot) { where += " and rootId=@rootId"; } else { where += " and classId in (" + columnConfig.childId + ")"; } int c = int.Parse(Sql.ExecuteScalar("select count(1) from maintable where " + where, new MySqlParameter[] { new MySqlParameter("title", title), new MySqlParameter("moduleId", parentColumn.moduleId), new MySqlParameter("rootId", parentColumn.rootId), new MySqlParameter("id", id) }).ToString()); if (c > 0) { throw new Exception("标题已存在"); } } addField("updatedate", System.DateTime.Now); System.Text.StringBuilder str = new System.Text.StringBuilder(); this.addField("id", id); this.addField("moduleId", parentColumn.moduleId); this.addField("rootId", parentColumn.rootId); string field1 = "", field2 = ""; int picFieldIndex = -1; foreach (var item in fields) { MySqlParameter p = (MySqlParameter)((DictionaryEntry)item).Value; if (p.ParameterName.IndexOf("u_") > -1) { if (field2 != "") { field2 += ","; } field2 += p.ParameterName + "=" + "@" + p.ParameterName; } else { if (field1 != "") { field1 += ","; } field1 += p.ParameterName + "=" + "@" + p.ParameterName; } if (p.Value != null && p.Value.GetType().Name == "String") { string value = (string)p.Value; verificationWord(ref value); downFiles(ref value); p.Value = value; } } if (picFieldIndex > -1) { setThumbnail((string)((MySqlParameter)fields[picFieldIndex]).Value, (string)((MySqlParameter)fields[picFieldIndex]).Value); } int count = 0; count = Sql.ExecuteNonQuery("update maintable set " + field1 + " where id=@id", fields); count = Sql.ExecuteNonQuery("update " + tableName + " set " + field2 + " where id=@id", fields); return(id); }