private void btnLogin_Click(object sender, EventArgs e) { string err = DataValidate(); Utils.DbCon dbcon = Utils.Helper.ReadConDb("DBCON"); Utils.DbCon empdbcon = Utils.Helper.ReadConDb("EMPDBCON"); if (string.IsNullOrEmpty(dbcon.DataSource)) { var b = new FrmConnection(); b.typeofcon = "DBCON"; b.ShowDialog(); return; } else { Utils.Helper.constr = dbcon.ToString(); } if (string.IsNullOrEmpty(empdbcon.DataSource)) { var b = new FrmConnection(); b.typeofcon = "EMPDBCON"; b.ShowDialog(); return; } else { Utils.Helper.Empconstr = empdbcon.ToString(); } if (string.IsNullOrEmpty(err)) { string sql = "Select * from MastUser Where UserID = '{0}' and Pass = '******' and Active = 'Y'"; DataSet ds = Utils.Helper.GetData(string.Format(sql, txtUserName.Text, txtPassword.Text), dbcon.ToString()); bool hasrows = ds.Tables.Cast <DataTable>().Any(table => table.Rows.Count != 0); if (hasrows) { Utils.User.GUserID = txtUserName.Text.Trim(); Utils.User.GUserPass = txtPassword.Text.Trim(); Utils.User.IsAdmin = (Convert.ToBoolean(ds.Tables[0].Rows[0]["IsAdmin"])) ? true : false; Utils.User.GUserName = ds.Tables[0].Rows[0]["UserName"].ToString(); this.Hide(); Program.OpenMDIFormOnClose = true; this.Close(); } else { MessageBox.Show("Invalid login id or Password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void mnuDBConn_Click(object sender, EventArgs e) { Form t = Application.OpenForms["FrmConnection"]; if (t == null) { FrmConnection m = new FrmConnection(); m.MdiParent = this; m.typeofcon = "DBCON"; m.Show(); } }