コード例 #1
0
        // 0 - saved
        // 1 - empty/used name
        // 2 - empty fields
        private int SaveMeasurement(string name)
        {
            Measurement m = new Measurement();

            try {
                m.name        = name;
                m.distance    = float.Parse(DistanceTextBox.Text, nfi);
                m.wireLenghtT = float.Parse(LengthTextBoxT.Text, nfi);
                m.wireLenghtR = float.Parse(LengthTextBoxR.Text, nfi);

                m.transmitter_id = (IsCustom(TransmitterComboBox.Text) ? this.dm.AddCustomDevice(new Device()
                {
                    name = "custom", gain = (float)GetValue(GainTextBoxT), power = (float)GetValue(PowerTextBoxT)
                }).id : this.dm.GetDeviceByName(TransmitterComboBox.Text).id);
                m.receiver_id    = (IsCustom(ReceiverComboBox.Text) ? this.dm.AddCustomDevice(new Device()
                {
                    name = "custom", gain = (float)GetValue(GainTextBoxR), power = 0
                }).id : this.dm.GetDeviceByName(ReceiverComboBox.Text).id);

                m.wireT_id = (IsCustom(WireComboBoxT.Text) ? this.wm.AddCustomWire(new Wire()
                {
                    name = "custom"
                }, new WireAttenuation()
                {
                    frequency = (float)GetValue(FrequencyTextBox), value = (float)GetValue(AttenuationWireTextBoxT)
                }).id : this.wm.GetWireByName(WireComboBoxT.Text).id);
                m.wireR_id = (IsCustom(WireComboBoxR.Text) ? this.wm.AddCustomWire(new Wire()
                {
                    name = "custom"
                }, new WireAttenuation()
                {
                    frequency = (float)GetValue(FrequencyTextBox), value = (float)GetValue(AttenuationWireTextBoxR)
                }).id : this.wm.GetWireByName(WireComboBoxR.Text).id);

                m.connectorT_id = (IsCustom(ConnectorComboBoxT.Text) ? this.cm.AddCustomConnector(new Connector()
                {
                    name = "custom", attenuation = (float)GetValue(AttenuationConnectorTextBoxT)
                }).id : this.cm.GetConnectorByName(ConnectorComboBoxT.Text).id);
                m.connectorR_id = (IsCustom(ConnectorComboBoxR.Text) ? this.cm.AddCustomConnector(new Connector()
                {
                    name = "custom", attenuation = (float)GetValue(AttenuationConnectorTextBoxR)
                }).id : this.cm.GetConnectorByName(ConnectorComboBoxR.Text).id);

                m.channel_id = this.chm.GetChannelByFrequency(Int32.Parse(FrequencyTextBox.Text, nfi)).id;
            } catch (NullReferenceException ex) { // custom
            } catch (FormatException ex) {        // empty or wrong value
                return(2);
            } catch (Exception ex) {              //wrong value
            }
            if (this.mm.AddMeasurement(m))
            {
                foreach (DataGridViewRow row in ObstaclesDataGridView.Rows)
                {
                    if (row.Cells["ObstacleColumn"].Value != null)
                    {
                        ObstacleAmount om = new ObstacleAmount();
                        om.amount = (int)GetValue(row.Cells["ObstacleAmountColumn"]);
                        if (IsCustom(row.Cells["ObstacleColumn"].Value.ToString()))
                        {
                            om.obstacles_id = this.om.AddCustomObstacle(new Obstacle()
                            {
                                name = "custom", attenuation_24 = (BandComboBox.Text == "2.4" ? float.Parse(row.Cells["ObstacleAttenuationtColumn"].Value.ToString()) : 0), attenuation_5 = (BandComboBox.Text == "5.0" ? float.Parse(row.Cells["ObstacleAttenuationtColumn"].Value.ToString()) : 0)
                            }).id;
                        }
                        else
                        {
                            om.obstacles_id = this.om.GetObstacleByName(row.Cells["ObstacleColumn"].Value.ToString()).id;
                        }
                        om.measurements_id = m.id;

                        this.omm.AddObstacleAmount(om);
                    }
                }

                return(0);
            }
            else
            {
                return(1);
            }
        }
コード例 #2
0
 public void AddObstacleAmount(ObstacleAmount om)
 {
     this.rep.Insert(om);
     rep.Commit();
 }