Beispiel #1
0
 public Database()
 {
     if (database == null)
     {
         string serverName = ApiFunction.GetIniString("SERVER_NAME", "NAME", Application.StartupPath + "\\ClientConfig.ini");
         if (serverName == "")
         {
             throw new Exception("ClientConfig.ini中[SERVER_NAME]的NAME未设置,请启动配置程序并设置当前服务器");
         }
         //获取连接字符串
         ConnectionType dbType           = ConnectionType.SQLSERVER;//在此设置数据库类型,以后根据数据库平台需要更改此处
         string         connectionString = GetConnnectionString(dbType, serverName);
         database = CreateConnection(dbType, connectionString);
         database.Open();
     }
 }
Beispiel #2
0
        private void GetNewFile()
        {
            string serverName = ApiFunction.GetIniString("SERVER_NAME", "NAME", Application.StartupPath + "\\ClientConfig.ini");

            if (serverName == "")
            {
                System.Windows.Forms.MessageBox.Show("ClientConfig.ini中[SERVER_NAME]的NAME未设置,请启动配置程序并设置当前服务器", "错误");
                Application.Exit();
                return;
            }
            string connectionString = GetConnnectionString(ConnectionType.SQLSERVER, serverName); // ****************设置获取连接字符串**********************

            pConnectionString = connectionString;
            ConnectionType connectionType = ConnectionType.SQLSERVER;

            #region 获得系统升级DataTable
            string commandText = "select id,type,name,update_time,version,dellocalreport from pub_systemupdate where delete_bit=0";
            systemUpdateTB = new DataTable();
            IDbConnection  cnn;
            IDbCommand     cmd;
            IDbDataAdapter adapter;
            switch (connectionType)
            {
            case ConnectionType.SQLSERVER:
                cnn            = new SqlConnection(connectionString);
                cmd            = new SqlCommand(commandText);
                cmd.Connection = (SqlConnection)cnn;
                adapter        = new SqlDataAdapter((SqlCommand)cmd);
                ((SqlDataAdapter)adapter).Fill(systemUpdateTB);
                cmd.Dispose();
                cmd = null;
                ((SqlDataAdapter)adapter).Dispose();
                adapter = null;
                break;

            default:
                cnn            = new OleDbConnection(connectionString);
                cmd            = new OleDbCommand(commandText);
                cmd.Connection = (OleDbConnection)cnn;
                adapter        = new OleDbDataAdapter((OleDbCommand)cmd);
                ((OleDbDataAdapter)adapter).Fill(systemUpdateTB);
                ((OleDbDataAdapter)adapter).Dispose();
                adapter = null;
                break;
            }
            #endregion
        }
Beispiel #3
0
        /// <summary>
        /// 获取连接字符串
        /// </summary>
        /// <param name="type">类型0、SQL SERVER 1、IBM DB2</param>
        /// <param name="applicationName">INI文件中段(SECTION)名称</param>
        private string GetConnnectionString(ConnectionType type, string applicationName)
        {
            string cnnString, hostName, database, userID, password, protocol, port, strCnnType;

            switch (type)
            {
            case ConnectionType.SQLSERVER:
                hostName  = Crypto.Instance().Decrypto(ApiFunction.GetIniString(applicationName, "HOSTNAME", Application.StartupPath + "\\ClientConfig.ini"));
                database  = Crypto.Instance().Decrypto(ApiFunction.GetIniString(applicationName, "DATASOURCE", Application.StartupPath + "\\ClientConfig.ini"));
                userID    = Crypto.Instance().Decrypto(ApiFunction.GetIniString(applicationName, "USER_ID", Application.StartupPath + "\\ClientConfig.ini"));
                password  = Crypto.Instance().Decrypto(ApiFunction.GetIniString(applicationName, "PASSWORD", Application.StartupPath + "\\ClientConfig.ini"));
                cnnString = @"packet size=4096;user id=" + userID + ";password="******";data source=" + hostName + ";persist security info=True;initial catalog=" + database;
                break;

            case ConnectionType.IBMDB2:
                hostName   = Crypto.Instance().Decrypto(ApiFunction.GetIniString(applicationName, "HOSTNAME", Application.StartupPath + "\\ClientConfig.ini"));
                protocol   = Crypto.Instance().Decrypto(ApiFunction.GetIniString(applicationName, "PROTOCOL", Application.StartupPath + "\\ClientConfig.ini"));
                port       = Crypto.Instance().Decrypto(ApiFunction.GetIniString(applicationName, "PORT", Application.StartupPath + "\\ClientConfig.ini"));
                database   = Crypto.Instance().Decrypto(ApiFunction.GetIniString(applicationName, "DATASOURCE", Application.StartupPath + "\\ClientConfig.ini"));
                userID     = Crypto.Instance().Decrypto(ApiFunction.GetIniString(applicationName, "USER_ID", Application.StartupPath + "\\ClientConfig.ini"));
                password   = Crypto.Instance().Decrypto(ApiFunction.GetIniString(applicationName, "PASSWORD", Application.StartupPath + "\\ClientConfig.ini"));
                strCnnType = Crypto.Instance().Decrypto(ApiFunction.GetIniString(applicationName, "CONNECTIONTYPE", Application.StartupPath + "\\ClientConfig.ini"));
                if (strCnnType == "1")
                {
                    cnnString = @"Provider=IBMDADB2;Database=" + database + ";HostName=" + hostName + ";Protocol=" + protocol + ";Port=" + port + ";User ID=" + userID + ";Password="******"Provider=IBMDADB2.1;User ID=" + userID + ";Password="******";Data Source=" + database + ";Mode=ReadWrite;Extended Properties=";
                }
                break;

            case ConnectionType.MSACCESS:
                database  = Crypto.Instance().Decrypto(ApiFunction.GetIniString(applicationName, "DATASOURCE", Application.StartupPath + "\\ClientConfig.ini"));
                cnnString = @"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data Source=" + database + ";Mode=Share Deny None;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1";
                break;

            default:
                cnnString = "";
                break;
            }
            return(cnnString);
        }
Beispiel #4
0
        private void FileUpdate()
        {
            string iniFile = Application.StartupPath + "\\UpdateFile.ini";

            try
            {
                this.btnOk.Enabled = false;
                FileStream fw = null;
                pbTotal.Maximum = systemUpdateTB.Rows.Count;
                pbTotal.Value   = 0;
                this.Refresh();
                for (int i = 0; i < systemUpdateTB.Rows.Count; i++)
                {
                    try
                    {
                        int    id            = Convert.ToInt32(systemUpdateTB.Rows[i]["ID"]);
                        string fileName      = systemUpdateTB.Rows[i]["name"].ToString();
                        string localVersion  = ApiFunction.GetIniString("FILEINFO", fileName, iniFile);
                        string serverVersion = systemUpdateTB.Rows[i]["Version"].ToString();
                        string fullFileName  = Application.StartupPath + "\\" + fileName;
                        string exName        = fileName.Substring(fileName.Length - 3, 3);
                        #region ...
                        //增加判断 Modify By Tany 2010-03-24
                        if ((File.Exists(Application.StartupPath + "\\SysUpdate.exe") && fileName.ToUpper() == "SYSUPDATE.EXE") ||
                            (File.Exists(Application.StartupPath + "\\SysUpdateEx.exe") && fileName.ToUpper() == "SYSUPDATEEX.EXE"))
                        {
                            //如果升级文件是自身,跳过
                            continue;
                        }
                        if (exName.Trim().ToUpper() == "RPT")
                        {
                            fullFileName = Application.StartupPath + "\\report\\" + fileName; //当前路径下的报表文件夹
                        }
                        int flag = Convert.IsDBNull(systemUpdateTB.Rows[i]["DelLocalReport"]) ? 0 : Convert.ToInt32(systemUpdateTB.Rows[i]["DelLocalReport"]);
                        #endregion
                        if (localVersion.Trim().ToUpper() != serverVersion.Trim().ToUpper())
                        {
                            lblUpdate.Text = "从旧版本(" + localVersion + ")升级到新版本(" + serverVersion + ")";
                            //DataRow dr = this.GetFileValue(id);
                            Object obj = this.GetFileValue(id);// dr["file_value"];
                            if (obj != null && !Convert.IsDBNull(obj))
                            {
                                if (File.Exists(fullFileName))
                                {
                                    File.Delete(fullFileName);
                                }
                                #region ...
                                fw = new FileStream(fullFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);

                                sttbplFiles.Text = fileName;

                                byte[] buffer     = (byte[])obj;
                                int    fileLength = (int)buffer.Length / BUFFER_LENGTH;
                                if (fileLength * BUFFER_LENGTH < buffer.Length)
                                {
                                    fileLength++;
                                }
                                pbCurrent.Maximum = fileLength;
                                pbCurrent.Value   = 0;
                                for (int j = 0; j < fileLength; j++)    //以长度为BUFFER_LENGTH字节的块进行传送
                                {
                                    if (buffer.Length - j * BUFFER_LENGTH >= BUFFER_LENGTH)
                                    {
                                        fw.Write(buffer, j * BUFFER_LENGTH, BUFFER_LENGTH);
                                    }
                                    else
                                    {
                                        fw.Write(buffer, j * BUFFER_LENGTH, buffer.Length - j * BUFFER_LENGTH);
                                    }
                                    fw.Seek(0, SeekOrigin.End);
                                    pbCurrent.Value++;
                                    this.Refresh();
                                }

                                #endregion
                                if (flag == 1)
                                {
                                    //删除指定目录下的报表文件
                                    if (File.Exists(this.CustomDirectory + "\\report\\" + fileName))
                                    {
                                        File.Delete(this.CustomDirectory + "\\report\\" + fileName);
                                    }
                                }
                                ApiFunction.WriteIniString("FILEINFO", fileName, serverVersion, iniFile);
                            }
                        }
                    }
                    catch (Exception err)
                    {
                        this.lstInfo.Items.Add(err.Message.ToString());
                        continue;
                    }
                    finally
                    {
                        pbTotal.PerformStep();
                    }
                }

                this.sttbDesc.Text = "升级成功!";
                this.btnOk.Enabled = true;

                //btnOk_Click(null, null);
            }
            catch (Exception err)
            {
                MessageBox.Show("升级失败:\n" + err.Message, "错误");
                //Process.Start(Application.StartupPath+ "\\"+mainExeName);
                this.Close();
            }
            finally
            {
                if (pConn != null && pConn.State == ConnectionState.Open)
                {
                    pConn.Close();
                }
                if (pConn != null)
                {
                    pConn.Dispose();
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// 更新文件
        /// </summary>
        public void Update()
        {
            string iniFile = Application.StartupPath + "\\UpdateFile.ini";
            string folder  = this.DownloadFolder;

            if (string.IsNullOrEmpty(folder))
            {
                folder = "";
            }
            if (folder == downloadFolder_default)
            {
                folder = "";
            }

            //如果folder为空,则表示当前要升级的文件时SystemUpdate.exe本身,HIS的升级程序默认在运行目录下,其他地方的同名文件则认为不是HIS的更新程序
            if (string.IsNullOrEmpty(folder))
            {
                //如果是自身需要更新,退出,不在此出更新,由框架去处理升级程序的更新
                if ((File.Exists(Application.StartupPath + "\\SysUpdate.exe") && this.name.ToUpper() == "SYSUPDATE.EXE") ||
                    (File.Exists(Application.StartupPath + "\\SysUpdateEx.exe") && this.name.ToUpper() == "SYSUPDATEEX.EXE"))
                {
                    return;
                }
            }

            string[] strArray = this.name.Split(".".ToCharArray());
            string   exName   = ""; //后缀名

            if (strArray.Length > 1)
            {
                exName = strArray[strArray.Length - 1].ToUpper();
            }
            string lpKeyName    = this.name;
            string fullFileName = Application.StartupPath + "\\" + this.name; //本地的文件,默认是当前HIS目录

            if (exName.ToUpper() == "RPT")
            {
                string str = Application.StartupPath + "\\report";
                if (!System.IO.Directory.Exists(str))
                {
                    System.IO.Directory.CreateDirectory(str);
                }
                fullFileName = Application.StartupPath + "\\report\\" + this.name; //当前路径下的报表文件夹
            }

            if (folder != "")
            {
                lpKeyName = folder + "\\" + this.name;
                //如果是指定下载目录,重新构造fullFileName,
                string parentFolder = "";
                if (this.DownloadFolder.Substring(0, 2) == downloadFolder_default)        //
                {
                    parentFolder = Application.StartupPath + downloadFolder.Remove(0, 2); //指定的下载目录为相对路径
                }
                else
                {
                    parentFolder = this.DownloadFolder;                                     //指定的下载目录为绝对路径
                }
                //路径不存在,则创建
                if (!System.IO.Directory.Exists(parentFolder))
                {
                    System.IO.Directory.CreateDirectory(parentFolder);
                }
                fullFileName = parentFolder + "\\" + this.name;
            }

            string localVersion  = ApiFunction.GetIniString("FILEINFO", lpKeyName, iniFile);
            string serverVersion = version;

            if (UpdateProcessing != null)
            {
                UpdateProcessing(Action.CompareVersion, "比较文件版本中...");
            }
            //比较本地文件版本和数据库文件版本
            if (localVersion.Trim().ToUpper() != serverVersion.Trim().ToUpper())
            {
                try
                {
                    if (UpdateProcessing != null)
                    {
                        UpdateProcessing(Action.DownLoadContent, "正在下载文件" + this.name + "中,请稍后......");
                    }
                    try
                    {
                        this.content = database.GetUpdateFileContent(this.id);
                    }
                    catch
                    {
                        if (UpdateProcessing != null)
                        {
                            UpdateProcessing(Action.DownLoadComplete, "文件" + this.name + "下载失败!");
                        }
                        return;
                    }
                    if (UpdateProcessing != null)
                    {
                        UpdateProcessing(Action.DownLoadComplete, "文件" + this.name + "下载完成!");
                    }

                    Object obj = this.content;
                    if (obj != null && !Convert.IsDBNull(obj))
                    {
                        if (File.Exists(fullFileName))
                        {
                            if (UpdateProcessing != null)
                            {
                                UpdateProcessing(Action.Updating, "文件备份中...");
                            }
                            //备份原文件
                            BackupOldFile(fullFileName, false);
                            //删除原文件
                            File.Delete(fullFileName);

                            Classes.Logger.Write(string.Format("旧文件{0}删除,原版本{1}", fullFileName, localVersion));
                        }
                        #region 把二进制数据转为文件

                        using (FileStream fw = new FileStream(fullFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                        {
                            try
                            {
                                byte[] buffer     = (byte[])obj;
                                int    fileLength = (int)buffer.Length / BUFFER_LENGTH;
                                if (fileLength * BUFFER_LENGTH < buffer.Length)
                                {
                                    fileLength++;
                                }
                                Classes.Logger.Write(string.Format("正在更新文件{0},长度{1},块{2}", this.name, buffer.Length, fileLength));

                                for (int j = 0; j < fileLength; j++)            //以长度为BUFFER_LENGTH字节的块进行传送
                                {
                                    if (buffer.Length - j * BUFFER_LENGTH >= BUFFER_LENGTH)
                                    {
                                        fw.Write(buffer, j * BUFFER_LENGTH, BUFFER_LENGTH);
                                    }
                                    else
                                    {
                                        fw.Write(buffer, j * BUFFER_LENGTH, buffer.Length - j * BUFFER_LENGTH);
                                    }
                                    fw.Seek(0, SeekOrigin.End);

                                    if (FileUpdate != null)
                                    {
                                        FileUpdate(this.name, fileLength, j);
                                    }
                                }
                            }
                            catch (Exception error)
                            {
                                Classes.Logger.Write(fullFileName, error);
                                return;
                            }
                            finally
                            {
                                fw.Close();
                                fw.Dispose();
                            }
                        }

                        #endregion

                        //对于报表文件,删除自定义目录下的文件即可
                        if (dellocalreport == 1 && exName == "RPT" && string.IsNullOrEmpty(folder))
                        {
                            //删除指定目录下的报表文件
                            string rptFile = CustomDirectory.Path + "\\report\\" + this.name;
                            if (File.Exists(rptFile))
                            {
                                if (UpdateProcessing != null)
                                {
                                    UpdateProcessing(Action.Updating, "文件备份中...");
                                }
                                //备份文件
                                BackupOldFile(rptFile, true);
                                //删除文件
                                File.Delete(rptFile);

                                Classes.Logger.Write(string.Format("原报表文件副本{0}已删除", rptFile));
                            }
                        }
                        //将文件名及服务器版本号写入到本地的ini中
                        if (UpdateProcessing != null)
                        {
                            UpdateProcessing(Action.Updating, "更新ini升级信息...");
                        }

                        //MessageBox.Show("lpKeyName:" + lpKeyName + ":serverVersion:" + serverVersion);
                        ApiFunction.WriteIniString("FILEINFO", lpKeyName, serverVersion, iniFile);

                        if (UpdateProcessing != null)
                        {
                            string sRet = name + "|" + localVersion + "|" + serverVersion + "|" + "更新完成...";
                            UpdateProcessing(Action.UpdateComplete, sRet);
                        }

                        Classes.Logger.Write(string.Format("文件{0}更新完成,版本{1}", name, serverVersion));
                    }
                }
                catch (Exception error)
                {
                    if (UpdateProcessing != null)
                    {
                        UpdateProcessing(Action.UpdateFailed, string.Format("文件名{0},错误:{1}", this.name, error.Message + error.StackTrace));
                    }

                    Classes.Logger.Write(name, error);
                }
            }
        }
Beispiel #6
0
        //static void Main(params string[] invokAppId)
        //Modify By Tany 2012-04-10 带参数启动
        static void Main(string[] args)
        {
            Classes.Logger.Write(new string[] { "Start Run Update Main Function" }, true);
            string hisStartupExe = "Trasen.exe";
            string procName      = "Trasen";

            //Modify By Tany 2012-03-09 获取主程序的exe名称
            hisStartupExe = GetIniString("MAINPROGRAMINFO", "hisStartupExe", Application.StartupPath + "\\ClientConfig.ini");
            procName      = GetIniString("MAINPROGRAMINFO", "Trasen", Application.StartupPath + "\\ClientConfig.ini");
            if (hisStartupExe.Trim() == "")
            {
                hisStartupExe = "Trasen.exe";
            }
            if (procName.Trim() == "")
            {
                procName = "Trasen";
            }

            //判断启动程序的参数,没有参数则是由Trasen.exe调用
            if (args.Length > 0)
            {
                hisStartupExe = args[0];
                //MessageBox.Show(args[0]);
            }
            if (args.Length > 1)
            {
                procName = args[1];

                //MessageBox.Show(args[1]);
            }

            Classes.Logger.Write(new string[] { "Beform CreateMutex" }, true);

            IntPtr hMutex = ApiFunction.CreateMutex(null, false, "SysUpdateEx");

            if (ApiFunction.GetLastError() == ApiFunction.ERROR_ALREADY_EXISTS)
            {
                ApiFunction.ReleaseMutex(hMutex);
                return;
            }

            #region add by wangzhi 记录升级程序的信息
            List <string> lstLogHeader = new List <string>();
            lstLogHeader.Add("*******************************************************************************************");
            lstLogHeader.Add(string.Format("hisStartupExe:{0}", hisStartupExe));
            lstLogHeader.Add(string.Format("procName:{0}", procName));
            if (args != null && args.Length > 0)
            {
                lstLogHeader.Add("Main.args[]:");
                for (int i = 0; i < args.Length; i++)
                {
                    if (!string.IsNullOrEmpty(args[i]))
                    {
                        lstLogHeader.Add(args[i]);
                    }
                }
            }
            lstLogHeader.Add("*******************************************************************************************");
            Classes.Logger.Write(lstLogHeader.ToArray(), false);
            #endregion

            Frmflash f = new Frmflash("正在关闭相关应用程序...");//jianqg  2013-4-22
            #region 关闭相关的程序
            try
            {
                f.Show();
                f.Refresh();
                KillProcess("");
            }
            catch (Exception err)
            {
                MessageBox.Show("升级程序无法关闭相关应用程序,请手工关闭程序后再试" + err.Message);
                return;
            }
            finally
            {
                f.Close();
            }
            #endregion

            //启动升级程序主界面
            Classes.Logger.Write("启动升级程序主界面.");
            Application.Run(new SystemUpdate.Forms.FrmFileUpdate());

            //升级结束后,启动HIS应用程序
            try
            {
                bool   invokeBySSO = false;
                string strags      = "";
                if (args.Length == 1 && args[0] == "SSO")
                {
                    //参数为SSO表示由单点登录的程序调用Trasen后再调用升级程序
                    invokeBySSO = true;
                }
                //jianqg  2013-4-22
                if (args.Length > 2)   //jianqg  2013-4-22 增加 通过接口如pacs 传入的参数
                {
                    strags += args[2];
                    //MessageBox.Show(args[2]);
                }
                if (args.Length > 3)   //jianqg  2013-4-22 增加 通过接口如pacs 传入的参数
                {
                    strags += " " + args[3] + " " + "IsFromUpdate";
                }
                //MessageBox.Show(hisStartupExe);
                //MessageBox.Show(strags);

                if (invokeBySSO)
                {
                    MessageBox.Show("升级完成,请重新由门户程序进入", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (strags == "")
                {
                    Classes.Logger.Write(string.Format("升级结束,正准备启动{0},参数{1}", hisStartupExe, "IsFormUpdate"));
                    Process.Start(Application.StartupPath + "\\" + hisStartupExe, "IsFormUpdate");
                }
                else
                {
                    Classes.Logger.Write(string.Format("升级结束,正准备启动{0},参数{1}", hisStartupExe, strags));
                    Process.Start(Application.StartupPath + "\\" + hisStartupExe, strags);
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }