private void btnBUpdate_Click(object sender, RoutedEventArgs e)
        {
            tabUpdate.Visibility    = Visibility.Visible;
            tabControl.SelectedItem = tabUpdate;
            events              = (Event)DGEvents.SelectedItem;
            lblEvName.Content   = events.EName;
            tbxEventVenue.Text  = events.EVenue;
            tbxEventPrice.Text  = events.EPrice.ToString();
            tbxEventlong.Text   = events.ELong.ToString();
            tbxEventlat.Text    = events.ELat.ToString();
            tbxEventDesc.Text   = events.EDesc;
            tbxupHighPrice.Text = events.HighPrice.ToString();
            tbxupLowPrice.Text  = events.LowPrice.ToString();
            tbxupStartDate.Text = events.StartDate.ToShortDateString();
            tbxupEndDate.Text   = events.EndDate.ToShortDateString();;
            tbxupStartTime.Text = events.StartTime.ToShortTimeString();
            tbxupEndTime.Text   = events.EndTime.ToShortTimeString();
            preBytes            = events.EImage;

            BitmapImage  bmpImage = new BitmapImage();
            MemoryStream mystream = new MemoryStream(events.EImage);

            bmpImage.SetSource(mystream);
            updateImage.Source = bmpImage;
        }
        private void btnBDelete_Click(object sender, RoutedEventArgs e)
        {
            tabDelete.Visibility    = Visibility.Visible;
            tabControl.SelectedItem = tabDelete;
            events = (Event)DGEvents.SelectedItem;
            lblEvenName.Content    = events.EName;
            lblEvenVenue.Content   = events.EVenue;
            lblEvenPrice.Content   = events.EPrice;
            lblEvenLong.Content    = events.ELong;
            lblEvenLat.Content     = events.ELat;
            lblEvenDesc.Content    = events.EDesc;
            lblEID.Content         = events.EID;
            lbldeHighPrice.Content = events.HighPrice;
            lbldeLowPrice.Content  = events.LowPrice;
            lbldeStartDate.Content = events.StartDate.ToShortDateString();
            lbldeEndDate.Content   = events.EndDate.ToShortDateString();
            lbldeStartTime.Content = events.StartTime.ToShortTimeString();
            lbldeEndTime.Content   = events.EndTime.ToShortTimeString();
            preBytes = events.EImage;

            if (lbldeHighPrice.Content.Equals("0"))
            {
                lbldeHighPrice.Visibility     = Visibility.Collapsed;
                lbldeleteHighPrice.Visibility = Visibility.Collapsed;
            }

            if (lbldeLowPrice.Content.Equals("0"))
            {
                lbldeLowPrice.Visibility     = Visibility.Collapsed;
                lbldeleteLowPrice.Visibility = Visibility.Collapsed;
            }

            if (lblEvenPrice.Content.Equals("0"))
            {
                lblEvenPrice.Visibility = Visibility.Collapsed;
                lblEvePrice.Visibility  = Visibility.Collapsed;
            }

            BitmapImage  bmpImage = new BitmapImage();
            MemoryStream mystream = new MemoryStream(events.EImage);

            bmpImage.SetSource(mystream);
            ImgDeleteImage.Source = bmpImage;
        }
        private void btnUpdate_Click(object sender, RoutedEventArgs e)
        {
            WCF = new WebService.Service1Client();
            WebService.Event upEvent = new WebService.Event();
            decimal          high    = Convert.ToDecimal(tbxupHighPrice.Text);
            decimal          low     = Convert.ToDecimal(tbxupLowPrice.Text);

            if (low < high)
            {
                upEvent.EName     = lblEvName.Content.ToString();
                upEvent.EVenue    = tbxEventVenue.Text;
                upEvent.EPrice    = Convert.ToDecimal(tbxEventPrice.Text);
                upEvent.ELong     = Convert.ToDecimal(tbxEventlong.Text);
                upEvent.ELat      = Convert.ToDecimal(tbxEventlat.Text);
                upEvent.EDesc     = tbxEventDesc.Text;
                upEvent.LowPrice  = low;
                upEvent.HighPrice = high;
                upEvent.StartDate = Convert.ToDateTime(tbxupStartDate.Text);
                upEvent.EndDate   = Convert.ToDateTime(tbxupEndDate.Text);
                upEvent.StartTime = Convert.ToDateTime(tbxupStartTime.Text);
                upEvent.EndTime   = Convert.ToDateTime(tbxupEndTime.Text);

                if (bytes != null)
                {
                    upEvent.EImage = bytes;
                }
                else
                {
                    upEvent.EImage = preBytes;
                }
                selected = false;
                WCF      = new WebService.Service1Client();
                WCF.UpdateEventAsync(upEvent);
                WCF.UpdateEventCompleted += new EventHandler <UpdateEventCompletedEventArgs>(WCF_UpdateEventCompleted);
            }
            else
            {
                MessageBox.Show("The value of low price cannot be more than the value of high price!", "Error Message", MessageBoxButton.OK);
            }
        }
        void WCF_checkEventCompleted(object sender, WebService.checkEventCompletedEventArgs e)
        {
            if (e.Result == true)
            {
                MessageBox.Show("Identical Data found!", "Insert", MessageBoxButton.OK);
            }
            else
            {
                decimal price = 0;
                if (!tbxPrice.Text.Equals(""))
                {
                    price = Convert.ToDecimal(tbxPrice.Text);
                }
                decimal elong = Convert.ToDecimal(tbxElong.Text);

                decimal elat = Convert.ToDecimal(tbxElat.Text);
                string  desc = tbxDesc.Text;
                img = bytes;
                decimal lowprice = 0;
                if (!tbxinLowPrice.Text.Equals(""))
                {
                    lowprice = Convert.ToDecimal(tbxinLowPrice.Text);
                }

                decimal highprice = 0;
                if (!tbxinHighPrice.Text.Equals(""))
                {
                    highprice = Convert.ToDecimal(tbxinHighPrice.Text);
                }
                evenue = tbxEVenue.Text;
                DateTime StartTime = Convert.ToDateTime(tbxinStartTime.Text);
                DateTime EndTime   = Convert.ToDateTime(tbxinEndTime.Text);


                WebService.Event upEvent = new WebService.Event();
                if (lowprice < highprice)
                {
                    upEvent.EName     = ename;
                    upEvent.EVenue    = evenue;
                    upEvent.EPrice    = price;
                    upEvent.ELong     = elong;
                    upEvent.ELat      = elat;
                    upEvent.EDesc     = desc;
                    upEvent.EImage    = img;
                    upEvent.LowPrice  = lowprice;
                    upEvent.HighPrice = highprice;
                    upEvent.StartDate = startDate;
                    upEvent.EndDate   = endDate;
                    upEvent.StartTime = StartTime;
                    upEvent.EndTime   = EndTime;
                    WCF.InsertEventAsync(upEvent);
                    WCF.InsertEventCompleted += new EventHandler <InsertEventCompletedEventArgs>(WCF_InsertEventCompleted);
                }
                else if (lowprice == highprice)
                {
                    upEvent.EName     = ename;
                    upEvent.EVenue    = evenue;
                    upEvent.EPrice    = price;
                    upEvent.ELong     = elong;
                    upEvent.ELat      = elat;
                    upEvent.EDesc     = desc;
                    upEvent.EImage    = img;
                    upEvent.LowPrice  = lowprice;
                    upEvent.HighPrice = highprice;
                    upEvent.StartDate = startDate;
                    upEvent.EndDate   = endDate;
                    upEvent.StartTime = StartTime;
                    upEvent.EndTime   = EndTime;
                    WCF.InsertEventAsync(upEvent);
                    WCF.InsertEventCompleted += new EventHandler <InsertEventCompletedEventArgs>(WCF_InsertEventCompleted);
                }
                else
                {
                    MessageBox.Show("The value of low price cannot be more than the value of high price!", "Error Message", MessageBoxButton.OK);
                }
            }
        }