public static void SendMailReport(string reportName, string reportTitle, List <ParameterValue> parameters, string company, string emailTo, string Subject, string body) { string deviceInfo = null; string extension = string.Empty; string mimeType = string.Empty; string encoding = string.Empty; Warning[] warnings = null; string[] streamIDs = null; string historyId = null; Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-us"); // Create a Report Execution object var rsExec = new ReportExecutionService() { ExecutionHeaderValue = new ExecutionHeader(), Timeout = Timeout.Infinite }; rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials; rsExec.Url = ReportServer + "/ReportExecution2005.asmx"; // Load the report ExecutionInfo execInfo = rsExec.LoadReport("/Report/" + reportName, historyId); TblCompany companyRow; using (var context = new WorkFlowManagerDBEntities()) { companyRow = context.TblCompanies.FirstOrDefault(x => x.DbName == company); } string Ip = companyRow.Ip + companyRow.Port; foreach (var item in execInfo.Parameters) { try { if (item.Name == "Ip" && !string.IsNullOrWhiteSpace(Ip)) { parameters.Add(new ParameterValue() { Name = item.Name, Value = Ip }); continue; } if (item.Name == "Database" && !string.IsNullOrWhiteSpace(company)) { parameters.Add(new ParameterValue() { Name = item.Name, Value = company }); continue; } //parameters.Add(new Microsoft.Reporting.WebForms.ReportParameter(item.Name, para[count])); } catch (Exception) { } } rsExec.SetExecutionParameters(parameters.ToArray(), "en-us"); // get pdf of report byte[] results = rsExec.Render("PDF", deviceInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs); //Walla...almost no code, it's easy to manage and your done. //Take the bytes and add as an attachment to a MailMessage(SMTP): var attach = new Attachment(new MemoryStream(results), string.Format("{0}.pdf", reportTitle)); string emailFrom; var service = new GlOperations.GlService(); try { emailFrom = service.GetRetailChainSetupByCode("CashDepositeFromMail", company).sSetupValue; } catch (Exception ex) { new AssistanceService().SaveLog(JsonConvert.SerializeObject(ex), 0); emailFrom = "*****@*****.**"; } SendEmail(attach, emailFrom, emailTo.Split(';').ToList(), Subject, body); }
public int UpdateNewUsersRequest(NewUserRequests UserRequest) { int Result = 0; string dbName = ""; TblAuthUser LikeUser = new TblAuthUser(); using (var context = new WorkFlowManagerDBEntities()) { var currentUserRequest = context.TblAddUserRequests.FirstOrDefault (x => x.UserCreateRequestID == UserRequest.UserCreateRequestID && x.NewUserID == UserRequest.NewUserID & x.NewUserCompanyID == UserRequest.NewUserCompanyID); currentUserRequest.Approved = UserRequest.Approved; currentUserRequest.Rejected = UserRequest.Rejected; currentUserRequest.ApproveDate = DateTime.Now; /*************************************Approved User*********************************/ if (currentUserRequest.Approved == "1") { LikeUser = context.TblAuthUsers.FirstOrDefault(x => x.PayrollCode == UserRequest.LikeUserID); int _NewUserCompanyID = int.Parse(UserRequest.NewUserCompanyID); dbName = context.TblCompanies.FirstOrDefault(x => x.Iserial == _NewUserCompanyID).DbName; //Create New User Login TblAuthUser CreateNewUser = new TblAuthUser(); CreateNewUser.UserName = currentUserRequest.UserName; CreateNewUser.UserPassword = currentUserRequest.UserPassword; CreateNewUser.Code = string.Format(@"{0}{1}", currentUserRequest.NewUserID, currentUserRequest.NewUserCompanyID); CreateNewUser.TblCompany = int.Parse(currentUserRequest.NewUserCompanyID); CreateNewUser.PayrollCode = currentUserRequest.NewUserID; CreateNewUser.Ename = currentUserRequest.UserName; CreateNewUser.Aname = currentUserRequest.UserName; CreateNewUser.TblJob = LikeUser.TblJob; CreateNewUser.CurrLang = LikeUser.CurrLang; context.TblAuthUsers.AddObject(CreateNewUser); } context.SaveChanges(); } if (UserRequest.Approved == "1" && UserRequest.IsSalesPerson == "1") { Operations.GlOperations.GlService service = new Operations.GlOperations.GlService(); using (var newContext = new ccnewEntities(service.GetSqlConnectionString(dbName))) { TBLSalesPerson newRow = new TBLSalesPerson(); int NextSerial = newContext.TBLSalesPersons.Select(x => x.ISerial).Max(); newRow.ISerial = NextSerial + 1; newRow.Ename = UserRequest.UserName; newRow.Aname = UserRequest.UserName; newRow.Code = UserRequest.NewUserID; newContext.TBLSalesPersons.AddObject(newRow); if (UserRequest.IsRetailPerson == "1") { TblUser newUser = new TblUser(); TblUser oldUser = newContext.TblUsers.FirstOrDefault(x => x.Code == UserRequest.LikeUserID); try { int NextUserSerial = newContext.TblUsers.Select(x => x.iserial).Max(); newUser.iserial = NextUserSerial + 1; newUser.Ename = UserRequest.UserName; newUser.Aname = UserRequest.UserName; newUser.Code = UserRequest.NewUserID; newUser.UserPassword = UserRequest.UserPassword; newUser.TblJob = oldUser.TblJob; newUser.Active = oldUser.Active; newUser.CurrLang = oldUser.CurrLang; newUser.ReportFont = oldUser.ReportFont; newUser.ActiveCashMach = oldUser.ActiveCashMach; newUser.ActiveStore = oldUser.ActiveStore; newUser.RegNo = oldUser.RegNo; newUser.AllowedStores = oldUser.AllowedStores; newUser.AllowedStoresTo = oldUser.AllowedStoresTo; newContext.TblUsers.AddObject(newUser); } catch { } } newContext.SaveChanges(); } AddUserToActiveDirectory(UserRequest); } return(Result); }