Esempio n. 1
0
        private void LoginFrm_Load(object sender, EventArgs e)
        {
            //判断目录是否存在
            if (!Directory.Exists(DirXml))
            {
                Directory.CreateDirectory(DirXml);
            }
            //判断软件环境配置文件是否存在,不存在创新赋值
            if (!File.Exists(DirData + @"\config.dat"))
            {
                configYQ cf = new configYQ();
                cf.uptime = 60;
                cf.isShow = true;
                cf.isupdate = true;
                cf.messagetime = 3;
                cf.savenumb = 100;
                FileStream fs = new FileStream(DirData + @"\config.dat", FileMode.Create);
                try
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(fs, cf);
                }
                catch (SerializationException ei)
                {

                    MessageBox.Show(ei.Message);
                }
                finally
                {
                    fs.Close();
                }
            }

            //第一次找配置文件,没找到,要用户输入用户名密码,并保存XML文件中
            if (!File.Exists(DirXml + @"\user.xml"))
            {
                labCon.Visible = txtCon.Visible = labFristLog.Visible = true;
                ckbRember.Visible = false;
                labFristLog.Text = "首次登录请输入用户名和密码!";

            }
            else//第二次以后,找文件,找到后,比较用户名和密码。
            {
                labCon.Visible = txtCon.Visible = labFristLog.Visible = false;
                labFristLog.Text = "";
                ckbRember.Visible = true;
                XElement xe = XElement.Load(DirXml + @"\user.xml");
                ckbRember.Checked = Convert.ToBoolean(xe.Element("user").Element("Rem").Value);
                if (ckbRember.Checked == true)
                {
                    txtName.Text = xe.Element("user").Element("Name").Value;
                    txtPwd.Text = xe.Element("user").Element("Pwd").Value;
                }
            }
        }
Esempio n. 2
0
        //取得配置文件
        private void GetConfig()
        {
            FileStream fs = new FileStream(DirData + @"\config.dat", FileMode.Open);
            configyq = new configYQ();
            try
            {
                BinaryFormatter formatter = new BinaryFormatter();
                configyq = (configYQ)formatter.Deserialize(fs);

            }
            catch (SerializationException se)
            {

                MessageBox.Show(se.Message);
            }
            finally
            {
                fs.Close();
            }
        }