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)";
         }
     }
 }
        //Kept here only for the template column to work fine
        public override void DeleteOperation(object sender, RoutedEventArgs e)
        {
            if (
                MessageBox.Show("Are you sure you want to delete this item?", "Confirm Delete",
                                MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
            {
                return;
            }

            DataGridRow row = DataGridRow.GetRowContainingElement(sender as FrameworkElement);

            //commit any unsaved changes to avoid an exception
            if (Grid.CommitEdit())
            {
                var rowToBeRemoved = (RGReportRow)row.DataContext;
                RGReportRows.Remove(rowToBeRemoved);
                //also delete from the datacontext
                ((RadiographyContext)this.DomainSource.DomainContext).RGReportRows
                .Remove(rowToBeRemoved as RGReportRow);

                //mark at least one row deleted
                RGReport.RowsDeleted = true;
            }
            UpdateSourceBasedOnThickness();
        }
        public override void AddOperation(object sender, RoutedEventArgs e)
        {
            //also give a few default empty string values so that UI copy operation is possible
            var rgReportRow = new RGReportRow
            {
                RGReport = this.RGReport,
                //auto increment sl no for each additional row
                SlNo             = RGReportRows.Max(p => p.SlNo) + 1,
                Density          = " ",
                Designation      = " ",
                Location         = " ",
                Segment          = " ",
                Sensitivity      = " ",
                FilmSizeString   = " ",
                RemarkText       = " ",
                TechnicianText   = " ",
                Observations     = " ",
                WelderText       = " ",
                RetakeReasonText = " ",
                FilmCount        = 1, //default value for film counts
                RowType          = ((RadiographyContext)DomainSource.DomainContext)
                                   .RGReportRowTypes
                                   .FirstOrDefault(p => p.Value == "FRESH")
            };

            RGReportRows.Add(rgReportRow);
            OnPropertyChanged("RGReportRows");
        }
        public void UpdateEnergyWiseArea()
        {
            var ctx = (RadiographyContext)this.DomainSource.DomainContext;
            var dt  = new DataTable("EnergyTable");

            var     headerRow  = new DataRow();
            DataRow actualRow1 = new DataRow();
            DataRow actualRow2 = new DataRow();

            AddTextColumn(dt, "HeadRow", "HeadRow");
            headerRow["FilmHeadRow"]  = "Film Count";
            actualRow1["FilmHeadRow"] = "First Film";
            actualRow2["FilmHeadRow"] = "Additional Film";

            headerRow["HeadRow"]  = "Isotope";
            actualRow1["HeadRow"] = "Sq. Inches";
            actualRow2["HeadRow"] = "Sq. Inches";

            //instead of encountering an error if context is still loading, just don't do it, it will get
            //done on the first save operation
            if (ctx.IsLoading)
            {
                return;
            }
            if (ctx.Energies != null && RGReportRows != null)
            {
                foreach (var e in ctx.Energies)
                {
                    AddTextColumn(dt, e.Name, e.Name);
                    headerRow[e.Name]  = e.Name;
                    actualRow1[e.Name] = RGReportRows
                                         .Where(p => p.EnergyID == e.ID &&
                                                p.RemarkText != "RETAKE")
                                         //30-Jun-12 - Roopesh added this to ensure that retake areas are not included
                                         .Sum(p => p.FilmSize.Area * 1);

                    actualRow2[e.Name] = RGReportRows
                                         .Where(p => p.EnergyID == e.ID &&
                                                p.RemarkText != "RETAKE")
                                         //30-Jun-12 - Roopesh added this to ensure that retake areas are not included
                                         .Sum(p => p.FilmSize.Area * (p.FilmCount > 1 ? (p.FilmCount - 1) : 0));
                }
            }

            dt.Rows.Add(headerRow);
            dt.Rows.Add(actualRow1);
            dt.Rows.Add(actualRow2);

            energyAreas.DataSource = dt;
            energyAreas.DataBind();

            OnPropertyChanged("TotalArea");
        }
 public void UpdatedStatus()
 {
     if (RGReport.StatusID == 2)
     {
         if (RGReportRows.SelectMany(p => p.Classifications).Count() > 0)
         {
             lblStatus.Text = "CASTING ACCEPTABLE AS PER LEVEL " + RGReportRows.SelectMany(p => p.Classifications.Split(',')).Where(m => !string.IsNullOrEmpty(m)).Select(int.Parse).Max();
         }
         else
         {
             lblStatus.Text = "CASTING ACCEPTABLE AS PER LEVEL 1";
         }
     }
 }
        private void btnPaste_Click(object sender, RoutedEventArgs e)
        {
            if (RGReportRowForCopying != null)
            {
                var rgReportRow = new RGReportRow
                {
                    RGReport = this.RGReport,
                    //auto increment sl no for each additional row
                    SlNo             = RGReportRows.Max(p => p.SlNo) + 1,
                    Density          = RGReportRowForCopying.Density,
                    Designation      = RGReportRowForCopying.Designation,
                    Location         = RGReportRowForCopying.Location,
                    Segment          = RGReportRowForCopying.Segment,
                    Sensitivity      = RGReportRowForCopying.Sensitivity,
                    FilmSizeString   = RGReportRowForCopying.FilmSizeString,
                    RemarkText       = RGReportRowForCopying.RemarkText,
                    TechnicianText   = RGReportRowForCopying.TechnicianText,
                    Observations     = RGReportRowForCopying.Observations,
                    WelderText       = RGReportRowForCopying.WelderText,
                    RetakeReasonText = RGReportRowForCopying.RetakeReasonText,
                    FilmCount        = RGReportRowForCopying.FilmCount, //default value for film counts
                    RowType          = ((RadiographyContext)DomainSource.DomainContext)
                                       .RGReportRowTypes
                                       .FirstOrDefault(p => p.Value == "FRESH"),
                    Energy           = RGReportRowForCopying.Energy,
                    EnergyText       = RGReportRowForCopying.EnergyText,
                    FilmSize         = RGReportRowForCopying.FilmSize,
                    Technique        = RGReportRowForCopying.Technique,
                    Remark           = RGReportRowForCopying.Remark,
                    RetakeReason     = RGReportRowForCopying.RetakeReason,
                    Technician       = RGReportRowForCopying.Technician,
                    Welder           = RGReportRowForCopying.Welder,
                    TechniqueText    = RGReportRowForCopying.TechniqueText,
                    ThicknessRange   = RGReportRowForCopying.ThicknessRange,
                    ThicknessRangeUI = RGReportRowForCopying.ThicknessRangeUI,
                    SFD = RGReportRowForCopying.SFD
                };

                RGReportRows.Add(rgReportRow);
                OnPropertyChanged("RGReportRows");
            }
            else
            {
                MessageBox.Show("Please copy any one row to paste!!");
                return;
            }
        }
        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));
        }