private bool DataIsValid()
        {
            if (string.IsNullOrEmpty(txtCode.Text))
            {
                MessageDialog.ShowValidationError(txtCode, "Code must not be blank");
                return(false);
            }

            if (string.IsNullOrEmpty(txtDescription.Text))
            {
                MessageDialog.ShowValidationError(txtDescription, "Description must not be blank");
                return(false);
            }


            var reader = new PositionDataReader();
            var item   = reader.GetItemWithCode(txtCode.Text.Trim());

            if (item != null && item.Id != ItemData.Id)
            {
                MessageDialog.ShowValidationError(txtCode, "Duplicate Position Code Exist!");
                return(false);
            }

            return(true);
        }
예제 #2
0
        public override void on_data_available(DDS.DataReader reader)
        {
            if (reader.GetType() == typeof(PositionDataReader))
            {
                PositionDataReader Position_reader =
                    (PositionDataReader)reader;

                try
                {
                    Position_reader.take(
                        pdata_seq,
                        info_seq,
                        DDS.ResourceLimitsQosPolicy.LENGTH_UNLIMITED,
                        DDS.SampleStateKind.ANY_SAMPLE_STATE,
                        DDS.ViewStateKind.ANY_VIEW_STATE,
                        DDS.InstanceStateKind.ANY_INSTANCE_STATE);
                }
                catch (DDS.Retcode_NoData)
                {
                    return;
                }
                catch (DDS.Exception e)
                {
                    Console.WriteLine("take error {0}", e);
                    return;
                }
                Console.WriteLine("MessageType\t Route\t\t Vehicle\t Traffic\t Stop#\t #Stops\t TimeBetweenStops\t Fill%\t TimeStamp");
                System.Int32 data_length = pdata_seq.length;
                for (int i = 0; i < data_length; ++i)
                {
                    if (info_seq.get_at(i).valid_data)
                    {
                        Position p = pdata_seq.get_at(i);
                        Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}",
                                          "Position", p.route, p.vehicle, p.trafficConditions, p.stopNumber, p.numStops, p.timeBetweenStops, p.fillInRatio, p.timestamp);
                        //PositionTypeSupport.print_data(pdata_seq.get_at(i));
                    }
                }

                try
                {
                    Position_reader.return_loan(pdata_seq, info_seq);
                }
                catch (DDS.Exception e)
                {
                    Console.WriteLine("return loan error {0}", e);
                }
            }
            else
            {
                AccidentDataReader Accident_reader =
                    (AccidentDataReader)reader;

                try
                {
                    Accident_reader.take(
                        adata_seq,
                        info_seq,
                        DDS.ResourceLimitsQosPolicy.LENGTH_UNLIMITED,
                        DDS.SampleStateKind.ANY_SAMPLE_STATE,
                        DDS.ViewStateKind.ANY_VIEW_STATE,
                        DDS.InstanceStateKind.ANY_INSTANCE_STATE);
                }
                catch (DDS.Retcode_NoData)
                {
                    return;
                }
                catch (DDS.Exception e)
                {
                    Console.WriteLine("take error {0}", e);
                    return;
                }

                System.Int32 data_length = adata_seq.length;
                for (int i = 0; i < data_length; ++i)
                {
                    if (info_seq.get_at(i).valid_data)
                    {
                        Accident a = adata_seq.get_at(i);
                        Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}",
                                          "Accident", a.route, a.vehicle, string.Empty, a.stopNumber, string.Empty, string.Empty, string.Empty, a.timestamp);

                        //AccidentTypeSupport.print_data(adata_seq.get_at(i));
                    }
                }

                try
                {
                    Accident_reader.return_loan(adata_seq, info_seq);
                }
                catch (DDS.Exception e)
                {
                    Console.WriteLine("return loan error {0}", e);
                }
            }
        }