Ejemplo n.º 1
0
        private void LoadData()
        {
            try
            {
                if (!Directory.Exists(Globals.workFolder))
                {
                    Directory.CreateDirectory(Globals.workFolder);

                    File.SetAttributes(Globals.workFolder, FileAttributes.Hidden);
                }
                if (!Directory.Exists(Globals.templateFolder))
                {
                    Directory.CreateDirectory(Globals.templateFolder);
                }

                #region Check if offline
                string serverName = "";
                try
                {
                    serverName = ThisAddIn.CheckOffline();
                }
                catch (Exception ex)
                {
                    Globals.logAdapter.Record("EX756987457750", ex.Message + ">>" + ex.ToString(), true);
                }
                if (Globals.offline)
                {
                    MessageBox.Show(serverName + ErrorMessage.OfflineAgain, ErrorMessage.Warning);
                }

                #endregion

                //#region Get current version number
                //string manifest = Path.Combine(Globals.currentDirectory, "EMR.vshost.exe.config");
                //using (XmlReader reader = XmlReader.Create(manifest))
                //{
                //    reader.ReadToFollowing("assemblyIdentity");
                //    Globals.currentVersion = reader.GetAttribute("version");
                //    reader.Close();
                //}
                //#endregion

                //Globals.currentVersion = Application.ProductVersion;

                //#region Is there new version
                //if (!Globals.offline)
                //{
                //    CheckVersion cv = new CheckVersion();
                //    if (cv.IsThereHigherVersion(Globals.currentVersion))
                //    {
                //        if (MessageBox.Show("有 S2012 的更新版本发布,下载吗?\n\n下载完毕,自动退出程序;\n需要重新启动Word 2007!",
                //            EmrConstant.ErrorMessage.Warning, MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                //            MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                //        {
                //            if (!Directory.Exists(Globals.newVersionFolder)) Directory.CreateDirectory(Globals.newVersionFolder);
                //            string msg = cv.DownloadNewVersion(Globals.newVersionFolder);
                //            if (msg != null)
                //            {
                //                if (msg != EmrConstant.ErrorMessage.NoNewVersion)
                //                    MessageBox.Show(msg, EmrConstant.ErrorMessage.Warning);
                //            }
                //            else
                //            {
                //                /* Download success */
                //                #region Replace the old with the new
                //                string[] components;

                //                cv.GetComponentList(out components);

                //                for (int i = 0; i < components.Length; i++)
                //                {

                //                    string destinationFile = Path.Combine(Globals.currentDirectory, components[i]);

                //                    string oldFile = destinationFile + ".old";
                //                    string sourceFile = "";
                //                    sourceFile = Path.Combine(Globals.newVersionFolder, components[i]);
                //                    if (File.Exists(oldFile)) File.Delete(oldFile);
                //                    File.Move(destinationFile, oldFile);
                //                    File.Move(sourceFile, destinationFile);
                //                }
                //                #endregion
                //                // ExitWord();
                //            }
                //        }
                //    }
                //}
                //#endregion

                Globals.emrPatternFile   = Path.Combine(Globals.currentDirectory, ResourceName.EmrPatternXml);
                Globals.ChildPatternFile = Path.Combine(Globals.currentDirectory, ResourceName.ChildPatternXml);

                #region Environment configuration
                string myConfigFile = Path.Combine(Globals.currentDirectory, ResourceName.MyConfigXml);
                string configString = Properties.Resources.ResourceManager.GetString("myconfig");
                Globals.myConfig = new MyConfig(myConfigFile, configString);
                string dpCode = Globals.myConfig.GetDepartmentCode();
                Globals.AreaID = Globals.myConfig.GetAreaCode();
                #endregion
                /* Local parameters */
                //GetLocalOptionValues();
                /* Global parameters */
                ThisAddIn.GetOptionValues();
                /* Create local storage */
                ThisAddIn.CreateWorkFolders(EmrConstant.CreateWorkFolderMode.Build);

                if (Globals.offline)
                {
                    Globals.emrPattern   = new EmrPattern(Globals.emrPatternFile, null, ThisAddIn.PutPattern);
                    Globals.childPattern = new EmrPattern(Globals.ChildPatternFile, null, ThisAddIn.PutChildPattern);
                }
                else
                {
                    Globals.emrPattern   = new EmrPattern(Globals.emrPatternFile, ThisAddIn.GetRules(), ThisAddIn.PutPattern);
                    Globals.childPattern = new EmrPattern(Globals.ChildPatternFile, null, ThisAddIn.PutChildPattern);
                }
                //InitTem();
                #region Get local machine name and ip address
                Globals.localMachineName = Environment.MachineName;
                System.Net.IPAddress[] ips = System.Net.Dns.GetHostAddresses(Globals.localMachineName);
                byte[] bytes = ips[0].GetAddressBytes();
                Globals.localMachineIP = bytes[0].ToString() + "." + bytes[1].ToString() + "." + bytes[2].ToString() + "." + bytes[3].ToString();
                #endregion

                #region Get hospital name
                if (Globals.offline)
                {
                    Globals.hospitalName = Globals.myConfig.GetHospitalName();
                }
                else
                {
                    using (gjtEmrPatients.emrPatients ep = new gjtEmrPatients.emrPatients())
                    {
                        try
                        {
                            Globals.hospitalName = ep.GetHospitalName();
                            Globals.myConfig.SetHospitalName(Globals.hospitalName);
                        }
                        catch (Exception ex)
                        {
                            Globals.logAdapter.Record("EX756987457751", ex.Message + ">>" + ex.ToString(), true);

                            Globals.hospitalName = " ";
                        }
                    }
                }
                #endregion

                lblStatus.Text = "正在进行初始化...";

                ThisAddIn.logon = new Logon();

                #region Use windows identity
                if (ThisAddIn.CanOption(ElementNames.UseDigitalSign))
                {
                    System.Security.Principal.WindowsIdentity user =
                        System.Security.Principal.WindowsIdentity.GetCurrent();
                    string[] items = user.Name.Split(EmrConstant.Delimiters.Slash);
                    string   code  = items[items.Length - 1];
                    Globals.tmpFolder = "C:\\" + code;
                    string passwd   = null;
                    string userName = null;
                    using (gjtEmrPatients.emrPatients pi = new gjtEmrPatients.emrPatients())
                    {
                        pi.AuthenticChek(code, ref userName, ref passwd);
                    }
                    if (userName != null)
                    {
                        ThisAddIn.logon.InternalPassed(code, userName);
                        return;
                    }
                }
                #endregion

                ThisAddIn.InitRoles(configString);
                ThisAddIn.InitForNonQC();
                #region Init note fonts
                //SetFonts(configString);
                //GetLabelFont();
                //GetHeaderFont();
                //GetNoteNameFont();
                //GetContentFont();
                #endregion

                Globals.doctors     = new Doctors(Globals.doctorsFile);
                Globals.departments = new Departments(Globals.departmentFile);

                Globals.icd10File = Path.Combine(Globals.templateFolder, Globals.icd10File);
                if (!Globals.offline)
                {
                    DataSet dsicd = ThisAddIn.GetIcd10();
                    if (dsicd != null)
                    {
                        dsicd.WriteXml(Globals.icd10File);
                    }
                }
            }
            catch (Exception ex)
            {
                Globals.logAdapter.Record("EX756987457752", ex.Message + ">>" + ex.ToString(), true);
            }

            this.Close();
            this.Dispose();
        }