Provides data for the RowUpdated event. This class cannot be inherited.
상속: System.Data.Common.RowUpdatedEventArgs
예제 #1
0
        protected override void OnRowUpdated(RowUpdatedEventArgs value)
        {
            MySqlRowUpdatedEventArgs    mySqlRowUpdatedEventArgs    = value as MySqlRowUpdatedEventArgs;
            MySqlRowUpdatedEventHandler mySqlRowUpdatedEventHandler = (MySqlRowUpdatedEventHandler)base.Events[MySqlDataAdapter.EventRowUpdated];

            if (mySqlRowUpdatedEventHandler != null && mySqlRowUpdatedEventArgs != null)
            {
                mySqlRowUpdatedEventHandler(this, mySqlRowUpdatedEventArgs);
            }
        }
예제 #2
0
        /// <summary>
        /// Overridden. Raises the RowUpdated event.
        /// </summary>
        /// <param name="value">A MySqlRowUpdatedEventArgs that contains the event data. </param>
        override protected void OnRowUpdated(RowUpdatedEventArgs value)
        {
            MySqlRowUpdatedEventArgs margs = (value as MySqlRowUpdatedEventArgs);
            //args.Command.CommandText = savedSql;

            MySqlRowUpdatedEventHandler handler = (MySqlRowUpdatedEventHandler)Events[EventRowUpdated];

            if ((null != handler) && (margs != null))
            {
                handler(this, margs);
            }
        }
예제 #3
0
 private void MySqlDatabase_RowUpdated(object sender, MySqlRowUpdatedEventArgs e)
 {
     if (e.RecordsAffected == 0)
     {
         if (e.Errors != null)
         {
             e.Row.RowError = "更新数据行时出错。";
             e.Status = UpdateStatus.SkipCurrentRow;
         }
     }
 }
예제 #4
0
 private void OnRowUpdated( object sender, MySqlRowUpdatedEventArgs args )
 {
     if( args.StatementType == StatementType.Insert )
     {
         // Get last inserted identity value.
         // MySQL has this handy property that gives it to us.
         // Except sometimes it's set to -1 and therefore not useful.
         int id = (int)this.DataAdapter.InsertCommand.LastInsertedId;
         if( id < 1 )
             id = Convert.ToInt32( identityCommand.ExecuteScalar() );
         if( args.Row["ID"] == DBNull.Value
             || Convert.ToInt32( args.Row["ID"] ) < 1 )
         {
             args.Row["ID"] = id;
         }
         if( (int)args.Row["ID"] != id )
         {
             throw new ApplicationException(
                 string.Format( "Database identity {0} does not match DataRow identity {1}",
                 id,
                 args.Row["ID"] ) );
         }
     }
 }
예제 #5
0
        protected static void OnRowUpdated(object sender, MySqlRowUpdatedEventArgs e)
        {
            try
            {
                PropertyCollection props = e.Row.Table.ExtendedProperties;
                if (props.ContainsKey("props"))
                {
                    props = (PropertyCollection)props["props"];
                }

                if (e.Status == UpdateStatus.Continue && (e.StatementType == StatementType.Insert || e.StatementType == StatementType.Update))
                {
                    tgDataRequest request = props["tgDataRequest"] as tgDataRequest;
                    tgEntitySavePacket packet = (tgEntitySavePacket)props["esEntityData"];
                    string source = props["Source"] as string;

                    if (e.StatementType == StatementType.Insert)
                    {
                        if (props.Contains("AutoInc"))
                        {
                            string autoInc = props["AutoInc"] as string;

                            MySqlCommand cmd = new MySqlCommand();
                            cmd.Connection = e.Command.Connection;
                            cmd.Transaction = e.Command.Transaction;
                            cmd.CommandText = "SELECT LAST_INSERT_ID();";

                            object o = null;

                            #region Profiling

                            if (sTraceHandler != null)
                            {
                                using (esTraceArguments esTrace = new esTraceArguments(request, cmd, "OnRowUpdated", System.Environment.StackTrace))
                                {
                                    try
                                    {
                                        o = cmd.ExecuteScalar();
                                    }
                                    catch (Exception ex)
                                    {
                                        esTrace.Exception = ex.Message;
                                        throw;
                                    }
                                }
                            }
                            else

                            #endregion Profiling

                            {
                                o = cmd.ExecuteScalar();
                            }

                            if (o != null)
                            {
                                e.Row[autoInc] = o;
                                e.Command.Parameters["?" + autoInc].Value = o;
                            }
                        }

                        if (props.Contains("EntitySpacesConcurrency"))
                        {
                            string esConcurrencyColumn = props["EntitySpacesConcurrency"] as string;
                            packet.CurrentValues[esConcurrencyColumn] = 1;
                        }
                    }

                    if (props.Contains("Timestamp"))
                    {
                        string column = props["Timestamp"] as string;

                        MySqlCommand cmd = new MySqlCommand();
                        cmd.Connection = e.Command.Connection;
                        cmd.Transaction = e.Command.Transaction;
                        cmd.CommandText = "SELECT LastTimestamp('" + source + "');";

                        object o = null;

                        #region Profiling

                        if (sTraceHandler != null)
                        {
                            using (esTraceArguments esTrace = new esTraceArguments(request, cmd, "OnRowUpdated", System.Environment.StackTrace))
                            {
                                try
                                {
                                    o = cmd.ExecuteScalar();
                                }
                                catch (Exception ex)
                                {
                                    esTrace.Exception = ex.Message;
                                    throw;
                                }
                            }
                        }
                        else

                        #endregion Profiling

                        {
                            o = cmd.ExecuteScalar();
                        }

                        if (o != null)
                        {
                            e.Command.Parameters["?" + column].Value = o;
                        }
                    }

                    //-------------------------------------------------------------------------------------------------
                    // Fetch any defaults, SQLite doesn't support output parameters so we gotta do this the hard way
                    //-------------------------------------------------------------------------------------------------
                    if (props.Contains("Defaults"))
                    {
                        // Build the Where parameter and parameters
                        MySqlCommand cmd = new MySqlCommand();
                        cmd.Connection = e.Command.Connection;
                        cmd.Transaction = e.Command.Transaction;

                        string select = (string)props["Defaults"];

                        string[] whereParameters = ((string)props["Where"]).Split(',');

                        string comma = String.Empty;
                        string where = String.Empty;
                        int i = 1;
                        foreach (string parameter in whereParameters)
                        {
                            MySqlParameter p = new MySqlParameter("?p" + i++.ToString(), e.Row[parameter]);
                            cmd.Parameters.Add(p);
                            where += comma + "`" + parameter + "` = " + p.ParameterName;
                            comma = " AND ";
                        }

                        // Okay, now we can execute the sql and get any values that have defaults that were
                        // null at the time of the insert and/or our timestamp
                        cmd.CommandText = "SELECT " + select + " FROM `" + request.ProviderMetadata.Source + "` WHERE " + where + ";";

                        MySqlDataReader rdr = null;

                        try
                        {
                            #region Profiling

                            if (sTraceHandler != null)
                            {
                                using (esTraceArguments esTrace = new esTraceArguments(request, cmd, "OnRowUpdated", System.Environment.StackTrace))
                                {
                                    try
                                    {
                                        rdr = cmd.ExecuteReader(CommandBehavior.SingleResult);
                                    }
                                    catch (Exception ex)
                                    {
                                        esTrace.Exception = ex.Message;
                                        throw;
                                    }
                                }
                            }
                            else

                            #endregion Profiling

                            {
                                rdr = cmd.ExecuteReader(CommandBehavior.SingleResult);
                            }

                            if (rdr.Read())
                            {
                                select = select.Replace("`", String.Empty).Replace("`", String.Empty);
                                string[] selectCols = select.Split(',');

                                for (int k = 0; k < selectCols.Length; k++)
                                {
                                    packet.CurrentValues[selectCols[k]] = rdr.GetValue(k);
                                }
                            }
                        }
                        finally
                        {
                            // Make sure we close the reader no matter what
                            if (rdr != null) rdr.Close();
                        }
                    }

                    if (e.StatementType == StatementType.Update)
                    {
                        string colName = props["EntitySpacesConcurrency"] as string;
                        object o = e.Row[colName];

                        MySqlParameter p = e.Command.Parameters["?" + colName];
                        object v = null;

                        switch (Type.GetTypeCode(o.GetType()))
                        {
                            case TypeCode.Int16: v = ((System.Int16)o) + 1; break;
                            case TypeCode.Int32: v = ((System.Int32)o) + 1; break;
                            case TypeCode.Int64: v = ((System.Int64)o) + 1; break;
                            case TypeCode.UInt16: v = ((System.UInt16)o) + 1; break;
                            case TypeCode.UInt32: v = ((System.UInt32)o) + 1; break;
                            case TypeCode.UInt64: v = ((System.UInt64)o) + 1; break;
                        }

                        p.Value = v;
                    }
                }
            }
            catch { }
        }
예제 #6
0
파일: MySQL.cs 프로젝트: oeli/yafra
 /// <summary>
 /// Handles the RowUpdated event
 /// </summary>
 /// <param name="obj">The object that published the event</param>
 /// <param name="e">The OleDbRowUpdatedEventArgs</param>
 protected void RowUpdated(object obj, MySqlRowUpdatedEventArgs e)
 {
     base.RowUpdated(obj, e);
 }
예제 #7
0
파일: Modele.cs 프로젝트: KMenant/TP-SIO-2
 // utile pour ajout,modif,supp
 private void OnRowUpdated(object sender, MySqlRowUpdatedEventArgs args)
 {
     string msg = "";
     Int64 nb = 0;
     if (args.Status == UpdateStatus.ErrorsOccurred)
     {
         if (vaction == 'd' || vaction == 'u') // on veut savoir si la personne existe encore dans la base
         {
             MySqlCommand vcommand = myConnection.CreateCommand();
             if (vtable == 'p') // ‘p’ pour table PERSONNE
             {
                 vcommand.CommandText = "SELECT COUNT(*) FROM personne WHERE IdPersonne = '" + args.Row[0, DataRowVersion.Original] + "'";
             }
             nb = (Int64)vcommand.ExecuteScalar();
         }
         if (vaction == 'd')
         {
             if (nb == 1) // pour delete si l'enr a été supprimé on n'affiche pas l'erreur
             {
                 if (vtable == 'p')
                 {
                     msg = "Pour le numéro de personnes : " + args.Row[0, DataRowVersion.Original] + "impossible delete car enr modifié dans la base";
                 }
                 rapport.Add(msg);
                 errmaj = true;
             }
         }
         if (vaction == 'u')
         {
             if (nb == 1)
             {
                 if (vtable == 'p')
                 {
                     msg = "pour le numéro de personne: " + args.Row[0, DataRowVersion.Original] + "impossible MAJ car enr modifié dans la base";
                 }
                 rapport.Add(msg);
                 errmaj = true;
             }
             else
             {
                 if (vtable == 'p')
                 {
                     msg = "pour le numéro de personne : " + args.Row[0, DataRowVersion.Original] + "impossible MAJ car enr supprimé dans la base";
                 }
                 rapport.Add(msg);
                 errmaj = true;
             }
         }
         if (vaction == 'c')
         {
             if (vtable == 'p')
             {
                 msg = "pour le numéro de personne : " + args.Row[0, DataRowVersion.Current] + "impossible ADD car erreur données";
             }
             rapport.Add(msg);
             errmaj = true;
         }
     }
 }
예제 #8
0
 /// <summary>
 /// Called when [my SQL row updated].
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="rowThatCouldNotBeWritten">The <see cref="MySqlRowUpdatedEventArgs"/> instance containing the event data.</param>
 /// <devdoc>
 /// Listens for the RowUpdate event on a data adapter to support
 /// UpdateBehavior.Continue
 /// </devdoc>
 private void OnMySqlRowUpdated(object sender, MySqlRowUpdatedEventArgs rowThatCouldNotBeWritten) {
     if(rowThatCouldNotBeWritten.RecordsAffected == 0) {
         if(rowThatCouldNotBeWritten.Errors != null) {
             rowThatCouldNotBeWritten.Row.RowError = "행을 갱신하는데 실패했습니다.";
             rowThatCouldNotBeWritten.Status = UpdateStatus.SkipCurrentRow;
         }
     }
 }
예제 #9
0
        // If it's an Insert we fetch the @@Identity value and stuff it in the proper column
        protected void OnRowUpdated(object sender, MySqlRowUpdatedEventArgs e)
        {
            try
            {
                if(e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert)
                {
                    TransactionMgr txMgr = TransactionMgr.ThreadTransactionMgr();

                    string identityCol = this.GetAutoKeyColumns();

                    MySqlCommand cmd = new MySqlCommand();

                    cmd.CommandText = "SELECT LAST_INSERT_ID();";

                    // We make sure we enlist in the ongoing transaction, otherwise, we
                    // would most likely deadlock
                    txMgr.Enlist(cmd, this);
                    object o = cmd.ExecuteScalar(); // Get the Identity Value
                    txMgr.DeEnlist(cmd, this);

                    if(o != null)
                    {
                        e.Row[identityCol] = o;
                    }

                    e.Row.AcceptChanges();
                }
            }
            catch {}
        }
예제 #10
0
 /// <devdoc>
 /// Listens for the RowUpdate event on a dataadapter to support UpdateBehavior.Continue
 /// </devdoc>
 private void OnMySqlRowUpdated(object sender, MySqlRowUpdatedEventArgs rowThatCouldNotBeWritten)
 {
     if (rowThatCouldNotBeWritten.RecordsAffected == 0)
     {
         if (rowThatCouldNotBeWritten.Errors != null)
         {
             rowThatCouldNotBeWritten.Row.RowError = SR.ExceptionMessageUpdateDataSetRowFailure;
             rowThatCouldNotBeWritten.Status = UpdateStatus.SkipCurrentRow;
         }
     }
 }