Ejemplo n.º 1
0
        public override bool UpdateData(DataAction dataAction)
        {
            if (!_dataChanged)
            {
                return(true);
            }

            bool isError = false;

            try
            {
                DbData.BeginMultiTrans();
                int index = DsData.Tables[0].Rows.IndexOf(_drCurrentMaster);

                if (!_customize.BeforeUpdate(index, DsData))
                {
                    DbData.RollbackMultiTrans();
                    return(false);
                }

                bool isNew = _drCurrentMaster.RowState == DataRowState.Added;
                if (Update(_drCurrentMaster))
                {
                    isError = isError || !TransferData(dataAction, index);
                    _customize.AfterUpdate();
                }
                else
                {
                    isError = true;
                }
                //
                if (!isError)
                {
                    DbData.EndMultiTrans();
                }
                else
                {
                    DbData.RollbackMultiTrans();
                }
                if (isNew && !isError)
                {
                    _autoIncreValues.UpdateNewStruct(_drCurrentMaster);
                }
                if (!isError)
                {
                    base.InsertHistory(dataAction, DsData);
                    DsData.AcceptChanges();
                    _dsDataTmp = DsData.Copy();
                }
                DataChanged = false;
            }
            finally
            {
                if (DbData.Connection.State != ConnectionState.Closed)
                {
                    DbData.Connection.Close();
                }
            }
            return(!isError);
        }
Ejemplo n.º 2
0
        public override bool UpdateData(DataAction dataAction)
        {
            if (!_dataChanged)
            {
                return(true);
            }
            DbData.BeginMultiTrans();
            int index = DsData.Tables[0].Rows.IndexOf(_drCurrentMaster);

            if (index == -1)
            {
                return(false);
            }
            if (!_customize.BeforeUpdate(index, DsData))
            {
                DbData.RollbackMultiTrans();
                return(false);
            }

            DataRow[] arrDrCurrentDetails = new DataRow[_lstDrCurrentDetails.Count];
            _lstDrCurrentDetails.CopyTo(arrDrCurrentDetails);
            bool isNew = _drCurrentMaster.RowState == DataRowState.Added;

            if ((dataAction != DataAction.Delete && Update(_drCurrentMaster) && UpdateDetail()) ||
                (dataAction == DataAction.Delete && UpdateDetail() && Update(_drCurrentMaster)))
            {
                TransferData(dataAction, index);
                _customize.AfterUpdate();
            }
            bool isError = DbData.HasErrors;

            if (!isError)
            {
                DbData.EndMultiTrans();
            }
            else
            {
                DbData.RollbackMultiTrans();
            }

            if (isNew && !isError)
            {
                _autoIncreValues.UpdateNewStruct(_drCurrentMaster);
            }
            if (!isError)
            {
                base.InsertHistory(dataAction, DsData);
                DsData.AcceptChanges();
                _dsDataTmp = DsData.Copy();
            }
            return(!isError);
        }
Ejemplo n.º 3
0
        public override bool UpdateData(DataAction dataAction)
        {
            DateTime btime = DateTime.Now;
            DateTime etime = DateTime.Now;

            if (!_dataChanged)
            {
                return(true);
            }
            bool isNew = _drCurrentMaster.RowState == DataRowState.Added;
            //kiểm tra Record trước khi update có thỏa điều kiện phân quyền không
            Boolean chkOk = false;

            if (extraWS != string.Empty)
            {
                object pkValue = null;

                string fieldName = string.Empty;

                bool     isDelete = false;
                bool     isModify = false;
                DataView vOrg     = new DataView(_drCurrentMaster.Table);

                if (_drCurrentMaster.RowState == DataRowState.Deleted)
                {
                    _drCurrentMaster.RejectChanges();
                    isDelete = true;
                }
                if (_drCurrentMaster.RowState == DataRowState.Modified)
                {
                    vOrg.RowStateFilter = DataViewRowState.ModifiedOriginal;
                    vOrg.RowFilter      = extraWS;
                    isModify            = true;
                }

                pkValue = _drCurrentMaster[PkMaster.FieldName];
                DataRow[] DRowtmp = DsData.Tables[0].Select(extraWS);
                foreach (DataRow drtmp in DRowtmp)
                {
                    if (pkValue == drtmp[PkMaster.FieldName])
                    {
                        if (isModify)
                        {
                            if (vOrg.Count > 0)
                            {
                                chkOk = true;
                            }
                        }
                        else
                        {
                            chkOk = true;
                        }
                    }
                }
                if (isDelete)
                {
                    _drCurrentMaster.Delete();
                }
            }
            else
            {
                chkOk = true;
            }
            if (!chkOk)
            {
                return(false);
            }
            //----
            bool isError = false;

            try
            {
                btime = DateTime.Now;
                DbData.BeginMultiTrans();
                this.CheckRules(dataAction);
                if (_drCurrentMaster.Table.DataSet.HasErrors)
                {
                    DbData.RollbackMultiTrans();
                    return(false);
                }
                int index = DsData.Tables[0].Rows.IndexOf(_drCurrentMaster);

                if (!_customize.BeforeUpdate(index, DsData))
                {
                    DbData.EndMultiTrans();
                    return(false);
                }

                if (Update(_drCurrentMaster))
                {
                    TransferData(dataAction, index);
                    _customize.AfterUpdate();
                }
                isError = DbData.HasErrors;
                if (!isError)
                {
                    etime = DateTime.Now;
                    DbData.EndMultiTrans();
                }
                else
                {
                    DbData.RollbackMultiTrans();
                }

                if (isNew && !isError)
                {
                    _autoIncreValues.UpdateNewStruct(_drCurrentMaster);
                }
                if (!isError)
                {
                    base.InsertHistory(dataAction, DsData, btime, etime);
                    DsData.AcceptChanges();
                    _dsDataTmp = DsData.Copy();
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (this.DbData.Connection.State != ConnectionState.Closed)
                {
                    this.DbData.Connection.Close();
                }
            }
            return(!isError);
        }