private void InitializeSchemaList(string defaultValue)
        {
            data_mapping_schema aSchema = new data_mapping_schema();

            DataTable allSchemas = aSchema.Search(aSchema.SearchSQL + " ORDER BY schema_name");

            cmbSchema.Items.Clear();

            foreach (DataRow aRow in allSchemas.Rows)
            {
                aSchema = new data_mapping_schema();
                aSchema.Load(aRow);

                cmbSchema.Items.Add(aSchema);
            }



            cmbSchema.Items.Add("Create new schema...");

            if (defaultValue == "")
            {
                cmbSchema.SelectedIndex = 0;
            }
            else
            {
                cmbSchema.SelectedIndex = cmbSchema.FindStringExact(defaultValue);
            }
        }
        private void mnuSyncWithEclaims_Click(object sender, EventArgs e)
        {
            data_mapping_schema dms;
            SqlConnection       dbConnection;

            try
            {
                dms = new data_mapping_schema();
                dms.Load(3);
                dbConnection = new SqlConnection(dms.GetConnectionString(false));
                dbConnection.Open();
            }
            catch
            {
                MessageBox.Show(this, "Could not open connection to Dentrix database.", "Could not connect");
                return;
            }

            try
            {
                // Remove all batches with a source of external, then pull them all back in
                claim_batch toDelete = new claim_batch();

                toDelete.ExecuteNonQuery("DELETE claim_batch, batch_claim_list FROM claim_batch " +
                                         " LEFT JOIN batch_claim_list ON claim_batch.id = batch_claim_list.batch_id WHERE source = 1");
                // Got rid of the existing external stuff, now pull in the stuff from the last few months
                // NHDG_CLAIM_BATCHES - CLAIMBATCHID, BATCH_DATE, HANDLING ("Paper", "Electronic (ApexEDI)"
                // NHDG_CLAIM_TRANSACTIONS - CLAIM_ID, CLAIM_DB, CLAIMBATCHID, RESUBMIT_FLAG (char?), BATCH_RESUBMITTED

                Dictionary <string, int> batchIDData = new Dictionary <string, int>(); // Update this as I iterate through claim batches, we'll grab all the items for valid
                // bacthes in a 2nd sql statement
                string batchIDList = "";

                SqlCommand command = new SqlCommand("SELECT * FROM NHDG_CLAIM_BATCHES cb " +
                                                    "WHERE DATEDIFF(\"dd\", cb.BATCH_DATE, GETDATE()) < 200", dbConnection);

                SqlDataReader reader = command.ExecuteReader();


                while (reader.Read())
                {
                    claim_batch cb = new claim_batch();

                    cb.batch_date = (DateTime)reader["batch_date"];
                    cb.handling   = ConvertHandlingFromDentrix(reader["handling"].ToString());
                    cb.batch_info = "Imported from Eclaims";
                    cb["source"]  = 1;
                    cb.Save();
                    batchIDData.Add(reader["claimbatchid"].ToString(), cb.id);
                }

                reader.Close();
                if (batchIDData.Count > 0)
                {
                    foreach (KeyValuePair <string, int> kvp in batchIDData)
                    {
                        batchIDList += kvp.Key + ",";
                    }
                    batchIDList = batchIDList.TrimEnd(",".ToCharArray());
                    //Clipboard.SetText(batchIDList);
                    //MessageBox.Show("Here's my batchid list (it's in the clipboard): " + batchIDList);

                    string searchSQL = "SELECT * FROM NHDG_CLAIM_TRANSACTIONS WHERE CLAIMBATCHID IN (" + batchIDList +
                                       ")";
                    command = new SqlCommand(searchSQL, dbConnection);

                    //Clipboard.SetText(searchSQL);
                    //MessageBox.Show("And here's the search sql: " + searchSQL);
                    reader = command.ExecuteReader();
                    string bigMessageBox = "";
                    int    foundCount    = 0;
                    while (reader.Read())
                    {
                        int claimID = FindClaim(reader["claim_id"].ToString(), reader["claim_db"].ToString());

                        bigMessageBox += reader["claim_id"].ToString() + " | ";

                        if (claimID > 0)
                        {
                            batch_claim_list bcl = new batch_claim_list();
                            claim_batch      cb  = new claim_batch(batchIDData[reader["claimbatchid"].ToString()]);
                            bcl.batch_id          = cb.id;
                            bcl.claim_id          = claimID;
                            bcl.still_in_batch    = reader["resubmit_flag"].ToString() != "Y";
                            bcl["last_send_date"] = cb.batch_date;
                            bcl.Save();

                            foundCount++;
                        }
                    }

                    //MessageBox.Show("Here are the claimIDs that were searched for. ( " + foundCount + " were found.)\n" + bigMessageBox);
                }
            }


            catch (Exception ex)
            {
                MessageBox.Show(this, "An unexpected error occurred syncing data.\n\n" + ex.Message);
            }

            MessageBox.Show(this, "Sync successful!", "Sync with Eclaims", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }