//登录 private void btnSignIn_Click(object sender, EventArgs e) { string account = this.textBoxAcount.Text; string pwd = this.textBoxPwd.Text; string sqlAddress = DBSQLite.selectValue(UtilConfig.SQL_ADDRESS_KEY) + ""; if (sqlAddress.Length == 0) { MessageBox.Show("你还没有配置数据库,需要先配置数据库,才能登录"); return; } if (string.IsNullOrEmpty(account)) { MessageBox.Show("账号不能为空"); return; } if (string.IsNullOrEmpty(pwd)) { MessageBox.Show("密码不能为空"); return; } bool flag = DBEmp.getInstance().isAccount(account); if (flag) { flag = DBEmp.getInstance().isLogin(account, pwd); if (flag) { //UtilConfig.ACCOUNT = account; DBSQLite.updateValue(UtilConfig.ACCOUNT_KEY, account); DBSQLite.updateValue(UtilConfig.PWD_KEY, pwd); goMainForm(); } else { MessageBox.Show("用户名与密码不匹配"); } ; } else { MessageBox.Show("账号不存在"); } }
//保存配置 private void btnSave_Click(object sender, EventArgs e) { if (this.tbDbName.Text != null) { if (DBSQLite.selectValue(UtilConfig.DB_NAME_KEY) != null) { DBSQLite.updateValue(UtilConfig.DB_NAME_KEY, this.tbDbName.Text); } else { DBSQLite.insertValue(UtilConfig.DB_NAME_KEY, this.tbDbName.Text); } } if (this.tbIP.Text != null) { if (DBSQLite.selectValue(UtilConfig.DB_IP_KEY) != null) { DBSQLite.updateValue(UtilConfig.DB_IP_KEY, this.tbIP.Text); } else { DBSQLite.insertValue(UtilConfig.DB_IP_KEY, this.tbIP.Text); } } if (this.tbUserName.Text != null) { //UtilTools.setData(UtilConfig.DB_USER_KEY, this.tbUserName.Text); if (DBSQLite.selectValue(UtilConfig.DB_USER_KEY) != null) { DBSQLite.updateValue(UtilConfig.DB_USER_KEY, this.tbUserName.Text); } else { DBSQLite.insertValue(UtilConfig.DB_USER_KEY, this.tbUserName.Text); } } if (this.tbPwd.Text != null) { // UtilTools.setData(UtilConfig.DB_PWD_KEY, this.tbPwd.Text); if (DBSQLite.selectValue(UtilConfig.DB_PWD_KEY) != null) { DBSQLite.updateValue(UtilConfig.DB_PWD_KEY, this.tbPwd.Text); } else { DBSQLite.insertValue(UtilConfig.DB_PWD_KEY, this.tbPwd.Text); } } string dbName = DBSQLite.selectValue(UtilConfig.DB_NAME_KEY); string ipAdd = DBSQLite.selectValue(UtilConfig.DB_IP_KEY); string user = DBSQLite.selectValue(UtilConfig.DB_USER_KEY); string pwd = DBSQLite.selectValue(UtilConfig.DB_PWD_KEY); if (dbName == null || ipAdd == null || user == null || pwd == null) { MessageBox.Show("保存失败"); } else { string sqlAddress = "server=" + ipAdd + ";port=3306;database=" + dbName + ";user="******";password="******";"; //UtilTools.setData(UtilConfig.SQL_ADDRESS_KEY, sqlAddress); if (DBSQLite.selectValue(UtilConfig.SQL_ADDRESS_KEY) != null) { DBSQLite.updateValue(UtilConfig.SQL_ADDRESS_KEY, sqlAddress); } else { DBSQLite.insertValue(UtilConfig.SQL_ADDRESS_KEY, sqlAddress); } DialogResult dr = MessageBox.Show("保存成功,是否退出?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { this.DialogResult = DialogResult.OK; this.Close(); } } }
//保存配置 private void btnSave_Click(object sender, EventArgs e) { if (this.tbDbName.Text != null) { if (DBSQLite.selectValue(UtilConfig.DB_NAME_KEY) != null) { DBSQLite.updateValue(UtilConfig.DB_NAME_KEY, this.tbDbName.Text); } else { DBSQLite.insertValue(UtilConfig.DB_NAME_KEY, this.tbDbName.Text); } } if (this.tbIP.Text != null) { if (DBSQLite.selectValue(UtilConfig.DB_IP_KEY) != null) { DBSQLite.updateValue(UtilConfig.DB_IP_KEY, this.tbIP.Text); } else { DBSQLite.insertValue(UtilConfig.DB_IP_KEY, this.tbIP.Text); } } if (this.tbUserName.Text != null) { //UtilTools.setData(UtilConfig.DB_USER_KEY, this.tbUserName.Text); if (DBSQLite.selectValue(UtilConfig.DB_USER_KEY) != null) { DBSQLite.updateValue(UtilConfig.DB_USER_KEY, this.tbUserName.Text); } else { DBSQLite.insertValue(UtilConfig.DB_USER_KEY, this.tbUserName.Text); } } if (this.tbPwd.Text != null) { // UtilTools.setData(UtilConfig.DB_PWD_KEY, this.tbPwd.Text); if (DBSQLite.selectValue(UtilConfig.DB_PWD_KEY) != null) { DBSQLite.updateValue(UtilConfig.DB_PWD_KEY, this.tbPwd.Text); } else { DBSQLite.insertValue(UtilConfig.DB_PWD_KEY, this.tbPwd.Text); } } string dbName = DBSQLite.selectValue(UtilConfig.DB_NAME_KEY); string ipAdd = DBSQLite.selectValue(UtilConfig.DB_IP_KEY); string user = DBSQLite.selectValue(UtilConfig.DB_USER_KEY); string pwd = DBSQLite.selectValue(UtilConfig.DB_PWD_KEY); if (dbName == null || ipAdd == null || user == null || pwd == null) { MessageBox.Show("保存失败"); } else { string sqlAddress = "server=" + ipAdd + ";port=3306;database=" + dbName + ";user="******";password="******";"; //UtilTools.setData(UtilConfig.SQL_ADDRESS_KEY, sqlAddress); if (DBSQLite.selectValue(UtilConfig.SQL_ADDRESS_KEY) != null) { DBSQLite.updateValue(UtilConfig.SQL_ADDRESS_KEY, sqlAddress); } else { DBSQLite.insertValue(UtilConfig.SQL_ADDRESS_KEY, sqlAddress); } MessageBox.Show("保存成功"); } }