Exemplo n.º 1
0
        /// <summary>
        /// 获取配置信息
        /// </summary>
        /// <returns></returns>
        public DBConfig getConfig()
        {
            try
            {
                KBFile file = new KBFile();
                file.path = System.Windows.Forms.Application.StartupPath + "\\dbConfig.kb";
                CrypToFile cy    = new CrypToFile();
                int        count = file.path.Split('.').Length;

                string fileExt  = file.path.Split('.')[count - 1];
                string fileName = file.path.Substring(0, file.path.Length - fileExt.Length - 1);

                if (cy.DecryptData(file.path, fileName + "pwd." + fileExt, "KingBoy"))
                {
                    file.path = fileName + "pwd." + fileExt;
                    DBConfig con = (DBConfig)file.readObjectFromFile();
                    System.IO.File.Delete(file.path);
                    return(con);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 将配置对象写入数据库
        /// </summary>
        /// <returns></returns>
        public int setConfig()
        {
            try
            {
                KBFile file = new KBFile();
                file.path = System.Windows.Forms.Application.StartupPath + "\\dbConfig.kb";

                if (file.writeObjectToFile(this) > 0)
                {
                    CrypToFile cy    = new CrypToFile();
                    int        count = file.path.Split('.').Length;

                    string fileExt  = file.path.Split('.')[count - 1];
                    string fileName = file.path.Substring(0, file.path.Length - fileExt.Length - 1);

                    if (cy.EncryptData(file.path, fileName + "pwd." + fileExt, "KingBoy"))
                    {
                        System.IO.File.Delete(file.path);
                        System.IO.File.Copy(fileName + "pwd." + fileExt, file.path, true);
                        System.IO.File.Delete(fileName + "pwd." + fileExt);
                        return(1);
                    }
                    else
                    {
                        return(-2);
                    }
                }
                else
                {
                    return(0);
                }
            }
            catch (Exception)
            {
                return(-1);
            }
        }