using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security.Permissions;
namespace TicheteC
{
public partial class formBirouri : Form
private SqlCommand mCommand;
private string mSqlConnectString;
private int mChangeCount;
#region Permisiuni
private static bool CanRequestNotifications()
try
SqlClientPermission perm = new SqlClientPermission(PermissionState.Unrestricted);
perm.Demand();
return true;
}
catch
return false;
private void GetData()
this.ticheteDataSet.Clear();
mCommand = this.birouriTableAdapter.SelectCommand;
mCommand.Notification = null;
SqlDependency dependency;
dependency = new SqlDependency(mCommand);
dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
this.birouriTableAdapter.Fill(this.ticheteDataSet.birouri);
InfotoolStripStatusLabel.Text = String.Format("{0} change(s).", mChangeCount);
#endregion
public formBirouri()
InitializeComponent();
private void Birouri_Load(object sender, EventArgs e)
if (CanRequestNotifications() == true)
mSqlConnectString = this.birouriTableAdapter.Connection.ConnectionString;
SqlDependency.Stop(mSqlConnectString);
SqlDependency.Start(mSqlConnectString);
GetData();
private void birouriBindingNavigatorSaveItem_Click(object sender, EventArgs e)
this.Validate();
this.birouriBindingSource.EndEdit();
this.birouriTableAdapter.Update(this.ticheteDataSet.birouri);
private void Birouri_FormClosed(object sender, FormClosedEventArgs e)
private void dependency_OnChange(object sender, SqlNotificationEventArgs e)
ISynchronizeInvoke i = (ISynchronizeInvoke)this;
if (i.InvokeRequired)
OnChangeEventHandler tempDelegate = new OnChangeEventHandler(dependency_OnChange);
object[] args = { sender, e };
i.BeginInvoke(tempDelegate, args);
return;
SqlDependency dependency = (SqlDependency)sender;
dependency.OnChange -= dependency_OnChange;
++mChangeCount;