private void OnTextBoxes_Validating(object sender, CancelEventArgs e) { var msg = ""; var o = (TextBox)sender; switch (o.Name) { case "txtGenus": case "txtSpecies": if (o.Text.Length < 2 && o.Text.Length > 0) { msg = "Name is too short"; e.Cancel = true; } else { var metaPhone = new DoubleMetaphoneShort(); if (o.Name == "txtGenus") { _genus = o.Text.Trim(); metaPhone.ComputeMetaphoneKeys(_genus, out short k1, out short k2); _genusMPH1 = k1; _genusMPH2 = k2; //ensure capitalization of first letter _genus = _genus[0].ToString().ToUpper() + _genus.Substring(1, _genus.Length - 1).ToLower(); o.Text = _genus; } else { _species = o.Text.Trim().ToLower(); metaPhone.ComputeMetaphoneKeys(_species, out short k1, out short k2); _speciesMPH1 = k1; _speciesMPH2 = k2; o.Text = _species; } } break; case "txtNotes": _notes = o.Text; break; } if (!e.Cancel && _dataStatus != fad3DataStatus.statusNew) { _dataStatus = o.Text != _genus ? fad3DataStatus.statusEdited : default; } else if (e.Cancel) { MessageBox.Show(msg, "Validation error", MessageBoxButtons.OK, MessageBoxIcon.Information); } o = null; }
public NewFisheryObjectName(string newName, FisheryObjectNameType nameType) { ObjectGUID = Guid.NewGuid().ToString(); NewName = newName; NameType = nameType; var mph = new DoubleMetaphoneShort(); mph.ComputeMetaphoneKeys(newName, out short key1, out short key2); Key1 = key1; Key2 = key2; }
private void SpeciesNameForm_Load(object sender, EventArgs e) { foreach (var item in CatchName.RetrieveTaxaDictionary()) { cboTaxa.Items.Add(item); } cboTaxa.DisplayMember = "Value"; cboTaxa.ValueMember = "Key"; cboTaxa.DropDownStyle = ComboBoxStyle.DropDownList; cboTaxa.AutoCompleteSource = AutoCompleteSource.ListItems; cboTaxa.AutoCompleteMode = AutoCompleteMode.Append; txtGenus.Text = _genus; txtSpecies.Text = _species; if (_dataStatus != fad3DataStatus.statusNew) { var speciesData = Names.RetrieveSpeciesData(_nameGuid); _taxaName = cboTaxa.Text = CatchName.TaxaNameFromTaxa(speciesData.taxa); _inFishBase = chkInFishbase.Checked = speciesData.inFishbase; _fishBaseSpeciesNumber = speciesData.fishBaseNo; _notes = txtNotes.Text = speciesData.notes; _genusMPH1 = speciesData.genusKey1 ?? default; _genusMPH2 = speciesData.genusKey2 ?? default; _speciesMPH1 = speciesData.speciesKey1 ?? default; _speciesMPH2 = speciesData.speciesKey2 ?? default; _catchCompositionRecordCount = Names.CatchCompositionRecordCount(_nameGuid); labelRecordCount.Text = _catchCompositionRecordCount.ToString(); if (_taxa == Taxa.Cephalopods) { _taxaName = "Cephalopods (squids etc)"; } else { _taxaName = _taxa.ToString(); } cboTaxa.Text = _taxaName; if (_catchCompositionRecordCount == 0) { buttonEdit.Text = "Delete"; } } else { labelRecordCount.Text = "0"; _nameGuid = Guid.NewGuid().ToString(); if (_genus.Length > 0 && _species.Length > 0) { var speciesFishBaseData = Names.NameInFishBaseEx(_genus, _species); _inFishBase = chkInFishbase.Checked = speciesFishBaseData.inFishBase; _fishBaseSpeciesNumber = speciesFishBaseData.fishBaseSpeciesNo; if (chkInFishbase.Checked) { cboTaxa.Text = "Fish"; } var metaPhone = new DoubleMetaphoneShort(); metaPhone.ComputeMetaphoneKeys(_genus, out short k1, out short k2); _genusMPH1 = k1; _genusMPH2 = k2; metaPhone.ComputeMetaphoneKeys(_species, out k1, out k2); _speciesMPH1 = k1; _speciesMPH2 = k2; var SimilarSoundingList = Names.RetrieveSpeciesWithSimilarMetaPhone(_genusMPH1, _genusMPH2, _speciesMPH1, _speciesMPH2); if (SimilarSoundingList.Count > 0) { Width = (int)(Width * 2); ListView lvSimilarNames = new ListView { Name = "lvSimilarNames", Top = txtSpecies.Top, Left = txtGenus.Left + txtGenus.Width + 20, Height = (txtNotes.Top + txtNotes.Height) - txtSpecies.Top, View = View.List, }; lvSimilarNames.Width = Width - (lvSimilarNames.Left + 20); lvSimilarNames.DoubleClick += OnListViewDoubleClick; Label labelSimilar = new Label { Left = lvSimilarNames.Left, Top = labelGenus.Top, Text = "Similar sounding names", AutoSize = false, Width = lvSimilarNames.Width }; Controls.Add(lvSimilarNames); Controls.Add(labelSimilar); foreach (var item in SimilarSoundingList) { var lvi = new ListViewItem(new string[] { item.fullName, item.genus, item.species }); lvSimilarNames.Items.Add(lvi); } } } buttonEdit.Enabled = false; } if (ReadOnly) { buttonCancel.Visible = false; buttonOK.Text = "Close"; } global.LoadFormSettings(this, true); }
public static bool AddCatchName(string nameGuid, string identification, string name1, string name2, int?taxaNumber = null, bool inFishbase = false, int?fbSpeciesNumber = null) { bool success = false; string sql = ""; var dms = new DoubleMetaphoneShort(); if (identification == "Scientific") { dms.ComputeMetaphoneKeys(name1, out short g1, out short g2); dms.ComputeMetaphoneKeys(name2, out short s1, out short s2); sql = $@"Insert into tblAllSpecies(Genus,species,ListedFB,TaxaNo,FBSpNo,SpeciesGUID,MPHG1,MPHG2,MPHS1,MPHS2) values ( '{name1}', '{name2}', {inFishbase}, {taxaNumber}, {(fbSpeciesNumber == null ? "null" : fbSpeciesNumber.ToString())}, {{{nameGuid}}}, {g1}, {g2}, {s1}, {s2} )"; } else if (identification == "LocalName") { dms.ComputeMetaphoneKeys(name1, out short ln1, out short ln2); sql = $@"Insert into tblBaseLocalNames(Name, NameNo, MPH1,MPH2) values ( '{name1}', {{{nameGuid}}}, {ln1}, {ln2} )"; } using (var conn = new OleDbConnection(global.ConnectionString)) { conn.Open(); using (OleDbCommand update = new OleDbCommand(sql, conn)) { try { success = update.ExecuteNonQuery() > 0; if (success) { string idType = ""; switch (identification) { case "Scientific": idType = "Species names"; break; case "LocalName": idType = "Local names"; break; } sql = $@"Insert into temp_AllNames (Name1,Name2,NameNo,Identification) values ( '{name1}','{name2}',{{{nameGuid}}},'{idType}' )"; using (OleDbCommand updateAll = new OleDbCommand(sql, conn)) { try { updateAll.ExecuteNonQuery(); } catch (OleDbException dbex) { Logger.Log(dbex.Message, "CatchName", "AddCatchName"); } catch (Exception ex1) { Logger.Log(ex1.Message, "CatchName", "AddCatchName"); } } } } catch (OleDbException) { success = false; } catch (Exception ex) { Logger.Log(ex.Message, "CatchName", "AddCatchName"); } } } return(success); }