/// <summary> /// 删除数据 /// 作者:董帅 创建时间:2012-8-28 22:17:10 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void butDeleteItems_Click(object sender, EventArgs e) { try { string s = Request["chkDic"]; string[] dicIds = new string[0]; if (!string.IsNullOrEmpty(s)) { dicIds = s.Split(','); //要删除的字典id } if (dicIds.Length > 0) { //获取配置文件路径。 string configFile = AppDomain.CurrentDomain.BaseDirectory.ToString() + SystemConfig.databaseConfigFileName; //创建数据库操作对象。 DataDicOperater dicOper = DataDicOperater.createDataDicOperater(configFile, SystemConfig.databaseConfigNodeName, SystemConfig.configFileKey); if (dicOper != null) { //删除字典项 int[] dicIntIds = new int[dicIds.Length]; for (int i = 0; i < dicIds.Length; i++) { dicIntIds[i] = Convert.ToInt32(dicIds[i]); } if (dicOper.deleteDataDictionarys(dicIntIds)) { this.Response.Redirect("dataDictionary_list.aspx?parentId=" + this.hidParentId.Value); //YMessageBox.showAndResponseScript(this, "删除数据成功!", "", "window.location.href='dataDictionary_list.aspx?parentId=" + this.hidParentId.Value + "'"); } else { YMessageBox.show(this, "删除数据失败!错误信息[" + dicOper.errorMessage + "]"); } } else { YMessageBox.show(this, "获取数据库实例失败!"); } } else { YMessageBox.show(this, "没有选择要删除的字典!"); } } catch (Exception ex) { YMessageBox.show(this, "系统运行异常!异常信息[" + ex.Message + "]"); } }
protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { //获取父id string parentId = Request.QueryString["parentId"]; if (!string.IsNullOrEmpty(parentId)) { this.hidParentId.Value = parentId; } else { this.hidParentId.Value = "-1"; } //获取id string strId = Request.QueryString["id"]; if (!string.IsNullOrEmpty(strId)) { this.hidDicId.Value = strId; //获取配置文件路径。 string configFile = AppDomain.CurrentDomain.BaseDirectory.ToString() + SystemConfig.databaseConfigFileName; //创建操作对象 DataDicOperater dicOper = DataDicOperater.createDataDicOperater(configFile, SystemConfig.databaseConfigNodeName, SystemConfig.configFileKey); if (dicOper != null) { ////获取字典项信息 DataDictionaryInfo dicInfo = dicOper.getDataDictionary(Convert.ToInt32(strId)); if (dicInfo != null) { this.txtDicName.Value = dicInfo.name; this.txtDicValue.Value = dicInfo.value.ToString(); this.txtDicCode.Value = dicInfo.code; this.txtDicOrder.Value = dicInfo.order.ToString(); } else { YMessageBox.show(this, "获取字典信息失败!错误信息[" + dicOper.errorMessage + "]"); return; } } else { YMessageBox.show(this, "创建数据库操作对象失败!"); return; } } } }
/// <summary> /// 绑定字典项。 /// 作者:董帅 创建时间:2012-8-28 21:46:08 /// </summary> public void bindDicInfos() { try { //获取配置文件路径。 string configFile = AppDomain.CurrentDomain.BaseDirectory.ToString() + SystemConfig.databaseConfigFileName; //获取数据库操作对象 DataDicOperater dicOper = DataDicOperater.createDataDicOperater(configFile, SystemConfig.databaseConfigNodeName, SystemConfig.configFileKey); if (dicOper != null) { //获取父字典项 if (this.hidParentId.Value == "-1") { this.spanParentName.InnerText = "顶级字典"; this.returnButton.Disabled = true; this.hidReturnId.Value = ""; } else { DataDictionaryInfo org = dicOper.getDataDictionary(Convert.ToInt32(this.hidParentId.Value)); this.spanParentName.InnerText = org.name; this.hidReturnId.Value = org.parentId.ToString(); } //获取组织机构列表 List <DataDictionaryInfo> dics = dicOper.getDataDictionaryByParentId(Convert.ToInt32(this.hidParentId.Value)); if (dics != null) { this.dicList.DataSource = dics; this.dicList.DataBind(); } else { YMessageBox.show(this, "获取字典数据失败!错误信息[" + dicOper.errorMessage + "]"); } } else { YMessageBox.show(this, "获取数据库操作对象失败!"); } } catch (Exception ex) { YMessageBox.show(this, "运行错误!错误信息[" + ex.Message + "]"); } }
/// <summary> /// 保存数据。 /// 作者:董帅 创建时间:2012-8-28 17:28:54 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void butSave_Click(object sender, EventArgs e) { try { DataDictionaryInfo dataDicInfo = new DataDictionaryInfo(); dataDicInfo.name = this.txtDicName.Value; if (string.IsNullOrEmpty(dataDicInfo.name) || dataDicInfo.name.Length > 20) { YMessageBox.show(this, "名称不合法!"); return; } dataDicInfo.value = Convert.ToInt32(this.txtDicValue.Value); dataDicInfo.code = this.txtDicCode.Value; dataDicInfo.order = Convert.ToInt32(this.txtDicOrder.Value); dataDicInfo.parentId = Convert.ToInt32(this.hidParentId.Value); //获取配置文件路径。 string configFile = AppDomain.CurrentDomain.BaseDirectory.ToString() + SystemConfig.databaseConfigFileName; //创建操作对象 DataDicOperater dataDicOper = DataDicOperater.createDataDicOperater(configFile, SystemConfig.databaseConfigNodeName, SystemConfig.configFileKey); if (dataDicOper != null) { if (string.IsNullOrEmpty(this.hidDicId.Value)) { //新增 if (dataDicOper.createNewDataDictionary(dataDicInfo) > 0) { YMessageBox.showAndResponseScript(this, "保存成功!", "", "window.parent.menuButtonOnClick('数据字典','icon-dictionary','sys/dataDictionary/dataDictionary_list.aspx?parentId=" + this.hidParentId.Value + "');window.parent.closePopupsWindow('#popups');"); } else { YMessageBox.show(this, "创建机构失败!错误信息:[" + dataDicOper.errorMessage + "]"); return; } } else { //修改 dataDicInfo.id = Convert.ToInt32(this.hidDicId.Value); if (dataDicOper.changeDataDictionary(dataDicInfo)) { YMessageBox.showAndResponseScript(this, "保存成功!", "", "window.parent.menuButtonOnClick('数据字典','icon-dictionary','sys/dataDictionary/dataDictionary_list.aspx?parentId=" + this.hidParentId.Value + "');window.parent.closePopupsWindow('#popups');"); } else { YMessageBox.show(this, "修改字典项失败!错误信息:[" + dataDicOper.errorMessage + "]"); return; } } } else { YMessageBox.show(this, "创建数据库操作对象失败!"); return; } } catch (Exception ex) { YMessageBox.show(this, "程序异常!错误信息[" + ex.Message + "]"); } }