When pressed the edit button the following code is executed:
keyserv.updateAreamasterAsync(int.Parse(txtarID.Text), txtarCode.Text, txtarDesc.Text);
otherwise (insert) the following code should be executed:
keyserv.insertAremasterAsync(txtarCode.Text, txtarDesc.Text);
in the okbttonclick event
the complete code is bellow
using System.Windows;
using System.Windows.Controls;
using System;
namespace amps1.Views
{
public partial class cwAreaMaster : ChildWindow
{
keyServiceReference.keyDataWebServiceSoapClient keyserv = new
amps1.keyServiceReference.keyDataWebServiceSoapClient();
public cwAreaMaster()
{
InitializeComponent();
keyserv.insertAremasterCompleted += new EventHandler<amps1.keyservicereference.insertaremastercompletedeventargs>(keyserv_insertAremasterCompleted);
keyserv.updateAreamasterCompleted += new EventHandler<amps1.keyservicereference.updateareamastercompletedeventargs>(keyserv_updateAreamasterCompleted);
}
private void OKButton_Click(object sender, RoutedEventArgs e)
{
Button btnedit = this.dtForm.FindNameInContent("edit")
as Button;
TextBox txtarID = this.dtForm.FindNameInContent("arID")
as TextBox;
TextBox txtarCode = this.dtForm.FindNameInContent("arCode")
as TextBox;
TextBox txtarDesc = this.dtForm.FindNameInContent("arDesc")
as TextBox;
if (btnedit.IsPressed == true)
{
keyserv.updateAreamasterAsync(int.Parse(txtarID.Text),
txtarCode.Text,
txtarDesc.Text);
}
else
{
keyserv.insertAremasterAsync(txtarCode.Text,
txtarDesc.Text);
}
OKButton.IsEnabled = false;
CancelButton.IsEnabled = false;
}
void keyserv_insertAremasterCompleted(object sender, amps1.keyServiceReference.insertAremasterCompletedEventArgs e)
{
if (e.Result > 0)
{
CancelButton.IsEnabled = true;
CancelButton.Content = "Close";
}
}
void keyserv_updateAreamasterCompleted(object sender, amps1.keyServiceReference.updateAreamasterCompletedEventArgs e)
{
if (e.Result > 0)
{
CancelButton.IsEnabled = true;
CancelButton.Content = "Close";
}
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}
}
}