Subscribe to DNN User Login Events - dotnetnuke

I'm trying to hook into DNN User Authenticated Event by implementing IUserEventHandlers. DNN is not trigerring the event.
public interfaceIUserEventHandlers
{
void UserAuthenticated(object sender, UserEventArgs args);
void UserCreated(object sender, UserEventArgs args);
void UserDeleted(object sender, UserEventArgs args);
void UserRemoved(object sender, UserEventArgs args);
void UserApproved(object sender, UserEventArgs args);
}
How to hook into DNN Login Authenticated Event?

This should do. Delete the unnecessary 'using'
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualBasic;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Services.Mail;
using DotNetNuke.Services.Social.Notifications;
using System.ComponentModel.Composition;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Entities.Profile;
using DotNetNuke.Entities.Tabs.Actions;
using DotNetNuke.Security.Roles;
using DotNetNuke.Services.FileSystem.EventArgs;
using DotNetNuke.Services.Log.EventLog;
using System.Net;
// For this I added a reference to the System.ComponentModel.Composition.dll
namespace TestProject.DotNetNuke.Entities.Users
{
[Export(typeof(IUserEventHandlers))]
public class UserEventHandlers : IUserEventHandlers
{
private void IUserEventHandlers_UserCreated(object sender, UserEventArgs args)
{
var x = "d";
}
private void IUserEventHandlers_UserDeleted(object sender, UserEventArgs args)
{
var x = "d";
}
public void IUserEventHandlers_UserAuthenticated(object sender, UserEventArgs args)
{
var x = "d";
}
public void IUserEventHandlers_UserUpdated(object sender, UpdateUserEventArgs args)
{
var x = "d";
}
private void IUserEventHandlers_UserRemoved(object sender, UserEventArgs args)
{
var x = "d";
}
private void IUserEventHandlers_UserApproved(object sender, UserEventArgs args)
{
System.Net.Mail.SendMail(args.User, MessageType.UserRegistrationPublic, PortalSettings.Current);
DeleteAllNotifications(args.User.UserID);
}
private void DeleteAllNotifications(int userId)
{
var nt = NotificationsController.Instance.GetNotificationType("NewUnauthorizedUserRegistration");
var notifications = NotificationsController.Instance.GetNotificationByContext(nt.NotificationTypeId, userId.ToString(CultureInfo.InvariantCulture));
foreach (var notification in notifications)
NotificationsController.Instance.DeleteNotification(notification.NotificationID);
}
}
}

Related

WinForms: DataGridView with E.F. does not show New Row

I have a simple WinForm with a DataGridView that shows record with Entity Framework.
My problem is that New Row feature appears only if the DataGridView is empty.
How is the problem?
Thank you in advance.
Luis
PS
Here some details of the WinForm class:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using GestioneFormazione;
namespace MpFormazione
{
public partial class MpFormazione : Form
{
public MpFormazione()
{
InitializeComponent();
this.dataGridView1.CellClick += DataGridView1_CellClick;
this.dataGridView1.AllowUserToAddRows = true;
this.dataGridView1.VirtualMode = true;
this.dataGridView1.AutoGenerateColumns = false;
}
private void DataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == this.ButtonColumunIndex)
{
if (e.RowIndex == 0)
{
Cliente cliente = new Cliente();
cliente.ID = Guid.NewGuid();
if (dataGridView1.Rows[0].Cells[1].Value != null)
cliente.Nome = dataGridView1.Rows[0].Cells[1].Value.ToString();
SaveToDb(cliente);
}
}
}
private void SaveToDb(Cliente cliente)
{
using (var context = new MPFORMAZIONEEntities())
{
context.Cliente.Add(cliente);
context.SaveChanges();
}
}
private void clienteBindingSource_CurrentChanged(object sender, EventArgs e)
{
}
private void ClienteBindingSource_AddingNew(object sender, System.ComponentModel.AddingNewEventArgs e)
{
}
private int ButtonColumunIndex
{
get
{
return 2;
}
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void MpFormazione_Load(object sender, EventArgs e)
{
using (var context = new MPFORMAZIONEEntities())
{
this.dataGridView1.DataSource = context.Cliente.ToList<Cliente>();
}
}
}
}
The page has only this code, and the Entity Framework for "Cliente" and "Dipendente" entities.

I want to covert the datagridview into an ini file after inputting the data

I want to covert the datagridview into an ini file after inputting the data.
http://www.hoons.net/Board/qacshap/Content/67073
When I enter the URL above,
I try to put data into the grid and press the export button to save it as an .ini file in the form of section, key, value. What should I do? Inside the code, the content is created as an ini file, but not as a grid.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
namespace EXPORT
{
public partial class Form1 : DevExpress.XtraEditors.XtraForm
{
[DllImport('kernel32')]
public static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport('kernel32')]
public static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
static string path = 'C:\\Test.ini';
public Form1()
{
InitializeComponent();
dataGridView1.AllowUserToAddRows =true; //자동 행 추가
dataGridView1.AutoGenerateColumns = false;
}
private void button1_Click(object sender, EventArgs e)
{
WritePrivateProfileString('SECTION', 'KEY', 'VALUE', #'C:\ConnectionInfo.ini');
MessageBox.Show('EXPORT successfully to *.INI format');
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void WriteInFile(string section,string key,string value,string path)
{
WritePrivateProfileString(section, key, value, path);
if (value == null)
{
throw new ArgumentException();
}
}
private void button2_Click(object sender, EventArgs e) //ADD_ROW Button
{
DataGridViewButtonColumn button = new DataGridViewButtonColumn();
{
dataGridView1.Rows.Add();
}
}
}
}
You can use my MadMilkman.Ini library for this, here is how:
private void button1_Click(object sender, EventArgs e)
{
IniFile iniFile = new IniFile();
IniSection iniSection = null;
foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
if (row.IsNewRow)
break;
string section = row.Cells[0].Value?.ToString();
string key = row.Cells[1].Value.ToString();
string value = row.Cells[2].Value.ToString();
if (!string.IsNullOrEmpty(section))
iniSection = iniFile.Sections.Add(section);
iniSection.Keys.Add(key, value);
}
iniFile.Save("C:\\Test.ini");
}
Also, here is how the generated "Test.ini" file looks like:
[a]
123=456
789=234
345=678
[b]
123=456
789=234
345=678

Need to click on a button in iFrame page

I am trying to click on "btnPunch". This button is located in an iFrame. I am unable to make this work. I have used the Selenium IDE to record this button being clicked and created a DLL that also runs this process in NUnit without a problem. Any help would be appreciated after three months of working on this.
Thank you
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Threading;
using NUnit.Framework;
using Selenium;
using OpenQA.Selenium.IE;
using OpenQA.Selenium;
namespace TimeClockEntry
{
public partial class PNow : Form
{
IWebDriver driver = new InternetExplorerDriver();
//driver = new InternetExplorerDriver();
//private ISelenium selenium;
//private StringBuilder verificationErrors;
//public void SetupTest()
//{
// selenium = new DefaultSelenium("localhost", 4444, "*chrome", "https://ew23.ultipro.com/");
// selenium.Start();
// verificationErrors = new StringBuilder();
//}
int linkcount = 0;
string userName;
string passWord;
public PNow()
{
InitializeComponent();
webBrowser1.Navigate("https://ew23.ultipro.com/login.aspx");
}
private void PNow_Load(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Normal;
userName = Properties.Settings.Default.userName;
passWord = Properties.Settings.Default.passWord;
}
private void PNow_FormClosed(object sender, FormClosedEventArgs e)
{
this.Hide();
welcome f1 = new welcome();
f1.ShowDialog();
this.Close();
}
protected override void OnLostFocus(EventArgs e)
{
base.OnLostFocus(e);
this.Focus();
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
linkcount++;
if (linkcount == 1)
{
webBrowser1.Document.GetElementById("ctl00_Content_Login1_UserName").SetAttribute("value", userName);
webBrowser1.Document.GetElementById("ctl00_Content_Login1_Password").SetAttribute("value", passWord);
webBrowser1.Document.GetElementById("ctl00_Content_Login1_LoginButton").InvokeMember("click");
}
if (linkcount == 2)
{
HtmlElement link = (from HtmlElement elem in webBrowser1.Document.GetElementsByTagName("a")
where elem.InnerHtml == "Time Clock Entry"
select elem).ElementAt(0);
link.InvokeMember("Click");
}
if (linkcount == 3)
{
// driver.FindElement(By.Id("btnPunch")).Click();
webBrowser1.Document.GetElementById("ctl00_Content_lnkLogout").InvokeMember("click");
this.Close();
}
}
}
}
You can try this also:-
if (linkcount == 3)
{
WebElement frameSwitch = driver.findElement(By.xpath("Xpath of iframe")); //Frame Xpath
driver.switchTo().frame(frameSwitch);
driver.FindElement(By.Id("btnPunch")).Click();
webBrowser1.Document.GetElementById("ctl00_Content_lnkLogout").InvokeMember("click");
driver.switchTo().defaultContent();
this.Close();
}
Try this.
if (linkcount == 3)
{
//get back to basic html source.
driver.SwitchTo().DefaultContent();
//switch to new frame
driver.SwitchTo().Frame("<FRAME NAME OR ID>");
driver.FindElement(By.Id("btnPunch")).Click();
}

Devexpress: An object reference is required for the non-static field

I keep getting this error in my devexpress code.
Here is the code I have put in:
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Drawing.Printing;
namespace DD
{
public partial class MasterReport : DevExpress.XtraReports.UI.XtraReport
{
//detailReport.catName.Value = ((DataRowView)e.Brick.Value).Row["EcoYear"].ToString();
public MasterReport()
{
InitializeComponent();
}
private void xrLabel1_BeforePrint(object sender, PrintEventArgs e)
{
// XRLabel l = sender as XRLabel;
// l.Tag = GetCurrentRow();
((XRLabel)sender).Tag = GetCurrentRow();
}
private void xrLabel1_PreviewClick(object sender, PreviewMouseEventArgs e)
{
DetailReport detailReport = new DetailReport();
detailReport.CaID.Value = (int)((DataRowView)e.Brick.Value).Row["CaseID"];
detailReport.EYear.Value = (int)((DataRowView)e.Brick.Value).Row["EcoYear"];
detailReport.ShowPreviewDialog();
}
private void xrLabel1_PreviewMouseMove(object sender, PreviewMouseEventArgs e)
{
Cursor.Current = Cursors.Hand;
}
private void xrPictureBox1_BeforePrint(object sender, PrintEventArgs e)
{
((XRLabel)sender).Tag = GetCurrentRow();
}
private void xrPictureBox1_PreviewClick(object sender, PreviewMouseEventArgs e)
{
PW pw = new PW();
PW.CaID.Value = (int)((DataRowView)e.Brick.Value).Row["CaseCaseID"];
PW.ShowPreviewDialog();
}
private void xrPictureBox1_PreviewMouseMove(object sender, PreviewMouseEventArgs e)
{
Cursor.Current = Cursors.Hand;
}
}
}
The PW.CaID.Value and the PW.ShowPreviewDialog(); are the lines that are giving me this error. Perhaps I am doing this the wrong way. What I wanted to do is click an icon (xrPictureBox1) on the main report and have it bring up the subreport (PW). I have done this in the code above for another subreport (detailreport). Thank you in advance for your help.
Your code should read:
PW pw = new PW();
pw.CaID.Value = (int)((DataRowView)e.Brick.Value).Row["CaseCaseID"];
pw.ShowPreviewDialog();
Note the case on PW/pw.

Run SSIS Package through winforms

I need to run a SSIS package through winforms.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Deployment;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using System.Net.Mime;
public string sPackage = String.Empty;
public string sConfig = String.Empty;
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog fDialog = new OpenFileDialog();
fDialog.Title = "Open Package";
fDialog.Filter = "SSIS Package (*.dts, *.dtsx)|*.dts;*.dtsx";
fDialog.InitialDirectory = #"C:\";
sPackage = fDialog.FileName.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog fDialog = new OpenFileDialog();
fDialog.Title = "Open Package";
fDialog.Filter = "SSIS Package (*.dts, *.dtsx)|*.dts;*.dtsx";
fDialog.InitialDirectory = #"C:\";
sConfig = fDialog.FileName.ToString();
}
private void button3_Click(object sender, EventArgs e)
{
Microsoft.SqlServer.Dts.Runtime.Wrapper.Application app = new Microsoft.SqlServer.Dts.Runtime.Wrapper.Application();
Package package = app.LoadPackage(sPackage,false,null);
package.ImportConfigurationFile(sConfig);
DTSExecResult result = package.Execute();
MessageBox.Show(result.ToString());
}
But this is giving me error at LoadPackage(sPackage,false,null)
Cannot implicitly convert type 'Microsoft.SqlServer.Dts.Runtime.Wrapper.IDTSPackage90' to 'Microsoft.SqlServer.Dts.Runtime.Wrapper.Package'. An explicit conversion exists (are you missing a cast?)
I figured out that button3_click should be handled like this
private void button3_Click(object sender, EventArgs e)
{
MyEventListener eventListener = new MyEventListener();
Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application();
Microsoft.SqlServer.Dts.Runtime.Package pkg = app.LoadPackage(sPackage, eventListener,false);
Microsoft.SqlServer.Dts.Runtime.DTSExecResult pkgResults = pkg.Execute(null, null, eventListener, null, null);
MessageBox.Show(pkgResults.ToString());
}
class MyEventListener : DefaultEvents
{
public override bool OnError(DtsObject source, int errorCode, string subComponent,
string description, string helpFile, int helpContext, string idofInterfaceWithError)
{
// Add application-specific diagnostics here.
MessageBox.Show("Error in " + "/t" + source + "/t" + subComponent + "/t" + description);
return false;
}
}

Resources