private void ConfigDBForm_Load(object sender, EventArgs e) { 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) { this.tbDbName.Text = dbName; } if (dbName != null) { this.tbIP.Text = ipAdd; } if (dbName != null) { this.tbUserName.Text = user; } if (dbName != null) { this.tbPwd.Text = pwd; } }
//弹出数据库配置 private void btnConfigDB_Click(object sender, EventArgs e) { FormConfigDB form = new FormConfigDB(); form.ShowDialog(); if (form.DialogResult == DialogResult.OK) { UtilConfig.SQL_ADDRESS = DBSQLite.selectValue(UtilConfig.SQL_ADDRESS_KEY); } }
private void FormAddSSZZ_Load(object sender, EventArgs e) { //获取用户名 string account = DBSQLite.selectValue(UtilConfig.ACCOUNT_KEY); DataTable dataTable = DBManager.getInstance().find(string.Format("select e_name from t_emp where e_account='{0}'", account)); if (dataTable != null && dataTable.Rows.Count > 0) { foreach (DataRow row in dataTable.Rows) { this.labSSZZ_Creator.Text = row["e_name"].ToString(); } } }
//登录 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("账号不存在"); } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Process[] tProcess = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName); if (tProcess.Length > 1) { Application.Exit(); } else { try { DBSQLite.CreateDB(); DBSQLite.CreateTable(); UtilConfig.SQL_ADDRESS = DBSQLite.selectValue(UtilConfig.SQL_ADDRESS_KEY); string account = DBSQLite.selectValue(UtilConfig.ACCOUNT_KEY); string pwd = DBSQLite.selectValue(UtilConfig.PWD_KEY); // 原先有保存连接,判断原先的数据库连接是否有用 Boolean isConnectionWorks = DBManager.isConnectionWorks(); if (isConnectionWorks) { bool flag = DBEmp.getInstance().isLogin(account, pwd); if (flag) { Application.Run(new FormMain()); } else { Application.Run(new FormSignIn()); } } else { Application.Run(new FormSignIn()); } } catch (Exception err) { MessageBox.Show(err.Message); } } }
//保存配置 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("保存成功"); } }