Пример #1
0
        /// <summary>
        /// 解压DataTable
        /// </summary>
        /// <param name="mybytes"></param>
        /// <returns></returns>
        public static DataTable ZipToDateTable(byte[] mybytes)
        {
            byte[]  myby = YezhanbafangCore.DecompressData(mybytes, 50);
            DataSet myds = YezhanbafangCore.RetrieveDataSet(myby);

            return(myds.Tables[0]);
        }
Пример #2
0
        /// <summary>
        /// 压缩DataTable
        /// </summary>
        /// <param name="mydt">DataTable</param>
        /// <returns></returns>
        public static byte[] DataTableToZip(DataTable mydt)
        {
            DataSet myds = new DataSet();

            myds.Tables.Add(mydt.Copy());
            byte[] mybt = YezhanbafangCore.GetBinaryFormatDataSet(myds);
            return(YezhanbafangCore.CompressData(mybt));
        }
Пример #3
0
 /// <summary>
 /// 解压DataSet
 /// </summary>
 /// <param name="mybytes"></param>
 /// <returns></returns>
 public static DataSet ZipToDataSet(byte[] mybytes)
 {
     byte[] myby = YezhanbafangCore.DecompressData(mybytes, 50);
     return(YezhanbafangCore.RetrieveDataSet(myby));
 }
Пример #4
0
 /// <summary>
 /// 压缩DataSet
 /// </summary>
 /// <param name="myds">DateSet</param>
 /// <returns></returns>
 public static byte[] DataSetToZip(DataSet myds)
 {
     byte[] mybys = YezhanbafangCore.GetBinaryFormatDataSet(myds);
     return(YezhanbafangCore.CompressData(mybys));
 }
Пример #5
0
 /// <summary>
 /// 解压缩字符串
 /// </summary>
 /// <param name="mybytes"></param>
 /// <returns></returns>
 public static string ZipToString(byte[] mybytes)
 {
     byte[] myte = YezhanbafangCore.DecompressData(mybytes, 10);
     return(YezhanbafangCore.BytesToString(myte));
 }
Пример #6
0
 /// <summary>
 /// 压缩字符串
 /// </summary>
 /// <param name="str">输入</param>
 /// <returns>压缩后的byte[]</returns>
 public static byte[] StringToZip(string str)
 {
     byte[] myby = YezhanbafangCore.StringToBytes(str);
     return(YezhanbafangCore.CompressData(myby));
 }
Пример #7
0
        /// <summary>
        /// 读取xml自定义的链接字符串
        /// </summary>
        /// <param name="path">xml文件的名称</param>
        /// <returns></returns>
        void ReadConString(string path)
        {
            XmlDocument xmlDoc = new XmlDocument();

            //判断是否存在此xml
            if (!File.Exists(path))
            {
                throw new Exception("不能找到IoRyClass类的XML配置文件!");
            }
            xmlDoc.Load(path);
            //判断连接字符的类型
            XmlNode contype = xmlDoc.SelectSingleNode("constring/type");

            if (contype.InnerText.Trim() != "MSSQL" && contype.InnerText.Trim() != "ACCESS" && contype.InnerText.Trim() != "Oracle" && contype.InnerText.Trim() != "Excel")
            {
                throw new Exception("数据连接类型没填写,或者填写错误,只能填写MSSQL;Oracle;MySQL;ACCESS;Excel并且区分大小写!");
            }

            if (contype.InnerText.Trim() == "MSSQL")//sql
            {
                this._Contype = ConType.MSSQL;
                //判断是否用简单的直接写字符串的方式
                XmlNode mynode = xmlDoc.SelectSingleNode("constring/sqlserver/simple");
                if (mynode.InnerText.Trim() != "")
                {
                    this.ConString = mynode.FirstChild.Value;
                }
                else
                {
                    mynode = xmlDoc.SelectSingleNode("constring/sqlserver/ip");
                    string ip = mynode.FirstChild.Value;
                    mynode = xmlDoc.SelectSingleNode("constring/sqlserver/databasename");
                    string databasename = mynode.FirstChild.Value;
                    mynode = xmlDoc.SelectSingleNode("constring/sqlserver/username");
                    string username = mynode.FirstChild.Value;
                    string password = null;
                    mynode = xmlDoc.SelectSingleNode("constring/sqlserver/passwordencryption");
                    //判断数据库字符串是否加密
                    if (mynode.InnerText.Trim() != "")
                    {
                        XmlNode key = xmlDoc.SelectSingleNode("constring/sqlserver/encryptKey");
                        password = YezhanbafangCore.DecryptDES(mynode.FirstChild.Value, key.FirstChild.Value);
                    }
                    else
                    {
                        mynode   = xmlDoc.SelectSingleNode("constring/sqlserver/password");
                        password = mynode.FirstChild.Value;
                    }
                    string con = string.Format("Data Source={0};Initial Catalog={1};Persist Security Info=True;User ID={2};Password={3}", ip, databasename, username, password);
                    this.ConString = con;
                }
            }
            else if (contype.InnerText.Trim() == "ACCESS") //access
            {
                this._Contype = ConType.Access;
                //判断是否用简单的直接写字符串的方式
                XmlNode mynode = xmlDoc.SelectSingleNode("constring/access/simple");
                if (mynode.InnerText.Trim() != "")
                {
                    this.ConString = mynode.FirstChild.Value;
                }
                else
                {
                    mynode = xmlDoc.SelectSingleNode("constring/access/path");
                    string accpath = mynode.FirstChild.Value;
                    if (File.Exists(accpath))
                    {
                        string password = null;
                        mynode = xmlDoc.SelectSingleNode("constring/access/passwordencryption");
                        //判断数据库字符串是否加密
                        if (mynode.InnerText.Trim() != "")
                        {
                            XmlNode key = xmlDoc.SelectSingleNode("constring/access/encryptKey");
                            password = YezhanbafangCore.DecryptDES(mynode.FirstChild.Value, key.FirstChild.Value);
                        }
                        else
                        {
                            mynode   = xmlDoc.SelectSingleNode("constring/access/password");
                            password = mynode.FirstChild.Value;
                        }
                        string con = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Jet OLEDB:Database Password={1}", accpath, password);
                        this.ConString = con;
                    }
                    else
                    {
                        throw new Exception("找不到文件:" + accpath);
                    }
                }
            }
            else if (contype.InnerText.Trim() == "Oracle") //Oracle
            {
                this._Contype = ConType.Oracle;
                //判断是否用简单的直接写字符串的方式
                XmlNode mynode = xmlDoc.SelectSingleNode("constring/Oracle/simple");
                if (mynode.InnerText.Trim() != "")
                {
                    this.ConString = mynode.FirstChild.Value;
                }
                else
                {
                    mynode = xmlDoc.SelectSingleNode("constring/Oracle/DataSource");
                    string DBServer = mynode.FirstChild.Value;
                    mynode = xmlDoc.SelectSingleNode("constring/Oracle/username");
                    string username = mynode.FirstChild.Value;
                    string password = null;
                    mynode = xmlDoc.SelectSingleNode("constring/Oracle/passwordencryption");
                    //判断数据库字符串是否加密
                    if (mynode.InnerText.Trim() != "")
                    {
                        XmlNode key = xmlDoc.SelectSingleNode("constring/Oracle/encryptKey");
                        password = YezhanbafangCore.DecryptDES(mynode.FirstChild.Value, key.FirstChild.Value);
                    }
                    else
                    {
                        mynode   = xmlDoc.SelectSingleNode("constring/Oracle/password");
                        password = mynode.FirstChild.Value;
                    }
                    mynode = xmlDoc.SelectSingleNode("constring/Oracle/Provider");
                    string con;
                    con            = string.Format("Data Source={0};User ID={1};Password={2}", DBServer, username, password);
                    this.ConString = con;
                }
            }
            else if (contype.InnerText.Trim() == "Excel")
            {
                this.Contype = ConType.Excel;
                XmlNode mynode    = xmlDoc.SelectSingleNode("constring/Excel/path");
                string  Excelpath = mynode.FirstChild.Value;
                if (File.Exists(Excelpath))
                {
                    this.ConString = this.GetExcelReadonlyConnStr(Excelpath);
                }
                else
                {
                    throw new Exception("找不到文件:" + Excelpath);
                }
            }
            else if (contype.InnerText.Trim() == "MySQL") //Oracle
            {
                this._Contype = ConType.MySQL;
                //判断是否用简单的直接写字符串的方式
                XmlNode mynode = xmlDoc.SelectSingleNode("constring/MySQL/simple");
                if (mynode.InnerText.Trim() != "")
                {
                    this.ConString = mynode.FirstChild.Value;
                }
                else
                {
                    mynode = xmlDoc.SelectSingleNode("constring/MySQL/databasename");
                    string databasename = mynode.FirstChild.Value;
                    mynode = xmlDoc.SelectSingleNode("constring/MySQL/ip");
                    string IP = mynode.FirstChild.Value;
                    mynode = xmlDoc.SelectSingleNode("constring/MySQL/port");
                    string PORT = mynode.FirstChild.Value;
                    mynode = xmlDoc.SelectSingleNode("constring/MySQL/username");
                    string username = mynode.FirstChild.Value;
                    string password = null;
                    mynode = xmlDoc.SelectSingleNode("constring/MySQL/passwordencryption");
                    //判断数据库字符串是否加密
                    if (mynode.InnerText.Trim() != "")
                    {
                        XmlNode key = xmlDoc.SelectSingleNode("constring/MySQL/encryptKey");
                        password = YezhanbafangCore.DecryptDES(mynode.FirstChild.Value, key.FirstChild.Value);
                    }
                    else
                    {
                        mynode   = xmlDoc.SelectSingleNode("constring/MySQL/password");
                        password = mynode.FirstChild.Value;
                    }
                    string con = string.Format("Database={0};Data Source={1};User Id={3};Password={4};pooling=false;CharSet=utf8;port={2}", databasename, IP, PORT, username, password);
                    this.ConString = con;
                }
            }
            else
            {
                this.ConString = null;
            }
        }