/// <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"; } } }
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; } }
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"; } }
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); } }
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 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 (!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; } }
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); }
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>()); }
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); } }
/// <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; } }
/// <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); } }
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> 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); }
private void ReloadPeriodicReportList() { // remove from grid only (not from DB) as Save is not yet clicked DataTable dtReports = new DataTable(); DataColumn dc1 = new DataColumn("ScheduleID"); DataColumn dc2 = new DataColumn("UserID"); DataColumn dc3 = new DataColumn("ReportID"); DataColumn dc4 = new DataColumn("ReportTitle"); DataColumn dc5 = new DataColumn("Username"); DataColumn dc6 = new DataColumn("ReportName"); DataColumn dc7 = new DataColumn("ReportFrequency"); dtReports.Columns.Add(dc1); dtReports.Columns.Add(dc2); dtReports.Columns.Add(dc3); dtReports.Columns.Add(dc4); dtReports.Columns.Add(dc5); dtReports.Columns.Add(dc6); dtReports.Columns.Add(dc7); foreach (GridViewRow row in PeriodicReportsGrid.Rows) { int schId = 0; Int32.TryParse(PeriodicReportsGrid.DataKeys[row.RowIndex].Values["ScheduleID"].ToString(), out schId); if (!SelectedForDelete.Keys.Contains(schId)) { DataRow dr = dtReports.NewRow(); int scheduleId = 0; Int32.TryParse(PeriodicReportsGrid.DataKeys[row.RowIndex].Values["ScheduleID"].ToString(), out scheduleId); dr["ScheduleID"] = scheduleId; int ReportID = 0; Int32.TryParse(PeriodicReportsGrid.DataKeys[row.RowIndex].Values["ReportID"].ToString(), out ReportID); dr["ReportID"] = ReportID; dr["ReportTitle"] = ((HyperLink)(PeriodicReportsGrid.Rows[row.RowIndex].Cells[4].Controls[0])).Text; int UserID = 0; Int32.TryParse(PeriodicReportsGrid.DataKeys[row.RowIndex].Values["UserID"].ToString(), out UserID); string username = PeriodicReportsGrid.Rows[row.RowIndex].Cells[5].Text; if (SelectedForReassign.Keys.Contains(scheduleId)) { int userId = 0; SelectedForReassign.TryGetValue(scheduleId, out userId); UserID = userId; BusinessServices.User user = new BusinessServices.User(); DataTable dtUser = user.GetUser(userId); username = dtUser.Rows[0]["Username"].ToString(); } dr["UserID"] = UserID; dr["Username"] = username; dr["ReportName"] = PeriodicReportsGrid.Rows[row.RowIndex].Cells[6].Text; dr["ReportFrequency"] = PeriodicReportsGrid.Rows[row.RowIndex].Cells[7].Text; dtReports.Rows.Add(dr); } } DataView dvReports = dtReports.DefaultView; PeriodicReportsGrid.DataSourceID = null; PeriodicReportsGrid.DataSource = dvReports; PeriodicReportsGrid.DataBind(); if (PeriodicReportsGrid.Rows.Count == 0) { lblNoneFound.Visible = true; SelectAll.Visible = false; ClearAll.Visible = false; DeleteSelected.Visible = false; ReassignSelected.Visible = false; } else { lblNoneFound.Visible = false; SelectAll.Visible = true; ClearAll.Visible = true; DeleteSelected.Visible = true; ReassignSelected.Visible = true; } }