Пример #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);
        }
Пример #2
0
        public void ChangeCode(DataRow OldRow, DataRow NewRow)
        {
            string pk      = _drTable["pk"].ToString();
            string OldCode = OldRow[pk].ToString();
            string NewCode = NewRow[pk].ToString();

            DbData.BeginMultiTrans();
            try
            {
                string    sql     = "select * from systable where systableid in(select systableid from sysfield where RootTable='" + _drTable["TableName"].ToString() + "' group by systableid) and Collecttype<>-1";
                DataTable dsTable = _dbStruct.GetDataTable(sql);
                sql = "select * from sysfield where RootTable='" + _drTable["TableName"].ToString() + "'";
                DataTable dsField = _dbStruct.GetDataTable(sql);

                foreach (DataRow dr in dsTable.Rows)
                {
                    DataRow[] lstField = dsField.Select("sysTableID=" + dr["sysTableID"].ToString());
                    foreach (DataRow drField in lstField)
                    {
                        sql = "Update " + dr["TableName"] + " set " + drField["FieldName"].ToString() + " ='" + NewCode + "' where " + drField["FieldName"].ToString() + " ='" + OldCode + "'";
                        DbData.UpdateByNonQuery(sql);
                    }
                }
                DbData.EndMultiTrans();
            }
            catch (Exception ex)
            {
                DbData.RollbackMultiTrans();
            }
        }
Пример #3
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);
        }
Пример #4
0
        public void updateWS()
        {
            try
            {
                DbData.BeginMultiTrans();
                string sql;// = "update " + _drTable["TableName"].ToString() + " set ws=null ";
                // if (extraWS != string.Empty)
                //     sql += " where " + extraWS;
                // DbData.UpdateByNonQuery(sql);
                DataRow[] drQ;
                if (extraWS != string.Empty)
                {
                    drQ = DsData.Tables[0].Select(extraWS);
                }
                else
                {
                    drQ = DsData.Tables[0].Select();
                }
                string extraForType = string.Empty;
                if (PkMaster.DbType == SqlDbType.VarChar || PkMaster.DbType == SqlDbType.UniqueIdentifier)
                {
                    extraForType = "'";
                }

                foreach (DataRow dr in drQ)
                {
                    if (dr.RowState == DataRowState.Modified)
                    {
                        sql = "update " + _drTable["TableName"].ToString() + " set Grws='" + dr["Grws"].ToString() + "' where " + PkMaster.FieldName + "=" + quote + dr[PkMaster.FieldName] + quote;
                        DbData.UpdateByNonQuery(sql);
                        dr.AcceptChanges();
                    }
                }
                if (DbData.HasErrors)
                {
                    DbData.RollbackMultiTrans();
                }
                else
                {
                    DbData.EndMultiTrans();
                }
            }
            finally
            {
                if (DbData.Connection.State != ConnectionState.Closed)
                {
                    DbData.Connection.Close();
                }
            }
        }
Пример #5
0
        public void updateWS()
        {
            DbData.BeginMultiTrans();
            string sql = "update " + _drTable["TableName"].ToString() + " set ws=null ";

            if (extraWS != string.Empty)
            {
                sql += " where " + extraWS;
            }
            DbData.UpdateByNonQuery(sql);
            DataRow[] drQ;
            if (extraWS != string.Empty)
            {
                drQ = DsData.Tables[0].Select(extraWS + " and not (ws is null or ws='')");
            }
            else
            {
                drQ = DsData.Tables[0].Select(" not (ws is null or ws='')");
            }
            string extraForType = string.Empty;

            if (PkMaster.DbType == SqlDbType.VarChar || PkMaster.DbType == SqlDbType.UniqueIdentifier)
            {
                extraForType = "'";
            }

            foreach (DataRow dr in drQ)
            {
                sql = "update " + _drTable["TableName"].ToString() + " set ws='" + dr["ws"].ToString() + "' where " + PkMaster.FieldName + "=" + extraForType + dr[PkMaster.FieldName] + extraForType;
                DbData.UpdateByNonQuery(sql);
            }
            if (DbData.HasErrors)
            {
                DbData.RollbackMultiTrans();
            }
            else
            {
                DbData.EndMultiTrans();
            }
        }
Пример #6
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);
        }