/// <summary> /// 用户登录 /// </summary> private void userLogin() { if (checkInput()) { try { SysUserBLL sysUserBll = new SysUserBLL(); SysUser userEntity = sysUserBll.Login(this.txtUser.Text, txtPass.Text); if (!userEntity.LoginOk)//登录失败 { untCommon.ErrorMsg("登录失败:" + userEntity.LoginMsg); } else { if (cbRemember.Checked) { LoginInfo loginInfo = new LoginInfo(); loginInfo.Number = this.txtUser.Text; loginInfo.Pwd = txtPass.Text; loginInfo.Remember = true; /*删除旧的配置文件*/ if (File.Exists(Application.StartupPath + @"\\loginConfig.lsf")) { File.Delete(Application.StartupPath + @"\\loginConfig.lsf"); } KBFile kbFile = new KBFile(); kbFile.path = Application.StartupPath + @"\\loginConfig.lsf"; if (kbFile.writeObjectToFile(loginInfo) < 1) { MessageBox.Show("保存登陆配置文件失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { /*删除旧的配置文件*/ if (File.Exists(Application.StartupPath + @"\\loginConfig.lsf")) { File.Delete(Application.StartupPath + @"\\loginConfig.lsf"); } } Globels.strName = userEntity.F_RealName; Globels.strUser = this.txtUser.Text; frmMain main = new frmMain(this); main.User = userEntity; main.Show(); this.Hide(); } } catch (Exception ex) { untCommon.ErrorMsg("用户登录异常:" + ex.Message); } } }
private void btnSave_Click(object sender, EventArgs e) { try { string filePath = Application.StartupPath + @"\config.lsf"; string skinfile = cbSkin.SelectedItem.ToString(); SysConfig config = new SysConfig(); if (skinfile == "None") { config.SkinFile = ""; } else { config.SkinFile = Application.StartupPath + @"\Skins\" + skinfile; } if (File.Exists(filePath)) { File.Delete(filePath); } KBFile kbFile = new KBFile(); kbFile.path = filePath; int result = kbFile.writeObjectToFile(config); if (result > 0) { frmParent.frmLogin.setSkin(config.SkinFile); untCommon.InfoMsg("设置成功!"); } else { untCommon.InfoMsg("设置失败!"); } } catch (Exception ex) { untCommon.ErrorMsg("皮肤设置异常:" + ex.Message); } }
/// <summary> /// 将配置对象写入数据库 /// </summary> /// <returns></returns> public int setConfig() { try { KBFile file = new KBFile(); file.path = System.Windows.Forms.Application.StartupPath + "\\dbConfig.kb"; if (file.writeObjectToFile(this) > 0) { CrypToFile cy = new CrypToFile(); int count = file.path.Split('.').Length; string fileExt = file.path.Split('.')[count - 1]; string fileName = file.path.Substring(0, file.path.Length - fileExt.Length - 1); if (cy.EncryptData(file.path, fileName + "pwd." + fileExt, "KingBoy")) { System.IO.File.Delete(file.path); System.IO.File.Copy(fileName + "pwd." + fileExt, file.path, true); System.IO.File.Delete(fileName + "pwd." + fileExt); return(1); } else { return(-2); } } else { return(0); } } catch (Exception) { return(-1); } }