瀏覽代碼

优化代码,修改缓存登陆信息

章政 8 年之前
父節點
當前提交
4cf2a90f00
共有 2 個文件被更改,包括 12 次插入18 次删除
  1. 6 9
      UAS-MES/Login.cs
  2. 6 9
      UAS-MES/PublicMethod/BaseUtil.cs

+ 6 - 9
UAS-MES/Login.cs

@@ -23,8 +23,6 @@ namespace UAS_MES
 
         Thread LoadMasterInf;
 
-
-
         public Login()
         {
             InitializeComponent();
@@ -48,8 +46,8 @@ namespace UAS_MES
             LoadMasterInf = new Thread(LoadMaster);
             LoadMasterInf.Start();
             //显示上次用户登录的用户名,将输入框定位到密码
-            UserName.Text = Properties.Settings.Default.LastLoginUser;
-            Source.Text = Properties.Settings.Default.LastLoginResource;
+            UserName.Text = BaseUtil.GetCacheData("LastLoginUser").ToString();
+            Source.Text = BaseUtil.GetCacheData("LastLoginResource").ToString();
             if (UserName.Text != "")
                 PassWord.Select();
             else
@@ -67,7 +65,7 @@ namespace UAS_MES
                 DB.DataSource = DbComboxData;
                 DB.DisplayMember = "ma_user";
                 DB.ValueMember = "ma_user";
-                DB.Text = Properties.Settings.Default.LastLoginSob;
+                DB.Text = BaseUtil.GetCacheData("LastLoginSob").ToString();
                 LoginButton.Enabled = true;
             }
             catch (Exception ex)
@@ -164,10 +162,9 @@ namespace UAS_MES
             UserInf = (DataTable)dh.ExecuteSql("select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') as systime from dual", "select");
             SystemInf.LoginTime = UserInf.Rows[0]["systime"].ToString();
             //记录在本地用户成功登录的用户名
-            Properties.Settings.Default.LastLoginUser = UserName.Text;
-            Properties.Settings.Default.LastLoginSob = DB.Text;
-            Properties.Settings.Default.LastLoginResource = Source.Text;
-            Properties.Settings.Default.Save();
+            BaseUtil.SetCacheData("LastLoginUser", UserName.Text);
+            BaseUtil.SetCacheData("LastLoginSob", DB.Text);
+            BaseUtil.SetCacheData("LastLoginResource", Source.Text);
         }
 
         private void ForGetPwd_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)

+ 6 - 9
UAS-MES/PublicMethod/BaseUtil.cs

@@ -125,7 +125,7 @@ namespace UAS_MES.PublicMethod
                     string controlName = collection[i].Name;
                     string controlsTag = collection[i].Tag == null ? "" : collection[i].Tag.ToString();
                     //默认给TextBox和Label赋值
-                    if (collection[i] is TextBox || collection[i] is Label || collection[i] is SearchTextBox || collection[i] is MaCodeSearchTextBox||collection[i] is EnterTextBox ||collection[i] is TextBoxGeneratePaCode)
+                    if (collection[i] is TextBox || collection[i] is Label || collection[i] is SearchTextBox || collection[i] is MaCodeSearchTextBox || collection[i] is EnterTextBox || collection[i] is TextBoxGeneratePaCode)
                     {
                         for (int j = 0; j < dt.Columns.Count; j++)
                         {
@@ -986,7 +986,8 @@ namespace UAS_MES.PublicMethod
             fs.Close();
         }
 
-        public static Object GetCacheData(string ParamName) {
+        public static Object GetCacheData(string ParamName)
+        {
             Object o = null;
             //根据地址读取xml文件
             XmlDocument doc = new XmlDocument();
@@ -1002,7 +1003,7 @@ namespace UAS_MES.PublicMethod
             foreach (XmlNode node in nodeList)
             {
                 //找到了这个节点名字
-                if (node.Name==ParamName)
+                if (node.Name == ParamName)
                 {
                     //返回节点的内容
                     switch (((XmlElement)node).GetAttribute("Type"))
@@ -1019,23 +1020,19 @@ namespace UAS_MES.PublicMethod
                         default:
                             break;
                     }
-                    //o = ;
                     break;
                 }
             }
             //关闭reader
             reader.Close();
             if (o == null)
-            {
                 return "";
-            }
             else
-            {
                 return o;
-            }
         }
 
-        public static void SetCacheData(string ParamName,object Value) {
+        public static void SetCacheData(string ParamName, object Value)
+        {
             //根据地址读取xml文件
             XmlDocument doc = new XmlDocument();
             XmlReaderSettings settings = new XmlReaderSettings();