示例#1
0
        public override void domainDataSource_LoadedData(object sender, LoadedDataEventArgs e)
        {
            base.domainDataSource_LoadedData(sender, e);
            //first item returned is the latest RG Report for the combination of inputs
            if (((DomainDataSourceView)((DomainDataSource)sender).Data).IsEmpty)
            {
                MessageBox.Show("Wrong Inputs Or RT No Already Completed\n\nCheck and try again");
                return;
            }

            RGReport     = (RGReport)((DomainDataSourceView)((DomainDataSource)sender).Data).GetItemAt(0);
            RGReportRows = RGReport.RGReportRows;

            //now that fixedpatternid is available
            FixedPatternsSource.Load();
            UpdateEnergyWiseArea();
            OnPropertyChanged("TotalArea");
            SetViewing();

            //if edit mode, add a clone of original RGReport to original entities for change tracking
            if (IsEditMode)
            {
                OriginalEntities.Add(RGReport.ID, RGReport.Clone(ExcludePropertiesFromTracking));
            }
        }
        public override void domainDataSource_LoadedData(object sender, LoadedDataEventArgs e)
        {
            base.domainDataSource_LoadedData(sender, e);
            //first item returned is the latest RG Report for the combination of inputs
            if (((DomainDataSourceView)((DomainDataSource)sender).Data).IsEmpty)
            {
                MessageBox.Show("Wrong Inputs Or RT No Already Completed\n\nCheck and try again");
                return;
            }

            RGReport     = (RGReport)((DomainDataSourceView)((DomainDataSource)sender).Data).GetItemAt(0);
            RGReportRows = RGReport.RGReportRows;
            //now that fixedpatternid is available
            FixedPatternsSource.Load();

            UpdateEnergyWiseArea();
            OnPropertyChanged("TotalArea");
            SetViewing();
            UpdatedStatus();
            if (isFromFetchMethod)
            {
                var      ctx      = (RadiographyContext)this.DomainSource.DomainContext;
                Coverage coverage = (Coverage)cmbCoverage.SelectedItem;
                ctx.Load(ctx.GetFixedPatternDetailsQuery(txtFPNo.Text, coverage.CoverageName, txtRTNo.Text));

                UpdateSourceBasedOnThickness();
                RGReport.FixedPattern = ctx.FixedPatterns.FirstOrDefault();
            }
            isFromFetchMethod = false;
            //if edit mode, add a clone of original RGReport to original entities for change tracking
            if (IsEditMode)
            {
                OriginalEntities.Add(RGReport.ID, RGReport.Clone(ExcludePropertiesFromTracking));
            }
            //ProcedureReference();
            BindToPage(cmbProcedureRef, ComboBox.SelectedValueProperty, "ProcedureReferences");
            BindToPage(cmbSpecifications, ComboBox.SelectedValueProperty, "Specifications");
            BindToPage(cmbAcceptance, ComboBox.SelectedValueProperty, "AcceptanceAsPers");
        }
        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));
        }