private void OnButton_Click(object sender, EventArgs e)
        {
            switch (((Button)sender).Name)
            {
            case "buttonOK":
                if (ValidateData())
                {
                    SaveOptionsToRegistry();
                    if (SaveGMS())
                    {
                        Close();
                        _parent_form.RefreshLF_GMS();
                    }
                }
                break;

            case "buttonCancel":
                Close();
                break;

            case "buttonAdd":

                if ((chkSex.Checked && _lastSex.Text.Length == 0)
                    // if an option is checked, then its corresponding textbox must not be empty
                    || (chkLenght.Checked && _lastLength.Text.Length == 0) ||
                    (chkGMS.Checked && _lastGMS.Text.Length == 0) ||
                    (chkGonadWt.Checked && _lastGonadWt.Text.Length == 0) ||
                    (chkWeight.Checked && _LastWeight.Text.Length == 0))
                {
                    if (chkSex.Checked && _lastSex.Text.Length == 0)
                    {
                        _lastSex.BackColor = global.MissingFieldBackColor;
                    }
                    if (chkLenght.Checked && _lastLength.Text.Length == 0)
                    {
                        _lastLength.BackColor = global.MissingFieldBackColor;
                    }
                    if (chkGMS.Checked && _lastGMS.Text.Length == 0)
                    {
                        _lastGMS.BackColor = global.MissingFieldBackColor;
                    }
                    if (chkGonadWt.Checked && _lastGonadWt.Text.Length == 0)
                    {
                        _lastGonadWt.BackColor = global.MissingFieldBackColor;
                    }
                    if (chkWeight.Checked && _LastWeight.Text.Length == 0)
                    {
                        _LastWeight.BackColor = global.MissingFieldBackColor;
                    }

                    MessageBox.Show("Please fill up the the data fields", "Validation error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    AddRow(IsNew: true);
                    _lastLength.Focus();
                }
                break;

            case "buttonRemove":
                GMSLineClass gls = _gmsData[_currentRow];
                gls.DataStatus        = fad3DataStatus.statusForDeletion;
                _gmsData[_currentRow] = gls;
                panelUI.Controls.Clear();
                if (_gmsData.Count == 1 || FieldRowCount() == 0)
                {
                    PopulateFieldControls(isNew: true);
                }
                else
                {
                    PopulateFieldControls(isNew: false, repopulate: true);
                }
                break;
            }
        }
        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++;
        }
示例#3
0
        public static Dictionary <string, GMSLineClass> RetrieveGMSData(string CatchCompRowNo)
        {
            _GMSMeasurementRows = 0;
            Dictionary <string, GMSLineClass> mydata = new Dictionary <string, GMSLineClass>();
            var dt = new DataTable();

            using (var conection = new OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0;data source=" + global.MDBPath))
            {
                try
                {
                    conection.Open();

                    string query = $@"SELECT tblGMS.RowGUID, tblGMS.Gonadwt, tblGMS.GMS, tblGMS.Sex, tblGMS.Wt, tblGMS.Len,
                                   tblGMS.CatchCompRow, tblGMS.Sequence, tblTaxa.TaxaNo, tblTaxa.Taxa FROM tblTaxa INNER JOIN
                                   (tblAllSpecies INNER JOIN(tblCatchComp INNER JOIN tblGMS ON
                                   tblCatchComp.RowGUID = tblGMS.CatchCompRow) ON
                                   tblAllSpecies.SpeciesGUID = tblCatchComp.NameGUID)
                                   ON tblTaxa.TaxaNo = tblAllSpecies.TaxaNo
                                   WHERE tblGMS.CatchCompRow ={{{CatchCompRowNo}}} ORDER By tblGMS.Sequence";

                    var adapter = new OleDbDataAdapter(query, conection);
                    adapter.Fill(dt);
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        DataRow dr = dt.Rows[i];

                        FishCrabGMS gms;
                        Enum.TryParse(dr["GMS"].ToString(), out gms);
                        Sex sex;
                        Enum.TryParse(dr["Sex"].ToString(), out sex);
                        Taxa taxa = Taxa.To_be_determined;
                        Enum.TryParse(dr["TaxaNo"].ToString(), out taxa);
                        double?Length      = null;
                        double?Weight      = null;
                        double?GonadWeight = null;
                        int    Sequence    = 0;

                        if (dr["Len"].ToString().Length > 0)
                        {
                            Length = double.Parse(dr["Len"].ToString());
                        }

                        if (dr["Wt"].ToString().Length > 0)
                        {
                            Weight = double.Parse(dr["Wt"].ToString());
                        }

                        if (dr["GonadWt"].ToString().Length > 0)
                        {
                            GonadWeight = double.Parse(dr["GonadWt"].ToString());
                        }

                        if (dr["Sequence"].ToString().Length > 0)
                        {
                            Sequence = int.Parse(dr["Sequence"].ToString());
                        }

                        GMSLineClass myGMS = new GMSLineClass(dr["CatchCompRow"].ToString(), dr["RowGUID"].ToString(),
                                                              Length, Weight, GonadWeight, sex, gms, dr["Taxa"].ToString(), taxa,
                                                              fad3DataStatus.statusFromDB, Sequence);

                        mydata.Add(dr["RowGUID"].ToString(), myGMS);
                        _GMSMeasurementRows++;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex.Message, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name);
                }
            }
            return(mydata);
        }