I'm really new at add-in stuff. My code should do these:
An outlook user saves/creates anything. If the created item is an appointment item my system must save it under the c: directory, taking the item subject as file name. Here is my code. What is wrong there?
Note: when I create a new appointment the if clause is working, if I write there any other code, it is working, but I can't get the ai's info, such as ai.Subject.
namespace SendToMRBS
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.ItemLoad += new Outlook.ApplicationEvents_11_ItemLoadEventHandler(Application_ItemLoad);
}
void Application_ItemLoad(object Item)
{
if (Item is Outlook.AppointmentItem)
{
Outlook.AppointmentItem ai = Item as Outlook.AppointmentItem;
ai.SaveAs("C:\\" + ai.Subject, Microsoft.Office.Interop.Outlook.OlSaveAsType.olICal);
}
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
I found the solution.. The Item object has no properties or something, so I had to use NewInspector event. Here is my new code:
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.ItemLoad += new Outlook.ApplicationEvents_11_ItemLoadEventHandler(Application_ItemLoad);
}
void Application_ItemLoad(object Item)
{
if (Item is Outlook.AppointmentItem)
{
this.Application.Inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
}
}
void Inspectors_NewInspector(Outlook.Inspector Inspector)
{
Outlook.AppointmentItem ai = Inspector.CurrentItem;
ai.Write += new Outlook.ItemEvents_10_WriteEventHandler(ai_Write);
}
void ai_Write(ref bool Cancel)
{
Outlook.Inspector ins = this.Application.ActiveInspector();
Outlook.AppointmentItem appi = ins.CurrentItem;
appi.SaveAs("c:\\test.ics", Microsoft.Office.Interop.Outlook.OlSaveAsType.olICal);
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
Related
Starting with this...
https://github.com/jeremytammik/RevitLookup/blob/master/CS/EventTrack/Events/ApplicationEvents.cs
I'm trying to add an event listener for a synchronization event. the code below throws an error stating that the m_app is null. Can i not subscribe to this event while Revit is starting up?
I was able to do this before with application.ViewActivated += ..... Im wondering if this has something to do with DB vs UI driven events and when they are allowed to be subscribed to? I just don't know.
namespace RevitModelHealth
{
public class checkHealth : IExternalApplication
{
// Document doc;
static public Autodesk.Revit.ApplicationServices.Application m_app = null;
public Result OnShutdown(UIControlledApplication application)
{
return Result.Succeeded;
}
public Result OnStartup(UIControlledApplication application)
{
m_app.DocumentSynchronizingWithCentral += new EventHandler<DocumentSynchronizingWithCentralEventArgs>(m_app_DocumentSavingToCentral);
return Result.Succeeded;
}
void m_app_DocumentSavingToCentral(object sender, Autodesk.Revit.DB.Events.DocumentSynchronizingWithCentralEventArgs e)
{
MessageBox.Show("asd","asd");
}
}
}
Here is updated code reflecting my response to the first answer. The message box opens when the document is loaded. No errors are thrown when I try to initialize the synchronization event handlers, however, neither of the message boxes open before or after a synchronization event.
public class checkHealth : IExternalApplication
{
// Document doc;
static public Autodesk.Revit.ApplicationServices.Application m_app;
public Result OnShutdown(UIControlledApplication application)
{
return Result.Succeeded;
}
public Result OnStartup(UIControlledApplication application)
{
application.ControlledApplication.DocumentOpened += new EventHandler<DocumentOpenedEventArgs>(app_DocOpened);
return Result.Succeeded;
}
public void app_DocOpened(object sender, DocumentOpenedEventArgs args)
{
MessageBox.Show("asd","asd");
m_app.DocumentSynchronizingWithCentral += new EventHandler<DocumentSynchronizingWithCentralEventArgs>(m_app_DocumentSavingToCentral);
m_app.DocumentSynchronizedWithCentral += new EventHandler<Autodesk.Revit.DB.Events.DocumentSynchronizedWithCentralEventArgs>(m_app_DocumentSavedToCentral);
}
void m_app_DocumentSavingToCentral(object sender, Autodesk.Revit.DB.Events.DocumentSynchronizingWithCentralEventArgs e)
{
MessageBox.Show("sync", "sync");
}
void m_app_DocumentSavedToCentral(object sender, Autodesk.Revit.DB.Events.DocumentSynchronizedWithCentralEventArgs e)
{
MessageBox.Show("Doone", "Done");
}
}
this worked.... Thanks largely in part to the SDK sample project EventsMonitor
namespace RevitModelHealth
{
public class checkHealth : IExternalApplication
{
public Result OnShutdown(UIControlledApplication application)
{
return Result.Succeeded;
}
public Result OnStartup(UIControlledApplication application)
{
application.ControlledApplication.DocumentSynchronizingWithCentral += new EventHandler<DocumentSynchronizingWithCentralEventArgs>(app_syncStart);
application.ControlledApplication.DocumentSynchronizedWithCentral += new EventHandler<DocumentSynchronizedWithCentralEventArgs>(app_syncOver);
return Result.Succeeded;
}
public void app_syncStart(object o ,DocumentSynchronizingWithCentralEventArgs args)
{
MessageBox.Show("","Stasrting");
}
public void app_syncOver(object o,DocumentSynchronizedWithCentralEventArgs args)
{
MessageBox.Show("", "Over");
}
}
}
Try
application.ControlledApplication.DocumentSynchronizingWithCentral += new EventHandler<DocumentSynchronizingWithCentralEventArgs>(m_app_DocumentSavingToCentral)
in your OnStartup() method.
The call is failing because instance member m_app is initialized to null.
The UIApplication.ControlledApplication object that raises the DocumentSynchronizingWithCentralEventArgs is being accessible from the parameter to OnStartup.
You can try this:
public void app_DocOpened(object sender, DocumentOpenedEventArgs args)
{
MessageBox.Show("asd","asd");
Autodesk.Revit.ApplicationServices.Application m_app = args.Document.Application;
m_app.DocumentSynchronizingWithCentral += new EventHandler<DocumentSynchronizingWithCentralEventArgs>(m_app_DocumentSavingToCentral);
m_app.DocumentSynchronizedWithCentral += new EventHandler<Autodesk.Revit.DB.Events.DocumentSynchronizedWithCentralEventArgs>(m_app_DocumentSavedToCentral);
}
is there a way of randomizing the user agent using Gecko Browser ? i tried doing it on a separated thread but i couldn't since Gecko must be ran on the same Thread.
try this
Create new class Global.cs
public class Globals
{
public static ArrayList Useragent = new ArrayList();
}
next in your form1 code
private string GetUserAgent()
{
Random Rnd = new Random();
return Convert.ToString(Globals.Useragent[Rnd.Next(0, Globals.Useragent.Count)]);
}
load your file with user agent lines
private void button2_Click(object sender, EventArgs e)
{
var OpenFile = new OpenFileDialog();
OpenFile.Filter = "*.txt | *.txt";
OpenFile.ShowDialog();
if (OpenFile.FileName != "")
{
Globals.Useragent.AddRange(File.ReadAllLines(OpenFile.FileName));
}
else
{
MessageBox.Show("Chooee Your User agent file");
}
}
======================
private string GetUserAgent()
{
Random Rnd = new Random();
return Convert.ToString(Globals.Useragent[Rnd.Next(0, Globals.Useragent.Count)]);
}
Ok its finish!
Now you can do this - input your new code GetUserAgent();
private void button1_Click(object sender, EventArgs e)
{
CookieManager.RemoveAll();
Gecko.GeckoPreferences.User["general.useragent.override"] = GetUserAgent();
}
I can't seem to figure out how to display Account ID and Account Balance into a textbox after the selected index is changed in the listbox. I have a Customer class and a Checking account class(which is a subclass of a Bank Account class). The part of the code that is messing up is at the bottom.
This is the part of my code that I'm having trouble with:
txtAccountID.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetAcctNumber();
txtBalance.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetBalance().ToString();
This is the rest of the code:
public partial class frmStart : Form
{
private static List<Customer_Account> customers;
private Customer_Account aCustomer;
private Saving_Account aSaver;
private static List<Saving_Account> savers;
private Checking_Account aChecker;
private static List<Checking_Account> checkers;
public frmStart()
{
InitializeComponent();
customers = new List<Customer_Account>();
checkers = new List<Checking_Account>();
savers = new List<Saving_Account>();
}
#region New form for Savings and Checking
private void lstFrmStartChecking_DoubleClick(object sender, EventArgs e)
{
//Shows Checking form
frmChecking showCheckingForm = new frmChecking();
this.Hide();
showCheckingForm.ShowDialog();
this.Close();
}
private void lstFrmStartSavings_SelectedIndexChanged(object sender, EventArgs e)
{
//Show Savings form
frmSavings showSavingForm = new frmSavings();
this.Hide();
showSavingForm.ShowDialog();
this.Close();
}
#endregion
#region Everything needed for TabPage1
//Sets CheckChanged event handler for either New customer or Existing Customer
private void rdoNewCustomer_CheckedChanged(object sender, EventArgs e)
{
groupBox2.Visible = true;
groupBox3.Visible = false;
}
private void rdoExistingCustomer_CheckedChanged(object sender, EventArgs e)
{
groupBox3.Visible = true;
groupBox2.Visible = false;
}//End of CheckChanged event handler
//Button controls for Adding customer to our bank and Clearing the textboxes
//in the 1st group panel
private void btnAddCustomer_Click(object sender, EventArgs e)
{
AddCustomerAccountToList();
PopulateListBox(customers);
}
private void AddCustomerAccountToList()
{
double socialSecurity;
double phoneNumber;
double zipCode;
if (double.TryParse(txtTab1SocialSecurity.Text, out socialSecurity) && double.TryParse(txtTab1PhoneNumber.Text, out phoneNumber)
&& double.TryParse(txtTab1Zip.Text, out zipCode))
{
aCustomer = new Customer_Account(txtTab1SocialSecurity.Text, txtTab1Name.Text, txtTab1Address.Text, txtTab1City.Text,
txtTab1State.Text, txtTab1Zip.Text, txtTab1PhoneNumber.Text, txtTab1Email.Text);
customers.Add(aCustomer);
}
else
{
MessageBox.Show("Please be sure to use only numeric entries for: \nSocial Security \nPhone Number \nZip Code", "Non-numeric Entry");
}
}//End of AddCustomerAccount
private void btnTab1Clear_Click(object sender, EventArgs e)
{
foreach (Control ctrl in groupBox2.Controls)
{
if (ctrl is TextBox)
{
((TextBox)ctrl).Clear();
}
txtTab1SocialSecurity.Focus();
}
}//end of button controls for 1st group panel
//Add CheckingAccount to List()
//Populate ListBox for List<>
private void PopulateListBox(List<Customer_Account> aListCustomerAccount)
{
lstTabPage1.Items.Clear();
lstTabPage2Checking.Items.Clear();
foreach (Customer_Account customer in aListCustomerAccount)
{
lstTabPage1.Items.Add(customer.GetCustomerName().ToUpper());
lstTabPage2Checking.Items.Add(customer.GetCustomerName().ToUpper());
}
}//End of Populate listbox
//Search for an existing member with name
private void txtTabPage1Search_TextChanged(object sender, EventArgs e)
{
for (int i = 0; i < lstTabPage1.Items.Count; i++)
{
if (string.IsNullOrEmpty(txtTabPage1Search.Text))
{
lstTabPage1.SetSelected(i, false);
}
else if (lstTabPage1.GetItemText(lstTabPage1.Items[i]).StartsWith(txtTabPage1Search.Text.ToUpper()))
{
lstTabPage1.SetSelected(i, true);
}
else
{
lstTabPage1.SetSelected(i, false);
}
}
}//End of search
//This button will open a checking account for the customer
private void btnOpenCheckingAccount_Click(object sender, EventArgs e)
{
string acctID;
acctID = txtAccountID.Text;
aChecker = new Checking_Account(acctID, DateTime.Today, 0,
200, frmStart.GetCustomer()[lstTabPage1.SelectedIndex]);
}
//This button will open a saving account for the customer
private void btnOpenSavingsAccount_Click(object sender, EventArgs e)
{
aSaver = new Saving_Account(txtAccountID.Text, DateTime.Today, 0, 0.05,
frmStart.GetCustomer()[lstTabPage1.SelectedIndex]);
}
private static List<Customer_Account> GetCustomer()
{
return customers;
}
#endregion
#region Everything Needed for TabPage2
//Search TabPage 2 Checkers
private void txtTabPage2SearchChecking_TextChanged(object sender, EventArgs e)
{
for (int i = 0; i < lstTabPage2Checking.Items.Count; i++)
{
if (string.IsNullOrEmpty(txtTabPage2SearchChecking.Text))
{
lstTabPage2Checking.SetSelected(i, false);
}
else if (lstTabPage1.GetItemText(lstTabPage2Checking.Items[i]).StartsWith(txtTabPage2SearchChecking.Text.ToUpper()))
{
lstTabPage2Checking.SetSelected(i, true);
}
else
{
lstTabPage2Checking.SetSelected(i, false);
}
}
}//End Search TabPage2 Checkers
//Display values in textboxes depending on user selection in listbox
private void lstTabPage2Checking_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
txtTab2SocialSecurity.Text = customers[lstTabPage2Checking.SelectedIndex].GetSocialSecurity().ToString();
txtTab2Name.Text = customers[lstTabPage2Checking.SelectedIndex].GetCustomerName().ToString();
txtTab2City.Text = customers[lstTabPage2Checking.SelectedIndex].GetCity().ToString();
txtTab2State.Text = customers[lstTabPage2Checking.SelectedIndex].GetState().ToString();
txtTab2Zip.Text = customers[lstTabPage2Checking.SelectedIndex].GetZip().ToString();
txtTab2PhoneNumber.Text = customers[lstTabPage2Checking.SelectedIndex].GetPhoneNumber().ToString();
txtTab2Email.Text = customers[lstTabPage2Checking.SelectedIndex].GetEmail().ToString();
txtTab2Address.Text = customers[lstTabPage2Checking.SelectedIndex].GetAddress().ToString();
txtAccountID.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetAcctNumber();
txtBalance.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetBalance().ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
#endregion
}
(This is what the error message says)
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Welcome to SO, Guy!
It looks to me that you are appending the .ToString() method to all of your controls except for this one:
txtAccountID.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetAcctNumber();
Change your code to:
txtAccountID.Text = frmStart.GetCustomer()[lstTabPage1.SelectedIndex].GetCheckers()[lstFrmStartChecking.SelectedIndex].GetAcctNumber().ToString();
And you should be fine!
In WinRT Applications, when you right click a ListBoxItem the AppBar is shown. But when you right click a GridViewItem the AppBar doesn't appear. Can this be configured?
If not is it beter to work with a ListBox instead of GridView and customize the templates. Or should I implement it With a RightTapped command.
(I work with MVVM Light, since Caliburn.Micro is currently not working)
Example of RightTappedCommand:
public sealed class RightTapped
{
#region Properties
#region Command
///
/// GetCommand
///
///
///
public static ICommand GetCommand(DependencyObject obj)
{
return (ICommand)obj.GetValue(CommandProperty);
}
///
/// SetCommand
///
///
///
public static void SetCommand(DependencyObject obj, ICommand value)
{
obj.SetValue(CommandProperty, value);
}
///
/// DependencyProperty CommandProperty
///
public static readonly DependencyProperty CommandProperty =
DependencyProperty.RegisterAttached("Command", typeof(ICommand), typeof(RightTapped), new PropertyMetadata(null, OnCommandChanged));
#endregion Command
#region CommandParameter
///
/// GetCommandParameter
///
///
///
public static object GetCommandParameter(DependencyObject obj)
{
return (object)obj.GetValue(CommandParameterProperty);
}
///
/// SetCommandParameter
///
///
///
public static void SetCommandParameter(DependencyObject obj, object value)
{
obj.SetValue(CommandParameterProperty, value);
}
///
/// DependencyProperty CommandParameterProperty
///
public static readonly DependencyProperty CommandParameterProperty =
DependencyProperty.RegisterAttached("CommandParameter", typeof(object), typeof(RightTapped), new PropertyMetadata(null, OnCommandParameterChanged));
#endregion CommandParameter
#region HasCommandParameter
private static bool GetHasCommandParameter(DependencyObject obj)
{
return (bool)obj.GetValue(HasCommandParameterProperty);
}
private static void SetHasCommandParameter(DependencyObject obj, bool value)
{
obj.SetValue(HasCommandParameterProperty, value);
}
private static readonly DependencyProperty HasCommandParameterProperty =
DependencyProperty.RegisterAttached("HasCommandParameter", typeof(bool), typeof(RightTapped), new PropertyMetadata(false));
#endregion HasCommandParameter
#endregion Propreties
#region Event Handling
private static void OnCommandParameterChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
SetHasCommandParameter(o, true);
}
private static void OnCommandChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
var element = o as FrameworkElement;
if (element != null)
{
if (e.NewValue == null)
{
element.RightTapped -= FrameworkElementKeyUp;
}
else if (e.OldValue == null)
{
element.RightTapped += FrameworkElementKeyUp;
}
}
}
private static void FrameworkElementKeyUp(object sender, RightTappedRoutedEventArgs e)
{
var o = sender as DependencyObject;
var command = GetCommand(sender as DependencyObject);
var element = e.OriginalSource as FrameworkElement;
if (element != null)
{
// If the command argument has been explicitly set (even to NULL)
if (GetHasCommandParameter(o))
{
var commandParameter = GetCommandParameter(o);
// Execute the command
if (command.CanExecute(commandParameter))
{
command.Execute(commandParameter);
}
}
else if (command.CanExecute(element.DataContext))
{
command.Execute(element.DataContext);
}
}
}
#endregion
}
In Xaml, something like this:
common:Tapped.Command="{Binding ShowAppBar}"
You can just do myAppBar.IsOpen = true.
It depends on the gridview selection mode, the right-click is used for selecting items. If you set the selectionmode property to None the appbar will open on right-click.
Using VB.Net
I am having the form name as "Employee Entry"
User want to open a Employee Entry from in 5 tabs...
For Example
When the user open a Employee Entry form, while entering the details at that same time, user again open a employee entry form (2nd Employee entry form show like a new employee entry from with out any details)
More Example
We can open Google, Yahoo, in one browser (by using Tab Function).
How to make this.
Need vb.net code Help
I'm assuming this is WinForms? You should design your Employee Entry as a User Control. You can then add a new instance of that control to your Form on each request of a new Employee. You would most likely have a seperate Employee object that you could pass to each instance of your EmployeeEntry user control.
EDIT1
Create a form with a menu strip across the top and a menu item called tsmiNewEmployee. Add a tab control to the form named tabEntryForms and set its fill style to Dock. Delete all default tab pages from it.
Add Class:
public class EmployeeRecord
{
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime HireDate { get; set; }
}
Add USerControl named EmployeeEntry. Puts osme Firts/Last name edit cotrols on it, etc. Add a Save button and a Cancel Button.
public partial class EmployeeEntry : UserControl
{
public event EventHandler Save;
public event EventHandler Cancel;
private EmployeeRecord empBeingEdited = null;
public EmployeeRecord Employee
{
get
{
return empBeingEdited;
}
set
{
empBeingEdited = value;
if (empBeingEdited == null)
{
// clear controls
}
else
{
// populate controls with employee values
}
}
}
public EmployeeEntry()
{
InitializeComponent();
}
private void btnSave_Click(object sender, EventArgs e)
{
if (Save != null)
Save(this, EventArgs.Empty);
}
private void btnCancel_Click(object sender, EventArgs e)
{
if (Cancel != null)
Cancel(this, EventArgs.Empty);
}
}
And in your main form that has the tab control:
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void tsmiNewEmployee_Click(object sender, EventArgs e)
{
TabPage tab = new TabPage("New Employee Entry");
EmployeeEntry empEntry = new EmployeeEntry();
empEntry.Employee = new EmployeeRecord();
empEntry.Save += new EventHandler(EmployeeEntry_Save);
empEntry.Cancel += new EventHandler(EmployeeEntry_Cancel);
tab.Controls.Add(empEntry);
empEntry.Dock = DockStyle.Fill;
tabEntryForms.TabPages.Add(tab);
}
private void EmployeeEntry_Save(object source, EventArgs args)
{
EmployeeEntry empEntry = source as EmployeeEntry;
MessageBox.Show("Saved");
TabPage parentTab = empEntry.Parent as TabPage;
parentTab.Controls.Remove(empEntry);
tabEntryForms.Controls.Remove(parentTab);
}
private void EmployeeEntry_Cancel(object source, EventArgs args)
{
EmployeeEntry empEntry = source as EmployeeEntry;
MessageBox.Show("NOT Saved");
TabPage parentTab = empEntry.Parent as TabPage;
parentTab.Controls.Remove(empEntry);
tabEntryForms.Controls.Remove(parentTab);
}
}
That should get you started.