public Guid AddNewDictionaryEntity(Guid dictionaryTreeID, Guid entityID) { DictionaryTree tree = DictionaryTrees.SingleOrDefault(d => d.ID == dictionaryTreeID); Guid id = Guid.NewGuid(); if (tree != null) { string sql = string.Format("insert into {0}({1})values('{2}')", tree.Dictionary.TableName, tree.PK, id); using (CommonDataProvider domain = new CommonDataProvider()) { domain.ExecuteNonQuery(sql); return id; } } return Guid.Empty; }
public Guid AddNewProduct(Guid parentProduct, bool withDictNomen, Guid dictNomenID, Guid UserID) { Product parent = Products.SingleOrDefault(p => p.ID == parentProduct); List<ClassificationTreeProduct> trees = parent.ClassificationTreeProducts.ToList(); Guid id = Guid.NewGuid(); if (parent != null) { //insert product entity string sql; if (withDictNomen) { sql = "INSERT INTO Product(ID,Name,CreatedDate,_dictNomenID)VALUES('{0}','{1}',CONVERT(datetime, '{2}', 120),'{3}')"; sql = string.Format(sql, id, parent.PublicName.Trim(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), Guid.Empty.Equals(dictNomenID) ? parent._dictNomenID : dictNomenID); } else { sql = "INSERT INTO Product(ID,Name,CreatedDate)VALUES('{0}','{1}',CONVERT(datetime, '{2}', 120))"; sql = string.Format(sql, id, parent.PublicName.Trim(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); } using (CommonDataProvider provider = new CommonDataProvider()) { provider.ExecuteNonQuery(sql); } //add to global classification tree List<ClassificationTreeProduct> classif = new List<ClassificationTreeProduct>(); foreach (ClassificationTreeProduct item in trees) { ClassificationTreeProduct entity = new ClassificationTreeProduct() { ClassificationTreeID = item.ClassificationTreeID, ID = Guid.NewGuid(), ProductID = id }; classif.Add(entity); } this.ClassificationTreeProducts.InsertAllOnSubmit(classif); this.SubmitChanges(); return id; } return Guid.Empty; }
public void SetProductDictioanryValue(Guid productID, string property, string value, Guid userID) { object oldValue = this.GetProductDicitonaryValue(productID, property); if (oldValue == DBNull.Value || value != oldValue.ToString()) { Aspect.Utility.TraceHelper.Log(userID, "Продукт: {0}. Свойство справочника изменино: {1}. Старое значение {2}. Новое значение {3}", productID, property, oldValue == DBNull.Value ? "NULL" : oldValue.ToString(), value); } string sql = string.Format("update Product set [{0}] = '{1}' where ID = '{2}'", property, value, productID); string sql2 = string.Format("update Product set [UserID] = '{0}' where ID = '{1}'", userID, productID); using (CommonDataProvider provider = new CommonDataProvider()) { provider.ExecuteNonQuery(sql); provider.ExecuteNonQuery(sql2); } }
public void SetDictionaryItemValue(Guid dictionaryTreeID, Guid entityID, string column, string value, Guid userID) { DictionaryTree tree = DictionaryTrees.SingleOrDefault(d => d.ID == dictionaryTreeID); if (tree != null) { using (CommonDataProvider domain = new CommonDataProvider()) { ColumnTypeEnum type = this.GetColumnType(domain, tree.Dictionary.TableName, column); int length = this.GetColumnLength(domain, tree.Dictionary.TableName, column); string sql; switch (type) { case ColumnTypeEnum.Integer: case ColumnTypeEnum.Numeric: case ColumnTypeEnum.Decimal: value = value.Replace(",", "."); if (string.IsNullOrEmpty(value)) value = "NULL"; sql = string.Format("UPDATE {1} SET [{0}] = {2} WHERE [{3}] = '{4}'", column, tree.Dictionary.TableName, value, tree.PK, entityID); break; case ColumnTypeEnum.Datetime: sql = string.Format("UPDATE {1} SET [{0}] = '{2}' WHERE [{3}] = '{4}'", column, tree.Dictionary.TableName, Convert.ToDateTime(value).ToString(CultureInfo.InvariantCulture), tree.PK, entityID); break; case ColumnTypeEnum.Varchar: if (value.Length > length) value = value.Substring(0, length); sql = string.Format("UPDATE {1} SET [{0}] = '{2}' WHERE [{3}] = '{4}'", column, tree.Dictionary.TableName, value, tree.PK, entityID); break; case ColumnTypeEnum.Uniqueidentifier: case ColumnTypeEnum.Unknown: default: sql = string.Format("UPDATE {1} SET [{0}] = '{2}' WHERE [{3}] = '{4}'", column, tree.Dictionary.TableName, value, tree.PK, entityID); break; } domain.ExecuteNonQuery(sql); // setting UserID sql = string.Format("UPDATE {0} SET [UserID] = '{1}' WHERE [{2}] = '{3}'", tree.Dictionary.TableName, userID, tree.PK, entityID); domain.ExecuteNonQuery(sql); } } }
public void DeleteProductDictionaryValue(Guid productID, string property, Guid userID) { object oldValue = this.GetProductDicitonaryValue(productID, property); if (oldValue != DBNull.Value) { Aspect.Utility.TraceHelper.Log(userID, "Продукт: {0}. Свойство справочника удалено: {1}. Старое значение {2}. Новое значение NULL", productID, property, oldValue == DBNull.Value ? "NULL" : oldValue.ToString()); } string sql = "update Product set [{0}] = NULL where ID = '{1}'"; sql = string.Format(sql, property, productID); using (CommonDataProvider provider = new CommonDataProvider()) { provider.ExecuteNonQuery(sql); } }
public void DeleteDictionaryItemValue(Guid dictionaryTreeID, Guid entityID, string column) { DictionaryTree tree = DictionaryTrees.SingleOrDefault(d => d.ID == dictionaryTreeID); if (tree != null) { string sql = string.Format("UPDATE {1} SET [{0}] = NULL WHERE [{2}] = '{3}'", column, tree.Dictionary.TableName, tree.PK, entityID); using (CommonDataProvider domain = new CommonDataProvider()) { domain.ExecuteNonQuery(sql); } } }