/// <summary> /// 初始化所有字典数据,进行数据缓存 /// </summary> private void init() { OleDbDataReader rst = null; try { m_htb_Dic = new Hashtable(); /// 首先查询出所有字典的名称 string str_SQL = Common.SELECT + Field.DICNAME + Common.S_FROM + Table.DICLIST; if (CommonQuery.qryRst(str_SQL, ref rst) == "0") { while (rst.Read()) { refresh(rst[Field.DICNAME].ToString()); } } rst.Close(); /// 载入系统特殊字典 refresh(Table.MANAGEUNIT); refresh(Table.AFFAIRTYPE); refresh(Table.EVENTTYPE); refresh(Table.USERLIST); } catch (Exception e) { } finally { } }
public static string ExpExcel(string path) { ReturnDoc obj_ReturnDoc = new ReturnDoc(); try { Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbooks workbooks = xlApp.Workbooks; Microsoft.Office.Interop.Excel.Workbook workbook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet); Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[1];//取得sheet1 worksheet.Cells[1, 1] = "管道名称"; // 数据查询 OleDbDataReader rst = null; string ret = CommonQuery.qryRst("select * from PIPELINE", ref rst); Int16 i = 2; DicCache dic = DicCache.getInstance(); if (ret.Equals("0")) { while (rst.Read()) { worksheet.Cells[i, 1] = rst["DATA1"].ToString(); i++; } rst.Close(); } string sPath = path; string filename = "海底管道数据导出.xls"; workbook.Saved = true; workbook.SaveCopyAs(sPath + filename); xlApp.Quit(); obj_ReturnDoc.addErrorResult(Common.RT_SUCCESS); obj_ReturnDoc.setFuncErrorInfo(filename); } catch (Exception e) { obj_ReturnDoc.addErrorResult(Common.RT_FUNCERROR); obj_ReturnDoc.setFuncErrorInfo(e.Message); } return(obj_ReturnDoc.getXml()); }
/// <summary> /// 初始化所有的汉字拼音 /// </summary> private void init() { OleDbDataReader rst = null; try { // 查询出拼音内容 string str_SQL = Common.SELECT + Field.WORD + Common.COMMA + Field.SPELL + Common.COMMA + Field.ASPELL + Common.S_FROM + Table.SPELL + Common.S_ORDER + Field.WORD; // 查询 string strRet = CommonQuery.qryRst(str_SQL, ref rst); // 初始化 arr_Spell ht_Spell = new Hashtable(); while (rst.Read()) { string chr_Word = rst[Field.WORD].ToString(); string chr_Spell = rst[Field.SPELL].ToString(); string str_ASpell = rst[Field.ASPELL].ToString(); ArrayList arr_Spell = new ArrayList(); arr_Spell.Add(new string[] { chr_Word, chr_Spell, str_ASpell }); ht_Spell.Add(chr_Word, arr_Spell); } rst.Close(); General.TracePrint("缓存中已载入" + ht_Spell.Count + "个拼音"); } catch (Exception e) { throw e; } }
/// <summary> /// 根据表结构需要动态创建字典 /// </summary> /// <param name="dicname">字典名称</param> /// <param name="sql">查询sql语句 /// (如:select gid,gname from gtable order by gid) /// select语句只需要查询出编码和描述就可以了 /// </param> public void createDicFile(string dicname, string sql) { OleDbDataReader rst = null; int rs_open = 0; if (CommonQuery.qryRst(sql, ref rst) == "0") { rs_open = 1; SpellCache spellcache = SpellCache.getInstance(); string strXML = Common.XML_HEADINFO + "<data/>"; XmlDocument doc = new XmlDocument(); doc.LoadXml(strXML); while (rst.Read()) { string str_DicCode = rst[0].ToString(); string str_DicText = rst[1].ToString(); // 从拼音缓存中做拼音翻译 string spell = spellcache.getSpell(str_DicText); string aspell = spellcache.getASpell(str_DicText); XmlElement el = doc.CreateElement("row"); doc.DocumentElement.AppendChild(el); el.SetAttribute(Field.DIC_CODE, str_DicCode); el.SetAttribute(Field.DIC_TEXT, str_DicText); el.SetAttribute(Field.DIC_SPELL, spell); el.SetAttribute(Field.DIC_ASPELL, aspell); el = null; } string sPath = getDicPath() + "\\" + dicname + ".xml"; doc.Save(sPath); } if (rs_open == 1) { rst.Close(); } }
public string getUserRightsByUserID() { /// 查询出该用户的权限信息 string str_SQL = Common.SELECT + Common.DISTINCT + Common.ALL + Common.S_FROM + Table.VW_USERRIGHTTREE + Common.S_WHERE + Field.USERID + Common.EQUAL + General.addQuotes(this.getUserID()) + Common.S_ORDER + Field.AFFAIRTYPEID + Common.COMMA + Field.EVENTTYPEID; OleDbDataReader rst_UserRight = null; try { string strRet = CommonQuery.qryRst(str_SQL, ref rst_UserRight); if (strRet != "0") { throw new Exception("获得用户权限失败"); } string str_PreAffairTypeID = ""; string str_PreEventTypeID = ""; ReturnDoc doc_RightTree = new ReturnDoc(); XmlDocument doc_tmp = doc_RightTree.getDocument(); XmlElement ele_Root = null; XmlElement ele_Query = null; XmlElement ele_AffairType = null; /// 对结果集进行遍历,用来生成功能树 while (rst_UserRight.Read()) { /// 创建查询返回节点 if (!doc_RightTree.createQueryInfoNode()) { throw new Exception("UserCache.setUserRightsByUserID.创建查询返回节点时发生错误"); } /// if (!doc_RightTree.createQueryInfoNode()) ele_Root = ele_Root == null ? (XmlElement)doc_RightTree.getQueryInfoNode() : ele_Root; string str_AffairTypeID = rst_UserRight[Field.AFFAIRTYPEID].ToString(); string str_AffairTypeName = rst_UserRight[Field.AFFAIRTYPENAME].ToString(); string str_EventTypeID = rst_UserRight[Field.EVENTTYPEID].ToString(); string str_EventTypeName = rst_UserRight[Field.EVENTTYPENAME].ToString(); string str_OpURL = rst_UserRight[Field.OPURL].ToString(); int int_AffairTypeID = Convert.ToInt32(str_AffairTypeID); XmlElement ele_EventType = null; /// 查询事务 if (int_AffairTypeID == 4) { ele_AffairType = doc_tmp.CreateElement(Common.XDOC_OPERATION); ele_AffairType.SetAttribute(Common.XML_PROP_AFFAIRTYPEID, str_AffairTypeID); ele_AffairType.SetAttribute(Common.XML_PROP_NAME, str_AffairTypeName); ele_Query = ele_AffairType; ele_Root.AppendChild(ele_AffairType); } /// if (int_AffairTypeID==4) else { if (!str_PreAffairTypeID.EndsWith(str_AffairTypeID)) { ele_AffairType = doc_tmp.CreateElement(Table.AFFAIRTYPE); ele_AffairType.SetAttribute(Common.XML_PROP_AFFAIRTYPEID, str_AffairTypeID); ele_AffairType.SetAttribute(Common.XML_PROP_TEXT, str_AffairTypeName); str_PreAffairTypeID = str_AffairTypeID; ele_Root.AppendChild(ele_AffairType); } } /// 相同的事件类型,则不用重复创建 if (!str_PreEventTypeID.Equals(str_EventTypeID)) { ele_EventType = doc_tmp.CreateElement(Table.EVENTTYPE); ele_EventType.SetAttribute(Common.XML_PROP_EVENTTYPEID, str_EventTypeID); ele_EventType.SetAttribute(Common.XML_PROP_TEXT, str_EventTypeName); ele_EventType.SetAttribute(Common.XML_PROP_OPURL, str_OpURL); ele_AffairType.AppendChild(ele_EventType); str_PreEventTypeID = str_EventTypeID; } /// if (!str_PreEventTypeID.equals(str_EventTypeID)) } /// while (rst_UserRight.next()) /// 将查询事务节点,追加到权限功能树的最后 if (ele_Query != null) { XmlElement ele_TempQuery = (XmlElement)ele_Query.Clone(); XmlElement ele_QueryInfo = (XmlElement)doc_RightTree.getQueryInfoNode(); ele_QueryInfo.RemoveChild(ele_Query); ele_QueryInfo.AppendChild(ele_TempQuery); } /// if (ele_Query!=null) if (!doc_RightTree.addErrorResult(Common.RT_QUERY_SUCCESS)) { throw new Exception("添加函数返回结果失败"); } /// if (!doc_RightTree.addErrorResult(Common.RT_QUERY_SUCCESS)) return(doc_RightTree.getXml()); } catch (Exception e) { return(e.Message); } finally { rst_UserRight.Close(); } }
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { try{ string strXml = Request["txtXML"]; // strXml = XmlFun.addXDocHead(strXml); XmlDocument doc = XmlFun.CreateNewDoc(strXml); string strUsertitle = XmlFun.getNodeValue(doc, Common.BAR2 + Common.XDOC_LOGININFO + Common.BAR + Field.USERTITLE); string strPassWord = XmlFun.getNodeValue(doc, Common.BAR2 + Common.XDOC_LOGININFO + Common.BAR + Field.USERPASSWORD); string strIP = XmlFun.getNodeValue(doc, Common.BAR2 + Common.XDOC_LOGININFO + Common.BAR + Field.LOGINIP); string strMac = XmlFun.getNodeValue(doc, Common.BAR2 + Common.XDOC_LOGININFO + Common.BAR + Field.MAC); string str_SQL = "SELECT * FROM VW_USERLIST WHERE USERTITLE='" + strUsertitle + "'"; string strErr = ""; ReturnDoc Rtdoc = new ReturnDoc(); OleDbDataReader rst = null; string strRet = CommonQuery.qryRst(str_SQL, ref rst); if (strRet == "0") { Rtdoc.getQueryInfo(rst); if (strPassWord != Rtdoc.getNodeValue(Common.BAR2 + Field.USERPASSWORD)) { strErr = "密码错误"; } } else { strErr = "查询用户信息为空"; } rst.Close(); if (strErr == "") { UserSession user = new UserSession(Rtdoc.getXml()); string[] arrSys = { user.getUserID(), user.getUserTitle(), user.getUserName(), "", user.getUnitID(), user.getUnitName(), strIP, strMac }; string logid = SystemLog.addSysLog(arrSys); user.setLogID(logid); Session.Add("RoleUser", user); Response.Redirect("Login.aspx"); Response.End(); } else { Response.Write("<script language=\"javascript\">"); Response.Write("alert('" + strErr + "');"); Response.Write("history.back();"); Response.Write("</script>"); } } catch (Exception ex) { } } }
/// <summary> /// 对单个量表进行数据缓存,放入hastable中 /// </summary> /// <param name="strDicName">字典名称</param> public void refresh(String strDicName) { /// 组织查询字典的 SQL 语句 string str_SQL = ""; /// 对系统特殊字典进行处理 if (strDicName.Equals(Table.MANAGEUNIT)) { str_SQL = Common.SELECT + Field.MUNITID + Common.SPACE + Field.DIC_CODE + Common.COMMA + Field.MUNITNAME + Common.SPACE + Field.DIC_TEXT + Common.COMMA + Field.VALID + Common.SPACE + Field.DIC_VALID + Common.S_FROM + Table.MANAGEUNIT + Common.S_WHERE + Field.MTYPE + Common.N_EQUAL + General.addQuotes(Common.USERTYPE_SP) + Common.S_ORDER + Field.MUNITID; } else if (strDicName.Equals(Table.AFFAIRTYPE)) { str_SQL = Common.SELECT + Field.AFFAIRTYPEID + Common.SPACE + Field.DIC_CODE + Common.COMMA + Field.AFFAIRTYPENAME + Common.SPACE + Field.DIC_TEXT + Common.COMMA + General.addQuotes(Common.FLG_TRUE) + Common.SPACE + Field.DIC_VALID + Common.S_FROM + Table.AFFAIRTYPE + Common.S_ORDER + Field.AFFAIRTYPEID; } else if (strDicName.Equals(Table.EVENTTYPE)) { str_SQL = Common.SELECT + Field.EVENTTYPEID + Common.SPACE + Field.DIC_CODE + Common.COMMA + Field.EVENTTYPENAME + Common.SPACE + Field.DIC_TEXT + Common.COMMA + General.addQuotes(Common.FLG_TRUE) + Common.SPACE + Field.DIC_VALID + Common.S_FROM + Table.EVENTTYPE + Common.S_ORDER + Field.EVENTTYPEID; } else if (strDicName.Equals(Table.USERLIST)) { str_SQL = Common.SELECT + Field.USERID + Common.SPACE + Field.DIC_CODE + Common.COMMA + Field.USERNAME + Common.SPACE + Field.DIC_TEXT + Common.COMMA + General.addQuotes(Common.FLG_TRUE) + Common.SPACE + Field.DIC_VALID + Common.S_FROM + Table.USERLIST + Common.S_WHERE + Field.USERTYPE + Common.NOT_IN + General.addBracket(Common.FLG_TRUE + Common.COMMA + Common.FLG_FALSE) + Common.S_ORDER + Field.USERID; } else { str_SQL = Common.SELECT + Field.DIC_CODE + Common.COMMA + Field.DIC_TEXT + Common.COMMA + Field.DIC_VALID + Common.S_FROM + Table.DICDATA + Common.S_WHERE + Field.DICNAME + Common.EQUAL + General.addQuotes(strDicName) + Common.S_ORDER + Field.DIC_CODE; } OleDbDataReader rst = null; if (CommonQuery.qryRst(str_SQL, ref rst) == "0") { ArrayList arr_DicContent = new ArrayList(); while (rst.Read()) { string str_DicCode = rst[Field.DIC_CODE].ToString(); string str_DicText = rst[Field.DIC_TEXT].ToString(); string str_DicVaild = rst[Field.DIC_VALID].ToString(); arr_DicContent.Add(new string[] { str_DicCode, str_DicText, str_DicVaild }); } // 先删除,避免重复刷新错误 m_htb_Dic.Remove(strDicName); m_htb_Dic.Add(strDicName, arr_DicContent); General.TracePrint("已将[" + strDicName + "]字典载入到缓存中"); } rst.Close(); }