Write event in the form region.

D

Deraldo

Hi!
I have a replacement task form. When the user clicks in the button to save, I do in the "write" event the whole processing of criticizes and if there is some I cancel the save and I keep the form opened. However, I realize that the command write is called in some cases more than one time. Does anybody have some idea on this?
I am using c# in visual studio 2008, vsto 3, outlook 2007
 
K

Ken Slovak - [MVP - Outlook]

In what cases is Write() being called more than once? What is calling it? Do
you have multiple Save statements in your code?
 
D

Deraldo

Hi!
Thx for your attention.

In the beginning I had several save() in my system, including some in the close of the form. I noticed that this was a problem and I passed the whole code inside of the event write. Now I don't have more any explicit save().
When we clicked in the button "Save & Close" the system executes the event write and later the close. In the first time that saved it makes this. If I open the item again and I order to save, he makes this process twice. In the second time, the fields of the form are empty. If I open again, it does three times and it continues in the sequence.
Inside of the write, I make to the item the property attributions. like:
item.Subject = txbSubject.Text.Trim();
...
greetings
 
K

Ken Slovak - [MVP - Outlook]

Show the code that you're using. I can't tell what's going on from your
description.
 
D

Deraldo

Quote
void apptItem_Write(ref bool Cancel)
{
if (certo && string.IsNullOrEmpty(txbAssunto.Text.Trim()))
{
return;
}
else
if (string.IsNullOrEmpty(txbAssunto.Text.Trim()))
{
txbAssunto.Text = apptItem.Subject.ToString();
txbLocal.Text = apptItem.Location.ToString();
rtbDescricao.Text = apptItem.Body.ToString();
cbbStarttime.SelectedValue = apptItem.Start.ToString("HH:mm");
cbbEndtime.SelectedValue = apptItem.End.ToString("HH:mm");
if (apptItem.AllDayEvent) ckbAllday.Checked = true;
ckbClosed.Checked = _sent.Value.ToString() == "S" ? true : false;
}
certo = true;

lblSubject.ForeColor = black;
toolTip1.SetToolTip(lblSubject, string.Empty);
if (string.IsNullOrEmpty(txbAssunto.Text.Trim()))
{
lblSubject.ForeColor = vermelho;
toolTip1.SetToolTip(lblSubject, itemreq);
certo = false;
}
else
{
charFound = string.Empty;
if (common.ParseForSpecialChars(txbAssunto.Text, "'\"<>{}[]#^%&~", out charFound))
{
lblSubject.ForeColor = vermelho;
toolTip1.SetToolTip(lblSubject, charinv);
certo = false;
}
}

lblLocal.ForeColor = black;
toolTip1.SetToolTip(lblLocal, string.Empty);
if (string.IsNullOrEmpty(txbLocal.Text.Trim()))
{
lblLocal.ForeColor = vermelho;
toolTip1.SetToolTip(lblLocal, itemreq);
certo = false;
}
else
{
charFound = string.Empty;
if (common.ParseForSpecialChars(txbLocal.Text, "", out charFound))
{
lblLocal.ForeColor = vermelho;
toolTip1.SetToolTip(lblLocal, charinv);
certo = false;
}
}

lblDescricao.ForeColor = black;
toolTip1.SetToolTip(lblDescricao, string.Empty);
if (!string.IsNullOrEmpty(rtbDescricao.Text.Trim()))
{
charFound = string.Empty;
if (common.ParseForSpecialChars(rtbDescricao.Text, "'\"<>{}[]#^%&~", out charFound))
{
lblDescricao.ForeColor = vermelho;
toolTip1.SetToolTip(lblDescricao, charinv);
certo = false;
}
}

if (!certo)
{
MessageBox.Show("Verifique os itens que estão em vermelho. Passe o mouse sobre eles para conhecer o erro!");
Cancel = true;
}
else
{
apptItem.Subject = txbAssunto.Text.Trim();
apptItem.Location = txbLocal.Text.Trim();
apptItem.AllDayEvent = ckbAllday.Checked ? true : false;
apptItem.Body = rtbDescricao.Text.Trim();
DateTime inicio = DateTime.Parse(dtpDtstart.Value.ToString("dd/MM/yyyy") + " " + cbbStarttime.SelectedValue.ToString());
DateTime fim = DateTime.Parse(dtpDtend.Value.ToString("dd/MM/yyyy") + " " + cbbEndtime.SelectedValue.ToString());
apptItem.Start = inicio;
apptItem.End = fim;

if (ckbClosed.Checked)
{
apptItem.Categories = string.Empty;
try
{
if ((apptItem.EntryID == null) || (apptItem.UserProperties["ID"].Value == null))
{
throw new MissingFieldException();
}
}
catch
{
UserProperty _ID = apptItem.UserProperties.Add("ID", OlUserPropertyType.olText, true, OlFormatText.olFormatTextText);
Guid guid = Guid.NewGuid();
_ID.Value = guid.ToString();
}
AgendaItem agenda = new AgendaItem();
agenda = AItemMethods.ToAgenda(apptItem);

agenda.Sent = "S";
_sent.Value = "S";
bool teste = cliente.SaveAgenda(agenda);
apptItem.Categories = "Categoria Vermelha";
cliente.Close();
//
}
else
{
if (_sent.Value.ToString() == "S")
{
apptItem.Categories = "Categoria Azul";
}

}
}
 
K

Ken Slovak - [MVP - Outlook]

There's nothing there that should fire multiple Write events. Write will
fire when you explicitly call Save() on the item or when the user saves it
or closes it if saving is selected. You will have to closely examine your
code, and step it to see what is calling Write multiple times.




Deraldo said:
Quote:
void apptItem_Write(ref bool Cancel)
{
if (certo && string.IsNullOrEmpty(txbAssunto.Text.Trim()))
{
return;
}
else
if (string.IsNullOrEmpty(txbAssunto.Text.Trim()))
{
txbAssunto.Text = apptItem.Subject.ToString();
txbLocal.Text = apptItem.Location.ToString();
rtbDescricao.Text = apptItem.Body.ToString();
cbbStarttime.SelectedValue = apptItem.Start.ToString("HH:mm");
cbbEndtime.SelectedValue = apptItem.End.ToString("HH:mm");
if (apptItem.AllDayEvent) ckbAllday.Checked = true;
ckbClosed.Checked = _sent.Value.ToString() == "S" ? true : false;
}
certo = true;

lblSubject.ForeColor = black;
toolTip1.SetToolTip(lblSubject, string.Empty);
if (string.IsNullOrEmpty(txbAssunto.Text.Trim()))
{
lblSubject.ForeColor = vermelho;
toolTip1.SetToolTip(lblSubject, itemreq);
certo = false;
}
else
{
charFound = string.Empty;
if (common.ParseForSpecialChars(txbAssunto.Text, "'\"<>{}[]#^%&~", out
charFound))
{
lblSubject.ForeColor = vermelho;
toolTip1.SetToolTip(lblSubject, charinv);
certo = false;
}
}

lblLocal.ForeColor = black;
toolTip1.SetToolTip(lblLocal, string.Empty);
if (string.IsNullOrEmpty(txbLocal.Text.Trim()))
{
lblLocal.ForeColor = vermelho;
toolTip1.SetToolTip(lblLocal, itemreq);
certo = false;
}
else
{
charFound = string.Empty;
if (common.ParseForSpecialChars(txbLocal.Text, "", out charFound))
{
lblLocal.ForeColor = vermelho;
toolTip1.SetToolTip(lblLocal, charinv);
certo = false;
}
}

lblDescricao.ForeColor = black;
toolTip1.SetToolTip(lblDescricao, string.Empty);
if (!string.IsNullOrEmpty(rtbDescricao.Text.Trim()))
{
charFound = string.Empty;
if (common.ParseForSpecialChars(rtbDescricao.Text, "'\"<>{}[]#^%&~", out
charFound))
{
lblDescricao.ForeColor = vermelho;
toolTip1.SetToolTip(lblDescricao, charinv);
certo = false;
}
}

if (!certo)
{
MessageBox.Show("Verifique os itens que estão em vermelho. Passe o mouse
sobre eles para conhecer o erro!");
Cancel = true;
}
else
{
apptItem.Subject = txbAssunto.Text.Trim();
apptItem.Location = txbLocal.Text.Trim();
apptItem.AllDayEvent = ckbAllday.Checked ? true : false;
apptItem.Body = rtbDescricao.Text.Trim();
DateTime inicio = DateTime.Parse(dtpDtstart.Value.ToString("dd/MM/yyyy")
+ " " + cbbStarttime.SelectedValue.ToString());
DateTime fim = DateTime.Parse(dtpDtend.Value.ToString("dd/MM/yyyy") + " "
+ cbbEndtime.SelectedValue.ToString());
apptItem.Start = inicio;
apptItem.End = fim;

if (ckbClosed.Checked)
{
apptItem.Categories = string.Empty;
try
{
if ((apptItem.EntryID == null) || (apptItem.UserProperties["ID"].Value ==
null))
{
throw new MissingFieldException();
}
}
catch
{
UserProperty _ID = apptItem.UserProperties.Add("ID",
OlUserPropertyType.olText, true, OlFormatText.olFormatTextText);
Guid guid = Guid.NewGuid();
_ID.Value = guid.ToString();
}
AgendaItem agenda = new AgendaItem();
agenda = AItemMethods.ToAgenda(apptItem);

agenda.Sent = "S";
_sent.Value = "S";
bool teste = cliente.SaveAgenda(agenda);
apptItem.Categories = "Categoria Vermelha";
cliente.Close();
//
}
else
{
if (_sent.Value.ToString() == "S")
{
apptItem.Categories = "Categoria Azul";
}

}
}
}
 
D

Deraldo

Ok. I am doing this the whole time.
using the debugger, we observed that when arriving in the end of the routine write(), ( using F11) the next command is the first command of the routine write() again. After the last time the flow finally goes to the close().

thx for your attention.
 
K

Ken Slovak - [MVP - Outlook]

I looked at the code again and I still don't see anything offhand. About all
I can think of to try is to start commenting out sections of the Write()
handler code until you localize which line or lines are causing Write() to
repeat.

I'd start by commenting the entire code block and then uncommenting as I
proceeded, probably.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top