Ejemplo n.º 1
0
        private void ControlToFocus(TextBox txt, char key = ' ')
        {
            _currentTextBox = txt;
            _cboEditor.Hide();
            bool Proceed = true;
            var  s       = txt.Text;

            switch (txt.Name)
            {
            case "textSex":
                _cboEditor = _cboSex;
                break;

            case "textGMS":
                _cboEditor = _cboGMS;
                break;

            default:
                Proceed = false;
                break;
            }

            if (Proceed)
            {
                _cboEditor.Show();
                _cboEditor.Tag    = txt.Tag;
                _cboEditor.Bounds = txt.Bounds;
                _cboEditor.BringToFront();
                _cboEditor.Show();
                _cboEditor.Focus();

                if (key > ' ')
                {
                    var itemIndex = _cboEditor.FindString(key.ToString());
                    if (itemIndex > -1)
                    {
                        if (txt.Name == "textSex")
                        {
                            _cboEditor.Text = _cboEditor.Items[itemIndex].ToString();
                        }
                        else
                        {
                            var gmsStage = (KeyValuePair <FishCrabGMS, string>)_cboEditor.Items[itemIndex];
                            _cboEditor.Text = GMSManager.GMSStageToString(_taxa, gmsStage.Key);
                        }
                    }

                    _cboEditor.Text = key.ToString();
                }
                else if (s.Length > 0)
                {
                    _cboEditor.Text = s;
                }

                SetEditorEvents();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Populates fields if GMS data exists or adds a new row
        /// </summary>
        /// <param name="IsNew"></param>
        private void PopulateFieldControls(bool isNew, bool repopulate = false)
        {
            _y   = 5;
            _row = 1;
            if (repopulate)
            {
                foreach (var item in _gmsData)
                {
                    if (item.Value.DataStatus != fad3DataStatus.statusForDeletion)
                    {
                        AddRow(IsNew: false, item.Key, item.Value);
                    }
                }
            }
            else
            {
                if (isNew)
                {
                    //adds a new row of empty fields
                    AddRow(IsNew: true);
                }
                else
                {
                    _gmsData = GMSManager.RetrieveGMSData(_catchRowGuid);
                    foreach (var item in _gmsData)
                    {
                        AddRow(IsNew: false, item.Key, item.Value);
                    }
                }

                foreach (Control c in panelUI.Controls)
                {
                    if (c.GetType().Name == "TextBox")
                    {
                        ((TextBox)c).With(o =>
                        {
                            o.Font   = Font;
                            o.Height = _ctlHeight;
                        });
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void OncboEditor_Validating(object sender, CancelEventArgs e)
        {
            switch (_cboEditor.Name)
            {
            case "cboSex":
                _gmsData[_cboEditor.Tag.ToString()].Sex = (Sex)Enum.Parse(typeof(Sex), _cboEditor.Text);
                break;

            case "cboGMS":
                _gmsData[_cboEditor.Tag.ToString()].GMS = GMSManager.GMSStageFromString(_cboEditor.Text, _gmsData[_cboEditor.Tag.ToString()].Taxa);
                break;
            }

            if (_currentTextBox.Text != _cboEditor.Text)
            {
                _currentTextBox.Text = _cboEditor.Text;
                SetRowStatusToEdited(_currentTextBox);
            }
        }
Ejemplo n.º 4
0
 private bool SaveGMS()
 {
     return(GMSManager.UpdateGMSData(_gmsData));
 }
Ejemplo n.º 5
0
        private void AddRow(bool IsNew, string key = "", GMSLineClass gmsLine = null)
        {
            const int x    = 0;
            int       yPos = _y - Math.Abs(panelUI.AutoScrollPosition.Y);

            Label   labelRow        = new Label();
            TextBox textLength      = new TextBox();
            TextBox textWeight      = new TextBox();
            TextBox textGonadWeight = new TextBox();
            TextBox textGMS         = new TextBox();
            TextBox textSex         = new TextBox();

            //we only add the comboboxes once
            if (_row == 1 && _comboBoxesSet == false)
            {
                _comboBoxesSet = true;

                _cboSex.With(o =>
                {
                    o.Width              = 120;
                    o.Name               = "cboSex";
                    o.Location           = new Point(0, 0);
                    o.Visible            = false;
                    o.DropDownStyle      = ComboBoxStyle.DropDownList;
                    o.DataSource         = Enum.GetValues(typeof(Sex));
                    o.AutoCompleteSource = AutoCompleteSource.ListItems;
                    o.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
                    o.Font               = Font;
                    _ctlHeight           = o.Height;
                });

                _cboGMS.With(o =>
                {
                    o.Width              = 120;
                    o.Font               = Font;
                    o.Name               = "cboGMS";
                    o.Location           = new Point(0, 0);
                    o.DropDownStyle      = ComboBoxStyle.DropDownList;
                    o.AutoCompleteSource = AutoCompleteSource.ListItems;
                    o.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
                    var hasGMSStage      = false;
                    var gmsDict          = GMSManager.GMSStages(_taxa, ref hasGMSStage);
                    if (hasGMSStage)
                    {
                        o.DataSource         = new BindingSource(gmsDict, null);
                        o.DisplayMember      = "Value";
                        o.ValueMember        = "Key";
                        o.AutoCompleteSource = AutoCompleteSource.ListItems;
                    }
                    else
                    {
                    }
                    o.Visible = false;
                });

                panelUI.Controls.Add(_cboSex);
                panelUI.Controls.Add(_cboGMS);
            }

            panelUI.Controls.With(o =>
            {
                o.Add(labelRow);
                o.Add(textLength);
                o.Add(textWeight);
                o.Add(textSex);
                o.Add(textGMS);
                o.Add(textGonadWeight);
            });

            if (IsNew)
            {
                key = Guid.NewGuid().ToString();
                _gmsData.Add(key, new GMSLineClass(_catchRowGuid));
                _gmsData[key].RowGuid    = Guid.NewGuid().ToString();
                _gmsData[key].Sequence   = _row;
                _gmsData[key].DataStatus = fad3DataStatus.statusNew;
                _gmsData[key].Taxa       = _taxa;
            }

            labelRow.With(o =>
            {
                o.Text      = _row.ToString();
                o.Location  = new Point(x, yPos);
                o.Width     = 40;
                o.TextAlign = ContentAlignment.MiddleLeft;
                o.Name      = "labelRow";
                o.Tag       = key;
            });

            textLength.With(o =>
            {
                o.Width    = 60;
                o.Name     = "textLen";
                o.Location = new Point(labelRow.Left + labelRow.Width + _spacer, yPos);
                _ctlWidth  = o.Width;
                if (!IsNew)
                {
                    if (_gmsData[key].Length != null)
                    {
                        o.Text = _gmsData[key].Length.ToString();
                    }
                }
                o.Tag = key;
                SetTextBoxEvents(o);
            });

            textWeight.With(o =>
            {
                o.Width    = 60;
                o.Name     = "textWgt";
                o.Location = new Point(textLength.Left + textLength.Width + _spacer, yPos);
                if (!IsNew)
                {
                    if (_gmsData[key].Weight != null)
                    {
                        o.Text = _gmsData[key].Weight.ToString();
                    }
                }
                o.Tag = key;
                SetTextBoxEvents(o);
            });

            textSex.With(o =>
            {
                o.Width    = 60;
                o.Name     = "textSex";
                o.Location = new Point(textWeight.Left + textWeight.Width + _spacer, yPos);
                o.Width   += (int)(_ctlWidth * 0.5);
                if (!IsNew)
                {
                    o.Text = _gmsData[key].Sex.ToString();
                }
                o.Tag = key;
                SetTextBoxEvents(o);
            });

            textGMS.With(o =>
            {
                o.Width    = 60;
                o.Name     = "textGMS";
                o.Location = new Point(textSex.Left + textSex.Width + _spacer, yPos);
                o.Width   += _ctlWidth;
                if (!IsNew)
                {
                    o.Text = GMSManager.GMSStageToString(_gmsData[key].Taxa, _gmsData[key].GMS);
                }
                o.Tag = key;
                SetTextBoxEvents(o);
            });

            textGonadWeight.With(o =>
            {
                o.Width    = 60;
                o.Name     = "textGonadWeight";
                o.Location = new Point(textGMS.Left + textGMS.Width + _spacer, yPos);
                if (!IsNew)
                {
                    if (_gmsData[key].GonadWeight != null)
                    {
                        o.Text = _gmsData[key].GonadWeight.ToString();
                    }
                }
                o.Tag = key;
                SetTextBoxEvents(o);
            });

            textLength.Enabled      = chkLenght.Checked;
            textWeight.Enabled      = chkWeight.Checked;
            textSex.Enabled         = chkSex.Checked;
            textGMS.Enabled         = chkGMS.Checked;
            textGonadWeight.Enabled = chkGonadWt.Checked;

            if (_row == 1)
            {
                labelCol1.Left = labelRow.Left;
                labelCol2.Left = textLength.Left;
                labelCol3.Left = textWeight.Left;
                labelCol4.Left = textSex.Left;
                labelCol5.Left = textGMS.Left;
                labelCol6.Left = textGonadWeight.Left;
            }

            _y += labelRow.Height + _spacer;

            if (IsNew || _row >= GMSManager.GMSMeasurementRows)
            {
                _lastGMS     = textGMS;
                _lastGonadWt = textGonadWeight;
                _lastLength  = textLength;
                _lastSex     = textSex;
                _LastWeight  = textWeight;
            }
            _row++;
        }