Пример #1
0
        /// <summary>
        /// UpdateMasterDetail
        /// </summary>
        /// <returns></returns>
        /// <remarks></remarks>
        public virtual bool Update()
        {
            bool             blnResult = false;
            MySqlTransaction ts        = null;

            using (var cnn = oDLBase.DataConnection)
            {
                try
                {
                    if (cnn.State == ConnectionState.Closed)
                    {
                        cnn.Open();
                    }
                    ts = cnn.BeginTransaction();
                    string strMessage = CheckUniqueExistsReturnString(MasterRow);
                    if (string.IsNullOrEmpty(strMessage))
                    {
                        blnResult = PrepareUpdate(ts);
                        if (oDLBase.update(drMasterRow, ts))
                        {
                            // nếu có detail thì cập nhật vào bảng detail
                            if (TableDetail != null && TableDetail.Rows.Count > 0)
                            {
                                oDLBase.UpdateData(TableDetail.DataSet, strTableDetailName, ts);
                                blnResult = true;
                            }
                            else
                            {
                                blnResult = true;
                            }
                        }
                        if (blnResult)
                        {
                            blnResult = CompleteUpdate(ts);
                        }
                        if (!blnResult)
                        {
                            ts.Rollback();
                        }
                        else
                        {
                            ts.Commit();
                        }
                    }
                    else
                    {
                        throw new Exception(strMessage);
                    }
                }
                catch (Exception ex)
                {
                    if (ts != null)
                    {
                        ts.Rollback();
                    }
                    throw ex;
                }
                finally
                {
                    if (ts != null)
                    {
                        ts.Dispose();
                    }
                    cnn.Close();
                }
            }
            return(blnResult);
        }