public int Insert(GovPublicCategoryInfo categoryInfo) { using (var conn = GetConnection()) { conn.Open(); using (var trans = conn.BeginTransaction()) { try { var parentDepartmentInfo = GetCategoryInfo(categoryInfo.ParentID); InsertWithTrans(parentDepartmentInfo, categoryInfo, trans); trans.Commit(); } catch { trans.Rollback(); throw; } } } return(categoryInfo.CategoryID); }
public static GovPublicCategoryTreeItem CreateInstance(GovPublicCategoryInfo categoryInfo, bool enabled) { var item = new GovPublicCategoryTreeItem { _enabled = enabled, _categoryInfo = categoryInfo }; return(item); }
public void Update(GovPublicCategoryInfo categoryInfo) { var updateParms = new IDataParameter[] { GetParameter(ParmCategoryName, EDataType.NVarChar, 255, categoryInfo.CategoryName), GetParameter(ParmCategoryCode, EDataType.VarChar, 50, categoryInfo.CategoryCode), GetParameter(ParmParentsPath, EDataType.NVarChar, 255, categoryInfo.ParentsPath), GetParameter(ParmParentsCount, EDataType.Integer, categoryInfo.ParentsCount), GetParameter(ParmChildrenCount, EDataType.Integer, categoryInfo.ChildrenCount), GetParameter(ParmIsLastNode, EDataType.VarChar, 18, categoryInfo.IsLastNode.ToString()), GetParameter(ParmSummary, EDataType.NVarChar, 255, categoryInfo.Summary), GetParameter(ParmContentNum, EDataType.Integer, categoryInfo.ContentNum), GetParameter(ParmCategoryId, EDataType.Integer, categoryInfo.CategoryID) }; ExecuteNonQuery(SqlUpdate, updateParms); }
public GovPublicCategoryInfo GetCategoryInfo(int categoryId) { GovPublicCategoryInfo categoryInfo = null; var parms = new IDataParameter[] { GetParameter(ParmCategoryId, EDataType.Integer, categoryId) }; using (var rdr = ExecuteReader(SqlSelect, parms)) { if (rdr.Read()) { var i = 0; categoryInfo = new GovPublicCategoryInfo(GetInt(rdr, i++), GetString(rdr, i++), GetInt(rdr, i++), GetString(rdr, i++), GetString(rdr, i++), GetInt(rdr, i++), GetString(rdr, i++), GetInt(rdr, i++), GetInt(rdr, i++), GetBool(rdr, i++), GetInt(rdr, i++), GetDateTime(rdr, i++), GetString(rdr, i++), GetInt(rdr, i)); } rdr.Close(); } return(categoryInfo); }
public override void Submit_OnClick(object sender, EventArgs e) { var isChanged = false; try { if (_categoryId == 0) { var categoryInfo = new GovPublicCategoryInfo(0, _classCode, PublishmentSystemId, CategoryName.Text, CategoryCode.Text, TranslateUtils.ToInt(ParentID.SelectedValue), string.Empty, 0, 0, false, 0, DateTime.Now, Summary.Text, 0); DataProvider.GovPublicCategoryDao.Insert(categoryInfo); } else { var categoryInfo = DataProvider.GovPublicCategoryDao.GetCategoryInfo(_categoryId); categoryInfo.CategoryName = CategoryName.Text; categoryInfo.CategoryCode = CategoryCode.Text; categoryInfo.Summary = Summary.Text; DataProvider.GovPublicCategoryDao.Update(categoryInfo); } Body.AddAdminLog("维护分类信息"); SuccessMessage("分类设置成功!"); isChanged = true; } catch (Exception ex) { FailMessage(ex, "分类设置失败!"); } if (isChanged) { PageUtils.CloseModalPageAndRedirect(Page, _returnUrl); } }
private void InsertWithTrans(GovPublicCategoryInfo parentInfo, GovPublicCategoryInfo categoryInfo, IDbTransaction trans) { if (parentInfo != null) { categoryInfo.ParentsPath = parentInfo.ParentsPath + "," + parentInfo.CategoryID; categoryInfo.ParentsCount = parentInfo.ParentsCount + 1; var maxTaxis = GetMaxTaxisByParentPath(categoryInfo.ClassCode, categoryInfo.PublishmentSystemID, categoryInfo.ParentsPath); if (maxTaxis == 0) { maxTaxis = parentInfo.Taxis; } categoryInfo.Taxis = maxTaxis + 1; } else { categoryInfo.ParentsPath = "0"; categoryInfo.ParentsCount = 0; var maxTaxis = GetMaxTaxisByParentPath(categoryInfo.ClassCode, categoryInfo.PublishmentSystemID, "0"); categoryInfo.Taxis = maxTaxis + 1; } var sqlInsert = "INSERT INTO wcm_GovPublicCategory (ClassCode, PublishmentSystemID, CategoryName, CategoryCode, ParentID, ParentsPath, ParentsCount, ChildrenCount, IsLastNode, Taxis, AddDate, Summary, ContentNum) VALUES (@ClassCode, @PublishmentSystemID, @CategoryName, @CategoryCode, @ParentID, @ParentsPath, @ParentsCount, @ChildrenCount, @IsLastNode, @Taxis, @AddDate, @Summary, @ContentNum)"; var insertParms = new IDataParameter[] { GetParameter(ParmClassCode, EDataType.NVarChar, 50, categoryInfo.ClassCode), GetParameter(ParmPublishmentsystemid, EDataType.Integer, categoryInfo.PublishmentSystemID), GetParameter(ParmCategoryName, EDataType.NVarChar, 255, categoryInfo.CategoryName), GetParameter(ParmCategoryCode, EDataType.VarChar, 50, categoryInfo.CategoryCode), GetParameter(ParmParentId, EDataType.Integer, categoryInfo.ParentID), GetParameter(ParmParentsPath, EDataType.NVarChar, 255, categoryInfo.ParentsPath), GetParameter(ParmParentsCount, EDataType.Integer, categoryInfo.ParentsCount), GetParameter(ParmChildrenCount, EDataType.Integer, 0), GetParameter(ParmIsLastNode, EDataType.VarChar, 18, true.ToString()), GetParameter(ParmTaxis, EDataType.Integer, categoryInfo.Taxis), GetParameter(ParmAddDate, EDataType.DateTime, categoryInfo.AddDate), GetParameter(ParmSummary, EDataType.NVarChar, 255, categoryInfo.Summary), GetParameter(ParmContentNum, EDataType.Integer, categoryInfo.ContentNum) }; string sqlString = $"UPDATE wcm_GovPublicCategory SET {SqlUtils.GetAddOne("Taxis")} WHERE (ClassCode = '{categoryInfo.ClassCode}' AND PublishmentSystemID = {categoryInfo.PublishmentSystemID} AND Taxis >= {categoryInfo.Taxis})"; ExecuteNonQuery(trans, sqlString); categoryInfo.CategoryID = ExecuteNonQueryAndReturnId(trans, sqlInsert, insertParms); if (!string.IsNullOrEmpty(categoryInfo.ParentsPath)) { sqlString = $"UPDATE wcm_GovPublicCategory SET {SqlUtils.GetAddOne("ChildrenCount")} WHERE CategoryID IN ({categoryInfo.ParentsPath})"; ExecuteNonQuery(trans, sqlString); } sqlString = $"UPDATE wcm_GovPublicCategory SET IsLastNode = '{false}' WHERE ParentID = {categoryInfo.ParentID} AND ClassCode = '{categoryInfo.ClassCode}' AND PublishmentSystemID = {categoryInfo.PublishmentSystemID}"; ExecuteNonQuery(trans, sqlString); //sqlString = // $"UPDATE wcm_GovPublicCategory SET IsLastNode = '{true}' WHERE (CategoryID IN (SELECT TOP 1 CategoryID FROM wcm_GovPublicCategory WHERE ParentID = {categoryInfo.ParentID} ORDER BY Taxis DESC))"; sqlString = $"UPDATE wcm_GovPublicCategory SET IsLastNode = '{true}' WHERE (CategoryID IN ({SqlUtils.GetInTopSqlString("wcm_GovPublicCategory", "CategoryID", $"WHERE ParentID = {categoryInfo.ParentID} ORDER BY Taxis DESC", 1)}))"; ExecuteNonQuery(trans, sqlString); }
public static string GetCategoryRowHtml(GovPublicCategoryInfo categoryInfo, bool enabled, EGovPublicCategoryLoadingType loadingType, NameValueCollection additional) { var treeItem = GovPublicCategoryTreeItem.CreateInstance(categoryInfo, enabled); var title = treeItem.GetItemHtml(loadingType); var rowHtml = string.Empty; if (loadingType == EGovPublicCategoryLoadingType.Tree || loadingType == EGovPublicCategoryLoadingType.Select) { rowHtml = $@" <tr treeItemLevel=""{categoryInfo.ParentsCount + 1}""> <td nowrap> {title} </td> </tr> "; } else if (loadingType == EGovPublicCategoryLoadingType.List) { var editUrl = string.Empty; var upLink = string.Empty; var downLink = string.Empty; var checkBoxHtml = string.Empty; if (enabled) { editUrl = $@"<a href=""javascript:;"" onclick=""{ModalGovPublicCategoryAdd.GetOpenWindowStringToEdit( categoryInfo.ClassCode, categoryInfo.PublishmentSystemID, categoryInfo.CategoryID, GetRedirectUrl(categoryInfo.PublishmentSystemID, categoryInfo.ClassCode, categoryInfo.CategoryID))}"">编辑</a>"; var urlUp = PageUtils.GetWcmUrl(nameof(PageGovPublicCategory), new NameValueCollection { { "PublishmentSystemID", categoryInfo.PublishmentSystemID.ToString() }, { "ClassCode", categoryInfo.ClassCode }, { "Subtract", true.ToString() }, { "CategoryID", categoryInfo.CategoryID.ToString() } }); upLink = $@"<a href=""{urlUp}""><img src=""../Pic/icon/up.gif"" border=""0"" alt=""上升"" /></a>"; var urlDown = PageUtils.GetWcmUrl(nameof(PageGovPublicCategory), new NameValueCollection { { "PublishmentSystemID", categoryInfo.PublishmentSystemID.ToString() }, { "ClassCode", categoryInfo.ClassCode }, { "Add", true.ToString() }, { "CategoryID", categoryInfo.CategoryID.ToString() } }); downLink = $@"<a href=""{urlDown}""><img src=""../Pic/icon/down.gif"" border=""0"" alt=""下降"" /></a>"; checkBoxHtml = $"<input type='checkbox' name='CategoryIDCollection' value='{categoryInfo.CategoryID}' />"; } rowHtml = $@" <tr treeItemLevel=""{categoryInfo.ParentsCount + 1}""> <td>{title}</td> <td>{categoryInfo.CategoryCode}</td> <td class=""center"">{upLink}</td> <td class=""center"">{downLink}</td> <td class=""center"">{editUrl}</td> <td class=""center"">{checkBoxHtml}</td> </tr> "; } return(rowHtml); }