protected void btnDelete0_Click(object sender, EventArgs e) { try { if (txtUserName0.Text.Trim().Length < 1) { lblMsg0.Text = "Please get one user first!"; } else { //delete from login if (Membership.DeleteUser(txtUserName0.Text.Trim())) { //delete from table string[] strParas = new string[1]; strParas[0] = txtUserName0.Text.Trim(); clsStoreProcedureAccess clsDelete = new clsStoreProcedureAccess("DeleteUserAccount", strSQLConn); clsDelete.fnExecuteSP(strParas); lblMsg0.Text = "Delete successfully!"; //refresh - to be done //fnLoadUserNames(); fnReset(); } } } catch (Exception ex) { lblMsg0.Text = ex.Message; } }
protected void btnSave0_Click(object sender, EventArgs e) { try { //change access level string username = ddlUserName0.SelectedItem.Value; string strUserRole = Roles.GetRolesForUser(username)[0].ToString(); Roles.RemoveUserFromRole(username, strUserRole); //add a specified role Roles.AddUserToRole(username, ddlAccessLevel0.SelectedItem.Value); //update other info string[] strParas = new string[9]; strParas[0] = ddlUserName0.SelectedItem.Value; strParas[1] = txtFirstName0.Text.Trim(); strParas[2] = txtLastName0.Text.Trim(); strParas[3] = txtPhoneNum0.Text.Trim(); strParas[4] = txtEmail0.Text.Trim(); strParas[5] = txtOrganization0.Text.Trim(); strParas[6] = ddlAccessLevel0.SelectedItem.Value; strParas[7] = ddlApprovalStatus0.SelectedItem.Value; strParas[8] = ddlExportData0.SelectedItem.Value; clsStoreProcedureAccess clsUpdate = new clsStoreProcedureAccess("UpdateUserAccountInfo", strSQLConn); clsUpdate.fnExecuteSP(strParas); lblMsg0.Text = "Done!"; } catch (Exception ex) { lblMsg0.Text = ex.Message; } }
protected void btnGetUser0_Click(object sender, EventArgs e) { try { string[] strParas = new string[1]; strParas[0] = ddlUserName0.SelectedItem.Value; clsStoreProcedureAccess clsSearchByUserName = new clsStoreProcedureAccess("GetUserByUserName", strSQLConn); DataTable dtSearch = clsSearchByUserName.fnExecuteSP2DataTable(strParas); if (dtSearch.Rows.Count < 1) { lblMsg.Text = "No record found!"; } if (dtSearch.Rows.Count == 1) { txtUserName0.Text = dtSearch.Rows[0][0].ToString(); txtFirstName0.Text = dtSearch.Rows[0][1].ToString(); txtLastName0.Text = dtSearch.Rows[0][2].ToString(); txtOrganization0.Text = dtSearch.Rows[0][3].ToString(); txtEmail0.Text = dtSearch.Rows[0][4].ToString(); txtPhoneNum0.Text = dtSearch.Rows[0][5].ToString(); ddlAccessLevel0.SelectedValue = dtSearch.Rows[0][6].ToString(); ddlApprovalStatus0.SelectedValue = dtSearch.Rows[0][7].ToString(); ddlExportData0.SelectedValue = dtSearch.Rows[0][8].ToString(); txtSignUpDate0.Text = dtSearch.Rows[0][9].ToString(); } lblMsg.Text = ""; } catch (Exception ex) { lblMsg.Text = "" + ex.Message; } }
protected void RegisterUser_CreatedUser(object sender, EventArgs e) { string strSQLConn = System.Configuration.ConfigurationManager.AppSettings["SQLConString"].Trim(); try { //FormsAuthentication.SetAuthCookie(RegisterUser.UserName, false /* createPersistentCookie */); //string continueUrl = RegisterUser.ContinueDestinationPageUrl; //if (String.IsNullOrEmpty(continueUrl)) //{ // continueUrl = "~/"; //} //Response.Redirect(continueUrl); Roles.AddUserToRole(RegisterUser.UserName, "pending");//role TextBox txtFirstName = (TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("FirstName"); TextBox txtLastName = (TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("LastName"); TextBox txtPhoneNum = (TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("PhoneNum"); TextBox txtEmailAddress = (TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Email"); TextBox txtOrganization = (TextBox)this.RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Organization"); TextBox txtUserName = (TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("UserName"); string[] strParas = new string[10]; for (int i = 0; i < strParas.Length; i++) { strParas[i] = ""; } strParas[0] = txtUserName.Text.Trim(); strParas[1] = txtFirstName.Text.Trim(); strParas[2] = txtLastName.Text.Trim(); strParas[3] = txtPhoneNum.Text.Trim(); strParas[4] = txtEmailAddress.Text.Trim(); strParas[5] = txtOrganization.Text.Trim(); strParas[6] = "pending"; strParas[7] = "Yes"; strParas[8] = "No"; strParas[9] = DateTime.Today.ToShortDateString(); clsStoreProcedureAccess clsNewAccount = new clsStoreProcedureAccess("InsertNewAccount", strSQLConn); clsNewAccount.fnExecuteSP(strParas); } catch (Exception ex)//lblSysMsg { Label lblMsg = (Label)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("lblSysMsg"); lblMsg.Text = "Error: " + ex.Message; } }
//===========================================================================================================================Manage============== private void fnLoadUserNames() { clsStoreProcedureAccess clsUserNames = new clsStoreProcedureAccess("GetUserNames", strSQLConn); DataTable dtAllUserNames = clsUserNames.fnExecuteSP2DataTable(); ddlUserName0.Items.Clear(); for (int i = 0; i < dtAllUserNames.Rows.Count; i++) { ListItem li = new ListItem(); li.Value = dtAllUserNames.Rows[i][0].ToString(); li.Text = dtAllUserNames.Rows[i][0].ToString(); ddlUserName0.Items.Add(li); } }
protected void btnSearch_Click(object sender, EventArgs e) { if (rblSearchBy.SelectedIndex == 0)//search all { clsStoreProcedureAccess clsSearchAll = new clsStoreProcedureAccess("GetAllUser", strSQLConn); DataTable dtAllUser = clsSearchAll.fnExecuteSP2DataTable(); gvSearchResult.DataSource = dtAllUser; gvSearchResult.DataBind(); lblMsg.Text = dtAllUser.Rows.Count + " records found!"; } else//search by criteria { string[] strParas = new string[6]; strParas[0] = txtFirstName.Visible ? txtFirstName.Text.Trim() : ddlFirstName.SelectedItem.Value; //first //if (strParas[0].Length < 1) strParas[0] = " "; strParas[1] = txtLastName.Visible ? txtLastName.Text.Trim() : ddlLastName.SelectedItem.Value; //lastname //if (strParas[1].Length < 1) strParas[1] = " "; strParas[2] = txtUserName.Visible ? txtUserName.Text.Trim() : ddlUserName.SelectedItem.Value; //username //if (strParas[2].Length < 1) strParas[2] = " "; strParas[3] = txtOrganization.Visible ? txtOrganization.Text.Trim() : ddlOrganization.SelectedItem.Value; //organization //if (strParas[3].Length < 1) strParas[3] = " "; strParas[4] = ddlAccessLevel2.SelectedIndex > 0 ? ddlAccessLevel2.SelectedItem.Value : ""; //accesslevel //if (strParas[4].Length < 1) strParas[4] = " "; if (rblApprovalStatus.SelectedIndex == 0) { strParas[5] = ""; } else if (rblApprovalStatus.SelectedIndex == 1) { strParas[5] = "Yes"; } else { strParas[5] = "No";//approvalstatus; } clsStoreProcedureAccess clsSearchByCriteria = new clsStoreProcedureAccess("GetUserByCriteria", strSQLConn); DataTable dtSearch = clsSearchByCriteria.fnExecuteSP2DataTable(strParas); gvSearchResult.DataSource = dtSearch; gvSearchResult.DataBind(); lblMsg.Text = dtSearch.Rows.Count + " records found!"; } }
protected void btnSave_Click(object sender, EventArgs e) { try { //update other info string[] strParas = new string[3]; strParas[0] = txtUserName.Text.Trim(); strParas[1] = ddlApprovalStatus.SelectedItem.Value; strParas[2] = ddlExportData.SelectedItem.Value; clsStoreProcedureAccess clsUpdate = new clsStoreProcedureAccess("UpdateUserAccountInfoSpec", strSQLConn); clsUpdate.fnExecuteSP(strParas); lblMsg.Text = "Successfully Done!"; } catch (Exception ex) { lblMsg.Text = ex.Message; } }
protected void Login1_LoggedIn(object sender, EventArgs e) { AgolToken ar = null; RestToken rt = null; Session["username"] = Login1.UserName; String[] roles = Roles.GetRolesForUser(Login1.UserName); MembershipUser mu = Membership.GetUser(Login1.UserName); if (roles.Length > 0) { //shufan added codes 08082014====== try { string strSQLConn = System.Configuration.ConfigurationManager.AppSettings["SQLConString"].Trim(); //insert log information string[] strParas = new string[2]; strParas[0] = Login1.UserName; strParas[1] = DateTime.Now.ToString("MM-dd-yyyy HH:mm:ss"); clsStoreProcedureAccess clsInsertLog = new clsStoreProcedureAccess("InsertLogRec", strSQLConn); clsInsertLog.fnExecuteSP(strParas); } catch (Exception ex) { throw ex; }//Shufan added codes end if (Roles.GetRolesForUser(mu.UserName).Contains("pending") == false) { string url = "https://www.arcgis.com/sharing/oauth2/token?" + "client_id=" + ConfigurationManager.AppSettings["client_id"] + "&client_secret=" + ConfigurationManager.AppSettings["client_secret"] + "&grant_type=client_credentials"; ar = MakeRequest(url); if (ar != null) { Session["agol_token"] = ar.access_token; } //url = "https://www.arcgis.com/sharing/generateToken?f=json&" + // "&token=" + ar.access_token + // "&serverUrl=http://analysis.arcgis.com"; url = "https://www.arcgis.com/sharing/generateToken?f=json&" + "&username="******"agol_user"] + "&password="******"agol_password"] + "&referer=https://www.scarchsite.org"; rt = MakeRequest2(url); if (rt != null) { Session["agol_analysis_token"] = rt.token; } Session["rolename"] = roles[0]; Session["DISPLAYNAME"] = ""; Session["AFFILIATION"] = ""; SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "[dbo].[aspnet_GetUserInfo]"; cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = conn; cmd.Parameters.Add("@username", SqlDbType.NVarChar, 256).Value = Login1.UserName; SqlCommand iCmd = new SqlCommand(); iCmd.CommandText = "[dbo].[aspnet_InsertUserToken]"; iCmd.CommandType = CommandType.StoredProcedure; iCmd.Connection = conn; iCmd.Parameters.Add("@username", SqlDbType.NVarChar, 256).Value = Login1.UserName; iCmd.Parameters.Add("@token", SqlDbType.NVarChar, 256).Value = ar.access_token; System.TimeSpan duration = new System.TimeSpan(0, 0, 0, ar.expires_in); iCmd.Parameters.Add("@expired", SqlDbType.DateTime).Value = DateTime.Now.Add(duration); conn.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { String name = ""; if (!(reader["FIRSTNAME"] is System.DBNull)) { name += reader["FIRSTNAME"].ToString(); } if (!(reader["LASTNAME"] is System.DBNull)) { name += " " + reader["LASTNAME"].ToString(); } Session["DISPLAYNAME"] = name; String affil = ""; if (!(reader["AFFILIATION"] is System.DBNull)) { affil = reader["AFFILIATION"].ToString(); } Session["AFFILIATION"] = affil; } } //Insert the token iCmd.ExecuteNonQuery(); conn.Close(); } } if (mu.Comment == "cp") { Response.Redirect("ChangePassword.aspx"); } else if (Roles.GetRolesForUser(mu.UserName)[0].Equals("admin")) { Response.Redirect("~/ManagementTool.aspx"); } else if (Roles.GetRolesForUser(mu.UserName).Contains("pending") == false) { Response.Redirect("~/Map/Map.aspx"); } else { Response.Redirect("~/PublicView.aspx"); } }
protected void btnGenerateReport_Click(object sender, EventArgs e) { DataTable dtReport = new DataTable(); if (rblReportBy.SelectedIndex == 0)//report by individual { //single day if (rblReportWhen.SelectedIndex == 0) { string[] strParas = new string[2]; strParas[0] = txtUserName1.Visible ? txtUserName1.Text.Trim() : ddlUserName1.SelectedItem.Value; strParas[1] = Convert.ToDateTime(txtSingleDay.Text.Trim()).ToString("yyyy-MM-dd"); clsStoreProcedureAccess clsIndividualSingleDay = new clsStoreProcedureAccess("GetLogInfoByUserNameDay", strSQLConn); dtReport = clsIndividualSingleDay.fnExecuteSP2DataTable(strParas); } //date range else if (rblReportWhen.SelectedIndex == 1) { string[] strParas = new string[3]; strParas[0] = txtUserName1.Visible ? txtUserName1.Text.Trim() : ddlUserName1.SelectedItem.Value; strParas[1] = Convert.ToDateTime(txtDayFrom.Text.Trim()).ToString("yyyy-MM-dd"); strParas[2] = Convert.ToDateTime(txtDayTo.Text.Trim()).AddDays(1).ToString("yyyy-MM-dd"); clsStoreProcedureAccess clsIndividualSingleDay = new clsStoreProcedureAccess("GetLogInfoByUserNameRange", strSQLConn); dtReport = clsIndividualSingleDay.fnExecuteSP2DataTable(strParas); } //all else { string[] strParas = new string[1]; strParas[0] = txtUserName1.Visible ? txtUserName1.Text.Trim() : ddlUserName1.SelectedItem.Value; clsStoreProcedureAccess clsIndividualSingleDay = new clsStoreProcedureAccess("GetLogInfoByUserName", strSQLConn); dtReport = clsIndividualSingleDay.fnExecuteSP2DataTable(strParas); } } else if (rblReportBy.SelectedIndex == 1)//report by organization { //single day if (rblReportWhen.SelectedIndex == 0) { string[] strParas = new string[2]; strParas[0] = txtOrganization1.Visible ? txtOrganization1.Text.Trim() : ddlOrganization1.SelectedItem.Value; strParas[1] = Convert.ToDateTime(txtSingleDay.Text.Trim()).ToString("yyyy-MM-dd"); clsStoreProcedureAccess clsIndividualSingleDay = new clsStoreProcedureAccess("GetLogInfoByOrganizationDay", strSQLConn); dtReport = clsIndividualSingleDay.fnExecuteSP2DataTable(strParas); } //date range else if (rblReportWhen.SelectedIndex == 1) { string[] strParas = new string[3]; strParas[0] = txtOrganization1.Visible ? txtOrganization1.Text.Trim() : ddlOrganization1.SelectedItem.Value; strParas[1] = Convert.ToDateTime(txtDayFrom.Text.Trim()).ToString("yyyy-MM-dd"); strParas[2] = Convert.ToDateTime(txtDayTo.Text.Trim()).AddDays(1).ToString("yyyy-MM-dd"); clsStoreProcedureAccess clsIndividualSingleDay = new clsStoreProcedureAccess("GetLogInfoByOrganizationRange", strSQLConn); dtReport = clsIndividualSingleDay.fnExecuteSP2DataTable(strParas); } //all else { string[] strParas = new string[1]; strParas[0] = txtOrganization1.Visible ? txtOrganization1.Text.Trim() : ddlOrganization1.SelectedItem.Value; clsStoreProcedureAccess clsIndividualSingleDay = new clsStoreProcedureAccess("GetLogInfoByOrganization", strSQLConn); dtReport = clsIndividualSingleDay.fnExecuteSP2DataTable(strParas); } } else if (rblReportBy.SelectedIndex == 2)//report by access level { //single day if (rblReportWhen.SelectedIndex == 0) { string[] strParas = new string[2]; strParas[0] = ddlAccessLevel2.SelectedItem.Value; strParas[1] = Convert.ToDateTime(txtSingleDay.Text.Trim()).ToString("yyyy-MM-dd"); clsStoreProcedureAccess clsIndividualSingleDay = new clsStoreProcedureAccess("GetLogInfoByAccessLevelDay", strSQLConn); dtReport = clsIndividualSingleDay.fnExecuteSP2DataTable(strParas); } //date range else if (rblReportWhen.SelectedIndex == 1) { string[] strParas = new string[3]; strParas[0] = ddlAccessLevel2.SelectedItem.Value; strParas[1] = Convert.ToDateTime(txtDayFrom.Text.Trim()).ToString("yyyy-MM-dd"); strParas[2] = Convert.ToDateTime(txtDayTo.Text.Trim()).AddDays(1).ToString("yyyy-MM-dd"); clsStoreProcedureAccess clsIndividualSingleDay = new clsStoreProcedureAccess("GetLogInfoByAccessLevelRange", strSQLConn); dtReport = clsIndividualSingleDay.fnExecuteSP2DataTable(strParas); } //all else { string[] strParas = new string[1]; strParas[0] = ddlAccessLevel2.SelectedItem.Value; clsStoreProcedureAccess clsIndividualSingleDay = new clsStoreProcedureAccess("GetLogInfoByAccessLevel", strSQLConn); dtReport = clsIndividualSingleDay.fnExecuteSP2DataTable(strParas); } } else//report all { //single day if (rblReportWhen.SelectedIndex == 0) { string[] strParas = new string[1]; strParas[0] = Convert.ToDateTime(txtSingleDay.Text.Trim()).ToString("yyyy-MM-dd"); clsStoreProcedureAccess clsIndividualSingleDay = new clsStoreProcedureAccess("GetLogInfoAllDay", strSQLConn); dtReport = clsIndividualSingleDay.fnExecuteSP2DataTable(strParas); } //date range else if (rblReportWhen.SelectedIndex == 1) { string[] strParas = new string[2]; strParas[0] = Convert.ToDateTime(txtDayFrom.Text.Trim()).ToString("yyyy-MM-dd"); strParas[1] = Convert.ToDateTime(txtDayTo.Text.Trim()).AddDays(1).ToString("yyyy-MM-dd"); clsStoreProcedureAccess clsIndividualSingleDay = new clsStoreProcedureAccess("GetLogInfoAllRange", strSQLConn); dtReport = clsIndividualSingleDay.fnExecuteSP2DataTable(strParas); } //all else { clsStoreProcedureAccess clsIndividualSingleDay = new clsStoreProcedureAccess("GetLogInfoAll", strSQLConn); dtReport = clsIndividualSingleDay.fnExecuteSP2DataTable(); } } gvReport.DataSource = dtReport; gvReport.DataBind(); lblMsg1.Text = dtReport.Rows.Count + " records found!"; }