protected void btnUpdate_Click(object sender, EventArgs e) { string value = tvSchema.SelectedNode.Value; if (value != "table" && value != "view") { Type type = Type.GetType(value); string dbTypeId = ConfigurationManager.AppSettings["DbType"]; TOP.Common.DbHelper.DbType dbType = (TOP.Common.DbHelper.DbType)short.Parse(dbTypeId); string connString = ConfigurationManager.AppSettings["ConnString"]; string sqlDrop = string.Empty; string sqlCreate = string.Empty; string parent = tvSchema.SelectedNode.Parent.Value; if (parent.Equals("Table", StringComparison.OrdinalIgnoreCase)) { DbSqlCreater dbSqlCreater = DbSqlCreater.GetDbSqlCreater(dbType); sqlDrop = dbSqlCreater.GenerateDropTableSql(type); sqlCreate = dbSqlCreater.GenerateCreateTableSql(type); } else if (parent.Equals("View", StringComparison.OrdinalIgnoreCase)) { string baseDir = Server.MapPath("~"); baseDir += @"\..\..\Database\Scripts"; DbQuery dbQuery = DbQuery.GetDbQuery(dbType); sqlDrop = dbQuery.GenerateDropViewSql(type, baseDir); sqlCreate = dbQuery.GenerateCreateViewSql(type, baseDir); } else { throw new ArgumentException("不能更新的类型 - " + parent + " - " + value); } using (DbOperator dbOperator = new DbOperator(connString)) { try { dbOperator.BeginTran(); dbOperator.ExecSql(sqlDrop); dbOperator.ExecSql(sqlCreate); dbOperator.CommintTran(); lblMessage.Text = "更新成功 - " + parent + " - " + value; } catch { dbOperator.RollbackTran(); throw new Exception("更新数据库对象错误 - " + parent + " - " + value); } } } else { lblMessage.Text = "所选择对象无效,请选择要更新的数据库对象。"; } }
public string CreateTemplate(string name, string content, string userId) { string id = Guid.NewGuid().ToString(); TOP.Template.Domain.Template template = new TOP.Template.Domain.Template(); template.Name = name; template.Content = content; template.CreateUserId = userId; template.LastUpdateUserId = userId; #region 执行SQL以创建对象 TemplateManager manager = new TemplateManager(); string sqlCreate = manager.GetCreateSql(template); using (DbOperator dbOperator = new DbOperator(ConnString)) { try { dbOperator.BeginTran(); dbOperator.ExecSql(sqlCreate); dbOperator.CommintTran(); return id; } catch (Exception ex) { dbOperator.RollbackTran(); throw new FacadeException("创建模板发生异常 - ", ex); } } #endregion }
public void DeleteItemCategoryByParentId(string categoryId) { ItemCategory category = new ItemCategory(); ItemCategoryManager manager = new ItemCategoryManager(); string sqlDelete = manager.GetDeleteSql(category); sqlDelete += string.Format("WHERE [ParentId] = N'{0}'", categoryId); using (DbOperator dbOperator = new DbOperator(ConnString)) { dbOperator.ExecSql(sqlDelete); } }
public void DbInitialize() { string sqlDropTable = dbSqlCreater.GenerateDropTableSql(typeof(Area)); string sqlCreateTable = dbSqlCreater.GenerateCreateTableSql(typeof(Area)); using (DbOperator dbOperator = new DbOperator(connString)) { try { dbOperator.BeginTran(); dbOperator.ExecSql(sqlDropTable); dbOperator.ExecSql(sqlCreateTable); dbOperator.CommintTran(); } catch (Exception ex) { dbOperator.RollbackTran(); Assert.Fail("初始化数据库错误 - " + ex.Message); } } }
public string AddArea(string id, string areaId, string areaTypeId, string areaName, string parentId, string zip, string createUserId) { #region 构造要新增的对象 if (string.IsNullOrEmpty(id) || id == Guid.Empty.ToString()) { id = Guid.NewGuid().ToString(); } Area area = new Area(); area.Id = id; area.AreaId = areaId; area.AreaTypeId = areaTypeId; area.AreaName = areaName; area.ParentId = parentId; area.Zip = zip; area.CreateDate = DateTime.Now; area.CreateUserId = createUserId; area.LastUpdateDate = DateTime.Now; area.LastUpdateUserId = createUserId; #endregion #region 执行SQL以创建对象 AreaManager manager = new AreaManager(); string sqlCreate = manager.GetCreateSql(area); using (DbOperator dbOperator = new DbOperator(ConnString)) { try { dbOperator.BeginTran(); dbOperator.ExecSql(sqlCreate); dbOperator.CommintTran(); return id; } catch (Exception ex) { dbOperator.RollbackTran(); throw new FacadeException("新增区域发生异常 - ", ex); } } #endregion }
public void AddImportGroup(string groupId, string operatorUserId, string operatorUserName, int totalCount , string fromNick, string fromTitle, string fromImageUrl, string toNick, string toTitle , ImportorEnumerations.ImportType importType, string userId) { ImportGroup groupEntity = new ImportGroup(); groupEntity.Id = groupId; groupEntity.OperatorUserId = operatorUserId; groupEntity.OperatorUserName = operatorUserName; groupEntity.TotalCount = totalCount; groupEntity.SuccessCount = 0; groupEntity.FailCount = 0; groupEntity.ImportFormSellerNick = fromNick; groupEntity.ImportFormShopTitle = fromTitle; groupEntity.ImportFormShopImageUrl = fromImageUrl; groupEntity.ImportToSellerNick = toNick; groupEntity.ImportToShopTitle = toTitle; groupEntity.ImportType = importType; groupEntity.ImportState = ImportorEnumerations.ImportState.Waitting; groupEntity.ImportResult = ImportorEnumerations.ImportGroupResult.Pending; groupEntity.ListDateTime = DateTime.Now; groupEntity.StartDateTime = null; groupEntity.FinishDateTime = null; groupEntity.CreateDate = DateTime.Now; groupEntity.CreateUserId = userId; groupEntity.LastUpdateDate = DateTime.Now; groupEntity.LastUpdateUserId = userId; ImportGroupManager groupManager = new ImportGroupManager(); string sqlCreateGroup = groupManager.GetCreateSql(groupEntity); using (DbOperator dbOperator = new DbOperator(ConnString)) { try { dbOperator.BeginTran(); dbOperator.ExecSql(sqlCreateGroup); dbOperator.CommintTran(); } catch (Exception ex) { dbOperator.RollbackTran(); throw new FacadeException("添加导入组发生异常 - ", ex); } } }
public string AddItemCategory(string id, string categoryId, string parentId, string name, bool isParent, string status, int sortOrder) { #region 构造要新增的对象 if (string.IsNullOrEmpty(id) || id == Guid.Empty.ToString()) { id = Guid.NewGuid().ToString(); } ItemCategory category = new ItemCategory(); category.Id = id; category.CategoryId = categoryId; category.ParentId = parentId; category.Name = name; category.IsParent = isParent; category.Status = status; category.SortOrder = sortOrder; #endregion #region 执行SQL以创建对象 ItemCategoryManager manager = new ItemCategoryManager(); string sqlCreate = manager.GetCreateSql(category); using (DbOperator dbOperator = new DbOperator(ConnString)) { try { dbOperator.BeginTran(); dbOperator.ExecSql(sqlCreate); dbOperator.CommintTran(); return id; } catch (Exception ex) { dbOperator.RollbackTran(); throw new FacadeException("新增类目发生异常 - ", ex); } } #endregion }
/// <summary> /// 注册新用户。返回用户Id。 /// </summary> /// <param name="id"></param> /// <param name="loginName">登录名</param> /// <param name="password">加密后的密码</param> /// <param name="userName">用户名</param> /// <returns></returns> public string Register(string id, string loginName, string password, string userName) { #region 构造要新增的对象 if (string.IsNullOrEmpty(id) || id == Guid.Empty.ToString()) { id = Guid.NewGuid().ToString(); } User _user = new User(); _user.Id = id; _user.LoginName = loginName; _user.Password = password; _user.UserName = userName; #endregion #region 执行SQL以创建对象 UserManager manager = new UserManager(); string sqlCreate = manager.GetCreateSql(_user); using (DbOperator dbOperator = new DbOperator(ConnString)) { try { dbOperator.BeginTran(); dbOperator.ExecSql(sqlCreate); dbOperator.CommintTran(); return id; } catch (Exception ex) { dbOperator.RollbackTran(); throw new FacadeException("注册用户发生异常 - ", ex); } } #endregion }
public void UpdateArea(string areaId, string areaTypeId, string areaName, string parentId, string zip, string updateUserId) { #region 构造要修改的对象 Area area = new Area(); area.AreaTypeId = areaTypeId; area.AreaName = areaName; area.ParentId = parentId; area.Zip = zip; area.LastUpdateDate = DateTime.Now; area.LastUpdateUserId = updateUserId; #endregion #region 执行SQL以修改对象 AreaManager manager = new AreaManager(); string sqlUpdate = manager.GetUpdateSql(area); sqlUpdate += string.Format("WHERE [AreaId] = N'{0}'", areaTypeId); using (DbOperator dbOperator = new DbOperator(ConnString)) { try { dbOperator.BeginTran(); dbOperator.ExecSql(sqlUpdate); dbOperator.CommintTran(); } catch (Exception ex) { dbOperator.RollbackTran(); throw new FacadeException("修改区域发生异常 - ", ex); } } #endregion }
public void TestIsItemCategoryExist_已经存在的情况() { #region 验证前置条件 ItemCategory category = new ItemCategory(); category.Id = "c2ecf0ef-dc5b-4308-9f38-047453d53919"; category.CategoryId = "50011665"; ItemCategoryManager manager = new ItemCategoryManager(); string sqlCreate = manager.GetCreateSql(category); using (DbOperator dbOperator = new DbOperator(connString)) { dbOperator.ExecSql(sqlCreate); } #endregion ItemCategoryFacade facade = new ItemCategoryFacade(); bool isExist = facade.IsItemCategoryExist("50011665"); Assert.AreEqual(true, isExist); }
public void TestGetItemCategory_已经存在的情况() { #region 验证前置条件 ItemCategory category = new ItemCategory(); category.Id = "c2ecf0ef-dc5b-4308-9f38-047453d53919"; category.CategoryId = "50011665"; category.Name = "测试类目"; category.ParentId = "0"; category.IsParent = true; category.SortOrder = 1; category.Status = "normal"; ItemCategoryManager manager = new ItemCategoryManager(); string sqlCreate = manager.GetCreateSql(category); using (DbOperator dbOperator = new DbOperator(connString)) { dbOperator.ExecSql(sqlCreate); } #endregion ItemCategoryFacade facade = new ItemCategoryFacade(); ItemCategoryInfo categoryInfo = facade.GetItemCategoryById("50011665"); #region 验证后置条件 Assert.IsNotNull(categoryInfo); Assert.AreEqual("c2ecf0ef-dc5b-4308-9f38-047453d53919", categoryInfo.Id); Assert.AreEqual("50011665", categoryInfo.CategoryId); Assert.AreEqual("测试类目", categoryInfo.Name); Assert.AreEqual("0", categoryInfo.ParentId); Assert.AreEqual(true, categoryInfo.IsParent); Assert.AreEqual(1, categoryInfo.SortOrder); Assert.AreEqual("normal", categoryInfo.Status); #endregion }
public void TestGetItemCategoryListByParent_有一条根数据() { #region 验证前置条件 ItemCategory category = new ItemCategory(); category.Id = "c2ecf0ef-dc5b-4308-9f38-047453d53919"; category.CategoryId = "50011665"; category.Name = "测试类目"; category.ParentId = "0"; category.IsParent = true; category.SortOrder = 1; category.Status = "normal"; ItemCategoryManager manager = new ItemCategoryManager(); string sqlCreate = manager.GetCreateSql(category); using (DbOperator dbOperator = new DbOperator(connString)) { dbOperator.ExecSql(sqlCreate); } #endregion ItemCategoryFacade facade = new ItemCategoryFacade(); List<ItemCategoryInfo> list = facade.GetItemCategoryListByParent(string.Empty); #region 验证后置条件 Assert.AreEqual(1, list.Count); Assert.AreEqual("c2ecf0ef-dc5b-4308-9f38-047453d53919", list[0].Id); Assert.AreEqual("50011665", list[0].CategoryId); Assert.AreEqual("测试类目", list[0].Name); Assert.AreEqual("0", list[0].ParentId); Assert.AreEqual(true, list[0].IsParent); Assert.AreEqual(1, list[0].SortOrder); Assert.AreEqual("normal", list[0].Status); #endregion }
public void AddImportItem(string itemId, string groupId, string operatorUserId, string operatorUserName , string fromItemIid, string fromItemTitle, string fromItemPrice, string fromSellerNick, string fromShopTitle, string userId) { ImportItem itemEntity = new ImportItem(); itemEntity.Id = itemId; itemEntity.OperatorUserId = operatorUserId; itemEntity.OperatorUserName = operatorUserName; itemEntity.ItsImportGroupId = groupId; itemEntity.ImportFormItemIid = fromItemIid; itemEntity.ImportFormItemTitle = fromItemTitle; itemEntity.ImportFormItemPrice = fromItemPrice; itemEntity.ImportFormSellerNick = fromSellerNick; itemEntity.ImportFormShopTitle = fromShopTitle; itemEntity.ImportState = ImportorEnumerations.ImportState.Waitting; itemEntity.ImportResult = ImportorEnumerations.ImportItemResult.Pending; itemEntity.ListDateTime = DateTime.Now; itemEntity.StartDateTime = null; itemEntity.FinishDateTime = null; itemEntity.CreateDate = DateTime.Now; itemEntity.CreateUserId = userId; itemEntity.LastUpdateDate = DateTime.Now; itemEntity.LastUpdateUserId = userId; ImportItemManager itemManager = new ImportItemManager(); string sqlCreateItem = itemManager.GetCreateSql(itemEntity); using (DbOperator dbOperator = new DbOperator(ConnString)) { try { dbOperator.BeginTran(); dbOperator.ExecSql(sqlCreateItem); dbOperator.CommintTran(); } catch (Exception ex) { dbOperator.RollbackTran(); throw new FacadeException("添加导入项发生异常 - ", ex); } } }
public void StartImportItem(string itemId, int version, string userId) { ImportItem itemEntity = new ImportItem(); itemEntity.Id = itemId; itemEntity.ImportState = ImportorEnumerations.ImportState.Importing; itemEntity.StartDateTime = DateTime.Now; itemEntity.LastUpdateDate = DateTime.Now; itemEntity.LastUpdateUserId = userId; itemEntity.CurrentVersion = version; ImportItemManager manager = new ImportItemManager(); string sqlUpdateItem = manager.GetUpdateSql(itemEntity, "ImportState", "StartDateTime"); #region 执行SQL以修改对象 using (DbOperator dbOperator = new DbOperator(ConnString)) { try { dbOperator.BeginTran(); dbOperator.ExecSql(sqlUpdateItem); dbOperator.CommintTran(); } catch (Exception ex) { dbOperator.RollbackTran(); throw new FacadeException("启动导入宝贝发生异常 - ", ex); } } #endregion }
public void StartImport(string groupId, int version, string userId) { ImportGroup groupEntity = new ImportGroup(); groupEntity.Id = groupId; groupEntity.ImportState = ImportorEnumerations.ImportState.Importing; groupEntity.LastUpdateDate = DateTime.Now; groupEntity.LastUpdateUserId = userId; groupEntity.CurrentVersion = version; #region 执行SQL以修改对象 ImportGroupManager manager = new ImportGroupManager(); string sqlUpdate = manager.GetUpdateSql(groupEntity, "ImportState"); using (DbOperator dbOperator = new DbOperator(ConnString)) { try { dbOperator.BeginTran(); dbOperator.ExecSql(sqlUpdate); dbOperator.CommintTran(); } catch (Exception ex) { dbOperator.RollbackTran(); throw new FacadeException("启动导入过程发生异常 - ", ex); } } #endregion }
public void TestGetItemCategoryListByParent_父子数据情况() { #region 验证前置条件 ItemCategory category1 = new ItemCategory(); category1.Id = "c2ecf0ef-dc5b-4308-9f38-047453d53919"; category1.CategoryId = "50011665"; category1.Name = "测试类目1"; category1.ParentId = "0"; category1.IsParent = true; category1.SortOrder = 1; category1.Status = "normal"; ItemCategory category2 = new ItemCategory(); category2.Id = "c2ecf0ef-dc5b-4308-9f38-047453d53929"; category2.CategoryId = "50011667"; category2.Name = "测试类目2"; category2.ParentId = "50011665"; category2.IsParent = true; category2.SortOrder = 0; category2.Status = "deleted"; ItemCategoryManager manager = new ItemCategoryManager(); string sqlCreate1 = manager.GetCreateSql(category1); string sqlCreate2 = manager.GetCreateSql(category2); using (DbOperator dbOperator = new DbOperator(connString)) { dbOperator.ExecSql(sqlCreate1); dbOperator.ExecSql(sqlCreate2); } #endregion ItemCategoryFacade facade = new ItemCategoryFacade(); #region 验证后置条件 List<ItemCategoryInfo> list1 = facade.GetItemCategoryListByParent(string.Empty); Assert.AreEqual(1, list1.Count); ItemCategoryInfo categoryInfo1 = list1[0]; Assert.AreEqual("c2ecf0ef-dc5b-4308-9f38-047453d53919", categoryInfo1.Id); Assert.AreEqual("50011665", categoryInfo1.CategoryId); Assert.AreEqual("测试类目1", categoryInfo1.Name); Assert.AreEqual("0", categoryInfo1.ParentId); Assert.AreEqual(true, categoryInfo1.IsParent); Assert.AreEqual(1, categoryInfo1.SortOrder); Assert.AreEqual("normal", categoryInfo1.Status); List<ItemCategoryInfo> list2 = facade.GetItemCategoryListByParent("50011665"); ItemCategoryInfo categoryInfo2 = list2[0]; Assert.AreEqual("c2ecf0ef-dc5b-4308-9f38-047453d53929", categoryInfo2.Id); Assert.AreEqual("50011667", categoryInfo2.CategoryId); Assert.AreEqual("测试类目2", categoryInfo2.Name); Assert.AreEqual("50011665", categoryInfo2.ParentId); Assert.AreEqual(true, categoryInfo2.IsParent); Assert.AreEqual(0, categoryInfo2.SortOrder); Assert.AreEqual("deleted", categoryInfo2.Status); #endregion }
public void FinishImportItem(string groupId, int groupVersion, string itemId, int itemVersion , ImportorEnumerations.ImportItemResult result , string toItemIid, string toItemTitle, string toItemPrice, string toSellerNick, string toShopTitle , int successCount, int failCount, string message, string userId) { ImportGroup groupEntity = new ImportGroup(); groupEntity.Id = groupId; groupEntity.SuccessCount = successCount; groupEntity.FailCount = failCount; groupEntity.LastUpdateDate = DateTime.Now; groupEntity.LastUpdateUserId = userId; groupEntity.CurrentVersion = groupVersion; ImportGroupManager managerGroup = new ImportGroupManager(); string sqlUpdateGroup = managerGroup.GetUpdateSql(groupEntity, "SuccessCount", "FailCount"); ImportItem itemEntity = new ImportItem(); itemEntity.Id = itemId; itemEntity.ImportState = ImportorEnumerations.ImportState.Finished; itemEntity.ImportResult = result; itemEntity.FinishDateTime = DateTime.Now; itemEntity.ImportToItemIid = toItemIid; itemEntity.ImportToItemTitle = toItemTitle; itemEntity.ImportToItemPrice = toItemPrice; itemEntity.ImportToSellerNick = toSellerNick; itemEntity.ImportToShopTitle = toShopTitle; itemEntity.ResultMessage = message; itemEntity.LastUpdateDate = DateTime.Now; itemEntity.LastUpdateUserId = userId; itemEntity.CurrentVersion = itemVersion; ImportItemManager managerItem = new ImportItemManager(); string sqlUpdateItem = managerItem.GetUpdateSql(itemEntity , "ImportState" , "ImportResult" , "FinishDateTime" , "ImportToItemIid" , "ImportToItemTitle" , "ImportToItemPrice" , "ImportToSellerNick" , "ImportToShopTitle" , "ResultMessage"); #region 执行SQL以修改对象 using (DbOperator dbOperator = new DbOperator(ConnString)) { try { dbOperator.BeginTran(); dbOperator.ExecSql(sqlUpdateGroup); dbOperator.ExecSql(sqlUpdateItem); dbOperator.CommintTran(); } catch (Exception ex) { dbOperator.RollbackTran(); throw new FacadeException("结束导入宝贝发生异常 - ", ex); } } #endregion }