Ejemplo n.º 1
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();
            }
        }
Ejemplo n.º 2
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();
                }
            }
        }
Ejemplo n.º 3
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();
            }
        }