Click here to Skip to main content
15,899,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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;
            //this.DialogResult = true;
        }


        //--------------------------------------------------------------
        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;
        }
    }
}
Posted
Updated 10-Jun-10 1:44am
v2
Comments
Toli Cuturicu 10-Jun-10 10:06am    
Reason for my vote of 1
No question whatsoever

You have not made it clear on why you have posted this.
Are you getting an error somewhere? If so, you need to post it here so someone can help you.
 
Share this answer
 
What is your question?

Beyond that, there are a couple of way you could improve this code:

0) Since the two events perform exactly the same function, you could get away with having just one handler instead of two.

1) Instead of having separate inesrt/update methods in your web service, you could have a single InsertOrUpdate() method that calls a stored procedure that determines on its own whether to insert or update. This would make all of the c#C code much cleaner and easier to maintain.

2) Setting DialogResult = true in the Cancel button handler is inappropriate. Dialogresult=true USUALLY indicates that the dialog box's functionality was successfully performed. Either change the button to be "Done" (or OK), or refactor this part of the code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900