Ejemplo n.º 1
0
        private void LoadConf()
        {
            log.WriteFileLog("加载配置文件");
            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load(conf);

            XmlElement root = xmldoc.DocumentElement;

            // 读取显示属性
            XmlNode xn;

            try
            {
                xn     = root.SelectSingleNode("encry_str");
                keystr = xn.Attributes["key"].InnerText;
            }
            catch (Exception ex)
            {
                keystr = string.Empty;
            }

            // 读取Ssh连接配置
            xn = root.SelectSingleNode("DBBase");
            XmlNodeList xnl = xn.ChildNodes;
            XmlNodeList xll;

            foreach (XmlNode x in xnl)
            {
                // 跳过注释,否则格式不对,会报错
                if (x.NodeType == XmlNodeType.Comment)
                {
                    continue;
                }

                DBConf d = new DBConf(x.Attributes["dbtns"].InnerText,
                                      x.Attributes["note"].InnerText);

                xll = x.ChildNodes;
                foreach (XmlNode xx in xll)
                {
                    DBUser u = new DBUser(xx.Attributes["name"].InnerText,
                                          xx.Attributes["pass"].InnerText,
                                          xx.Attributes["note"].InnerText);

                    u.file = xx.Attributes["file"].InnerText;
                    d.Users.Add(u);
                }
                DBs.Add(d);
            }

            log.WriteFileLog("配置初始化完成");
        }
Ejemplo n.º 2
0
        private void LoadConf()
        {
            log.WriteFileLog("加载配置文件");
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(conf);

            XmlElement root = xmldoc.DocumentElement;

            // 读取显示属性
            XmlNode xn;
            try
            {
                xn = root.SelectSingleNode("encry_str");
                keystr = xn.Attributes["key"].InnerText;
            }
            catch (Exception ex)
            {
                keystr = string.Empty;
            }

            // 读取Ssh连接配置
            xn = root.SelectSingleNode("DBBase");
            XmlNodeList xnl = xn.ChildNodes;
            XmlNodeList xll;
            foreach (XmlNode x in xnl)
            {
                // 跳过注释,否则格式不对,会报错
                if (x.NodeType == XmlNodeType.Comment)
                    continue;

                DBConf d = new DBConf(x.Attributes["dbtns"].InnerText,
                    x.Attributes["note"].InnerText);

                xll = x.ChildNodes;
                foreach (XmlNode xx in xll)
                {
                    DBUser u = new DBUser(xx.Attributes["name"].InnerText,
                        xx.Attributes["pass"].InnerText,
                        xx.Attributes["note"].InnerText);

                    u.file = xx.Attributes["file"].InnerText;
                    d.Users.Add(u);

                }
                DBs.Add(d);
            }

            log.WriteFileLog("配置初始化完成");
        }
Ejemplo n.º 3
0
        public Boolean RunNhs()  // 执行Nhs文件
        {
            string s, SqlContent = string.Empty;

            // 先解压缩,然后执行
            Extract(file);

            DBUser d = null;

            foreach (DBUser u in dbconf.Users)
            {
                if (u.name.Equals(user))
                {
                    d = u;
                    break;
                }
            }

            if (d == null)
            {
                // 报错返回
            }

            string oradb = "Data Source=" + dbconf.tnsname + ";User Id=" + d.name + ";Password="******";";

            conn = new OracleConnection(oradb); // C#

            try
            {
                conn.Open();
            }
            catch (OracleException e)
            {
                string err = "连接Oracle数据库失败,TNSNAME:" + dbconf.tnsname + ",Oracle异常信息:" + e.Message;
                oplog.WriteLog(err, LogLevel.Error);
                System.Windows.Forms.MessageBox.Show(err);

                return(false);
            }
            catch (Exception e)
            {
                string err = "连接Oracle数据库失败,TNSNAME:" + dbconf.tnsname + ",异常信息:" + e.Message;
                oplog.WriteLog(err, LogLevel.Error);
                System.Windows.Forms.MessageBox.Show(err);

                return(false);
            }

            cmd            = new OracleCommand();
            cmd.Connection = conn;


            // 读取文件
            try
            {
                // 重定位流,否则读取从最后开始,无数据了
                ms.Seek(0, SeekOrigin.Begin);
                using (StreamReader sr = new StreamReader(ms,
                                                          Encoding.GetEncoding("gb2312")))
                {
                    // 读取到 Sql 分隔符
                    while ((s = sr.ReadLine()) != null)
                    {
                        // 读到了 /,做一次提交
                        if (s.Trim().Equals("/"))
                        {
                            if (!ExSqlBlock(SqlContent))
                            {
                                return(false);
                            }

                            SqlContent = string.Empty;
                        }
                        else
                        {
                            // readline 会去掉最后的换行符,这里把格式补上,否则编译出来的过程都不换行,很难看
                            SqlContent = SqlContent + "\n" + s;
                        }
                    }

                    RaiseEvent("执行!" + file + "完成!");
                    return(true);
                }
            }
            catch (Exception ex)
            {
                OperLog.instance.WriteLog("Nhs文件读取异常。" + ex.Message, LogLevel.Error);

                return(false);
            }

            finally
            {
                cmd.Dispose();
                conn.Dispose();
            }
        }
Ejemplo n.º 4
0
 private void button3_Click(object sender, EventArgs e)
 {
     label1.Text = DBUser.EncPass(maskedTextBox1.Text);
 }