コード例 #1
0
ファイル: App.xaml.cs プロジェクト: joelihn/WpfApplication1
        protected override void OnStartup(StartupEventArgs e)
        {
            var other = FindWindow(null, "WpfApplicaiton1");

            if (other != IntPtr.Zero)
            {
                SetForegroundWindow(other);
                if (IsIconic(other))
                {
                    OpenIcon(other);
                }


                System.Windows.Application.Current.Shutdown();
                return;
            }

            if (Current.Resources.MergedDictionaries.Count == 0)
            {
                Current.Resources.MergedDictionaries.Add(new ResourceDictionary
                {
                    Source =
                        new Uri(
                            System.Windows.Forms.Application.StartupPath +
                            "\\" + "CN.Xaml")
                });
            }

            config_xmlDoc = new XmlDocument();
            string configFilename = System.Windows.Forms.Application.UserAppDataPath + "\\WpfApplication1\\lic.xml";

            if (File.Exists(configFilename))
            {
                try
                {
                    config_xmlDoc.Load(configFilename);
                }
                catch (Exception ee)
                {
                    MessageBox.Show("Error occured:\n\n" + configFilename + " " + ee.Message);
                    System.Windows.Application.Current.Shutdown();
                    return;
                }
            }
            else
            {
                if (!Directory.Exists(System.Windows.Forms.Application.UserAppDataPath + "\\WpfApplication1"))
                {
                    Directory.CreateDirectory(System.Windows.Forms.Application.UserAppDataPath + "\\WpfApplication1");
                }
                FileStream config   = File.Create(configFilename);
                byte[]     rootNode = Encoding.UTF8.GetBytes("<System>\n</System>");
                config.Write(rootNode, 0, rootNode.Length);
                config.Close();

                config_xmlDoc.Load(configFilename);


                XmlNode SystemCfg = config_xmlDoc.SelectSingleNode("System");

                XmlNode setting = config_xmlDoc.SelectSingleNode("System/Setting");

                XmlElement xmlform = null;
                if (setting == null)
                {
                    xmlform = config_xmlDoc.CreateElement("Setting");
                }
                else
                {
                    xmlform = (XmlElement)setting;
                }

                XmlElement xmlele = config_xmlDoc.CreateElement("Item");
                xmlele.SetAttribute("name", "UT");
                int times = EncryptInt(0);
                xmlele.SetAttribute("value", times.ToString());
                xmlform.AppendChild(xmlele);

                SystemCfg.AppendChild(xmlform);

                config_xmlDoc.Save(configFilename);
            }

            List <string> macAddress   = Utils.Utils.GetMacAddress();
            bool          fileNotExist = !File.Exists(ConstDefinition.RunningPath + "\\license.dat");

            bool succ = false;

            //Byte[] encryptBytes;
            if (!fileNotExist)
            {
                string str;
                using (var licfile = new StreamReader(ConstDefinition.RunningPath + "\\license.dat", true))
                {
                    str = licfile.ReadLine();
                }
                foreach (string mac in macAddress)
                {
                    string encryptStr = Utils.Utils.MD5Encrypt(mac + "0");

                    if (str.Equals(encryptStr))
                    {
                        ConstDefinition.Runlevel = 0;
                        succ = true;
                        break;
                    }
                    encryptStr = Utils.Utils.MD5Encrypt(mac + "1");

                    if (str.Equals(encryptStr))
                    {
                        ConstDefinition.Runlevel = 1;
                        succ = true;
                        break;
                    }
                }
            }

            if (fileNotExist || !succ)
            {
                // 试用次数
                bool flag  = true;
                int  times = 0;

                try
                {
                    XmlDocument xmlDoc = this.config_xmlDoc;
                    if (xmlDoc != null)
                    {
                        XmlNodeList xmlNodeList = xmlDoc.SelectNodes("System/Setting/Item");
                        if (xmlNodeList != null && xmlNodeList.Count != 0)
                        {
                            for (int i = 0; i < xmlNodeList.Count; i++)
                            {
                                XmlAttribute atrribName  = xmlNodeList[i].Attributes["name"];
                                XmlAttribute atrribValue = xmlNodeList[i].Attributes["value"];

                                if ((atrribName != null) && (atrribValue != null) && (atrribName.Value.Equals("UT")))
                                {
                                    times = Int32.Parse(atrribValue.Value);
                                }
                            }
                        }
                    }

                    times = DecryptInt(times);

                    times++;

                    if (times > ConstDefinition.TryVersionTimes)
                    {
                        times--;
                        var messageBox1 = new RemindMessageBox1(true);
                        messageBox1.remindText.Text = "您使用的是试用版,而且试用次数已用尽,如需继续使用请注册.";
                        messageBox1.ShowDialog();
                        Shutdown();
                        return;
                    }
                    else if (times > 0)
                    {
                        int left = ConstDefinition.TryVersionTimes - times + 1;
                        //var messageBox1 = new RemindMessageBox1(true);
                        //messageBox1.remindText.Text = "您使用的是试用版,在您购买正式版之前还能试用 " + left + " 次.";
                        //messageBox1.ShowDialog();
                        times = EncryptInt(times);
                        string formname = "System/Setting";
                        Repopulate_Node_Of_Config_XMLDoc(formname, "Item", "UT", "value", times.ToString());
                    }
                    else
                    {
                        var messageBox1 = new RemindMessageBox1(true);
                        messageBox1.remindText.Text = "您使用的是试用版,而且试用次数已用尽,如需继续使用请注册.";
                        messageBox1.ShowDialog();
                        Shutdown();
                        return;
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message);
                    var messageBox1 = new RemindMessageBox1(true);
                    messageBox1.remindText.Text = "您使用的是试用版,而且试用次数已用尽,如需继续使用请注册.";
                    messageBox1.ShowDialog();
                    Shutdown();
                    return;
                }
            }


            ////var s = new SplashScreen("SplashScreen.png");
            //var s = new SplashScreen("welcome.jpg");
            //s.Show(false, true);
            //s.Close(new TimeSpan(0, 0, 1));

            StartupUri = new Uri("MainWindow.xaml", UriKind.Relative);
        }
コード例 #2
0
        public MainWindow()
        {
            ConstDefinition.DbStr = "server=" + config.AppSettings.Settings["IpAddress"].Value + ";database=" + config.AppSettings.Settings["Database"].Value
                                    + ";uid=" + config.AppSettings.Settings["Username"].Value + ";pwd=" + config.AppSettings.Settings["Password"].Value + ";Timeout=10";
            SqlConnection sqlConn = null;

            try
            {
                sqlConn = new SqlConnection(ConstDefinition.DbStr);
                sqlConn.Open();
            }
            catch (Exception e)
            {
                var messageBox1 = new RemindMessageBox1(true);
                messageBox1.remindText.Text = (string)FindResource("Message40");
                messageBox1.ShowDialog();
                Log.WriteErrorLog("数据路连接失败,请确认数据库文件和密码设置是否正确.", e);
                Close();
                return;
            }
            finally
            {
                if (sqlConn != null)
                {
                    sqlConn.Close();
                }
            }

            InitializeComponent();

            this.Title = config.AppSettings.Settings["Title"].Value.ToString();

            Key["姓名"]   = "NAME";
            Key["性别"]   = "GENDER";
            Key["血型"]   = "BLOODTYPE";
            Key["婚姻状况"] = "MARRIAGE";
            Key["感染情况"] = "INFECTTYPEID";
            Key["治疗状态"] = "TREATSTATUSID";
            Key["固定床位"] = "ISFIXEDBED";
            Key["所属分区"] = "AREAID";

            Symbol["大于"]  = ">";
            Symbol["小于"]  = "<";
            Symbol["等于"]  = "=";
            Symbol["包含"]  = "like";
            Symbol["不包含"] = "not like";


            Dispatcher.UnhandledException += Dispatcher_UnhandledException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;

            //if (config.AppSettings.Settings["DataBasePath"].Value.Equals(""))
            //{
            //    config.AppSettings.Settings["DataBasePath"].Value = Application.StartupPath;
            //    config.Save(ConfigurationSaveMode.Modified);
            //    ConfigurationManager.RefreshSection("appSettings");
            //}


            //TODO test all database table access operation
            #region
            //using (var bedDao = new BedDao())
            //{
            //    var bed = new WpfApplication1.DAOModule.Bed();
            //    bed.PatientRoomId = 1;
            //    bed.Name = "床位1";
            //    bed.Type = 0;
            //    bed.IsAvailable = true;
            //    bed.IsOccupy = false;
            //    bed.Description = "描述";
            //    bed.Reserved = "保留字段";

            //    int lastInsertId = -1;
            //    bedDao.InsertBed(bed, ref lastInsertId);

            //    var condition = new Dictionary<string, object>();
            //    condition["NAME"] = "床位1";
            //    var list = bedDao.SelectBed(condition);

            //    var fields = new Dictionary<string, object>();
            //    fields["DESCRIPTION"] = "描述描述";
            //    bedDao.UpdateBed(fields, condition);

            //    bedDao.DeleteBed((int)list[0].Id);
            //}
            #endregion


            patientGroupPanel = new PatientGroupPanel(this);
            initContent       = new Init(this);
            orderContent      = new Order(this);
            sheduleContent    = new Shedule(this);
            bedContent        = new Bed(this);
            configContent     = new Config(this);
            reeportContent    = new Report(this);

            /*initContent.ButtonNew.Click += delegate
             * {
             *  var a = new SignUP(this);
             *  a.ShowDialog();
             * };*/

            /* if (ConstDefinition.Runlevel == 1)
             *   this.ConfigButton.IsEnabled = true;
             * else
             *   this.ConfigButton.IsEnabled = false;*/
            this.RightContentR.Content = initContent;
            this.RightContentL.Content = patientGroupPanel;

            TopMenuListBox.ItemsSource = TopMenuCollection;
            TopMenuCollection.Add("登记");
            TopMenuCollection.Add("医嘱");
            TopMenuCollection.Add("排班");
            TopMenuCollection.Add("排床");
            TopMenuCollection.Add("设置");
            TopMenuCollection.Add("报表");
        }
コード例 #3
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (tbName.Text.Equals("") || tbUid.Text.Equals(""))
            {
                var a = new RemindMessageBox1();
                a.remindText.Text = "患者名称和唯一识别码不能为空.";
                a.ShowDialog();
                return;
            }

            name = tbName.Text;
            if (rbM.IsChecked == true)
            {
                sex = "男";
            }
            else
            {
                sex = "女";
            }
            birthday = dpBirthday.Text;

            if ((bool)this.rbNegative1.IsChecked)
            {
                infectionTypeId = 0;
            }
            else if ((bool)this.rbNegative2.IsChecked)
            {
                using (InfectTypeDao infectTypeDao = new InfectTypeDao())
                {
                    var condition = new Dictionary <string, object>();
                    condition["Name"] = InfectTypeComboBox.Text;
                    infectionName     = InfectTypeComboBox.Text;
                    var list = infectTypeDao.SelectInfectType(condition);
                    if (list != null)
                    {
                        infectionTypeId = list[0].Id;
                    }
                }
            }

            if ((bool)this.rbTreatStatus1.IsChecked)
            {
                treatmentStatus    = 0;
                treatmentStausName = "在治";
            }
            else if ((bool)this.rbTreatStatus2.IsChecked)
            {
                using (TreatStatusDao treatStatusDao = new TreatStatusDao())
                {
                    var condition = new Dictionary <string, object>();
                    condition["Name"]  = StatusComboBox.Text;
                    treatmentStausName = StatusComboBox.Text;
                    var list = treatStatusDao.SelectTreatStatus(condition);
                    if (list != null)
                    {
                        treatmentStatus = list[0].Id;
                    }
                }
            }

            if ((bool)this.rbFixBed1.IsChecked)
            {
                isFixBed = true;
            }
            else if ((bool)this.rbFixBed2.IsChecked)
            {
                isFixBed = false;
            }

            uid = tbUid.Text;

            using (PatientAreaDao patientAreaDao = new PatientAreaDao())
            {
                var condition = new Dictionary <string, object>();
                condition["Name"] = AreaComboBox.Text;
                areaName          = AreaComboBox.Text;
                var list = patientAreaDao.SelectPatientArea(condition);
                if (list != null)
                {
                    areaId = list[0].Id;
                }
            }

            result = System.Windows.Forms.DialogResult.OK;

            using (PatientDao patientDao = new PatientDao())
            {
                Patient patient = new Patient();
                patient.Name          = name;
                patient.Gender        = sex;
                patient.Dob           = birthday;
                patient.InfectTypeId  = infectionTypeId;
                patient.TreatStatusId = treatmentStatus;
                patient.IsFixedBed    = isFixBed;
                patient.PatientId     = uid;
                patient.AreaId        = areaId;
                patient.BedId         = -1;
                int lastInsertId = -1;
                patientDao.InsertPatient(patient, ref lastInsertId);

                InitMedicalOrderData(lastInsertId);

                Basewindow.initContent.IDTextBox.Text   = lastInsertId.ToString();
                Basewindow.initContent.NameTextBox.Text = patient.Name;
                if (patient.Gender.Equals("男"))
                {
                    Basewindow.initContent.RadioButton1.IsChecked = true;
                }
                else if (patient.Gender.Equals("女"))
                {
                    Basewindow.initContent.RadioButton2.IsChecked = true;
                }
                Basewindow.initContent.DatePicker1.Text = DateTime.Parse(patient.Dob).ToString();

                using (InfectTypeDao infectTypeDao = new InfectTypeDao())
                {
                    var condition = new Dictionary <string, object>();
                    condition["ID"] = patient.InfectTypeId;
                    var list = infectTypeDao.SelectInfectType(condition);
                    if ((list != null) && (list.Count > 0))
                    {
                        Basewindow.initContent.InfectTypeComboBox.Text = list[0].Name;
                    }
                }

                using (TreatStatusDao treatStatusDao = new TreatStatusDao())
                {
                    var condition = new Dictionary <string, object>();
                    condition["ID"] = patient.TreatStatusId;
                    var list = treatStatusDao.SelectTreatStatus(condition);
                    if ((list != null) && (list.Count > 0))
                    {
                        Basewindow.initContent.StatusComboBox.Text = list[0].Name;
                    }
                }

                Basewindow.initContent.IDTextBox.Text = patient.PatientId;
                if (patient.IsFixedBed)
                {
                    Basewindow.initContent.RadioButton3.IsChecked = true;
                }
                else
                {
                    Basewindow.initContent.RadioButton4.IsChecked = true;
                }

                using (PatientAreaDao patientAreaDao = new PatientAreaDao())
                {
                    var condition = new Dictionary <string, object>();
                    condition["ID"] = patient.AreaId;
                    var list = patientAreaDao.SelectPatientArea(condition);
                    if ((list != null) && (list.Count > 0))
                    {
                        Basewindow.initContent.AreaComboBox.Text = list[0].Name;
                    }
                }
            }

            //TODO:判断一下当前添加的患者是否满足当前患者组条件,如果满足需要刷新患者列表
            Basewindow.patientGroupPanel.RefreshData();


            Basewindow.initContent.ButtonNew.IsEnabled    = true;
            Basewindow.initContent.ButtonDelete.IsEnabled = true;
            Basewindow.initContent.ButtonApply.IsEnabled  = false;
            Basewindow.initContent.ButtonCancel.IsEnabled = false;

            this.Close();
        }