コード例 #1
0
        /// <summary>
        /// BLL_RegisterAccount()方法,向数据库insert一条数据
        /// </summary>
        /// <param name="name">要注册的用户名</param>
        /// <param name="pwd">要注册的密码</param>
        /// <returns></returns>
        public bool RegisterAccount(string name, string pwd)
        {
            DAL.Register register = new DAL.Register();
            //把用户输入的密码,进行MD5加密,再存入数据库
            pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "md5").ToLower();
            //微软提供的FormsAuthentication类的,HashPasswordForStoringInConfigFile()方法,会把加密后的MD5字符串自动
            //转成大写,故:要ToLower()

            int res = register.RegisterAccount(name, pwd);
            if (res==1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
コード例 #2
0
        // Calls upon the 'Save' function in the BookManager - Saves the listbox-items as file in the project-path (usually bookmanager\bin)
        public void SaveObject()
        {
            // to use as Save As...
            Register bcvm = new DAL.Register();

            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.FileName   = "Standard_File_Name";
            dlg.DefaultExt = ".cust";                         // Custom File Type
            dlg.Filter     = "Text Documents (.cust)|*.cust"; //Filter Files by Extension

            // Show Dialog
            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                FileStream      fs = new FileStream(dlg.FileName, FileMode.Create, FileAccess.Write, FileShare.None);
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(fs, bc);
                fs.Close();
            }
        }
コード例 #3
0
        // Calls upon the "Load" function in the Bookmanager - Loads the listbox-items and adds them to the project from the saved file.
        public void LoadObject()
        {
            Register bcvm = new DAL.Register();

            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.FileName   = "Standard_File_Name";
            dlg.DefaultExt = ".cust";                         // Custom File Type
            dlg.Filter     = "Text Documents (.cust)|*.cust"; //Filter Files by Extension

            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                FileStream      fs = new FileStream(dlg.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                BinaryFormatter bf = new BinaryFormatter();
                Instance.bc.Clear();
                foreach (Book m in (Model.BookCollection)bf.Deserialize(fs))
                {
                    Instance.bc.Add(m);
                }
                fs.Close();
            }
        }