private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (ID != 0)
                {
                    if (MessageBox.Show("Do you want to delete '" + txtRelationName.Text + "'", "DELETE", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        MASTERRELATION ms      = db.MASTERRELATIONs.Where(x => x.RELATION_CODE == ID).FirstOrDefault();
                        var            OldData = new JSonHelper().ConvertObjectToJSon(ms);

                        db.MASTERRELATIONs.Remove(ms);
                        db.SaveChanges();

                        AppLib.EventHistory(this.Tag.ToString(), 2, OldData, "", "MASTERRELATION");

                        MessageBox.Show("Deleted Successfully!", "DELETED", MessageBoxButton.OK, MessageBoxImage.Information);
                        FormClear();
                    }
                }
                else
                {
                    MessageBox.Show("Please Select any Relation! (Double Click to Select)", "SELECT", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception ex)
            {
                Nube.ExceptionLogging.SendErrorToText(ex);
            }
        }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (txtRelationName.Text == "")
                {
                    MessageBox.Show("Enter Relation...", "Information");
                }
                else
                {
                    if (MessageBox.Show("Do you wanrt to save this record?", "SAVE CONFIRMATION", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                    {
                        if (ID != 0)
                        {
                            MASTERRELATION ms      = db.MASTERRELATIONs.Where(x => x.RELATION_CODE == ID).FirstOrDefault();
                            var            OldData = new JSonHelper().ConvertObjectToJSon(ms);

                            ms.RELATION_NAME = txtRelationName.Text;
                            db.SaveChanges();
                            AppLib.lstMASTERRELATION = db.MASTERRELATIONs.OrderBy(x => x.RELATION_NAME).ToList();

                            var NewData = new JSonHelper().ConvertObjectToJSon(ms);
                            AppLib.EventHistory(this.Tag.ToString(), 1, OldData, NewData, "MASTERRELATION");
                            MessageBox.Show("Saved Successfully!", "Saved", MessageBoxButton.OK, MessageBoxImage.Information);
                            FormClear();
                        }
                        else
                        {
                            if (db.MASTERRELATIONs.Where(x => x.RELATION_NAME == txtRelationName.Text).Select(x => x.RELATION_NAME).FirstOrDefault() == txtRelationName.Text.ToString())
                            {
                                MessageBox.Show("'" + txtRelationName.Text + "' already exist! Enter new  Country...", "Information");
                            }
                            else
                            {
                                MASTERRELATION ms = new MASTERRELATION();
                                ms.RELATION_NAME = txtRelationName.Text;

                                db.MASTERRELATIONs.Add(ms);
                                db.SaveChanges();
                                AppLib.lstMASTERRELATION = db.MASTERRELATIONs.OrderBy(x => x.RELATION_NAME).ToList();

                                var NewData = new JSonHelper().ConvertObjectToJSon(ms);
                                AppLib.EventHistory(this.Tag.ToString(), 0, "", NewData, "MASTERRELATION");
                                MessageBox.Show("Saved Successfully!", "Saved", MessageBoxButton.OK, MessageBoxImage.Information);
                                FormClear();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Nube.ExceptionLogging.SendErrorToText(ex);
            }
        }
 private void dgvReason_MouseDoubleClick(object sender, MouseButtonEventArgs e)
 {
     try
     {
         if (bIsEdit == true)
         {
             MASTERRELATION r = dgvReason.SelectedItem as MASTERRELATION;
             txtRelationName.Text = r.RELATION_NAME;
             ID = Convert.ToInt16(r.RELATION_CODE);
         }
     }
     catch (Exception ex)
     {
         Nube.ExceptionLogging.SendErrorToText(ex);
     }
 }