public CResult ReadCurrentUserAndBrance(string cuser, string cbrance) { CUserAndBranch oUserAndBranch = new CUserAndBranch(); oResult = new CResult(); conn = oConnManager.GetConnection(out s_DBError); if (conn != null) { try { DataSet ds = new DataSet(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "sp_ReadCurrentUserAndBrance"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@cuser", cuser); cmd.Parameters.AddWithValue("@cbrance", cbrance); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(ds); DataTable dt = ds.Tables[0]; foreach (DataRow dr in dt.Rows) { oUserAndBranch.User = GetresultoUser(dr); } DataTable dt2 = ds.Tables[1]; foreach (DataRow dr in dt2.Rows) { oUserAndBranch.Branch = GetResultSetToCompanyBranch(dr); } oResult.IsSuccess = true; oResult.Data = oUserAndBranch; } catch (SqlException e) { oResult.IsSuccess = false; oResult.ErrMsg = e.Message; } finally { oConnManager.Close(); } } else { oResult.IsSuccess = false; oResult.ErrMsg = s_DBError; } return(oResult); }
private void UserLogin() { CUserBO oUserBO = new CUserBO(); CResult oResult = new CResult(); string Name = txtUserName.Text; string Password = txtPassword.Text; // Advance Start Password = (txtPassword.Text.Substring(0, 1) == "_") ? txtPassword.Text.Substring(1) : txtPassword.Text; defaultUserMode = (txtPassword.Text.Substring(0, 1) == "_") ? false : true; // Advance End string Branch = cmbBranch.Text.ToString(); oResult = oUserBO.UserLogin(Name, Password); if (oResult.IsSuccess) { CUser oUser = (CUser)oResult.Data; if (oUser != null) { if (oUser.User_UserType == "Admin") { ETLPOSMDI OETLPOSMDI = new ETLPOSMDI(); CUserAndBranch oUserAndBranch = new CUserAndBranch(); string cuser = txtUserName.Text; string cbrance = cmbBranch.Text; oResult = oUserBO.ReadCurrentUserAndBrance(cuser, cbrance); if (oResult.IsSuccess) { oUserAndBranch = (CUserAndBranch)oResult.Data; currentUser = oUserAndBranch.User; currentBranch = oUserAndBranch.Branch; } else { MessageBox.Show(oResult.ErrMsg.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } // Advance Start if (!defaultUserMode) { new frmVatClnNo().ShowDialog(this); } // Advance End OETLPOSMDI.Show(); this.Hide(); } else if (oUser.User_UserType == "Sales") { ETLPOSMDI OETLPOSMDI = new ETLPOSMDI(true); CUserAndBranch oUserAndBranch = new CUserAndBranch(); string cuser = txtUserName.Text; string cbrance = cmbBranch.Text; oResult = oUserBO.ReadCurrentUserAndBrance(cuser, cbrance); if (oResult.IsSuccess) { oUserAndBranch = (CUserAndBranch)oResult.Data; currentUser = oUserAndBranch.User; currentBranch = oUserAndBranch.Branch; } else { MessageBox.Show(oResult.ErrMsg.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } // Advance Start if (!defaultUserMode) { new frmVatClnNo().ShowDialog(this); } // Advance End OETLPOSMDI.Show(); this.Hide(); } } else { MessageBox.Show("Login Information Is Not Valid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }