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 cmdImport_Click(object sender, EventArgs e)
 {
     if (cmbSchema.SelectedIndex >= 0)
     {
         if (!chkMergeData.Checked)
         {
             if (MessageBox.Show(this, "You have selected not to merge with existing information. All current data will be " +
                                 "deleted, including calls, claim batches, and other information.\n\nAre you sure you want to do this?", "Import and Replace Data", MessageBoxButtons.YesNo) == DialogResult.Yes)
             {
                 okToZap = true;
             }
             else
             {
                 CancelImport();
                 return;
             }
         }
         else
         {
             if (chkMergeChanges.Checked)
             {
                 changesOnly = true;
             }
         }
         Cursor = Cursors.WaitCursor;
         dms    = (data_mapping_schema)cmbSchema.SelectedItem;
         ImportThread.RunWorkerAsync();
     }
 }
Пример #3
0
 public frmConfigureSchema(data_mapping_schema schemaToLoad)
 {
     InitializeComponent();
     _formSchema = schemaToLoad;
     InitializeDataTypesDropDown();
     LoadData();
 }
        private void cmbSchema_SelectedIndexChanged(object sender, EventArgs e)
        {
            data_mapping_schema toLoad;

            if (cmbSchema.SelectedIndex == cmbSchema.Items.Count - 1)
            {
                toLoad                     = new data_mapping_schema();
                toLoad.schema_name         = GenerateNewName();
                toLoad.data_type           = DataMappingConnectionTypes.SQLServer;
                toLoad.allow_password_save = false;
                toLoad.Save();
                frmConfigureSchema toShow = new frmConfigureSchema(toLoad);
                toShow.ShowDialog();

                InitializeSchemaList(toShow.SchemaName);
            }
        }
        private void sendEclaimsDataToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string XMLPATH = Application.StartupPath + "\\syncdata.xml";
            // start by getting the date everything was sent out from the xml file
            DateTime lastWrite    = new DateTime(1999, 12, 31);
            bool     okToContinue = true;

            if (File.Exists(XMLPATH))
            {
                XmlDocument toOpen = new XmlDocument();
                toOpen.Load(XMLPATH);

                try
                {
                    XmlElement ele = toOpen.DocumentElement;
                    lastWrite = System.Convert.ToDateTime(ele.InnerText);
                }
                catch
                {
                    // assume the data is corrupt and there was no last write date.
                    okToContinue = MessageBox.Show(this, "The file that specifies which batches have been sent to eclaims has been corrupted. Would you like to continue and " +
                                                   "send all batches to eclaims?", "Sync File Corrupt", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes;
                }
            }
            int count = 0;

            if (okToContinue)
            {
                // Get the claims to process
                List <claim_batch> cbList    = new List <claim_batch>();
                claim_batch        cb        = new claim_batch();
                string             searchSQL = "SELECT * FROM claim_batch WHERE batch_date > CAST('" + CommonFunctions.ToMySQLDateTime(lastWrite)
                                               + "' AS DATETIME) AND SOURCE = 0";
                DataTable dt = cb.Search(searchSQL);
                count = dt.Rows.Count;

                foreach (DataRow aBatch in dt.Rows)
                {
                    cb = new claim_batch();
                    cb.Load(aBatch);
                    cbList.Add(cb);
                }



                // Add the claims as claims in Dentrix
                // NHDG_CLAIM_BATCHES - CLAIMBATCHID, BATCH_DATE, HANDLING ("Paper", "Electronic (ApexEDI)"
                // NHDG_CLAIM_TRANSACTIONS - CLAIM_ID, CLAIM_DB, CLAIMBATCHID, RESUBMIT_FLAG (char?), BATCH_RESUBMITTED
                data_mapping_schema dms          = new data_mapping_schema(3);
                SqlConnection       dbConnection = new SqlConnection(dms.GetConnectionString(false));

                try
                {
                    dbConnection.Open();

                    foreach (claim_batch aBatch in cbList)
                    {
                        SqlCommand sc = new SqlCommand("INSERT INTO NHDG_CLAIM_BATCHES (batch_date, handling) VALUES ('" +
                                                       CommonFunctions.ToMySQLDateTime(aBatch.batch_date) + "', '" + ConvertHandlingToDentrix(aBatch.handlingAsString) +
                                                       "')", dbConnection);
                        sc.ExecuteNonQuery();

                        sc.CommandText = "SELECT IDENT_CURRENT('NHDG_CLAIM_BATCHES')";
                        SqlDataReader getID = sc.ExecuteReader();
                        getID.Read();
                        int lastID = System.Convert.ToInt32(getID[0]);
                        getID.Close();

                        // Insert all the claims in the batch into nhdg_claim_transactions
                        foreach (claim aClaim in aBatch.GetMatchingClaims())
                        {
                            sc.CommandText = "INSERT INTO NHDG_CLAIM_TRANSACTIONS (CLAIM_ID, CLAIM_DB, CLAIMBATCHID) " +
                                             " VALUES (" + aClaim.claimidnum + "," + aClaim.claimdb + "," + lastID + ")";
                            sc.ExecuteNonQuery();
                        }
                    }
                }
                catch
                {
                    okToContinue = false;
                    MessageBox.Show("There was an error getting the data into the Dentrix database. The process cannot continue.");
                }
            }
            if (okToContinue)
            {
                XmlDocument toSave = new XmlDocument();
                XmlNode     toChange;
                if (File.Exists(XMLPATH))
                {
                    toSave.Load(XMLPATH);
                    toChange = toSave.DocumentElement;
                }
                else
                {
                    toChange = toSave.AppendChild(toSave.CreateNode(XmlNodeType.Element, "SyncData", ""));
                    toChange = toSave.DocumentElement.AppendChild(toSave.CreateTextNode("LastUpdate"));
                }

                toChange.InnerText = DateTime.Now.ToString();
                toSave.Save(XMLPATH);

                MessageBox.Show(count + " batches synced successfully.");
            }


            else
            {
                MessageBox.Show("Please contact a system administrator to fix the problems you encountered while syncing.");
            }
        }
        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);
        }