public SubmissionResult SubmitChanges()
        {
            //Console.WriteLine("BEGIN send sql commands");
            SubmissionResult result = new SubmissionResult();

            result.HasUpdateCommands      = this.m_SqlUpdateCommands.Count > 0;
            result.HasDeleteFirstCommands = this.m_SqlDeleteFirstCommands.Count > 0;
            result.HasDeleteCommands      = this.m_SqlDeleteCommands.Count > 0;
            result.HasInsertCommands      = this.m_SqlInsertCommands.Count > 0;
            result.HasInsertLastCommands  = this.m_SqlInsertLastCommands.Count > 0;

            //if (result.HasDeleteCommands || result.HasDeleteFirstCommands) System.Windows.MessageBox.Show("Delete Commands - pause and step");

            this.RunSqlCommands(this.m_SqlUpdateCommands);
            this.RunSqlCommands(this.m_SqlDeleteFirstCommands);
            this.RunSqlCommands(this.m_SqlDeleteCommands);
            this.RunSqlCommands(this.m_SqlInsertCommands);
            this.RunSqlCommands(this.m_SqlInsertLastCommands);
            //Console.WriteLine("END send sql commands");
            return(result);
        }
Example #2
0
        public SubmissionResult SubmitChanges()
        {
            SubmissionResult result = new SubmissionResult();

            result.HasUpdateCommands      = this.m_SqlUpdateCommands.Count > 0;
            result.HasDeleteFirstCommands = this.m_SqlDeleteFirstCommands.Count > 0;
            result.HasDeleteCommands      = this.m_SqlDeleteCommands.Count > 0;
            result.HasInsertCommands      = this.m_SqlInsertCommands.Count > 0;
            result.HasInsertLastCommands  = this.m_SqlInsertLastCommands.Count > 0;

            if (result.HasUpdateCommands || result.HasDeleteFirstCommands || result.HasDeleteCommands || result.HasInsertCommands || result.HasInsertLastCommands)
            {
                using (MySqlConnection cn = new MySqlConnection(this.m_ConnectionString))
                {
                    cn.Open();

                    MySqlTransaction trans = cn.BeginTransaction();
                    try
                    {
                        this.RunSqlCommands(this.m_SqlUpdateCommands, cn, trans);
                        this.RunSqlCommands(this.m_SqlDeleteFirstCommands, cn, trans);
                        this.RunSqlCommands(this.m_SqlDeleteCommands, cn, trans);
                        this.RunSqlCommands(this.m_SqlInsertCommands, cn, trans);
                        this.RunSqlCommands(this.m_SqlInsertLastCommands, cn, trans);
                        trans.Commit();
                    }
                    catch (Exception ex) //error occurred
                    {
                        if (cn.State == System.Data.ConnectionState.Open)
                        {
                            trans.Rollback();
                            cn.Close();
                        }
                        throw(ex);
                    }
                }
            }
            return(result);
        }