partial void DeleteKrestniJmena(KrestniJmena instance);
 partial void InsertKrestniJmena(KrestniJmena instance);
 partial void UpdateKrestniJmena(KrestniJmena instance);
        /// <summary>
        /// Reads in a spreadsheet containing given (first) names
        /// and adds the names to the given names database table if they don't already exist there.
        /// </summary>
        /// <param name="sender">originator of the event</param>
        /// <param name="e">additional details on the event</param>
        private void givenNamesMergeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string sGivenNames;
            string sGender = "Female"; // "Male"

            if (DialogResult.OK != Utilities.CheckForDataFile("GivenNames" + sGender + "Transliterated-2.xls", out sGivenNames))
                return;
            var fNames = new ExcelFile(sGivenNames);

            txtResponse.Clear();
            int iBlanks, iNames, iNew, iModified, iRow;
            for (iBlanks = 0, iNames = 0, iNew = 0, iModified = 0, iRow = 2; iBlanks < 5; ++iRow)
            {
                string sId = fNames.ValueAt(new Point(1, iRow)).Trim();
                string sNative = fNames.ValueAt(new Point(2, iRow)).Trim();
                string sHtml = fNames.ValueAt(new Point(3, iRow)).Trim();
                string sPlainText = fNames.ValueAt(new Point(4, iRow)).Trim();
                string sCount = fNames.ValueAt(new Point(5, iRow)).Trim();

                if ((iRow % 1000) == 0)
                {
                    txtResponse.AppendText("Row " + iRow + ": Name \"" + sNative + "\"" + Environment.NewLine);
                    Application.DoEvents();
                    // break;
                }

                if (string.IsNullOrEmpty(sPlainText))
                    ++iBlanks;
                else
                {
                    int iCount, iId;
                    if (!int.TryParse(sCount, out iCount))
                        txtResponse.AppendText(string.Format("Invalid count \"{0}\" found at row {1}{2}", sCount, iRow, Environment.NewLine));
                    if (!int.TryParse(sId, out iId ))
                        txtResponse.AppendText( string.Format("Invalid ID \"{0}\" found at row {1}{2}", sId, iRow, Environment.NewLine));

                    KrestniJmena q = (from jmNext in _mdB.KrestniJmenas
                                      where jmNext.CodePage == sNative
                                      select jmNext).FirstOrDefault();

                    bool bIsNewRecord = false;

                    if (q != null)
                    {
                        ++iModified;
                        //q.CodePage = sNative;
                        //q.Web = sHtml;
                        //q.PlainText = sPlainText;
                        // txtResponse.AppendText("Modifying existing entry \"" + sNative + "\" with ID=" + sId + " and Count=" + sCount + Environment.NewLine);
                        // Application.DoEvents();
                    }
                    else
                    {
                        bIsNewRecord = true;

                        if ((iCount > 1) || !sNative.Contains(' '))
                        {
                            ++iNew;
                            // txtResponse.AppendText("Adding new entry \"" + sNative + "\" with ID=" + sId + " and Count=" + sCount + Environment.NewLine);
                            q = new KrestniJmena {CodePage = sNative, Web = sHtml, PlainText = sPlainText};
                            // Application.DoEvents();
                        }
                    }

                    if (q != null)
                    {
                        switch (sGender)
                        {
                            case "Male":
                                q.MaleIndex = iId;
                                q.MaleCount = iCount;
                                break;
                            case "Female":
                                q.FemaleIndex = iId;
                                q.FemaleCount = iCount;
                                break;
                        }

                        if ( bIsNewRecord )
                            _mdB.KrestniJmenas.InsertOnSubmit(q);

                        try
                        {
                            _mdB.SubmitChanges();
                        }
                        catch (Exception ex)
                        {
                            txtResponse.AppendText(string.Format("Database error at row {0}: {1}{2}", iRow, ex, Environment.NewLine));
                        }
                    }

                    ++iNames;
                    iBlanks = 0;
                }
            }

            txtResponse.AppendText(iNames + " names found in spreadsheet" + Environment.NewLine);
            txtResponse.AppendText(iNew + " records added" + Environment.NewLine);
            txtResponse.AppendText(iModified + " records modified" + Environment.NewLine);
            fNames.Close();
        }