public void UpdateSourceBasedOnThickness()
 {
     if (RGReport != null && (RGReport.ReshootNo < 1 || chkIsInchCms.IsChecked == true) && RGReportRows != null)
     {
         if (RGReportRows.Select(o => o.EnergyID).Distinct().Count() == 1)
         {
             RGReportRow RGReportRow = RGReportRows.FirstOrDefault();
             if (RGReportRow.EnergyID == 1)
             {
                 this.txtSource.Text     = "Co 60";
                 this.txtSourceSize.Text = "4.1 mm(Effective size)";
             }
             else
             {
                 this.txtSource.Text     = "Ir 192";
                 this.txtSourceSize.Text = "3.6 mm(Effective size)";
             }
         }
         else
         {
             this.txtSource.Text     = "Co 60/Ir 192";
             this.txtSourceSize.Text = "4.1 mm(Effective size)/3.6 mm(Effective size)";
         }
     }
 }
        public override void SaveOperation(object sender, RoutedEventArgs e)
        {
            //validations on each row
            foreach (var row in RGReportRows)
            {
                row.ThicknessRangeUI = row.ThicknessRange;
                row.TechnicianText   = row.Technique;
                //sl no should be unique
                var duplicateRow = RGReportRows.FirstOrDefault(p => p.SlNo == row.SlNo && p != row);
                if (duplicateRow != null)
                {
                    MessageBox.Show(string.Format("Sl no {0} has been repeated twice, Correct this before saving",
                                                  row.SlNo));
                    return;
                }

                //Location + segment uniqueness validation validation
                var conflictingRow =
                    RGReportRows.FirstOrDefault(
                        p => p.SlNo != row.SlNo && p.Location == row.Location && p.Segment == row.Segment);
                if (conflictingRow != null)
                {
                    MessageBox.Show(
                        string.Format(
                            "Rows with Sl No {0} and {1} have the same location and segments. Correct this before saving",
                            row.SlNo, conflictingRow.SlNo));
                    return;
                }
            }

            //set the viewing
            SetViewing();

            /** FOR SIMPLICITY OF DESIGN, SERVER DEPENDS ON THE CLIENT TO SET THE STATUS. THIS IS IMPORTANT! WITHOUT THIS THE LOGIC WILL FAIL **/

            MessageBoxResult result;

            if (RGReportRows.Any(p => p.RemarkText.Trim() == String.Empty))
            {
                result = MessageBox.Show("Save Incomplete Report. Fetching this RT No will fetch Same Report again",
                                         "Confirm Save", MessageBoxButton.OKCancel);
            }
            //for the first report, deleted rows do not affect status of the casting but for later reports if even a single row
            // is deleted, then the report can never be the final report (hence the casting will remain in pending state)
            else if (RGReportRows.Any(p => p.RemarkText.ToUpper() != "ACCEPTABLE") ||
                     ((!RGReport.First) && RGReport.RowsDeleted))
            {
                result =
                    MessageBox.Show(
                        "Mark Casting as Pending. At least one report is needed after this for this RT No",
                        "Confirm Save", MessageBoxButton.OKCancel);

                if (result != MessageBoxResult.Cancel)
                {
                    RGReport.Status =
                        ((RadiographyContext)DomainSource.DomainContext).RGStatus.FirstOrDefault(
                            p => p.Status == "CASTING UNDER REPAIR");
                }
            }
            else
            {
                result = MessageBox.Show("Mark Casting as complete. This will be Last Report for this RT No.",
                                         "Confirm Save", MessageBoxButton.OKCancel);

                if (result != MessageBoxResult.Cancel)
                {
                    RGReport.Status =
                        ((RadiographyContext)DomainSource.DomainContext).RGStatus.FirstOrDefault(
                            p => p.Status == "COMPLETE");
                }
            }

            //allow cancel
            if (result == MessageBoxResult.Cancel)
            {
                return;
            }
            UpdateReportDate();
            base.SaveOperation(sender, e);

            //update the energy grid
            UpdateEnergyWiseArea();

            //clear and repopulate the original entities collection
            OriginalEntities.Clear();
            OriginalEntities.Add(RGReport.ID, RGReport.Clone(ExcludePropertiesFromTracking));
        }