protected void btnArchiveUsers_Click(object sender, System.EventArgs e) { if (txtUserIDs.Text != "") { Bdw.Application.Salt.BusinessServices.User u = new User(); u.ArchiveUsers(txtUserIDs.Text, UserContext.UserID); lblError.Text = ResourceManager.GetString("lblMessage.UsersArchived"); lblError.CssClass = "FeedbackMessage"; lblError.Visible = true; plhPreviewUsers.Visible = false; btnArchiveUsers.Visible = false; // for periodic reports owned by archived users Session["InactivatedUsernames"] = null; string[] archivedUserIds = txtUserIDs.Text.Split(new char[] { ',' }); List <string> inactivatedUsernames = new List <string>(); for (int i = 0; i < archivedUserIds.Length; i++) { int userid = 0; Int32.TryParse(archivedUserIds[i], out userid); BusinessServices.User user = new BusinessServices.User(); DataTable dtUser = user.GetUser(userid); string username = dtUser.Rows[0]["UserName"].ToString(); inactivatedUsernames.Add(username); } Session["InactivatedUsernames"] = inactivatedUsernames; btnPeriodicReport.Visible = true; } }
/// <summary> /// Load data the page is first loaded /// </summary> private void LoadData() { BusinessServices.User objUser; DataTable dtbUser; string strName; int intOrganisationID; objUser = new BusinessServices.User(); dtbUser = objUser.GetUser(this.m_intUserID); strName = dtbUser.Rows[0]["FirstName"].ToString() + " " + dtbUser.Rows[0]["LastName"].ToString(); intOrganisationID = (int)dtbUser.Rows[0]["OrganisationID"]; this.lblName.Text = strName; //1. Load Course list that are assigned to this User this.GetCourseList(intOrganisationID); if (this.cboCourse.Items.Count > 0) { //2. Lists all modules in the selected course this.GetModuleAccess(); } else { this.cboCourse.Visible = false; this.btnSave.Visible = false; this.lblMessage.Text = ResourceManager.GetString("lblMessage.NoCourse"); this.lblMessage.CssClass = "FeedbackMessage"; } }
private void LoadPolicy() { int UserID = UserContext.UserID; BusinessServices.User objUser = new BusinessServices.User(); DataTable dtUserProfiles = objUser.GetProfilePeriodList(UserID); int PolicyID = int.Parse(Request.QueryString["PolicyID"].ToString()); BusinessServices.Policy objPolicy = new BusinessServices.Policy(); // if the policy as not accepted, enable to checkbox if (!objPolicy.CheckAccepted(PolicyID, UserID)) { string ConfirmationMessage = objPolicy.GetConfirmationMessage(PolicyID); this.chkAgree.Text = ConfirmationMessage; } else { this.chkAgree.Enabled = false; this.chkAgree.Checked = true; string lastAccepted = objPolicy.GetLastAccepted(UserID, UserContext.UserData.OrgID, PolicyID); this.chkAgree.Text = ResourceManager.GetString("lblLastAccepted") + " " + lastAccepted; } string PolicyName = objPolicy.GetPolicyFileName(PolicyID, UserContext.UserData.OrgID); string PolicyDir = @"\General\Policy\" + UserContext.UserData.OrgID.ToString(); this.pdfFrame.Attributes["src"] = PolicyDir + @"\" + PolicyName; this.pdfFrame.Visible = true; }
private void BindCPDProfile() { //int OrganisationID = UserContext.UserData.OrgID; //BusinessServices.Profile objProfile = new BusinessServices.Profile(); //DataTable dtPolicyPoints = objProfile.GetProfileList(OrganisationID); //if (dtPolicyPoints.Rows.Count > 0) //{ // ddlCPDProfile.DataSource = dtPolicyPoints; // ddlCPDProfile.DataValueField = "ProfileID"; // ddlCPDProfile.DataTextField = "ProfileName"; // ddlCPDProfile.DataBind(); //} int UserID = UserContext.UserID; BusinessServices.User objUser = new BusinessServices.User(); DataTable dtProfileList = objUser.GetProfilePeriodList(UserID); if (dtProfileList.Rows.Count > 0) { ddlCPDProfile.DataSource = dtProfileList; ddlCPDProfile.DataValueField = "ProfileID"; ddlCPDProfile.DataTextField = "ProfileName"; ddlCPDProfile.DataBind(); } }
protected void btnSend_Click(object sender, System.EventArgs e) { try { BusinessServices.Email objMail = new BusinessServices.Email(); BusinessServices.User objUser = new BusinessServices.User(); // Get the current users details. DataTable dtbCurrentUserDetails = objUser.GetUser(UserContext.UserID); // Setup email header string strFromName = dtbCurrentUserDetails.Rows[0]["FirstName"].ToString() + " " + dtbCurrentUserDetails.Rows[0]["LastName"].ToString(); string strFromEmail = dtbCurrentUserDetails.Rows[0]["Email"].ToString(); string strToEmail = txtToEmail.Text; string strToName = txtToEmail.Text; objMail.setUserCopyEmailBody(txtBody.Text); objMail.SendEmail(strToEmail, strToName, strFromEmail, strFromName, null, null, lblSubject.Text, lblMailServer.Text, UserContext.UserData.OrgID, 0); this.lblMessage.Text = "Email sent to " + strToName + ". Please check!"; this.lblMessage.CssClass = "SuccessMessage"; } catch (Exception ex) { this.lblMessage.Text = ex.Message; } }
public void certemail(int intUserID, int intCourseID, int intProfileID) { int orgid; BusinessServices.User objUser = new BusinessServices.User(); DataTable dtUser = objUser.GetUser(intUserID); Int32.TryParse(dtUser.Rows[0]["OrganisationID"].ToString(), out orgid); string username = dtUser.Rows[0]["UserName"].ToString(); BusinessServices.AppConfig objAppConfig = new BusinessServices.AppConfig(); DataTable dtbAppConfig = objAppConfig.GetList(); string strHostname = HttpContext.Current.Request.Url.Authority.ToString(); bool isSSL = bool.Parse(dtbAppConfig.Select("Name='SSL'")[0]["Value"].ToString()); string strUrl = null; if (strHostname.ToLower().Equals("127.0.0.2")) { strUrl = "https://" + strHostname; } else { strUrl = "http://" + strHostname; } strUrl = "https://" + strHostname; //WriteErrorLog(strUrl.ToString()); OrganisationConfig objOrgConfig = new OrganisationConfig(); string strCss = objOrgConfig.GetOne(orgid, "css"); string pdfFileName = "cert_" + username + "_" + intCourseID.ToString() + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf"; bool status = HtmlToPdf.WKHtmlToPdf(strUrl + @"/Certificate.aspx?courseid=" + intCourseID + "&profileid=" + intProfileID + "&userid=" + intUserID + "&orgid=" + orgid + "&css=" + strCss, pdfFileName); string filename = ""; if (status) { filename = HttpContext.Current.Server.MapPath(ConfigurationSettings.AppSettings["WorkingFolder"]) + "\\" + pdfFileName; } else { ErrorLog objError = new ErrorLog(new Exception("Course completion certificate"), ErrorLevel.Medium, "DefaultQuiz.cs", "GenerateCourseCompletionCertificate", "Course completion certificate generation failed: " + pdfFileName); } sendCertEmail(intUserID, intCourseID, orgid, filename); try { FileInfo fileinfo = new FileInfo(filename); if (fileinfo.Exists) { File.Delete(filename); } } catch (Exception e) { ErrorLog objError = new ErrorLog(e, ErrorLevel.Medium, "DefaultQuiz.cs", "DeleteCourseCompletionCertificate", "Course completion certificate deletion failed: " + pdfFileName); } }
/// <summary> /// Get Pagination Data /// </summary> /// <returns></returns> private DataView GetPaginationData() { //Customize, and return DataView // conduct search based on criteria BusinessServices.User objUser = new BusinessServices.User(); DataSet dstResults = objUser.GetUnassigned(UserContext.UserData.OrgID); return(dstResults.Tables[0].DefaultView); }
} // StartPagination /// <summary> /// Gets the pagination data. /// </summary> /// <returns> DataView with all users that are SALT administrators.</returns> private DataView GetPaginationData() { // Get all SALT Administrators defined in the application but do not show the // currently logged on SALT Administrator BusinessServices.User objUser = new BusinessServices.User(); DataTable dtbAdmins = objUser.GetSALTAdministrators(UserContext.UserID, UserContext.UserData.OrgID); // Customize, and return DataView return(dtbAdmins.DefaultView); } // GetPaginationData
private void btnSendEmail_Click(object sender, System.EventArgs e) { string strSubject = txtsubject.Text; // get the subject string strEmailBodyTemplate = txtEmailBody.Text; // get the email text string strEmailBody = ""; string strEmailAddress; string strEmailToName; string strUsers =""; BusinessServices.Email objEmail = new BusinessServices.Email(); // Get the current users details. BusinessServices.User objUser = new BusinessServices.User(); DataTable dtbCurrentUserDetails = objUser.GetUser(UserContext.UserID); // Setup email header string strEmailFromName = dtbCurrentUserDetails.Rows[0]["FirstName"].ToString() + " " + dtbCurrentUserDetails.Rows[0]["LastName"].ToString(); string strEmailFromEmail = dtbCurrentUserDetails.Rows[0]["Email"].ToString(); // Validate that the user has a valid recipient, subject and body. if (this.txtUserIDs.Text.Length > 0 && strSubject.Length > 0 && strEmailBodyTemplate.Length > 0) { DataTable dtbUsers = objUser.GetEmails(this.txtUserIDs.Text); DataTable dtbEmailAddresses = objUser.GetEmails(this.txtUserIDs.Text); // For each user in the table foreach(DataRow drwEmailAddress in dtbEmailAddresses.Rows) { // get the email address strEmailAddress = drwEmailAddress.ItemArray[3].ToString(); // Get their Name strEmailToName = drwEmailAddress.ItemArray[0].ToString() + " " + drwEmailAddress.ItemArray[1].ToString(); // get userid int userID = 0; Int32.TryParse(drwEmailAddress["userID"].ToString(), out userID); objEmail.SetEmailBody(strEmailBodyTemplate, userID, "", "", "", "", "", "", "", ""); strSubject = objEmail.emailHeaderSub(strSubject); // Attempt to send them an email objEmail.SendEmail(strEmailAddress, strEmailToName, strEmailFromEmail, strEmailFromName, null, null, strSubject, ApplicationSettings.MailServer, UserContext.UserData.OrgID, userID); strUsers += "\n\t" + strEmailToName; } } // send the administrator email string strAdminEmail = GetEmailBody(EmailReportType.Email_Incomplete_CPD_Administrator); objEmail.SetEmailBody(strAdminEmail, UserContext.UserID, "", "", "", strUsers, "", "", "", ""); objEmail.SendEmail(strEmailFromEmail, strEmailFromName, strEmailFromEmail, strEmailFromName, null, null, strSubject, ApplicationSettings.MailServer, UserContext.UserData.OrgID, UserContext.UserID); // done this.plhReportResults.Visible=false; this.plhComplete.Visible=true; }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { if (CCUsers == null) { LoadInitialCCGrid(); } else { DataTable dtCCUsers = new DataTable(); DataColumn dc1 = new DataColumn("UserID"); DataColumn dc2 = new DataColumn("UserName"); dtCCUsers.Columns.Add(dc1); dtCCUsers.Columns.Add(dc2); if (CCUsers != null) { foreach (int userId in CCUsers) { BusinessServices.User user = new BusinessServices.User(); DataTable dtUser = user.GetUser(userId); DataRow dr = dtCCUsers.NewRow(); dr["UserID"] = (int)dtUser.Rows[0]["UserID"]; dr["UserName"] = dtUser.Rows[0]["UserName"].ToString(); dtCCUsers.Rows.Add(dr); } ccGridRowCount = dtCCUsers.Rows.Count; CCListGrid.DataSource = dtCCUsers.DefaultView; CCListGrid.DataBind(); if (CCListGrid.Rows.Count == 0) { lblCCNone.Visible = true; RemoveSelected.Visible = false; SelectAllCC.Visible = false; ClearAllCC.Visible = false; } else { lblCCNone.Visible = false; RemoveSelected.Visible = true; SelectAllCC.Visible = true; ClearAllCC.Visible = true; } } } SelectAll.Visible = false; ClearAll.Visible = false; AddSelected.Visible = false; } }
/// <summary> /// Get Data /// </summary> /// <returns></returns> private DataView GetData() { string strParentUnits; strParentUnits = String.Join(",", this.trvUnitsSelector.GetSelectedValues()); BusinessServices.User objUser = new BusinessServices.User(); DataTable dtbSearchResults = objUser.Search(UserContext.UserData.OrgID, strParentUnits, this.txtFirstName.Text, this.txtLastName.Text, this.txtUsername.Text, UserContext.UserID, this.chkInactiveUsers.Checked); return(dtbSearchResults.DefaultView); }
/// <summary> /// Item Command /// </summary> /// <param name="source"></param> /// <param name="e"></param> private void grdPagination_ItemCommand(object source, DataGridCommandEventArgs e) { // If user is resending the email if (e.CommandName.ToLower() == "resend") { BusinessServices.User objUser; int emailID = 0; // get the user FROM info (which is the currently logged in user) objUser = new BusinessServices.User(); DataTable dtbCurrentUser = objUser.GetUser(UserContext.UserID); // get the email ID and retrieve this email from the database Int32.TryParse(e.CommandArgument.ToString(), out emailID); BusinessServices.Email objEmail = new BusinessServices.Email(); DataTable dtbEmails = objEmail.Search(emailID, UserContext.UserData.OrgID); // only get the first (since there SHOULD only be one emailid) if (dtbEmails.Rows.Count != 0) { // get the user id for this email int userID = 0; Int32.TryParse(dtbEmails.Rows[0]["userid"].ToString(), out userID); string strEmailTo = dtbEmails.Rows[0]["toemail"].ToString(); string strNameTo = null; if (userID == 0) { // get the To name strNameTo = dtbEmails.Rows[0]["toname"] == null ? null : dtbEmails.Rows[0]["toname"].ToString(); } else { DataTable dtbUser = objUser.GetUser(userID); strNameTo = dtbUser.Rows[0]["FirstName"].ToString() + " " + dtbUser.Rows[0]["LastName"].ToString(); } string strEmailFrom = dtbCurrentUser.Rows[0]["email"].ToString(); string strNameFrom = dtbCurrentUser.Rows[0]["FirstName"].ToString() + " " + dtbCurrentUser.Rows[0]["LastName"].ToString(); string strBody = dtbEmails.Rows[0]["body"].ToString(); string strSubject = dtbEmails.Rows[0]["subject"].ToString(); // no need to do the subs here as its just trying to resend the email. objEmail.setUserCopyEmailBody(strBody); objEmail.SendEmail(strEmailTo, strNameTo, strEmailFrom, strNameFrom, null, null, strSubject, ApplicationSettings.MailServer, UserContext.UserData.OrgID, userID); this.lblMessage.Text = ResourceManager.GetString("lblMessage.EmailSent"); this.lblMessage.Visible = true; this.lblMessage.CssClass = "SuccessMessage"; } } }
/// <summary> /// Lists all modules in the selected course /// </summary> private void GetModuleAccess() { BusinessServices.User objUser = new BusinessServices.User(); int intCourseID = int.Parse(this.cboCourse.SelectedValue); DataTable dtbModules = objUser.GetModuleAccess(this.m_intUserID, intCourseID); //this.grdModules.DataSource = dtbModules; //this.grdModules.DataBind(); this.rptModuleList.DataSource = dtbModules; this.rptModuleList.DataBind(); }
private void PaintWelcomeMessage() { BusinessServices.User objUser = new BusinessServices.User(); DataTable dtblUserDetails = objUser.GetUser(UserContext.UserID); if (dtblUserDetails.Rows[0].ItemArray[1].ToString().Length != 0) { lblHomepagePersonalisation.Text = String.Format(ResourceManager.GetString("lblHi"), dtblUserDetails.Rows[0].ItemArray[1].ToString()); } else { lblHomepagePersonalisation.Text = ""; } this.lblHomepageWelcome.Text = String.Format(ResourceManager.GetString("lblHomepageWelcome"), Utilities.ApplicationSettings.AppName, Utilities.ApplicationSettings.TradeMark); }
/// <summary> /// Save User module access settings /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, System.EventArgs e) { string strGrantedModuleIDs; strGrantedModuleIDs = Request.Form["chkGrantedModule"]; int intCourseID = int.Parse(this.cboCourse.SelectedValue); BusinessServices.User objUser = new BusinessServices.User(); objUser.SaveModuleAccess(this.m_intUserID, intCourseID, strGrantedModuleIDs); this.GetModuleAccess(); this.lblMessage.Text = ResourceManager.GetString("lblMessage.Saved"); this.lblMessage.CssClass = "SuccessMessage"; }
/// <summary> /// Get Pagination Data /// </summary> /// <returns></returns> private DataView GetPaginationData() { BusinessServices.User objUser; DataTable dtbUsers; string strFirstName, strLastName; strFirstName = this.txtFirstName.Text.Trim(); strLastName = this.txtLastName.Text.Trim(); objUser = new BusinessServices.User(); dtbUsers = objUser.Search(UserContext.UserData.OrgID, null, strFirstName, strLastName, UserContext.UserID, false); return(dtbUsers.DefaultView); }
/// <summary> /// //Load user data and set user role (login User type) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Application_AuthenticateRequest(Object sender, EventArgs e) { if (HttpContext.Current.User != null) { if (HttpContext.Current.User.Identity.IsAuthenticated) { //Load user data and set user role (login User type) if (HttpContext.Current.User.Identity is FormsIdentity) { string strUserData; UserData objUserData; //1. Get Authentication Data strUserData = WebSecurity.GetAuthData(); objUserData = new UserData(strUserData); //2. Check whether user role has been changed(only check administrator) //if changed, signout and redirect to login page if (objUserData.UserType != UserType.User) { UserType enmUserType = UserType.User; BusinessServices.User objUser = new BusinessServices.User(); //try //{ int uid = UserContext.UserID; enmUserType = objUser.GetUserType(uid); //} //catch (Exception ex) //{ // throw new ApplicationException("Convert UserID to int32 failed, UserID = '" + UserContext.UserID.ToString() + "'"); //} if (enmUserType != objUserData.UserType) { WebSecurity.SignOut(); } } //3.Save the user data in the current context UserContext.UserData = objUserData; //4. Set User Roles (Login User type act as user role, they are: SaltAdmin = 1, OrgAdmin = 2, UnitAdmin = 3, User = 4 string[] roles = new string[1]; roles[0] = UserContext.UserData.UserType.ToString(); HttpContext.Current.User = new GenericPrincipal(HttpContext.Current.User.Identity, roles); } } } }
private int PeriodicReportCountUser(int UserId) { int OrgID = UserContext.UserData.OrgID; BusinessServices.User user = new BusinessServices.User(); DataTable dtUser = user.GetUser(UserId); String Username = dtUser.Rows[0]["UserName"].ToString(); string connectionString = ConfigurationSettings.AppSettings["ConnectionString"] + "password="******"password"] + ";"; PeriodicReportListDataContext prl = new PeriodicReportListDataContext(connectionString); ISingleResult <prcGetPeriodicReportListOnInactivateUserResult> result = prl.prcGetPeriodicReportListOnInactivateUser(OrgID, Username); var query = from pr in result.AsQueryable <prcGetPeriodicReportListOnInactivateUserResult>() select pr; return(query.Count <prcGetPeriodicReportListOnInactivateUserResult>()); }
/// <summary> /// Get Data /// </summary> /// <returns></returns> private DataView GetData() { string strParentUnits; int userID; strParentUnits = String.Join(",", this.trvUnitsSelector.GetSelectedValues()); // convert the user ID text to int bool result = Int32.TryParse(this.txtUserID.Text, out userID); if (!result) { userID = 0; } BusinessServices.User objUser = new BusinessServices.User(); DataTable dtbSearchResults = objUser.Search(UserContext.UserData.OrgID, strParentUnits, this.txtFirstName.Text, this.txtLastName.Text, this.txtUsername.Text, UserContext.UserID, this.chkInactiveUsers.Checked, this.txtEmail.Text, userID); return(dtbSearchResults.DefaultView); }
private void ReassignSelectedReports() { BusinessServices.Report report = new BusinessServices.Report(); BusinessServices.User user = new BusinessServices.User(); if ((Username != null) && (Username != "")) { int UserID = user.GetIdFromUsername(Username); foreach (KeyValuePair <int, int> keyvalue in SelectedForReassign) { report.ReassignReportInactive(keyvalue.Key, UserID, keyvalue.Value); } } else if (InactivatedUsernames.Count > 0) { foreach (string Uname in InactivatedUsernames) { int UserID = user.GetIdFromUsername(Uname); foreach (KeyValuePair <int, int> keyvalue in SelectedForReassign) { report.ReassignReportInactive(keyvalue.Key, UserID, keyvalue.Value); } } InactivatedUsernames = null; } else if (InactivatedEmails.Count > 0) { foreach (string email in InactivatedEmails) { int UserID = user.GetIdFromEmail(email); foreach (KeyValuePair <int, int> keyvalue in SelectedForReassign) { report.ReassignReportInactive(keyvalue.Key, UserID, keyvalue.Value); } } InactivatedEmails = null; } //LoadPeriodicReportsList(); SelectedForReassign = null; }
private void LoadUserList() { BusinessServices.User objUser = new BusinessServices.User(); DataTable dtbSearchResults = objUser.SearchAdminUsers(UserContext.UserData.OrgID, FirstNameTextBox.Text, LastNameTextBox.Text); UserCount = dtbSearchResults.Rows.Count; ReassignUserGrid.DataSource = dtbSearchResults.DefaultView; ReassignUserGrid.DataBind(); if (ReassignUserGrid.Rows.Count == 0) { lblUsersNone.Visible = true; } else { lblUsersNone.Visible = false; } }
protected void rptEmailList_ItemCommand(object sender, RepeaterCommandEventArgs e) { if (e.CommandName == "ResendEmail") { BusinessServices.User objUser; int intOrganisationID, emailID; // get the user TO info objUser = new BusinessServices.User(); DataTable dtbUser = objUser.GetUser(this.m_intUserID); intOrganisationID = (int)dtbUser.Rows[0]["OrganisationID"]; // get the user FROM info DataTable dtbCurrentUser = objUser.GetUser(UserContext.UserID); // convert the emailID text to int bool result = Int32.TryParse(e.CommandArgument.ToString(), out emailID); if (result) { BusinessServices.Email objEmail = new BusinessServices.Email(); DataTable dtbEmails = objEmail.Search(emailID, intOrganisationID); if (dtbEmails.Rows.Count != 0) { string strEmailTo = dtbEmails.Rows[0]["toemail"].ToString(); string strNameTo = dtbUser.Rows[0]["FirstName"].ToString() + " " + dtbUser.Rows[0]["LastName"].ToString(); string strEmailFrom = dtbCurrentUser.Rows[0]["email"].ToString(); string strNameFrom = dtbCurrentUser.Rows[0]["FirstName"].ToString() + " " + dtbCurrentUser.Rows[0]["LastName"].ToString(); string strBody = dtbEmails.Rows[0]["body"].ToString(); string strSubject = dtbEmails.Rows[0]["subject"].ToString(); objEmail.setUserCopyEmailBody(strBody); objEmail.SendEmail(strEmailTo, strNameTo, strEmailFrom, strNameFrom, null, null, strSubject, ApplicationSettings.MailServer, intOrganisationID, UserContext.UserID); this.lblMessage.Text = ResourceManager.GetString("lblMessage.EmailSent"); this.lblMessage.Visible = true; this.lblMessage.CssClass = "SuccessMessage"; } } } }
protected void Page_Load(object sender, EventArgs e) { if (UserContext.UserData.UserType == UserType.User) { Response.Redirect("~/Default.aspx"); } if ((Request.QueryString["user"] == null) && (Request.QueryString["isoninactivate"] != "true")) { PeriodicReportListControl prlc = (PeriodicReportListControl)Page.LoadControl("/Reporting/PeriodicReportListControl.ascx"); prlc.Username = ""; PeriodicReportListHolder.Controls.Add(prlc); } else if ((Request.QueryString["user"] != null) && (Request.QueryString["isoninactivate"] != "true")) { PeriodicReportListControl prlc = (PeriodicReportListControl)Page.LoadControl("/Reporting/PeriodicReportListControl.ascx"); int userId = 0; Int32.TryParse(Request.QueryString["user"].ToString(), out userId); BusinessServices.User user = new BusinessServices.User(); DataTable dtUser = user.GetUser(userId); prlc.Username = dtUser.Rows[0]["UserName"].ToString(); PeriodicReportListHolder.Controls.Add(prlc); } else if ((Request.QueryString["user"] == null) && (Request.QueryString["isoninactivate"] == "true")) { PeriodicReportInactiveListControl prilc = (PeriodicReportInactiveListControl)Page.LoadControl("/Reporting/PeriodicReportInactiveListControl.ascx"); prilc.IsOnInactivate = true; prilc.Username = ""; PeriodicReportListHolder.Controls.Add(prilc); } else if ((Request.QueryString["user"] != null) && (Request.QueryString["isoninactivate"] == "true")) { PeriodicReportInactiveListControl prilc = (PeriodicReportInactiveListControl)Page.LoadControl("/Reporting/PeriodicReportInactiveListControl.ascx"); prilc.IsOnInactivate = true; int userId = 0; Int32.TryParse(Request.QueryString["user"].ToString(), out userId); BusinessServices.User user = new BusinessServices.User(); DataTable dtUser = user.GetUser(userId); prilc.Username = dtUser.Rows[0]["UserName"].ToString(); PeriodicReportListHolder.Controls.Add(prilc); } }
protected void btnFinish_Click(object sender, System.EventArgs e) { int PolicyID = int.Parse(Request.QueryString["PolicyID"].ToString()); //int ProfileID = int.Parse(Request.QueryString["ProfileID"].ToString()); int UserID = UserContext.UserID; BusinessServices.User objUser = new BusinessServices.User(); DataTable dtUserProfiles = objUser.GetProfilePeriodList(UserID); BusinessServices.Policy objPolicy = new BusinessServices.Policy(); // Only want to do anything if user has read and understood the policy if (this.chkAgree.Checked) { // Check if policy marked as accepted // If not then mark user as accepted the policy if (!objPolicy.CheckAccepted(PolicyID, UserID)) { objPolicy.Accept(PolicyID, UserID); } // Check if points have already been assigned for this policy and user // If not then assign points for the policy to the user foreach (DataRow dr in dtUserProfiles.Rows) { int ProfileID = Int32.Parse(dr["ProfileID"].ToString()); if (!objPolicy.CheckPointsAssigned(PolicyID, UserID, ProfileID)) { if (objPolicy.CheckProfileExists(PolicyID, UserID, ProfileID)) { objPolicy.AssignPoints(PolicyID, UserID, ProfileID); } } } } Response.Redirect("/MyTraining.aspx"); //Response.Write("<script language='javascript'> {opener.location.reload(); self.close(); }</script>"); }
/// <summary> /// Load data the page is first loaded /// </summary> private void LoadData() { DateTime dteDateFrom, dteDateTo; BusinessServices.User objUser; DataTable dtbUser; string strName, strEmail; int intOrganisationID; objUser = new BusinessServices.User(); dtbUser = objUser.GetUser(this.m_intUserID); strName = dtbUser.Rows[0]["FirstName"].ToString() + " " + dtbUser.Rows[0]["LastName"].ToString(); strEmail = dtbUser.Rows[0]["Email"].ToString(); intOrganisationID = (int)dtbUser.Rows[0]["OrganisationID"]; // set to the past to search for emails from the beginning // maybe there is a better way to set to the beginning but right now use the hardcoded values dteDateFrom = new DateTime(1990, 1, 1); dteDateTo = DateTime.Now; BusinessServices.Email objEmail = new BusinessServices.Email(); DataTable dtbEmails = objEmail.SearchByUserID(this.m_intUserID, intOrganisationID); if (dtbEmails.Rows.Count == 0) { this.lblMessage.Text = ResourceManager.GetString("lblMessage.NoEmails"); this.lblMessage.CssClass = "WarningMessage"; this.lblMessage.Visible = true; } else { this.rptEmailList.DataSource = dtbEmails; this.rptEmailList.DataBind(); this.lblMessage.Visible = false; } }
public void ProcessRequest(HttpContext context) { int courseID = 0; if (context.Request.QueryString["CourseID"] != null) { bool result = Int32.TryParse(context.Request.QueryString["CourseID"], out courseID); if (result) { bool hasAccess = false; // flag to determine if the user has access to this course bool isSaltAdmin = false; BusinessServices.Course objCourse = new BusinessServices.Course(); // check if the user attempting to download this has valid permission/access to the course // Salt Administrator can download the file without restriction if (UserContext.UserData.UserType == UserType.SaltAdmin) { // Salt admin always have access isSaltAdmin = true; hasAccess = true; } else { // Course Object DataTable dtbCourses = objCourse.GetCourseListAccessableToUser(UserContext.UserID); // iterate to check if the user has access to this course foreach (DataRow row in dtbCourses.Rows) { int rowCourseID = 0; bool rslCourseID = Int32.TryParse(row["courseid"].ToString(), out rowCourseID); if (rslCourseID && rowCourseID == courseID) { // user has access, break from the loop hasAccess = true; break; } } } // get ebook details DataTable dtbEbook = objCourse.GetEbook(courseID, UserContext.UserData.OrgID); // if ebook exists if (dtbEbook.Rows.Count > 0) { string eBookPath = ConfigurationManager.AppSettings["EBookPath"]; // the location of the ebook in the server string eBookFile = context.Server.MapPath(eBookPath + dtbEbook.Rows[0]["ServerFileName"].ToString()); // the original filename of the ebook string eBookName = dtbEbook.Rows[0]["EbookFileName"].ToString(); // get the ebook id int ebookID = 0; bool rslEbookID = Int32.TryParse(dtbEbook.Rows[0]["ebookid"].ToString(), out ebookID); if (!rslEbookID) { ebookID = 0; // shouldn't be error... } // log the user's activity to download this ebook string userAgent = context.Request.UserAgent; BusinessServices.User objUser = new BusinessServices.User(); // detect the request to see if the user is using iPad if (!userAgent.ToLower().Contains("ipad") && !isSaltAdmin) { objUser.LogEbookDownload(UserContext.UserID, ebookID, userAgent, "unsupported device"); context.Response.Redirect("/General/Errors/NoSuchPage.aspx"); return; } // if the user has access to the course, we retrieve the ebook if (hasAccess) { // retrieve the file from the server FileInfo fileInfo = new FileInfo(eBookFile); try { if (fileInfo.Exists) { context.Response.Clear(); context.Response.AddHeader("Content-Disposition", "inline;filename=\"" + eBookName + "\""); context.Response.AddHeader("Content-Length", fileInfo.Length.ToString()); context.Response.ContentType = "application/epub+zip"; context.Response.TransmitFile(fileInfo.FullName); context.Response.Flush(); } } catch (Exception ex) { context.Response.Redirect("/General/Errors/NoSuchPage.aspx"); // log the user's ebook log with the error message objUser.LogEbookDownload(UserContext.UserID, ebookID, userAgent, ex.Message); } finally { context.Response.End(); objUser.LogEbookDownload(UserContext.UserID, ebookID, userAgent, "success"); } } else { // user has no access objUser.LogEbookDownload(UserContext.UserID, ebookID, userAgent, "no access"); } } } context.Response.Redirect("/General/Errors/NoSuchPage.aspx"); } }
/// <summary> /// Get Pagination Data /// </summary> /// <returns> DataView with all users that are not organisation administrators.</returns> private DataView GetPaginationData() { // Get the selected units // string strParentUnits = String.Join(",",this.trvUnitsSelector.GetSelectedValues()); BusinessServices.Unit objUnit = new BusinessServices.Unit(); string strParentUnits = String.Join(",", objUnit.ReturnAdministrableUnitsByUserID(UserContext.UserID, UserContext.UserData.OrgID, trvUnitsSelector.GetSelectedValues())); if (strParentUnits.Length == 0) { strParentUnits = null; } // Get the selected course and Complete / Incomplete status int intCourseID = Convert.ToInt32(cboCourse.SelectedValue); bool bolStatus = Convert.ToBoolean(optStatus.SelectedValue); // Gather date parts for historic date DateTime dtEffective; if ((this.lstEffectiveDay.SelectedValue.Length > 0) && (this.lstEffectiveMonth.SelectedValue.Length > 0) && (this.lstEffectiveYear.SelectedValue.Length > 0)) { dtEffective = new DateTime(int.Parse(this.lstEffectiveYear.SelectedValue), int.Parse(this.lstEffectiveMonth.SelectedValue), int.Parse(this.lstEffectiveDay.SelectedValue)); if (dtEffective.CompareTo(System.DateTime.Today) >= 1) { // Can't provide a historic date in the future throw new ArgumentOutOfRangeException(); } } else { dtEffective = DateTime.MinValue; } // Execute the report BusinessServices.Report objReport = new BusinessServices.Report(); DataTable dtblReport = objReport.GetCompletedUsersReport(UserContext.UserData.OrgID, strParentUnits, intCourseID, dtEffective, bolStatus); if (dtblReport.Rows.Count == 0) { this.lblError.Visible = true; this.lblError.Text += ResourceManager.GetString("lblError.NoUsers"); //"No users found."; this.lblError.CssClass = "FeedbackMessage"; } else { BusinessServices.User objUser = new BusinessServices.User(); DataTable dtbUser = objUser.GetUser(UserContext.UserID); if (dtbUser.Rows.Count > 0) { // Display Report Criteria this.ucCriteria.Criteria.Add(ResourceManager.GetString("ReportRunBy"), dtbUser.Rows[0]["LastName"].ToString() + ", " + dtbUser.Rows[0]["FirstName"].ToString()); this.ucCriteria.Criteria.Add(ResourceManager.GetString("ReportRunAt"), DateTime.Now.ToString("dd/MM/yyyy") + " " + DateTime.Now.ToLongTimeString()); } if (trvUnitsSelector.GetSelectedValues().Length == 0) { this.ucCriteria.AddUnits(null); } else { this.ucCriteria.AddUnits(strParentUnits); } this.ucCriteria.AddCourses(intCourseID.ToString()); if (bolStatus) { this.ucCriteria.Criteria.Add(ResourceManager.GetString("cmnStatus"), ResourceManager.GetString("optStatus.1")); } else { this.ucCriteria.Criteria.Add(ResourceManager.GetString("cmnStatus"), ResourceManager.GetString("optStatus.2")); } if (dtEffective != DateTime.MinValue) { this.ucCriteria.Criteria.Add(ResourceManager.GetString("EffectiveDate"), dtEffective.ToString("dd/MM/yyyy")); } else { this.ucCriteria.Criteria.Add(ResourceManager.GetString("EffectiveDate"), DateTime.Now.ToString("dd/MM/yyyy")); } this.ucCriteria.Render(); } //Customize, and return DataView return(dtblReport.DefaultView); }
protected void btnCPDExportpdf_Click(object sender, EventArgs e) { try { BusinessServices.User objUser = new BusinessServices.User(); DataTable dtUser = objUser.GetUser(UserContext.UserID); string username = dtUser.Rows[0]["UserName"].ToString(); string strHostname = HttpContext.Current.Request.Url.Authority.ToString(); string strUrl = null; if (strHostname.ToLower().Equals("127.0.0.2")) { strUrl = "https://" + strHostname; } else { strUrl = "http://" + strHostname; } strUrl = "https://" + strHostname; // strUrl = "http://" + strHostname; --use http for demosite string pdfFileName = "PersonalReport_" + username + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf"; //bool status = HtmlToPdf.WKHtmlToPdf(strUrl + @"/Reporting/Individual/TestCPD.aspx", pdfFileName); //WebClient client = new WebClient(); //String htmlCode = client.DownloadString(strUrl + @"/Reporting/Individual/ExportCPDProfileReport.aspx"); ////Session["htmlContent"] = htmlCode; //Globals.MyGlobalValue = ""; //Globals.MyGlobalValue = htmlCode; //bool status = HtmlToPdf.WKHtmlToPdf(strUrl + @"/Reporting/Individual/TestCPD.aspx", pdfFileName); //bool status = HtmlToPdf.WKHtmlToPdf(strUrl + @"/Reporting/Individual/TestCPD.aspx", pdfFileName); //bool status = HtmlToPdf.WKHtmlToPdf(@"http://demo.saltcompliance.com/Reporting/Individual/TestCPD.aspx", pdfFileName); bool status = HtmlToPdf.WKHtmlToPdf(strUrl + @"/Reporting/Individual/ExportCPDProfileReport.aspx?UserId=" + UserContext.UserID + "&OrgID=" + UserContext.UserData.OrgID, pdfFileName); string filename = ""; if (status) { filename = HttpContext.Current.Server.MapPath(ConfigurationSettings.AppSettings["WorkingFolder"]) + "\\" + pdfFileName; } else { ErrorLog objError = new ErrorLog(new Exception("Export to PDF"), ErrorLevel.Medium, "IndividualReport.cs", "btnCPDExportpdf_Click", "Export to PDF generation failed: " + pdfFileName); } FileInfo fileInfo = new FileInfo(filename); try { if (fileInfo.Exists) { Response.Clear(); Response.Buffer = true; Response.ClearHeaders(); Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition", "attachment; filename=" + pdfFileName + ""); Response.TransmitFile(Server.MapPath("~/General/wkhtmltopdf/" + pdfFileName)); Response.Flush(); } try { FileInfo fileinfo = new FileInfo(filename); if (fileinfo.Exists) { File.Delete(filename); } } catch (Exception ex) { ErrorLog objError = new ErrorLog(new Exception("Export to PDF"), ErrorLevel.Medium, "IndividualReport.cs", "btnCPDExportpdf_Click", "Delete Personal Report PDF failed: " + pdfFileName); } } catch (Exception ex) { } } catch (Exception Ex) { ErrorHandler.ErrorLog Error = new ErrorHandler.ErrorLog(Ex, ErrorLevel.Medium, "IndividualReport.cs", "btnCPDExportpdf_Click", "Export to PDF"); throw (Ex); } }
/// <summary> /// Get Pagination Data /// </summary> /// <returns></returns> private DataView GetPaginationData() { // Customize, and return DataView // conduct search based on criteria Report objReport = new Report(); string[] astrUnits; string strUnits; string strCourse; strCourse = ""; strUnits = ""; DataTable dtbResults = new DataTable(); this.lblError.Text = ""; this.lblError.Visible = false; try { BusinessServices.Unit objUnit = new BusinessServices.Unit(); astrUnits = objUnit.ReturnAdministrableUnitsByUserID(UserContext.UserID, UserContext.UserData.OrgID, this.trvUnitsSelector.GetSelectedValues()); // Convert array back to a csv string. foreach (string strUnit in astrUnits) { strUnits += strUnit + ","; } if (astrUnits.Length > 0) { strUnits = strUnits.Substring(0, strUnits.Length - 1); } else { strUnits = null; } strCourse = cboCourses.SelectedValue; if (strCourse.Length > 0) { dtbResults = objReport.GetTrendReport(UserContext.UserData.OrgID, strUnits, Convert.ToInt32(strCourse)); if (dtbResults.Rows.Count == 0) { this.lblError.Text += ResourceManager.GetString("lblError.NoUser"); //"No users found"; this.lblError.Visible = true; } else { this.plhSearchCriteria.Visible = false; this.plhReportResults.Visible = true; BusinessServices.User objUser = new BusinessServices.User(); DataTable dtbUser = objUser.GetUser(UserContext.UserID); if (dtbUser.Rows.Count > 0) { // Display Report Criteria this.ucCriteria.Criteria.Add(ResourceManager.GetString("Reportrunby"), dtbUser.Rows[0]["LastName"].ToString() + ", " + dtbUser.Rows[0]["FirstName"].ToString()); this.ucCriteria.Criteria.Add(ResourceManager.GetString("Reportrunat"), DateTime.Now.ToString("dd/MM/yyyy") + " " + DateTime.Now.ToLongTimeString()); } if (trvUnitsSelector.GetSelectedValues().Length == 0) { this.ucCriteria.AddUnits(null); } else { this.ucCriteria.AddUnits(strUnits); } this.ucCriteria.AddCourses(strCourse); this.ucCriteria.Render(); BusinessServices.Course objCourse = new Course(); DataTable dtbCourseDetails = objCourse.GetCourse(Int32.Parse(strCourse), UserContext.UserData.OrgID); this.lblPageTitle.Text = String.Format(ResourceManager.GetString("lblPageTitle.1"), dtbCourseDetails.Rows[0]["Name"].ToString());//"Trend Report - " + dtbCourseDetails.Rows[0]["Name"].ToString(); plhSearchCriteria.Visible = false; plhReportResults.Visible = true; lblError.Visible = false; } } else { lblError.Visible = true; lblError.Text = ResourceManager.GetString("lblError.OnCourse"); //"You must select at least one course."; } } catch (Exception Ex) { ErrorLog Error = new ErrorLog(Ex, ErrorLevel.Medium, "TrendReport.aspx", "btnGenerate_Click", ""); throw (Ex); } return(dtbResults.DefaultView); }
/// <summary> /// Compiles the list of users to which the email should be sent, /// and attempts to send it to that list + anyone on the CC list /// + the current user. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSendEmail_Click(object sender, System.EventArgs e) { string strUnitIDs = ""; string strUserIDs = ""; lblError.Text = ""; try { // Get selected units BusinessServices.Unit objUnit = new BusinessServices.Unit(); string[] astrUnitIDs = astrUnitIDs = objUnit.ReturnAdministrableUnitsByUserID(UserContext.UserID, UserContext.UserData.OrgID, trvUnitsSelector.GetSelectedValues()); foreach (string strUnit in astrUnitIDs) { strUnitIDs += strUnit + ","; } if (strUnitIDs.Length > 0) { strUnitIDs = strUnitIDs.Substring(0, strUnitIDs.Length - 1); } // Get users DataTable dtbResults = new Email().GetUsersToEmail(UserContext.UserData.OrgID, strUnitIDs); foreach (DataRow drwUser in dtbResults.Rows) { strUserIDs += drwUser.ItemArray[0].ToString() + ","; } if (strUserIDs.Length > 0) { strUserIDs = strUserIDs.Substring(0, strUserIDs.Length - 1); } // Validate that the user has a valid recipient, subject and body. if (strUserIDs.Length > 0 && this.txtEmailSubject.Text.Length > 0 && this.txtEmailBody.Text.Length > 0) { // Config BusinessServices.AppConfig objAppConfig = new BusinessServices.AppConfig(); DataTable dtbAppConfig = objAppConfig.GetList(); this.lblError.Text = ""; // Email setup BusinessServices.User objUser = new BusinessServices.User(); DataTable dtbCurrentUserDetails = objUser.GetUser(UserContext.UserID); string strEmailFromName = dtbCurrentUserDetails.Rows[0]["FirstName"].ToString() + " " + dtbCurrentUserDetails.Rows[0]["LastName"].ToString(); string strEmailFromEmail = dtbCurrentUserDetails.Rows[0]["Email"].ToString(); string strEmailSubject = this.txtEmailSubject.Text; string strUsers = "\n\nSent To:"; BusinessServices.Email objEmail = new BusinessServices.Email(); // target users string strEmailToName = ""; string strEmailToEmail = ""; DataTable dtbEmailAddresses = objUser.GetEmails(strUserIDs); foreach (DataRow drwEmailAddress in dtbEmailAddresses.Rows) { strEmailToEmail = drwEmailAddress.ItemArray[3].ToString(); strEmailToName = drwEmailAddress.ItemArray[0].ToString() + " " + drwEmailAddress.ItemArray[1].ToString(); int intUserId = Int32.Parse(drwEmailAddress.ItemArray[1].ToString()); objEmail.SetEmailBody(this.txtEmailBody.Text, intUserId, "", "", "", "", "", "", "", ""); strEmailSubject = objEmail.emailHeaderSub(strEmailSubject); objEmail.SendEmail(strEmailToEmail, strEmailToName, strEmailFromEmail, strEmailFromName, null, null, strEmailSubject, ApplicationSettings.MailServer, UserContext.UserData.OrgID, intUserId); // accumulate user list to append to current user email strUsers += "\n\t" + strEmailToName; } // CC list. string strEmailCCName = ""; strUsers += "\n\nCC:"; foreach (string addr in this.txtCC.Text.Split(new char[] { ',', ';' })) { string strEmailCCEmail = addr.Trim(); if (strEmailCCEmail != "") { try { objEmail.SendEmail(strEmailCCEmail, strEmailCCName, strEmailFromEmail, strEmailFromName, null, null, strEmailSubject, ApplicationSettings.MailServer, UserContext.UserData.OrgID, 0); strUsers += "\n\t" + strEmailCCEmail; } catch (Exception) { objEmail.setCCSendError(strEmailCCEmail); objEmail.SendEmail(strEmailFromEmail, strEmailFromName, strEmailFromEmail, strEmailFromName, null, null, "Error sending mail to CC recipient", ApplicationSettings.MailServer, UserContext.UserData.OrgID, UserContext.UserID); } } } // copy to Current user objEmail.setUserCopyEmailBody(this.txtEmailBody.Text + strUsers); objEmail.SendEmail(strEmailFromEmail, strEmailFromName, strEmailFromEmail, strEmailFromName, null, null, strEmailSubject, ApplicationSettings.MailServer, UserContext.UserData.OrgID, UserContext.UserID); this.plhEditEmail.Visible = false; this.plhComplete.Visible = true; } else { lblError.Text = ResourceManager.GetString("lblError.OneRecip"); //"To send an email you must have at least one recipient, an email subject and an email body."; this.lblError.CssClass = "WarningMessage"; } } catch (Exception ex) { //Catch and throw error ErrorLog objError = new ErrorLog(ex, ErrorLevel.High, "EmailUsers.aspx.cs", "btnSendEmail_Click", "General error occurred attempting to send email"); throw (ex); } }